4 * Copyright 1996 Ulrich Schmid
10 /***********************************************************************
12 * PROGRAM_ProgramWndProc
15 static LRESULT PROGRAM_ProgramWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
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);
29 case WM_NCLBUTTONDBLCLK:
31 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLong(hWnd, 0));
41 hdc = BeginPaint(hWnd,&ps);
42 program = LocalLock((HLOCAL) GetWindowLong(hWnd, 0));
44 DrawIcon(hdc, 0, 0, program->hIcon);
49 return(DefWindowProc(hWnd, msg, wParam, lParam));
52 /***********************************************************************
54 * PROGRAM_RegisterProgramWinClass
57 ATOM PROGRAM_RegisterProgramWinClass()
61 class.style = CS_HREDRAW | CS_VREDRAW;
62 class.lpfnWndProc = PROGRAM_ProgramWndProc;
64 class.cbWndExtra = sizeof(LONG);
65 class.hInstance = Globals.hInstance;
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 /***********************************************************************
80 VOID PROGRAM_NewProgram(HLOCAL hGroup)
82 INT nCmdShow = SW_SHOWNORMAL;
85 CHAR szName[MAX_PATHNAME_LEN] = "";
86 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
87 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
88 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
91 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
92 &hIcon, &nIconIndex, &nHotKey,
93 &nCmdShow, MAX_PATHNAME_LEN))
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))
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,
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);
143 /***********************************************************************
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);
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);
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;
179 p = &group->hPrograms;
183 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
187 program = LocalLock(hProgram);
188 program->hGroup = hGroup;
189 program->hPrior = hPrior;
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;
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);
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);
228 /* FIXME shouldn't be necessary */
229 OpenIcon(((GROUP*)LocalLock(hGroup))->hWnd);
231 if (!PROGRAM_AddProgram(hGroup,
233 CopyIcon(program->hIcon),
237 LocalLock(program->hName),
238 program->x, program->y,
239 LocalLock(program->hCmdLine),
240 LocalLock(program->hIconFile),
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;
280 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
282 ((GROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
285 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
288 GRPFILE_WriteGroupFile(program->hGroup);
290 DestroyWindow(program->hWnd);
293 DestroyIcon(program->hIcon);
295 LocalFree(program->hName);
296 LocalFree(program->hCmdLine);
297 LocalFree(program->hIconFile);
298 LocalFree(program->hWorkDir);
302 /***********************************************************************
304 * PROGRAM_FirstProgram
307 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
310 if (!hGroup) return(0);
311 group = LocalLock(hGroup);
312 return(group->hPrograms);
315 /***********************************************************************
317 * PROGRAM_NextProgram
320 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
323 if (!hProgram) return(0);
324 program = LocalLock(hProgram);
325 return(program->hNext);
328 /***********************************************************************
330 * PROGRAM_ActiveProgram
333 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
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)
351 if (!hProgram) return(0);
352 program = LocalLock(hProgram);
353 return(LocalLock(program->hName));
356 /* Local Variables: */
357 /* c-file-style: "GNU" */