4 * Copyright 1996 Ulrich Schmid
5 * Copyright 2002 Sylvain Petreolle
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 static VOID MAIN_CreateGroups(void);
34 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
35 static ATOM MAIN_RegisterMainWinClass(void);
36 static VOID MAIN_CreateMainWindow(void);
37 static VOID MAIN_CreateMDIWindow(void);
38 static VOID MAIN_AutoStart(void);
40 #define BUFFER_SIZE 1000
42 /***********************************************************************
47 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
51 Globals.lpszIniFile = "progman.ini";
52 Globals.lpszIcoFile = "progman.ico";
54 Globals.hInstance = hInstance;
56 Globals.hActiveGroup = 0;
58 /* Read Options from `progman.ini' */
59 Globals.bAutoArrange =
60 GetPrivateProfileIntA("Settings", "AutoArrange", 0, Globals.lpszIniFile);
62 GetPrivateProfileIntA("Settings", "MinOnRun", 0, Globals.lpszIniFile);
63 Globals.bSaveSettings =
64 GetPrivateProfileIntA("Settings", "SaveSettings", 0, Globals.lpszIniFile);
66 /* Load default icons */
67 Globals.hMainIcon = ExtractIconA(Globals.hInstance, Globals.lpszIcoFile, 0);
68 Globals.hGroupIcon = ExtractIconA(Globals.hInstance, Globals.lpszIcoFile, 0);
69 Globals.hDefaultIcon = ExtractIconA(Globals.hInstance, Globals.lpszIcoFile, 0);
70 if (!Globals.hMainIcon) Globals.hMainIcon = LoadIconW(0, (LPWSTR)DEFAULTICON);
71 if (!Globals.hGroupIcon) Globals.hGroupIcon = LoadIconW(0, (LPWSTR)DEFAULTICON);
72 if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIconW(0, (LPWSTR)DEFAULTICON);
74 /* Register classes */
77 if (!MAIN_RegisterMainWinClass()) return(FALSE);
78 if (!GROUP_RegisterGroupWinClass()) return(FALSE);
79 if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
82 /* Create main window */
83 MAIN_CreateMainWindow();
84 Globals.hAccel = LoadAcceleratorsW(Globals.hInstance, MAKEINTRESOURCEW(IDA_ACCEL));
86 /* Setup menu, stringtable and resourcenames */
89 MAIN_CreateMDIWindow();
91 /* Initialize groups */
94 /* Start initial applications */
98 while (GetMessageW (&msg, 0, 0, 0))
99 if (!TranslateAcceleratorW(Globals.hMainWnd, Globals.hAccel, &msg))
101 TranslateMessage (&msg);
102 DispatchMessageW (&msg);
107 /***********************************************************************
112 static VOID MAIN_CreateGroups(void)
114 CHAR buffer[BUFFER_SIZE];
115 CHAR szPath[MAX_PATHNAME_LEN];
118 /* Initialize groups according the `Order' entry of `progman.ini' */
119 GetPrivateProfileStringA("Settings", "Order", "", buffer, sizeof(buffer), Globals.lpszIniFile);
121 while (ptr < buffer + sizeof(buffer))
124 ret = sscanf(ptr, "%d%n", &num, &skip);
126 MAIN_MessageBoxIDS_s(IDS_FILE_READ_ERROR_s, Globals.lpszIniFile, IDS_ERROR, MB_OK);
129 sprintf(key, "Group%d", num);
130 GetPrivateProfileStringA("Groups", key, "", szPath,
131 sizeof(szPath), Globals.lpszIniFile);
132 if (!szPath[0]) continue;
134 GRPFILE_ReadGroupFile(szPath);
138 /* FIXME initialize other groups, not enumerated by `Order' */
141 /***********************************************************************
146 VOID MAIN_AutoStart(void)
148 CHAR buffer[BUFFER_SIZE];
149 HLOCAL hGroup, hProgram;
151 GetPrivateProfileStringA("Settings", "AutoStart", "Autostart", buffer,
152 sizeof(buffer), Globals.lpszIniFile);
154 for (hGroup = GROUP_FirstGroup(); hGroup; hGroup = GROUP_NextGroup(hGroup))
155 if (!lstrcmpA(buffer, GROUP_GroupName(hGroup)))
156 for (hProgram = PROGRAM_FirstProgram(hGroup); hProgram;
157 hProgram = PROGRAM_NextProgram(hProgram))
158 PROGRAM_ExecuteProgram(hProgram);
161 /***********************************************************************
166 static LRESULT CALLBACK MAIN_MainWndProc(HWND hWnd, UINT msg,
167 WPARAM wParam, LPARAM lParam)
172 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
173 MF_BYCOMMAND | (Globals.bAutoArrange ? MF_CHECKED : MF_UNCHECKED));
174 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
175 MF_BYCOMMAND | (Globals.bMinOnRun ? MF_CHECKED : MF_UNCHECKED));
176 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
177 MF_BYCOMMAND | (Globals.bSaveSettings ? MF_CHECKED : MF_UNCHECKED));
181 if (LOWORD(wParam) < PM_FIRST_CHILD){
182 MAIN_MenuCommand(hWnd, LOWORD(wParam), lParam);
190 return DefFrameProcW(hWnd, Globals.hMDIWnd, msg, wParam, lParam);
193 /***********************************************************************
198 static VOID MAIN_MenuCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
200 HLOCAL hActiveGroup = GROUP_ActiveGroup();
201 HLOCAL hActiveProgram = PROGRAM_ActiveProgram(hActiveGroup);
202 HWND hActiveGroupWnd = GROUP_GroupWnd(hActiveGroup);
208 switch (DIALOG_New((hActiveGroupWnd && !IsIconic(hActiveGroupWnd)) ?
209 PM_NEW_PROGRAM : PM_NEW_GROUP))
212 if (hActiveGroup) PROGRAM_NewProgram(hActiveGroup);
223 PROGRAM_ExecuteProgram(hActiveProgram);
224 else if (hActiveGroupWnd)
225 OpenIcon(hActiveGroupWnd);
231 PROGRAM_CopyMoveProgram(hActiveProgram, wParam == PM_MOVE);
237 if (DIALOG_Delete(IDS_DELETE_PROGRAM_s, PROGRAM_ProgramName(hActiveProgram)))
238 PROGRAM_DeleteProgram(hActiveProgram, TRUE);
240 else if (hActiveGroup)
242 if (DIALOG_Delete(IDS_DELETE_GROUP_s, GROUP_GroupName(hActiveGroup)))
243 GROUP_DeleteGroup(hActiveGroup);
249 PROGRAM_ModifyProgram(hActiveProgram);
250 else if (hActiveGroup)
251 GROUP_ModifyGroup(hActiveGroup);
263 case PM_AUTO_ARRANGE:
264 Globals.bAutoArrange = !Globals.bAutoArrange;
265 CheckMenuItem(Globals.hOptionMenu, PM_AUTO_ARRANGE,
266 MF_BYCOMMAND | (Globals.bAutoArrange ?
267 MF_CHECKED : MF_UNCHECKED));
268 WritePrivateProfileStringA("Settings", "AutoArrange",
269 Globals.bAutoArrange ? "1" : "0",
270 Globals.lpszIniFile);
271 WritePrivateProfileStringA(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
275 Globals.bMinOnRun = !Globals.bMinOnRun;
276 CheckMenuItem(Globals.hOptionMenu, PM_MIN_ON_RUN,
277 MF_BYCOMMAND | (Globals.bMinOnRun ?
278 MF_CHECKED : MF_UNCHECKED));
279 WritePrivateProfileStringA("Settings", "MinOnRun",
280 Globals.bMinOnRun ? "1" : "0",
281 Globals.lpszIniFile);
282 WritePrivateProfileStringA(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
285 case PM_SAVE_SETTINGS:
286 Globals.bSaveSettings = !Globals.bSaveSettings;
287 CheckMenuItem(Globals.hOptionMenu, PM_SAVE_SETTINGS,
288 MF_BYCOMMAND | (Globals.bSaveSettings ?
289 MF_CHECKED : MF_UNCHECKED));
290 WritePrivateProfileStringA("Settings", "SaveSettings",
291 Globals.bSaveSettings ? "1" : "0",
292 Globals.lpszIniFile);
293 WritePrivateProfileStringA(NULL,NULL,NULL,Globals.lpszIniFile); /* flush it */
298 SendMessageW(Globals.hMDIWnd, WM_MDICASCADE, 0, 0);
301 case PM_SIDE_BY_SIDE:
302 SendMessageW(Globals.hMDIWnd, WM_MDITILE, MDITILE_VERTICAL, 0);
307 if (hActiveGroupWnd && !IsIconic(hActiveGroupWnd))
308 ArrangeIconicWindows(hActiveGroupWnd);
310 SendMessageW(Globals.hMDIWnd, WM_MDIICONARRANGE, 0, 0);
315 if (!WinHelpA(Globals.hMainWnd, "progman.hlp", HELP_CONTENTS, 0))
316 MAIN_MessageBoxIDS(IDS_WINHELP_ERROR, IDS_ERROR, MB_OK);
320 ShellAboutA(hWnd, "WINE", "Program Manager", 0);
324 MAIN_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
329 /***********************************************************************
331 * MAIN_RegisterMainWinClass
334 static ATOM MAIN_RegisterMainWinClass(void)
338 class.style = CS_HREDRAW | CS_VREDRAW;
339 class.lpfnWndProc = MAIN_MainWndProc;
340 class.cbClsExtra = 0;
341 class.cbWndExtra = 0;
342 class.hInstance = Globals.hInstance;
343 class.hIcon = Globals.hMainIcon;
344 class.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
345 class.hbrBackground = GetStockObject (NULL_BRUSH);
346 class.lpszMenuName = 0;
347 class.lpszClassName = STRING_MAIN_WIN_CLASS_NAME;
349 return RegisterClassW(&class);
352 /***********************************************************************
354 * MAIN_CreateMainWindow
357 static VOID MAIN_CreateMainWindow(void)
359 INT left , top, right, bottom, width, height, show;
363 Globals.hMainMenu = 0;
365 /* Get the geometry of the main window */
366 GetPrivateProfileStringA("Settings", "Window", "", buffer, sizeof(buffer), Globals.lpszIniFile);
367 if (5 == sscanf(buffer, "%d %d %d %d %d", &left, &top, &right, &bottom, &show))
369 width = right - left;
370 height = bottom - top;
374 left = top = width = height = CW_USEDEFAULT;
375 show = SW_SHOWNORMAL;
378 /* Create main Window */
380 CreateWindowW(STRING_MAIN_WIN_CLASS_NAME, NULL,
381 WS_OVERLAPPEDWINDOW, left, top, width, height,
382 0, 0, Globals.hInstance, 0);
384 ShowWindow (Globals.hMainWnd, show);
385 UpdateWindow (Globals.hMainWnd);
388 /***********************************************************************
390 * MAIN_CreateMDIWindow
393 static VOID MAIN_CreateMDIWindow(void)
395 CLIENTCREATESTRUCT ccs;
398 /* Get the geometry of the MDI window */
399 GetClientRect(Globals.hMainWnd, &rect);
401 ccs.hWindowMenu = Globals.hWindowsMenu;
402 ccs.idFirstChild = PM_FIRST_CHILD;
404 /* Create MDI Window */
406 CreateWindowW(STRING_MDI_WIN_CLASS_NAME, NULL,
407 WS_CHILD, rect.left, rect.top,
408 rect.right - rect.left, rect.bottom - rect.top,
410 Globals.hInstance, &ccs);
412 ShowWindow (Globals.hMDIWnd, SW_SHOW);
413 UpdateWindow (Globals.hMDIWnd);
416 /**********************************************************************/
417 /***********************************************************************
421 INT MAIN_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
423 CHAR text[MAX_STRING_LEN];
424 CHAR title[MAX_STRING_LEN];
426 LoadStringA(Globals.hInstance, ids_text, text, sizeof(text));
427 LoadStringA(Globals.hInstance, ids_title, title, sizeof(title));
429 return(MessageBoxA(Globals.hMainWnd, text, title, type));
432 /***********************************************************************
434 * MAIN_MessageBoxIDS_s
436 INT MAIN_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
438 CHAR text[MAX_STRING_LEN];
439 CHAR title[MAX_STRING_LEN];
440 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
442 LoadStringA(Globals.hInstance, ids_text, text, sizeof(text));
443 LoadStringA(Globals.hInstance, ids_title, title, sizeof(title));
444 wsprintfA(newtext, text, str);
446 return(MessageBoxA(Globals.hMainWnd, newtext, title, type));
449 /***********************************************************************
454 VOID MAIN_ReplaceString(HLOCAL *handle, LPSTR replace)
456 HLOCAL newhandle = LocalAlloc(LMEM_FIXED, strlen(replace) + 1);
459 LPSTR newstring = LocalLock(newhandle);
460 strcpy(newstring, replace);
464 else MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);