1 /* Control Panel management
3 * Copyright 2001 Eric Pouech
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/winbase16.h"
32 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 #define NO_SHLWAPI_REG
41 WINE_DEFAULT_DEBUG_CHANNEL(shlctrl
);
43 CPlApplet
* Control_UnloadApplet(CPlApplet
* applet
)
48 for (i
= 0; i
< applet
->count
; i
++) {
49 if (!applet
->info
[i
].dwSize
) continue;
50 applet
->proc(applet
->hWnd
, CPL_STOP
, i
, applet
->info
[i
].lData
);
52 if (applet
->proc
) applet
->proc(applet
->hWnd
, CPL_EXIT
, 0L, 0L);
53 FreeLibrary(applet
->hModule
);
55 HeapFree(GetProcessHeap(), 0, applet
);
59 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
66 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
71 if (!(applet
->hModule
= LoadLibraryW(cmd
))) {
72 WARN("Cannot load control panel applet %s\n", debugstr_w(cmd
));
75 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
76 WARN("Not a valid control panel applet %s\n", debugstr_w(cmd
));
79 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
80 WARN("Init of applet has failed\n");
83 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
84 WARN("No subprogram in applet\n");
88 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
89 sizeof(*applet
) + (applet
->count
- 1) * sizeof(NEWCPLINFOW
));
91 for (i
= 0; i
< applet
->count
; i
++) {
92 ZeroMemory(&newinfo
, sizeof(newinfo
));
93 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
94 applet
->info
[i
].dwSize
= sizeof(NEWCPLINFOW
);
95 /* proc is supposed to return a null value upon success for
96 * CPL_INQUIRE and CPL_NEWINQUIRE
97 * However, real drivers don't seem to behave like this
98 * So, use introspection rather than return value
100 applet
->proc(hWnd
, CPL_NEWINQUIRE
, i
, (LPARAM
)&newinfo
);
101 if (newinfo
.hIcon
== 0) {
102 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
103 if (info
.idIcon
== 0 || info
.idName
== 0) {
104 WARN("Couldn't get info from sp %u\n", i
);
105 applet
->info
[i
].dwSize
= 0;
107 /* convert the old data into the new structure */
108 applet
->info
[i
].dwFlags
= 0;
109 applet
->info
[i
].dwHelpContext
= 0;
110 applet
->info
[i
].lData
= info
.lData
;
111 applet
->info
[i
].hIcon
= LoadIconW(applet
->hModule
,
112 MAKEINTRESOURCEW(info
.idIcon
));
113 LoadStringW(applet
->hModule
, info
.idName
,
114 applet
->info
[i
].szName
, sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
115 LoadStringW(applet
->hModule
, info
.idInfo
,
116 applet
->info
[i
].szInfo
, sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
117 applet
->info
[i
].szHelpFile
[0] = '\0';
122 CopyMemory(&applet
->info
[i
], &newinfo
, newinfo
.dwSize
);
123 if (newinfo
.dwSize
!= sizeof(NEWCPLINFOW
))
125 applet
->info
[i
].dwSize
= sizeof(NEWCPLINFOW
);
126 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szName
,
127 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szName
) / sizeof(CHAR
),
128 applet
->info
[i
].szName
,
129 sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
130 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
131 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
132 applet
->info
[i
].szInfo
,
133 sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
134 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
135 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
136 applet
->info
[i
].szHelpFile
,
137 sizeof(applet
->info
[i
].szHelpFile
) / sizeof(WCHAR
));
142 applet
->next
= panel
->first
;
143 panel
->first
= applet
;
148 Control_UnloadApplet(applet
);
152 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTA
* cs
)
154 CPanel
* panel
= (CPanel
*)cs
->lpCreateParams
;
156 SetWindowLongA(hWnd
, 0, (LPARAM
)panel
);
166 static BOOL
Control_Localize(const CPanel
* panel
, unsigned cx
, unsigned cy
,
167 CPlApplet
** papplet
, unsigned* psp
)
169 unsigned i
, x
= (XSTEP
-XICON
)/2, y
= 0;
173 GetClientRect(panel
->hWnd
, &rc
);
174 for (applet
= panel
->first
; applet
; applet
= applet
->next
) {
175 for (i
= 0; i
< applet
->count
; i
++) {
176 if (!applet
->info
[i
].dwSize
) continue;
177 if (x
+ XSTEP
>= rc
.right
- rc
.left
) {
181 if (cx
>= x
&& cx
< x
+ XICON
&& cy
>= y
&& cy
< y
+ YSTEP
) {
192 static LRESULT
Control_WndProc_Paint(const CPanel
* panel
, WPARAM wParam
)
197 unsigned i
, x
= 0, y
= 0;
201 hdc
= (wParam
) ? (HDC
)wParam
: BeginPaint(panel
->hWnd
, &ps
);
202 hOldFont
= SelectObject(hdc
, GetStockObject(ANSI_VAR_FONT
));
203 GetClientRect(panel
->hWnd
, &rc
);
204 for (applet
= panel
->first
; applet
; applet
= applet
->next
) {
205 for (i
= 0; i
< applet
->count
; i
++) {
206 if (x
+ XSTEP
>= rc
.right
- rc
.left
) {
210 if (!applet
->info
[i
].dwSize
) continue;
211 DrawIcon(hdc
, x
+ (XSTEP
-XICON
)/2, y
, applet
->info
[i
].hIcon
);
213 txtRect
.right
= x
+ XSTEP
;
214 txtRect
.top
= y
+ YICON
;
215 txtRect
.bottom
= y
+ YSTEP
;
216 DrawTextW(hdc
, applet
->info
[i
].szName
, -1, &txtRect
,
217 DT_CENTER
| DT_VCENTER
);
221 SelectObject(hdc
, hOldFont
);
222 if (!wParam
) EndPaint(panel
->hWnd
, &ps
);
226 static LRESULT
Control_WndProc_LButton(CPanel
* panel
, LPARAM lParam
, BOOL up
)
231 if (Control_Localize(panel
, LOWORD(lParam
), HIWORD(lParam
), &applet
, &i
)) {
233 if (panel
->clkApplet
== applet
&& panel
->clkSP
== i
) {
234 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, i
, applet
->info
[i
].lData
);
237 panel
->clkApplet
= applet
;
244 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
245 WPARAM lParam1
, LPARAM lParam2
)
247 CPanel
* panel
= (CPanel
*)GetWindowLongA(hWnd
, 0);
249 if (panel
|| wMsg
== WM_CREATE
) {
252 Control_WndProc_Create(hWnd
, (CREATESTRUCTA
*)lParam2
);
256 CPlApplet
* applet
= panel
->first
;
258 applet
= Control_UnloadApplet(applet
);
263 return Control_WndProc_Paint(panel
, lParam1
);
265 return Control_WndProc_LButton(panel
, lParam2
, TRUE
);
267 return Control_WndProc_LButton(panel
, lParam2
, FALSE
);
268 /* EPP case WM_COMMAND: */
269 /* EPP return Control_WndProc_Command(mwi, lParam1, lParam2); */
273 return DefWindowProcA(hWnd
, wMsg
, lParam1
, lParam2
);
276 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
280 const CHAR
* appName
= "Wine Control Panel";
281 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
282 wc
.lpfnWndProc
= Control_WndProc
;
284 wc
.cbWndExtra
= sizeof(CPlApplet
*);
285 wc
.hInstance
= hInst
;
288 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
289 wc
.lpszMenuName
= NULL
;
290 wc
.lpszClassName
= "Shell_Control_WndClass";
292 if (!RegisterClassA(&wc
)) return;
294 CreateWindowExA(0, wc
.lpszClassName
, appName
,
295 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
296 CW_USEDEFAULT
, CW_USEDEFAULT
,
297 CW_USEDEFAULT
, CW_USEDEFAULT
,
298 hWnd
, NULL
, hInst
, panel
);
299 if (!panel
->hWnd
) return;
302 /* FIXME appName & message should be localized */
303 MessageBoxA(panel
->hWnd
, "Cannot load any applets", appName
, MB_OK
);
307 while (GetMessageA(&msg
, panel
->hWnd
, 0, 0)) {
308 TranslateMessage(&msg
);
309 DispatchMessageA(&msg
);
313 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
317 WCHAR buffer
[MAX_PATH
];
318 static const WCHAR wszAllCpl
[] = {'*','.','c','p','l',0};
321 GetSystemDirectoryW( buffer
, MAX_PATH
);
322 p
= buffer
+ strlenW(buffer
);
324 lstrcpyW(p
, wszAllCpl
);
326 if ((h
= FindFirstFileW(buffer
, &fd
)) != INVALID_HANDLE_VALUE
) {
328 lstrcpyW(p
, fd
.cFileName
);
329 Control_LoadApplet(hWnd
, buffer
, panel
);
330 } while (FindNextFileW(h
, &fd
));
334 Control_DoInterface(panel
, hWnd
, hInst
);
337 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
353 LPWSTR extraPmts
= NULL
;
356 buffer
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd
) + 1) * sizeof(*wszCmd
));
359 end
= lstrcpyW(buffer
, wszCmd
);
363 if (ch
== '"') quoted
= !quoted
;
364 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
369 } else if (*beg
== '\0') {
375 if (ch
== '\0') break;
377 if (ch
== ' ') while (end
[1] == ' ') end
++;
381 while ((ptr
= StrChrW(buffer
, '"')))
382 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
384 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer
), debugstr_w(extraPmts
), sp
);
386 Control_LoadApplet(hWnd
, buffer
, panel
);
389 CPlApplet
* applet
= panel
->first
;
391 assert(applet
&& applet
->next
== NULL
);
392 if (sp
>= applet
->count
) {
393 WARN("Out of bounds (%u >= %u), setting to 0\n", sp
, applet
->count
);
396 if (applet
->info
[sp
].dwSize
) {
397 if (!applet
->proc(applet
->hWnd
, CPL_STARTWPARMSA
, sp
, (LPARAM
)extraPmts
))
398 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].lData
);
400 Control_UnloadApplet(applet
);
402 HeapFree(GetProcessHeap(), 0, buffer
);
405 /*************************************************************************
406 * Control_RunDLLW [SHELL32.@]
409 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
413 TRACE("(%p, %p, %s, 0x%08lx)\n",
414 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
416 memset(&panel
, 0, sizeof(panel
));
419 Control_DoWindow(&panel
, hWnd
, hInst
);
421 Control_DoLaunch(&panel
, hWnd
, cmd
);
425 /*************************************************************************
426 * Control_RunDLLA [SHELL32.@]
429 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
431 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
432 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
433 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
435 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
437 HeapFree(GetProcessHeap(), 0, wszCmd
);
440 /*************************************************************************
441 * Control_FillCache_RunDLLW [SHELL32.@]
444 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
446 FIXME("%p %p 0x%08lx 0x%08lx stub\n", hWnd
, hModule
, w
, x
);
450 /*************************************************************************
451 * Control_FillCache_RunDLLA [SHELL32.@]
454 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
456 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
460 /*************************************************************************
461 * RunDLL_CallEntry16 [SHELL32.122]
462 * the name is probably wrong
464 void WINAPI
RunDLL_CallEntry16( DWORD proc
, HWND hwnd
, HINSTANCE inst
,
465 LPCSTR cmdline
, INT cmdshow
)
470 TRACE( "proc %lx hwnd %p inst %p cmdline %s cmdshow %d\n",
471 proc
, hwnd
, inst
, debugstr_a(cmdline
), cmdshow
);
473 cmdline_seg
= MapLS( cmdline
);
474 args
[4] = HWND_16(hwnd
);
475 args
[3] = MapHModuleLS(inst
);
476 args
[2] = SELECTOROF(cmdline_seg
);
477 args
[1] = OFFSETOF(cmdline_seg
);
479 WOWCallback16Ex( proc
, WCB16_PASCAL
, sizeof(args
), args
, NULL
);
480 UnMapLS( cmdline_seg
);
483 /*************************************************************************
484 * CallCPLEntry16 [SHELL32.166]
486 * called by desk.cpl on "Advanced" with:
487 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
490 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
492 FIXME("(%p, %p, %08lx, %08lx, %08lx, %08lx): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);