ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

advanced.c
Go to the documentation of this file.
00001 #include "intl.h"
00002 
00003 typedef struct CPStruct
00004 {
00005     WORD    Status;
00006     UINT    CPage;
00007     HANDLE  hCPage;
00008     TCHAR   Name[MAX_PATH];
00009     struct  CPStruct *NextItem;
00010 } CPAGE, *LPCPAGE;
00011 
00012 static LPCPAGE PCPage = NULL;
00013 static HINF hIntlInf;
00014 static BOOL bSpain = FALSE;
00015 static HWND hLangList;
00016 
00017 static BOOL
00018 GetSupportedCP(VOID)
00019 {
00020     UINT uiCPage, Number;
00021     LONG Count;
00022     INFCONTEXT infCont;
00023     LPCPAGE lpCPage;
00024     HANDLE hCPage;
00025     CPINFOEX cpInfEx;
00026     //TCHAR Section[MAX_PATH];
00027 
00028     Count = SetupGetLineCount(hIntlInf, _T("CodePages"));
00029     if (Count <= 0) return FALSE;
00030 
00031     for (Number = 0; Number < (UINT)Count; Number++)
00032     {
00033         if (SetupGetLineByIndex(hIntlInf, _T("CodePages"), Number, &infCont) &&
00034             SetupGetIntField(&infCont, 0, (PINT)&uiCPage))
00035         {
00036             if (!(hCPage = GlobalAlloc(GHND, sizeof(CPAGE)))) return FALSE;
00037 
00038             lpCPage            = GlobalLock(hCPage);
00039             lpCPage->CPage     = uiCPage;
00040             lpCPage->hCPage    = hCPage;
00041             lpCPage->Status    = 0;
00042             (lpCPage->Name)[0] = 0;
00043 
00044             if (GetCPInfoEx(uiCPage, 0, &cpInfEx))
00045             {
00046                 _tcscpy(lpCPage->Name, cpInfEx.CodePageName);
00047             }
00048             else if (!SetupGetStringField(&infCont, 1, lpCPage->Name, MAX_PATH, NULL))
00049             {
00050                 GlobalUnlock(hCPage);
00051                 GlobalFree(hCPage);
00052                 continue;
00053             }
00054 
00055             lpCPage->NextItem = PCPage;
00056             PCPage = lpCPage;
00057         }
00058     }
00059 
00060     return TRUE;
00061 }
00062 
00063 static BOOL CALLBACK
00064 InstalledCPProc(LPTSTR lpStr)
00065 {
00066     LPCPAGE lpCP;
00067     UINT uiCP;
00068 
00069     lpCP = PCPage;
00070     uiCP = _ttol(lpStr);
00071 
00072     for (;;)
00073     {
00074         if (!lpCP) break;
00075         if (lpCP->CPage == uiCP)
00076         {
00077             lpCP->Status |= 0x0001;
00078             break;
00079         }
00080         lpCP = lpCP->NextItem;
00081     }
00082 
00083     return TRUE;
00084 }
00085 
00086 static VOID
00087 InitCodePagesList(HWND hwndDlg)
00088 {
00089     LPCPAGE lpCPage;
00090     INT ItemIndex;
00091     HWND hList;
00092     LV_COLUMN column;
00093     LV_ITEM item;
00094     RECT ListRect;
00095 
00096     hList = GetDlgItem(hwndDlg, IDC_CONV_TABLES);
00097 
00098     hIntlInf = SetupOpenInfFile(_T("intl.inf"), NULL, INF_STYLE_WIN4, NULL);
00099 
00100     if (hIntlInf == INVALID_HANDLE_VALUE)
00101         return;
00102 
00103     if (!SetupOpenAppendInfFile(NULL, hIntlInf, NULL))
00104     {
00105         SetupCloseInfFile(hIntlInf);
00106         hIntlInf = NULL;
00107         return;
00108     }
00109 
00110     if (!GetSupportedCP())
00111         return;
00112 
00113     SetupCloseInfFile(hIntlInf);
00114 
00115     if (!EnumSystemCodePages(InstalledCPProc, CP_INSTALLED))
00116         return;
00117 
00118     ZeroMemory(&column, sizeof(LV_COLUMN));
00119     column.mask = LVCF_FMT|LVCF_TEXT|LVCF_WIDTH;
00120     column.fmt  = LVCFMT_LEFT;
00121     GetClientRect(hList, &ListRect);
00122     column.cx   = ListRect.right - GetSystemMetrics(SM_CYHSCROLL);
00123     (VOID) ListView_InsertColumn(hList, 0, &column);
00124 
00125     (VOID) ListView_SetExtendedListViewStyle(hList, LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT);
00126 
00127     lpCPage = PCPage;
00128 
00129     for (;;)
00130     {
00131         if (!lpCPage) break;
00132         ZeroMemory(&item, sizeof(LV_ITEM));
00133         item.mask      = LVIF_TEXT|LVIF_PARAM|LVIF_STATE;
00134         item.state     = 0;
00135         item.stateMask = LVIS_STATEIMAGEMASK;
00136         item.pszText   = lpCPage->Name;
00137         item.lParam    = (LPARAM)lpCPage;
00138 
00139         ItemIndex = ListView_InsertItem(hList, &item);
00140 
00141         if (ItemIndex >= 0)
00142         {
00143             if (lpCPage->Status & 0x0001)
00144             {
00145                 ListView_SetItemState(hList, ItemIndex,
00146                                       INDEXTOSTATEIMAGEMASK(LVIS_SELECTED),
00147                                       LVIS_STATEIMAGEMASK);
00148             }
00149             else
00150             {
00151                 ListView_SetItemState(hList, ItemIndex,
00152                                       INDEXTOSTATEIMAGEMASK(LVIS_FOCUSED),
00153                                       LVIS_STATEIMAGEMASK);
00154             }
00155         }
00156 
00157         lpCPage = lpCPage->NextItem;
00158     }
00159 }
00160 
00161 static BOOL CALLBACK
00162 LocalesEnumProc(LPTSTR lpLocale)
00163 {
00164     LCID lcid;
00165     TCHAR lang[255];
00166     INT index;
00167     BOOL bNoShow = FALSE;
00168 
00169     lcid = _tcstoul(lpLocale, NULL, 16);
00170 
00171     if (lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT) ||
00172         lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT))
00173     {
00174         if (bSpain == FALSE)
00175         {
00176             LoadString(hApplet, IDS_SPAIN, lang, 255);
00177             bSpain = TRUE;
00178         }
00179         else
00180         {
00181             bNoShow = TRUE;
00182         }
00183     }
00184     else
00185     {
00186         GetLocaleInfo(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(TCHAR));
00187     }
00188 
00189     if (bNoShow == FALSE)
00190     {
00191     index = SendMessage(hLangList,
00192                         CB_ADDSTRING,
00193                         0,
00194                         (LPARAM)lang);
00195 
00196     SendMessage(hLangList,
00197                 CB_SETITEMDATA,
00198                 index,
00199                 (LPARAM)lcid);
00200     }
00201 
00202     return TRUE;
00203 }
00204 
00205 static VOID
00206 InitLanguagesList(HWND hwndDlg)
00207 {
00208     TCHAR langSel[255];
00209 
00210     hLangList = GetDlgItem(hwndDlg, IDC_LANGUAGE_COMBO);
00211 
00212     bSpain = FALSE;
00213     EnumSystemLocales(LocalesEnumProc, LCID_SUPPORTED);
00214 
00215     /* Select current locale */
00216     GetLocaleInfo(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, sizeof(langSel)/sizeof(TCHAR));
00217 
00218     SendMessage(hLangList, CB_SELECTSTRING, -1, (LPARAM)langSel);
00219 }
00220 
00221 static VOID
00222 GetCurrentDPI(LPTSTR szDPI)
00223 {
00224     DWORD dwType, dwSize, dwDPI, dwDefDPI = 0x00000060; // Default 96 DPI
00225     HKEY hKey;
00226 
00227     if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontDPI"), 0, NULL,
00228                        REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) != ERROR_SUCCESS)
00229     {
00230         _tcscpy(szDPI, _T("96"));
00231         return;
00232     }
00233 
00234     dwType = REG_DWORD;
00235     dwSize = sizeof(DWORD);
00236 
00237     if (RegQueryValueEx(hKey, _T("LogPixels"), NULL, &dwType, (LPBYTE)&dwDPI, &dwSize) != ERROR_SUCCESS)
00238     {
00239         if (RegSetValueEx(hKey, _T("LogPixels"), 0, REG_DWORD, (LPBYTE)&dwDefDPI, sizeof(DWORD)) == ERROR_SUCCESS)
00240         {
00241             _tcscpy(szDPI, _T("96"));
00242             RegCloseKey(hKey);
00243             return;
00244         }
00245     }
00246     else wsprintf(szDPI, _T("%d"), dwDPI);
00247 
00248     RegCloseKey(hKey);
00249 }
00250 
00251 VOID
00252 SetNonUnicodeLang(HWND hwnd, LCID lcid)
00253 {
00254     TCHAR szDefCP[5 + 1], szSection[MAX_PATH], szDPI[3 + 1];
00255     HINF hFontInf;
00256     UINT Count;
00257 
00258     GetLocaleInfo(MAKELCID(lcid, SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, szDefCP, sizeof(szDefCP) / sizeof(TCHAR));
00259     GetCurrentDPI(szDPI);
00260 
00261     wsprintf(szSection, _T("Font.CP%s.%s"), szDefCP, szDPI);
00262 
00263     hFontInf = SetupOpenInfFile(_T("font.inf"), NULL, INF_STYLE_WIN4, NULL);
00264 
00265     if (hFontInf == INVALID_HANDLE_VALUE)
00266         return;
00267 
00268     if (!SetupOpenAppendInfFile(NULL, hFontInf, NULL))
00269     {
00270         SetupCloseInfFile(hFontInf);
00271         return;
00272     }
00273 
00274     Count = (UINT) SetupGetLineCount(hFontInf, szSection);
00275     if (Count <= 0) return;
00276 
00277     if (!SetupInstallFromInfSection(hwnd, hFontInf, szSection, SPINST_REGISTRY & ~SPINST_FILES,
00278                                     NULL, NULL, 0, NULL, NULL, NULL, NULL))
00279         MessageBox(hwnd, _T("Unable to install a new language for programs don't support unicode!"),
00280                    NULL, MB_ICONERROR | MB_OK);
00281 
00282     SetupCloseInfFile(hFontInf);
00283 }
00284 
00285 /* Property page dialog callback */
00286 INT_PTR CALLBACK
00287 AdvancedPageProc(HWND hwndDlg,
00288                  UINT uMsg,
00289                  WPARAM wParam,
00290                  LPARAM lParam)
00291 {
00292     switch(uMsg)
00293     {
00294         case WM_INITDIALOG:
00295         {
00296             InitLanguagesList(hwndDlg);
00297             InitCodePagesList(hwndDlg);
00298         }
00299         break;
00300 
00301         case WM_COMMAND:
00302         {
00303             switch (LOWORD(wParam))
00304             {
00305                 case IDC_LANGUAGE_COMBO:
00306                 {
00307                     if (HIWORD(wParam) == CBN_SELCHANGE)
00308                         PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00309                 }
00310                 break;
00311             }
00312         }
00313         break;
00314 
00315         case WM_NOTIFY:
00316         {
00317             LPNMHDR lpnm = (LPNMHDR)lParam;
00318 
00319             if (lpnm->code == (UINT)PSN_APPLY)
00320             {
00321                 LCID lcid;
00322                 INT iIndex;
00323 
00324                 PropSheet_UnChanged(GetParent(hwndDlg), hwndDlg);
00325 
00326                 iIndex = SendMessage(hLangList, CB_GETCURSEL, 0, 0);
00327                 if (iIndex == CB_ERR)
00328                     break;
00329 
00330                 lcid = SendMessage(hLangList, CB_GETITEMDATA, iIndex, 0);
00331                 if (lcid == (LCID)CB_ERR)
00332                     break;
00333 
00334                 SetNonUnicodeLang(hwndDlg, lcid);
00335             }
00336         }
00337         break;
00338     }
00339 
00340     return FALSE;
00341 }
00342 
00343 /* EOF */

Generated on Sun May 27 2012 04:20:57 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.