ReactOS 0.4.15-dev-7788-g1ad9096
add_dialog.c
Go to the documentation of this file.
1/*
2* PROJECT: input.dll
3* FILE: dll/cpl/input/add_dialog.c
4* PURPOSE: input.dll
5* PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6*/
7
8#include "input.h"
9#include "locale_list.h"
10#include "layout_list.h"
11#include "input_list.h"
12
13
14static DWORD
16{
17 DWORD dwResult = 0;
18 HINF hIntlInf;
19
20 hIntlInf = SetupOpenInfFileW(L"intl.inf", NULL, INF_STYLE_WIN4, NULL);
21 if (hIntlInf != INVALID_HANDLE_VALUE)
22 {
23 WCHAR szLangID[MAX_STR_LEN];
24 INFCONTEXT InfContext;
25
26 StringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"%08X", dwLocaleId);
27
28 if (SetupFindFirstLineW(hIntlInf, L"Locales", szLangID, &InfContext))
29 {
30 if (SetupGetFieldCount(&InfContext) >= 5)
31 {
32 WCHAR szField[MAX_STR_LEN];
33
34 if (SetupGetStringFieldW(&InfContext, 5, szField, ARRAYSIZE(szField), NULL))
35 {
36 if (wcslen(szField) == 13) // like 0409:00000409 (13 chars)
37 {
38 WCHAR *pszSeparator = L":";
39 WCHAR *pszToken;
40
41 pszToken = wcstok(szField, pszSeparator);
42 if (pszToken != NULL)
43 pszToken = wcstok(NULL, pszSeparator);
44
45 if (pszToken != NULL)
46 {
47 dwResult = DWORDfromString(pszToken);
48 }
49 }
50 }
51 }
52 }
53
54 SetupCloseInfFile(hIntlInf);
55 }
56
57 return dwResult;
58}
59
60
61static VOID
63{
64 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
65 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
66 LOCALE_LIST_NODE *pCurrentLocale;
67 LAYOUT_LIST_NODE *pCurrentLayout;
68 DWORD dwDefaultLocaleId;
69 DWORD dwDefaultLayoutId;
70 INT iItemIndex;
71
72 dwDefaultLocaleId = GetSystemDefaultLCID();
73
74 for (pCurrentLocale = LocaleList_GetFirst();
75 pCurrentLocale != NULL;
76 pCurrentLocale = pCurrentLocale->pNext)
77 {
78 iItemIndex = ComboBox_AddString(hwndLocaleCombo, pCurrentLocale->pszName);
79 ComboBox_SetItemData(hwndLocaleCombo, iItemIndex, pCurrentLocale);
80
81 if (pCurrentLocale->dwId == dwDefaultLocaleId)
82 {
83 ComboBox_SetCurSel(hwndLocaleCombo, iItemIndex);
84 }
85 }
86
87 dwDefaultLayoutId = GetDefaultLayoutForLocale(dwDefaultLocaleId);
88
89 for (pCurrentLayout = LayoutList_GetFirst();
90 pCurrentLayout != NULL;
91 pCurrentLayout = pCurrentLayout->pNext)
92 {
93 iItemIndex = ComboBox_AddString(hwndLayoutCombo, pCurrentLayout->pszName);
94 ComboBox_SetItemData(hwndLayoutCombo, iItemIndex, pCurrentLayout);
95
96 if (pCurrentLayout->dwKLID == dwDefaultLayoutId)
97 {
98 ComboBox_SetCurSel(hwndLayoutCombo, iItemIndex);
99 }
100 }
101
102 if (dwDefaultLayoutId == 0)
103 ComboBox_SetCurSel(hwndLayoutCombo, 0);
104}
105
106
107static VOID
109{
110 switch (LOWORD(wParam))
111 {
112 case IDOK:
113 {
114 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
115 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
116 LOCALE_LIST_NODE *pCurrentLocale;
117 LAYOUT_LIST_NODE *pCurrentLayout;
118
119 pCurrentLocale = (LOCALE_LIST_NODE*)ComboBox_GetItemData(hwndLocaleCombo,
120 ComboBox_GetCurSel(hwndLocaleCombo));
121 pCurrentLayout = (LAYOUT_LIST_NODE*)ComboBox_GetItemData(hwndLayoutCombo,
122 ComboBox_GetCurSel(hwndLayoutCombo));
123
124 InputList_Add(pCurrentLocale, pCurrentLayout);
125
126 EndDialog(hwndDlg, LOWORD(wParam));
127 }
128 break;
129
130 case IDCANCEL:
131 {
132 EndDialog(hwndDlg, LOWORD(wParam));
133 }
134 break;
135
137 {
139 {
140 HWND hwndLocaleCombo = GetDlgItem(hwndDlg, IDC_INPUT_LANG_COMBO);
141 HWND hwndLayoutCombo = GetDlgItem(hwndDlg, IDC_KEYBOARD_LO_COMBO);
142 LOCALE_LIST_NODE *pCurrentLocale;
143
144 pCurrentLocale = (LOCALE_LIST_NODE*)ComboBox_GetItemData(hwndLocaleCombo,
145 ComboBox_GetCurSel(hwndLocaleCombo));
146 if (pCurrentLocale != NULL)
147 {
148 DWORD dwLayoutId;
149 INT iIndex;
150 INT iCount;
151
152 dwLayoutId = GetDefaultLayoutForLocale(pCurrentLocale->dwId);
153
154 iCount = ComboBox_GetCount(hwndLayoutCombo);
155
156 for (iIndex = 0; iIndex < iCount; iIndex++)
157 {
158 LAYOUT_LIST_NODE *pCurrentLayout;
159
160 pCurrentLayout = (LAYOUT_LIST_NODE*)ComboBox_GetItemData(hwndLayoutCombo, iIndex);
161
162 if (pCurrentLayout != NULL && pCurrentLayout->dwKLID == dwLayoutId)
163 {
164 ComboBox_SetCurSel(hwndLayoutCombo, iIndex);
165 break;
166 }
167 }
168 }
169 }
170 }
171 break;
172 }
173}
174
175
178{
179 switch (uMsg)
180 {
181 case WM_INITDIALOG:
182 OnInitAddDialog(hwndDlg);
183 return TRUE;
184
185 case WM_COMMAND:
186 OnCommandAddDialog(hwndDlg, wParam);
187 break;
188
189 case WM_DESTROY:
190 break;
191 }
192
193 return FALSE;
194}
static VOID OnCommandAddDialog(HWND hwndDlg, WPARAM wParam)
Definition: add_dialog.c:108
INT_PTR CALLBACK AddDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: add_dialog.c:177
static VOID OnInitAddDialog(HWND hwndDlg)
Definition: add_dialog.c:62
static DWORD GetDefaultLayoutForLocale(DWORD dwLocaleId)
Definition: add_dialog.c:15
#define MAX_STR_LEN
Definition: defines.h:43
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static DWORD DWORDfromString(const WCHAR *pszString)
Definition: input.h:80
#define IDC_KEYBOARD_LO_COMBO
Definition: resource.h:32
#define IDC_INPUT_LANG_COMBO
Definition: resource.h:31
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CALLBACK
Definition: compat.h:35
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define INF_STYLE_WIN4
Definition: infsupp.h:41
BOOL InputList_Add(LOCALE_LIST_NODE *pLocale, LAYOUT_LIST_NODE *pLayout)
Definition: input_list.c:502
LCID WINAPI GetSystemDefaultLCID(void)
Definition: lang.c:797
LAYOUT_LIST_NODE * LayoutList_GetFirst(VOID)
Definition: layout_list.c:249
LOCALE_LIST_NODE * LocaleList_GetFirst(VOID)
Definition: locale_list.c:146
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
_Check_return_ _CRTIMP wchar_t *__cdecl wcstok(_Inout_opt_z_ wchar_t *_Str, _In_z_ const wchar_t *_Delim)
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:14
struct _LOCALE_LIST_NODE * pNext
Definition: locale_list.h:12
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:186
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:56
ULONG WINAPI SetupGetFieldCount(IN PINFCONTEXT Context)
Definition: infsupp.c:93
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define ComboBox_SetCurSel(hwndCtl, index)
Definition: windowsx.h:66
#define ComboBox_GetItemData(hwndCtl, index)
Definition: windowsx.h:54
#define ComboBox_GetCount(hwndCtl)
Definition: windowsx.h:48
#define ComboBox_GetCurSel(hwndCtl)
Definition: windowsx.h:49
#define ComboBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:41
#define ComboBox_SetItemData(hwndCtl, index, data)
Definition: windowsx.h:69
#define IDCANCEL
Definition: winuser.h:831
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
#define CBN_SELCHANGE
Definition: winuser.h:1979
#define WM_DESTROY
Definition: winuser.h:1609
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180