Altered WM_MOUSEHOVER so the lParam and wParam fields are set
[wine/multimedia.git] / programs / progman / program.c
blob1060dd97640a785bf06a2b7e4155ed3c69542e98
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <string.h>
22 #include "windows.h"
23 #include "windowsx.h"
24 #include "progman.h"
26 /***********************************************************************
28 * PROGRAM_ProgramWndProc
31 static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
33 switch (msg)
35 case WM_NCLBUTTONDOWN:
37 HLOCAL hProgram = (HLOCAL) GetWindowLong(hWnd, 0);
38 PROGRAM *program = LocalLock(hProgram);
39 PROGGROUP *group = LocalLock(program->hGroup);
40 group->hActiveProgram = hProgram;
41 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
42 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
43 break;
45 case WM_NCLBUTTONDBLCLK:
47 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLong(hWnd, 0));
48 return(0);
51 case WM_PAINTICON:
52 case WM_NCPAINT:
54 PROGRAM *program;
55 PAINTSTRUCT ps;
56 HDC hdc;
57 hdc = BeginPaint(hWnd,&ps);
58 program = LocalLock((HLOCAL) GetWindowLong(hWnd, 0));
59 if (program->hIcon)
60 DrawIcon(hdc, 0, 0, program->hIcon);
61 EndPaint(hWnd,&ps);
62 break;
65 return(DefWindowProc(hWnd, msg, wParam, lParam));
68 /***********************************************************************
70 * PROGRAM_RegisterProgramWinClass
73 ATOM PROGRAM_RegisterProgramWinClass()
75 WNDCLASS class;
77 class.style = CS_HREDRAW | CS_VREDRAW;
78 class.lpfnWndProc = PROGRAM_ProgramWndProc;
79 class.cbClsExtra = 0;
80 class.cbWndExtra = sizeof(LONG);
81 class.hInstance = Globals.hInstance;
82 class.hIcon = 0;
83 class.hCursor = LoadCursor (0, IDC_ARROW);
84 class.hbrBackground = GetStockObject (WHITE_BRUSH);
85 class.lpszMenuName = 0;
86 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
88 return RegisterClass(&class);
91 /***********************************************************************
93 * PROGRAM_NewProgram
96 VOID PROGRAM_NewProgram(HLOCAL hGroup)
98 INT nCmdShow = SW_SHOWNORMAL;
99 INT nHotKey = 0;
100 INT nIconIndex = 0;
101 CHAR szName[MAX_PATHNAME_LEN] = "";
102 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
103 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
104 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
105 HICON hIcon = 0;
107 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
108 &hIcon, &nIconIndex, &nHotKey,
109 &nCmdShow, MAX_PATHNAME_LEN))
110 return;
112 if (!hIcon) hIcon = LoadIcon(0, IDI_WINLOGO);
115 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
116 nIconIndex, szWorkDir, nHotKey, nCmdShow))
117 return;
119 GRPFILE_WriteGroupFile(hGroup);
122 /***********************************************************************
124 * PROGRAM_ModifyProgram
127 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
129 PROGRAM *program = LocalLock(hProgram);
130 CHAR szName[MAX_PATHNAME_LEN];
131 CHAR szCmdLine[MAX_PATHNAME_LEN];
132 CHAR szIconFile[MAX_PATHNAME_LEN];
133 CHAR szWorkDir[MAX_PATHNAME_LEN];
135 lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
136 lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
137 lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
138 lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
140 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
141 &program->hIcon, &program->nIconIndex,
142 &program->nHotKey, &program->nCmdShow,
143 MAX_PATHNAME_LEN))
144 return;
146 MAIN_ReplaceString(&program->hName, szName);
147 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
148 MAIN_ReplaceString(&program->hIconFile, szIconFile);
149 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
151 SetWindowText(program->hWnd, szName);
152 UpdateWindow(program->hWnd);
154 GRPFILE_WriteGroupFile(program->hGroup);
156 return;
159 /***********************************************************************
161 * PROGRAM_AddProgram
164 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
165 INT x, INT y, LPCSTR lpszCmdLine,
166 LPCSTR lpszIconFile, INT nIconIndex,
167 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
169 PROGGROUP *group = LocalLock(hGroup);
170 PROGRAM *program;
171 HLOCAL hPrior, *p;
172 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
173 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
174 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszCmdLine));
175 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszIconFile));
176 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszWorkDir));
177 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
179 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
180 if (hProgram) LocalFree(hProgram);
181 if (hName) LocalFree(hName);
182 if (hCmdLine) LocalFree(hCmdLine);
183 if (hIconFile) LocalFree(hIconFile);
184 if (hWorkDir) LocalFree(hWorkDir);
185 return(0);
187 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
188 memcpy(LocalLock(hCmdLine), lpszCmdLine, 1 + lstrlen(lpszCmdLine));
189 memcpy(LocalLock(hIconFile), lpszIconFile, 1 + lstrlen(lpszIconFile));
190 memcpy(LocalLock(hWorkDir), lpszWorkDir, 1 + lstrlen(lpszWorkDir));
192 group->hActiveProgram = hProgram;
194 hPrior = 0;
195 p = &group->hPrograms;
196 while (*p)
198 hPrior = *p;
199 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
201 *p = hProgram;
203 program = LocalLock(hProgram);
204 program->hGroup = hGroup;
205 program->hPrior = hPrior;
206 program->hNext = 0;
207 program->hName = hName;
208 program->hCmdLine = hCmdLine;
209 program->hIconFile = hIconFile;
210 program->nIconIndex = nIconIndex;
211 program->hWorkDir = hWorkDir;
212 program->hIcon = hIcon;
213 program->nCmdShow = nCmdShow;
214 program->nHotKey = nHotKey;
216 program->hWnd =
217 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME, (LPSTR)lpszName,
218 WS_CHILD | WS_CAPTION,
219 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
220 group->hWnd, 0, Globals.hInstance, 0);
222 SetWindowLong(program->hWnd, 0, (LONG) hProgram);
224 ShowWindow (program->hWnd, SW_SHOWMINIMIZED);
225 SetWindowPos (program->hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
226 UpdateWindow (program->hWnd);
228 return hProgram;
231 /***********************************************************************
233 * PROGRAM_CopyMoveProgram
236 VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove)
238 PROGRAM *program = LocalLock(hProgram);
239 PROGGROUP *fromgroup = LocalLock(program->hGroup);
240 HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName),
241 LocalLock(fromgroup->hName), bMove);
242 if (!hGroup) return;
244 /* FIXME shouldn't be necessary */
245 OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd);
247 if (!PROGRAM_AddProgram(hGroup,
248 #if 0
249 CopyIcon(program->hIcon),
250 #else
251 program->hIcon,
252 #endif
253 LocalLock(program->hName),
254 program->x, program->y,
255 LocalLock(program->hCmdLine),
256 LocalLock(program->hIconFile),
257 program->nIconIndex,
258 LocalLock(program->hWorkDir),
259 program->nHotKey, program->nCmdShow)) return;
260 GRPFILE_WriteGroupFile(hGroup);
262 if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE);
265 /***********************************************************************
267 * PROGRAM_ExecuteProgram
270 VOID PROGRAM_ExecuteProgram(HLOCAL hProgram)
272 PROGRAM *program = LocalLock(hProgram);
273 LPSTR lpszCmdLine = LocalLock(program->hCmdLine);
274 LPSTR lpszWorkDir = LocalLock(program->hWorkDir);
276 /* FIXME set working directory */
277 lpszWorkDir = lpszWorkDir;
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));
372 /* Local Variables: */
373 /* c-file-style: "GNU" */
374 /* End: */