msi: Unload riched20 after its window is destroyed.
[wine/multimedia.git] / programs / progman / group.c
blob211776d8cb06d304bfc475e5f7d991915066f031
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 #include <stdio.h>
22 #include <string.h>
23 #include "windows.h"
24 #include "windowsx.h"
25 #include "progman.h"
27 /***********************************************************************
29 * GROUP_GroupWndProc
32 static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
33 WPARAM wParam, LPARAM lParam)
35 #if 0
36 printf("G %4.4x %4.4x\n", msg, wParam);
37 #endif
38 switch (msg)
40 case WM_SYSCOMMAND:
41 if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
42 break;
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;
51 return(DefMDIChildProc(hWnd, msg, wParam, lParam));
54 /***********************************************************************
56 * GROUP_RegisterGroupWinClass
59 ATOM GROUP_RegisterGroupWinClass()
61 WNDCLASS class;
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;
74 return RegisterClass(&class);
77 /***********************************************************************
79 * GROUP_NewGroup
82 VOID GROUP_NewGroup()
84 CHAR szName[MAX_PATHNAME_LEN] = "";
85 CHAR szFile[MAX_PATHNAME_LEN] = "";
86 OFSTRUCT dummy;
88 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
90 if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
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);
101 else /* File exist */
102 GRPFILE_ReadGroupFile(szFile);
104 /* FIXME Update progman.ini */
107 /***********************************************************************
109 * GROUP_AddGroup
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)
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)
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);
134 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
135 memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + lstrlen(lpszGrpFile));
137 Globals.hActiveGroup = hGroup;
139 seqnum = 1;
140 hPrior = 0;
141 p = &Globals.hGroups;
142 while (*p)
144 hPrior = *p;
145 prior = LocalLock(hPrior);
146 p = &prior->hNext;
147 if (prior->seqnum >= seqnum)
148 seqnum = prior->seqnum + 1;
150 *p = hGroup;
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;
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;
180 group->hWnd = (HWND)SendMessage(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
182 SetWindowLong(group->hWnd, 0, (LONG) hGroup);
184 #if 1
185 if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
186 #endif
188 ShowWindow (group->hWnd, nCmdShow);
189 UpdateWindow (group->hWnd);
192 return(hGroup);
195 /***********************************************************************
197 * GROUP_ModifyGroup
200 VOID GROUP_ModifyGroup(HLOCAL hGroup)
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);
208 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
210 if (strcmp(szFile, LocalLock(group->hGrpFile)))
211 group->bOverwriteFileOk = FALSE;
213 MAIN_ReplaceString(&group->hName, szName);
214 MAIN_ReplaceString(&group->hGrpFile, szFile);
216 GRPFILE_WriteGroupFile(hGroup);
218 /* FIXME Delete old GrpFile if GrpFile changed */
220 /* FIXME Update progman.ini */
222 SetWindowText(group->hWnd, szName);
225 /***********************************************************************
227 * GROUP_ShowGroupWindow
230 /* FIXME shouldn't be necessary */
231 VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
233 PROGGROUP *group = LocalLock(hGroup);
234 ShowWindow (group->hWnd, group->nCmdShow);
235 UpdateWindow (group->hWnd);
238 /***********************************************************************
240 * GROUP_DeleteGroup
243 VOID GROUP_DeleteGroup(HLOCAL hGroup)
245 PROGGROUP *group = LocalLock(hGroup);
247 Globals.hActiveGroup = 0;
249 if (group->hPrior)
250 ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
251 else Globals.hGroups = group->hNext;
253 if (group->hNext)
254 ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
256 while (group->hPrograms)
257 PROGRAM_DeleteProgram(group->hPrograms, FALSE);
259 /* FIXME Update progman.ini */
261 SendMessage(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
263 LocalFree(group->hName);
264 LocalFree(group->hGrpFile);
265 LocalFree(hGroup);
268 /***********************************************************************
270 * GROUP_FirstGroup
273 HLOCAL GROUP_FirstGroup()
275 return(Globals.hGroups);
278 /***********************************************************************
280 * GROUP_NextGroup
283 HLOCAL GROUP_NextGroup(HLOCAL hGroup)
285 PROGGROUP *group;
286 if (!hGroup) return(0);
287 group = LocalLock(hGroup);
288 return(group->hNext);
291 /***********************************************************************
293 * GROUP_ActiveGroup
296 HLOCAL GROUP_ActiveGroup()
298 return(Globals.hActiveGroup);
301 /***********************************************************************
303 * GROUP_GroupWnd
306 HWND GROUP_GroupWnd(HLOCAL hGroup)
308 PROGGROUP *group;
309 if (!hGroup) return(0);
310 group = LocalLock(hGroup);
311 return(group->hWnd);
314 /***********************************************************************
316 * GROUP_GroupName
319 LPCSTR GROUP_GroupName(HLOCAL hGroup)
321 PROGGROUP *group;
322 if (!hGroup) return(0);
323 group = LocalLock(hGroup);
324 return(LocalLock(group->hName));
327 /* Local Variables: */
328 /* c-file-style: "GNU" */
329 /* End: */