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