Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1165 lines
29 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: staticip.cpp
  4. //
  5. // Synopsis: This file holds the implmentation of the
  6. // of CStaticIp class
  7. //
  8. // History: 12/15/2000 serdarun Created
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //#--------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LocalUIControls.h"
  16. #include "StaticIp.h"
  17. ///////////////////////////////////////////////////////////////////
  18. // CStaticIp
  19. //
  20. // registry path for LCID value
  21. //
  22. const WCHAR LOCALIZATION_MANAGER_REGISTRY_PATH [] =
  23. L"SOFTWARE\\Microsoft\\ServerAppliance\\LocalizationManager\\resources";
  24. const WCHAR LANGID_VALUE [] = L"LANGID";
  25. //++--------------------------------------------------------------
  26. //
  27. // Function: get_IpAddress
  28. //
  29. // Synopsis: This is the IStaticIp interface method
  30. // through which ip address entry is retrieved
  31. //
  32. // Arguments: BSTR *pVal
  33. //
  34. // Returns: HRESULT - success/failure
  35. //
  36. // History: serdarun Created 12/15/2000
  37. //
  38. //----------------------------------------------------------------
  39. STDMETHODIMP CStaticIp::get_IpAddress(BSTR *pVal)
  40. {
  41. if (pVal == NULL)
  42. {
  43. return E_POINTER;
  44. }
  45. return TrimDuplicateZerosAndCopy(m_strIpAddress,pVal);
  46. } // end of CStaticIp::get_IpAddress method
  47. //++--------------------------------------------------------------
  48. //
  49. // Function: put_IpAddress
  50. //
  51. // Synopsis: This is the IStaticIp interface method
  52. // through which ip address entry is set
  53. //
  54. // Arguments: BSTR newVal
  55. //
  56. // Returns: HRESULT - success/failure
  57. //
  58. // History: serdarun Created 12/15/2000
  59. //
  60. //----------------------------------------------------------------
  61. STDMETHODIMP CStaticIp::put_IpAddress(BSTR newVal)
  62. {
  63. HRESULT hr;
  64. if (newVal == NULL)
  65. {
  66. return E_POINTER;
  67. }
  68. hr = FormatAndCopy(newVal,m_strIpAddress);
  69. if (FAILED(hr))
  70. {
  71. return hr;
  72. }
  73. return S_OK;
  74. } // end of CStaticIp::put_IpAddress method
  75. //++--------------------------------------------------------------
  76. //
  77. // Function: get_SubnetMask
  78. //
  79. // Synopsis: This is the IStaticIp interface method
  80. // through which subnet mask entry is retrieved
  81. //
  82. // Arguments: BSTR *pVal
  83. //
  84. // Returns: HRESULT - success/failure
  85. //
  86. // History: serdarun Created 12/15/2000
  87. //
  88. //----------------------------------------------------------------
  89. STDMETHODIMP CStaticIp::get_SubnetMask(BSTR *pVal)
  90. {
  91. if (pVal == NULL)
  92. {
  93. return E_POINTER;
  94. }
  95. return TrimDuplicateZerosAndCopy(m_strSubnetMask,pVal);
  96. } // end of CStaticIp::get_SubnetMask method
  97. //++--------------------------------------------------------------
  98. //
  99. // Function: put_SubnetMask
  100. //
  101. // Synopsis: This is the IStaticIp interface method
  102. // through which ip address entry is set
  103. //
  104. // Arguments: BSTR newVal
  105. //
  106. // Returns: HRESULT - success/failure
  107. //
  108. // History: serdarun Created 12/15/2000
  109. //
  110. //----------------------------------------------------------------
  111. STDMETHODIMP CStaticIp::put_SubnetMask(BSTR newVal)
  112. {
  113. HRESULT hr;
  114. if (newVal == NULL)
  115. {
  116. return E_POINTER;
  117. }
  118. hr = FormatAndCopy(newVal,m_strSubnetMask);
  119. if (FAILED(hr))
  120. {
  121. return hr;
  122. }
  123. return S_OK;
  124. } // end of CStaticIp::put_SubnetMask method
  125. //++--------------------------------------------------------------
  126. //
  127. // Function: get_Gateway
  128. //
  129. // Synopsis: This is the IStaticIp interface method
  130. // through which gateway entry is retrieved
  131. //
  132. // Arguments: BSTR *pVal
  133. //
  134. // Returns: HRESULT - success/failure
  135. //
  136. // History: serdarun Created 12/15/2000
  137. //
  138. //----------------------------------------------------------------
  139. STDMETHODIMP CStaticIp::get_Gateway(BSTR *pVal)
  140. {
  141. if (pVal == NULL)
  142. {
  143. return E_POINTER;
  144. }
  145. return TrimDuplicateZerosAndCopy(m_strGateway,pVal);
  146. } // end of CStaticIp::get_SubnetMask method
  147. //++--------------------------------------------------------------
  148. //
  149. // Function: put_Gateway
  150. //
  151. // Synopsis: This is the IStaticIp interface method
  152. // through which ip address entry is set
  153. //
  154. // Arguments: BSTR newVal
  155. //
  156. // Returns: HRESULT - success/failure
  157. //
  158. // History: serdarun Created 12/15/2000
  159. //
  160. //----------------------------------------------------------------
  161. STDMETHODIMP CStaticIp::put_Gateway(BSTR newVal)
  162. {
  163. HRESULT hr;
  164. if (newVal == NULL)
  165. {
  166. return E_POINTER;
  167. }
  168. hr = FormatAndCopy(newVal,m_strGateway);
  169. if (FAILED(hr))
  170. {
  171. return hr;
  172. }
  173. return S_OK;
  174. } // end of CStaticIp::put_Gateway method
  175. //++--------------------------------------------------------------
  176. //
  177. // Function: FormatAndCopy
  178. //
  179. // Synopsis: This is the public method of CStaticIp
  180. // to format and copy ip structure
  181. //
  182. // Arguments: BSTR bstrValue "0.0.0.0"
  183. // WCHAR *strValue "000.000.000.000"
  184. //
  185. // Returns: HRESULT - success/failure
  186. //
  187. // History: serdarun Created 12/15/2000
  188. //
  189. //----------------------------------------------------------------
  190. HRESULT CStaticIp::FormatAndCopy(
  191. /*[in]*/BSTR bstrValue,
  192. /*[in,out]*/ WCHAR *strValue
  193. )
  194. {
  195. int iIndex = 0;
  196. int iDestIndex = 0;
  197. int iLength = 0;
  198. iLength = wcslen(bstrValue);
  199. if (iLength <= 0)
  200. {
  201. return E_INVALIDARG;
  202. }
  203. iIndex = iLength - 1;
  204. iDestIndex = IpAddressSize - 2;
  205. wcscpy(strValue,L"...............");
  206. //
  207. // Start copying from end of the string
  208. //
  209. while ( iDestIndex >= 0 )
  210. {
  211. //
  212. // If it is not '.' just copy
  213. //
  214. if ( (iIndex >= 0) && (bstrValue[iIndex] != '.') )
  215. {
  216. strValue[iDestIndex] = bstrValue[iIndex];
  217. iIndex--;
  218. iDestIndex--;
  219. }
  220. //
  221. // it is a '.', put zeros as necessary
  222. //
  223. else
  224. {
  225. while ( (iDestIndex % 4 != 3) && (iDestIndex >= 0) )
  226. {
  227. strValue[iDestIndex] = '0';
  228. iDestIndex--;
  229. }
  230. iDestIndex--;
  231. iIndex--;
  232. }
  233. }
  234. return S_OK;
  235. } // end of CStaticIp::FormatAndCopy method
  236. //++--------------------------------------------------------------
  237. //
  238. // Function: TrimDuplicateZerosAndCopy
  239. //
  240. // Synopsis: This is the public method of CStaticIp
  241. // to format and copy ip structure
  242. //
  243. // Arguments: WCHAR *strValue "000.000.000.000"
  244. // BSTR *pNewVal "0.0.0.0"
  245. //
  246. // Returns: HRESULT - success/failure
  247. //
  248. // History: serdarun Created 12/15/2000
  249. //
  250. //----------------------------------------------------------------
  251. HRESULT CStaticIp::TrimDuplicateZerosAndCopy(
  252. /*[in]*/WCHAR *strValue,
  253. /*[in,out]*/ BSTR *pNewVal
  254. )
  255. {
  256. int iIndex = 0;
  257. WCHAR strNewValue[IpAddressSize];
  258. int iDestIndex = 0;
  259. while ( iIndex < IpAddressSize-2 )
  260. {
  261. //
  262. // Don't copy one of two adjacent zeros
  263. //
  264. if (strValue[iIndex] == '0')
  265. {
  266. //
  267. // first digit of the octet cannot be zero
  268. //
  269. if ((iIndex % 4) == 0)
  270. {
  271. iIndex++;
  272. continue;
  273. }
  274. //
  275. // second digit cannot be zero if first digit is zero
  276. //
  277. if ( ((iIndex % 4) == 1) && (strValue[iIndex-1] == '0') )
  278. {
  279. iIndex++;
  280. continue;
  281. }
  282. }
  283. strNewValue[iDestIndex] = strValue[iIndex];
  284. iDestIndex++;
  285. iIndex++;
  286. }
  287. strNewValue[iDestIndex] = strValue[iIndex];
  288. strNewValue[iDestIndex+1] = 0;
  289. *pNewVal = SysAllocString(strNewValue);
  290. if (*pNewVal)
  291. {
  292. return S_OK;
  293. }
  294. return E_OUTOFMEMORY;
  295. } // end of CStaticIp::TrimDuplicateZerosAndCopy method
  296. //++--------------------------------------------------------------
  297. //
  298. // Function: FinalConstruct
  299. //
  300. // Synopsis: This is the CStaticIp method to get the localized strings
  301. //
  302. // Arguments: none
  303. //
  304. // Returns: HRESULT - success/failure
  305. //
  306. // History: serdarun Created 01/01/2001
  307. //
  308. //----------------------------------------------------------------
  309. STDMETHODIMP CStaticIp::FinalConstruct()
  310. {
  311. HRESULT hr;
  312. //
  313. // resource id's for strings we are looking for
  314. //
  315. ULONG ulIpHeaderResourceID = 1073872921;
  316. ULONG ulSubnetHeaderResourceID = 1073872922;
  317. ULONG ulDefaultGatewayHeaderResourceID = 1073872923;
  318. CComBSTR bstrResourceFileName = CComBSTR(L"salocaluimsg.dll");
  319. if (bstrResourceFileName.m_str == NULL)
  320. {
  321. SATraceString("CStaticIp::FinalConstruct failed on memory allocation ");
  322. return E_OUTOFMEMORY;
  323. }
  324. const WCHAR LOCALIZATION_MANAGER[] = L"ServerAppliance.LocalizationManager";
  325. CLSID clsid;
  326. CComPtr<ISALocInfo> pSALocInfo = NULL;
  327. //
  328. // get the localized string names for headers, ip subnetmask and default gateway
  329. //
  330. //
  331. // get the CLSID localization manager
  332. //
  333. hr = ::CLSIDFromProgID (
  334. LOCALIZATION_MANAGER,
  335. &clsid
  336. );
  337. if (FAILED (hr))
  338. {
  339. SATracePrintf ("CStaticIp::FinalConstruct failed on CLSIDFromProgID:%x",hr);
  340. }
  341. else
  342. {
  343. //
  344. // create the Localization Manager COM object
  345. //
  346. hr = ::CoCreateInstance (
  347. clsid,
  348. NULL,
  349. CLSCTX_INPROC_SERVER,
  350. __uuidof (ISALocInfo),
  351. (PVOID*) &pSALocInfo
  352. );
  353. if (FAILED (hr))
  354. {
  355. SATracePrintf ("CStaticIp::FinalConstruct failed on CoCreateInstance:%x",hr);
  356. }
  357. else
  358. {
  359. CComVariant varReplacementString;
  360. hr = pSALocInfo->GetString(
  361. bstrResourceFileName,
  362. ulIpHeaderResourceID,
  363. &varReplacementString,
  364. &m_bstrIpHeader
  365. );
  366. if (FAILED(hr))
  367. {
  368. SATracePrintf ("CStaticIp::FinalConstruct, failed on getting ip header %x :",hr);
  369. }
  370. hr = pSALocInfo->GetString(
  371. bstrResourceFileName,
  372. ulSubnetHeaderResourceID,
  373. &varReplacementString,
  374. &m_bstrSubnetHeader
  375. );
  376. if (FAILED(hr))
  377. {
  378. SATracePrintf ("CStaticIp::FinalConstruct, failed on getting subnet mask header, %x :",hr);
  379. }
  380. hr = pSALocInfo->GetString(
  381. bstrResourceFileName,
  382. ulDefaultGatewayHeaderResourceID,
  383. &varReplacementString,
  384. &m_bstrDefaultGatewayHeader
  385. );
  386. if (FAILED(hr))
  387. {
  388. SATracePrintf ("CStaticIp::FinalConstruct, failed on getting default gateway header, %x :",hr);
  389. }
  390. }
  391. }
  392. //
  393. // set the font now
  394. //
  395. LOGFONT logfnt;
  396. ::memset (&logfnt, 0, sizeof (logfnt));
  397. logfnt.lfOutPrecision = OUT_TT_PRECIS;
  398. logfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  399. logfnt.lfQuality = PROOF_QUALITY;
  400. logfnt.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
  401. logfnt.lfHeight = 12;
  402. logfnt.lfCharSet = GetCharacterSet ();
  403. //
  404. // we chose the fontface for Japanese and let GDI
  405. // decide for the rest
  406. //
  407. if (SHIFTJIS_CHARSET == logfnt.lfCharSet)
  408. {
  409. lstrcpy(logfnt.lfFaceName, TEXT("MS UI Gothic"));
  410. }
  411. else
  412. {
  413. lstrcpy(logfnt.lfFaceName, TEXT("Arial"));
  414. }
  415. m_hFont = ::CreateFontIndirect(&logfnt);
  416. return S_OK;
  417. } // end of CStaticIp::FinalConstruct method
  418. //++--------------------------------------------------------------
  419. //
  420. // Function: FinalRelease
  421. //
  422. // Synopsis: Called just after the destructor,
  423. // deletes the font
  424. //
  425. // Arguments: none
  426. //
  427. // Returns: HRESULT - success/failure
  428. //
  429. // History: serdarun Created 04/18/2001
  430. //
  431. //----------------------------------------------------------------
  432. STDMETHODIMP CStaticIp::FinalRelease(void)
  433. {
  434. if (m_hFont)
  435. {
  436. DeleteObject(m_hFont);
  437. }
  438. return S_OK;
  439. }
  440. //++--------------------------------------------------------------
  441. //
  442. // Function: GetCharacterSet
  443. //
  444. // Synopsis: This is method used to get the character set to use
  445. // for the FONTS
  446. // Arguments:
  447. //
  448. // Returns: BYTE - CharacterSet
  449. //
  450. // History: serdarun Created 04/18/2001
  451. //
  452. // Called By: FinalConstruct method
  453. //
  454. //----------------------------------------------------------------
  455. BYTE CStaticIp::GetCharacterSet ()
  456. {
  457. HKEY hOpenKey = NULL;
  458. BYTE byCharSet = DEFAULT_CHARSET;
  459. do
  460. {
  461. DWORD dwLangId = 0;
  462. //
  463. // open the local machine registry
  464. //
  465. LONG lRetVal = ::RegOpenKeyEx (
  466. HKEY_LOCAL_MACHINE,
  467. LOCALIZATION_MANAGER_REGISTRY_PATH,
  468. NULL, //reserved
  469. KEY_QUERY_VALUE,
  470. &hOpenKey
  471. );
  472. if (ERROR_SUCCESS == lRetVal)
  473. {
  474. DWORD dwBufferSize = sizeof (dwLangId);
  475. //
  476. // get the LANGID now
  477. //
  478. lRetVal = ::RegQueryValueEx (
  479. hOpenKey,
  480. LANGID_VALUE,
  481. NULL, //reserved
  482. NULL,
  483. (LPBYTE) &dwLangId,
  484. &dwBufferSize
  485. );
  486. if (ERROR_SUCCESS == lRetVal)
  487. {
  488. SATracePrintf (
  489. "CStaticIp got the language ID:%d",
  490. dwLangId
  491. );
  492. }
  493. else
  494. {
  495. SATraceFailure (
  496. "CStaticIp unable to get language ID",
  497. GetLastError()
  498. );
  499. }
  500. }
  501. else
  502. {
  503. SATraceFailure (
  504. "CStaticIp failed to open registry to get language id",
  505. GetLastError());
  506. }
  507. switch (dwLangId)
  508. {
  509. case 0x401:
  510. // Arabic
  511. byCharSet = ARABIC_CHARSET;
  512. break;
  513. case 0x404:
  514. //Chinese (Taiwan)
  515. byCharSet = CHINESEBIG5_CHARSET;
  516. break;
  517. case 0x804:
  518. //Chinese (PRC)
  519. byCharSet = GB2312_CHARSET;
  520. break;
  521. case 0x408:
  522. //Greek
  523. byCharSet = GREEK_CHARSET;
  524. break;
  525. case 0x40D:
  526. //Hebrew
  527. byCharSet = HEBREW_CHARSET;
  528. break;
  529. case 0x411:
  530. //Japanese
  531. byCharSet = SHIFTJIS_CHARSET;
  532. break;
  533. case 0x419:
  534. //Russian
  535. byCharSet = RUSSIAN_CHARSET;
  536. break;
  537. case 0x41E:
  538. //Thai
  539. byCharSet = THAI_CHARSET;
  540. break;
  541. case 0x41F:
  542. //Turkish
  543. byCharSet = TURKISH_CHARSET;
  544. break;
  545. default:
  546. byCharSet = ANSI_CHARSET;
  547. break;
  548. }
  549. }
  550. while (false);
  551. if (hOpenKey) {::RegCloseKey (hOpenKey);}
  552. SATracePrintf ("CStaticIp using Character Set:%d", byCharSet);
  553. return (byCharSet);
  554. } // end of CStaticIp::GetCharacterSet method
  555. //++--------------------------------------------------------------
  556. //
  557. // Function: OnDraw
  558. //
  559. // Synopsis: This is the public method of CStaticIp
  560. // which handles paint messages
  561. //
  562. // Arguments: ATL_DRAWINFO& di
  563. //
  564. // Returns: HRESULT - success/failure
  565. //
  566. // History: serdarun Created 12/15/2000
  567. //
  568. //----------------------------------------------------------------
  569. HRESULT CStaticIp::OnDraw(ATL_DRAWINFO& di)
  570. {
  571. HFONT hOldFont = NULL;
  572. //
  573. // if we don't have a valid font, return failure
  574. //
  575. if (m_hFont == NULL)
  576. {
  577. return E_FAIL;
  578. }
  579. hOldFont = (HFONT) ::SelectObject(di.hdcDraw, m_hFont);
  580. RECT rectIp = {0,0,14,13};
  581. DrawText(
  582. di.hdcDraw,
  583. m_bstrIpHeader,
  584. wcslen(m_bstrIpHeader),
  585. &rectIp,
  586. DT_VCENTER|DT_LEFT
  587. );
  588. RECT rectSubnet = {0,13,128,26};
  589. DrawText(
  590. di.hdcDraw,
  591. m_bstrSubnetHeader,
  592. wcslen(m_bstrSubnetHeader),
  593. &rectSubnet,
  594. DT_VCENTER|DT_LEFT
  595. );
  596. RECT rectGateway = {0,39,128,52};
  597. DrawText(
  598. di.hdcDraw,
  599. m_bstrDefaultGatewayHeader,
  600. wcslen(m_bstrDefaultGatewayHeader),
  601. &rectGateway,
  602. DT_VCENTER|DT_LEFT
  603. );
  604. RECT rect;
  605. WCHAR strFocusEntry[17];
  606. rect.left = 14;
  607. rect.top = 0;
  608. rect.right = 128;
  609. rect.bottom = 13;
  610. if (m_iEntryFocus == IPHASFOCUS)
  611. {
  612. CreateFocusString(strFocusEntry,m_strIpAddress);
  613. DrawText(
  614. di.hdcDraw,
  615. strFocusEntry,
  616. wcslen(strFocusEntry),
  617. &rect,
  618. DT_VCENTER|DT_LEFT
  619. );
  620. }
  621. else
  622. {
  623. DrawText(
  624. di.hdcDraw,
  625. m_strIpAddress,
  626. wcslen(m_strIpAddress),
  627. &rect,
  628. DT_VCENTER|DT_LEFT
  629. );
  630. }
  631. rect.left = 0;
  632. rect.top = 26;
  633. rect.right = 128;
  634. rect.bottom = 39;
  635. if (m_iEntryFocus == SUBNETHASFOCUS)
  636. {
  637. CreateFocusString(strFocusEntry,m_strSubnetMask);
  638. DrawText(
  639. di.hdcDraw,
  640. strFocusEntry,
  641. wcslen(strFocusEntry),
  642. &rect,
  643. DT_VCENTER|DT_LEFT
  644. );
  645. }
  646. else
  647. {
  648. DrawText(
  649. di.hdcDraw,
  650. m_strSubnetMask,
  651. wcslen(m_strSubnetMask),
  652. &rect,
  653. DT_VCENTER|DT_LEFT
  654. );
  655. }
  656. rect.left = 0;
  657. rect.top = 52;
  658. rect.right = 128;
  659. rect.bottom = 64;
  660. if (m_iEntryFocus == GATEWAYHASFOCUS)
  661. {
  662. CreateFocusString(strFocusEntry,m_strGateway);
  663. DrawText(
  664. di.hdcDraw,
  665. strFocusEntry,
  666. wcslen(strFocusEntry),
  667. &rect,
  668. DT_VCENTER|DT_LEFT
  669. );
  670. }
  671. else
  672. {
  673. DrawText(
  674. di.hdcDraw,
  675. m_strGateway,
  676. wcslen(m_strGateway),
  677. &rect,
  678. DT_VCENTER|DT_LEFT
  679. );
  680. }
  681. SelectObject(di.hdcDraw,hOldFont);
  682. return S_OK;
  683. }// end of CStaticIp::OnDraw method
  684. //++--------------------------------------------------------------
  685. //
  686. // Function: OnKeyDown
  687. //
  688. // Synopsis: This is the public method of CStaticIp
  689. // to handle keydown messages
  690. //
  691. // Arguments: windows message arguments
  692. //
  693. // Returns: HRESULT - success/failure
  694. //
  695. // History: serdarun Created 12/15/2000
  696. //
  697. //----------------------------------------------------------------
  698. LRESULT CStaticIp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  699. {
  700. WCHAR * strFocus;
  701. //
  702. // notify the container about any key press
  703. //
  704. Fire_KeyPressed();
  705. //
  706. // Enter key received, notify the container
  707. //
  708. if (wParam == VK_RETURN)
  709. {
  710. Fire_StaticIpEntered();
  711. return 0;
  712. }
  713. //
  714. // Escape key received, notify the container
  715. //
  716. if (wParam == VK_ESCAPE)
  717. {
  718. Fire_OperationCanceled();
  719. return 0;
  720. }
  721. if (wParam == VK_RIGHT)
  722. {
  723. m_iPositionFocus++;
  724. if (m_iPositionFocus >= LASTPOSITION)
  725. {
  726. m_iPositionFocus = 0;
  727. m_iEntryFocus++;
  728. if (m_iEntryFocus > NUMBEROFENTRIES)
  729. {
  730. m_iEntryFocus = IPHASFOCUS;
  731. }
  732. }
  733. //
  734. // '.' cannot have the focus
  735. //
  736. if ( (m_iPositionFocus % 4) == 3)
  737. {
  738. m_iPositionFocus++;
  739. }
  740. }
  741. else if (wParam == VK_LEFT)
  742. {
  743. m_iPositionFocus--;
  744. if (m_iPositionFocus < 0)
  745. {
  746. m_iPositionFocus = LASTPOSITION - 1;
  747. m_iEntryFocus--;
  748. if (m_iEntryFocus == 0)
  749. {
  750. m_iEntryFocus = GATEWAYHASFOCUS;
  751. }
  752. }
  753. //
  754. // '.' cannot have the focus
  755. //
  756. if ( (m_iPositionFocus % 4) == 3)
  757. {
  758. m_iPositionFocus--;
  759. }
  760. }
  761. else if ( (wParam == VK_UP) || (wParam == VK_DOWN) )
  762. {
  763. if (m_iEntryFocus == IPHASFOCUS)
  764. {
  765. strFocus = m_strIpAddress;
  766. }
  767. else if (m_iEntryFocus == SUBNETHASFOCUS)
  768. {
  769. strFocus = m_strSubnetMask;
  770. }
  771. else
  772. {
  773. strFocus = m_strGateway;
  774. }
  775. ProcessArrowKey(strFocus,wParam);
  776. }
  777. FireViewChange();
  778. return 0;
  779. }// end of CStaticIp::OnKeyDown method
  780. //++--------------------------------------------------------------
  781. //
  782. // Function: ProcessArrowKey
  783. //
  784. // Synopsis: This is the public method of CStaticIp
  785. // to increment or decrement ip character
  786. //
  787. // Arguments: WCHAR * strFocus
  788. // WPARAM wParam
  789. //
  790. // Returns: HRESULT - success/failure
  791. //
  792. // History: serdarun Created 12/15/2000
  793. //
  794. //----------------------------------------------------------------
  795. void CStaticIp::ProcessArrowKey(WCHAR * strFocus,WPARAM wParam)
  796. {
  797. if (wParam == VK_UP)
  798. strFocus[m_iPositionFocus]++;
  799. else
  800. strFocus[m_iPositionFocus]--;
  801. //
  802. // third position from nearest . from left
  803. //
  804. if ( (m_iPositionFocus % 4) == 2 )
  805. {
  806. //
  807. // cannot be smaller than '0'
  808. //
  809. if (strFocus[m_iPositionFocus] < '0')
  810. {
  811. //
  812. // if preceeded by 25 it must go to 5
  813. //
  814. if ( (strFocus[m_iPositionFocus-2] == '2') && (strFocus[m_iPositionFocus-1] == '5') )
  815. {
  816. strFocus[m_iPositionFocus] = '5';
  817. }
  818. //
  819. // it must be 9
  820. //
  821. else
  822. {
  823. strFocus[m_iPositionFocus] = '9';
  824. }
  825. }
  826. //
  827. // cannot be greater than '9'
  828. //
  829. else if (strFocus[m_iPositionFocus] > '9')
  830. {
  831. strFocus[m_iPositionFocus] = '0';
  832. }
  833. //
  834. // greater than '5' and proceeded by 25, it must go to '0'
  835. //
  836. else if (strFocus[m_iPositionFocus] > '5')
  837. {
  838. if ( (strFocus[m_iPositionFocus-2] == '2') && (strFocus[m_iPositionFocus-1] == '5') )
  839. {
  840. strFocus[m_iPositionFocus] = '0';
  841. }
  842. }
  843. }
  844. //
  845. // second position from nearest . from left
  846. //
  847. else if ( (m_iPositionFocus % 4) == 1 )
  848. {
  849. //
  850. // cannot be smaller than '0'
  851. //
  852. if (strFocus[m_iPositionFocus] < '0')
  853. {
  854. //
  855. // if preceeded by 2 it must go to 5
  856. //
  857. if (strFocus[m_iPositionFocus-1] == '2')
  858. {
  859. strFocus[m_iPositionFocus] = '5';
  860. //
  861. // if followed by something greater than '5',
  862. // change folowing value to 0
  863. //
  864. if (strFocus[m_iPositionFocus+1] > '5')
  865. {
  866. strFocus[m_iPositionFocus+1] = '0';
  867. }
  868. }
  869. //
  870. // it must be 9
  871. //
  872. else
  873. {
  874. strFocus[m_iPositionFocus] = '9';
  875. }
  876. }
  877. //
  878. // cannot be greater than '9'
  879. //
  880. else if (strFocus[m_iPositionFocus] > '9')
  881. {
  882. strFocus[m_iPositionFocus] = '0';
  883. }
  884. //
  885. // greater than '5' and proceeded by 2, it must go to '0'
  886. //
  887. else if (strFocus[m_iPositionFocus] > '5')
  888. {
  889. if (strFocus[m_iPositionFocus-1] == '2')
  890. {
  891. strFocus[m_iPositionFocus] = '0';
  892. }
  893. }
  894. //
  895. // greater than '5' and proceeded by 2, third position cannot be higher than 5
  896. //
  897. else if (strFocus[m_iPositionFocus] == '5')
  898. {
  899. if ( (strFocus[m_iPositionFocus-1] == '2') && (strFocus[m_iPositionFocus+1] > '5') )
  900. {
  901. strFocus[m_iPositionFocus+1] = '0';
  902. }
  903. }
  904. }
  905. //
  906. // first position from nearest . from left
  907. //
  908. else
  909. {
  910. //
  911. // cannot be smaller than '0'
  912. //
  913. if (strFocus[m_iPositionFocus] < '0')
  914. {
  915. strFocus[m_iPositionFocus] = '2';
  916. //
  917. // if followed by something greater than '5',
  918. // change that value to '0'
  919. //
  920. if (strFocus[m_iPositionFocus+1] > '5')
  921. {
  922. strFocus[m_iPositionFocus+1] = '0';
  923. }
  924. //
  925. // if followed by '5'check if third position is greater than '5',
  926. // if so, change that value to '0'
  927. //
  928. if (strFocus[m_iPositionFocus+1] == '5')
  929. {
  930. //
  931. // if followed by something greater than '5',
  932. // change folowing value to 0
  933. //
  934. if (strFocus[m_iPositionFocus+2] > '5')
  935. {
  936. strFocus[m_iPositionFocus+2] = '0';
  937. }
  938. }
  939. }
  940. //
  941. // cannot be greater than '2'
  942. //
  943. else if (strFocus[m_iPositionFocus] > '2')
  944. {
  945. strFocus[m_iPositionFocus] = '0';
  946. }
  947. else if (strFocus[m_iPositionFocus] == '2')
  948. {
  949. //
  950. // if followed by something greater than '5',
  951. // change that value to '0'
  952. //
  953. if (strFocus[m_iPositionFocus+1] > '5')
  954. {
  955. strFocus[m_iPositionFocus+1] = '0';
  956. }
  957. //
  958. // if followed by '5'check if third position is greater than '5',
  959. // if so, change that value to '0'
  960. //
  961. else if (strFocus[m_iPositionFocus+1] == '5')
  962. {
  963. //
  964. // if followed by something greater than '5',
  965. // change folowing value to 0
  966. //
  967. if (strFocus[m_iPositionFocus+2] > '5')
  968. {
  969. strFocus[m_iPositionFocus+2] = '0';
  970. }
  971. }
  972. }
  973. }
  974. }// end of CStaticIp::ProcessArrowKey method
  975. //++--------------------------------------------------------------
  976. //
  977. // Function: CreateFocusString
  978. //
  979. // Synopsis: This is the public method of CStaticIp
  980. // to create string with an underscore indicating focus
  981. //
  982. // Arguments: WCHAR * strFocus
  983. // WCHAR * strEntry
  984. //
  985. // Returns: HRESULT - success/failure
  986. //
  987. // History: serdarun Created 12/15/2000
  988. //
  989. //----------------------------------------------------------------
  990. void CStaticIp::CreateFocusString(WCHAR * strFocus,WCHAR * strEntry)
  991. {
  992. int iDestIndex = 0;
  993. int iIndex = 0;
  994. while (iIndex < LASTPOSITION)
  995. {
  996. if (iIndex == m_iPositionFocus)
  997. {
  998. strFocus[iDestIndex] = '&';
  999. iDestIndex++;
  1000. }
  1001. strFocus[iDestIndex] = strEntry[iIndex];
  1002. iDestIndex++;
  1003. iIndex++;
  1004. }
  1005. strFocus[iDestIndex] = 0;
  1006. }// end of CStaticIp::CreateFocusString method