group.c 8.24 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 * Program Manager
 *
 * Copyright 1996 Ulrich Schmid
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21 22
#define WIN32_LEAN_AND_MEAN

Alexandre Julliard's avatar
Alexandre Julliard committed
23
#include <stdio.h>
24
#include <string.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
25
#include "windows.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28 29 30 31 32
#include "progman.h"

/***********************************************************************
 *
 *           GROUP_GroupWndProc
 */

33
static LRESULT CALLBACK GROUP_GroupWndProc(HWND hWnd, UINT msg,
Alexandre Julliard's avatar
Alexandre Julliard committed
34 35 36 37 38 39 40 41 42 43 44 45 46
				   WPARAM wParam, LPARAM lParam)
{
#if 0
  printf("G %4.4x %4.4x\n", msg, wParam);
#endif
  switch (msg)
    {
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) wParam = SC_MINIMIZE;
      break;

    case WM_CHILDACTIVATE:
    case WM_NCLBUTTONDOWN:
Mike McCormack's avatar
Mike McCormack committed
47
      Globals.hActiveGroup = (HLOCAL) GetWindowLongPtr(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
48 49 50 51 52 53 54 55 56 57 58 59
      EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_GRAYED);
      EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_GRAYED);
      break;
    }
  return(DefMDIChildProc(hWnd, msg, wParam, lParam));
}

/***********************************************************************
 *
 *           GROUP_RegisterGroupWinClass
 */

60
ATOM GROUP_RegisterGroupWinClass(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
61 62 63 64 65 66
{
  WNDCLASS class;

  class.style         = CS_HREDRAW | CS_VREDRAW;
  class.lpfnWndProc   = GROUP_GroupWndProc;
  class.cbClsExtra    = 0;
Mike McCormack's avatar
Mike McCormack committed
67
  class.cbWndExtra    = sizeof(LONG_PTR);
Alexandre Julliard's avatar
Alexandre Julliard committed
68
  class.hInstance     = Globals.hInstance;
69
  class.hIcon         = LoadIcon (0, IDI_WINLOGO);
Alexandre Julliard's avatar
Alexandre Julliard committed
70 71 72 73 74 75 76 77 78 79 80 81 82
  class.hCursor       = LoadCursor (0, IDC_ARROW);
  class.hbrBackground = GetStockObject (WHITE_BRUSH);
  class.lpszMenuName  = 0;
  class.lpszClassName = STRING_GROUP_WIN_CLASS_NAME;

  return RegisterClass(&class);
}

/***********************************************************************
 *
 *           GROUP_NewGroup
 */

83
VOID GROUP_NewGroup(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
{
  CHAR szName[MAX_PATHNAME_LEN] = "";
  CHAR szFile[MAX_PATHNAME_LEN] = "";
  OFSTRUCT dummy;

  if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;

  if (OpenFile(szFile, &dummy, OF_EXIST) == HFILE_ERROR)
    {
      /* File doesn't exist */
      HLOCAL hGroup =
	GROUP_AddGroup(szName, szFile, SW_SHOWNORMAL,
		       DEF_GROUP_WIN_XPOS, DEF_GROUP_WIN_YPOS,
		       DEF_GROUP_WIN_WIDTH, DEF_GROUP_WIN_HEIGHT, 0, 0,
		       FALSE, FALSE, FALSE);
      if (!hGroup) return;
      GRPFILE_WriteGroupFile(hGroup);
    }
  else /* File exist */
    GRPFILE_ReadGroupFile(szFile);

  /* FIXME Update progman.ini */
}

/***********************************************************************
 *
 *           GROUP_AddGroup
 */

HLOCAL GROUP_AddGroup(LPCSTR lpszName, LPCSTR lpszGrpFile, INT nCmdShow,
		      INT x, INT y, INT width, INT height,
		      INT iconx, INT icony,
		      BOOL bFileNameModified, BOOL bOverwriteFileOk,
		      /* FIXME shouldn't be necessary */
		      BOOL bSuppressShowWindow)
{
120
  PROGGROUP *group, *prior;
Alexandre Julliard's avatar
Alexandre Julliard committed
121 122 123
  MDICREATESTRUCT cs;
  INT    seqnum;
  HLOCAL hPrior, *p;
124
  HLOCAL hGroup   = LocalAlloc(LMEM_FIXED, sizeof(PROGGROUP));
Alexandre Julliard's avatar
Alexandre Julliard committed
125 126 127 128
  HLOCAL hName    = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszName));
  HLOCAL hGrpFile = LocalAlloc(LMEM_FIXED, 1 + lstrlen(lpszGrpFile));
  if (!hGroup || !hName || !hGrpFile)
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
129
      MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
Alexandre Julliard's avatar
Alexandre Julliard committed
130 131 132 133 134
      if (hGroup)   LocalFree(hGroup);
      if (hName)    LocalFree(hName);
      if (hGrpFile) LocalFree(hGrpFile);
      return(0);
    }
