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 #define WIN32_LEAN_AND_MEAN
28 /***********************************************************************
30 * PROGRAM_ProgramWndProc
33 static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
37 case WM_NCLBUTTONDOWN:
39 HLOCAL hProgram = (HLOCAL) GetWindowLong(hWnd, 0);
40 PROGRAM *program = LocalLock(hProgram);
41 PROGGROUP *group = LocalLock(program->hGroup);
42 group->hActiveProgram = hProgram;
43 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
44 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
47 case WM_NCLBUTTONDBLCLK:
49 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLong(hWnd, 0));
59 hdc = BeginPaint(hWnd,&ps);
60 program = LocalLock((HLOCAL) GetWindowLong(hWnd, 0));
62 DrawIcon(hdc, 0, 0, program->hIcon);
67 return(DefWindowProc(hWnd, msg, wParam, lParam));
70 /***********************************************************************
72 * PROGRAM_RegisterProgramWinClass
75 ATOM PROGRAM_RegisterProgramWinClass()
79 class.style = CS_HREDRAW | CS_VREDRAW;
80 class.lpfnWndProc = PROGRAM_ProgramWndProc;
82 class.cbWndExtra = sizeof(LONG);
83 class.hInstance = Globals.hInstance;
85 class.hCursor = LoadCursor (0, IDC_ARROW);
86 class.hbrBackground = GetStockObject (WHITE_BRUSH);
87 class.lpszMenuName = 0;
88 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
90 return RegisterClass(&class);
93 /***********************************************************************
98 VOID PROGRAM_NewProgram(HLOCAL hGroup)
100 INT nCmdShow = SW_SHOWNORMAL;
103 CHAR szName[MAX_PATHNAME_LEN] = "";
104 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
105 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
106 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
109 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
110 &hIcon, &nIconIndex, &nHotKey,
111 &nCmdShow, MAX_PATHNAME_LEN))
114 if (!hIcon) hIcon = LoadIcon(0, IDI_WINLOGO);
117 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
118 nIconIndex, szWorkDir, nHotKey, nCmdShow))
121 GRPFILE_WriteGroupFile(hGroup);
124 /***********************************************************************
126 * PROGRAM_ModifyProgram
129 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
131 PROGRAM *program = LocalLock(hProgram);
132 CHAR szName[MAX_PATHNAME_LEN];
133 CHAR szCmdLine[MAX_PATHNAME_LEN];
134 CHAR szIconFile[MAX_PATHNAME_LEN];
135 CHAR szWorkDir[MAX_PATHNAME_LEN];
137 lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
138 lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
139 lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
140 lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
142 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
143 &program->hIcon, &program->nIconIndex,
144 &program->nHotKey, &program->nCmdShow,
148 MAIN_ReplaceString(&program->hName, szName);
149 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
150 MAIN_ReplaceString(&program->hIconFile, szIconFile);
151 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
153 SetWindowText(program->hWnd, szName);
154 UpdateWindow(program->hWnd);
156 GRPFILE_WriteGroupFile(program->hGroup);
161 /***********************************************************************
166 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
167 INT x, INT y, LPCSTR lpszCmdLine,
168 LPCSTR lpszIconFile, INT nIconIndex,
169 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
171 PROGGROUP *group = LocalLock(hGroup);
174 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
175 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
176 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszCmdLine));
177 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszIconFile));
178 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszWorkDir));
179 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
181 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
182 if (hProgram) LocalFree(hProgram);
183 if (hName) LocalFree(hName);
184 if (hCmdLine) LocalFree(hCmdLine);
185 if (hIconFile) LocalFree(hIconFile);
186 if (hWorkDir) LocalFree(hWorkDir);
189 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
190 memcpy(LocalLock(hCmdLine), lpszCmdLine, 1 + lstrlen(lpszCmdLine));
191 memcpy(LocalLock(hIconFile), lpszIconFile, 1 + lstrlen(lpszIconFile));
192 memcpy(LocalLock(hWorkDir), lpszWorkDir, 1 + lstrlen(lpszWorkDir));
194 group->hActiveProgram = hProgram;
197 p = &group->hPrograms;
201 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
205 program = LocalLock(hProgram);
206 program->hGroup = hGroup;
207 program->hPrior = hPrior;
209 program->hName = hName;
210 program->hCmdLine = hCmdLine;
211 program->hIconFile = hIconFile;
212 program->nIconIndex = nIconIndex;
213 program->hWorkDir = hWorkDir;
214 program->hIcon = hIcon;
215 program->nCmdShow = nCmdShow;
216 program->nHotKey = nHotKey;
219 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME, lpszName,
220 WS_CHILD | WS_CAPTION,
221 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
222 group->hWnd, 0, Globals.hInstance, 0);
224 SetWindowLong(program->hWnd, 0, (LONG) 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);
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);
246 /* FIXME shouldn't be necessary */
247 OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd);
249 if (!PROGRAM_AddProgram(hGroup,
251 CopyIcon(program->hIcon),
255 LocalLock(program->hName),
256 program->x, program->y,
257 LocalLock(program->hCmdLine),
258 LocalLock(program->hIconFile),
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);
276 LPSTR lpszWorkDir = LocalLock(program->hWorkDir);
278 /* FIXME set working directory */
279 lpszWorkDir = lpszWorkDir;
281 WinExec(lpszCmdLine, program->nCmdShow);
282 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
285 /***********************************************************************
287 * PROGRAM_DeleteProgram
290 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
292 PROGRAM *program = LocalLock(hProgram);
293 PROGGROUP *group = LocalLock(program->hGroup);
295 group->hActiveProgram = 0;
298 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
300 ((PROGGROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
303 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
306 GRPFILE_WriteGroupFile(program->hGroup);
308 DestroyWindow(program->hWnd);
311 DestroyIcon(program->hIcon);
313 LocalFree(program->hName);
314 LocalFree(program->hCmdLine);
315 LocalFree(program->hIconFile);
316 LocalFree(program->hWorkDir);
320 /***********************************************************************
322 * PROGRAM_FirstProgram
325 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
328 if (!hGroup) return(0);
329 group = LocalLock(hGroup);
330 return(group->hPrograms);
333 /***********************************************************************
335 * PROGRAM_NextProgram
338 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
341 if (!hProgram) return(0);
342 program = LocalLock(hProgram);
343 return(program->hNext);
346 /***********************************************************************
348 * PROGRAM_ActiveProgram
351 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
354 if (!hGroup) return(0);
355 group = LocalLock(hGroup);
356 if (IsIconic(group->hWnd)) return(0);
358 return(group->hActiveProgram);
361 /***********************************************************************
363 * PROGRAM_ProgramName
366 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
369 if (!hProgram) return(0);
370 program = LocalLock(hProgram);
371 return(LocalLock(program->hName));
374 /* Local Variables: */
375 /* c-file-style: "GNU" */