Wine keyboard and mouse have now their own UIDs.
[wine/multimedia.git] / programs / progman / program.c
blob871e93981278c544dbbaccaa2cf3db2f15b30c6e
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
5 */
7 #include "windows.h"
8 #include "progman.h"
10 /***********************************************************************
12 * PROGRAM_ProgramWndProc
15 static LRESULT PROGRAM_ProgramWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
17 switch (msg)
19 case WM_NCLBUTTONDOWN:
21 HLOCAL hProgram = (HLOCAL) GetWindowLong(hWnd, 0);
22 PROGRAM *program = LocalLock(hProgram);
23 GROUP *group = LocalLock(program->hGroup);
24 group->hActiveProgram = hProgram;
25 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
26 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
27 break;
29 case WM_NCLBUTTONDBLCLK:
31 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLong(hWnd, 0));
32 return(0);
35 case WM_PAINTICON:
36 case WM_NCPAINT:
38 PROGRAM *program;
39 PAINTSTRUCT ps;
40 HDC hdc;
41 hdc = BeginPaint(hWnd,&ps);
42 program = LocalLock((HLOCAL) GetWindowLong(hWnd, 0));
43 if (program->hIcon)
44 DrawIcon(hdc, 0, 0, program->hIcon);
45 EndPaint(hWnd,&ps);
46 break;
49 return(DefWindowProc(hWnd, msg, wParam, lParam));
52 /***********************************************************************
54 * PROGRAM_RegisterProgramWinClass
57 ATOM PROGRAM_RegisterProgramWinClass()
59 WNDCLASS class;
61 class.style = CS_HREDRAW | CS_VREDRAW;
62 class.lpfnWndProc = PROGRAM_ProgramWndProc;
63 class.cbClsExtra = 0;
64 class.cbWndExtra = sizeof(LONG);
65 class.hInstance = Globals.hInstance;
66 class.hIcon = 0;
67 class.hCursor = LoadCursor (0, IDC_ARROW);
68 class.hbrBackground = GetStockObject (WHITE_BRUSH);
69 class.lpszMenuName = 0;
70 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
72 return RegisterClass(&class);
75 /***********************************************************************
77 * PROGRAM_NewProgram
80 VOID PROGRAM_NewProgram(HLOCAL hGroup)
82 INT nCmdShow = SW_SHOWNORMAL;
83 INT nHotKey = 0;
84 INT nIconIndex = 0;
85 CHAR szName[MAX_PATHNAME_LEN] = "";
86 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
87 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
88 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
89 HICON hIcon = 0;
91 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
92 &hIcon, &nIconIndex, &nHotKey,
93 &nCmdShow, MAX_PATHNAME_LEN))
94 return;
96 if (!hIcon) hIcon = LoadIcon(0, MAKEINTRESOURCE(OIC_WINEICON));
99 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
100 nIconIndex, szWorkDir, nHotKey, nCmdShow))
101 return;
103 GRPFILE_WriteGroupFile(hGroup);
106 /***********************************************************************
108 * PROGRAM_ModifyProgram
111 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
113 PROGRAM *program = LocalLock(hProgram);
114 CHAR szName[MAX_PATHNAME_LEN];
115 CHAR szCmdLine[MAX_PATHNAME_LEN];
116 CHAR szIconFile[MAX_PATHNAME_LEN];
117 CHAR szWorkDir[MAX_PATHNAME_LEN];
119 lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
120 lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
121 lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
122 lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
124 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
125 &program->hIcon, &program->nIconIndex,
126 &program->nHotKey, &program->nCmdShow,
127 MAX_PATHNAME_LEN))
128 return;
130 MAIN_ReplaceString(&program->hName, szName);
131 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
132 MAIN_ReplaceString(&program->hIconFile, szIconFile);
133 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
135 SetWindowText(program->hWnd, szName);
136 UpdateWindow(program->hWnd);
138 GRPFILE_WriteGroupFile(program->hGroup);
140 return;
143 /***********************************************************************
145 * PROGRAM_AddProgram
148 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
149 INT x, INT y, LPCSTR lpszCmdLine,
150 LPCSTR lpszIconFile, INT nIconIndex,
151 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
153 GROUP *group = LocalLock(hGroup);
154 PROGRAM *program;
155 HLOCAL hPrior, *p;
156 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
157 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
158 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszCmdLine));
159 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszIconFile));
160 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszWorkDir));
161 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
163 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
164 if (hProgram) LocalFree(hProgram);
165 if (hName) LocalFree(hName);
166 if (hCmdLine) LocalFree(hCmdLine);
167 if (hIconFile) LocalFree(hIconFile);
168 if (hWorkDir) LocalFree(hWorkDir);
169 return(0);
171 hmemcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
172 hmemcpy(LocalLock(hCmdLine), lpszCmdLine, 1 + lstrlen(lpszCmdLine));
173 hmemcpy(LocalLock(hIconFile), lpszIconFile, 1 + lstrlen(lpszIconFile));
174 hmemcpy(LocalLock(hWorkDir), lpszWorkDir, 1 + lstrlen(lpszWorkDir));
176 group->hActiveProgram = hProgram;
178 hPrior = 0;
179 p = &group->hPrograms;
180 while (*p)
182 hPrior = *p;
183 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
185 *p = hProgram;
187 program = LocalLock(hProgram);
188 program->hGroup = hGroup;
189 program->hPrior = hPrior;
190 program->hNext = 0;
191 program->hName = hName;
192 program->hCmdLine = hCmdLine;
193 program->hIconFile = hIconFile;
194 program->nIconIndex = nIconIndex;
195 program->hWorkDir = hWorkDir;
196 program->hIcon = hIcon;
197 program->nCmdShow = nCmdShow;
198 program->nHotKey = nHotKey;
200 program->hWnd =
201 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME, (LPSTR)lpszName,
202 WS_CHILD | WS_CAPTION,
203 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
204 group->hWnd, 0, Globals.hInstance, 0);
206 SetWindowLong(program->hWnd, 0, (LONG) hProgram);
208 ShowWindow (program->hWnd, SW_SHOWMINIMIZED);
209 SetWindowPos (program->hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
210 UpdateWindow (program->hWnd);
212 return hProgram;
215 /***********************************************************************
217 * PROGRAM_CopyMoveProgram
220 VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove)
222 PROGRAM *program = LocalLock(hProgram);
223 GROUP *fromgroup = LocalLock(program->hGroup);
224 HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName),
225 LocalLock(fromgroup->hName), bMove);
226 if (!hGroup) return;
228 /* FIXME shouldn't be necessary */
229 OpenIcon(((GROUP*)LocalLock(hGroup))->hWnd);
231 if (!PROGRAM_AddProgram(hGroup,
232 #if 0
233 CopyIcon(program->hIcon),
234 #else
235 program->hIcon,
236 #endif
237 LocalLock(program->hName),
238 program->x, program->y,
239 LocalLock(program->hCmdLine),
240 LocalLock(program->hIconFile),
241 program->nIconIndex,
242 LocalLock(program->hWorkDir),
243 program->nHotKey, program->nCmdShow)) return;
244 GRPFILE_WriteGroupFile(hGroup);
246 if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE);
249 /***********************************************************************
251 * PROGRAM_ExecuteProgram
254 VOID PROGRAM_ExecuteProgram(HLOCAL hProgram)
256 PROGRAM *program = LocalLock(hProgram);
257 LPSTR lpszCmdLine = LocalLock(program->hCmdLine);
258 LPSTR lpszWorkDir = LocalLock(program->hWorkDir);
260 /* FIXME set working directory */
261 lpszWorkDir = lpszWorkDir;
263 WinExec(lpszCmdLine, program->nCmdShow);
264 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
267 /***********************************************************************
269 * PROGRAM_DeleteProgram
272 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
274 PROGRAM *program = LocalLock(hProgram);
275 GROUP *group = LocalLock(program->hGroup);
277 group->hActiveProgram = 0;
279 if (program->hPrior)
280 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
281 else
282 ((GROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
284 if (program->hNext)
285 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
287 if (bUpdateGrpFile)
288 GRPFILE_WriteGroupFile(program->hGroup);
290 DestroyWindow(program->hWnd);
291 #if 0
292 if (program->hIcon)
293 DestroyIcon(program->hIcon);
294 #endif
295 LocalFree(program->hName);
296 LocalFree(program->hCmdLine);
297 LocalFree(program->hIconFile);
298 LocalFree(program->hWorkDir);
299 LocalFree(hProgram);
302 /***********************************************************************
304 * PROGRAM_FirstProgram
307 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
309 GROUP *group;
310 if (!hGroup) return(0);
311 group = LocalLock(hGroup);
312 return(group->hPrograms);
315 /***********************************************************************
317 * PROGRAM_NextProgram
320 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
322 PROGRAM *program;
323 if (!hProgram) return(0);
324 program = LocalLock(hProgram);
325 return(program->hNext);
328 /***********************************************************************
330 * PROGRAM_ActiveProgram
333 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
335 GROUP *group;
336 if (!hGroup) return(0);
337 group = LocalLock(hGroup);
338 if (IsIconic(group->hWnd)) return(0);
340 return(group->hActiveProgram);
343 /***********************************************************************
345 * PROGRAM_ProgramName
348 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
350 PROGRAM *program;
351 if (!hProgram) return(0);
352 program = LocalLock(hProgram);
353 return(LocalLock(program->hName));
356 /* Local Variables: */
357 /* c-file-style: "GNU" */
358 /* End: */