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