group.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #define WIN32_LEAN_AND_MEAN
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "windows.h"
  24. #include "progman.h"
  25. /***********************************************************************
  26. *
  27. * GROUP_GroupWndProc
  28. */
  29. static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
  30. WPARAM wParam, LPARAM lParam)
  31. {
  32. switch (msg)
  33. {
  34. case WM_SYSCOMMAND:
  35. if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
  36. break;
  37. case WM_CHILDACTIVATE:
  38. case WM_NCLBUTTONDOWN:
  39. Globals.hActiveGroup = (HLOCAL)GetWindowLongPtrW(hWnd, 0);
  40. EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_GRAYED);
  41. EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_GRAYED);
  42. break;
  43. }
  44. return DefMDIChildProcW(hWnd, msg, wParam, lParam);
  45. }
  46. /***********************************************************************
  47. *
  48. * GROUP_RegisterGroupWinClass
  49. */
  50. ATOM GROUP_RegisterGroupWinClass(void)
  51. {
  52. WNDCLASSW class;
  53. class.style = CS_HREDRAW | CS_VREDRAW;
  54. class.lpfnWndProc = GROUP_GroupWndProc;
  55. class.cbClsExtra = 0;
  56. class.cbWndExtra = sizeof(LONG_PTR);
  57. class.hInstance = Globals.hInstance;
  58. class.hIcon = LoadIconW (0, (LPWSTR)IDI_WINLOGO);
  59. class.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
  60. class.hbrBackground = GetStockObject (WHITE_BRUSH);
  61. class.lpszMenuName = 0;
  62. class.lpszClassName = STRING_GROUP_WIN_CLASS_NAME;
  63. return RegisterClassW(&class);
  64. }
  65. /***********************************************************************
  66. *
  67. * GROUP_NewGroup
  68. */
  69. VOID GROUP_NewGroup(void)
  70. {
  71. CHAR szName[MAX_PATHNAME_LEN] = "";
  72. CHAR szFile[MAX_PATHNAME_LEN] = "";
  73. OFSTRUCT dummy;
  74. if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
  75. if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
  76. {
  77. /* File doesn't exist */
  78. HLOCAL hGroup =
  79. GROUP_AddGroup(szName, szFile, SW_SHOWNORMAL,
  80. DEF_GROUP_WIN_XPOS, DEF_GROUP_WIN_YPOS,
  81. DEF_GROUP_WIN_WIDTH, DEF_GROUP_WIN_HEIGHT, 0, 0,
  82. FALSE, FALSE, FALSE);
  83. if (!hGroup) return;
  84. GRPFILE_WriteGroupFile(hGroup);
  85. }
  86. else /* File exist */
  87. GRPFILE_ReadGroupFile(szFile);
  88. /* FIXME Update progman.ini */
  89. }
  90. /***********************************************************************
  91. *
  92. * GROUP_AddGroup
  93. */
  94. HLOCAL GROUP_AddGroup(LPCSTR lpszName, LPCSTR lpszGrpFile, INT nCmdShow,
  95. INT x, INT y, INT width, INT height,
  96. INT iconx, INT icony,
  97. BOOL bFileNameModified, BOOL bOverwriteFileOk,
  98. /* FIXME shouldn't be necessary */
  99. BOOL bSuppressShowWindow)
  100. {
  101. PROGGROUP *group, *prior;
  102. MDICREATESTRUCTW cs;
  103. INT seqnum;
  104. HLOCAL hPrior, *p;
  105. HLOCAL hGroup = LocalAlloc(LMEM_FIXED, sizeof(PROGGROUP));
  106. HLOCAL hName = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszName));
  107. HLOCAL hGrpFile = LocalAlloc(LMEM_FIXED, 1 + strlen(lpszGrpFile));
  108. if (!hGroup || !hName || !hGrpFile)
  109. {
  110. MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
  111. if (hGroup) LocalFree(hGroup);
  112. if (hName) LocalFree(hName);
  113. if (hGrpFile) LocalFree(hGrpFile);
  114. return(0);
  115. }
  116. memcpy(LocalLock(hName), lpszName, 1 + strlen(lpszName));
  117. memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + strlen(lpszGrpFile));
  118. Globals.hActiveGroup = hGroup;
  119. seqnum = 1;
  120. hPrior = 0;
  121. p = &Globals.hGroups;
  122. while (*p)
  123. {
  124. hPrior = *p;
  125. prior = LocalLock(hPrior);
  126. p = &prior->hNext;
  127. if (prior->seqnum >= seqnum)
  128. seqnum = prior->seqnum + 1;
  129. }
  130. *p = hGroup;
  131. group = LocalLock(hGroup);
  132. group->hPrior = hPrior;
  133. group->hNext = 0;
  134. group->hName = hName;
  135. group->hGrpFile = hGrpFile;
  136. group->bFileNameModified = bFileNameModified;
  137. group->bOverwriteFileOk = bOverwriteFileOk;
  138. group->seqnum = seqnum;
  139. group->nCmdShow = nCmdShow;
  140. group->x = x;
  141. group->y = y;
  142. group->width = width;
  143. group->height = height;
  144. group->iconx = iconx;
  145. group->icony = icony;
  146. group->hPrograms = 0;
  147. group->hActiveProgram = 0;
  148. cs.szClass = STRING_GROUP_WIN_CLASS_NAME;
  149. cs.szTitle = NULL;
  150. cs.hOwner = 0;
  151. cs.x = x;
  152. cs.y = y;
  153. cs.cx = width;
  154. cs.cy = height;
  155. cs.style = 0;
  156. cs.lParam = 0;
  157. group->hWnd = (HWND)SendMessageA(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);
  158. SetWindowTextA( group->hWnd, lpszName );
  159. SetWindowLongPtrW(group->hWnd, 0, (LONG_PTR) hGroup);
  160. #if 1
  161. if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
  162. #endif
  163. {
  164. ShowWindow (group->hWnd, nCmdShow);
  165. UpdateWindow (group->hWnd);
  166. }
  167. return(hGroup);
  168. }
  169. /***********************************************************************
  170. *
  171. * GROUP_ModifyGroup
  172. */
  173. VOID GROUP_ModifyGroup(HLOCAL hGroup)
  174. {
  175. PROGGROUP *group = LocalLock(hGroup);
  176. CHAR szName[MAX_PATHNAME_LEN];
  177. CHAR szFile[MAX_PATHNAME_LEN];
  178. lstrcpynA(szName, LocalLock(group->hName), MAX_PATHNAME_LEN);
  179. lstrcpynA(szFile, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN);
  180. if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;
  181. if (strcmp(szFile, LocalLock(group->hGrpFile)))
  182. group->bOverwriteFileOk = FALSE;
  183. MAIN_ReplaceString(&group->hName, szName);
  184. MAIN_ReplaceString(&group->hGrpFile, szFile);
  185. GRPFILE_WriteGroupFile(hGroup);
  186. /* FIXME Delete old GrpFile if GrpFile changed */
  187. /* FIXME Update progman.ini */
  188. SetWindowTextA(group->hWnd, szName);
  189. }
  190. /***********************************************************************
  191. *
  192. * GROUP_ShowGroupWindow
  193. */
  194. /* FIXME shouldn't be necessary */
  195. VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
  196. {
  197. PROGGROUP *group = LocalLock(hGroup);
  198. ShowWindow (group->hWnd, group->nCmdShow);
  199. UpdateWindow (group->hWnd);
  200. }
  201. /***********************************************************************
  202. *
  203. * GROUP_DeleteGroup
  204. */
  205. VOID GROUP_DeleteGroup(HLOCAL hGroup)
  206. {
  207. PROGGROUP *group = LocalLock(hGroup);
  208. Globals.hActiveGroup = 0;
  209. if (group->hPrior)
  210. ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
  211. else Globals.hGroups = group->hNext;
  212. if (group->hNext)
  213. ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
  214. while (group->hPrograms)
  215. PROGRAM_DeleteProgram(group->hPrograms, FALSE);
  216. /* FIXME Update progman.ini */
  217. SendMessageW(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);
  218. LocalFree(group->hName);
  219. LocalFree(group->hGrpFile);
  220. LocalFree(hGroup);
  221. }
  222. /***********************************************************************
  223. *
  224. * GROUP_FirstGroup
  225. */
  226. HLOCAL GROUP_FirstGroup(void)
  227. {
  228. return(Globals.hGroups);
  229. }
  230. /***********************************************************************
  231. *
  232. * GROUP_NextGroup
  233. */
  234. HLOCAL GROUP_NextGroup(HLOCAL hGroup)
  235. {
  236. PROGGROUP *group;
  237. if (!hGroup) return(0);
  238. group = LocalLock(hGroup);
  239. return(group->hNext);
  240. }
  241. /***********************************************************************
  242. *
  243. * GROUP_ActiveGroup
  244. */
  245. HLOCAL GROUP_ActiveGroup(void)
  246. {
  247. return(Globals.hActiveGroup);
  248. }
  249. /***********************************************************************
  250. *
  251. * GROUP_GroupWnd
  252. */
  253. HWND GROUP_GroupWnd(HLOCAL hGroup)
  254. {
  255. PROGGROUP *group;
  256. if (!hGroup) return(0);
  257. group = LocalLock(hGroup);
  258. return(group->hWnd);
  259. }
  260. /***********************************************************************
  261. *
  262. * GROUP_GroupName
  263. */
  264. LPCSTR GROUP_GroupName(HLOCAL hGroup)
  265. {
  266. PROGGROUP *group;
  267. if (!hGroup) return(0);
  268. group = LocalLock(hGroup);
  269. return(LocalLock(group->hName));
  270. }