135 136
  memcpy(LocalLock(hName), lpszName, 1 + lstrlen(lpszName));
  memcpy(LocalLock(hGrpFile), lpszGrpFile, 1 + lstrlen(lpszGrpFile));
Alexandre Julliard's avatar
Alexandre Julliard committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

  Globals.hActiveGroup   = hGroup;

  seqnum = 1;
  hPrior = 0;
  p = &Globals.hGroups;
  while (*p)
    {
      hPrior = *p;
      prior  = LocalLock(hPrior);
      p      = &prior->hNext;
      if (prior->seqnum >= seqnum)
	seqnum = prior->seqnum + 1;
    }
  *p = hGroup;

  group = LocalLock(hGroup);
  group->hPrior    = hPrior;
  group->hNext     = 0;
  group->hName     = hName;
  group->hGrpFile  = hGrpFile;
  group->bFileNameModified = bFileNameModified;
  group->bOverwriteFileOk  = bOverwriteFileOk;
  group->seqnum    = seqnum;
  group->nCmdShow  = nCmdShow;
  group->x         = x;
  group->y         = y;
  group->width     = width;
  group->height    = height;
  group->iconx     = iconx;
  group->icony     = icony;
  group->hPrograms = 0;
  group->hActiveProgram = 0;

  cs.szClass = STRING_GROUP_WIN_CLASS_NAME;
172
  cs.szTitle = lpszName;
Alexandre Julliard's avatar
Alexandre Julliard committed
173 174 175 176 177 178 179 180 181 182
  cs.hOwner  = 0;
  cs.x       = x;
  cs.y       = y;
  cs.cx      = width;
  cs.cy      = height;
  cs.style   = 0;
  cs.lParam  = 0;

  group->hWnd = (HWND)SendMessage(Globals.hMDIWnd, WM_MDICREATE, 0, (LPARAM)&cs);

Mike McCormack's avatar
Mike McCormack committed
183
  SetWindowLongPtr(group->hWnd, 0, (LONG_PTR) hGroup);
Alexandre Julliard's avatar
Alexandre Julliard committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

#if 1
  if (!bSuppressShowWindow) /* FIXME shouldn't be necessary */
#endif
    {
      ShowWindow (group->hWnd, nCmdShow);
      UpdateWindow (group->hWnd);
    }

  return(hGroup);
}

/***********************************************************************
 *
 *           GROUP_ModifyGroup
 */

VOID GROUP_ModifyGroup(HLOCAL hGroup)
{
203
  PROGGROUP *group = LocalLock(hGroup);
Alexandre Julliard's avatar
Alexandre Julliard committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  CHAR szName[MAX_PATHNAME_LEN];
  CHAR szFile[MAX_PATHNAME_LEN];
  lstrcpyn(szName, LocalLock(group->hName), MAX_PATHNAME_LEN);
  lstrcpyn(szFile, LocalLock(group->hGrpFile), MAX_PATHNAME_LEN);

  if (!DIALOG_GroupAttributes(szName, szFile, MAX_PATHNAME_LEN)) return;

  if (strcmp(szFile, LocalLock(group->hGrpFile)))
    group->bOverwriteFileOk = FALSE;

  MAIN_ReplaceString(&group->hName,    szName);
  MAIN_ReplaceString(&group->hGrpFile, szFile);

  GRPFILE_WriteGroupFile(hGroup);

  /* FIXME Delete old GrpFile if GrpFile changed */

  /* FIXME Update progman.ini */

  SetWindowText(group->hWnd, szName);
}

