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.

628 lines
16 KiB

  1. /*++
  2. Copyright (c) 1994-2000, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. sortdlg.c
  5. Abstract:
  6. This module implements the sorting property sheet for the Regional
  7. Options applet.
  8. Revision History:
  9. --*/
  10. //
  11. // Include Files.
  12. //
  13. #include "intl.h"
  14. #include <windowsx.h>
  15. #include <winnls.h>
  16. #include "intlhlp.h"
  17. #include "maxvals.h"
  18. #include "winnlsp.h"
  19. #define STRSAFE_LIB
  20. #include <strsafe.h>
  21. //
  22. // Global Variables.
  23. //
  24. static DWORD g_savLocaleId;
  25. //
  26. // Context Help Ids.
  27. //
  28. static int aSortingHelpIds[] =
  29. {
  30. IDC_SORTING, IDH_INTL_SORT_SORTING,
  31. IDC_SORTING_TEXT1, IDH_INTL_SORT_SORTING,
  32. IDC_SORTING_TEXT2, IDH_INTL_SORT_SORTING,
  33. 0, 0
  34. };
  35. ////////////////////////////////////////////////////////////////////////////
  36. //
  37. // Sorting_UpdateSortingCombo
  38. //
  39. ////////////////////////////////////////////////////////////////////////////
  40. void Sorting_UpdateSortingCombo(
  41. HWND hDlg)
  42. {
  43. HWND hSorting = GetDlgItem(hDlg, IDC_SORTING);
  44. DWORD dwIndex;
  45. TCHAR szBuf[SIZE_128];
  46. LCID LocaleID;
  47. LANGID LangID;
  48. int ctr;
  49. //
  50. // Reset the contents of the combo box.
  51. //
  52. ComboBox_ResetContent(hSorting);
  53. //
  54. // Get the language id from the locale id.
  55. //
  56. LocaleID = UserLocaleID;
  57. LangID = LANGIDFROMLCID(UserLocaleID);
  58. //
  59. // Special case Spanish (Spain) - list International sort first.
  60. //
  61. if (LangID == LANG_SPANISH_TRADITIONAL)
  62. {
  63. LangID = LANG_SPANISH_INTL;
  64. LocaleID = LCID_SPANISH_INTL;
  65. }
  66. //
  67. // Store the sort name for the locale.
  68. //
  69. if (GetLocaleInfo((LCID)LangID, LOCALE_SSORTNAME, szBuf, SIZE_128))
  70. {
  71. //
  72. // Add the new sorting option to the sorting combo box.
  73. //
  74. dwIndex = ComboBox_AddString(hSorting, szBuf);
  75. ComboBox_SetItemData(hSorting, dwIndex, (LCID)LangID);
  76. //
  77. // Set this as the current selection.
  78. //
  79. ComboBox_SetCurSel(hSorting, dwIndex);
  80. }
  81. //
  82. // Special case Spanish (Spain) - list Traditional sort second.
  83. //
  84. if (LangID == LANG_SPANISH_INTL)
  85. {
  86. LangID = LANG_SPANISH_TRADITIONAL;
  87. if (GetLocaleInfo((LCID)LangID, LOCALE_SSORTNAME, szBuf, SIZE_128))
  88. {
  89. //
  90. // Add the new sorting option to the sorting combo box.
  91. //
  92. dwIndex = ComboBox_AddString(hSorting, szBuf);
  93. ComboBox_SetItemData(hSorting, dwIndex, LCID_SPANISH_TRADITIONAL);
  94. //
  95. // Set this as the current selection if it's the current
  96. // locale id.
  97. //
  98. if (UserLocaleID == LCID_SPANISH_TRADITIONAL)
  99. {
  100. ComboBox_SetCurSel(hSorting, dwIndex);
  101. }
  102. }
  103. LangID = LANGIDFROMLCID(UserLocaleID);
  104. }
  105. //
  106. // Fill in the drop down if necessary.
  107. //
  108. for (ctr = 0; ctr < g_NumAltSorts; ctr++)
  109. {
  110. LocaleID = pAltSorts[ctr];
  111. if ((LANGIDFROMLCID(LocaleID) == LangID) &&
  112. (GetLocaleInfo(LocaleID, LOCALE_SSORTNAME, szBuf, SIZE_128)))
  113. {
  114. //
  115. // Add the new sorting option to the sorting combo box.
  116. //
  117. dwIndex = ComboBox_AddString(hSorting, szBuf);
  118. ComboBox_SetItemData(hSorting, dwIndex, LocaleID);
  119. //
  120. // Set this as the current selection if it's the current
  121. // locale id.
  122. //
  123. if (LocaleID == UserLocaleID)
  124. {
  125. ComboBox_SetCurSel(hSorting, dwIndex);
  126. }
  127. }
  128. }
  129. }
  130. ////////////////////////////////////////////////////////////////////////////
  131. //
  132. // Sorting_SaveValues
  133. //
  134. // Save values in case we need to restore them.
  135. //
  136. ////////////////////////////////////////////////////////////////////////////
  137. void Sorting_SaveValues()
  138. {
  139. //
  140. // Save locale values.
  141. //
  142. g_savLocaleId = RegUserLocaleID;
  143. }
  144. ////////////////////////////////////////////////////////////////////////////
  145. //
  146. // Sorting_RestoreValues
  147. //
  148. ////////////////////////////////////////////////////////////////////////////
  149. void Sorting_RestoreValues()
  150. {
  151. if (!(g_dwCustChange & Process_Sorting))
  152. {
  153. return;
  154. }
  155. //
  156. // See if the current selections are different from the original
  157. // selections.
  158. //
  159. if (UserLocaleID != g_savLocaleId)
  160. {
  161. //
  162. // Install the new locale by adding the appropriate information
  163. // to the registry.
  164. //
  165. Intl_InstallUserLocale(g_savLocaleId, FALSE, FALSE);
  166. //
  167. // Update the NLS process cache.
  168. //
  169. NlsResetProcessLocale();
  170. //
  171. // Reset the registry user locale value.
  172. //
  173. UserLocaleID = g_savLocaleId;
  174. RegUserLocaleID = g_savLocaleId;
  175. //
  176. // Need to make sure the proper keyboard layout is installed.
  177. //
  178. Intl_InstallKeyboardLayout(NULL, g_savLocaleId, 0, FALSE, FALSE, FALSE);
  179. //
  180. // Register the regional change every time so that all other property
  181. // pages will be updated due to the locale settings change.
  182. //
  183. Verified_Regional_Chg = INTL_CHG;
  184. }
  185. }
  186. ////////////////////////////////////////////////////////////////////////////
  187. //
  188. // Sorting_ClearValues
  189. //
  190. // Reset each of the list boxes in the sorting property sheet page.
  191. //
  192. ////////////////////////////////////////////////////////////////////////////
  193. void Sorting_ClearValues(
  194. HWND hDlg)
  195. {
  196. ComboBox_ResetContent(GetDlgItem(hDlg, IDC_SORTING));
  197. }
  198. ////////////////////////////////////////////////////////////////////////////
  199. //
  200. // Sorting_SetValues
  201. //
  202. // Initialize all of the controls in the sorting property sheet page.
  203. //
  204. ////////////////////////////////////////////////////////////////////////////
  205. void Sorting_SetValues(
  206. HWND hDlg,
  207. BOOL fInit)
  208. {
  209. DWORD dwIndex;
  210. TCHAR szSorting[SIZE_128];
  211. HWND hSorting = GetDlgItem(hDlg, IDC_SORTING);
  212. //
  213. // Reset the combo box.
  214. //
  215. Sorting_ClearValues(hDlg);
  216. //
  217. // Fill in the appropriate Sorting name for the selected locale.
  218. //
  219. Sorting_UpdateSortingCombo(hDlg);
  220. dwIndex = ComboBox_GetCurSel(hSorting);
  221. if (ComboBox_SetCurSel( hSorting,
  222. ComboBox_FindStringExact( hSorting,
  223. -1,
  224. szSorting ) ) == CB_ERR)
  225. {
  226. ComboBox_SetCurSel(hSorting, dwIndex);
  227. }
  228. //
  229. // Store the sorting state.
  230. //
  231. if (fInit)
  232. {
  233. g_dwCurSorting = ComboBox_GetCurSel(hSorting);
  234. g_dwLastSorting = g_dwCurSorting;
  235. }
  236. else
  237. {
  238. g_dwCurSorting = ComboBox_GetCurSel(hSorting);
  239. }
  240. }
  241. ////////////////////////////////////////////////////////////////////////////
  242. //
  243. // Sorting_ApplySettings
  244. //
  245. // For every control that has changed (that affects the Locale settings),
  246. // call Set_Locale_Values to update the user locale information. Notify
  247. // the parent of changes and reset the change flag stored in the property
  248. // sheet page structure appropriately. Redisplay the time sample if
  249. // bRedisplay is TRUE.
  250. //
  251. ////////////////////////////////////////////////////////////////////////////
  252. BOOL Sorting_ApplySettings(
  253. HWND hDlg)
  254. {
  255. TCHAR szLCID[25];
  256. DWORD dwSorting;
  257. LCID NewLocale, SortLocale;
  258. HCURSOR hcurSave;
  259. HWND hSorting = GetDlgItem(hDlg, IDC_SORTING);
  260. LPPROPSHEETPAGE lpPropSheet = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  261. LPARAM Changes = lpPropSheet->lParam;
  262. //
  263. // See if there are any changes.
  264. //
  265. if (Changes <= SC_EverChg)
  266. {
  267. return (TRUE);
  268. }
  269. //
  270. // Put up the hour glass.
  271. //
  272. hcurSave = SetCursor(LoadCursor(NULL, IDC_WAIT));
  273. //
  274. // See if there are any changes to the user locale.
  275. //
  276. if (Changes & SC_Sorting)
  277. {
  278. //
  279. // Get the current selections.
  280. //
  281. dwSorting = ComboBox_GetCurSel(hSorting);
  282. //
  283. // See if the current selections are different from the original
  284. // selections.
  285. //
  286. if (dwSorting != g_dwCurSorting)
  287. {
  288. //
  289. // Get the locale id with the sort id.
  290. //
  291. NewLocale = UserLocaleID;
  292. SortLocale = (LCID)ComboBox_GetItemData(hSorting, dwSorting);
  293. //
  294. // See if we've got Spanish.
  295. //
  296. if (SortLocale == LCID_SPANISH_TRADITIONAL)
  297. {
  298. NewLocale = LCID_SPANISH_TRADITIONAL;
  299. }
  300. else if (SortLocale == LCID_SPANISH_INTL)
  301. {
  302. NewLocale = LCID_SPANISH_INTL;
  303. }
  304. //
  305. // Make sure the sort locale is okay.
  306. //
  307. if (LANGIDFROMLCID(SortLocale) != LANGIDFROMLCID(NewLocale))
  308. {
  309. SortLocale = NewLocale;
  310. }
  311. //
  312. // Set the current locale values in the pDlgData structure.
  313. //
  314. g_dwCurSorting = dwSorting;
  315. //
  316. // Install the new locale by adding the appropriate information
  317. // to the registry.
  318. //
  319. Intl_InstallUserLocale(SortLocale, FALSE, FALSE);
  320. //
  321. // Update the NLS process cache.
  322. //
  323. NlsResetProcessLocale();
  324. //
  325. // Reset the registry user locale value.
  326. //
  327. UserLocaleID = SortLocale;
  328. RegUserLocaleID = SortLocale;
  329. //
  330. // Need to make sure the proper keyboard layout is installed.
  331. //
  332. Intl_InstallKeyboardLayout(hDlg, SortLocale, 0, FALSE, FALSE, FALSE);
  333. //
  334. // Register the regional change every time so that all other property
  335. // pages will be updated due to the locale settings change.
  336. //
  337. Verified_Regional_Chg = INTL_CHG;
  338. }
  339. }
  340. //
  341. // Reset the property page settings.
  342. //
  343. PropSheet_UnChanged(GetParent(hDlg), hDlg);
  344. Changes = SC_EverChg;
  345. //
  346. // Turn off the hour glass.
  347. //
  348. SetCursor(hcurSave);
  349. //
  350. // Changes made in the second level.
  351. //
  352. if (Changes)
  353. {
  354. g_dwCustChange |= Process_Sorting;
  355. }
  356. //
  357. // Return success.
  358. //
  359. return (TRUE);
  360. }
  361. ////////////////////////////////////////////////////////////////////////////
  362. //
  363. // Sorting_ValidatePPS
  364. //
  365. // Validate each of the combo boxes whose values are constrained.
  366. // If any of the input fails, notify the user and then return FALSE
  367. // to indicate validation failure.
  368. //
  369. ////////////////////////////////////////////////////////////////////////////
  370. BOOL Sorting_ValidatePPS(
  371. HWND hDlg,
  372. LPARAM Changes)
  373. {
  374. //
  375. // Return success.
  376. //
  377. return (TRUE);
  378. }
  379. ////////////////////////////////////////////////////////////////////////////
  380. //
  381. // Sorting_InitPropSheet
  382. //
  383. // The extra long value for the property sheet page is used as a set of
  384. // state or change flags for each of the list boxes in the property sheet.
  385. // Initialize this value to 0. Call Sorting_SetValues with the property
  386. // sheet handle to initialize all of the property sheet controls. Limit
  387. // the length of the text in some of the ComboBoxes.
  388. //
  389. ////////////////////////////////////////////////////////////////////////////
  390. void Sorting_InitPropSheet(
  391. HWND hDlg,
  392. LPARAM lParam)
  393. {
  394. //
  395. // The lParam holds a pointer to the property sheet page. Save it
  396. // for later reference.
  397. //
  398. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  399. //
  400. // Load the information into the dialog.
  401. //
  402. Sorting_SetValues(hDlg, TRUE);
  403. }
  404. ////////////////////////////////////////////////////////////////////////////
  405. //
  406. // SortingDlgProc
  407. //
  408. ////////////////////////////////////////////////////////////////////////////
  409. INT_PTR CALLBACK SortingDlgProc(
  410. HWND hDlg,
  411. UINT message,
  412. WPARAM wParam,
  413. LPARAM lParam)
  414. {
  415. NMHDR *lpnm;
  416. LPPROPSHEETPAGE lpPropSheet = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  417. switch (message)
  418. {
  419. case ( WM_NOTIFY ) :
  420. {
  421. lpnm = (NMHDR *)lParam;
  422. switch (lpnm->code)
  423. {
  424. case ( PSN_SETACTIVE ) :
  425. {
  426. //
  427. // If there has been a change in the regional Locale
  428. // setting, clear all of the current info in the
  429. // property sheet, get the new values, and update the
  430. // appropriate registry values.
  431. //
  432. if (Verified_Regional_Chg & Process_Sorting)
  433. {
  434. Verified_Regional_Chg &= ~Process_Sorting;
  435. Sorting_ClearValues(hDlg);
  436. Sorting_SetValues(hDlg, FALSE);
  437. lpPropSheet->lParam = 0;
  438. }
  439. break;
  440. }
  441. case ( PSN_KILLACTIVE ) :
  442. {
  443. //
  444. // Validate the entries on the property page.
  445. //
  446. SetWindowLongPtr( hDlg,
  447. DWLP_MSGRESULT,
  448. !Sorting_ValidatePPS( hDlg, lpPropSheet->lParam ) );
  449. break;
  450. }
  451. case ( PSN_APPLY ) :
  452. {
  453. //
  454. // Apply the settings.
  455. //
  456. if (Sorting_ApplySettings(hDlg))
  457. {
  458. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  459. //
  460. // Zero out the TC_EverChg bit.
  461. //
  462. lpPropSheet->lParam = 0;
  463. }
  464. else
  465. {
  466. SetWindowLongPtr( hDlg,
  467. DWLP_MSGRESULT,
  468. PSNRET_INVALID_NOCHANGEPAGE );
  469. }
  470. break;
  471. }
  472. default :
  473. {
  474. return (FALSE);
  475. }
  476. }
  477. break;
  478. }
  479. case ( WM_INITDIALOG ) :
  480. {
  481. Sorting_InitPropSheet(hDlg, lParam);
  482. Sorting_SaveValues();
  483. break;
  484. }
  485. case ( WM_DESTROY ) :
  486. {
  487. break;
  488. }
  489. case ( WM_HELP ) :
  490. {
  491. WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
  492. szHelpFile,
  493. HELP_WM_HELP,
  494. (DWORD_PTR)(LPTSTR)aSortingHelpIds );
  495. break;
  496. }
  497. case ( WM_CONTEXTMENU ) : // right mouse click
  498. {
  499. WinHelp( (HWND)wParam,
  500. szHelpFile,
  501. HELP_CONTEXTMENU,
  502. (DWORD_PTR)(LPTSTR)aSortingHelpIds );
  503. break;
  504. }
  505. case ( WM_COMMAND ) :
  506. {
  507. switch (LOWORD(wParam))
  508. {
  509. case ( IDC_SORTING ) :
  510. {
  511. //
  512. // See if it's a selection change.
  513. //
  514. if (HIWORD(wParam) == CBN_SELCHANGE)
  515. {
  516. lpPropSheet->lParam |= SC_Sorting;
  517. }
  518. break;
  519. }
  520. }
  521. //
  522. // Turn on ApplyNow button.
  523. //
  524. if (lpPropSheet->lParam > SC_EverChg)
  525. {
  526. PropSheet_Changed(GetParent(hDlg), hDlg);
  527. }
  528. break;
  529. }
  530. default :
  531. {
  532. return (FALSE);
  533. }
  534. }
  535. //
  536. // Return success.
  537. //
  538. return (TRUE);
  539. }