winevulkan: Update to VK spec version 1.2.188.
[wine.git] / programs / progman / program.c
blob883864fff13731f2f45343d7e66f51653a37326b
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
23 #include <string.h>
24 #include "windows.h"
25 #include "progman.h"
27 /***********************************************************************
29 * PROGRAM_ProgramWndProc
32 static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
34 switch (msg)
36 case WM_NCLBUTTONDOWN:
38 HLOCAL hProgram = (HLOCAL) GetWindowLongPtrW(hWnd, 0);
39 PROGRAM *program = LocalLock(hProgram);
40 PROGGROUP *group = LocalLock(program->hGroup);
41 group->hActiveProgram = hProgram;
42 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
43 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
44 break;
46 case WM_NCLBUTTONDBLCLK:
48 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLongPtrW(hWnd, 0));
49 return(0);
52 case WM_PAINTICON:
53 case WM_NCPAINT:
55 PROGRAM *program;
56 PAINTSTRUCT ps;
57 HDC hdc;
58 hdc = BeginPaint(hWnd,&ps);
59 program = LocalLock((HLOCAL) GetWindowLongPtrW(hWnd, 0));
60 if (program->hIcon)
61 DrawIcon(hdc, 0, 0, program->hIcon);
62 EndPaint(hWnd,&ps);
63 break;
66 return DefWindowProcW(hWnd, msg, wParam, lParam);
69 /***********************************************************************
71 * PROGRAM_RegisterProgramWinClass
74 ATOM PROGRAM_RegisterProgramWinClass(void)
76 WNDCLASSW class;
78 class.style = CS_HREDRAW | CS_VREDRAW;
79 class.lpfnWndProc = PROGRAM_ProgramWndProc;
80 class.cbClsExtra = 0;
81 class.cbWndExtra = sizeof(LONG_PTR);
82 class.hInstance = Globals.hInstance;
83 class.hIcon = 0;
84 class.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
85 class.hbrBackground = GetStockObject (WHITE_BRUSH);
86 class.lpszMenuName = 0;
87 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
89 return RegisterClassW(&class);
92 /***********************************************************************
94 * PROGRAM_NewProgram
97 VOID PROGRAM_NewProgram(HLOCAL hGroup)
99 INT nCmdShow = SW_SHOWNORMAL;
100 INT nHotKey = 0;
101 INT nIconIndex = 0;
102 CHAR szName[MAX_PATHNAME_LEN] = "";
103 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
104 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
105 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
106 HICON hIcon = 0;
108 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
109 &hIcon, &nIconIndex, &nHotKey,
110 &nCmdShow, MAX_PATHNAME_LEN))
111 return;
113 if (!hIcon) hIcon = LoadIconW(0, (LPWSTR)IDI_WINLOGO);
116 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
117 nIconIndex, szWorkDir, nHotKey, nCmdShow))
118 return;
120 GRPFILE_WriteGroupFile(hGroup);
123 /***********************************************************************
125 * PROGRAM_ModifyProgram
128 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
130 PROGRAM *program = LocalLock(hProgram);
131 CHAR szName[MAX_PATHNAME_LEN];
132 CHAR szCmdLine[MAX_PATHNAME_LEN];
133 CHAR szIconFile[MAX_PATHNAME_LEN];
134 CHAR szWorkDir[MAX_PATHNAME_LEN];
136 lstrcpynA(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
137 lstrcpynA(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
138 lstrcpynA(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
139 lstrcpynA(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
141 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
142 &program->hIcon, &program->nIconIndex,
143 &program->nHotKey, &program->nCmdShow,
144 MAX_PATHNAME_LEN))
145 return;
147 MAIN_ReplaceString(&program->hName, szName);
148 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
149 MAIN_ReplaceString(&program->hIconFile, szIconFile);
150 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
152 SetWindowTextA(program->hWnd, szName);
153 UpdateWindow(program->hWnd);
155 GRPFILE_WriteGroupFile(program->hGroup);
157 return;
160 /***********************************************************************
162 * PROGRAM_AddProgram
165 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
166 INT x, INT y, LPCSTR lpszCmdLine,
167 LPCSTR lpszIconFile, INT nIconIndex,
168 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
170 PROGGROUP *group = LocalLock(hGroup);
171 PROGRAM *program;
172 HLOCAL hPrior, *p;
173 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
174 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszName));
175 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszCmdLine));
176 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszIconFile));
177 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszWorkDir));
178 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
180 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
181 if (hProgram) LocalFree(hProgram);
182 if (hName) LocalFree(hName);
183 if (hCmdLine) LocalFree(hCmdLine);
184 if (hIconFile) LocalFree(hIconFile);
185 if (hWorkDir) LocalFree(hWorkDir);
186 return(0);
188 memcpy(LocalLock(hName), lpszName, 1 + strlen(lpszName));
189 memcpy(LocalLock(hCmdLine), lpszCmdLine, 1 + strlen(lpszCmdLine));
190 memcpy(LocalLock(hIconFile), lpszIconFile, 1 + strlen(lpszIconFile));
191 memcpy(LocalLock(hWorkDir), lpszWorkDir, 1 + strlen(lpszWorkDir));
193 group->hActiveProgram = hProgram;
195 hPrior = 0;
196 p = &group->hPrograms;
197 while (*p)
199 hPrior = *p;
200 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
202 *p = hProgram;
204 program = LocalLock(hProgram);
205 program->hGroup = hGroup;
206 program->hPrior = hPrior;
207 program->hNext = 0;
208 program->hName = hName;
209 program->hCmdLine = hCmdLine;
210 program->hIconFile = hIconFile;
211 program->nIconIndex = nIconIndex;
212 program->hWorkDir = hWorkDir;
213 program->hIcon = hIcon;
214 program->nCmdShow = nCmdShow;
215 program->nHotKey = nHotKey;
217 program->hWnd =
218 CreateWindowW(STRING_PROGRAM_WIN_CLASS_NAME, NULL,
219 WS_CHILD | WS_CAPTION,
220 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
221 group->hWnd, 0, Globals.hInstance, 0);
223 SetWindowTextA(program->hWnd, lpszName);
224 SetWindowLongPtrW(program->hWnd, 0, (LONG_PTR) hProgram);
226 ShowWindow (program->hWnd, SW_SHOWMINIMIZED);
227 SetWindowPos (program->hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
228 UpdateWindow (program->hWnd);
230 return hProgram;
233 /***********************************************************************
235 * PROGRAM_CopyMoveProgram
238 VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove)
240 PROGRAM *program = LocalLock(hProgram);
241 PROGGROUP *fromgroup = LocalLock(program->hGroup);
242 HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName),
243 LocalLock(fromgroup->hName), bMove);
244 if (!hGroup) return;
246 /* FIXME shouldn't be necessary */
247 OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd);
249 if (!PROGRAM_AddProgram(hGroup,
250 #if 0
251 CopyIcon(program->hIcon),
252 #else
253 program->hIcon,
254 #endif
255 LocalLock(program->hName),
256 program->x, program->y,
257 LocalLock(program->hCmdLine),
258 LocalLock(program->hIconFile),
259 program->nIconIndex,
260 LocalLock(program->hWorkDir),
261 program->nHotKey, program->nCmdShow)) return;
262 GRPFILE_WriteGroupFile(hGroup);
264 if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE);
267 /***********************************************************************
269 * PROGRAM_ExecuteProgram
272 VOID PROGRAM_ExecuteProgram(HLOCAL hProgram)
274 PROGRAM *program = LocalLock(hProgram);
275 LPSTR lpszCmdLine = LocalLock(program->hCmdLine);
277 /* FIXME set working directory from program->hWorkDir */
279 WinExec(lpszCmdLine, program->nCmdShow);
280 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
283 /***********************************************************************
285 * PROGRAM_DeleteProgram
288 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
290 PROGRAM *program = LocalLock(hProgram);
291 PROGGROUP *group = LocalLock(program->hGroup);
293 group->hActiveProgram = 0;
295 if (program->hPrior)
296 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
297 else
298 ((PROGGROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
300 if (program->hNext)
301 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
303 if (bUpdateGrpFile)
304 GRPFILE_WriteGroupFile(program->hGroup);
306 DestroyWindow(program->hWnd);
307 #if 0
308 if (program->hIcon)
309 DestroyIcon(program->hIcon);
310 #endif
311 LocalFree(program->hName);
312 LocalFree(program->hCmdLine);
313 LocalFree(program->hIconFile);
314 LocalFree(program->hWorkDir);
315 LocalFree(hProgram);
318 /***********************************************************************
320 * PROGRAM_FirstProgram
323 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
325 PROGGROUP *group;
326 if (!hGroup) return(0);
327 group = LocalLock(hGroup);
328 return(group->hPrograms);
331 /***********************************************************************
333 * PROGRAM_NextProgram
336 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
338 PROGRAM *program;
339 if (!hProgram) return(0);
340 program = LocalLock(hProgram);
341 return(program->hNext);
344 /***********************************************************************
346 * PROGRAM_ActiveProgram
349 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
351 PROGGROUP *group;
352 if (!hGroup) return(0);
353 group = LocalLock(hGroup);
354 if (IsIconic(group->hWnd)) return(0);
356 return(group->hActiveProgram);
359 /***********************************************************************
361 * PROGRAM_ProgramName
364 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
366 PROGRAM *program;
367 if (!hProgram) return(0);
368 program = LocalLock(hProgram);
369 return(LocalLock(program->hName));