7232e0a165a8a033a4c3ac4a6b4e895ce31f52f6
[reactos.git] / reactos / base / shell / progman / group.c
1 /*
2 * Program Manager
3 *
4 * Copyright 1996 Ulrich Schmid
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "progman.h"
22
23 /***********************************************************************
24 *
25 * GROUP_GroupWndProc
26 */
27
28 static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
29 WPARAM wParam, LPARAM lParam)
30 {
31 switch (msg)
32 {
33 case WM_SYSCOMMAND:
34 if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
35 break;
36
37 case WM_CHILDACTIVATE:
38 case WM_NCLBUTTONDOWN:
39 Globals.hActiveGroup = (HLOCAL)GetWindowLongPtrW(hWnd, 0);
40 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_GRAYED);
41 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_GRAYED);
42 break;
43 }
44 return DefMDIChildProcW(hWnd, msg, wParam, lParam);
45 }
46
47 /***********************************************************************
48 *
49 * GROUP_RegisterGroupWinClass
50 */
51
52 ATOM GROUP_RegisterGroupWinClass(void)
53 {
54 WNDCLASSW class;
55
56 class.style = CS_HREDRAW | CS_VREDRAW;
57 class.lpfnWndProc = GROUP_GroupWndProc;
58 class.cbClsExtra = 0;
59 class.cbWndExtra = sizeof(LONG_PTR);
60 class.hInstance = Globals.hInstance;
61 class.hIcon = LoadIconW(0, (LPWSTR)IDI_WINLOGO);
62 class.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
63 class.hbrBackground = GetStockObject (WHITE_BRUSH);
64 class.lpszMenuName = 0;
65 class.lpszClassName = STRING_GROUP_WIN_CLASS_NAME;
66
67 return RegisterClassW(&class);
68 }
69
70 /***********************************************************************
71 *
72 * GROUP_NewGroup
73 */
74
75 VOID GROUP_NewGroup(void)
76 {
77 CHAR szName[MAX_PATHNAME_LEN] = "";
78 CHAR szFile[MAX_PATHNAME_LEN] = "";
79 OFSTRUCT dummy;
80
81 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
82
83 if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
84 {
85 /* File doesn't exist */
86 HLOCAL hGroup =
87 GROUP_AddGroup(szName, szFile, SW_SHOWNORMAL,
88 DEF_GROUP_WIN_XPOS, DEF_GROUP_WIN_YPOS,
89 DEF_GROUP_WIN_WIDTH, DEF_GROUP_WIN_HEIGHT, 0, 0,
90 FALSE, FALSE, FALSE);
91 if (!hGroup) return;
92 GRPFILE_WriteGroupFile(hGroup);
93 }
94 else /* File exist */
95 GRPFILE_ReadGroupFile(szFile);
96
97 /* FIXME Update progman.ini */
98 }
99
100 /***********************************************************************
101 *
102 * GROUP_AddGroup
103 */
104
105 HLOCAL GROUP_AddGroup(LPCSTR lpszName, LPCSTR lpszGrpFile, INT nCmdShow,
106 INT x, INT y, INT width, INT height,
107 INT iconx, INT icony,
108 BOOL bFileNameModified, BOOL bOverwriteFileOk,
109 /* FIXME shouldn't be necessary */
110 BOOL bSuppressShowWindow)
111 {
112 PROGGROUP *group, *prior;
113 MDICREATESTRUCTW cs;
114 INT seqnum;
115 HLOCAL hPrior, *p;
116 HLOCAL hGroup = LocalAlloc(LMEM_FIXED, sizeof(PROGGROUP));
117 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszName));
118 HLOCAL hGrpFile = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszGrpFile));
119 if (!hGroup || !hName || !hGrpFile)
120 {
121 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
122 if (hGroup) LocalFree(hGroup);
123 if (hName) LocalFree(hName);
124 if (hGrpFile) LocalFree(hGrpFile);
125 return(0);
126 }
127 memcpy(LocalLock(hName), lpszName, 1 + strlen(lpszName));
128 memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + strlen(lpszGrpFile));
129
130 Globals.hActiveGroup = hGroup;
131
132 seqnum = 1;
133 hPrior = 0;
134 p = &Globals.hGroups;
135 while (*p)
136 {
137 hPrior = *p;
138 prior = LocalLock(hPrior);
139 p = &prior->hNext;
140 if (prior->seqnum >= seqnum)
141 seqnum = prior->seqnum + 1;
142 }
143 *p = hGroup;
144
145 group = LocalLock(hGroup);
146 group->hPrior = hPrior;
147 group->hNext = 0;
148 group->hName = hName;
149 group->hGrpFile = hGrpFile;
150 group->bFileNameModified = bFileNameModified;
151 group->bOverwriteFileOk = bOverwriteFileOk;
152 group->seqnum = seqnum;
153 group->nCmdShow = nCmdShow;
154 group->x = x;
155 group->y = y;
156 group->width = width;
157 group->height = height;
158 group->iconx = iconx;
159 group->icony = icony;
160 group->hPrograms = 0;
161 group->hActiveProgram = 0;
162
163 cs.szClass = STRING_GROUP_WIN_CLASS_NAME;
164 cs.szTitle = NULL;
165 cs.hOwner = 0;
166 cs.x = x;
167 cs.y = y;
168 cs.cx = width;
169 cs.cy = height;
170 cs.style = 0;
171 cs.lParam = 0;
172
173 group->hWnd = (HWND)SendMessageW(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
174 SetWindowTextA( group->hWnd, lpszName );
175 SetWindowLongPtrW(group->hWnd, 0, (LONG_PTR) hGroup);
176
177 #if 1
178 if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
179 #endif
180 {
181 ShowWindow (group->hWnd, nCmdShow);
182 UpdateWindow (group->hWnd);
183 }
184
185 return(hGroup);
186 }
187
188 /***********************************************************************
189 *
190 * GROUP_ModifyGroup
191 */
192
193 VOID GROUP_ModifyGroup(HLOCAL hGroup)
194 {
195 PROGGROUP *group = LocalLock(hGroup);
196 CHAR szName[MAX_PATHNAME_LEN];
197 CHAR szFile[MAX_PATHNAME_LEN];
198 lstrcpynA(szName, LocalLock(group->hName), MAX_PATHNAME_LEN);
199 lstrcpynA(szFile, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN);
200
201 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
202
203 if (strcmp(szFile, LocalLock(group->hGrpFile)))
204 group->bOverwriteFileOk = FALSE;
205
206 MAIN_ReplaceString(&group->hName, szName);
207 MAIN_ReplaceString(&group->hGrpFile, szFile);
208
209 GRPFILE_WriteGroupFile(hGroup);
210
211 /* FIXME Delete old GrpFile if GrpFile changed */
212
213 /* FIXME Update progman.ini */
214
215 SetWindowTextA(group->hWnd, szName);
216 }
217
218 /***********************************************************************
219 *
220 * GROUP_ShowGroupWindow
221 */
222
223 /* FIXME shouldn't be necessary */
224 VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
225 {
226 PROGGROUP *group = LocalLock(hGroup);
227 ShowWindow (group->hWnd, group->nCmdShow);
228 UpdateWindow (group->hWnd);
229 }
230
231 /***********************************************************************
232 *
233 * GROUP_DeleteGroup
234 */
235
236 VOID GROUP_DeleteGroup(HLOCAL hGroup)
237 {
238 PROGGROUP *group = LocalLock(hGroup);
239
240 Globals.hActiveGroup = 0;
241
242 if (group->hPrior)
243 ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
244 else Globals.hGroups = group->hNext;
245
246 if (group->hNext)
247 ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
248
249 while (group->hPrograms)
250 PROGRAM_DeleteProgram(group->hPrograms, FALSE);
251
252 /* FIXME Update progman.ini */
253
254 SendMessageW(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
255
256 LocalFree(group->hName);
257 LocalFree(group->hGrpFile);
258 LocalFree(hGroup);
259 }
260
261 /***********************************************************************
262 *
263 * GROUP_FirstGroup
264 */
265
266 HLOCAL GROUP_FirstGroup(void)
267 {
268 return(Globals.hGroups);
269 }
270
271 /***********************************************************************
272 *
273 * GROUP_NextGroup
274 */
275
276 HLOCAL GROUP_NextGroup(HLOCAL hGroup)
277 {
278 PROGGROUP *group;
279 if (!hGroup) return(0);
280 group = LocalLock(hGroup);
281 return(group->hNext);
282 }
283
284 /***********************************************************************
285 *
286 * GROUP_ActiveGroup
287 */
288
289 HLOCAL GROUP_ActiveGroup(void)
290 {
291 return(Globals.hActiveGroup);
292 }
293
294 /***********************************************************************
295 *
296 * GROUP_GroupWnd
297 */
298
299 HWND GROUP_GroupWnd(HLOCAL hGroup)
300 {
301 PROGGROUP *group;
302 if (!hGroup) return(0);
303 group = LocalLock(hGroup);
304 return(group->hWnd);
305 }
306
307 /***********************************************************************
308 *
309 * GROUP_GroupName
310 */
311
312 LPCSTR GROUP_GroupName(HLOCAL hGroup)
313 {
314 PROGGROUP *group;
315 if (!hGroup) return(0);
316 group = LocalLock(hGroup);
317 return(LocalLock(group->hName));
318 }