Compile fix.
[wine.git] / programs / progman / program.c
blob51a4e545a77eceb7f673b684188b909c6243cfd6
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
5 */
7 #include <string.h>
8 #include "windows.h"
9 #include "windowsx.h"
10 #include "progman.h"
12 /***********************************************************************
14 * PROGRAM_ProgramWndProc
17 static LRESULT PROGRAM_ProgramWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
19 switch (msg)
21 case WM_NCLBUTTONDOWN:
23 HLOCAL hProgram = (HLOCAL) GetWindowLong(hWnd, 0);
24 PROGRAM *program = LocalLock(hProgram);
25 GROUP *group = LocalLock(program->hGroup);
26 group->hActiveProgram = hProgram;
27 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
28 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
29 break;
31 case WM_NCLBUTTONDBLCLK:
33 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLong(hWnd, 0));
34 return(0);
37 case WM_PAINTICON:
38 case WM_NCPAINT:
40 PROGRAM *program;
41 PAINTSTRUCT ps;
42 HDC hdc;
43 hdc = BeginPaint(hWnd,&ps);
44 program = LocalLock((HLOCAL) GetWindowLong(hWnd, 0));
45 if (program->hIcon)
46 DrawIcon(hdc, 0, 0, program->hIcon);
47 EndPaint(hWnd,&ps);
48 break;
51 return(DefWindowProc(hWnd, msg, wParam, lParam));
54 /***********************************************************************
56 * PROGRAM_RegisterProgramWinClass
59 ATOM PROGRAM_RegisterProgramWinClass()
61 WNDCLASS class;
63 class.style = CS_HREDRAW | CS_VREDRAW;
64 class.lpfnWndProc = PROGRAM_ProgramWndProc;
65 class.cbClsExtra = 0;
66 class.cbWndExtra = sizeof(LONG);
67 class.hInstance = Globals.hInstance;
68 class.hIcon = 0;
69 class.hCursor = LoadCursor (0, IDC_ARROW);
70 class.hbrBackground = GetStockObject (WHITE_BRUSH);
71 class.lpszMenuName = 0;
72 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
74 return RegisterClass(&class);
77 /***********************************************************************
79 * PROGRAM_NewProgram
82 VOID PROGRAM_NewProgram(HLOCAL hGroup)
84 INT nCmdShow = SW_SHOWNORMAL;
85 INT nHotKey = 0;
86 INT nIconIndex = 0;
87 CHAR szName[MAX_PATHNAME_LEN] = "";
88 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
89 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
90 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
91 HICON hIcon = 0;
93 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
94 &hIcon, &nIconIndex, &nHotKey,
95 &nCmdShow, MAX_PATHNAME_LEN))
96 return;
98 if (!hIcon) hIcon = LoadIcon(0, MAKEINTRESOURCE(OIC_WINEICON));
101 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
102 nIconIndex, szWorkDir, nHotKey, nCmdShow))
103 return;
105 GRPFILE_WriteGroupFile(hGroup);
108 /***********************************************************************
110 * PROGRAM_ModifyProgram
113 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
115 PROGRAM *program = LocalLock(hProgram);
116 CHAR szName[MAX_PATHNAME_LEN];
117 CHAR szCmdLine[MAX_PATHNAME_LEN];
118 CHAR szIconFile[MAX_PATHNAME_LEN];
119 CHAR szWorkDir[MAX_PATHNAME_LEN];
121 lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
122 lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
123 lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
124 lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
126 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
127 &program->hIcon, &program->nIconIndex,
128 &program->nHotKey, &program->nCmdShow,
129 MAX_PATHNAME_LEN))
130 return;
132 MAIN_ReplaceString(&program->hName, szName);
133 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
134 MAIN_ReplaceString(&program->hIconFile, szIconFile);
135 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
137 SetWindowText(program->hWnd, szName);
138 UpdateWindow(program->hWnd);
140 GRPFILE_WriteGroupFile(program->hGroup);
142 return;
145 /***********************************************************************
147 * PROGRAM_AddProgram
150 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
151 INT x, INT y, LPCSTR lpszCmdLine,
152 LPCSTR lpszIconFile, INT nIconIndex,
153 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
155 GROUP *group = LocalLock(hGroup);
156 PROGRAM *program;
157 HLOCAL hPrior, *p;
158 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
159 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
160 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszCmdLine));
161 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszIconFile));
162 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszWorkDir));
163 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
165 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
166 if (hProgram) LocalFree(hProgram);
167 if (hName) LocalFree(hName);
168 if (hCmdLine) LocalFree(hCmdLine);
169 if (hIconFile) LocalFree(hIconFile);
170 if (hWorkDir) LocalFree(hWorkDir);
171 return(0);
173 hmemcpy16(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
174 hmemcpy16(LocalLock(hCmdLine), lpszCmdLine, 1 + lstrlen(lpszCmdLine));
175 hmemcpy16(LocalLock(hIconFile), lpszIconFile, 1 + lstrlen(lpszIconFile));
176 hmemcpy16(LocalLock(hWorkDir), lpszWorkDir, 1 + lstrlen(lpszWorkDir));
178 group->hActiveProgram = hProgram;
180 hPrior = 0;
181 p = &group->hPrograms;
182 while (*p)
184 hPrior = *p;
185 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
187 *p = hProgram;
189 program = LocalLock(hProgram);
190 program->hGroup = hGroup;
191 program->hPrior = hPrior;
192 program->hNext = 0;
193 program->hName = hName;
194 program->hCmdLine = hCmdLine;
195 program->hIconFile = hIconFile;
196 program->nIconIndex = nIconIndex;
197 program->hWorkDir = hWorkDir;
198 program->hIcon = hIcon;
199 program->nCmdShow = nCmdShow;
200 program->nHotKey = nHotKey;
202 program->hWnd =
203 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME, (LPSTR)lpszName,
204 WS_CHILD | WS_CAPTION,
205 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
206 group->hWnd, 0, Globals.hInstance, 0);
208 SetWindowLong(program->hWnd, 0, (LONG) hProgram);
210 ShowWindow (program->hWnd, SW_SHOWMINIMIZED);
211 SetWindowPos (program->hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
212 UpdateWindow (program->hWnd);
214 return hProgram;
217 /***********************************************************************
219 * PROGRAM_CopyMoveProgram
222 VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove)
224 PROGRAM *program = LocalLock(hProgram);
225 GROUP *fromgroup = LocalLock(program->hGroup);
226 HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName),
227 LocalLock(fromgroup->hName), bMove);
228 if (!hGroup) return;
230 /* FIXME shouldn't be necessary */
231 OpenIcon(((GROUP*)LocalLock(hGroup))->hWnd);
233 if (!PROGRAM_AddProgram(hGroup,
234 #if 0
235 CopyIcon(program->hIcon),
236 #else
237 program->hIcon,
238 #endif
239 LocalLock(program->hName),
240 program->x, program->y,
241 LocalLock(program->hCmdLine),
242 LocalLock(program->hIconFile),
243 program->nIconIndex,
244 LocalLock(program->hWorkDir),
245 program->nHotKey, program->nCmdShow)) return;
246 GRPFILE_WriteGroupFile(hGroup);
248 if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE);
251 /***********************************************************************
253 * PROGRAM_ExecuteProgram
256 VOID PROGRAM_ExecuteProgram(HLOCAL hProgram)
258 PROGRAM *program = LocalLock(hProgram);
259 LPSTR lpszCmdLine = LocalLock(program->hCmdLine);
260 LPSTR lpszWorkDir = LocalLock(program->hWorkDir);
262 /* FIXME set working directory */
263 lpszWorkDir = lpszWorkDir;
265 WinExec(lpszCmdLine, program->nCmdShow);
266 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
269 /***********************************************************************
271 * PROGRAM_DeleteProgram
274 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
276 PROGRAM *program = LocalLock(hProgram);
277 GROUP *group = LocalLock(program->hGroup);
279 group->hActiveProgram = 0;
281 if (program->hPrior)
282 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
283 else
284 ((GROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
286 if (program->hNext)
287 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
289 if (bUpdateGrpFile)
290 GRPFILE_WriteGroupFile(program->hGroup);
292 DestroyWindow(program->hWnd);
293 #if 0
294 if (program->hIcon)
295 DestroyIcon(program->hIcon);
296 #endif
297 LocalFree(program->hName);
298 LocalFree(program->hCmdLine);
299 LocalFree(program->hIconFile);
300 LocalFree(program->hWorkDir);
301 LocalFree(hProgram);
304 /***********************************************************************
306 * PROGRAM_FirstProgram
309 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
311 GROUP *group;
312 if (!hGroup) return(0);
313 group = LocalLock(hGroup);
314 return(group->hPrograms);
317 /***********************************************************************
319 * PROGRAM_NextProgram
322 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
324 PROGRAM *program;
325 if (!hProgram) return(0);
326 program = LocalLock(hProgram);
327 return(program->hNext);
330 /***********************************************************************
332 * PROGRAM_ActiveProgram
335 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
337 GROUP *group;
338 if (!hGroup) return(0);
339 group = LocalLock(hGroup);
340 if (IsIconic(group->hWnd)) return(0);
342 return(group->hActiveProgram);
345 /***********************************************************************
347 * PROGRAM_ProgramName
350 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
352 PROGRAM *program;
353 if (!hProgram) return(0);
354 program = LocalLock(hProgram);
355 return(LocalLock(program->hName));
358 /* Local Variables: */
359 /* c-file-style: "GNU" */
360 /* End: */