kernel32: comm.c: increase time slop.
[wine/wine64.git] / programs / progman / group.c
blobc8e79edfd17fa8a6b3613900863499e68f27972c
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
23 #include <stdio.h>
24 #include <string.h>
25 #include "windows.h"
26 #include "progman.h"
28 /***********************************************************************
30 * GROUP_GroupWndProc
33 static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
34 WPARAM wParam, LPARAM lParam)
36 #if 0
37 printf("G %4.4x %4.4x\n", msg, wParam);
38 #endif
39 switch (msg)
41 case WM_SYSCOMMAND:
42 if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
43 break;
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;
52 return(DefMDIChildProc(hWnd, msg, wParam, lParam));
55 /***********************************************************************
57 * GROUP_RegisterGroupWinClass
60 ATOM GROUP_RegisterGroupWinClass(void)
62 WNDCLASS class;
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;
75 return RegisterClass(&class);
78 /***********************************************************************
80 * GROUP_NewGroup
83 VOID GROUP_NewGroup(void)
85 CHAR szName[MAX_PATHNAME_LEN] = "";
86 CHAR szFile[MAX_PATHNAME_LEN] = "";
87 OFSTRUCT dummy;
89 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
91 if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
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);
102 else /* File exist */
103 GRPFILE_ReadGroupFile(szFile);
105 /* FIXME Update progman.ini */
108 /***********************************************************************
110 * GROUP_AddGroup
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)
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)
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);
135 memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
136 memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + lstrlen(lpszGrpFile));
138 Globals.hActiveGroup = hGroup;
140 seqnum = 1;
141 hPrior = 0;
142 p = &Globals.hGroups;
143 while (*p)
145 hPrior = *p;
146 prior = LocalLock(hPrior);
147 p = &prior->hNext;
148 if (prior->seqnum >= seqnum)
149 seqnum = prior->seqnum + 1;
151 *p = hGroup;
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;
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;
181 group->hWnd = (HWND)SendMessage(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
183 SetWindowLongPtr(group->hWnd, 0, (LONG_PTR) hGroup);
185 #if 1
186 if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
187 #endif
189 ShowWindow (group->hWnd, nCmdShow);
190 UpdateWindow (group->hWnd);
193 return(hGroup);
196 /***********************************************************************
198 * GROUP_ModifyGroup
201 VOID GROUP_ModifyGroup(HLOCAL hGroup)
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);
209 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
211 if (strcmp(szFile, LocalLock(group->hGrpFile)))
212 group->bOverwriteFileOk = FALSE;
214 MAIN_ReplaceString(&group->hName, szName);
215 MAIN_ReplaceString(&group->hGrpFile, szFile);
217 GRPFILE_WriteGroupFile(hGroup);
219 /* FIXME Delete old GrpFile if GrpFile changed */
221 /* FIXME Update progman.ini */
223 SetWindowText(group->hWnd, szName);
226 /***********************************************************************
228 * GROUP_ShowGroupWindow
231 /* FIXME shouldn't be necessary */
232 VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
234 PROGGROUP *group = LocalLock(hGroup);
235 ShowWindow (group->hWnd, group->nCmdShow);
236 UpdateWindow (group->hWnd);
239 /***********************************************************************
241 * GROUP_DeleteGroup
244 VOID GROUP_DeleteGroup(HLOCAL hGroup)
246 PROGGROUP *group = LocalLock(hGroup);
248 Globals.hActiveGroup = 0;
250 if (group->hPrior)
251 ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
252 else Globals.hGroups = group->hNext;
254 if (group->hNext)
255 ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
257 while (group->hPrograms)
258 PROGRAM_DeleteProgram(group->hPrograms, FALSE);
260 /* FIXME Update progman.ini */
262 SendMessage(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
264 LocalFree(group->hName);
265 LocalFree(group->hGrpFile);
266 LocalFree(hGroup);
269 /***********************************************************************
271 * GROUP_FirstGroup
274 HLOCAL GROUP_FirstGroup(void)
276 return(Globals.hGroups);
279 /***********************************************************************
281 * GROUP_NextGroup
284 HLOCAL GROUP_NextGroup(HLOCAL hGroup)
286 PROGGROUP *group;
287 if (!hGroup) return(0);
288 group = LocalLock(hGroup);
289 return(group->hNext);
292 /***********************************************************************
294 * GROUP_ActiveGroup
297 HLOCAL GROUP_ActiveGroup(void)
299 return(Globals.hActiveGroup);
302 /***********************************************************************
304 * GROUP_GroupWnd
307 HWND GROUP_GroupWnd(HLOCAL hGroup)
309 PROGGROUP *group;
310 if (!hGroup) return(0);
311 group = LocalLock(hGroup);
312 return(group->hWnd);
315 /***********************************************************************
317 * GROUP_GroupName
320 LPCSTR GROUP_GroupName(HLOCAL hGroup)
322 PROGGROUP *group;
323 if (!hGroup) return(0);
324 group = LocalLock(hGroup);
325 return(LocalLock(group->hName));
328 /* Local Variables: */
329 /* c-file-style: "GNU" */
330 /* End: */