- Don't show applets on taskbar
[reactos.git] / reactos / dll / cpl / intl / intl.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS International Control Panel
22 * FILE: lib/cpl/intl/intl.c
23 * PURPOSE: Property sheet code
24 * PROGRAMMER: Eric Kohl
25 */
26 #include <windows.h>
27 #include <commctrl.h>
28 #include <cpl.h>
29 #include <setupapi.h>
30 #include <tchar.h>
31
32 #include "intl.h"
33 #include "resource.h"
34
35
36 #define NUM_APPLETS (1)
37
38 static LONG APIENTRY
39 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
40
41
42 HINSTANCE hApplet = 0;
43 HWND hCPLWindow;
44 HINF hSetupInf = INVALID_HANDLE_VALUE;
45 DWORD IsUnattendedSetupEnabled = 0;
46 DWORD UnattendLCID = 0;
47
48
49 /* Applets */
50 APPLET Applets[NUM_APPLETS] =
51 {
52 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
53 };
54
55
56 static VOID
57 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
58 {
59 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
60 psp->dwSize = sizeof(PROPSHEETPAGE);
61 psp->dwFlags = PSP_DEFAULT;
62 psp->hInstance = hApplet;
63 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
64 psp->pfnDlgProc = DlgProc;
65 }
66
67 BOOL
68 OpenSetupInf(VOID)
69 {
70 LPTSTR lpCmdLine;
71 LPTSTR lpSwitch;
72 size_t len;
73
74 lpCmdLine = GetCommandLine();
75
76 lpSwitch = _tcsstr(lpCmdLine, _T("/f:\""));
77
78 if(!lpSwitch)
79 {
80 return FALSE;
81 }
82
83 len = _tcslen(lpSwitch);
84 if (len < 5)
85 {
86 return FALSE;
87 }
88
89 if(lpSwitch[len-1] != _T('\"'))
90 {
91 return FALSE;
92 }
93
94 lpSwitch[len-1] = _T('\0');
95
96 hSetupInf = SetupOpenInfFile(&lpSwitch[4], NULL,
97 INF_STYLE_OLDNT, NULL);
98
99 return (hSetupInf != INVALID_HANDLE_VALUE);
100 }
101
102 VOID
103 ParseSetupInf(VOID)
104 {
105 INFCONTEXT InfContext;
106 TCHAR szBuffer[30];
107
108 if (!SetupFindFirstLine(hSetupInf,
109 _T("Unattend"),
110 _T("LocaleID"),
111 &InfContext))
112 {
113 SetupCloseInfFile(hSetupInf);
114 return;
115 }
116
117 if (!SetupGetStringField(&InfContext, 1, szBuffer,
118 sizeof(szBuffer) / sizeof(TCHAR), NULL))
119 {
120 SetupCloseInfFile(hSetupInf);
121 return;
122 }
123
124 UnattendLCID = _tcstoul(szBuffer, NULL, 16);
125 IsUnattendedSetupEnabled = 1;
126 SetupCloseInfFile(hSetupInf);
127 }
128
129 static LONG APIENTRY
130 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
131 {
132 PROPSHEETPAGE psp[3];
133 PROPSHEETHEADER psh;
134 TCHAR Caption[256];
135
136 if (OpenSetupInf())
137 {
138 ParseSetupInf();
139 }
140
141 LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
142
143 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
144 psh.dwSize = sizeof(PROPSHEETHEADER);
145 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
146 psh.hwndParent = hCPLWindow;
147 psh.hInstance = hApplet;
148 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
149 psh.pszCaption = Caption;
150 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
151 psh.nStartPage = 0;
152 psh.ppsp = psp;
153
154 InitPropSheetPage(&psp[0], IDD_GENERALPAGE, GeneralPageProc);
155 InitPropSheetPage(&psp[1], IDD_LANGUAGESPAGE, LanguagesPageProc);
156 InitPropSheetPage(&psp[2], IDD_ADVANCEDPAGE, AdvancedPageProc);
157
158 return (LONG)(PropertySheet(&psh) != -1);
159 }
160
161
162 /* Control Panel Callback */
163 LONG APIENTRY
164 CPlApplet(HWND hwndCpl,
165 UINT uMsg,
166 LPARAM lParam1,
167 LPARAM lParam2)
168 {
169 switch(uMsg)
170 {
171 case CPL_INIT:
172 return TRUE;
173
174 case CPL_GETCOUNT:
175 return NUM_APPLETS;
176
177 case CPL_INQUIRE:
178 {
179 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
180 UINT uAppIndex = (UINT)lParam1;
181
182 CPlInfo->lData = 0;
183 CPlInfo->idIcon = Applets[uAppIndex].idIcon;
184 CPlInfo->idName = Applets[uAppIndex].idName;
185 CPlInfo->idInfo = Applets[uAppIndex].idDescription;
186 break;
187 }
188
189 case CPL_DBLCLK:
190 {
191 UINT uAppIndex = (UINT)lParam1;
192 hCPLWindow = hwndCpl;
193 Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
194 break;
195 }
196 }
197
198 return FALSE;
199 }
200
201
202 BOOL STDCALL
203 DllMain(HINSTANCE hinstDLL,
204 DWORD dwReason,
205 LPVOID lpReserved)
206 {
207 switch(dwReason)
208 {
209 case DLL_PROCESS_ATTACH:
210 case DLL_THREAD_ATTACH:
211 hApplet = hinstDLL;
212 break;
213 }
214
215 return TRUE;
216 }
217