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.

585 lines
20 KiB

  1. /****************************************************************************
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name: cplgeneraltab.cpp
  4. Author: toddb - 10/06/98
  5. ****************************************************************************/
  6. //
  7. // Functions used only by the General tab of the New Location Property Sheet.
  8. // Shared functions are in the Location.cpp file.
  9. //
  10. #include "cplPreComp.h"
  11. #include "cplLocationPS.h"
  12. void UpdateSampleString(HWND hwnd, CLocation * pLoc, PCWSTR pwszAddress, CCallingCard * pCard)
  13. {
  14. CCallingCard cc;
  15. LPWSTR pwszDialable;
  16. LPWSTR pwszDisplayable;
  17. TCHAR szBuf[512];
  18. DWORD dwOptions = pLoc->HasCallWaiting() ? LINETRANSLATEOPTION_CANCELCALLWAITING : 0;
  19. if ( (NULL == pCard) && pLoc->HasCallingCard() )
  20. {
  21. if ( SUCCEEDED(cc.Initialize(pLoc->GetPreferredCardID())) )
  22. {
  23. pCard = &cc;
  24. }
  25. }
  26. if ( 0 == pLoc->TranslateAddress(pwszAddress, pCard, dwOptions, &dwOptions, NULL, &pwszDialable, &pwszDisplayable) )
  27. {
  28. SHUnicodeToTChar(pwszDisplayable, szBuf, ARRAYSIZE(szBuf));
  29. ClientFree(pwszDialable);
  30. ClientFree(pwszDisplayable);
  31. }
  32. else
  33. {
  34. LOG((TL_ERROR, "UpdateSampleString failed to call pLoc->TranslateAddress\n"));
  35. // REVIEW: Should we load some sort of error string instead? Perhaps we should featch the
  36. // error text for the given error code from the message resources in tapiui?
  37. szBuf[0] = TEXT('\0');
  38. }
  39. SetWindowText(hwnd, szBuf);
  40. }
  41. INT_PTR CALLBACK CLocationPropSheet::General_DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  42. {
  43. CLocationPropSheet* pthis = (CLocationPropSheet*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  44. switch(uMsg)
  45. {
  46. case WM_INITDIALOG:
  47. pthis = (CLocationPropSheet*)(((PROPSHEETPAGE*)lParam)->lParam);
  48. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pthis);
  49. return pthis->General_OnInitDialog(hwndDlg);
  50. case WM_COMMAND:
  51. return pthis->General_OnCommand(hwndDlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam );
  52. case WM_NOTIFY:
  53. return pthis->General_OnNotify(hwndDlg, (LPNMHDR)lParam);
  54. case WM_HELP:
  55. // Process clicks on controls after Context Help mode selected
  56. TapiCplWinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (DWORD_PTR)(LPTSTR) a102HelpIDs);
  57. break;
  58. case WM_CONTEXTMENU:
  59. // Process right-clicks on controls
  60. TapiCplWinHelp ((HWND) wParam, gszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID) a102HelpIDs);
  61. break;
  62. }
  63. return 0;
  64. }
  65. BOOL CLocationPropSheet::General_OnInitDialog(HWND hwndDlg)
  66. {
  67. TCHAR szBuf[1024];
  68. HWND hwnd;
  69. hwnd = GetDlgItem( hwndDlg, IDC_LOCATIONNAME );
  70. SHUnicodeToTChar(m_pLoc->GetName(), szBuf, ARRAYSIZE(szBuf));
  71. SetWindowText(hwnd, szBuf);
  72. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  73. hwnd = GetDlgItem( hwndDlg, IDC_COUNTRY );
  74. m_dwCountryID = m_pLoc->GetCountryID();
  75. PopulateCountryList( hwnd, m_dwCountryID );
  76. CCountry * pCountry;
  77. HRESULT hr;
  78. hr = CreateCountryObject(m_dwCountryID, &pCountry);
  79. if ( SUCCEEDED(hr) )
  80. {
  81. m_iCityRule = IsCityRule(pCountry->GetLongDistanceRule());
  82. m_iLongDistanceCarrierCodeRule = IsLongDistanceCarrierCodeRule( pCountry->GetLongDistanceRule() );
  83. m_iInternationalCarrierCodeRule = IsInternationalCarrierCodeRule( pCountry->GetInternationalRule() );
  84. delete pCountry;
  85. } else {
  86. LOG((TL_ERROR, "General_OnInitDialog failed to create country %d", m_dwCountryID));
  87. m_iCityRule = CITY_OPTIONAL;
  88. m_iLongDistanceCarrierCodeRule = LONG_DISTANCE_CARRIER_OPTIONAL;
  89. m_iInternationalCarrierCodeRule = INTERNATIONAL_CARRIER_OPTIONAL;
  90. }
  91. hwnd = GetDlgItem(hwndDlg,IDC_AREACODE);
  92. SHUnicodeToTChar(m_pLoc->GetAreaCode(), szBuf, ARRAYSIZE(szBuf));
  93. SetWindowText(hwnd, szBuf);
  94. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  95. LimitInput(hwnd, LIF_ALLOWNUMBER);
  96. if ( m_iCityRule == CITY_NONE )
  97. {
  98. // The selected country does not have area codes
  99. EnableWindow(hwnd, FALSE);
  100. }
  101. hwnd = GetDlgItem(hwndDlg,IDC_LOCALACCESSNUM);
  102. SHUnicodeToTChar(m_pLoc->GetLocalAccessCode(), szBuf, ARRAYSIZE(szBuf));
  103. SetWindowText(hwnd, szBuf);
  104. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  105. LimitInput(hwnd, LIF_ALLOWNUMBER|LIF_ALLOWPOUND|LIF_ALLOWSTAR|LIF_ALLOWCOMMA);
  106. hwnd = GetDlgItem(hwndDlg,IDC_LONGDISTANCEACCESSNUM);
  107. SHUnicodeToTChar(m_pLoc->GetLongDistanceAccessCode(), szBuf, ARRAYSIZE(szBuf));
  108. SetWindowText(hwnd, szBuf);
  109. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  110. LimitInput(hwnd, LIF_ALLOWNUMBER|LIF_ALLOWPOUND|LIF_ALLOWSTAR|LIF_ALLOWCOMMA);
  111. hwnd = GetDlgItem(hwndDlg,IDC_LONGDISTANCECARRIERCODE);
  112. SHUnicodeToTChar(m_pLoc->GetLongDistanceCarrierCode(), szBuf, ARRAYSIZE(szBuf));
  113. SetWindowText(hwnd, szBuf);
  114. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  115. LimitInput(hwnd, LIF_ALLOWNUMBER);
  116. if ( LONG_DISTANCE_CARRIER_NONE == m_iLongDistanceCarrierCodeRule )
  117. {
  118. // The selected country does not have long distance carrier codes
  119. EnableWindow(hwnd, FALSE);
  120. EnableWindow(GetDlgItem(hwndDlg, IDC_STATICLDC), FALSE);
  121. }
  122. hwnd = GetDlgItem(hwndDlg,IDC_INTERNATIONALCARRIERCODE);
  123. SHUnicodeToTChar(m_pLoc->GetInternationalCarrierCode(), szBuf, ARRAYSIZE(szBuf));
  124. SetWindowText(hwnd, szBuf);
  125. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  126. LimitInput(hwnd, LIF_ALLOWNUMBER);
  127. if ( INTERNATIONAL_CARRIER_NONE == m_iInternationalCarrierCodeRule )
  128. {
  129. // The selected country does not have international carrier codes
  130. EnableWindow(hwnd, FALSE);
  131. EnableWindow(GetDlgItem(hwndDlg, IDC_STATICIC), FALSE);
  132. }
  133. hwnd = GetDlgItem(hwndDlg,IDC_DISABLESTRING);
  134. LPWSTR lpwsz = m_pLoc->GetDisableCallWaitingCode();
  135. SHUnicodeToTChar(lpwsz, szBuf, ARRAYSIZE(szBuf));
  136. SendMessage(hwnd, CB_LIMITTEXT, CPL_SETTEXTLIMIT, 0);
  137. PopulateDisableCallWaitingCodes(hwnd, szBuf);
  138. LimitCBInput(hwnd, LIF_ALLOWNUMBER|LIF_ALLOWPOUND|LIF_ALLOWSTAR|LIF_ALLOWCOMMA);
  139. if ( NULL == *lpwsz || !m_pLoc->HasCallWaiting() )
  140. {
  141. EnableWindow(hwnd, FALSE);
  142. }
  143. else
  144. {
  145. hwnd = GetDlgItem(hwndDlg,IDC_DISABLECALLWAITING);
  146. SendMessage(hwnd,BM_SETCHECK, BST_CHECKED, 0);
  147. }
  148. CheckRadioButton(hwndDlg,IDC_TONE,IDC_PULSE,m_pLoc->HasToneDialing()?IDC_TONE:IDC_PULSE);
  149. if (!m_pwszAddress)
  150. {
  151. ShowWindow(GetDlgItem(hwndDlg,IDC_PHONENUMBERTEXT), SW_HIDE);
  152. }
  153. return 0;
  154. }
  155. BOOL PopulateCountryList(HWND hwndCombo, DWORD dwSelectedCountry)
  156. {
  157. BOOL bResult = FALSE;
  158. CCountries CountryList;
  159. SendMessage(hwndCombo,CB_RESETCONTENT,0,0);
  160. if ( SUCCEEDED(CountryList.Initialize()) )
  161. {
  162. TCHAR szText[1024];
  163. CCountry * pC;
  164. DWORD dwCurCountryID;
  165. LRESULT iIndex;
  166. CountryList.Reset();
  167. while ( S_OK == CountryList.Next(1,&pC,NULL) )
  168. {
  169. SHUnicodeToTChar(pC->GetCountryName(), szText, ARRAYSIZE(szText));
  170. iIndex = SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)szText);
  171. dwCurCountryID = pC->GetCountryID();
  172. SendMessage(hwndCombo,CB_SETITEMDATA,iIndex,(LPARAM)dwCurCountryID);
  173. if ( dwCurCountryID == dwSelectedCountry )
  174. {
  175. SendMessage(hwndCombo,CB_SETCURSEL,iIndex,0);
  176. bResult = TRUE;
  177. }
  178. }
  179. }
  180. // REVIEW: If no country was selected (bResult == FALSE) should we simply select some
  181. // arbitrary country? First in the list? The USA?
  182. return bResult;
  183. }
  184. BOOL CLocationPropSheet::PopulateDisableCallWaitingCodes(HWND hwndCombo, LPTSTR szSelected)
  185. {
  186. TCHAR cszTelephonyKey[] = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations");
  187. HKEY hkey;
  188. int i;
  189. // These get read from the registry
  190. // NOTE: This might fail on a tightly locked down system, but there's nothing I can do
  191. // about that. Worst case the list of codes is empty and the user just types the code.
  192. if ( ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, cszTelephonyKey,
  193. 0, KEY_QUERY_VALUE, &hkey) )
  194. {
  195. TCHAR szDisableCallWaiting[32];
  196. TCHAR szCode[32];
  197. DWORD dwType;
  198. DWORD dwSize;
  199. for ( i=0; ; i++ )
  200. {
  201. // This string is a reg value and is not localized
  202. wsprintf(szDisableCallWaiting, TEXT("DisableCallWaiting%d"), i);
  203. dwSize = sizeof(szCode);
  204. if ( ERROR_SUCCESS != RegQueryValueEx(hkey, szDisableCallWaiting, NULL, &dwType, (LPBYTE)szCode, &dwSize) )
  205. {
  206. // when we fail to read an item its most likely because their are no more items,
  207. // but even if it's some other error we don't know how to handle it anyhow.
  208. break;
  209. }
  210. if ( dwType != REG_SZ )
  211. {
  212. // I'll just skip any values that I don't know how to deal with
  213. continue;
  214. }
  215. SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)szCode);
  216. }
  217. }
  218. // and then we add a special one if the current code is not a standard code
  219. if ( szSelected && *szSelected )
  220. {
  221. LRESULT lResult;
  222. lResult = SendMessage(hwndCombo, CB_FINDSTRINGEXACT, -1, (LPARAM)szSelected);
  223. if ( lResult == (LRESULT)CB_ERR )
  224. {
  225. // if the item wasn't found, we add it
  226. lResult = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)szSelected);
  227. }
  228. SendMessage(hwndCombo, CB_SETCURSEL, lResult, 0);
  229. }
  230. return TRUE;
  231. }
  232. BOOL CLocationPropSheet::General_OnCommand(HWND hwndParent, int wID, int wNotifyCode, HWND hwndCtl)
  233. {
  234. WCHAR wszBuf[512];
  235. switch (wID)
  236. {
  237. case IDC_DISABLECALLWAITING:
  238. if ( BN_CLICKED == wNotifyCode )
  239. {
  240. BOOL bOn = SendMessage(hwndCtl, BM_GETCHECK, 0,0) == BST_CHECKED;
  241. HWND hwnd = GetDlgItem(hwndParent, IDC_DISABLESTRING);
  242. EnableWindow(hwnd, bOn);
  243. m_pLoc->UseCallWaiting(bOn);
  244. if ( bOn )
  245. {
  246. SetFocus(hwnd);
  247. }
  248. break;
  249. }
  250. return 1;
  251. case IDC_TONE:
  252. case IDC_PULSE:
  253. m_pLoc->UseToneDialing(IDC_TONE==wID);
  254. break;
  255. case IDC_COUNTRY:
  256. if ( CBN_SELCHANGE == wNotifyCode )
  257. {
  258. LRESULT lrSel = SendMessage(hwndCtl,CB_GETCURSEL,0,0);
  259. m_dwCountryID = (DWORD)SendMessage(hwndCtl,CB_GETITEMDATA,lrSel,0);
  260. m_pLoc->SetCountryID(m_dwCountryID);
  261. CCountry * pCountry;
  262. HRESULT hr;
  263. hr = CreateCountryObject(m_dwCountryID, &pCountry);
  264. if ( SUCCEEDED(hr) )
  265. {
  266. m_iCityRule = IsCityRule(pCountry->GetLongDistanceRule());
  267. m_iLongDistanceCarrierCodeRule = IsLongDistanceCarrierCodeRule( pCountry->GetLongDistanceRule() );
  268. m_iInternationalCarrierCodeRule = IsInternationalCarrierCodeRule( pCountry->GetInternationalRule() );
  269. delete pCountry;
  270. } else {
  271. LOG((TL_ERROR, "General_OnInitDialog failed to create country %d", m_dwCountryID));
  272. m_iCityRule = CITY_OPTIONAL;
  273. m_iLongDistanceCarrierCodeRule = LONG_DISTANCE_CARRIER_OPTIONAL;
  274. m_iInternationalCarrierCodeRule = INTERNATIONAL_CARRIER_OPTIONAL;
  275. }
  276. HWND hwnd = GetDlgItem(hwndParent,IDC_AREACODE);
  277. if ( m_iCityRule == CITY_NONE )
  278. {
  279. SetWindowText(hwnd, TEXT(""));
  280. m_pLoc->SetAreaCode(L"");
  281. EnableWindow(hwnd, FALSE);
  282. }
  283. else
  284. {
  285. EnableWindow(hwnd, TRUE);
  286. }
  287. hwnd = GetDlgItem(hwndParent,IDC_LONGDISTANCECARRIERCODE);
  288. if ( LONG_DISTANCE_CARRIER_NONE == m_iLongDistanceCarrierCodeRule )
  289. {
  290. SetWindowText(hwnd, TEXT(""));
  291. m_pLoc->SetLongDistanceAccessCode(L"");
  292. EnableWindow(hwnd, FALSE);
  293. EnableWindow(GetDlgItem(hwndParent,IDC_STATICLDC), FALSE);
  294. }
  295. else
  296. {
  297. EnableWindow(hwnd, TRUE);
  298. EnableWindow(GetDlgItem(hwndParent,IDC_STATICLDC), TRUE);
  299. }
  300. hwnd = GetDlgItem(hwndParent,IDC_INTERNATIONALCARRIERCODE);
  301. if ( INTERNATIONAL_CARRIER_NONE == m_iInternationalCarrierCodeRule )
  302. {
  303. SetWindowText(hwnd, TEXT(""));
  304. m_pLoc->SetInternationalCarrierCode(L"");
  305. EnableWindow(hwnd, FALSE);
  306. EnableWindow(GetDlgItem(hwndParent,IDC_STATICIC), FALSE);
  307. }
  308. else
  309. {
  310. EnableWindow(hwnd, TRUE);
  311. EnableWindow(GetDlgItem(hwndParent,IDC_STATICIC), TRUE);
  312. }
  313. break;
  314. }
  315. return 1;
  316. case IDC_LOCATIONNAME:
  317. case IDC_AREACODE:
  318. case IDC_LONGDISTANCECARRIERCODE:
  319. case IDC_INTERNATIONALCARRIERCODE:
  320. case IDC_LOCALACCESSNUM:
  321. case IDC_LONGDISTANCEACCESSNUM:
  322. if ( EN_CHANGE == wNotifyCode )
  323. {
  324. TCHAR szValue[512];
  325. GetWindowText(hwndCtl, szValue, ARRAYSIZE(szValue));
  326. SHTCharToUnicode(szValue, wszBuf, ARRAYSIZE(wszBuf));
  327. switch (wID)
  328. {
  329. case IDC_LOCATIONNAME:
  330. m_pLoc->SetName(wszBuf);
  331. break;
  332. case IDC_AREACODE:
  333. m_pLoc->SetAreaCode(wszBuf);
  334. break;
  335. case IDC_LONGDISTANCECARRIERCODE:
  336. m_pLoc->SetLongDistanceCarrierCode(wszBuf);
  337. break;
  338. case IDC_INTERNATIONALCARRIERCODE:
  339. m_pLoc->SetInternationalCarrierCode(wszBuf);
  340. break;
  341. case IDC_LOCALACCESSNUM:
  342. m_pLoc->SetLocalAccessCode(wszBuf);
  343. break;
  344. case IDC_LONGDISTANCEACCESSNUM:
  345. m_pLoc->SetLongDistanceAccessCode(wszBuf);
  346. break;
  347. }
  348. break;
  349. }
  350. return 1;
  351. case IDC_DISABLESTRING:
  352. switch ( wNotifyCode )
  353. {
  354. case CBN_SELCHANGE:
  355. {
  356. TCHAR szDisableCode[128];
  357. LRESULT lr = SendMessage(hwndCtl, CB_GETCURSEL, 0,0);
  358. SendMessage(hwndCtl, CB_GETLBTEXT, lr, (LPARAM)szDisableCode);
  359. SHTCharToUnicode(szDisableCode, wszBuf, ARRAYSIZE(wszBuf));
  360. m_pLoc->SetDisableCallWaitingCode(wszBuf);
  361. }
  362. break;
  363. case CBN_EDITCHANGE:
  364. {
  365. TCHAR szDisableCode[128];
  366. GetWindowText(hwndCtl, szDisableCode, ARRAYSIZE(szDisableCode));
  367. SHTCharToUnicode(szDisableCode, wszBuf, ARRAYSIZE(wszBuf));
  368. m_pLoc->SetDisableCallWaitingCode(wszBuf);
  369. }
  370. break;
  371. default:
  372. return 1;
  373. }
  374. break;
  375. default:
  376. return 0;
  377. }
  378. if (m_pwszAddress)
  379. {
  380. CCallingCard * pCard = NULL;
  381. if (m_pLoc->HasCallingCard())
  382. {
  383. pCard = m_Cards.GetCallingCard(m_pLoc->GetPreferredCardID());
  384. }
  385. UpdateSampleString(GetDlgItem(hwndParent, IDC_PHONENUMBERSAMPLE), m_pLoc, m_pwszAddress, pCard);
  386. }
  387. m_pLoc->Changed();
  388. SendMessage(GetParent(hwndParent),PSM_CHANGED,(WPARAM)hwndParent,0);
  389. return 1;
  390. }
  391. BOOL CLocationPropSheet::General_OnNotify(HWND hwndDlg, LPNMHDR pnmhdr)
  392. {
  393. // Let the generic handler have a crack at it first
  394. OnNotify(hwndDlg, pnmhdr);
  395. switch (pnmhdr->code)
  396. {
  397. case PSN_APPLY: // user pressed OK or Apply
  398. return General_OnApply(hwndDlg);
  399. case PSN_SETACTIVE:
  400. if (m_pwszAddress)
  401. {
  402. CCallingCard * pCard = NULL;
  403. if (m_pLoc->HasCallingCard())
  404. {
  405. pCard = m_Cards.GetCallingCard(m_pLoc->GetPreferredCardID());
  406. }
  407. UpdateSampleString(GetDlgItem(hwndDlg, IDC_PHONENUMBERSAMPLE), m_pLoc, m_pwszAddress, pCard);
  408. }
  409. break;
  410. default:
  411. break;
  412. }
  413. return FALSE;
  414. }
  415. // General_OnApply
  416. //
  417. // Called when the user selects OK or APPLY on the prop sheet.
  418. // Return PSNRET_INVALID_NOCHANGEPAGE if anything is wrong.
  419. // Return PSNRET_NOERROR if everything is OK.
  420. BOOL CLocationPropSheet::General_OnApply(HWND hwndDlg)
  421. {
  422. PWSTR pwszName;
  423. int iCtl;
  424. int iErr;
  425. // First we do the sanity checks. We return without changing the object if any of these fail.
  426. // * The location must have a name
  427. // * The location must have an area code if it's not a CityRule
  428. // * If "Disable call waiting" is checked, a disable code must have been entered
  429. // * A Country must be selected (it should be impossible for this not to be true, but we check to be safe).
  430. // * The name, as entered, must be unique
  431. pwszName = m_pLoc->GetName();
  432. if ( !*pwszName )
  433. {
  434. iCtl = IDC_LOCATIONNAME;
  435. iErr = IDS_NEEDALOCATIONNAME;
  436. goto ExitWithError;
  437. }
  438. if ( (CITY_MANDATORY==m_iCityRule) && !*(m_pLoc->GetAreaCode()) )
  439. {
  440. iCtl = IDC_AREACODE;
  441. iErr = IDS_NEEDANAREACODE;
  442. goto ExitWithError;
  443. }
  444. if ( (LONG_DISTANCE_CARRIER_MANDATORY == m_iLongDistanceCarrierCodeRule) &&
  445. !*(m_pLoc->GetLongDistanceCarrierCode()) )
  446. {
  447. iCtl = IDC_LONGDISTANCECARRIERCODE;
  448. iErr = IDS_NEEDALONGDISTANCECARRIERCODE;
  449. goto ExitWithError;
  450. }
  451. if ( (INTERNATIONAL_CARRIER_MANDATORY == m_iInternationalCarrierCodeRule) &&
  452. !*(m_pLoc->GetInternationalCarrierCode()) )
  453. {
  454. iCtl = IDC_INTERNATIONALCARRIERCODE;
  455. iErr = IDS_NEEDANINTERNATIONALCARRIERCODE;
  456. goto ExitWithError;
  457. }
  458. if ( m_pLoc->HasCallWaiting() && !*(m_pLoc->GetDisableCallWaitingCode()) )
  459. {
  460. iCtl = IDC_DISABLESTRING;
  461. iErr = IDS_NEEDADISABLESTRING;
  462. goto ExitWithError;
  463. }
  464. if ( !m_dwCountryID )
  465. {
  466. iCtl = IDC_COUNTRY;
  467. iErr = IDS_NEEDACOUNTRY;
  468. goto ExitWithError;
  469. }
  470. // We need to ensure that the name is unique.
  471. CLocation * pLoc;
  472. m_pLocList->Reset();
  473. while (S_OK == m_pLocList->Next(1, &pLoc, NULL))
  474. {
  475. // exclude ourselves from this comparision.
  476. if ( pLoc->GetLocationID() != m_pLoc->GetLocationID() )
  477. {
  478. // see if the names are identical
  479. if ( 0 == StrCmpIW(pLoc->GetName(), pwszName))
  480. {
  481. // yes, the name is in conflict
  482. iCtl = IDC_LOCATIONNAME;
  483. iErr = IDS_NEEDUNIQUENAME;
  484. goto ExitWithError;
  485. }
  486. }
  487. }
  488. // everything is OK
  489. m_bWasApplied = TRUE;
  490. return PSNRET_NOERROR;
  491. ExitWithError:
  492. PropSheet_SetCurSelByID(GetParent(hwndDlg),IDD_LOC_GENERAL);
  493. ShowErrorMessage(GetDlgItem(hwndDlg,iCtl), iErr);
  494. SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT,PSNRET_INVALID_NOCHANGEPAGE);
  495. return TRUE;
  496. }