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