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
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 /***********************************************************************
47 INT
DIALOG_New(INT nDefault
)
49 DLGPROC lpfnDlg
= MakeProcInstance(DIALOG_NEW_DlgProc
, Globals
.hInstance
);
52 New
.nDefault
= nDefault
;
54 ret
= DialogBox(Globals
.hInstance
, STRING_NEW
,
55 Globals
.hMainWnd
, lpfnDlg
);
56 FreeProcInstance(lpfnDlg
);
60 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
65 static INT_PTR CALLBACK
DIALOG_NEW_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
70 CheckRadioButton(hDlg
, PM_NEW_GROUP
, PM_NEW_PROGRAM
, New
.nDefault
);
78 CheckRadioButton(hDlg
, PM_NEW_GROUP
, PM_NEW_PROGRAM
, wParam
);
82 EndDialog(hDlg
, IsDlgButtonChecked(hDlg
, PM_NEW_GROUP
) ?
83 PM_NEW_GROUP
: PM_NEW_PROGRAM
);
87 EndDialog(hDlg
, IDCANCEL
);
94 /***********************************************************************
101 LPCSTR lpszProgramName
, lpszFromGroupName
;
105 HLOCAL
DIALOG_CopyMove(LPCSTR lpszProgramName
, LPCSTR lpszFromGroupName
,
108 DLGPROC lpfnDlg
= MakeProcInstance(DIALOG_COPY_MOVE_DlgProc
, Globals
.hInstance
);
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
)
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
);
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;
160 CopyMove
.hToGroup
= hGroup
;
161 EndDialog(hDlg
, IDOK
);
166 EndDialog(hDlg
, IDCANCEL
);
173 /***********************************************************************
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
192 LPSTR lpszTitle
, lpszGrpFile
;
196 BOOL
DIALOG_GroupAttributes(LPSTR lpszTitle
, LPSTR lpszGrpFile
, INT nSize
)
198 DLGPROC lpfnDlg
= MakeProcInstance(DIALOG_GROUP_DlgProc
, Globals
.hInstance
);
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
);
211 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
213 * DIALOG_GROUP_DlgProc
216 static INT_PTR CALLBACK
DIALOG_GROUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
221 SetDlgItemText(hDlg
, PM_DESCRIPTION
, GroupAttributes
.lpszTitle
);
222 SetDlgItemText(hDlg
, PM_FILE
, GroupAttributes
.lpszGrpFile
);
229 GetDlgItemText(hDlg
, PM_DESCRIPTION
, GroupAttributes
.lpszTitle
,
230 GroupAttributes
.nSize
);
231 GetDlgItemText(hDlg
, PM_FILE
, GroupAttributes
.lpszGrpFile
,
232 GroupAttributes
.nSize
);
233 EndDialog(hDlg
, IDOK
);
237 EndDialog(hDlg
, IDCANCEL
);
244 /***********************************************************************
246 * DIALOG_ProgramAttributes
251 LPSTR lpszTitle
, lpszCmdLine
, lpszWorkDir
, lpszIconFile
, lpszTmpIconFile
;
256 HICON
*lphIcon
, hTmpIcon
;
257 INT
*lpnIconIndex
, nTmpIconIndex
;
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
);
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
;
280 ProgramAttributes
.hTmpIcon
= 0;
282 ProgramAttributes
.hTmpIcon
= *lphIcon
;
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
);
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
];
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);
325 CheckDlgButton(hDlg
, PM_SYMBOL
, !IsDlgButtonChecked(hDlg
, PM_SYMBOL
));
330 CHAR filename
[MAX_PATHNAME_LEN
];
332 if (DIALOG_BrowsePrograms(hDlg
, filename
, sizeof(filename
)))
333 SetDlgItemText(hDlg
, PM_COMMAND_LINE
, filename
);
337 case PM_OTHER_SYMBOL
:
339 DIALOG_Symbol(&ProgramAttributes
.hTmpIcon
,
340 ProgramAttributes
.lpszTmpIconFile
,
341 &ProgramAttributes
.nTmpIconIndex
,
344 SendDlgItemMessage(hDlg
, PM_ICON
, STM_SETICON
,
345 (WPARAM
) ProgramAttributes
.hTmpIcon
, 0);
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
)
363 if (*ProgramAttributes
.lphIcon
)
364 DestroyIcon(*ProgramAttributes
.lphIcon
);
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
);
380 EndDialog(hDlg
, IDCANCEL
);
388 /***********************************************************************
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
)
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);
435 PMEASUREITEMSTRUCT measure
= (PMEASUREITEMSTRUCT
) lParam
;
436 measure
->itemWidth
= 32;
437 measure
->itemHeight
= 32;
443 PDRAWITEMSTRUCT dis
= (PDRAWITEMSTRUCT
) lParam
;
444 DrawIcon(dis
->hDC
, dis
->rcItem
.left
, dis
->rcItem
.top
, (HICON
)dis
->itemData
);
453 CHAR filename
[MAX_PATHNAME_LEN
];
455 if (DIALOG_BrowseSymbols(hDlg
, filename
, sizeof(filename
)))
456 SetDlgItemText(hDlg
, PM_ICON_FILE
, filename
);
461 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
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
,
472 (WPARAM
) nCurSel
, 0);
474 *Symbol
.lphIcon
= CopyIcon(*Symbol
.lphIcon
);
477 EndDialog(hDlg
, IDOK
);
482 EndDialog(hDlg
, IDCANCEL
);
489 /***********************************************************************
494 VOID
DIALOG_Execute(void)
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
)
517 CheckDlgButton(hDlg
, PM_SYMBOL
, !IsDlgButtonChecked(hDlg
, PM_SYMBOL
));
522 CHAR filename
[MAX_PATHNAME_LEN
];
524 if (DIALOG_BrowsePrograms(hDlg
, filename
, sizeof(filename
)))
525 SetDlgItemText(hDlg
, PM_COMMAND
, filename
);
530 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
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
);
547 EndDialog(hDlg
, IDCANCEL
);
554 /***********************************************************************
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;
607 *p
+= strlen(*p
) + 1;
611 /***********************************************************************
613 * DIALOG_BrowsePrograms
616 static BOOL
DIALOG_BrowsePrograms(HWND hDlg
, LPSTR lpszFile
, INT nMaxFile
)
618 CHAR szzFilter
[2 * MAX_STRING_LEN
+ 100];
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];
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" */