wintrust: Add some tests.
[wine/wine64.git] / programs / progman / dialog.c
blobf3c297479cc029153c16a43989a16b2f9a09380f
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
5 * Copyright 2002 Sylvain Petreolle
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN
25 #include "windows.h"
26 #include "commdlg.h"
27 #include "progman.h"
28 static BOOL DIALOG_BrowsePrograms(HWND, LPSTR, INT);
29 static BOOL DIALOG_BrowseSymbols(HWND, LPSTR, INT);
30 static INT_PTR CALLBACK DIALOG_NEW_DlgProc(HWND, UINT, WPARAM, LPARAM);
31 static INT_PTR CALLBACK DIALOG_COPY_MOVE_DlgProc(HWND, UINT, WPARAM, LPARAM);
32 static INT_PTR CALLBACK DIALOG_GROUP_DlgProc(HWND, UINT, WPARAM, LPARAM);
33 static INT_PTR CALLBACK DIALOG_PROGRAM_DlgProc(HWND, UINT, WPARAM, LPARAM);
34 static INT_PTR CALLBACK DIALOG_SYMBOL_DlgProc(HWND, UINT, WPARAM, LPARAM);
35 static INT_PTR CALLBACK DIALOG_EXECUTE_DlgProc(HWND, UINT, WPARAM, LPARAM);
37 /***********************************************************************
39 * DIALOG_New
42 static struct
44 INT nDefault;
45 } New;
47 INT DIALOG_New(INT nDefault)
49 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_NEW_DlgProc, Globals.hInstance);
50 INT ret;
52 New.nDefault = nDefault;
54 ret = DialogBox(Globals.hInstance, STRING_NEW,
55 Globals.hMainWnd, lpfnDlg);
56 FreeProcInstance(lpfnDlg);
57 return ret;
60 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
62 * DIALOG_NEW_DlgProc
65 static INT_PTR CALLBACK DIALOG_NEW_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
67 switch (msg)
69 case WM_INITDIALOG:
70 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, New.nDefault);
71 break;
73 case WM_COMMAND:
74 switch (wParam)
76 case PM_NEW_GROUP:
77 case PM_NEW_PROGRAM:
78 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, wParam);
79 return TRUE;
81 case IDOK:
82 EndDialog(hDlg, IsDlgButtonChecked(hDlg, PM_NEW_GROUP) ?
83 PM_NEW_GROUP : PM_NEW_PROGRAM);
84 return TRUE;
86 case IDCANCEL:
87 EndDialog(hDlg, IDCANCEL);
88 return TRUE;
91 return FALSE;
94 /***********************************************************************
96 * DIALOG_CopyMove
99 static struct
101 LPCSTR lpszProgramName, lpszFromGroupName;
102 HLOCAL hToGroup;
103 } CopyMove;
105 HLOCAL DIALOG_CopyMove(LPCSTR lpszProgramName, LPCSTR lpszFromGroupName,
106 BOOL bMove)
108 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_COPY_MOVE_DlgProc, Globals.hInstance);
109 INT ret;
111 CopyMove.lpszProgramName = lpszProgramName;
112 CopyMove.lpszFromGroupName = lpszFromGroupName;
113 CopyMove.hToGroup = 0;
115 ret = DialogBox(Globals.hInstance,
116 bMove ? STRING_MOVE : STRING_COPY,
117 Globals.hMainWnd, lpfnDlg);
118 FreeProcInstance(lpfnDlg);
120 return((ret == IDOK) ? CopyMove.hToGroup : 0);
123 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
125 * DIALOG_COPY_MOVE_DlgProc
128 static INT_PTR CALLBACK DIALOG_COPY_MOVE_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
130 HLOCAL hGroup;
132 switch (msg)
134 case WM_INITDIALOG:
135 /* List all group names */
136 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
137 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_ADDSTRING, 0,
138 (LPARAM) GROUP_GroupName(hGroup));
140 SetDlgItemText(hDlg, PM_PROGRAM, CopyMove.lpszProgramName);
141 SetDlgItemText(hDlg, PM_FROM_GROUP, CopyMove.lpszFromGroupName);
142 break;
144 case WM_COMMAND:
145 switch (wParam)
147 case IDOK:
149 /* Get selected group */
150 INT nCurSel = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETCURSEL, 0, 0);
151 INT nLen = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXTLEN, nCurSel, 0);
152 HLOCAL hBuffer = LocalAlloc(LMEM_FIXED, nLen + 1);
153 LPSTR buffer = LocalLock(hBuffer);
155 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXT, nCurSel, (LPARAM)buffer);
156 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
157 if (!lstrcmp(buffer, GROUP_GroupName(hGroup))) break;
158 LocalFree(hBuffer);
160 CopyMove.hToGroup = hGroup;
161 EndDialog(hDlg, IDOK);
162 return TRUE;
165 case IDCANCEL:
166 EndDialog(hDlg, IDCANCEL);
167 return TRUE;
170 return FALSE;
173 /***********************************************************************
175 * DIALOG_Delete
178 BOOL DIALOG_Delete(UINT ids_text_s, LPCSTR lpszName)
180 return (IDYES == MAIN_MessageBoxIDS_s(ids_text_s, lpszName, IDS_DELETE,
181 MB_YESNO | MB_DEFBUTTON2));
185 /***********************************************************************
187 * DIALOG_GroupAttributes
190 static struct
192 LPSTR lpszTitle, lpszGrpFile;
193 INT nSize;
194 } GroupAttributes;
196 BOOL DIALOG_GroupAttributes(LPSTR lpszTitle, LPSTR lpszGrpFile, INT nSize)
198 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_GROUP_DlgProc, Globals.hInstance);
199 INT ret;
201 GroupAttributes.nSize = nSize;
202 GroupAttributes.lpszTitle = lpszTitle;
203 GroupAttributes.lpszGrpFile = lpszGrpFile;
205 ret = DialogBox(Globals.hInstance, STRING_GROUP,
206 Globals.hMainWnd, lpfnDlg);
207 FreeProcInstance(lpfnDlg);
208 return(ret == IDOK);
211 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
213 * DIALOG_GROUP_DlgProc
216 static INT_PTR CALLBACK DIALOG_GROUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
218 switch (msg)
220 case WM_INITDIALOG:
221 SetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle);
222 SetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile);
223 break;
225 case WM_COMMAND:
226 switch (wParam)
228 case IDOK:
229 GetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle,
230 GroupAttributes.nSize);
231 GetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile,
232 GroupAttributes.nSize);
233 EndDialog(hDlg, IDOK);
234 return TRUE;
236 case IDCANCEL:
237 EndDialog(hDlg, IDCANCEL);
238 return TRUE;
241 return FALSE;
244 /***********************************************************************
246 * DIALOG_ProgramAttributes
249 static struct
251 LPSTR lpszTitle, lpszCmdLine, lpszWorkDir, lpszIconFile, lpszTmpIconFile;
252 INT nSize;
253 INT *lpnCmdShow;
254 INT *lpnHotKey;
255 HWND hSelGroupWnd;
256 HICON *lphIcon, hTmpIcon;
257 INT *lpnIconIndex, nTmpIconIndex;
258 } ProgramAttributes;
260 BOOL DIALOG_ProgramAttributes(LPSTR lpszTitle, LPSTR lpszCmdLine,
261 LPSTR lpszWorkDir, LPSTR lpszIconFile,
262 HICON *lphIcon, INT *lpnIconIndex,
263 INT *lpnHotKey, INT *lpnCmdShow, INT nSize)
265 CHAR szTmpIconFile[MAX_PATHNAME_LEN];
266 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_PROGRAM_DlgProc, Globals.hInstance);
267 INT ret;
269 ProgramAttributes.nSize = nSize;
270 ProgramAttributes.lpszTitle = lpszTitle;
271 ProgramAttributes.lpszCmdLine = lpszCmdLine;
272 ProgramAttributes.lpszWorkDir = lpszWorkDir;
273 ProgramAttributes.lpszIconFile = lpszIconFile;
274 ProgramAttributes.lpnCmdShow = lpnCmdShow;
275 ProgramAttributes.lpnHotKey = lpnHotKey;
276 ProgramAttributes.lphIcon = lphIcon;
277 ProgramAttributes.lpnIconIndex = lpnIconIndex;
279 #if 0
280 ProgramAttributes.hTmpIcon = 0;
281 #else
282 ProgramAttributes.hTmpIcon = *lphIcon;
283 #endif
284 ProgramAttributes.nTmpIconIndex = *lpnIconIndex;
285 ProgramAttributes.lpszTmpIconFile = szTmpIconFile;
286 lstrcpyn(ProgramAttributes.lpszTmpIconFile, lpszIconFile, MAX_PATHNAME_LEN);
288 ret = DialogBox(Globals.hInstance, STRING_PROGRAM,
289 Globals.hMainWnd, lpfnDlg);
290 FreeProcInstance(lpfnDlg);
292 return(ret == IDOK);
295 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
297 * DIALOG_PROGRAM_DlgProc
300 static INT_PTR CALLBACK DIALOG_PROGRAM_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
302 CHAR buffer[MAX_STRING_LEN];
303 switch (msg)
305 case WM_INITDIALOG:
306 SetDlgItemText(hDlg, PM_DESCRIPTION, ProgramAttributes.lpszTitle);
307 SetDlgItemText(hDlg, PM_COMMAND_LINE, ProgramAttributes.lpszCmdLine);
308 SetDlgItemText(hDlg, PM_DIRECTORY, ProgramAttributes.lpszWorkDir);
309 if (!*ProgramAttributes.lpnHotKey)
311 LoadString(Globals.hInstance, IDS_NO_HOT_KEY, buffer, sizeof(buffer));
312 SetDlgItemText(hDlg, PM_HOT_KEY, buffer);
315 CheckDlgButton(hDlg, PM_SYMBOL,
316 (*ProgramAttributes.lpnCmdShow == SW_SHOWMINIMIZED));
317 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
318 (WPARAM) ProgramAttributes.hTmpIcon, 0);
319 break;
321 case WM_COMMAND:
322 switch (wParam)
324 case PM_SYMBOL:
325 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
326 return TRUE;
328 case PM_BROWSE:
330 CHAR filename[MAX_PATHNAME_LEN];
331 filename[0] = 0;
332 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
333 SetDlgItemText(hDlg, PM_COMMAND_LINE, filename);
334 return TRUE;
337 case PM_OTHER_SYMBOL:
339 DIALOG_Symbol(&ProgramAttributes.hTmpIcon,
340 ProgramAttributes.lpszTmpIconFile,
341 &ProgramAttributes.nTmpIconIndex,
342 MAX_PATHNAME_LEN);
344 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
345 (WPARAM) ProgramAttributes.hTmpIcon, 0);
346 return TRUE;
349 case IDOK:
350 GetDlgItemText(hDlg, PM_DESCRIPTION,
351 ProgramAttributes.lpszTitle,
352 ProgramAttributes.nSize);
353 GetDlgItemText(hDlg, PM_COMMAND_LINE,
354 ProgramAttributes.lpszCmdLine,
355 ProgramAttributes.nSize);
356 GetDlgItemText(hDlg, PM_DIRECTORY,
357 ProgramAttributes.lpszWorkDir,
358 ProgramAttributes.nSize);
360 if (ProgramAttributes.hTmpIcon)
362 #if 0
363 if (*ProgramAttributes.lphIcon)
364 DestroyIcon(*ProgramAttributes.lphIcon);
365 #endif
366 *ProgramAttributes.lphIcon = ProgramAttributes.hTmpIcon;
367 *ProgramAttributes.lpnIconIndex = ProgramAttributes.nTmpIconIndex;
368 lstrcpyn(ProgramAttributes.lpszIconFile,
369 ProgramAttributes.lpszTmpIconFile,
370 ProgramAttributes.nSize);
373 *ProgramAttributes.lpnCmdShow =
374 IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
375 SW_SHOWMINIMIZED : SW_SHOWNORMAL;
376 EndDialog(hDlg, IDOK);
377 return TRUE;
379 case IDCANCEL:
380 EndDialog(hDlg, IDCANCEL);
381 return TRUE;
383 return FALSE;
385 return FALSE;
388 /***********************************************************************
390 * DIALOG_Symbol
393 static struct
395 LPSTR lpszIconFile;
396 INT nSize;
397 HICON *lphIcon;
398 INT *lpnIconIndex;
399 } Symbol;
401 VOID DIALOG_Symbol(HICON *lphIcon, LPSTR lpszIconFile,
402 INT *lpnIconIndex, INT nSize)
404 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_SYMBOL_DlgProc, Globals.hInstance);
406 Symbol.nSize = nSize;
407 Symbol.lpszIconFile = lpszIconFile;
408 Symbol.lphIcon = lphIcon;
409 Symbol.lpnIconIndex = lpnIconIndex;
411 DialogBox(Globals.hInstance, STRING_SYMBOL,
412 Globals.hMainWnd, lpfnDlg);
413 FreeProcInstance(lpfnDlg);
416 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
418 * DIALOG_SYMBOL_DlgProc
421 static INT_PTR CALLBACK DIALOG_SYMBOL_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
423 switch (msg)
425 case WM_INITDIALOG:
426 SetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile);
427 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETITEMHEIGHT, 0, (LPARAM) 32);
428 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)*Symbol.lphIcon);
429 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)Globals.hDefaultIcon);
430 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETCURSEL, 0, 0);
431 return TRUE;
433 case WM_MEASUREITEM:
435 PMEASUREITEMSTRUCT measure = (PMEASUREITEMSTRUCT) lParam;
436 measure->itemWidth = 32;
437 measure->itemHeight = 32;
438 return TRUE;
441 case WM_DRAWITEM:
443 PDRAWITEMSTRUCT dis = (PDRAWITEMSTRUCT) lParam;
444 DrawIcon(dis->hDC, dis->rcItem.left, dis->rcItem.top, (HICON)dis->itemData);
445 return TRUE;
448 case WM_COMMAND:
449 switch (wParam)
451 case PM_BROWSE:
453 CHAR filename[MAX_PATHNAME_LEN];
454 filename[0] = 0;
455 if (DIALOG_BrowseSymbols(hDlg, filename, sizeof(filename)))
456 SetDlgItemText(hDlg, PM_ICON_FILE, filename);
457 return TRUE;
460 case PM_HELP:
461 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
462 return TRUE;
464 case IDOK:
466 INT nCurSel = SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_GETCURSEL, 0, 0);
468 GetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile, Symbol.nSize);
470 *Symbol.lphIcon = (HICON)SendDlgItemMessage(hDlg, PM_SYMBOL_LIST,
471 CB_GETITEMDATA,
472 (WPARAM) nCurSel, 0);
473 #if 0
474 *Symbol.lphIcon = CopyIcon(*Symbol.lphIcon);
475 #endif
477 EndDialog(hDlg, IDOK);
478 return TRUE;
481 case IDCANCEL:
482 EndDialog(hDlg, IDCANCEL);
483 return TRUE;
486 return FALSE;
489 /***********************************************************************
491 * DIALOG_Execute
494 VOID DIALOG_Execute(void)
496 INT_PTR z;
497 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_EXECUTE_DlgProc, Globals.hInstance);
498 z=DialogBox(Globals.hInstance, STRING_EXECUTE,
499 Globals.hMainWnd, lpfnDlg);
500 FreeProcInstance(lpfnDlg);
503 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
505 * DIALOG_EXECUTE_DlgProc
508 static INT_PTR CALLBACK DIALOG_EXECUTE_DlgProc(HWND hDlg, UINT msg,
509 WPARAM wParam, LPARAM lParam)
511 switch (msg)
513 case WM_COMMAND:
514 switch (wParam)
516 case PM_SYMBOL:
517 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
518 return TRUE;
520 case PM_BROWSE:
522 CHAR filename[MAX_PATHNAME_LEN];
523 filename[0] = 0;
524 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
525 SetDlgItemText(hDlg, PM_COMMAND, filename);
526 return TRUE;
529 case PM_HELP:
530 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
531 return TRUE;
533 case IDOK:
535 CHAR cmdline[MAX_PATHNAME_LEN];
536 GetDlgItemText(hDlg, PM_COMMAND, cmdline, sizeof(cmdline));
538 WinExec(cmdline, IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
539 SW_SHOWMINIMIZED : SW_SHOWNORMAL);
540 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
542 EndDialog(hDlg, IDOK);
543 return TRUE;
546 case IDCANCEL:
547 EndDialog(hDlg, IDCANCEL);
548 return TRUE;
551 return FALSE;
554 /***********************************************************************
556 * DIALOG_Browse
559 static BOOL DIALOG_Browse(HWND hDlg, LPCSTR lpszzFilter,
560 LPSTR lpstrFile, INT nMaxFile)
563 OPENFILENAME openfilename;
565 CHAR szDir[MAX_PATH];
566 CHAR szDefaultExt[] = "exe";
568 ZeroMemory(&openfilename, sizeof(openfilename));
570 GetCurrentDirectory(sizeof(szDir), szDir);
572 openfilename.lStructSize = sizeof(openfilename);
573 openfilename.hwndOwner = Globals.hMainWnd;
574 openfilename.hInstance = Globals.hInstance;
575 openfilename.lpstrFilter = lpszzFilter;
576 openfilename.lpstrFile = lpstrFile;
577 openfilename.nMaxFile = nMaxFile;
578 openfilename.lpstrInitialDir = szDir;
579 openfilename.Flags = 0;
580 openfilename.lpstrDefExt = szDefaultExt;
581 openfilename.lpstrCustomFilter = 0;
582 openfilename.nMaxCustFilter = 0;
583 openfilename.nFilterIndex = 0;
584 openfilename.lpstrFileTitle = 0;
585 openfilename.nMaxFileTitle = 0;
586 openfilename.lpstrInitialDir = 0;
587 openfilename.lpstrTitle = 0;
588 openfilename.nFileOffset = 0;
589 openfilename.nFileExtension = 0;
590 openfilename.lCustData = 0;
591 openfilename.lpfnHook = 0;
592 openfilename.lpTemplateName = 0;
594 return GetOpenFileName(&openfilename);
597 /***********************************************************************
599 * DIALOG_AddFilterItem
602 static VOID DIALOG_AddFilterItem(LPSTR *p, UINT ids, LPCSTR filter)
604 LoadString(Globals.hInstance, ids, *p, MAX_STRING_LEN);
605 *p += strlen(*p) + 1;
606 lstrcpy(*p, filter);
607 *p += strlen(*p) + 1;
608 **p = '\0';
611 /***********************************************************************
613 * DIALOG_BrowsePrograms
616 static BOOL DIALOG_BrowsePrograms(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
618 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
619 LPSTR p = szzFilter;
621 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe;*.pif;*.com;*.bat");
622 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
624 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
627 /***********************************************************************
629 * DIALOG_BrowseSymbols
632 static BOOL DIALOG_BrowseSymbols(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
634 CHAR szzFilter[5 * MAX_STRING_LEN + 100];
635 LPSTR p = szzFilter;
637 DIALOG_AddFilterItem(&p, IDS_SYMBOL_FILES, "*.ico;*.exe;*.dll");
638 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe");
639 DIALOG_AddFilterItem(&p, IDS_LIBRARIES_DLL, "*.dll");
640 DIALOG_AddFilterItem(&p, IDS_SYMBOLS_ICO, "*.ico");
641 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
643 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
646 /* Local Variables: */
647 /* c-file-style: "GNU" */
648 /* End: */