1 /*
2
3 IMASM Macro Precompiler
4
5 Copyright (C) 2003 Joe Fisher, Shiny Technologies, LLC
6 http://www.shinytechnologies.com
7 Portions Copyright (C) 2003 Joseph Zbiciak.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 */
24
25 #include "includes.h"
26
27 extern bool g_bAutoUpdate;
28 extern HINSTANCE g_hInst;
29 extern HWND g_hToolBar;
30 extern HWND g_hStatBar;
31 extern char g_szCmdLineFile[MAX_PATH];
32
33 HWND g_hCurChild = NULL;
34 HWND g_hMDIClient = NULL;
35
36 const int iNumMenus = 7;
37 PopupStruct g_aPopup[iNumMenus];
38
39 FilePane *g_pFP = NULL;
40
41 RegHelp g_reg(HKEY_CURRENT_USER);
42
43 //-----------------------------------------------------------------------------
44 // NAME: FrameProc(HWND, unsigned, WORD, LONG)
45 // DESCRIPTION: Processes messages for the main window.
46 //-----------------------------------------------------------------------------
FrameProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)47 LRESULT CALLBACK FrameProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
48 {
49 switch (message)
50 {
51 case WM_CREATE: // This happens when window is first created
52 {
53 CLIENTCREATESTRUCT ccs;
54
55 // Open the registry key we will be using
56 g_reg.OpenKey(IMASM_REGISTRY_KEY);
57
58 // Retrieve the handle to the window menu and assign the
59 // first child window identifier.
60 ccs.hWindowMenu = GetSubMenu(GetMenu(hWnd), 3);
61 ccs.idFirstChild = IDC_CHILDBASE;
62
63 // Create the MDI client window.
64 g_hMDIClient = CreateWindowEx(0,
65 "MDICLIENT",
66 (LPCTSTR)NULL,
67 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
68 CW_USEDEFAULT,
69 CW_USEDEFAULT,
70 CW_USEDEFAULT,
71 CW_USEDEFAULT,
72 hWnd,
73 (HMENU)IDC_CLIENT,
74 g_hInst,
75 (LPVOID)&ccs);
76 ShowWindow(g_hMDIClient, SW_SHOW);
77
78 // Create the file pane window
79 g_pFP = new FilePane(hWnd);
80
81 // Create the status bar
82 g_hStatBar = CreateWindowEx( 0,
83 STATUSCLASSNAME,
84 NULL,
85 WS_VISIBLE | WS_CHILD | SBARS_SIZEGRIP,
86 CW_USEDEFAULT,
87 CW_USEDEFAULT,
88 CW_USEDEFAULT,
89 CW_USEDEFAULT,
90 hWnd,
91 (HMENU)IDC_STATUS,
92 g_hInst,
93 0);
94
95 CreateToolbar(hWnd);
96
97 if (g_bAutoUpdate)
98 {
99 SendMessage(g_hToolBar, TB_SETSTATE, (WPARAM)IDC_AUTO, (LPARAM)(TBSTATE_ENABLED | TBSTATE_CHECKED));
100 }
101
102 // Fill up the popup structure
103 HMENU hMenu = GetMenu(hWnd);
104 HMENU hFile = GetSubMenu(hMenu, 0);
105 HMENU hFormat = GetSubMenu(hMenu, 1);
106 HMENU hProject = GetSubMenu(hMenu, 2);
107 HMENU hWindow = GetSubMenu(hMenu, 3);
108 HMENU hHelp = GetSubMenu(hMenu, 4);
109
110 g_aPopup[0].hMenu = hMenu;
111 g_aPopup[0].uiString = IDS_FILE_MENU;
112 g_aPopup[1].hMenu = hFile;
113 g_aPopup[1].uiString = IDS_FILE_MENU;
114 g_aPopup[2].hMenu = hFormat;
115 g_aPopup[2].uiString = IDS_FORMAT_MENU;
116 g_aPopup[3].hMenu = hProject;
117 g_aPopup[3].uiString = IDS_PROJECT_MENU;
118 g_aPopup[4].hMenu = hWindow;
119 g_aPopup[4].uiString = IDS_WINDOW_MENU;
120 g_aPopup[5].hMenu = hHelp;
121 g_aPopup[5].uiString = IDS_HELP_MENU;
122 g_aPopup[6].hMenu = 0;
123 g_aPopup[6].uiString = 0;
124
125 return 0;
126 }// WM_CREATE
127
128 case WM_COMMAND:
129 switch (LOWORD(wParam))
130 {
131 case IDC_NEW:
132 HandleIDC_NEW(g_hMDIClient);
133 break;
134
135 case IDC_OPEN:
136 HandleIDC_OPEN(g_hMDIClient);
137 break;
138
139 case IDC_OPENPROJECT:
140 HandleIDC_OPENPROJECT(g_hMDIClient, g_pFP);
141 break;
142
143 case IDC_SAVEAS:
144 if (HandleIDC_SAVEAS(g_hCurChild) == 0)
145 {
146 break;
147 }
148 // FALLTHROUGH:
149
150 case IDC_SAVE:
151 HandleIDC_SAVE(g_hCurChild);
152 break;
153
154 case IDC_FONT:
155 HandleIDC_FONT(g_hMDIClient);
156 break;
157
158 case IDC_EXIT:
159 PostMessage(hWnd, WM_CLOSE, 0, 0);
160 break;
161
162 case IDC_ABOUT:
163 DialogBoxParam( g_hInst,
164 MAKEINTRESOURCE(IDD_ABOUT),
165 hWnd,
166 (DLGPROC)AboutProc,
167 0);
168 break;
169
170 case IDC_AUTO:
171 {
172 DWORD dwState = SendMessage(g_hToolBar, TB_GETSTATE, (WPARAM)IDC_AUTO, 0);
173
174 if ((dwState & TBSTATE_CHECKED) != 0)
175 {
176 g_bAutoUpdate = true;
177 HighlightDoc(GetDlgItem(g_hCurChild, IDC_MAINRICHED));
178 SetTimer(hWnd, UPDATETIMER, 20000, NULL);
179 }
180 else
181 {
182 g_bAutoUpdate = false;
183 KillTimer(hWnd, UPDATETIMER);
184 }
185 break;
186 }
187
188 case IDC_PRECOMPILE:
189 HandleIDC_PRECOMPILE(g_hCurChild);
190 break;
191
192 case IDC_CASCADE:
193 SendMessage(g_hMDIClient, WM_MDICASCADE, MDITILE_SKIPDISABLED, 0);
194 break;
195
196 case IDC_TILEHORIZ:
197 SendMessage(g_hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL | MDITILE_SKIPDISABLED, 0);
198 break;
199
200 case IDC_TILEVERT:
201 SendMessage(g_hMDIClient, WM_MDITILE, MDITILE_VERTICAL | MDITILE_SKIPDISABLED, 0);
202 break;
203
204 case IDC_PROJECTNEW:
205 HandleIDC_PROJECTNEW(hWnd, g_pFP);
206 break;
207
208 case IDC_PROJECTADDSOURCE:
209 HandleIDC_PROJECTADDSOURCE(hWnd, g_pFP);
210 break;
211
212 case IDC_PROJECTADDINCLUDE:
213 HandleIDC_PROJECTADDINCLUDE(hWnd, g_pFP);
214 break;
215
216 case IDC_PROJECTADDOTHER:
217 HandleIDC_PROJECTADDOTHER(hWnd, g_pFP);
218 break;
219
220 case IDC_PROJECTREMOVE:
221 HandleIDC_PROJECTREMOVE(hWnd, g_pFP);
222 break;
223 }
224 break;
225
226 case WM_NOTIFY:
227 {
228 LPNMHDR pHdr = (LPNMHDR)lParam;
229
230 switch (pHdr->code)
231 {
232 case TTN_GETDISPINFO:
233 {
234 LPTOOLTIPTEXT lpttt;
235
236 lpttt = (LPTOOLTIPTEXT)lParam;
237 lpttt->hinst = g_hInst;
238
239 // Specify the resource identifier of the descriptive
240 // text for the given button.
241 switch (lpttt->hdr.idFrom)
242 {
243 case IDC_NEW:
244 lpttt->lpszText = MAKEINTRESOURCE(IDS_NEW);
245 break;
246 case IDC_OPEN:
247 lpttt->lpszText = MAKEINTRESOURCE(IDS_OPEN);
248 break;
249 case IDC_OPENPROJECT:
250 lpttt->lpszText = MAKEINTRESOURCE(IDS_OPENPROJECT);
251 break;
252 case IDC_SAVE:
253 lpttt->lpszText = MAKEINTRESOURCE(IDS_SAVE);
254 break;
255 case IDC_SAVEAS:
256 lpttt->lpszText = MAKEINTRESOURCE(IDS_SAVEAS);
257 break;
258 case IDC_AUTO:
259 lpttt->lpszText = MAKEINTRESOURCE(IDS_AUTO);
260 break;
261 case IDC_PRECOMPILE:
262 lpttt->lpszText = MAKEINTRESOURCE(IDS_PRECOMPILE);
263 break;
264 }
265 break;
266 }
267
268 case NM_DBLCLK:
269 case NM_RETURN:
270 {
271 char szPath[MAX_PATH];
272
273 if (g_pFP->GetCurSelPath(szPath, MAX_PATH))
274 {
275 LoadFileIntoNewWindow(szPath);
276 }
277 break;
278 }
279
280 case TVN_KEYDOWN:
281 {
282 NMTVKEYDOWN *pKD;
283
284 pKD = (NMTVKEYDOWN *)lParam;
285
286 if (pKD->wVKey == VK_DELETE)
287 {
288 g_pFP->RemoveSelected();
289 }
290 break;
291 }
292
293 default:
294 break;
295 }
296 break;
297 }
298
299 case WM_MENUSELECT:
300 {
301 UINT uFlags = (UINT)HIWORD(wParam);
302 HMENU hMain = NULL;
303 UINT i = 0;
304
305 if (uFlags & MF_SYSMENU) // Handle non-system popup menus
306 {
307 MenuHelp(WM_MENUSELECT, wParam, lParam, NULL, g_hInst, g_hStatBar, &i);
308 }
309 else if (uFlags & MF_POPUP)
310 {
311 MenuHelp(WM_MENUSELECT, wParam, lParam, GetMenu(hWnd), g_hInst, g_hStatBar, (UINT *)g_aPopup);
312 }
313 else
314 {
315 for (i = 1; i < iNumMenus; i++)
316 {
317 if ((HMENU)lParam == g_aPopup[i].hMenu)
318 {
319 MenuHelp(WM_MENUSELECT, wParam, lParam, GetMenu(hWnd), g_hInst, g_hStatBar, (LPUINT)&g_aPopup[i].uiString);
320 break;
321 }
322 }
323 }
324
325
326
327 return 0;
328 }
329
330 case WM_CLOSE:
331 DestroyChildren(g_hMDIClient);
332 DestroyWindow(hWnd);
333 break;
334
335 case WM_SIZE: // Get size of client
336 {
337 int iClientX = LOWORD(lParam);
338 int iClientY = HIWORD(lParam);
339
340 SendMessage(g_hToolBar, TB_AUTOSIZE, 0, 0);
341
342 int aiParts[] = {iClientX - 210, iClientX - 110, iClientX - 80, iClientX - 50, iClientX - 20};
343 SendMessage(g_hStatBar, SB_SETPARTS, (WPARAM)5, (LPARAM)aiParts);
344 SendMessage(g_hStatBar, WM_SIZE, 0, 0);
345 UpdateStatusBar(g_hCurChild);
346
347 RECT rc;
348
349 GetWindowRect(g_hToolBar, &rc);
350
351 int cyTool = rc.bottom - rc.top;
352
353 GetWindowRect(g_hStatBar, &rc);
354
355 int cyStat = rc.bottom - rc.top;
356
357 // Now resize the file pane
358 int cxFilePane = iClientX / 5;
359 g_pFP->Resize(0, cyTool, cxFilePane, iClientY - cyTool - cyStat);
360
361 // And resize the MDI Client window
362 MoveWindow(g_hMDIClient, cxFilePane, cyTool, iClientX - cxFilePane, iClientY - cyTool - cyStat, TRUE);
363
364 // Do this on the first WM_SIZE message so the window is sized properly
365 if (*g_szCmdLineFile != NUL)
366 {
367 LoadFileIntoNewWindow(g_szCmdLineFile);
368 *g_szCmdLineFile = NUL;
369 }
370
371 return 0; // WM_SIZE
372 }
373
374 case WM_DESTROY:
375 if (g_pFP)
376 {
377 delete g_pFP;
378 }
379
380 DoExitProcessing(hWnd);
381 PostQuitMessage(0);
382 break; // WM_DESTROY
383
384 default: // Otherwise, let Windows process message
385 break;
386 }// end switch
387
388 return DefFrameProc(hWnd, g_hMDIClient, message, wParam, lParam);
389 }
390
391 //-----------------------------------------------------------------------------
392 // Name: void DestroyChildren(HWND hWnd)()
393 // Desc:
394 //-----------------------------------------------------------------------------
DestroyChildren(HWND hClient)395 void DestroyChildren(HWND hClient)
396 {
397 HWND hWnd = (HWND)SendMessage(hClient, WM_MDIGETACTIVE, 0, 0);
398 HWND hLast = NULL;
399
400 while (hWnd != hLast)
401 {
402 hLast = hWnd;
403 ConfirmSave(hWnd);
404 SendMessage(hClient, WM_MDIDESTROY, (WPARAM)hWnd, 0);
405 hWnd = (HWND)SendMessage(hClient, WM_MDIGETACTIVE, 0, 0);
406 }
407 }
408
409 //-----------------------------------------------------------------------------
410 // Name: ()
411 // Desc:
412 //-----------------------------------------------------------------------------
413