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.

379 lines
15 KiB

  1. /****************************************************************************
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name: cplsimplelocation.cpp
  4. Author: toddb - 10/06/98
  5. ****************************************************************************/
  6. //
  7. // The dialog proc for the SimpleLocation page. This is used as a page
  8. // inside the Modem wizard (in modemui.dll) and as a dialog from tapi
  9. // when there are no locations.
  10. //
  11. #include "cplPreComp.h"
  12. #include "cplResource.h"
  13. HRESULT CreateCountryObject(DWORD dwCountryID, CCountry **ppCountry);
  14. int IsCityRule(LPWSTR lpRule);
  15. int IsCityRule(DWORD dwCountryID)
  16. {
  17. CCountry * pCountry;
  18. HRESULT hr;
  19. hr = CreateCountryObject(dwCountryID, &pCountry);
  20. if ( SUCCEEDED(hr) )
  21. {
  22. int ret = IsCityRule(pCountry->GetLongDistanceRule());
  23. delete pCountry;
  24. return ret;
  25. }
  26. // in the error case we return optional as a compromise that works
  27. // for any possible case (though no optimally).
  28. LOG((TL_ERROR, "IsCityRule(DWORD dwCountryID) failed to create country %d", dwCountryID ));
  29. return CITY_OPTIONAL;
  30. }
  31. //***************************************************************************
  32. extern "C"
  33. INT_PTR
  34. CALLBACK
  35. LocWizardDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  36. {
  37. static DWORD dwVersion;
  38. switch (uMsg)
  39. {
  40. case WM_INITDIALOG:
  41. {
  42. HWND hwnd;
  43. // we either pass in zero or the TAPI version as the lParam.
  44. dwVersion = (DWORD)lParam;
  45. DWORD dwDefaultCountryID = GetProfileInt(TEXT("intl"), TEXT("iCountry"), 1);
  46. hwnd = GetDlgItem(hwndDlg, IDC_COUNTRY);
  47. PopulateCountryList(hwnd, dwDefaultCountryID);
  48. CCountry * pCountry;
  49. HRESULT hr;
  50. int iCityRule;
  51. int iLongDistanceCarrierCodeRule;
  52. int iInternationalCarrierCodeRule;
  53. hr = CreateCountryObject(dwDefaultCountryID, &pCountry);
  54. if ( SUCCEEDED(hr) )
  55. {
  56. iCityRule = IsCityRule( pCountry->GetLongDistanceRule() );
  57. iLongDistanceCarrierCodeRule = IsLongDistanceCarrierCodeRule( pCountry->GetLongDistanceRule() );
  58. iInternationalCarrierCodeRule = IsInternationalCarrierCodeRule( pCountry->GetInternationalRule() );
  59. delete pCountry;
  60. } else
  61. {
  62. LOG((TL_ERROR, "LocWizardDlgProc failed to create country %d", dwDefaultCountryID));
  63. iCityRule = CITY_OPTIONAL;
  64. iLongDistanceCarrierCodeRule = LONG_DISTANCE_CARRIER_OPTIONAL;
  65. iInternationalCarrierCodeRule = INTERNATIONAL_CARRIER_OPTIONAL;
  66. }
  67. hwnd = GetDlgItem(hwndDlg,IDC_AREACODE);
  68. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  69. LimitInput(hwnd, LIF_ALLOWNUMBER);
  70. if ( iCityRule == CITY_NONE )
  71. {
  72. SetWindowText(hwnd, TEXT(""));
  73. EnableWindow(hwnd, FALSE);
  74. }
  75. hwnd = GetDlgItem(hwndDlg,IDC_CARRIERCODE);
  76. SendMessage(hwnd,EM_SETLIMITTEXT,CPL_SETTEXTLIMIT,0);
  77. LimitInput(hwnd, LIF_ALLOWNUMBER);
  78. if ( (LONG_DISTANCE_CARRIER_NONE == iLongDistanceCarrierCodeRule) &&
  79. (INTERNATIONAL_CARRIER_NONE == iInternationalCarrierCodeRule) )
  80. {
  81. SetWindowText(hwnd, TEXT(""));
  82. EnableWindow(GetDlgItem(hwndDlg, IDC_STATICCC), FALSE);
  83. EnableWindow(hwnd, FALSE);
  84. }
  85. hwnd = GetDlgItem(hwndDlg,IDC_LOCALACCESSNUM);
  86. SendMessage(hwnd, EM_SETLIMITTEXT, CPL_SETTEXTLIMIT, 0);
  87. LimitInput(hwnd, LIF_ALLOWNUMBER|LIF_ALLOWPOUND|LIF_ALLOWSTAR|LIF_ALLOWCOMMA);
  88. BOOL bUseToneDialing = TRUE;
  89. CheckRadioButton(hwndDlg,IDC_TONE,IDC_PULSE,bUseToneDialing?IDC_TONE:IDC_PULSE);
  90. SetForegroundWindow (hwndDlg);
  91. return TRUE; // auto set focus
  92. }
  93. case WM_NOTIFY:
  94. // If we are controlling the property page then we will recieve WM_NOTIFY
  95. // messages from it.
  96. switch (((LPNMHDR)lParam)->code)
  97. {
  98. case PSN_WIZFINISH:
  99. case PSN_KILLACTIVE:
  100. // This dialog is shown in different places depending on if this is a legacy modem install
  101. // or a PNP modem install. In the PNP case, the dialog shows on a single page wizard that
  102. // has a "finsih" button, in the legacy case it shows in the middle of a series of pages and
  103. // has a "next" button. We get different notify messages based on which case we are in, but
  104. // luckly both of those notifies can be handled with the same code (ie they use the same
  105. // return codes to mean "don't leave this page yet"). This is why we treat both PSN_WIZFINISH
  106. // and PSN_KILLACTIVE in the same mannor.
  107. wParam = IDOK;
  108. break;
  109. case PSN_SETACTIVE:
  110. return TRUE;
  111. default:
  112. return FALSE;
  113. }
  114. // fall through. This causes WM_NOTIFY:PSN_KILLACTIVE to be treated exactly
  115. // the same as WM_COMMAND:IDOK.
  116. case WM_COMMAND:
  117. // we get lots of WM_COMMAND messages, but the only one we care about is the
  118. // "OK" button that dismisses us in dialog mode
  119. switch ( LOWORD(wParam) )
  120. {
  121. case IDOK:
  122. {
  123. HWND hwnd;
  124. TCHAR szBuffer[128];
  125. WCHAR wszAreaCode[32];
  126. WCHAR wszCarrierCode[32];
  127. DWORD dwCountryID;
  128. // verify all the input
  129. hwnd = GetDlgItem( hwndDlg, IDC_COUNTRY );
  130. LRESULT lr = SendMessage( hwnd, CB_GETCURSEL, 0, 0 );
  131. dwCountryID = (DWORD)SendMessage( hwnd, CB_GETITEMDATA, lr, 0 );
  132. if ( CB_ERR == dwCountryID )
  133. {
  134. // No country is selected
  135. ShowErrorMessage(hwnd, IDS_NEEDACOUNTRY);
  136. // if we are a wizard page, prevent swicthing pages
  137. if ( uMsg == WM_NOTIFY )
  138. {
  139. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
  140. }
  141. return TRUE;
  142. }
  143. CCountry * pCountry;
  144. HRESULT hr;
  145. int iCityRule;
  146. int iLongDistanceCarrierCodeRule;
  147. int iInternationalCarrierCodeRule;
  148. hr = CreateCountryObject(dwCountryID, &pCountry);
  149. if ( SUCCEEDED(hr) )
  150. {
  151. iCityRule = IsCityRule(pCountry->GetLongDistanceRule());
  152. iLongDistanceCarrierCodeRule = IsLongDistanceCarrierCodeRule( pCountry->GetLongDistanceRule() );
  153. iInternationalCarrierCodeRule = IsInternationalCarrierCodeRule( pCountry->GetInternationalRule() );
  154. delete pCountry;
  155. } else {
  156. LOG((TL_ERROR, "LocWizardDlgProc failed to create country %d", dwCountryID));
  157. iCityRule = CITY_OPTIONAL;
  158. iLongDistanceCarrierCodeRule = LONG_DISTANCE_CARRIER_OPTIONAL;
  159. iInternationalCarrierCodeRule = INTERNATIONAL_CARRIER_OPTIONAL;
  160. }
  161. hwnd = GetDlgItem(hwndDlg, IDC_AREACODE);
  162. GetWindowText( hwnd, szBuffer, ARRAYSIZE(szBuffer) );
  163. SHTCharToUnicode( szBuffer, wszAreaCode, ARRAYSIZE(wszAreaCode) );
  164. // if the selected country requires an area code && no area code is given
  165. if ( (CITY_MANDATORY==iCityRule) && !*wszAreaCode )
  166. {
  167. // complain that the area code is missing.
  168. ShowErrorMessage(hwnd, IDS_NEEDANAREACODE);
  169. // if we are a wizard page, prevent swicthing pages
  170. if ( uMsg == WM_NOTIFY )
  171. {
  172. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
  173. }
  174. return TRUE;
  175. }
  176. hwnd = GetDlgItem(hwndDlg, IDC_CARRIERCODE);
  177. GetWindowText( hwnd, szBuffer, ARRAYSIZE(szBuffer) );
  178. SHTCharToUnicode( szBuffer, wszCarrierCode, ARRAYSIZE(wszCarrierCode) );
  179. // if the selected country requires a carrier code && no carrier code is given
  180. if ( ((LONG_DISTANCE_CARRIER_MANDATORY == iLongDistanceCarrierCodeRule) ||
  181. (INTERNATIONAL_CARRIER_MANDATORY == iInternationalCarrierCodeRule)) &&
  182. !*wszCarrierCode )
  183. {
  184. // complain that the carrier code is missing.
  185. ShowErrorMessage(hwnd, IDS_NEEDACARRIERCODE);
  186. // if we are a wizard page, prevent swicthing pages
  187. if ( uMsg == WM_NOTIFY )
  188. {
  189. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
  190. }
  191. return TRUE;
  192. }
  193. // if we get here then the input is all valid
  194. WCHAR wszLocationName[128];
  195. WCHAR wszAccessCode[32];
  196. BOOL bUseTone;
  197. LoadString( GetUIInstance(), IDS_MYLOCATION, szBuffer, ARRAYSIZE(szBuffer) );
  198. SHTCharToUnicode( szBuffer, wszLocationName, ARRAYSIZE(wszLocationName) );
  199. hwnd = GetDlgItem(hwndDlg, IDC_LOCALACCESSNUM);
  200. GetWindowText( hwnd, szBuffer, ARRAYSIZE(szBuffer) );
  201. SHTCharToUnicode( szBuffer, wszAccessCode, ARRAYSIZE(wszAccessCode) );
  202. hwnd = GetDlgItem( hwndDlg, IDC_TONE );
  203. bUseTone = (BST_CHECKED == SendMessage(hwnd, BM_GETCHECK, 0,0));
  204. // Create a location.
  205. CLocation location;
  206. // Initialize it with the values from the dialog
  207. location.Initialize(
  208. wszLocationName,
  209. wszAreaCode,
  210. iLongDistanceCarrierCodeRule?wszCarrierCode:L"",
  211. iInternationalCarrierCodeRule?wszCarrierCode:L"",
  212. wszAccessCode,
  213. wszAccessCode,
  214. L"",
  215. 0,
  216. dwCountryID,
  217. 0,
  218. bUseTone?LOCATION_USETONEDIALING:0 );
  219. location.NewID();
  220. // Write it to the registry
  221. location.WriteToRegistry();
  222. if ( uMsg == WM_COMMAND )
  223. {
  224. EndDialog(hwndDlg, IDOK);
  225. }
  226. }
  227. break;
  228. case IDCANCEL:
  229. // Do a version check, if the version is < 2.2 then we
  230. // need to provide a strong warning message about legacy apps
  231. // not working correctly without this information. Only upon
  232. // a confirmation from the user will we then end the dialog.
  233. if ( dwVersion < TAPI_VERSION2_2 )
  234. {
  235. int ret;
  236. TCHAR szText[1024];
  237. TCHAR szCaption[128];
  238. LoadString( GetUIInstance(), IDS_NOLOCWARNING, szText, ARRAYSIZE(szText) );
  239. LoadString( GetUIInstance(), IDS_NOLOCCAPTION, szCaption, ARRAYSIZE(szCaption) );
  240. ret = MessageBox(hwndDlg, szText, szCaption, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 );
  241. if ( IDYES != ret )
  242. {
  243. return TRUE;
  244. }
  245. }
  246. EndDialog(hwndDlg, IDCANCEL);
  247. break;
  248. case IDC_COUNTRY:
  249. if ( CBN_SELCHANGE == HIWORD(wParam) )
  250. {
  251. HWND hwnd;
  252. DWORD dwCountryID;
  253. int iCityRule;
  254. hwnd = GetDlgItem( hwndDlg, IDC_COUNTRY );
  255. LRESULT lr = SendMessage( hwnd, CB_GETCURSEL, 0, 0 );
  256. dwCountryID = (DWORD)SendMessage( hwnd, CB_GETITEMDATA, lr, 0 );
  257. CCountry * pCountry;
  258. HRESULT hr;
  259. int iLongDistanceCarrierCodeRule;
  260. int iInternationalCarrierCodeRule;
  261. hr = CreateCountryObject(dwCountryID, &pCountry);
  262. if ( SUCCEEDED(hr) )
  263. {
  264. iCityRule = IsCityRule( pCountry->GetLongDistanceRule() );
  265. iLongDistanceCarrierCodeRule = IsLongDistanceCarrierCodeRule( pCountry->GetLongDistanceRule() );
  266. iInternationalCarrierCodeRule = IsInternationalCarrierCodeRule( pCountry->GetInternationalRule() );
  267. delete pCountry;
  268. } else
  269. {
  270. LOG((TL_ERROR, "LocWizardDlgProc failed to create country %d", dwCountryID));
  271. iCityRule = CITY_OPTIONAL;
  272. iLongDistanceCarrierCodeRule = LONG_DISTANCE_CARRIER_OPTIONAL;
  273. iInternationalCarrierCodeRule = INTERNATIONAL_CARRIER_OPTIONAL;
  274. }
  275. hwnd = GetDlgItem(hwndDlg,IDC_AREACODE);
  276. if ( iCityRule == CITY_NONE )
  277. {
  278. SetWindowText(hwnd, TEXT(""));
  279. EnableWindow(hwnd, FALSE);
  280. }
  281. else
  282. {
  283. EnableWindow(hwnd, TRUE);
  284. }
  285. hwnd = GetDlgItem(hwndDlg, IDC_CARRIERCODE);
  286. if ( (LONG_DISTANCE_CARRIER_NONE == iLongDistanceCarrierCodeRule) &&
  287. (INTERNATIONAL_CARRIER_NONE == iInternationalCarrierCodeRule) )
  288. {
  289. SetWindowText(hwnd, TEXT(""));
  290. EnableWindow(hwnd, FALSE);
  291. EnableWindow(GetDlgItem(hwndDlg, IDC_STATICCC), FALSE);
  292. }
  293. else
  294. {
  295. EnableWindow(hwnd, TRUE);
  296. EnableWindow(GetDlgItem(hwndDlg, IDC_STATICCC), TRUE);
  297. }
  298. }
  299. break;
  300. }
  301. break;
  302. case WM_HELP:
  303. // Process clicks on controls after Context Help mode selected
  304. TapiCplWinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (DWORD_PTR)(LPTSTR) a115HelpIDs);
  305. break;
  306. case WM_CONTEXTMENU:
  307. // Process right-clicks on controls
  308. TapiCplWinHelp ((HWND) wParam, gszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)(LPVOID) a115HelpIDs);
  309. break;
  310. default:
  311. // message is not handled, return FALSE.
  312. return FALSE;
  313. }
  314. // message was handled. return TRUE.
  315. return TRUE;
  316. }