/***********************************************************************
 *
 *           GROUP_ShowGroupWindow
 */

/* FIXME shouldn't be necessary */
VOID GROUP_ShowGroupWindow(HLOCAL hGroup)
{
234
  PROGGROUP *group = LocalLock(hGroup);
Alexandre Julliard's avatar
Alexandre Julliard committed
235 236 237 238 239 240 241 242 243 244 245
  ShowWindow (group->hWnd, group->nCmdShow);
  UpdateWindow (group->hWnd);
}

/***********************************************************************
 *
 *           GROUP_DeleteGroup
 */

VOID GROUP_DeleteGroup(HLOCAL hGroup)
{
246
  PROGGROUP *group = LocalLock(hGroup);
Alexandre Julliard's avatar
Alexandre Julliard committed
247 248 249 250

  Globals.hActiveGroup = 0;

  if (group->hPrior)
251
    ((PROGGROUP*)LocalLock(group->hPrior))->hNext = group->hNext;
Alexandre Julliard's avatar
Alexandre Julliard committed
252 253 254
  else Globals.hGroups = group->hNext;

  if (group->hNext)
255
    ((PROGGROUP*)LocalLock(group->hNext))->hPrior = group->hPrior;
Alexandre Julliard's avatar
Alexandre Julliard committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273

  while (group->hPrograms)
    PROGRAM_DeleteProgram(group->hPrograms, FALSE);

  /* FIXME Update progman.ini */

  SendMessage(Globals.hMDIWnd, WM_MDIDESTROY, (WPARAM)group->hWnd, 0);

  LocalFree(group->hName);
  LocalFree(group->hGrpFile);
  LocalFree(hGroup);
}

/***********************************************************************
 *
 *           GROUP_FirstGroup
 */

274
HLOCAL GROUP_FirstGroup(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
275 276 277 278 279 280 281 282 283 284 285
{
  return(Globals.hGroups);
}

/***********************************************************************
 *
 *           GROUP_NextGroup
 */

HLOCAL GROUP_NextGroup(HLOCAL hGroup)
{
286
  PROGGROUP *group;
Alexandre Julliard's avatar
Alexandre Julliard committed
287 288 289 290 291 292 293 294 295 296
  if (!hGroup) return(0);
  group = LocalLock(hGroup);
  return(group->hNext);
}

/***********************************************************************
 *
 *           GROUP_ActiveGroup
 */

297
HLOCAL GROUP_ActiveGroup(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
298 299 300 301 302 303 304 305 306 307 308
{
  return(Globals.hActiveGroup);
}

/***********************************************************************
 *
 *           GROUP_GroupWnd
 */

HWND GROUP_GroupWnd(HLOCAL hGroup)
{
309
  PROGGROUP *group;
Alexandre Julliard's avatar
Alexandre Julliard committed
310 311 312 313 314 315 316 317 318 319 320 321
  if (!hGroup) return(0);
  group = LocalLock(hGroup);
  return(group->hWnd);
}

/***********************************************************************
 *
 *           GROUP_GroupName
 */

LPCSTR GROUP_GroupName(HLOCAL hGroup)
{
322
  PROGGROUP *group;
Alexandre Julliard's avatar
Alexandre Julliard committed
323 324 325 326 327 328 329 330
  if (!hGroup) return(0);
  group = LocalLock(hGroup);
  return(LocalLock(group->hName));
}

/* Local Variables:    */
/* c-file-style: "GNU" */
/* End:                */