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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
27 /***********************************************************************
29 * PROGRAM_ProgramWndProc
32 static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
36 case WM_NCLBUTTONDOWN:
38 HLOCAL hProgram = (HLOCAL) GetWindowLongPtr(hWnd, 0);
39 PROGRAM *program = LocalLock(hProgram);
40 PROGGROUP *group = LocalLock(program->hGroup);
41 group->hActiveProgram = hProgram;
42 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
43 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
46 case WM_NCLBUTTONDBLCLK:
48 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLongPtr(hWnd, 0));
58 hdc = BeginPaint(hWnd,&ps);
59 program = LocalLock((HLOCAL) GetWindowLongPtr(hWnd, 0));
61 DrawIcon(hdc, 0, 0, program->hIcon);
66 return(DefWindowProc(hWnd, msg, wParam, lParam));
69 /***********************************************************************
71 * PROGRAM_RegisterProgramWinClass
74 ATOM PROGRAM_RegisterProgramWinClass(void)
78 class.style = CS_HREDRAW | CS_VREDRAW;
79 class.lpfnWndProc = PROGRAM_ProgramWndProc;
81 class.cbWndExtra = sizeof(LONG_PTR);
82 class.hInstance = Globals.hInstance;
84 class.hCursor = LoadCursor (0, IDC_ARROW);
85 class.hbrBackground = GetStockObject (WHITE_BRUSH);
86 class.lpszMenuName = 0;
87 class.lpszClassName = STRING_PROGRAM_WIN_CLASS_NAME;
89 return RegisterClass(&class);
92 /***********************************************************************
97 VOID PROGRAM_NewProgram(HLOCAL hGroup)
99 INT nCmdShow = SW_SHOWNORMAL;
102 CHAR szName[MAX_PATHNAME_LEN] = "";
103 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
104 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
105 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
108 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
109 &hIcon, &nIconIndex, &nHotKey,
110 &nCmdShow, MAX_PATHNAME_LEN))
113 if (!hIcon) hIcon = LoadIcon(0, IDI_WINLOGO);
116 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
117 nIconIndex, szWorkDir, nHotKey, nCmdShow))
120 GRPFILE_WriteGroupFile(hGroup);
123 /***********************************************************************
125 * PROGRAM_ModifyProgram
128 VOID PROGRAM_ModifyProgram(HLOCAL hProgram)
130 PROGRAM *program = LocalLock(hProgram);
131 CHAR szName[MAX_PATHNAME_LEN];
132 CHAR szCmdLine[MAX_PATHNAME_LEN];
133 CHAR szIconFile[MAX_PATHNAME_LEN];
134 CHAR szWorkDir[MAX_PATHNAME_LEN];
136 lstrcpyn(szName, LocalLock(program->hName), MAX_PATHNAME_LEN);
137 lstrcpyn(szCmdLine, LocalLock(program->hCmdLine), MAX_PATHNAME_LEN);
138 lstrcpyn(szIconFile, LocalLock(program->hIconFile), MAX_PATHNAME_LEN);
139 lstrcpyn(szWorkDir, LocalLock(program->hWorkDir), MAX_PATHNAME_LEN);
141 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
142 &program->hIcon, &program->nIconIndex,
143 &program->nHotKey, &program->nCmdShow,
147 MAIN_ReplaceString(&program->hName, szName);
148 MAIN_ReplaceString(&program->hCmdLine, szCmdLine);
149 MAIN_ReplaceString(&program->hIconFile, szIconFile);
150 MAIN_ReplaceString(&program->hWorkDir, szWorkDir);
152 SetWindowText(program->hWnd, szName);
153 UpdateWindow(program->hWnd);
155 GRPFILE_WriteGroupFile(program->hGroup);
160 /***********************************************************************
165 HLOCAL PROGRAM_AddProgram(HLOCAL hGroup, HICON hIcon, LPCSTR lpszName,
166 INT x, INT y, LPCSTR lpszCmdLine,
167 LPCSTR lpszIconFile, INT nIconIndex,
168 LPCSTR lpszWorkDir, INT nHotKey, INT nCmdShow)
170 PROGGROUP *group = LocalLock(hGroup);
173 HLOCAL hProgram = LocalAlloc(LMEM_FIXED, sizeof(PROGRAM));
174 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
175 HLOCAL hCmdLine = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszCmdLine));
176 HLOCAL hIconFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszIconFile));
177 HLOCAL hWorkDir = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszWorkDir));
178 if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
180 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
181 if (hProgram) LocalFree(hProgram);
182 if (hName) LocalFree(hName);
183 if (hCmdLine) LocalFree(hCmdLine);
184 if (hIconFile) LocalFree(hIconFile);
185 if (hWorkDir) LocalFree(hWorkDir);
188 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
189 memcpy(LocalLock(hCmdLine), lpszCmdLine, 1 + lstrlen(lpszCmdLine));
190 memcpy(LocalLock(hIconFile), lpszIconFile, 1 + lstrlen(lpszIconFile));
191 memcpy(LocalLock(hWorkDir), lpszWorkDir, 1 + lstrlen(lpszWorkDir));
193 group->hActiveProgram = hProgram;
196 p = &group->hPrograms;
200 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
204 program = LocalLock(hProgram);
205 program->hGroup = hGroup;
206 program->hPrior = hPrior;
208 program->hName = hName;
209 program->hCmdLine = hCmdLine;
210 program->hIconFile = hIconFile;
211 program->nIconIndex = nIconIndex;
212 program->hWorkDir = hWorkDir;
213 program->hIcon = hIcon;
214 program->nCmdShow = nCmdShow;
215 program->nHotKey = nHotKey;
218 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME, lpszName,
219 WS_CHILD | WS_CAPTION,
220 x, y, CW_USEDEFAULT, CW_USEDEFAULT,
221 group->hWnd, 0, Globals.hInstance, 0);
223 SetWindowLongPtr(program->hWnd, 0, (LONG_PTR) hProgram);
225 ShowWindow (program->hWnd, SW_SHOWMINIMIZED);
226 SetWindowPos (program->hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
227 UpdateWindow (program->hWnd);
232 /***********************************************************************
234 * PROGRAM_CopyMoveProgram
237 VOID PROGRAM_CopyMoveProgram(HLOCAL hProgram, BOOL bMove)
239 PROGRAM *program = LocalLock(hProgram);
240 PROGGROUP *fromgroup = LocalLock(program->hGroup);
241 HLOCAL hGroup = DIALOG_CopyMove(LocalLock(program->hName),
242 LocalLock(fromgroup->hName), bMove);
245 /* FIXME shouldn't be necessary */
246 OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd);
248 if (!PROGRAM_AddProgram(hGroup,
250 CopyIcon(program->hIcon),
254 LocalLock(program->hName),
255 program->x, program->y,
256 LocalLock(program->hCmdLine),
257 LocalLock(program->hIconFile),
259 LocalLock(program->hWorkDir),
260 program->nHotKey, program->nCmdShow)) return;
261 GRPFILE_WriteGroupFile(hGroup);
263 if (bMove) PROGRAM_DeleteProgram(hProgram, TRUE);
266 /***********************************************************************
268 * PROGRAM_ExecuteProgram
271 VOID PROGRAM_ExecuteProgram(HLOCAL hProgram)
273 PROGRAM *program = LocalLock(hProgram);
274 LPSTR lpszCmdLine = LocalLock(program->hCmdLine);
276 /* FIXME set working directory from program->hWorkDir */
278 WinExec(lpszCmdLine, program->nCmdShow);
279 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
282 /***********************************************************************
284 * PROGRAM_DeleteProgram
287 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
289 PROGRAM *program = LocalLock(hProgram);
290 PROGGROUP *group = LocalLock(program->hGroup);
292 group->hActiveProgram = 0;
295 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
297 ((PROGGROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
300 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
303 GRPFILE_WriteGroupFile(program->hGroup);
305 DestroyWindow(program->hWnd);
308 DestroyIcon(program->hIcon);
310 LocalFree(program->hName);
311 LocalFree(program->hCmdLine);
312 LocalFree(program->hIconFile);
313 LocalFree(program->hWorkDir);
317 /***********************************************************************
319 * PROGRAM_FirstProgram
322 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
325 if (!hGroup) return(0);
326 group = LocalLock(hGroup);
327 return(group->hPrograms);
330 /***********************************************************************
332 * PROGRAM_NextProgram
335 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
338 if (!hProgram) return(0);
339 program = LocalLock(hProgram);
340 return(program->hNext);
343 /***********************************************************************
345 * PROGRAM_ActiveProgram
348 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
351 if (!hGroup) return(0);
352 group = LocalLock(hGroup);
353 if (IsIconic(group->hWnd)) return(0);
355 return(group->hActiveProgram);
358 /***********************************************************************
360 * PROGRAM_ProgramName
363 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
366 if (!hProgram) return(0);
367 program = LocalLock(hProgram);
368 return(LocalLock(program->hName));
371 /* Local Variables: */
372 /* c-file-style: "GNU" */