mlang: Implement DllCanUnloadNow.
[wine/gsoc_dplay.git] / programs / progman / group.c
blob2f8c5fccfa508d6fa4c276d462f42d9de6cf63dc
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define WIN32_LEAN_AND_MEAN
23 #include <stdio.h>
24 #include <string.h>
25 #include "windows.h"
26 #include "windowsx.h"
27 #include "progman.h"
29 /***********************************************************************
31 * GROUP_GroupWndProc
34 static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
35 WPARAM wParam, LPARAM lParam)
37 #if 0
38 printf("G %4.4x %4.4x\n", msg, wParam);
39 #endif
40 switch (msg)
42 case WM_SYSCOMMAND:
43 if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
44 break;
46 case WM_CHILDACTIVATE:
47 case WM_NCLBUTTONDOWN:
48 Globals.hActiveGroup = (HLOCAL) GetWindowLong(hWnd, 0);
49 EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_GRAYED);
50 EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_GRAYED);
51 break;
53 return(DefMDIChildProc(hWnd, msg, wParam, lParam));
56 /***********************************************************************
58 * GROUP_RegisterGroupWinClass
61 ATOM GROUP_RegisterGroupWinClass()
63 WNDCLASS class;
65 class.style = CS_HREDRAW | CS_VREDRAW;
66 class.lpfnWndProc = GROUP_GroupWndProc;
67 class.cbClsExtra = 0;
68 class.cbWndExtra = sizeof(LONG);
69 class.hInstance = Globals.hInstance;
70 class.hIcon = LoadIcon (0, IDI_WINLOGO);
71 class.hCursor = LoadCursor (0, IDC_ARROW);
72 class.hbrBackground = GetStockObject (WHITE_BRUSH);
73 class.lpszMenuName = 0;
74 class.lpszClassName = STRING_GROUP_WIN_CLASS_NAME;
76 return RegisterClass(&class);
79 /***********************************************************************
81 * GROUP_NewGroup
84 VOID GROUP_NewGroup()
86 CHAR szName[MAX_PATHNAME_LEN] = "";
87 CHAR szFile[MAX_PATHNAME_LEN] = "";
88 OFSTRUCT dummy;
90 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
92 if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
94 /* File doesn't exist */
95 HLOCAL hGroup =
96 GROUP_AddGroup(szName, szFile, SW_SHOWNORMAL,
97 DEF_GROUP_WIN_XPOS, DEF_GROUP_WIN_YPOS,
98 DEF_GROUP_WIN_WIDTH, DEF_GROUP_WIN_HEIGHT, 0, 0,
99 FALSE, FALSE, FALSE);
100 if (!hGroup) return;
101 GRPFILE_WriteGroupFile(hGroup);
103 else /* File exist */
104 GRPFILE_ReadGroupFile(szFile);
106 /* FIXME Update progman.ini */
109 /***********************************************************************
111 * GROUP_AddGroup
114 HLOCAL GROUP_AddGroup(LPCSTR lpszName, LPCSTR lpszGrpFile, INT nCmdShow,
115 INT x, INT y, INT width, INT height,
116 INT iconx, INT icony,
117 BOOL bFileNameModified, BOOL bOverwriteFileOk,
118 /* FIXME shouldn't be necessary */
119 BOOL bSuppressShowWindow)
121 PROGGROUP *group, *prior;
122 MDICREATESTRUCT cs;
123 INT seqnum;
124 HLOCAL hPrior, *p;
125 HLOCAL hGroup = LocalAlloc(LMEM_FIXED, sizeof(PROGGROUP));
126 HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
127 HLOCAL hGrpFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszGrpFile));
128 if (!hGroup || !hName || !hGrpFile)
130 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
131 if (hGroup) LocalFree(hGroup);
132 if (hName) LocalFree(hName);
133 if (hGrpFile) LocalFree(hGrpFile);
134 return(0);
136 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
137 memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + lstrlen(lpszGrpFile));
139 Globals.hActiveGroup = hGroup;
141 seqnum = 1;
142 hPrior = 0;
143 p = &Globals.hGroups;
144 while (*p)
146 hPrior = *p;
147 prior = LocalLock(hPrior);
148 p = &prior->hNext;
149 if (prior->seqnum >= seqnum)
150 seqnum = prior->seqnum + 1;
152 *p = hGroup;
154 group = LocalLock(hGroup);
155 group->hPrior = hPrior;
156 group->hNext = 0;
157 group->hName = hName;
158 group->hGrpFile = hGrpFile;
159 group->bFileNameModified = bFileNameModified;
160 group->bOverwriteFileOk = bOverwriteFileOk;
161 group->seqnum = seqnum;
162 group->nCmdShow = nCmdShow;
163 group->x = x;
164 group->y = y;
165 group->width = width;
166 group->height = height;
167 group->iconx = iconx;
168 group->icony = icony;
169 group->hPrograms = 0;
170 group->hActiveProgram = 0;
172 cs.szClass = STRING_GROUP_WIN_CLASS_NAME;
173 cs.szTitle = (LPSTR)lpszName;
174 cs.hOwner = 0;
175 cs.x = x;
176 cs.y = y;
177 cs.cx = width;
178 cs.cy = height;
179 cs.style = 0;
180 cs.lParam = 0;
182 group->hWnd = (HWND)SendMessage(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
184 SetWindowLong(group->hWnd, 0, (LONG) hGroup);
186 #if 1
187 if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
188 #endif
190 ShowWindow (group->hWnd, nCmdShow);
191 UpdateWindow (group->hWnd);
194 return(hGroup);
197 /***********************************************************************
199 * GROUP_ModifyGroup
202 VOID GROUP_ModifyGroup(HLOCAL hGroup)
204 PROGGROUP *group = LocalLock(hGroup);
205 CHAR szName[MAX_PATHNAME_LEN];
206 CHAR szFile[MAX_PATHNAME_LEN];
207 lstrcpyn(szName, LocalLock(group->hName), MAX_PATHNAME_LEN);
208 lstrcpyn(szFile, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN);
210 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
212 if (strcmp(szFile, LocalLock(group->hGrpFile)))
213 group->bOverwriteFileOk = FALSE;
215 MAIN_ReplaceString(&group->hName, szName);
216 MAIN_ReplaceString(&group->hGrpFile, szFile);
218 GRPFILE_WriteGroupFile(hGroup);
220 /* FIXME Delete old GrpFile if GrpFile changed */
222 /* FIXME Update progman.ini */
224 SetWindowText(group->hWnd, szName);
227 /***********************************************************************
229 * GROUP_ShowGroupWindow
232 /* FIXME shouldn't be necessary */
233 VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
235 PROGGROUP *group = LocalLock(hGroup);
236 ShowWindow (group->hWnd, group->nCmdShow);
237 UpdateWindow (group->hWnd);
240 /***********************************************************************
242 * GROUP_DeleteGroup
245 VOID GROUP_DeleteGroup(HLOCAL hGroup)
247 PROGGROUP *group = LocalLock(hGroup);
249 Globals.hActiveGroup = 0;
251 if (group->hPrior)
252 ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
253 else Globals.hGroups = group->hNext;
255 if (group->hNext)
256 ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
258 while (group->hPrograms)
259 PROGRAM_DeleteProgram(group->hPrograms, FALSE);
261 /* FIXME Update progman.ini */
263 SendMessage(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
265 LocalFree(group->hName);
266 LocalFree(group->hGrpFile);
267 LocalFree(hGroup);
270 /***********************************************************************
272 * GROUP_FirstGroup
275 HLOCAL GROUP_FirstGroup()
277 return(Globals.hGroups);
280 /***********************************************************************
282 * GROUP_NextGroup
285 HLOCAL GROUP_NextGroup(HLOCAL hGroup)
287 PROGGROUP *group;
288 if (!hGroup) return(0);
289 group = LocalLock(hGroup);
290 return(group->hNext);
293 /***********************************************************************
295 * GROUP_ActiveGroup
298 HLOCAL GROUP_ActiveGroup()
300 return(Globals.hActiveGroup);
303 /***********************************************************************
305 * GROUP_GroupWnd
308 HWND GROUP_GroupWnd(HLOCAL hGroup)
310 PROGGROUP *group;
311 if (!hGroup) return(0);
312 group = LocalLock(hGroup);
313 return(group->hWnd);
316 /***********************************************************************
318 * GROUP_GroupName
321 LPCSTR GROUP_GroupName(HLOCAL hGroup)
323 PROGGROUP *group;
324 if (!hGroup) return(0);
325 group = LocalLock(hGroup);
326 return(LocalLock(group->hName));
329 /* Local Variables: */
330 /* c-file-style: "GNU" */
331 /* End: */