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.

514 lines
15 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // lang.c
  8. //
  9. // Description:
  10. // This file contains the dialog procedure for language settings page.
  11. // (IDD_LANGUAGE_SETTINGS)
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. #define MAX_SELECTIONS 20
  17. //
  18. // This variable determines whether the user just moved here from another
  19. // page or has remained on this page
  20. //
  21. static bHasMovedOffThisPage = TRUE;
  22. //----------------------------------------------------------------------------
  23. //
  24. // Function: GetLangGroupFromLocale
  25. //
  26. // Purpose: Takes a locale string Id and finds the language group node that
  27. // corresponds to that locale.
  28. //
  29. // Arguments: IN LPTSTR lpLocaleId- the locale Id to find the language
  30. // group of
  31. //
  32. // Returns: LANGUAGEGROUP_NODE* - language group node the locale corresponds to
  33. //
  34. //----------------------------------------------------------------------------
  35. LANGUAGEGROUP_NODE*
  36. GetLangGroupFromLocale( IN LPTSTR lpLocaleId ) {
  37. LANGUAGELOCALE_NODE *CurrentLocale;
  38. //
  39. // Sweep through the local list until the locale is found and return
  40. // the language group
  41. //
  42. for( CurrentLocale = FixedGlobals.LanguageLocaleList;
  43. CurrentLocale != NULL;
  44. CurrentLocale = CurrentLocale->next )
  45. {
  46. if( lstrcmp( lpLocaleId, CurrentLocale->szLanguageLocaleId ) == 0 )
  47. {
  48. return( CurrentLocale->pLanguageGroup );
  49. }
  50. }
  51. //
  52. // If we get to here, then the locale was not found
  53. //
  54. AssertMsg( FALSE, "The locale was not found." );
  55. //
  56. // return the first language group so there is at least something to return
  57. //
  58. return( FixedGlobals.LanguageLocaleList->pLanguageGroup );
  59. }
  60. //----------------------------------------------------------------------------
  61. //
  62. // Function: GetLangGroupFromKeyboardLayout
  63. //
  64. // Purpose: Takes a keyboard layout string Id and finds the language group
  65. // node that corresponds to that keyboard layout.
  66. //
  67. // Arguments: IN LPTSTR lpKeyboardLayoutId- the keyboard layout Id to find
  68. // the language group of
  69. //
  70. // Returns: LANGUAGEGROUP_NODE* - language group node the keyboard layout
  71. // corresponds to
  72. //
  73. //----------------------------------------------------------------------------
  74. LANGUAGEGROUP_NODE*
  75. GetLangGroupFromKeyboardLayout( IN LPTSTR lpKeyboardLayoutId )
  76. {
  77. return( GetLangGroupFromLocale( lpKeyboardLayoutId ) );
  78. }
  79. //----------------------------------------------------------------------------
  80. //
  81. // Function: AddLocalesLangGroup
  82. //
  83. // Purpose: Takes the a locale and finds its corresponding language group
  84. // and adds it to the language group list.
  85. //
  86. // Arguments: IN LPTSTR pLocale - the locale to find and add the language
  87. // group of
  88. //
  89. // Returns: VOID
  90. //
  91. //----------------------------------------------------------------------------
  92. VOID
  93. AddLocalesLangGroup( IN LPTSTR pLocale ) {
  94. LANGUAGEGROUP_NODE *pLangGroup;
  95. pLangGroup = GetLangGroupFromLocale( pLocale );
  96. AddNameToNameListNoDuplicates( &GenSettings.LanguageGroups,
  97. pLangGroup->szLanguageGroupId );
  98. AddNameToNameListNoDuplicates( &GenSettings.LanguageFilePaths,
  99. pLangGroup->szLangFilePath );
  100. }
  101. //----------------------------------------------------------------------------
  102. //
  103. // Function: AddKeyboardLocaleLangGroup
  104. //
  105. // Purpose: Takes the a keyboard layoutand finds its corresponding language
  106. // group and adds it to the language group list.
  107. //
  108. // Arguments: IN LPTSTR pLocale - the locale to find and add the language
  109. // group of
  110. //
  111. // Returns: VOID
  112. //
  113. //----------------------------------------------------------------------------
  114. VOID
  115. AddKeyboardLocaleLangGroup( IN LPTSTR pKeyboardLocale )
  116. {
  117. LANGUAGEGROUP_NODE *pLangGroup;
  118. pLangGroup = GetLangGroupFromKeyboardLayout( pKeyboardLocale );
  119. AddNameToNameListNoDuplicates( &GenSettings.LanguageGroups,
  120. pLangGroup->szLanguageGroupId );
  121. AddNameToNameListNoDuplicates( &GenSettings.LanguageFilePaths,
  122. pLangGroup->szLangFilePath );
  123. }
  124. //----------------------------------------------------------------------------
  125. //
  126. // Function: OnLanguageSettingsInitDialog
  127. //
  128. // Purpose: Fills the Language Group box with the languages.
  129. //
  130. // Arguments: IN HWND hwnd - handle to the dialog box
  131. //
  132. // Returns: VOID
  133. //
  134. //----------------------------------------------------------------------------
  135. VOID
  136. OnLanguageSettingsInitDialog( IN HWND hwnd ) {
  137. INT_PTR iListBoxIndex;
  138. LANGUAGEGROUP_NODE *pLangEntry;
  139. //
  140. // Fill the list box with the data from the Language Group list
  141. //
  142. for( pLangEntry = FixedGlobals.LanguageGroupList;
  143. pLangEntry != NULL;
  144. pLangEntry = pLangEntry->next ) {
  145. //
  146. // Add language group to the list box
  147. //
  148. iListBoxIndex = SendDlgItemMessage( hwnd,
  149. IDC_LANGUAGES,
  150. LB_ADDSTRING,
  151. 0,
  152. (LPARAM) pLangEntry->szLanguageGroupName );
  153. //
  154. // Associate the Language Group struct with its entry in the list box
  155. //
  156. SendDlgItemMessage( hwnd,
  157. IDC_LANGUAGES,
  158. LB_SETITEMDATA,
  159. iListBoxIndex,
  160. (LPARAM) pLangEntry );
  161. }
  162. }
  163. //----------------------------------------------------------------------------
  164. //
  165. // Function: OnLanguageSettingsSetActive
  166. //
  167. // Purpose: If they just moved here from another page, it makes sure for the
  168. // locales they have selected that there corresponding language
  169. // groups are selected.
  170. //
  171. // Arguments: IN HWND hwnd - handle to the dialog box
  172. //
  173. // Returns: VOID
  174. //
  175. //----------------------------------------------------------------------------
  176. VOID
  177. OnLanguageSettingsSetActive( IN HWND hwnd ) {
  178. INT i;
  179. INT_PTR iListBoxCount;
  180. BOOL bIsAnAdditionLangGroup;
  181. BOOL bIsAnUserChosenLangGroup;
  182. LANGUAGEGROUP_NODE *pLangEntry;
  183. //
  184. // The variable AdditionalLangGroups holds those language groups that need
  185. // to be installed because the user has already picked a locale that needs
  186. // it. We need to force those Language groups to automatically be
  187. // installed so we auto-select them.
  188. //
  189. NAMELIST AdditionalLangGroups = { 0 };
  190. //
  191. // Make sure language groups are selected for the locals they chose on the
  192. // regional settings page but only do this if they moved from another page
  193. // onto this page. If this is just another SetActive message but they
  194. // haven't left the page then do nothing.
  195. //
  196. if( bHasMovedOffThisPage )
  197. {
  198. bHasMovedOffThisPage = FALSE;
  199. //
  200. // Find out what language groups we have to install
  201. //
  202. if( GenSettings.iRegionalSettings == REGIONAL_SETTINGS_SPECIFY )
  203. {
  204. if( GenSettings.bUseCustomLocales )
  205. {
  206. pLangEntry = GetLangGroupFromLocale( GenSettings.szMenuLanguage );
  207. AddNameToNameListNoDuplicates( &AdditionalLangGroups,
  208. pLangEntry->szLanguageGroupId );
  209. pLangEntry = GetLangGroupFromLocale( GenSettings.szNumberLanguage );
  210. AddNameToNameListNoDuplicates( &AdditionalLangGroups,
  211. pLangEntry->szLanguageGroupId );
  212. pLangEntry = GetLangGroupFromKeyboardLayout( GenSettings.szLanguageLocaleId );
  213. AddNameToNameListNoDuplicates( &AdditionalLangGroups,
  214. pLangEntry->szLanguageGroupId );
  215. }
  216. else
  217. {
  218. pLangEntry = GetLangGroupFromLocale( GenSettings.szLanguage );
  219. AddNameToNameListNoDuplicates( &AdditionalLangGroups,
  220. pLangEntry->szLanguageGroupId );
  221. }
  222. }
  223. //
  224. // Select the language groups in the AdditionalLangGroups list
  225. //
  226. iListBoxCount = SendDlgItemMessage( hwnd,
  227. IDC_LANGUAGES,
  228. LB_GETCOUNT,
  229. 0,
  230. 0 );
  231. for( i = 0; i < iListBoxCount; i++ )
  232. {
  233. pLangEntry = (LANGUAGEGROUP_NODE *) SendDlgItemMessage( hwnd,
  234. IDC_LANGUAGES,
  235. LB_GETITEMDATA,
  236. i,
  237. 0 );
  238. if( FindNameInNameList( &GenSettings.LanguageGroups,
  239. pLangEntry->szLanguageGroupId ) != -1 )
  240. {
  241. bIsAnUserChosenLangGroup = TRUE;
  242. }
  243. else
  244. {
  245. bIsAnUserChosenLangGroup = FALSE;
  246. }
  247. if( FindNameInNameList( &AdditionalLangGroups,
  248. pLangEntry->szLanguageGroupId ) != -1 )
  249. {
  250. bIsAnAdditionLangGroup = TRUE;
  251. }
  252. else {
  253. bIsAnAdditionLangGroup = FALSE;
  254. }
  255. if( bIsAnUserChosenLangGroup || bIsAnAdditionLangGroup )
  256. {
  257. SendDlgItemMessage( hwnd,
  258. IDC_LANGUAGES,
  259. LB_SETSEL,
  260. TRUE,
  261. i );
  262. }
  263. }
  264. }
  265. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  266. }
  267. //----------------------------------------------------------------------------
  268. //
  269. // Function: OnWizNextLanguageSettings
  270. //
  271. // Purpose: Stores the language groups that are selected. Also, stores the
  272. // the language groups that are not selected but are needed by one
  273. // of the locales they chose.
  274. //
  275. // Arguments: IN HWND hwnd - handle to the dialog box
  276. //
  277. // Returns: VOID
  278. //
  279. //----------------------------------------------------------------------------
  280. VOID
  281. OnWizNextLanguageSettings( IN HWND hwnd ) {
  282. INT_PTR i;
  283. INT_PTR iNumberSelected;
  284. UINT rgiCurrentSelections[MAX_SELECTIONS];
  285. LANGUAGEGROUP_NODE *pLangGroupEntry;
  286. // ISSUE-2002/02/28-stelo- going to have to force whatever locale choices they made on the
  287. // previous page for the those language groups to automatically get
  288. // installed
  289. iNumberSelected = SendDlgItemMessage( hwnd,
  290. IDC_LANGUAGES,
  291. LB_GETSELITEMS,
  292. MAX_SELECTIONS,
  293. (LPARAM) rgiCurrentSelections );
  294. ResetNameList( &GenSettings.LanguageGroups );
  295. ResetNameList( &GenSettings.LanguageFilePaths );
  296. if( WizGlobals.iProductInstall == PRODUCT_SYSPREP ) {
  297. //
  298. // Set this to true so we know to write out the key to specify the path
  299. // to the language files
  300. //
  301. GenSettings.bSysprepLangFilesCopied = TRUE;
  302. }
  303. for( i = 0; i < iNumberSelected; i++ ) {
  304. pLangGroupEntry = (LANGUAGEGROUP_NODE *) SendDlgItemMessage( hwnd,
  305. IDC_LANGUAGES,
  306. LB_GETITEMDATA,
  307. rgiCurrentSelections[i],
  308. 0 );
  309. //
  310. // store the language group ID in the namelist
  311. //
  312. AddNameToNameList( &GenSettings.LanguageGroups,
  313. pLangGroupEntry->szLanguageGroupId );
  314. //
  315. // store the path to the language files
  316. //
  317. AddNameToNameList( &GenSettings.LanguageFilePaths,
  318. pLangGroupEntry->szLangFilePath );
  319. }
  320. //
  321. // Force whatever language groups to be installed that are needed for the
  322. // locales they chose
  323. //
  324. if( GenSettings.iRegionalSettings == REGIONAL_SETTINGS_SPECIFY ) {
  325. if( GenSettings.bUseCustomLocales ) {
  326. AddLocalesLangGroup( GenSettings.szMenuLanguage );
  327. AddLocalesLangGroup( GenSettings.szNumberLanguage );
  328. AddKeyboardLocaleLangGroup( GenSettings.szLanguageLocaleId );
  329. }
  330. else {
  331. AddLocalesLangGroup( GenSettings.szLanguage );
  332. }
  333. }
  334. }
  335. //----------------------------------------------------------------------------
  336. //
  337. // Function: DlgLangSettingsPage
  338. //
  339. // Purpose: Dialog procedure for the Language Settings page
  340. //
  341. // Arguments: standard Win32 dialog proc arguments
  342. //
  343. // Returns: standard Win32 dialog proc return value -- whether the message
  344. // was handled or not
  345. //
  346. //----------------------------------------------------------------------------
  347. INT_PTR CALLBACK
  348. DlgLangSettingsPage( IN HWND hwnd,
  349. IN UINT uMsg,
  350. IN WPARAM wParam,
  351. IN LPARAM lParam ) {
  352. BOOL bStatus = TRUE;
  353. switch( uMsg ) {
  354. case WM_INITDIALOG:
  355. {
  356. OnLanguageSettingsInitDialog( hwnd );
  357. break;
  358. }
  359. case WM_NOTIFY:
  360. {
  361. LPNMHDR pnmh = (LPNMHDR)lParam;
  362. switch( pnmh->code )
  363. {
  364. case PSN_QUERYCANCEL:
  365. WIZ_CANCEL(hwnd);
  366. break;
  367. case PSN_SETACTIVE:
  368. {
  369. g_App.dwCurrentHelp = IDH_LANGS;
  370. OnLanguageSettingsSetActive( hwnd );
  371. break;
  372. }
  373. case PSN_WIZBACK:
  374. bHasMovedOffThisPage = TRUE;
  375. bStatus = FALSE;
  376. break;
  377. case PSN_WIZNEXT:
  378. {
  379. OnWizNextLanguageSettings( hwnd );
  380. bStatus = FALSE;
  381. break;
  382. }
  383. case PSN_HELP:
  384. WIZ_HELP();
  385. break;
  386. default:
  387. break;
  388. }
  389. break;
  390. }
  391. default:
  392. bStatus = FALSE;
  393. break;
  394. }
  395. return( bStatus );
  396. }