winemaker: Ignore the Global section.
[wine/testsucceed.git] / programs / progman / dialog.c
blob65eae87aa633602385591cee6182cf66ec922ea2
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"
30 /***********************************************************************
32 * DIALOG_Browse
35 static BOOL DIALOG_Browse(HWND hDlg, LPCSTR lpszzFilter,
36 LPSTR lpstrFile, INT nMaxFile)
39 OPENFILENAME openfilename;
41 CHAR szDir[MAX_PATH];
42 CHAR szDefaultExt[] = "exe";
44 ZeroMemory(&openfilename, sizeof(openfilename));
46 GetCurrentDirectory(sizeof(szDir), szDir);
48 openfilename.lStructSize = sizeof(openfilename);
49 openfilename.hwndOwner = Globals.hMainWnd;
50 openfilename.hInstance = Globals.hInstance;
51 openfilename.lpstrFilter = lpszzFilter;
52 openfilename.lpstrFile = lpstrFile;
53 openfilename.nMaxFile = nMaxFile;
54 openfilename.lpstrInitialDir = szDir;
55 openfilename.Flags = 0;
56 openfilename.lpstrDefExt = szDefaultExt;
57 openfilename.lpstrCustomFilter = 0;
58 openfilename.nMaxCustFilter = 0;
59 openfilename.nFilterIndex = 0;
60 openfilename.lpstrFileTitle = 0;
61 openfilename.nMaxFileTitle = 0;
62 openfilename.lpstrInitialDir = 0;
63 openfilename.lpstrTitle = 0;
64 openfilename.nFileOffset = 0;
65 openfilename.nFileExtension = 0;
66 openfilename.lCustData = 0;
67 openfilename.lpfnHook = 0;
68 openfilename.lpTemplateName = 0;
70 return GetOpenFileName(&openfilename);
73 /***********************************************************************
75 * DIALOG_AddFilterItem
78 static VOID DIALOG_AddFilterItem(LPSTR *p, UINT ids, LPCSTR filter)
80 LoadString(Globals.hInstance, ids, *p, MAX_STRING_LEN);
81 *p += strlen(*p) + 1;
82 lstrcpy(*p, filter);
83 *p += strlen(*p) + 1;
84 **p = '\0';
87 /***********************************************************************
89 * DIALOG_BrowsePrograms
92 static BOOL DIALOG_BrowsePrograms(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
94 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
95 LPSTR p = szzFilter;
97 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe;*.pif;*.com;*.bat");
98 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
100 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
103 /***********************************************************************
105 * DIALOG_BrowseSymbols
108 static BOOL DIALOG_BrowseSymbols(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
110 CHAR szzFilter[5 * MAX_STRING_LEN + 100];
111 LPSTR p = szzFilter;
113 DIALOG_AddFilterItem(&p, IDS_SYMBOL_FILES, "*.ico;*.exe;*.dll");
114 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe");
115 DIALOG_AddFilterItem(&p, IDS_LIBRARIES_DLL, "*.dll");
116 DIALOG_AddFilterItem(&p, IDS_SYMBOLS_ICO, "*.ico");
117 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
119 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
122 static struct
124 INT nDefault;
125 } New;
127 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
129 * DIALOG_NEW_DlgProc
131 static INT_PTR CALLBACK DIALOG_NEW_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
133 switch (msg)
135 case WM_INITDIALOG:
136 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, New.nDefault);
137 break;
139 case WM_COMMAND:
140 switch (wParam)
142 case PM_NEW_GROUP:
143 case PM_NEW_PROGRAM:
144 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, wParam);
145 return TRUE;
147 case IDOK:
148 EndDialog(hDlg, IsDlgButtonChecked(hDlg, PM_NEW_GROUP) ?
149 PM_NEW_GROUP : PM_NEW_PROGRAM);
150 return TRUE;
152 case IDCANCEL:
153 EndDialog(hDlg, IDCANCEL);
154 return TRUE;
157 return FALSE;
160 /***********************************************************************
162 * DIALOG_New
164 INT DIALOG_New(INT nDefault)
166 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_NEW_DlgProc, Globals.hInstance);
167 INT ret;
169 New.nDefault = nDefault;
171 ret = DialogBox(Globals.hInstance, STRING_NEW,
172 Globals.hMainWnd, lpfnDlg);
173 FreeProcInstance(lpfnDlg);
174 return ret;
178 static struct
180 LPCSTR lpszProgramName, lpszFromGroupName;
181 HLOCAL hToGroup;
182 } CopyMove;
184 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
186 * DIALOG_COPY_MOVE_DlgProc
188 static INT_PTR CALLBACK DIALOG_COPY_MOVE_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
190 HLOCAL hGroup;
192 switch (msg)
194 case WM_INITDIALOG:
195 /* List all group names */
196 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
197 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_ADDSTRING, 0,
198 (LPARAM) GROUP_GroupName(hGroup));
200 SetDlgItemText(hDlg, PM_PROGRAM, CopyMove.lpszProgramName);
201 SetDlgItemText(hDlg, PM_FROM_GROUP, CopyMove.lpszFromGroupName);
202 break;
204 case WM_COMMAND:
205 switch (wParam)
207 case IDOK:
209 /* Get selected group */
210 INT nCurSel = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETCURSEL, 0, 0);
211 INT nLen = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXTLEN, nCurSel, 0);
212 HLOCAL hBuffer = LocalAlloc(LMEM_FIXED, nLen + 1);
213 LPSTR buffer = LocalLock(hBuffer);
215 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXT, nCurSel, (LPARAM)buffer);
216 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
217 if (!lstrcmp(buffer, GROUP_GroupName(hGroup))) break;
218 LocalFree(hBuffer);
220 CopyMove.hToGroup = hGroup;
221 EndDialog(hDlg, IDOK);
222 return TRUE;
225 case IDCANCEL:
226 EndDialog(hDlg, IDCANCEL);
227 return TRUE;
230 return FALSE;
233 /***********************************************************************
235 * DIALOG_CopyMove
237 HLOCAL DIALOG_CopyMove(LPCSTR lpszProgramName, LPCSTR lpszFromGroupName,
238 BOOL bMove)
240 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_COPY_MOVE_DlgProc, Globals.hInstance);
241 INT ret;
243 CopyMove.lpszProgramName = lpszProgramName;
244 CopyMove.lpszFromGroupName = lpszFromGroupName;
245 CopyMove.hToGroup = 0;
247 ret = DialogBox(Globals.hInstance,
248 bMove ? STRING_MOVE : STRING_COPY,
249 Globals.hMainWnd, lpfnDlg);
250 FreeProcInstance(lpfnDlg);
252 return((ret == IDOK) ? CopyMove.hToGroup : 0);
255 /***********************************************************************
257 * DIALOG_Delete
260 BOOL DIALOG_Delete(UINT ids_text_s, LPCSTR lpszName)
262 return (IDYES == MAIN_MessageBoxIDS_s(ids_text_s, lpszName, IDS_DELETE,
263 MB_YESNO | MB_DEFBUTTON2));
267 static struct
269 LPSTR lpszTitle, lpszGrpFile;
270 INT nSize;
271 } GroupAttributes;
273 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
275 * DIALOG_GROUP_DlgProc
277 static INT_PTR CALLBACK DIALOG_GROUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
279 switch (msg)
281 case WM_INITDIALOG:
282 SetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle);
283 SetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile);
284 break;
286 case WM_COMMAND:
287 switch (wParam)
289 case IDOK:
290 GetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle,
291 GroupAttributes.nSize);
292 GetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile,
293 GroupAttributes.nSize);
294 EndDialog(hDlg, IDOK);
295 return TRUE;
297 case IDCANCEL:
298 EndDialog(hDlg, IDCANCEL);
299 return TRUE;
302 return FALSE;
305 /***********************************************************************
307 * DIALOG_GroupAttributes
309 BOOL DIALOG_GroupAttributes(LPSTR lpszTitle, LPSTR lpszGrpFile, INT nSize)
311 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_GROUP_DlgProc, Globals.hInstance);
312 INT ret;
314 GroupAttributes.nSize = nSize;
315 GroupAttributes.lpszTitle = lpszTitle;
316 GroupAttributes.lpszGrpFile = lpszGrpFile;
318 ret = DialogBox(Globals.hInstance, STRING_GROUP,
319 Globals.hMainWnd, lpfnDlg);
320 FreeProcInstance(lpfnDlg);
321 return(ret == IDOK);
325 static struct
327 LPSTR lpszIconFile;
328 INT nSize;
329 HICON *lphIcon;
330 INT *lpnIconIndex;
331 } Symbol;
333 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
335 * DIALOG_SYMBOL_DlgProc
337 static INT_PTR CALLBACK DIALOG_SYMBOL_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
339 switch (msg)
341 case WM_INITDIALOG:
342 SetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile);
343 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETITEMHEIGHT, 0, (LPARAM) 32);
344 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)*Symbol.lphIcon);
345 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)Globals.hDefaultIcon);
346 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETCURSEL, 0, 0);
347 return TRUE;
349 case WM_MEASUREITEM:
351 PMEASUREITEMSTRUCT measure = (PMEASUREITEMSTRUCT) lParam;
352 measure->itemWidth = 32;
353 measure->itemHeight = 32;
354 return TRUE;
357 case WM_DRAWITEM:
359 PDRAWITEMSTRUCT dis = (PDRAWITEMSTRUCT) lParam;
360 DrawIcon(dis->hDC, dis->rcItem.left, dis->rcItem.top, (HICON)dis->itemData);
361 return TRUE;
364 case WM_COMMAND:
365 switch (wParam)
367 case PM_BROWSE:
369 CHAR filename[MAX_PATHNAME_LEN];
370 filename[0] = 0;
371 if (DIALOG_BrowseSymbols(hDlg, filename, sizeof(filename)))
372 SetDlgItemText(hDlg, PM_ICON_FILE, filename);
373 return TRUE;
376 case PM_HELP:
377 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
378 return TRUE;
380 case IDOK:
382 INT nCurSel = SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_GETCURSEL, 0, 0);
384 GetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile, Symbol.nSize);
386 *Symbol.lphIcon = (HICON)SendDlgItemMessage(hDlg, PM_SYMBOL_LIST,
387 CB_GETITEMDATA,
388 (WPARAM) nCurSel, 0);
389 #if 0
390 *Symbol.lphIcon = CopyIcon(*Symbol.lphIcon);
391 #endif
393 EndDialog(hDlg, IDOK);
394 return TRUE;
397 case IDCANCEL:
398 EndDialog(hDlg, IDCANCEL);
399 return TRUE;
402 return FALSE;
405 /***********************************************************************
407 * DIALOG_Symbol
409 static VOID DIALOG_Symbol(HICON *lphIcon, LPSTR lpszIconFile,
410 INT *lpnIconIndex, INT nSize)
412 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_SYMBOL_DlgProc, Globals.hInstance);
414 Symbol.nSize = nSize;
415 Symbol.lpszIconFile = lpszIconFile;
416 Symbol.lphIcon = lphIcon;
417 Symbol.lpnIconIndex = lpnIconIndex;
419 DialogBox(Globals.hInstance, STRING_SYMBOL,
420 Globals.hMainWnd, lpfnDlg);
421 FreeProcInstance(lpfnDlg);
425 static struct
427 LPSTR lpszTitle, lpszCmdLine, lpszWorkDir, lpszIconFile, lpszTmpIconFile;
428 INT nSize;
429 INT *lpnCmdShow;
430 INT *lpnHotKey;
431 HWND hSelGroupWnd;
432 HICON *lphIcon, hTmpIcon;
433 INT *lpnIconIndex, nTmpIconIndex;
434 } ProgramAttributes;
436 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
438 * DIALOG_PROGRAM_DlgProc
440 static INT_PTR CALLBACK DIALOG_PROGRAM_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
442 CHAR buffer[MAX_STRING_LEN];
443 switch (msg)
445 case WM_INITDIALOG:
446 SetDlgItemText(hDlg, PM_DESCRIPTION, ProgramAttributes.lpszTitle);
447 SetDlgItemText(hDlg, PM_COMMAND_LINE, ProgramAttributes.lpszCmdLine);
448 SetDlgItemText(hDlg, PM_DIRECTORY, ProgramAttributes.lpszWorkDir);
449 if (!*ProgramAttributes.lpnHotKey)
451 LoadString(Globals.hInstance, IDS_NO_HOT_KEY, buffer, sizeof(buffer));
452 SetDlgItemText(hDlg, PM_HOT_KEY, buffer);
455 CheckDlgButton(hDlg, PM_SYMBOL,
456 (*ProgramAttributes.lpnCmdShow == SW_SHOWMINIMIZED));
457 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
458 (WPARAM) ProgramAttributes.hTmpIcon, 0);
459 break;
461 case WM_COMMAND:
462 switch (wParam)
464 case PM_SYMBOL:
465 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
466 return TRUE;
468 case PM_BROWSE:
470 CHAR filename[MAX_PATHNAME_LEN];
471 filename[0] = 0;
472 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
473 SetDlgItemText(hDlg, PM_COMMAND_LINE, filename);
474 return TRUE;
477 case PM_OTHER_SYMBOL:
479 DIALOG_Symbol(&ProgramAttributes.hTmpIcon,
480 ProgramAttributes.lpszTmpIconFile,
481 &ProgramAttributes.nTmpIconIndex,
482 MAX_PATHNAME_LEN);
484 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
485 (WPARAM) ProgramAttributes.hTmpIcon, 0);
486 return TRUE;
489 case IDOK:
490 GetDlgItemText(hDlg, PM_DESCRIPTION,
491 ProgramAttributes.lpszTitle,
492 ProgramAttributes.nSize);
493 GetDlgItemText(hDlg, PM_COMMAND_LINE,
494 ProgramAttributes.lpszCmdLine,
495 ProgramAttributes.nSize);
496 GetDlgItemText(hDlg, PM_DIRECTORY,
497 ProgramAttributes.lpszWorkDir,
498 ProgramAttributes.nSize);
500 if (ProgramAttributes.hTmpIcon)
502 #if 0
503 if (*ProgramAttributes.lphIcon)
504 DestroyIcon(*ProgramAttributes.lphIcon);
505 #endif
506 *ProgramAttributes.lphIcon = ProgramAttributes.hTmpIcon;
507 *ProgramAttributes.lpnIconIndex = ProgramAttributes.nTmpIconIndex;
508 lstrcpyn(ProgramAttributes.lpszIconFile,
509 ProgramAttributes.lpszTmpIconFile,
510 ProgramAttributes.nSize);
513 *ProgramAttributes.lpnCmdShow =
514 IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
515 SW_SHOWMINIMIZED : SW_SHOWNORMAL;
516 EndDialog(hDlg, IDOK);
517 return TRUE;
519 case IDCANCEL:
520 EndDialog(hDlg, IDCANCEL);
521 return TRUE;
523 return FALSE;
525 return FALSE;
528 /***********************************************************************
530 * DIALOG_ProgramAttributes
532 BOOL DIALOG_ProgramAttributes(LPSTR lpszTitle, LPSTR lpszCmdLine,
533 LPSTR lpszWorkDir, LPSTR lpszIconFile,
534 HICON *lphIcon, INT *lpnIconIndex,
535 INT *lpnHotKey, INT *lpnCmdShow, INT nSize)
537 CHAR szTmpIconFile[MAX_PATHNAME_LEN];
538 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_PROGRAM_DlgProc, Globals.hInstance);
539 INT ret;
541 ProgramAttributes.nSize = nSize;
542 ProgramAttributes.lpszTitle = lpszTitle;
543 ProgramAttributes.lpszCmdLine = lpszCmdLine;
544 ProgramAttributes.lpszWorkDir = lpszWorkDir;
545 ProgramAttributes.lpszIconFile = lpszIconFile;
546 ProgramAttributes.lpnCmdShow = lpnCmdShow;
547 ProgramAttributes.lpnHotKey = lpnHotKey;
548 ProgramAttributes.lphIcon = lphIcon;
549 ProgramAttributes.lpnIconIndex = lpnIconIndex;
551 #if 0
552 ProgramAttributes.hTmpIcon = 0;
553 #else
554 ProgramAttributes.hTmpIcon = *lphIcon;
555 #endif
556 ProgramAttributes.nTmpIconIndex = *lpnIconIndex;
557 ProgramAttributes.lpszTmpIconFile = szTmpIconFile;
558 lstrcpyn(ProgramAttributes.lpszTmpIconFile, lpszIconFile, MAX_PATHNAME_LEN);
560 ret = DialogBox(Globals.hInstance, STRING_PROGRAM,
561 Globals.hMainWnd, lpfnDlg);
562 FreeProcInstance(lpfnDlg);
564 return(ret == IDOK);
568 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
570 * DIALOG_EXECUTE_DlgProc
572 static INT_PTR CALLBACK DIALOG_EXECUTE_DlgProc(HWND hDlg, UINT msg,
573 WPARAM wParam, LPARAM lParam)
575 switch (msg)
577 case WM_COMMAND:
578 switch (wParam)
580 case PM_SYMBOL:
581 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
582 return TRUE;
584 case PM_BROWSE:
586 CHAR filename[MAX_PATHNAME_LEN];
587 filename[0] = 0;
588 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
589 SetDlgItemText(hDlg, PM_COMMAND, filename);
590 return TRUE;
593 case PM_HELP:
594 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
595 return TRUE;
597 case IDOK:
599 CHAR cmdline[MAX_PATHNAME_LEN];
600 GetDlgItemText(hDlg, PM_COMMAND, cmdline, sizeof(cmdline));
602 WinExec(cmdline, IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
603 SW_SHOWMINIMIZED : SW_SHOWNORMAL);
604 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
606 EndDialog(hDlg, IDOK);
607 return TRUE;
610 case IDCANCEL:
611 EndDialog(hDlg, IDCANCEL);
612 return TRUE;
615 return FALSE;
618 /***********************************************************************
620 * DIALOG_Execute
623 VOID DIALOG_Execute(void)
625 DLGPROC lpfnDlg = MakeProcInstance(DIALOG_EXECUTE_DlgProc, Globals.hInstance);
626 DialogBox(Globals.hInstance, STRING_EXECUTE, Globals.hMainWnd, lpfnDlg);
627 FreeProcInstance(lpfnDlg);
630 /* Local Variables: */
631 /* c-file-style: "GNU" */
632 /* End: */