Merge 14551:14980 from trunk
[reactos.git] / reactos / lib / cpl / intl / locale.c
index a37b9ea..46118ea 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ReactOS
- *  Copyright (C) 2004 ReactOS Team
+ *  Copyright (C) 2004, 2005 ReactOS Team
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  * FILE:            lib/cpl/intl/locale.c
  * PURPOSE:         Locale property page
  * PROGRAMMER:      Eric Kohl
+ *                  Klemens Friedl
+ *                  Aleksey Bragin
  */
 
+#define WINVER 0x0501
+
 #include <windows.h>
 #include <commctrl.h>
 #include <cpl.h>
 
+#include <stdio.h>
+
 #include "intl.h"
 #include "resource.h"
 
+HWND hList;
+
+BOOL CALLBACK LocalesEnumProc(
+  LPTSTR lpLocale // locale id
+)
+{
+       LCID lcid;
+       TCHAR lang[255];
+       int index;
+
+       //swscanf(lpLocale, L"%lx", &lcid); // maybe use wcstoul?
+       lcid = wcstoul(lpLocale, NULL, 16);
+
+       GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang));
+
+    index = SendMessageW(hList,
+                  CB_ADDSTRING,
+                  0,
+                  (LPARAM)lang);
+
+       SendMessageW(hList,
+                  CB_SETITEMDATA,
+                  index,
+                  (LPARAM)lcid);
+
+       return TRUE;
+}
+
+
+static VOID
+CreateLanguagesList(HWND hwnd)
+{
+       TCHAR langSel[255];
+
+       hList = hwnd;
+       EnumSystemLocalesW(LocalesEnumProc, LCID_SUPPORTED);
+
+       // Select current locale
+       GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)); // or should it be System and not user?
+       
+       SendMessageW(hList,
+                  CB_SELECTSTRING,
+                  -1,
+                  (LPARAM)langSel);
+}
+
+/*
+static VOID
+ShowLanguagesList(HWND hwnd)
+{
+  TIME_ZONE_INFORMATION TimeZoneInfo;
+  PTIMEZONE_ENTRY Entry;
+  DWORD dwIndex;
+  DWORD i;
+
+  GetTimeZoneInformation(&TimeZoneInfo);
+
+  dwIndex = 0;
+  i = 0;
+  Entry = TimeZoneListHead;
+  while (Entry != NULL)
+    {
+      SendMessageW(hwnd,
+                  CB_ADDSTRING,
+                  0,
+                  (LPARAM)Entry->Description);
+
+      if (!wcscmp(Entry->StandardName, TimeZoneInfo.StandardName))
+       dwIndex = i;
+
+      i++;
+      Entry = Entry->Next;
+    }
+
+  SendMessageW(hwnd,
+              CB_SETCURSEL,
+              (WPARAM)dwIndex,
+              0);
+}
+*/
 
 /* Property page dialog callback */
 INT_PTR CALLBACK
@@ -39,12 +125,60 @@ LocalePageProc(HWND hwndDlg,
               WPARAM wParam,
               LPARAM lParam)
 {
-  switch(uMsg)
-  {
-    case WM_INITDIALOG:
-      break;
-  }
-  return FALSE;
+       switch(uMsg)
+       {
+       case WM_INITDIALOG:
+               CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST));
+               break;
+       case WM_COMMAND:
+               switch (LOWORD(wParam))
+               {
+               case IDC_LANGUAGELIST:
+                       if (HIWORD(wParam) == CBN_SELCHANGE)
+                       {
+                               PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+                       }
+                       break;
+               }
+               break;
+
+       case WM_NOTIFY:
+               {
+                       LPNMHDR lpnm = (LPNMHDR)lParam;
+                       if (lpnm->code == PSN_APPLY)
+                       {
+                               // Apply changes
+                               LCID NewLcid;
+                               int iCurSel;
+                               char tmp[100];
+
+                               // Acquire new value
+                               iCurSel = SendMessageW(hList,
+                                       CB_GETCURSEL,
+                                       0,
+                                       0);
+                               if (iCurSel == CB_ERR)
+                                       break;
+
+                               NewLcid = SendMessageW(hList,
+                                       CB_GETITEMDATA,
+                                       iCurSel,
+                                       0);
+
+                               if (NewLcid == CB_ERR)
+                                       break;
+
+
+                               //TOOD: Actually set new locale
+
+                               sprintf(tmp, "%lx, cursel=%d", NewLcid, iCurSel);
+                               MessageBoxA(hwndDlg, tmp, "debug", MB_OK);
+                       }
+               }
+               break;
+       }
+       return FALSE;
 }
 
+
 /* EOF */