gdiplus: Implemented GdipAddPathCurve2I using GdipAddPathCurve2.
[wine/gsoc_dplay.git] / programs / progman / program.c
blobbfbbc89e7b1eb5e8973b9f73af34b4caabec5a7e
1 /*
2 * Program Manager
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
23 #include <string.h>
24 #include "windows.h"
25 #include "progman.h"
27 /***********************************************************************
29 * PROGRAM_ProgramWndProc
32 static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
34 switch (msg)
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);
44 break;
46 case WM_NCLBUTTONDBLCLK:
48 PROGRAM_ExecuteProgram((HLOCAL) GetWindowLongPtr(hWnd, 0));
49 return(0);
52 case WM_PAINTICON:
53 case WM_NCPAINT:
55 PROGRAM *program;
56 PAINTSTRUCT ps;
57 HDC hdc;
58 hdc = BeginPaint(hWnd,&ps);
59 program = LocalLock((HLOCAL) GetWindowLongPtr(hWnd, 0));
60 if (program->hIcon)
61 DrawIcon(hdc, 0, 0, program->hIcon);
62 EndPaint(hWnd,&ps);
63 break;
66 return(DefWindowProc(hWnd, msg, wParam, lParam));
69 /***********************************************************************
71 * PROGRAM_RegisterProgramWinClass
74 ATOM PROGRAM_RegisterProgramWinClass(void)
76 WNDCLASS class;
78 class.style = CS_HREDRAW | CS_VREDRAW;
79 class.lpfnWndProc = PROGRAM_ProgramWndProc;
80 class.cbClsExtra = 0;
81 class.cbWndExtra = sizeof(LONG_PTR);
82 class.hInstance = Globals.hInstance;
83 class.hIcon = 0;
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 /***********************************************************************
94 * PROGRAM_NewProgram
97 VOID PROGRAM_NewProgram(HLOCAL hGroup)
99 INT nCmdShow = SW_SHOWNORMAL;
100 INT nHotKey = 0;
101 INT nIconIndex = 0;
102 CHAR szName[MAX_PATHNAME_LEN] = "";
103 CHAR szCmdLine[MAX_PATHNAME_LEN] = "";
104 CHAR szIconFile[MAX_PATHNAME_LEN] = "";
105 CHAR szWorkDir[MAX_PATHNAME_LEN] = "";
106 HICON hIcon = 0;
108 if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
109 &hIcon, &nIconIndex, &nHotKey,
110 &nCmdShow, MAX_PATHNAME_LEN))
111 return;
113 if (!hIcon) hIcon = LoadIcon(0, IDI_WINLOGO);
116 if (!PROGRAM_AddProgram(hGroup, hIcon, szName, 0, 0, szCmdLine, szIconFile,
117 nIconIndex, szWorkDir, nHotKey, nCmdShow))
118 return;
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,
144 MAX_PATHNAME_LEN))
145 return;
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);
157 return;
160 /***********************************************************************
162 * PROGRAM_AddProgram
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);
171 PROGRAM *program;
172 HLOCAL hPrior, *p;
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);
186 return(0);
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;
195 hPrior = 0;
196 p = &group->hPrograms;
197 while (*p)
199 hPrior = *p;
200 p = &((PROGRAM*)LocalLock(hPrior))->hNext;
202 *p = hProgram;
204 program = LocalLock(hProgram);
205 program->hGroup = hGroup;
206 program->hPrior = hPrior;
207 program->hNext = 0;
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;
217 program->hWnd =
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);
229 return hProgram;
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);
243 if (!hGroup) return;
245 /* FIXME shouldn't be necessary */
246 OpenIcon(((PROGGROUP*)LocalLock(hGroup))->hWnd);
248 if (!PROGRAM_AddProgram(hGroup,
249 #if 0
250 CopyIcon(program->hIcon),
251 #else
252 program->hIcon,
253 #endif
254 LocalLock(program->hName),
255 program->x, program->y,
256 LocalLock(program->hCmdLine),
257 LocalLock(program->hIconFile),
258 program->nIconIndex,
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);
275 LPSTR lpszWorkDir = LocalLock(program->hWorkDir);
277 /* FIXME set working directory */
278 lpszWorkDir = lpszWorkDir;
280 WinExec(lpszCmdLine, program->nCmdShow);
281 if (Globals.bMinOnRun) CloseWindow(Globals.hMainWnd);
284 /***********************************************************************
286 * PROGRAM_DeleteProgram
289 VOID PROGRAM_DeleteProgram(HLOCAL hProgram, BOOL bUpdateGrpFile)
291 PROGRAM *program = LocalLock(hProgram);
292 PROGGROUP *group = LocalLock(program->hGroup);
294 group->hActiveProgram = 0;
296 if (program->hPrior)
297 ((PROGRAM*)LocalLock(program->hPrior))->hNext = program->hNext;
298 else
299 ((PROGGROUP*)LocalLock(program->hGroup))->hPrograms = program->hNext;
301 if (program->hNext)
302 ((PROGRAM*)LocalLock(program->hNext))->hPrior = program->hPrior;
304 if (bUpdateGrpFile)
305 GRPFILE_WriteGroupFile(program->hGroup);
307 DestroyWindow(program->hWnd);
308 #if 0
309 if (program->hIcon)
310 DestroyIcon(program->hIcon);
311 #endif
312 LocalFree(program->hName);
313 LocalFree(program->hCmdLine);
314 LocalFree(program->hIconFile);
315 LocalFree(program->hWorkDir);
316 LocalFree(hProgram);
319 /***********************************************************************
321 * PROGRAM_FirstProgram
324 HLOCAL PROGRAM_FirstProgram(HLOCAL hGroup)
326 PROGGROUP *group;
327 if (!hGroup) return(0);
328 group = LocalLock(hGroup);
329 return(group->hPrograms);
332 /***********************************************************************
334 * PROGRAM_NextProgram
337 HLOCAL PROGRAM_NextProgram(HLOCAL hProgram)
339 PROGRAM *program;
340 if (!hProgram) return(0);
341 program = LocalLock(hProgram);
342 return(program->hNext);
345 /***********************************************************************
347 * PROGRAM_ActiveProgram
350 HLOCAL PROGRAM_ActiveProgram(HLOCAL hGroup)
352 PROGGROUP *group;
353 if (!hGroup) return(0);
354 group = LocalLock(hGroup);
355 if (IsIconic(group->hWnd)) return(0);
357 return(group->hActiveProgram);
360 /***********************************************************************
362 * PROGRAM_ProgramName
365 LPCSTR PROGRAM_ProgramName(HLOCAL hProgram)
367 PROGRAM *program;
368 if (!hProgram) return(0);
369 program = LocalLock(hProgram);
370 return(LocalLock(program->hName));
373 /* Local Variables: */
374 /* c-file-style: "GNU" */
375 /* End: */