Optimized implementation of LoadStringA.
[wine/multimedia.git] / programs / progman / dialog.c
blob107462ab3f16e12a6daf64721cf67421996d2d6c
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
5 */
7 #include "windows.h"
8 #include "commdlg.h"
9 #include "progman.h"
11 static BOOL DIALOG_BrowsePrograms(HWND, LPSTR, INT);
12 static BOOL DIALOG_BrowseSymbols(HWND, LPSTR, INT);
13 static LRESULT DIALOG_NEW_DlgProc(HWND, UINT, WPARAM, LPARAM);
14 static LRESULT DIALOG_COPY_MOVE_DlgProc(HWND, UINT, WPARAM, LPARAM);
15 static LRESULT DIALOG_GROUP_DlgProc(HWND, UINT, WPARAM, LPARAM);
16 static LRESULT DIALOG_PROGRAM_DlgProc(HWND, UINT, WPARAM, LPARAM);
17 static LRESULT DIALOG_SYMBOL_DlgProc(HWND, UINT, WPARAM, LPARAM);
18 static LRESULT DIALOG_EXECUTE_DlgProc(HWND, UINT, WPARAM, LPARAM);
20 /***********************************************************************
22 * DIALOG_New
25 static struct
27 INT nDefault;
28 } New;
30 INT DIALOG_New(INT nDefault)
32 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_NEW_DlgProc, Globals.hInstance);
33 INT ret;
35 New.nDefault = nDefault;
37 ret = DialogBox(Globals.hInstance, STRING_NEW_Xx,
38 Globals.hMainWnd, (DLGPROC)lpfnDlg);
39 FreeProcInstance(lpfnDlg);
40 return ret;
43 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
45 * DIALOG_NEW_DlgProc
48 static LRESULT DIALOG_NEW_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
50 switch (msg)
52 case WM_INITDIALOG:
53 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, New.nDefault);
54 break;
56 case WM_COMMAND:
57 switch (wParam)
59 case PM_NEW_GROUP:
60 case PM_NEW_PROGRAM:
61 CheckRadioButton(hDlg, PM_NEW_GROUP, PM_NEW_PROGRAM, wParam);
62 return TRUE;
64 case IDOK:
65 EndDialog(hDlg, IsDlgButtonChecked(hDlg, PM_NEW_GROUP) ?
66 PM_NEW_GROUP : PM_NEW_PROGRAM);
67 return TRUE;
69 case IDCANCEL:
70 EndDialog(hDlg, IDCANCEL);
71 return TRUE;
74 return FALSE;
77 /***********************************************************************
79 * DIALOG_CopyMove
82 static struct
84 LPCSTR lpszProgramName, lpszFromGroupName;
85 HLOCAL hToGroup;
86 } CopyMove;
88 HLOCAL DIALOG_CopyMove(LPCSTR lpszProgramName, LPCSTR lpszFromGroupName,
89 BOOL bMove)
91 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_COPY_MOVE_DlgProc, Globals.hInstance);
92 INT ret;
94 CopyMove.lpszProgramName = lpszProgramName;
95 CopyMove.lpszFromGroupName = lpszFromGroupName;
96 CopyMove.hToGroup = 0;
98 ret = DialogBox(Globals.hInstance,
99 bMove ? STRING_MOVE_Xx : STRING_COPY_Xx,
100 Globals.hMainWnd, (DLGPROC)lpfnDlg);
101 FreeProcInstance(lpfnDlg);
103 return((ret == IDOK) ? CopyMove.hToGroup : 0);
106 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
108 * DIALOG_COPY_MOVE_DlgProc
111 static LRESULT DIALOG_COPY_MOVE_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
113 HLOCAL hGroup;
115 switch (msg)
117 case WM_INITDIALOG:
118 /* List all group names */
119 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
120 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_ADDSTRING, 0,
121 (LPARAM) GROUP_GroupName(hGroup));
123 SetDlgItemText(hDlg, PM_PROGRAM, (LPSTR)CopyMove.lpszProgramName);
124 SetDlgItemText(hDlg, PM_FROM_GROUP, (LPSTR)CopyMove.lpszFromGroupName);
125 break;
127 case WM_COMMAND:
128 switch (wParam)
130 case IDOK:
132 /* Get selected group */
133 INT nCurSel = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETCURSEL, 0, 0);
134 INT nLen = SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXTLEN, nCurSel, 0);
135 HLOCAL hBuffer = LocalAlloc(LMEM_FIXED, nLen + 1);
136 LPSTR buffer = LocalLock(hBuffer);
138 SendDlgItemMessage(hDlg, PM_TO_GROUP, CB_GETLBTEXT, nCurSel, (LPARAM)buffer);
139 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
140 if (!lstrcmp(buffer, GROUP_GroupName(hGroup))) break;
141 LocalFree(hBuffer);
143 CopyMove.hToGroup = hGroup;
144 EndDialog(hDlg, IDOK);
145 return TRUE;
148 case IDCANCEL:
149 EndDialog(hDlg, IDCANCEL);
150 return TRUE;
153 return FALSE;
156 /***********************************************************************
158 * DIALOG_Delete
161 BOOL DIALOG_Delete(UINT ids_text_s, LPCSTR lpszName)
163 return (IDYES == MAIN_MessageBoxIDS_s(ids_text_s, lpszName, IDS_DELETE,
164 MB_YESNO | MB_DEFBUTTON2));
168 /***********************************************************************
170 * DIALOG_GroupAttributes
173 static struct
175 LPSTR lpszTitle, lpszGrpFile;
176 INT nSize;
177 } GroupAttributes;
179 BOOL DIALOG_GroupAttributes(LPSTR lpszTitle, LPSTR lpszGrpFile, INT nSize)
181 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_GROUP_DlgProc, Globals.hInstance);
182 INT ret;
184 GroupAttributes.nSize = nSize;
185 GroupAttributes.lpszTitle = lpszTitle;
186 GroupAttributes.lpszGrpFile = lpszGrpFile;
188 ret = DialogBox(Globals.hInstance, STRING_GROUP_Xx,
189 Globals.hMainWnd, (DLGPROC)lpfnDlg);
190 FreeProcInstance(lpfnDlg);
191 return(ret == IDOK);
194 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
196 * DIALOG_GROUP_DlgProc
199 static LRESULT DIALOG_GROUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
201 switch (msg)
203 case WM_INITDIALOG:
204 SetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle);
205 SetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile);
206 break;
208 case WM_COMMAND:
209 switch (wParam)
211 case IDOK:
212 GetDlgItemText(hDlg, PM_DESCRIPTION, GroupAttributes.lpszTitle,
213 GroupAttributes.nSize);
214 GetDlgItemText(hDlg, PM_FILE, GroupAttributes.lpszGrpFile,
215 GroupAttributes.nSize);
216 EndDialog(hDlg, IDOK);
217 return TRUE;
219 case IDCANCEL:
220 EndDialog(hDlg, IDCANCEL);
221 return TRUE;
224 return FALSE;
227 /***********************************************************************
229 * DIALOG_ProgramAttributes
232 static struct
234 LPSTR lpszTitle, lpszCmdLine, lpszWorkDir, lpszIconFile, lpszTmpIconFile;
235 INT nSize;
236 INT *lpnCmdShow;
237 INT *lpnHotKey;
238 HWND hSelGroupWnd;
239 HICON *lphIcon, hTmpIcon;
240 INT *lpnIconIndex, nTmpIconIndex;
241 } ProgramAttributes;
243 BOOL DIALOG_ProgramAttributes(LPSTR lpszTitle, LPSTR lpszCmdLine,
244 LPSTR lpszWorkDir, LPSTR lpszIconFile,
245 HICON *lphIcon, INT *lpnIconIndex,
246 INT *lpnHotKey, INT *lpnCmdShow, INT nSize)
248 CHAR szTmpIconFile[MAX_PATHNAME_LEN];
249 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_PROGRAM_DlgProc, Globals.hInstance);
250 INT ret;
252 ProgramAttributes.nSize = nSize;
253 ProgramAttributes.lpszTitle = lpszTitle;
254 ProgramAttributes.lpszCmdLine = lpszCmdLine;
255 ProgramAttributes.lpszWorkDir = lpszWorkDir;
256 ProgramAttributes.lpszIconFile = lpszIconFile;
257 ProgramAttributes.lpnCmdShow = lpnCmdShow;
258 ProgramAttributes.lpnHotKey = lpnHotKey;
259 ProgramAttributes.lphIcon = lphIcon;
260 ProgramAttributes.lpnIconIndex = lpnIconIndex;
262 #if 0
263 ProgramAttributes.hTmpIcon = 0;
264 #else
265 ProgramAttributes.hTmpIcon = *lphIcon;
266 #endif
267 ProgramAttributes.nTmpIconIndex = *lpnIconIndex;
268 ProgramAttributes.lpszTmpIconFile = szTmpIconFile;
269 lstrcpyn(ProgramAttributes.lpszTmpIconFile, lpszIconFile, MAX_PATHNAME_LEN);
271 ret = DialogBox(Globals.hInstance, STRING_PROGRAM_Xx,
272 Globals.hMainWnd, (DLGPROC)lpfnDlg);
273 FreeProcInstance(lpfnDlg);
275 return(ret == IDOK);
278 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
280 * DIALOG_PROGRAM_DlgProc
283 static LRESULT DIALOG_PROGRAM_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
285 CHAR buffer[MAX_STRING_LEN];
286 switch (msg)
288 case WM_INITDIALOG:
289 SetDlgItemText(hDlg, PM_DESCRIPTION, ProgramAttributes.lpszTitle);
290 SetDlgItemText(hDlg, PM_COMMAND_LINE, ProgramAttributes.lpszCmdLine);
291 SetDlgItemText(hDlg, PM_DIRECTORY, ProgramAttributes.lpszWorkDir);
292 if (!*ProgramAttributes.lpnHotKey)
294 LoadString(Globals.hInstance, IDS_NO_HOT_KEY, buffer, sizeof(buffer));
295 SetDlgItemText(hDlg, PM_HOT_KEY, buffer);
298 CheckDlgButton(hDlg, PM_SYMBOL,
299 (*ProgramAttributes.lpnCmdShow == SW_SHOWMINIMIZED));
300 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
301 (WPARAM) ProgramAttributes.hTmpIcon, 0);
302 break;
304 case WM_COMMAND:
305 switch (wParam)
307 case PM_SYMBOL:
308 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
309 return TRUE;
311 case PM_BROWSE:
313 CHAR filename[MAX_PATHNAME_LEN];
314 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
315 SetDlgItemText(hDlg, PM_COMMAND_LINE, filename);
316 return TRUE;
319 case PM_OTHER_SYMBOL:
321 DIALOG_Symbol(&ProgramAttributes.hTmpIcon,
322 ProgramAttributes.lpszTmpIconFile,
323 &ProgramAttributes.nTmpIconIndex,
324 MAX_PATHNAME_LEN);
326 SendDlgItemMessage(hDlg, PM_ICON, STM_SETICON,
327 (WPARAM) ProgramAttributes.hTmpIcon, 0);
328 return TRUE;
331 case IDOK:
332 GetDlgItemText(hDlg, PM_DESCRIPTION,
333 ProgramAttributes.lpszTitle,
334 ProgramAttributes.nSize);
335 GetDlgItemText(hDlg, PM_COMMAND_LINE,
336 ProgramAttributes.lpszCmdLine,
337 ProgramAttributes.nSize);
338 GetDlgItemText(hDlg, PM_DIRECTORY,
339 ProgramAttributes.lpszWorkDir,
340 ProgramAttributes.nSize);
342 if (ProgramAttributes.hTmpIcon)
344 #if 0
345 if (*ProgramAttributes.lphIcon)
346 DestroyIcon(*ProgramAttributes.lphIcon);
347 #endif
348 *ProgramAttributes.lphIcon = ProgramAttributes.hTmpIcon;
349 *ProgramAttributes.lpnIconIndex = ProgramAttributes.nTmpIconIndex;
350 lstrcpyn(ProgramAttributes.lpszIconFile,
351 ProgramAttributes.lpszTmpIconFile,
352 ProgramAttributes.nSize);
355 *ProgramAttributes.lpnCmdShow =
356 IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
357 SW_SHOWMINIMIZED : SW_SHOWNORMAL;
358 EndDialog(hDlg, IDOK);
359 return TRUE;
361 case IDCANCEL:
362 EndDialog(hDlg, IDCANCEL);
363 return TRUE;
365 return FALSE;
367 return FALSE;
370 /***********************************************************************
372 * DIALOG_Symbol
375 static struct
377 LPSTR lpszIconFile;
378 INT nSize;
379 HICON *lphIcon;
380 INT *lpnIconIndex;
381 } Symbol;
383 VOID DIALOG_Symbol(HICON *lphIcon, LPSTR lpszIconFile,
384 INT *lpnIconIndex, INT nSize)
386 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_SYMBOL_DlgProc, Globals.hInstance);
388 Symbol.nSize = nSize;
389 Symbol.lpszIconFile = lpszIconFile;
390 Symbol.lphIcon = lphIcon;
391 Symbol.lpnIconIndex = lpnIconIndex;
393 DialogBox(Globals.hInstance, STRING_SYMBOL_Xx,
394 Globals.hMainWnd, (DLGPROC)lpfnDlg);
395 FreeProcInstance(lpfnDlg);
398 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
400 * DIALOG_SYMBOL_DlgProc
403 static LRESULT DIALOG_SYMBOL_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
405 switch (msg)
407 case WM_INITDIALOG:
408 SetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile);
409 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETITEMHEIGHT, 0, (LPARAM) 32);
410 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)*Symbol.lphIcon);
411 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_ADDSTRING, 0, (LPARAM)Globals.hDefaultIcon);
412 SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_SETCURSEL, 0, 0);
413 return TRUE;
415 case WM_MEASUREITEM:
417 PMEASUREITEMSTRUCT measure = (PMEASUREITEMSTRUCT) lParam;
418 measure->itemWidth = 32;
419 measure->itemHeight = 32;
420 return TRUE;
423 case WM_DRAWITEM:
425 PDRAWITEMSTRUCT dis = (PDRAWITEMSTRUCT) lParam;
426 DrawIcon(dis->hDC, dis->rcItem.left, dis->rcItem.top, (HICON)dis->itemData);
427 return TRUE;
430 case WM_COMMAND:
431 switch (wParam)
433 case PM_BROWSE:
435 CHAR filename[MAX_PATHNAME_LEN];
436 if (DIALOG_BrowseSymbols(hDlg, filename, sizeof(filename)))
437 SetDlgItemText(hDlg, PM_ICON_FILE, filename);
438 return TRUE;
441 case PM_HELP:
442 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
443 return TRUE;
445 case IDOK:
447 INT nCurSel = SendDlgItemMessage(hDlg, PM_SYMBOL_LIST, CB_GETCURSEL, 0, 0);
449 GetDlgItemText(hDlg, PM_ICON_FILE, Symbol.lpszIconFile, Symbol.nSize);
451 *Symbol.lphIcon = (HICON)SendDlgItemMessage(hDlg, PM_SYMBOL_LIST,
452 CB_GETITEMDATA,
453 (WPARAM) nCurSel, 0);
454 #if 0
455 *Symbol.lphIcon = CopyIcon(*Symbol.lphIcon);
456 #endif
458 EndDialog(hDlg, IDOK);
459 return TRUE;
462 case IDCANCEL:
463 EndDialog(hDlg, IDCANCEL);
464 return TRUE;
467 return FALSE;
470 /***********************************************************************
472 * DIALOG_Execute
475 VOID DIALOG_Execute()
477 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_EXECUTE_DlgProc, Globals.hInstance);
478 DialogBox(Globals.hInstance, STRING_EXECUTE_Xx,
479 Globals.hMainWnd, (DLGPROC)lpfnDlg);
480 FreeProcInstance(lpfnDlg);
483 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
485 * DIALOG_EXECUTE_DlgProc
488 static LRESULT DIALOG_EXECUTE_DlgProc(HWND hDlg, UINT msg,
489 WPARAM wParam, LPARAM lParam)
491 switch (msg)
493 case WM_COMMAND:
494 switch (wParam)
496 case PM_SYMBOL:
497 CheckDlgButton(hDlg, PM_SYMBOL, !IsDlgButtonChecked(hDlg, PM_SYMBOL));
498 return TRUE;
500 case PM_BROWSE:
502 CHAR filename[MAX_PATHNAME_LEN];
503 if (DIALOG_BrowsePrograms(hDlg, filename, sizeof(filename)))
504 SetDlgItemText(hDlg, PM_COMMAND, filename);
505 return TRUE;
508 case PM_HELP:
509 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
510 return TRUE;
512 case IDOK:
514 CHAR cmdline[MAX_PATHNAME_LEN];
515 GetDlgItemText(hDlg, PM_COMMAND, cmdline, sizeof(cmdline));
517 WinExec(cmdline, IsDlgButtonChecked(hDlg, PM_SYMBOL) ?
518 SW_SHOWMINIMIZED : SW_SHOWNORMAL);
519 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
521 EndDialog(hDlg, IDOK);
522 return TRUE;
525 case IDCANCEL:
526 EndDialog(hDlg, IDCANCEL);
527 return TRUE;
530 return FALSE;
533 /***********************************************************************
535 * DIALOG_Browse
538 static BOOL DIALOG_Browse(HWND hDlg, LPCSTR lpszzFilter,
539 LPSTR lpstrFile, INT nMaxFile)
541 OPENFILENAME openfilename;
543 /* FIXME is this correct ? */
544 openfilename.lStructSize = 0;
545 openfilename.hwndOwner = hDlg;
546 openfilename.hInstance = Globals.hInstance;
547 openfilename.lpstrFilter = (LPSTR)lpszzFilter;
548 openfilename.lpstrCustomFilter = 0;
549 openfilename.nMaxCustFilter = 0;
550 openfilename.nFilterIndex = 0;
551 openfilename.lpstrFile = lpstrFile;
552 openfilename.nMaxFile = sizeof(lpstrFile);
553 openfilename.lpstrFileTitle = 0;
554 openfilename.nMaxFileTitle = 0;
555 openfilename.lpstrInitialDir = 0;
556 openfilename.lpstrTitle = 0;
557 openfilename.Flags = 0;
558 openfilename.nFileOffset = 0;
559 openfilename.nFileExtension = 0;
560 openfilename.lpstrDefExt = 0;
561 openfilename.lCustData = 0;
562 openfilename.lpfnHook = 0;
563 openfilename.lpTemplateName = 0;
564 return GetOpenFileName(&openfilename);
567 /***********************************************************************
569 * DIALOG_AddFilterItem
572 static VOID DIALOG_AddFilterItem(LPSTR *p, UINT ids, LPCSTR filter)
574 LoadString(Globals.hInstance, ids, *p, MAX_STRING_LEN);
575 *p += strlen(*p) + 1;
576 lstrcpy(*p, filter);
577 *p += strlen(*p) + 1;
578 **p = '\0';
581 /***********************************************************************
583 * DIALOG_BrowsePrograms
586 static BOOL DIALOG_BrowsePrograms(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
588 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
589 LPSTR p = szzFilter;
591 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe;*.pif;*.com;*.bat");
592 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
594 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
597 /***********************************************************************
599 * DIALOG_BrowseSymbols
602 static BOOL DIALOG_BrowseSymbols(HWND hDlg, LPSTR lpszFile, INT nMaxFile)
604 CHAR szzFilter[5 * MAX_STRING_LEN + 100];
605 LPSTR p = szzFilter;
607 DIALOG_AddFilterItem(&p, IDS_SYMBOL_FILES, "*.ico;*.exe;*.dll");
608 DIALOG_AddFilterItem(&p, IDS_PROGRAMS, "*.exe");
609 DIALOG_AddFilterItem(&p, IDS_LIBRARIES_DLL, "*.dll");
610 DIALOG_AddFilterItem(&p, IDS_SYMBOLS_ICO, "*.ico");
611 DIALOG_AddFilterItem(&p, IDS_ALL_FILES, "*.*");
613 return(DIALOG_Browse(hDlg, szzFilter, lpszFile, nMaxFile));
616 /* Local Variables: */
617 /* c-file-style: "GNU" */
618 /* End: */