Reimplemented Read/WriteFile to use server file descriptors.
[wine/multimedia.git] / programs / progman / group.c
blob0fcbadaa7a16f1766194940acfffab2f45280d85
1 /*
2 * Program Manager
4 * Copyright 1996 Ulrich Schmid
5 */
7 #include <stdio.h>
8 #include "windows.h"
9 #include "progman.h"
11 /***********************************************************************
13 * GROUP_GroupWndProc
16 static LRESULT GROUP_GroupWndProc (HWND hWnd, UINT msg,
17 WPARAM wParam, LPARAM lParam)
19 #if 0
20 printf("G %4.4x %4.4x\n", msg, wParam);
21 #endif
22 switch (msg)
24 case WM_SYSCOMMAND:
25 if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
26 break;
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;
35 return(DefMDIChildProc(hWnd, msg, wParam, lParam));
38 /***********************************************************************
40 * GROUP_RegisterGroupWinClass
43 ATOM GROUP_RegisterGroupWinClass()
45 WNDCLASS class;
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;
58 return RegisterClass(&class);
61 /***********************************************************************
63 * GROUP_NewGroup
66 VOID GROUP_NewGroup()
68 CHAR szName[MAX_PATHNAME_LEN] = "";
69 CHAR szFile[MAX_PATHNAME_LEN] = "";
70 OFSTRUCT dummy;
72 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
74 if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
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);
85 else /* File exist */
86 GRPFILE_ReadGroupFile(szFile);
88 /* FIXME Update progman.ini */
91 /***********************************************************************
93 * GROUP_AddGroup
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)
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)
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);
118 hmemcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
119 hmemcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + lstrlen(lpszGrpFile));
121 Globals.hActiveGroup = hGroup;
123 seqnum = 1;
124 hPrior = 0;
125 p = &Globals.hGroups;
126 while (*p)
128 hPrior = *p;
129 prior = LocalLock(hPrior);
130 p = &prior->hNext;
131 if (prior->seqnum >= seqnum)
132 seqnum = prior->seqnum + 1;
134 *p = hGroup;
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;
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;
164 group->hWnd = (HWND)SendMessage(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
166 SetWindowLong(group->hWnd, 0, (LONG) hGroup);
168 #if 1
169 if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
170 #endif
172 ShowWindow (group->hWnd, nCmdShow);
173 UpdateWindow (group->hWnd);
176 return(hGroup);
179 /***********************************************************************
181 * GROUP_ModifyGroup
184 VOID GROUP_ModifyGroup(HLOCAL hGroup)
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);
192 if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
194 if (strcmp(szFile, LocalLock(group->hGrpFile)))
195 group->bOverwriteFileOk = FALSE;
197 MAIN_ReplaceString(&group->hName, szName);
198 MAIN_ReplaceString(&group->hGrpFile, szFile);
200 GRPFILE_WriteGroupFile(hGroup);
202 /* FIXME Delete old GrpFile if GrpFile changed */
204 /* FIXME Update progman.ini */
206 SetWindowText(group->hWnd, szName);
209 /***********************************************************************
211 * GROUP_ShowGroupWindow
214 /* FIXME shouldn't be necessary */
215 VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
217 GROUP *group = LocalLock(hGroup);
218 ShowWindow (group->hWnd, group->nCmdShow);
219 UpdateWindow (group->hWnd);
222 /***********************************************************************
224 * GROUP_DeleteGroup
227 VOID GROUP_DeleteGroup(HLOCAL hGroup)
229 GROUP *group = LocalLock(hGroup);
231 Globals.hActiveGroup = 0;
233 if (group->hPrior)
234 ((GROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
235 else Globals.hGroups = group->hNext;
237 if (group->hNext)
238 ((GROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
240 while (group->hPrograms)
241 PROGRAM_DeleteProgram(group->hPrograms, FALSE);
243 /* FIXME Update progman.ini */
245 SendMessage(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
247 LocalFree(group->hName);
248 LocalFree(group->hGrpFile);
249 LocalFree(hGroup);
252 /***********************************************************************
254 * GROUP_FirstGroup
257 HLOCAL GROUP_FirstGroup()
259 return(Globals.hGroups);
262 /***********************************************************************
264 * GROUP_NextGroup
267 HLOCAL GROUP_NextGroup(HLOCAL hGroup)
269 GROUP *group;
270 if (!hGroup) return(0);
271 group = LocalLock(hGroup);
272 return(group->hNext);
275 /***********************************************************************
277 * GROUP_ActiveGroup
280 HLOCAL GROUP_ActiveGroup()
282 return(Globals.hActiveGroup);
285 /***********************************************************************
287 * GROUP_GroupWnd
290 HWND GROUP_GroupWnd(HLOCAL hGroup)
292 GROUP *group;
293 if (!hGroup) return(0);
294 group = LocalLock(hGroup);
295 return(group->hWnd);
298 /***********************************************************************
300 * GROUP_GroupName
303 LPCSTR GROUP_GroupName(HLOCAL hGroup)
305 GROUP *group;
306 if (!hGroup) return(0);
307 group = LocalLock(hGroup);
308 return(LocalLock(group->hName));
311 /* Local Variables: */
312 /* c-file-style: "GNU" */
313 /* End: */