int __cdecl main(int argc, char *argv[]) { LCID lcid; if (PAL_Initialize(argc, argv)) { return FAIL; } lcid = GetUserDefaultLCID(); if (lcid == 0) { Fail("GetUserDefaultLCID failed!\n"); } if (!IsValidLocale(lcid, LCID_INSTALLED)) { Fail("GetUserDefaultLCID gave an invalid locale!\n"); } /* Make sure results consistent with using LOCALE_USER_DEFAULT */ if (!SetThreadLocale(LOCALE_USER_DEFAULT)) { Fail("Unexpected error testing GetUserDefaultLCID!\n"); } if (GetThreadLocale() != lcid) { Fail("Results from GetUserDefaultLCID inconsistent with " "LOCALE_USER_DEFAULT!\n"); } PAL_Terminate(); return PASS; }
static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) { /* locale string */ if (!(pack->flags & LPF_NOLOCALE)) { TCHAR szLocaleName[128]; szLocaleName[0] = _T('\0'); /* can't use LOCALE_SNAME as it is not present on pre WinVista */ if (!GetLocaleInfo(pack->Locale, LOCALE_SISO639LANGNAME, szLocaleName, SIZEOF(szLocaleName))) { /* Win98/NT4+ */ if (!GetLocaleInfo(pack->Locale, LOCALE_SLANGUAGE, szLocaleName, SIZEOF(szLocaleName))) /* not unique! */ szLocaleName[0] = _T('\0'); } else { if (GetLocaleInfo(pack->Locale, LOCALE_SISO3166CTRYNAME, &szLocaleName[3], SIZEOF(szLocaleName) - 3)) /* Win98/NT4+ */ szLocaleName[2] = _T('-'); } /* add some note if its incompatible */ if (szLocaleName[0]) { if (!IsValidLocale(pack->Locale, LCID_INSTALLED)) { TCHAR *pszIncompat; pszIncompat = TranslateT("(incompatible)"); szLocaleName[SIZEOF(szLocaleName) - lstrlen(pszIncompat) - 1] = 0; lstrcat(lstrcat(szLocaleName, _T(" ")), pszIncompat); /* buffer safe */ } SetDlgItemText(hwndDlg, IDC_LANGLOCALE, szLocaleName); } else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown")); } else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Current")); /* file date */ SYSTEMTIME stFileDate; TCHAR szDate[128]; szDate[0] = _T('\0'); if (FileTimeToSystemTime(&pack->ftFileDate, &stFileDate)) GetDateFormat((LCID)CallService(MS_LANGPACK_GETLOCALE, 0, 0), DATE_SHORTDATE, &stFileDate, NULL, szDate, SIZEOF(szDate)); SetDlgItemText(hwndDlg, IDC_LANGDATE, szDate); /* version */ SetDlgItemTextA(hwndDlg, IDC_LANGVERSION, pack->szVersion); if (pack->szVersion[0] && pack->szFLName[0]) { if (!IsWindowVisible(GetDlgItem(hwndDlg, IDC_LANGVERSIONLABEL))) { ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSIONLABEL), SW_SHOW); ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSION), SW_SHOW); } } else { ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSIONLABEL), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDC_LANGVERSION), SW_HIDE); } /* general */ SetDlgItemTextA(hwndDlg, IDC_LANGMODUSING, pack->szLastModifiedUsing); SetDlgItemTextA(hwndDlg, IDC_LANGAUTHORS, pack->szAuthors); SetDlgItemTextA(hwndDlg, IDC_LANGEMAIL, pack->szAuthorEmail); SetDlgItemText(hwndDlg, IDC_LANGINFOFRAME, TranslateTS(pack->szLanguage)); }
static inline bool useRTL_Extensions(QSysInfo::WinVersion ver) { // This is SDK dependent on CE so out of scope for now if (QSysInfo::windowsVersion() & QSysInfo::WV_CE_based) return false; if ((ver & QSysInfo::WV_NT_based) && (ver >= QSysInfo::WV_VISTA)) { // Since the IsValidLanguageGroup/IsValidLocale functions always return true on // Vista, check the Keyboard Layouts for enabling RTL. if (const UINT nLayouts = GetKeyboardLayoutList(0, 0)) { QScopedArrayPointer<HKL> lpList(new HKL[nLayouts]); GetKeyboardLayoutList(nLayouts, lpList.data()); for (UINT i = 0; i < nLayouts; ++i) { switch (PRIMARYLANGID((quintptr)lpList[i])) { case LANG_ARABIC: case LANG_HEBREW: case LANG_FARSI: case LANG_SYRIAC: return true; default: break; } } } return false; } // NT/Vista #ifndef Q_OS_WINCE // Pre-NT: figure out whether a RTL language is installed return IsValidLanguageGroup(LGRPID_ARABIC, LGRPID_INSTALLED) || IsValidLanguageGroup(LGRPID_HEBREW, LGRPID_INSTALLED) || IsValidLocale(MAKELCID(MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED) || IsValidLocale(MAKELCID(MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED) || IsValidLocale(MAKELCID(MAKELANGID(LANG_SYRIAC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED) || IsValidLocale(MAKELCID(MAKELANGID(LANG_FARSI, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED); #else return false; #endif }
int __cdecl main(int argc, char *argv[]) { LCID lcid; if (PAL_Initialize(argc, argv)) { return FAIL; } /* * Passing LOCALE_USER_DEFAULT to IsValidLocale will fail, so instead * the current thread localed is changed to it, and that lcid is passed * to IsValidLocale (which should always pass) */ if (!SetThreadLocale(LOCALE_USER_DEFAULT)) { Fail("Unable to set locale to LOCALE_USER_DEFAULT!\n"); } lcid = GetThreadLocale(); if (!IsValidLocale(lcid, LCID_SUPPORTED)) { Fail("IsValidLocale found the default user locale unsupported!\n"); } if (!IsValidLocale(lcid, LCID_INSTALLED)) { Fail("IsValidLocale found the default user locale uninstalled!\n"); } /* * Test out bad parameters */ if (IsValidLocale(-1, LCID_SUPPORTED)) { Fail("IsValideLocale passed with an invalid LCID!\n"); } if (IsValidLocale(-1, LCID_INSTALLED)) { Fail("IsValideLocale passed with an invalid LCID!\n"); } if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_SUPPORTED)) { Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); } if (IsValidLocale(LOCALE_USER_DEFAULT, LCID_INSTALLED)) { Fail("IsValidLocale passed with LOCALE_USER_DEFAULT!\n"); } PAL_Terminate(); return PASS; }
static BOOL CALLBACK LocalesEnumProc(LPTSTR lpLocale) { LCID lcid; WCHAR lang[255]; INT index; BOOL bNoShow = FALSE; lcid = wcstoul(lpLocale, NULL, 16); /* Display only languages with installed support */ if (!IsValidLocale(lcid, LCID_INSTALLED)) return TRUE; if (lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT) || lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT)) { if (bSpain == FALSE) { LoadStringW(hInstance, IDS_SPAIN, lang, 255); bSpain = TRUE; } else { bNoShow = TRUE; } } else { GetLocaleInfoW(lcid, LOCALE_SLANGUAGE, lang, sizeof(lang)/sizeof(WCHAR)); } if (bNoShow == FALSE) { index = SendMessageW(hList, CB_ADDSTRING, 0, (LPARAM)lang); SendMessageW(hList, CB_SETITEMDATA, index, (LPARAM)lcid); } return TRUE; }
int __cdecl main(int argc, char *argv[]) { LCID lcid; LANGID LangID; if (PAL_Initialize(argc, argv)) { return FAIL; } LangID = GetSystemDefaultLangID(); if (LangID == 0) { Fail("GetSystemDefaultLangID failed!\n"); } /* Try using the langid (with default sort) as a locale */ if (!SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT))) { Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); } lcid = GetThreadLocale(); if (!IsValidLocale(lcid, LCID_INSTALLED)) { Fail("Unable to use GetSystemDefaultLangID as a locale!\n"); } /* Make sure results consistent with using LOCALE_USER_DEFAULT */ if (!SetThreadLocale(LOCALE_USER_DEFAULT)) { Fail("Unexpected error testing GetSystemDefaultLangID!\n"); } if (GetThreadLocale() != lcid) { Fail("Results from GetSystemDefaultLangID inconsistent with " "LOCALE_USER_DEFAULT!\n"); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { LCID lcid; if (PAL_Initialize(argc, argv)) { return FAIL; } lcid = GetThreadLocale(); if (!IsValidLocale(lcid, LCID_INSTALLED)) { Fail("GetThreadLocale returned a locale that is not installed!\n"); } PAL_Terminate(); return PASS; }
static void DisplayPackInfo(HWND hwndDlg, const LANGPACK_INFO *pack) { /* locale string */ if (!(pack->flags & LPF_NOLOCALE)) { TCHAR szLocaleName[256], szLanguageName[128], szContryName[128]; if (!GetLocaleInfo(pack->Locale, WINVER >= _WIN32_WINNT_WIN7 ? LOCALE_SENGLISHLANGUAGENAME : LOCALE_SENGLANGUAGE, szLanguageName, _countof(szLanguageName))) szLanguageName[0] = _T('\0'); if (!GetLocaleInfo(pack->Locale, WINVER >= _WIN32_WINNT_WIN7 ? LOCALE_SENGLISHCOUNTRYNAME : LOCALE_SENGCOUNTRY, szContryName, _countof(szContryName))) szContryName[0] = _T('\0'); /* add some note if its incompatible */ if (szLanguageName[0] && szContryName[0]) { mir_sntprintf(szLocaleName, _T("%s (%s)"), TranslateTS(szLanguageName), TranslateTS(szContryName)); if (!IsValidLocale(pack->Locale, LCID_INSTALLED)) { TCHAR *pszIncompat; pszIncompat = TranslateT("(incompatible)"); szLocaleName[_countof(szLocaleName) - mir_tstrlen(pszIncompat) - 1] = 0; mir_tstrcat(mir_tstrcat(szLocaleName, _T(" ")), pszIncompat); } SetDlgItemText(hwndDlg, IDC_LANGLOCALE, szLocaleName); } else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown")); } else SetDlgItemText(hwndDlg, IDC_LANGLOCALE, TranslateT("Unknown")); /* file date */ SYSTEMTIME stFileDate; TCHAR szDate[128]; szDate[0] = 0; if (FileTimeToSystemTime(&pack->ftFileDate, &stFileDate)) GetDateFormat(Langpack_GetDefaultLocale(), DATE_SHORTDATE, &stFileDate, NULL, szDate, _countof(szDate)); SetDlgItemText(hwndDlg, IDC_LANGDATE, szDate); /* general */ SetDlgItemText_CP(hwndDlg, IDC_LANGMODUSING, pack->szLastModifiedUsing); SetDlgItemText_CP(hwndDlg, IDC_LANGAUTHORS, pack->szAuthors); SetDlgItemText_CP(hwndDlg, IDC_LANGEMAIL, pack->szAuthorEmail); SetDlgItemText(hwndDlg, IDC_LANGINFOFRAME, TranslateTS(pack->tszLanguage)); }
LPSTR _setLocaleFromString(LPWIN32LOCALE _locale, LPCSTR LocaleName) { char* p = (LPSTR) LocaleName; char token[256]; char locale[256]; int tokenp; SHORT Category = 0; _lock_locale(); memset(token, 0, sizeof(token)); tokenp = 0; while (*p) { if (*p == '=') { if (strcmp(token, "LC_CTYPE") == 0) Category |= LC_CTYPE; if (strcmp(token, "LC_TIME") == 0) Category |= LC_TIME; if (strcmp(token, "LC_NUMERIC") == 0) Category |= LC_NUMERIC; if (strcmp(token, "LC_MONETARY") == 0) Category |= LC_MONETARY; if (strcmp(token, "LC_COLLATE") == 0) Category |= LC_COLLATE; memset(token, 0, sizeof(token)); tokenp = 0; } else if (*p == '\n') { strcpy(locale, token); memset(token, 0, sizeof(token)); tokenp = 0; } else token[tokenp++] = *p; p++; } _locale->handle = _getLocale(_locale, locale); if (!IsValidLocale(_locale->handle, LCID_INSTALLED) && !_locale->isCLocale) { SetLastError(ERROR_LOCALE_NOTINSTALLED); _unlock_locale(); return NULL; } /* SetThreadLocale will only work for NT but it's better to do it in case the application uses OLE2 or some other functionnality requiring a Locale. */ SetThreadLocale(__locale->handle); _cleanCategories(__locale); if (_setNewCategories(__locale, Category) == 0) { SetLastError(ERROR_CATEGORY_INVALID); _unlock_locale(); return NULL; } _unlock_locale(); return __locale->setLocaleReturn; }
LPSTR _setLocale32A(SHORT Category, LPCSTR localeName) { char codepage[7]; BOOL restoreC = FALSE; char* LocaleName = NULL; LCID Handle = 0; char* p; CPINFO cpinfo; if (localeName) LocaleName = strdup(localeName); _lock_locale(); if (__locale == NULL || __locale == &CLOCALE) { if (__locale == &CLOCALE) restoreC = TRUE; if ((__locale = (LPWIN32LOCALE) calloc(1, sizeof(WIN32LOCALE))) == NULL) { SetLastError(ERROR_OUTOFMEMORY); free(LocaleName); _unlock_locale(); return NULL; } } if (__locale->setLocaleReturn != NULL) { free(__locale->setLocaleReturn); __locale->setLocaleReturn = NULL; } if (LocaleName == NULL || LocaleName[0] == 0x0) { if (LocaleName == NULL) { if (restoreC) { _cleanCategories(__locale); free(__locale); __locale = &CLOCALE; } else { if ((Category & LC_MONETARY) == LC_MONETARY) _addCategoryName(__locale, "LC_MONETARY"); if ((Category & LC_NUMERIC) == LC_NUMERIC) _addCategoryName(__locale, "LC_NUMERIC"); if ((Category & LC_TIME) == LC_TIME) _addCategoryName(__locale, "LC_TIME"); if ((Category & LC_COLLATE) == LC_COLLATE) _addCategoryName(__locale, "LC_COLLATE"); if ((Category & LC_CTYPE) == LC_CTYPE) _addCategoryName(__locale, "LC_CTYPE"); free(LocaleName); _llocaleconv(); _unlock_locale(); return __locale->setLocaleReturn; } } else { Handle = GetUserDefaultLCID(); GetLocaleInfoA(Handle, LOCALE_IDEFAULTCODEPAGE, codepage, 7); __locale->codepage = atol(codepage); __locale->isCLocale = FALSE; } } else { if (strstr(localeName, "en_US")) { strcpy(LocaleName, "ENU"); if ((p = strchr(localeName, '.')) != NULL) strcpy(&LocaleName[3], p); } else if (strstr(localeName, "en_GB")) { strcpy(LocaleName, "ENG"); if ((p = strchr(localeName, '.')) != NULL) strcpy(&LocaleName[3], p); } else if (strstr(localeName, "fr_FR")) { strcpy(LocaleName, "FRA"); if ((p = strchr(localeName, '.')) != NULL) strcpy(&LocaleName[3], p); } else if (strstr(localeName, "de_DE")) { strcpy(LocaleName, "DEU"); if ((p = strchr(localeName, '.')) != NULL) strcpy(&LocaleName[3], p); } if (strcmp(localeName, "C") == 0) { _cleanCategories(__locale); free(__locale); __locale = &CLOCALE; } else if (LocaleName[0] == 'L' && LocaleName[1] == 'C' && LocaleName[2] == '_') { free(LocaleName); _unlock_locale(); return _setLocaleFromString(__locale, localeName); } else { __locale->isCLocale = FALSE; if ((Handle = _getLocale(__locale, (LPSTR)LocaleName)) == 0) { if (restoreC) { free(__locale); __locale = &CLOCALE; } _unlock_locale(); free(LocaleName); return NULL; } } } __locale->handle = Handle; free(LocaleName); if (!IsValidLocale(__locale->handle, LCID_INSTALLED) && !__locale->isCLocale) { SetLastError(ERROR_LOCALE_NOTINSTALLED); if (restoreC) { _cleanCategories(__locale); free(__locale); __locale = &CLOCALE; } _unlock_locale(); return NULL; } /* SetThreadLocale will only work under NT but it's best to do it in case the application uses OLE2 or some other functionnality requiring a Locale. */ SetThreadLocale(__locale->handle); if (!__locale->isCLocale) { _cleanCategories(__locale); if (_setNewCategories(__locale, Category) == 0) { SetLastError(ERROR_CATEGORY_INVALID); if (restoreC) { _cleanCategories(__locale); free(__locale); __locale = &CLOCALE; } _unlock_locale(); return NULL; } if (_setmbcp(__locale->codepage) != 0 || !GetCPInfo(__locale->codepage, &cpinfo)) { _unlock_locale(); SetLastError(ERROR_MBCS_CODEPAGE_INVALID); return NULL; } __mb_cur_max = cpinfo.MaxCharSize; _llocaleconv(); _unlock_locale(); return __locale->setLocaleReturn; } else { __mb_cur_max = 1; _llocaleconv(); _unlock_locale(); return __locale->setLocaleReturn; } }
/*** *BOOL __get_qualified_locale - return fully qualified locale * *Purpose: * get default locale, qualify partially complete locales * *Entry: * lpInStr - input strings to be qualified * lpOutId - pointer to numeric LCIDs and codepage output * lpOutStr - pointer to string LCIDs and codepage output * *Exit: * TRUE if success, qualified locale is valid * FALSE if failure * *Exceptions: * *******************************************************************************/ BOOL __cdecl __get_qualified_locale(const LPLC_STRINGS lpInStr, LPLC_ID lpOutId, LPLC_STRINGS lpOutStr) { int iCodePage; // initialize pointer to call locale info routine based on operating system if (!pfnGetLocaleInfoA) { pfnGetLocaleInfoA = IsThisWindowsNT() ? GetLocaleInfoA : crtGetLocaleInfoA; } if (!lpInStr) { // if no input defined, just use default LCID GetLcidFromDefault(); } else { // convert non-NLS language strings to three-letter abbreviations pchLanguage = lpInStr->szLanguage; if (pchLanguage && *pchLanguage) TranslateName(__rg_language, sizeof(__rg_language) / sizeof(LOCALETAB) - 1, &pchLanguage); // convert non-NLS country strings to three-letter abbreviations pchCountry = lpInStr->szCountry; if (pchCountry && *pchCountry) TranslateName(__rg_country, sizeof(__rg_country) / sizeof(LOCALETAB) - 1, &pchCountry); iLcidState = 0; if (pchLanguage && *pchLanguage) { if (pchCountry && *pchCountry) { // both language and country strings defined GetLcidFromLangCountry(); } else { // language string defined, but country string undefined GetLcidFromLanguage(); } } else { if (pchCountry && *pchCountry) { // country string defined, but language string undefined GetLcidFromCountry(); } else { // both language and country strings undefined GetLcidFromDefault(); } } } // test for error in LCID processing if (!iLcidState) return FALSE; // process codepage value iCodePage = ProcessCodePage(lpInStr->szCodePage); // verify codepage validity if (!iCodePage || !IsValidCodePage((WORD)iCodePage)) return FALSE; // verify locale is installed if (!IsValidLocale(lcidLanguage, LCID_INSTALLED)) return FALSE; // set numeric LCID and codepage results if (lpOutId) { lpOutId->wLanguage = LANGIDFROMLCID(lcidLanguage); lpOutId->wCountry = LANGIDFROMLCID(lcidCountry); lpOutId->wCodePage = (WORD)iCodePage; } // set string language, country, and codepage results if (lpOutStr) { if ((*pfnGetLocaleInfoA)(lcidLanguage, LOCALE_SENGLANGUAGE, lpOutStr->szLanguage, MAX_LANG_LEN) == 0) return FALSE; if ((*pfnGetLocaleInfoA)(lcidCountry, LOCALE_SENGCOUNTRY, lpOutStr->szCountry, MAX_CTRY_LEN) == 0) return FALSE; _itoa((int)iCodePage, (char *)lpOutStr->szCodePage, 10); } return TRUE; }
/*** *BOOL __get_qualified_locale - return fully qualified locale * *Purpose: * get default locale, qualify partially complete locales * *Entry: * dwType - indicates type of lpInput, either QF_STRINGS or QF_LCID * lpInput - input string/id to be qualified * lpOutId - pointer to output id, may be NULL if lpOutStr is !NULL * lpOutStr - pointer to output string, may be NULL if lpOutId is !NULL * *Exit: * TRUE if success, qualified locale is valid * FALSE if failure * *Exceptions: * *******************************************************************************/ BOOL __cdecl __get_qualified_locale( const LPLC_STRINGS lpInStr, LPLC_ID lpOutId, LPLC_STRINGS lpOutStr ) { LC_ID Id; LCID cpLCID; BOOL fOCP = FALSE; WCHAR wcsTemp[MAX_TEMP_STR_LEN]; if (!lpOutId && !lpOutStr) return FALSE; Id.wLanguage = (WORD)0; Id.wCountry = (WORD)0; Id.wCodePage = (WORD)0; /* ----------------------------------------------------------------------- stage 1: convert input to internal LC_ID. -----------------------------------------------------------------------*/ if (lpInStr->szLanguage && *(lpInStr->szLanguage) && (!(Id.wLanguage = trans_lang_lang((const PSZ)lpInStr->szLanguage)))) return FALSE; if (lpInStr->szCountry && *(lpInStr->szCountry) && (!(Id.wCountry = trans_ctry_ctry((const PSZ)lpInStr->szCountry)))) return FALSE; if (lpInStr->szCodePage && *(lpInStr->szCodePage)) { /* ACP is the default anyway */ if (!strcmp(lpInStr->szCodePage, "ACP")) /* do nothing */ ; /* if OCP, set flag */ else if (!strcmp(lpInStr->szCodePage, "OCP")) fOCP = TRUE; /* user supplied a code page */ else if (!(Id.wCodePage = atoi((const char *)lpInStr->szCodePage))) return FALSE; } /* ----------------------------------------------------------------------- stage 2: qualify internal LC_ID -----------------------------------------------------------------------*/ if (!Id.wLanguage) { /* language undefined*/ if (!Id.wCountry) { /* language undefined, country undefined*/ Id.wLanguage = Id.wCountry = LANGIDFROMLCID(GetUserDefaultLCID()); if (!Id.wCodePage) cpLCID = GetUserDefaultLCID(); } else { /* language undefined, country defined*/ Id.wCountry = Id.wLanguage = trans_ctry_lang(Id.wCountry); if (!Id.wCodePage) cpLCID = MAKELCID(Id.wCountry, SORT_DEFAULT); } } else { /* language defined*/ if (!Id.wCountry) { /* language defined, country undefined*/ Id.wCountry = Id.wLanguage; if (!Id.wCodePage) cpLCID = MAKELCID(Id.wCountry, SORT_DEFAULT); } else { /* language defined, country defined*/ /* match and set country and language*/ if (!match_ctry_lang((WORD *)&Id.wCountry, (WORD *)&Id.wLanguage)) return FALSE; if (!Id.wCodePage) cpLCID = MAKELCID(Id.wCountry, SORT_DEFAULT); } } if (!Id.wCodePage) { if (__crtGetLocaleInfoW(cpLCID, (fOCP) ? LOCALE_IDEFAULTCODEPAGE : LOCALE_IDEFAULTANSICODEPAGE, wcsTemp, MAX_TEMP_STR_LEN, 0) == 0) return FALSE; Id.wCodePage = (WORD)wcstol(wcsTemp, NULL, 10); } /* * Must verify ALL code pages - even those coming from OS. */ if (!IsValidCodePage(Id.wCodePage)) return FALSE; /* * Must verify locale is installed. */ if (!IsValidLocale(MAKELCID(Id.wLanguage, SORT_DEFAULT), LCID_INSTALLED)) return FALSE; /* ----------------------------------------------------------------------- stage 3: convert to proper output format -----------------------------------------------------------------------*/ if (lpOutId) { *lpOutId = Id; } if (lpOutStr) { if (__crtGetLocaleInfoA(MAKELCID(Id.wLanguage, SORT_DEFAULT), LOCALE_SENGLANGUAGE, lpOutStr->szLanguage, MAX_LANG_LEN, 0) == 0) return FALSE; if (__crtGetLocaleInfoA(MAKELCID(Id.wCountry, SORT_DEFAULT), LOCALE_SENGCOUNTRY, lpOutStr->szCountry, MAX_CTRY_LEN, 0) == 0) return FALSE; _itoa((int)Id.wCodePage, (char *)lpOutStr->szCodePage, 10); } return TRUE; }
LRESULT APIENTRY ListBoxWndProcWorker( PWND pwnd, UINT message, WPARAM wParam, LPARAM lParam, DWORD fAnsi) { HWND hwnd = HWq(pwnd); PAINTSTRUCT ps; HDC hdc; LPRECT lprc; PLBIV plb; /* List Box Instance Variable */ INT iSel; /* Index of selected item */ DWORD dw; TL tlpwndParent; UINT wFlags; LPWSTR lpwsz = NULL; LRESULT lReturn = 0; static BOOL fInit = TRUE; CheckLock(pwnd); VALIDATECLASSANDSIZE(pwnd, FNID_LISTBOX); INITCONTROLLOOKASIDE(&ListboxLookaside, LBIV, spwnd, 4); /* * Get the plb for the given window now since we will use it a lot in * various handlers. This was stored using SetWindowLong(hwnd,0,plb) * when the listbox was first created (by INITCONTROLLOOKASIDE above) */ plb = ((PLBWND)pwnd)->pLBIV; /* * Handle ANSI translations of input parameters */ if (fAnsi) { switch (message) { case LB_ADDSTRING: case LB_ADDSTRINGUPPER: case LB_ADDSTRINGLOWER: case LB_FINDSTRING: case LB_FINDSTRINGEXACT: case LB_INSERTSTRING: case LB_INSERTSTRINGUPPER: case LB_INSERTSTRINGLOWER: case LB_SELECTSTRING: if (!plb->fHasStrings) { break; } // Fall through... case LB_ADDFILE: case LB_DIR: if (lParam) { if (!MBToWCS((LPSTR)lParam, -1, &lpwsz, -1, TRUE)) return LB_ERR; } break; default: break; } if (lpwsz) { lParam = (LPARAM)lpwsz; } } switch (message) { case LB_GETTOPINDEX: // Return index of top item displayed. return plb->iTop; case LB_SETTOPINDEX: if (wParam && ((INT)wParam < 0 || (INT)wParam >= plb->cMac)) { RIPERR0(ERROR_INVALID_INDEX, RIP_VERBOSE, ""); return LB_ERR; } if (plb->cMac) { xxxNewITop(plb, (INT)wParam); } break; case WM_STYLECHANGED: plb->fRtoLReading = (TestWF(pwnd, WEFRTLREADING) != 0); plb->fRightAlign = (TestWF(pwnd, WEFRIGHT) != 0); xxxCheckRedraw(plb, FALSE, 0); break; case WM_WINDOWPOSCHANGED: /* * If we are in the middle of creation, ignore this * message because it will generate a WM_SIZE message. * See xxxLBCreate(). */ if (!plb->fIgnoreSizeMsg) goto CallDWP; break; case WM_SIZE: /* * If we are in the middle of creation, ignore size * messages. See xxxLBCreate(). */ if (!plb->fIgnoreSizeMsg) xxxLBSize(plb, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); break; case WM_ERASEBKGND: ThreadLock(plb->spwndParent, &tlpwndParent); FillWindow(HW(plb->spwndParent), hwnd, (HDC)wParam, (HBRUSH)CTLCOLOR_LISTBOX); ThreadUnlock(&tlpwndParent); return TRUE; case LB_RESETCONTENT: xxxLBResetContent(plb); break; case WM_TIMER: if (wParam == IDSYS_LBSEARCH) { plb->iTypeSearch = 0; NtUserKillTimer(hwnd, IDSYS_LBSEARCH); xxxInvertLBItem(plb, plb->iSel, TRUE); break; } message = WM_MOUSEMOVE; xxxTrackMouse(plb, message, plb->ptPrev); break; /* * Fall through */ case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: { POINT pt; POINTSTOPOINT(pt, lParam); xxxTrackMouse(plb, message, pt); } break; case WM_MBUTTONDOWN: EnterReaderModeHelper(hwnd); break; case WM_CAPTURECHANGED: // // Note that this message should be handled only on unexpected // capture changes currently. // UserAssert(TestWF(pwnd, WFWIN40COMPAT)); if (plb->fCaptured) xxxLBButtonUp(plb, LBUP_NOTIFY); break; case LBCB_STARTTRACK: // // Start tracking mouse moves in the listbox, setting capture // if (!plb->pcbox) break; plb->fCaptured = FALSE; if (wParam) { POINT pt; POINTSTOPOINT(pt, lParam); _ScreenToClient(pwnd, &pt); xxxTrackMouse(plb, WM_LBUTTONDOWN, pt); } else { NtUserSetCapture(hwnd); plb->fCaptured = TRUE; plb->iLastSelection = plb->iSel; } break; case LBCB_ENDTRACK: // Kill capture, tracking, etc. if (plb->fCaptured) xxxLBButtonUp(plb, LBUP_RELEASECAPTURE | (wParam ? LBUP_SELCHANGE : LBUP_RESETSELECTION)); break; case WM_PRINTCLIENT: xxxLBPaint(plb, (HDC) wParam, NULL); break; case WM_PAINT: if (wParam) { hdc = (HDC) wParam; lprc = NULL; } else { hdc = NtUserBeginPaint(hwnd, &ps); lprc = &(ps.rcPaint); } if (IsLBoxVisible(plb)) xxxLBPaint(plb, hdc, lprc); if (!wParam) NtUserEndPaint(hwnd, &ps); break; case WM_NCDESTROY: case WM_FINALDESTROY: xxxDestroyLBox(plb, pwnd); break; case WM_SETFOCUS: // DISABLED in Win 3.1 xxxUpdateWindow(pwnd); CaretCreate(plb); xxxLBSetCaret(plb, TRUE); xxxNotifyOwner(plb, LBN_SETFOCUS); if (FWINABLE()) { if (_IsWindowVisible(pwnd)) { LBEvent(plb, EVENT_OBJECT_FOCUS, plb->iSelBase); } } break; case WM_KILLFOCUS: /* * Reset the wheel delta count. */ gcWheelDelta = 0; xxxLBSetCaret(plb, FALSE); xxxCaretDestroy(plb); xxxNotifyOwner(plb, LBN_KILLFOCUS); if (plb->iTypeSearch) { plb->iTypeSearch = 0; NtUserKillTimer(hwnd, IDSYS_LBSEARCH); } if (plb->pszTypeSearch) { UserLocalFree(plb->pszTypeSearch); plb->pszTypeSearch = NULL; } break; case WM_MOUSEWHEEL: { int cDetants; int cPage; int cLines; RECT rc; int windowWidth; int cPos; /* * Don't handle zoom and datazoom. */ if (wParam & (MK_SHIFT | MK_CONTROL)) { goto CallDWP; } lReturn = 1; gcWheelDelta -= (short) HIWORD(wParam); cDetants = gcWheelDelta / WHEEL_DELTA; if ( cDetants != 0 && gpsi->ucWheelScrollLines > 0 && (pwnd->style & (WS_VSCROLL | WS_HSCROLL))) { gcWheelDelta = gcWheelDelta % WHEEL_DELTA; if (pwnd->style & WS_VSCROLL) { cPage = max(1, (plb->cItemFullMax - 1)); cLines = cDetants * (int) min((UINT) cPage, gpsi->ucWheelScrollLines); cPos = max(0, min(plb->iTop + cLines, plb->cMac - 1)); if (cPos != plb->iTop) { xxxLBoxCtlScroll(plb, SB_THUMBPOSITION, cPos); xxxLBoxCtlScroll(plb, SB_ENDSCROLL, 0); } } else if (plb->fMultiColumn) { cPage = max(1, plb->numberOfColumns); cLines = cDetants * (int) min((UINT) cPage, gpsi->ucWheelScrollLines); cPos = max( 0, min((plb->iTop / plb->itemsPerColumn) + cLines, plb->cMac - 1 - ((plb->cMac - 1) % plb->itemsPerColumn))); if (cPos != plb->iTop) { xxxLBoxCtlHScrollMultiColumn(plb, SB_THUMBPOSITION, cPos); xxxLBoxCtlHScrollMultiColumn(plb, SB_ENDSCROLL, 0); } } else { _GetClientRect(plb->spwnd, &rc); windowWidth = rc.right; cPage = max(plb->cxChar, (windowWidth / 3) * 2) / plb->cxChar; cLines = cDetants * (int) min((UINT) cPage, gpsi->ucWheelScrollLines); cPos = max( 0, min(plb->xOrigin + (cLines * plb->cxChar), plb->maxWidth)); if (cPos != plb->xOrigin) { xxxLBoxCtlHScroll(plb, SB_THUMBPOSITION, cPos); xxxLBoxCtlHScroll(plb, SB_ENDSCROLL, 0); } } } } break; case WM_VSCROLL: xxxLBoxCtlScroll(plb, LOWORD(wParam), HIWORD(wParam)); break; case WM_HSCROLL: xxxLBoxCtlHScroll(plb, LOWORD(wParam), HIWORD(wParam)); break; case WM_GETDLGCODE: return DLGC_WANTARROWS | DLGC_WANTCHARS; case WM_CREATE: return xxxLBCreate(plb, pwnd, (LPCREATESTRUCT) lParam); case WM_SETREDRAW: /* * If wParam is nonzero, the redraw flag is set * If wParam is zero, the flag is cleared */ xxxLBSetRedraw(plb, (wParam != 0)); break; case WM_ENABLE: xxxLBInvalidateRect(plb, NULL, !plb->OwnerDraw); break; case WM_SETFONT: xxxLBSetFont(plb, (HANDLE)wParam, LOWORD(lParam)); break; case WM_GETFONT: return (LRESULT)plb->hFont; case WM_DRAGSELECT: case WM_DRAGLOOP: case WM_DRAGMOVE: case WM_DROPFILES: ThreadLock(plb->spwndParent, &tlpwndParent); lReturn = SendMessage(HW(plb->spwndParent), message, wParam, lParam); ThreadUnlock(&tlpwndParent); return lReturn; case WM_QUERYDROPOBJECT: case WM_DROPOBJECT: /* * fix up control data, then pass message to parent */ LBDropObjectHandler(plb, (PDROPSTRUCT)lParam); ThreadLock(plb->spwndParent, &tlpwndParent); lReturn = SendMessage(HW(plb->spwndParent), message, wParam, lParam); ThreadUnlock(&tlpwndParent); return lReturn; case LB_GETITEMRECT: return LBGetItemRect(plb, (INT)wParam, (LPRECT)lParam); case LB_GETITEMDATA: return LBGetItemData(plb, (INT)wParam); // wParam = item index case LB_SETITEMDATA: /* * wParam is item index */ return LBSetItemData(plb, (INT)wParam, lParam); case LB_ADDSTRINGUPPER: wFlags = UPPERCASE | LBI_ADD; goto CallInsertItem; case LB_ADDSTRINGLOWER: wFlags = LOWERCASE | LBI_ADD; goto CallInsertItem; case LB_ADDSTRING: wFlags = LBI_ADD; goto CallInsertItem; case LB_INSERTSTRINGUPPER: wFlags = UPPERCASE; goto CallInsertItem; case LB_INSERTSTRINGLOWER: wFlags = LOWERCASE; goto CallInsertItem; case LB_INSERTSTRING: wFlags = 0; CallInsertItem: lReturn = ((LRESULT) xxxLBInsertItem(plb, (LPWSTR) lParam, (int) wParam, wFlags)); break; case LB_INITSTORAGE: return xxxLBInitStorage(plb, fAnsi, (INT)wParam, (INT)lParam); case LB_DELETESTRING: return xxxLBoxCtlDelete(plb, (INT)wParam); case LB_DIR: /* * wParam - Dos attribute value. * lParam - Points to a file specification string */ lReturn = xxxLbDir(plb, (INT)wParam, (LPWSTR)lParam); break; case LB_ADDFILE: lReturn = xxxLbInsertFile(plb, (LPWSTR)lParam); break; case LB_SETSEL: return xxxLBSetSel(plb, (wParam != 0), (INT)lParam); case LB_SETCURSEL: /* * If window obscured, update so invert will work correctly */ // DISABLED in Win 3.1 xxxUpdateWindow(pwnd); return xxxLBSetCurSel(plb, (INT)wParam); case LB_GETSEL: if (wParam >= (UINT) plb->cMac) return((LRESULT) LB_ERR); return IsSelected(plb, (INT)wParam, SELONLY); case LB_GETCURSEL: if (plb->wMultiple == SINGLESEL) { return plb->iSel; } return plb->iSelBase; case LB_SELITEMRANGE: if (plb->wMultiple == SINGLESEL) { /* * Can't select a range if only single selections are enabled */ RIPERR0(ERROR_INVALID_INDEX, RIP_VERBOSE,"Invalid index passed to LB_SELITEMRANGE"); return LB_ERR; } xxxLBSelRange(plb, LOWORD(lParam), HIWORD(lParam), (wParam != 0)); break; case LB_SELITEMRANGEEX: if (plb->wMultiple == SINGLESEL) { /* * Can't select a range if only single selections are enabled */ RIPERR0(ERROR_INVALID_LB_MESSAGE, RIP_VERBOSE,"LB_SELITEMRANGEEX:Can't select a range if only single selections are enabled"); return LB_ERR; } else { BOOL fHighlight = ((DWORD)lParam > (DWORD)wParam); if (fHighlight == FALSE) { ULONG_PTR temp = lParam; lParam = wParam; wParam = temp; } xxxLBSelRange(plb, (INT)wParam, (INT)lParam, fHighlight); } break; case LB_GETTEXTLEN: if (lParam != 0) { RIPMSG1(RIP_WARNING, "LB_GETTEXTLEN with lParam = %lx\n", lParam); } lReturn = LBGetText(plb, TRUE, fAnsi, (INT)wParam, NULL); break; case LB_GETTEXT: lReturn = LBGetText(plb, FALSE, fAnsi, (INT)wParam, (LPWSTR)lParam); break; case LB_GETCOUNT: // Lotus Approach calls CallWndProc(ListWndProc, LB_GETCOUNT,...) // on a window that doesn't have a plb yet. So, we need to make // this check. Bug #6675 - 11/7/94 -- if(plb) return((LRESULT) plb->cMac); else return(0); case LB_SETCOUNT: return xxxLBSetCount(plb, (INT)wParam); case LB_SELECTSTRING: case LB_FINDSTRING: iSel = xxxFindString(plb, (LPWSTR)lParam, (INT)wParam, PREFIX, TRUE); if (message == LB_FINDSTRING || iSel == LB_ERR) { lReturn = iSel; } else { lReturn = xxxLBSetCurSel(plb, iSel); } break; case LB_GETLOCALE: return plb->dwLocaleId; case LB_SETLOCALE: /* * Validate locale */ wParam = ConvertDefaultLocale((LCID)wParam); if (!IsValidLocale((LCID)wParam, LCID_INSTALLED)) return LB_ERR; dw = plb->dwLocaleId; plb->dwLocaleId = (DWORD)wParam; return dw; case WM_KEYDOWN: /* * IanJa: Use LOWORD() to get low 16-bits of wParam - this should * work for Win16 & Win32. The value obtained is the virtual key */ xxxLBoxCtlKeyInput(plb, message, LOWORD(wParam)); break; case WM_CHAR: xxxLBoxCtlCharInput(plb, LOWORD(wParam), fAnsi); break; case LB_GETSELITEMS: case LB_GETSELCOUNT: /* * IanJa/Win32 should this be LPWORD now? */ return LBoxGetSelItems(plb, (message == LB_GETSELCOUNT), (INT)wParam, (LPINT)lParam); case LB_SETTABSTOPS: /* * IanJa/Win32: Tabs given by array of INT for backwards compatability */ return LBSetTabStops(plb, (INT)wParam, (LPINT)lParam); case LB_GETHORIZONTALEXTENT: /* * Return the max width of the listbox used for horizontal scrolling */ return plb->maxWidth; case LB_SETHORIZONTALEXTENT: /* * Set the max width of the listbox used for horizontal scrolling */ if (plb->maxWidth != (INT)wParam) { plb->maxWidth = (INT)wParam; /* * When horizontal extent is set, Show/hide the scroll bars. * NOTE: LBShowHideScrollBars() takes care if Redraw is OFF. * Fix for Bug #2477 -- 01/14/91 -- SANKAR -- */ xxxLBShowHideScrollBars(plb); //Try to show or hide scroll bars if (plb->fHorzBar && plb->fRightAlign && !(plb->fMultiColumn || plb->OwnerDraw)) { /* * origin to right */ xxxLBoxCtlHScroll(plb, SB_BOTTOM, 0); } } break; /* originally returned register ax (message) ! */ case LB_SETCOLUMNWIDTH: /* * Set the width of a column in a multicolumn listbox */ plb->cxColumn = (INT)wParam; LBCalcItemRowsAndColumns(plb); if (IsLBoxVisible(plb)) NtUserInvalidateRect(hwnd, NULL, TRUE); xxxLBShowHideScrollBars(plb); break; case LB_SETANCHORINDEX: if ((INT)wParam >= plb->cMac) { RIPERR0(ERROR_INVALID_INDEX, RIP_VERBOSE,"Invalid index passed to LB_SETANCHORINDEX"); return LB_ERR; } plb->iMouseDown = (INT)wParam; plb->iLastMouseMove = (INT)wParam; xxxInsureVisible(plb, (int) wParam, (BOOL)(lParam != 0)); break; case LB_GETANCHORINDEX: return plb->iMouseDown; case LB_SETCARETINDEX: if ( (plb->iSel == -1) || ((plb->wMultiple != SINGLESEL) && (plb->cMac > (INT)wParam))) { /* * Set's the iSelBase to the wParam * if lParam, then don't scroll if partially visible * else scroll into view if not fully visible */ xxxInsureVisible(plb, (INT)wParam, (BOOL)LOWORD(lParam)); xxxSetISelBase(plb, (INT)wParam); break; } else { if ((INT)wParam >= plb->cMac) { RIPERR0(ERROR_INVALID_INDEX, RIP_VERBOSE,"Invalid index passed to LB_SETCARETINDEX"); } return LB_ERR; } break; case LB_GETCARETINDEX: return plb->iSelBase; case LB_SETITEMHEIGHT: case LB_GETITEMHEIGHT: return LBGetSetItemHeightHandler(plb, message, (INT)wParam, LOWORD(lParam)); break; case LB_FINDSTRINGEXACT: lReturn = xxxFindString(plb, (LPWSTR)lParam, (INT)wParam, EQ, TRUE); break; case LB_ITEMFROMPOINT: { POINT pt; BOOL bOutside; DWORD dwItem; POINTSTOPOINT(pt, lParam); bOutside = ISelFromPt(plb, pt, &dwItem); UserAssert(bOutside == 1 || bOutside == 0); return (LRESULT)MAKELONG(dwItem, bOutside); } case LBCB_CARETON: /* * Internal message for combo box support */ CaretCreate(plb); // Set up the caret in the proper location for drop downs. plb->iSelBase = plb->iSel; xxxLBSetCaret(plb, TRUE); if (FWINABLE()) { if (_IsWindowVisible(pwnd)) { LBEvent(plb, EVENT_OBJECT_FOCUS, plb->iSelBase); } } return(plb->iSel); case LBCB_CARETOFF: /* * Internal message for combo box support */ xxxLBSetCaret(plb, FALSE); xxxCaretDestroy(plb); break; case WM_NCCREATE: if ((pwnd->style & LBS_MULTICOLUMN) && (pwnd->style & WS_VSCROLL)) { DWORD mask = WS_VSCROLL; DWORD flags = 0; if (!TestWF(pwnd, WFWIN40COMPAT)) { mask |= WS_HSCROLL; flags = WS_HSCROLL; } NtUserAlterWindowStyle(hwnd, mask, flags); } goto CallDWP; default: CallDWP: return DefWindowProcWorker(pwnd, message, wParam, lParam, fAnsi); } /* * Handle translation of ANSI output data and free buffer */ if (lpwsz) { UserLocalFree(lpwsz); } return lReturn; }