Rudimentiary drivebar support added.
[reactos.git] / rosapps / winfile / framewnd.c
1 /*
2 * ReactOS winfile
3 *
4 * framewnd.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 //#include <shellapi.h>
38 #include <windowsx.h>
39 #include <assert.h>
40 #define ASSERT assert
41
42 #include "main.h"
43 #include "about.h"
44 #include "framewnd.h"
45 #include "childwnd.h"
46 #include "worker.h"
47 #include "utils.h"
48 #include "shell.h"
49 #include "network.h"
50 #include "dialogs.h"
51
52
53 ////////////////////////////////////////////////////////////////////////////////
54 // Global and Local Variables:
55 //
56
57 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
58 int nOldWidth; // Holds the previous client area width
59 int nOldHeight; // Holds the previous client area height
60
61 static HHOOK hcbthook;
62 static ChildWnd* newchild = NULL;
63
64
65 ////////////////////////////////////////////////////////////////////////////////
66 // Local module support methods
67 //
68
69 static void resize_frame_rect(HWND hWnd, PRECT prect)
70 {
71 int new_top;
72 RECT rt;
73
74 if (IsWindowVisible(Globals.hToolBar)) {
75 SendMessage(Globals.hToolBar, WM_SIZE, 0, 0);
76 GetClientRect(Globals.hToolBar, &rt);
77 prect->top = rt.bottom+3;
78 prect->bottom -= rt.bottom+3;
79 }
80 if (IsWindowVisible(Globals.hDriveBar)) {
81 SendMessage(Globals.hDriveBar, WM_SIZE, 0, 0);
82 GetClientRect(Globals.hDriveBar, &rt);
83 // new_top = --prect->top + rt.bottom+3;
84 new_top = --prect->top + rt.bottom+0;
85 MoveWindow(Globals.hDriveBar, 0, prect->top, rt.right, new_top, TRUE);
86 prect->top = new_top;
87 // prect->bottom -= rt.bottom+2;
88 prect->bottom -= rt.bottom-1;
89 }
90 if (IsWindowVisible(Globals.hStatusBar)) {
91 SetupStatusBar(TRUE);
92 // int parts[] = {300, 500};
93 // SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0);
94 // SendMessage(Globals.hStatusBar, SB_SETPARTS, 2, (LPARAM)&parts);
95 GetClientRect(Globals.hStatusBar, &rt);
96 prect->bottom -= rt.bottom;
97 }
98 MoveWindow(Globals.hMDIClient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
99 }
100
101 static void resize_frame(HWND hWnd, int cx, int cy)
102 {
103 RECT rect = {0, 0, cx, cy};
104
105 resize_frame_rect(hWnd, &rect);
106 }
107
108 void resize_frame_client(HWND hWnd)
109 {
110 RECT rect;
111
112 GetClientRect(hWnd, &rect);
113 resize_frame_rect(hWnd, &rect);
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117
118 static LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
119 {
120 if (code == HCBT_CREATEWND && newchild) {
121 ChildWnd* pChildWnd = newchild;
122 newchild = NULL;
123 pChildWnd->hWnd = (HWND)wParam;
124 SetWindowLong(pChildWnd->hWnd, GWL_USERDATA, (LPARAM)pChildWnd);
125 }
126 return CallNextHookEx(hcbthook, code, wParam, lParam);
127 }
128
129
130 /*
131 BOOL FindChildWindow(int cmd)
132 {
133 TCHAR drv[_MAX_DRIVE];
134 LPCTSTR root = Globals.drives;
135 int i;
136 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
137 while(*root)
138 root++;
139 if (activate_drive_window(root))
140 return TRUE;
141 _tsplitpath(root, drv, 0, 0, 0);
142 if (!SetCurrentDirectory(drv)) {
143 display_error(hWnd, GetLastError());
144 //return TRUE;
145 }
146 return FALSE;
147 }
148 */
149
150 static ChildWnd* alloc_child_window(LPCTSTR path)
151 {
152 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
153 ChildWnd* pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
154 Root* root = &pChildWnd->root;
155 Entry* entry;
156
157 memset(pChildWnd, 0, sizeof(ChildWnd));
158 pChildWnd->left.treePane = TRUE;
159 pChildWnd->left.visible_cols = 0;
160 pChildWnd->right.treePane = FALSE;
161 #ifndef _NO_EXTENSIONS
162 pChildWnd->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
163 #else
164 pChildWnd->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES;
165 #endif
166 pChildWnd->pos.length = sizeof(WINDOWPLACEMENT);
167 pChildWnd->pos.flags = 0;
168 pChildWnd->pos.showCmd = SW_SHOWNORMAL;
169 pChildWnd->pos.rcNormalPosition.left = CW_USEDEFAULT;
170 pChildWnd->pos.rcNormalPosition.top = CW_USEDEFAULT;
171 pChildWnd->pos.rcNormalPosition.right = CW_USEDEFAULT;
172 pChildWnd->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
173 pChildWnd->nFocusPanel = 0;
174 pChildWnd->nSplitPos = 300;
175 pChildWnd->sortOrder = SORT_NAME;
176 pChildWnd->header_wdths_ok = FALSE;
177 lstrcpy(pChildWnd->szPath, path);
178 _tsplitpath(path, drv, dir, name, ext);
179 #if !defined(_NO_EXTENSIONS) && defined(__linux__)
180 if (*path == '/') {
181 root->drive_type = GetDriveType(path);
182 lstrcat(drv, _T("/"));
183 lstrcpy(root->volname, _T("root fs"));
184 root->fs_flags = 0;
185 lstrcpy(root->fs, _T("unixfs"));
186 lstrcpy(root->path, _T("/"));
187 entry = read_tree_unix(root, path, pChildWnd->sortOrder);
188 } else
189 #endif
190 {
191 root->drive_type = GetDriveType(path);
192 lstrcat(drv, _T("\\"));
193 GetVolumeInformation(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
194 lstrcpy(root->path, drv);
195 entry = read_tree_win(root, path, pChildWnd->sortOrder);
196 }
197 //@@lstrcpy(root->entry.data.cFileName, drv);
198 wsprintf(root->entry.data.cFileName, _T("%s - %s"), drv, root->fs);
199 root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
200 pChildWnd->left.root = &root->entry;
201 set_curdir(pChildWnd, entry);
202 return pChildWnd;
203 }
204
205 HWND CreateChildWindow(int drv_id)
206 {
207 //TCHAR drv[_MAX_DRIVE];
208 TCHAR path[MAX_PATH];
209 ChildWnd* pChildWnd = NULL;
210 /*
211 LPCTSTR root = Globals.drives;
212 int i;
213 for(i = cmd - ID_DRIVE_FIRST; i--; root++)
214 while(*root)
215 root++;
216 if (activate_drive_window(root))
217 return 0;
218 _tsplitpath(root, drv, 0, 0, 0);
219 if (!SetCurrentDirectory(drv)) {
220 display_error(hWnd, GetLastError());
221 return 0;
222 }
223 */
224 GetCurrentDirectory(MAX_PATH, path);
225 // pChildWnd = (ChildWnd*)malloc(sizeof(ChildWnd));
226 pChildWnd = alloc_child_window(path);
227 // if (!create_child_window(pChildWnd))
228 // free(pChildWnd);
229
230 if (pChildWnd != NULL) {
231 MDICREATESTRUCT mcs = {
232 szChildClass, path, hInst,
233 // CW_USEDEFAULT, CW_USEDEFAULT,
234 // CW_USEDEFAULT, CW_USEDEFAULT,
235 20, 20, 200, 200,
236 WS_MAXIMIZE, 0
237 // 0/*style*/, 0/*lParam*/
238 };
239 hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId());
240 newchild = pChildWnd;
241 pChildWnd->hWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
242 UnhookWindowsHookEx(hcbthook);
243 if (pChildWnd->hWnd != NULL) {
244 return pChildWnd->hWnd;
245 } else {
246 free(pChildWnd);
247 newchild = pChildWnd = NULL;
248 }
249 }
250 return 0;
251 }
252
253 static BOOL CALLBACK CloseEnumProc(HWND hWnd, LPARAM lParam)
254 {
255 if (!GetWindow(hWnd, GW_OWNER)) {
256 SendMessage(GetParent(hWnd), WM_MDIRESTORE, (WPARAM)hWnd, 0);
257 if (SendMessage(hWnd, WM_QUERYENDSESSION, 0, 0)) {
258 SendMessage(GetParent(hWnd), WM_MDIDESTROY, (WPARAM)hWnd, 0);
259 }
260 }
261 return 1;
262 }
263
264 static void OnEnterMenuLoop(HWND hWnd)
265 {
266 int nParts;
267
268 // Update the status bar pane sizes
269 nParts = -1;
270 SendMessage(Globals.hStatusBar, SB_SETPARTS, 1, (long)&nParts);
271 bInMenuLoop = TRUE;
272 SendMessage(Globals.hStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
273 }
274
275 static void OnExitMenuLoop(HWND hWnd)
276 {
277 /*
278 RECT rc;
279 int nParts[3];
280
281 bInMenuLoop = FALSE;
282 // Update the status bar pane sizes
283 GetClientRect(hWnd, &rc);
284 nParts[0] = 100;
285 nParts[1] = 210;
286 nParts[2] = rc.right;
287 SendMessage(Globals.hStatusBar, SB_SETPARTS, 3, (long)nParts);
288 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
289 */
290 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)_T(""));
291 bInMenuLoop = FALSE;
292 SetupStatusBar(TRUE);
293 UpdateStatusBar();
294 }
295
296 static void OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
297 {
298 TCHAR str[100];
299
300 if (hSysMenu == NULL) return;
301
302 _tcscpy(str, _T(""));
303 if (nFlags & MF_POPUP) {
304 switch (nItemID) {
305 case ID_FILE_MENU:
306 //EnableMenuItem(hSysMenu, uIDEnableItem, MF_BYCOMMAND|MF_ENABLED);
307 break;
308 case ID_DISK_MENU:
309 // EnableMenuItem(hSysMenu, ID_DISK_COPY_DISK, MF_BYCOMMAND|MF_GRAYED);
310 EnableMenuItem(hSysMenu, ID_DISK_COPY_DISK, MF_BYCOMMAND|MF_ENABLED);
311 break;
312 case ID_TREE_MENU:
313 case ID_VIEW_MENU:
314 case ID_OPTIONS_MENU:
315 case ID_SECURITY_MENU:
316 case ID_WINDOW_MENU:
317 case ID_HELP_MENU:
318 break;
319 }
320 // if (hSysMenu != GetMenu(hWnd)) {
321 // if (nItemID == 2) nItemID = 5;
322 // }
323 }
324 if (LoadString(Globals.hInstance, nItemID, str, 100)) {
325 // load appropriate string
326 LPTSTR lpsz = str;
327 // first newline terminates actual string
328 lpsz = _tcschr(lpsz, '\n');
329 if (lpsz != NULL)
330 *lpsz = '\0';
331 }
332 SendMessage(Globals.hStatusBar, SB_SETTEXT, 0, (LPARAM)str);
333 }
334
335
336 static BOOL activate_drive_window(LPCTSTR path)
337 {
338 TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
339 HWND child_wnd;
340
341 _tsplitpath(path, drv1, 0, 0, 0);
342
343 // search for a already open window for the same drive
344 for (child_wnd = GetNextWindow(Globals.hMDIClient,GW_CHILD);
345 child_wnd;
346 child_wnd = GetNextWindow(child_wnd, GW_HWNDNEXT)) {
347 ChildWnd* pChildWnd = (ChildWnd*) GetWindowLong(child_wnd, GWL_USERDATA);
348 if (pChildWnd) {
349 _tsplitpath(pChildWnd->root.path, drv2, 0, 0, 0);
350 if (!lstrcmpi(drv2, drv1)) {
351 SendMessage(Globals.hMDIClient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
352 if (IsMinimized(child_wnd))
353 ShowWindow(child_wnd, SW_SHOWNORMAL);
354 return TRUE;
355 }
356 }
357 }
358 return FALSE;
359 }
360
361 static void toggle_child(HWND hWnd, UINT cmd, HWND hchild)
362 {
363 BOOL vis = IsWindowVisible(hchild);
364
365 CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
366 ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
367 #ifndef _NO_EXTENSIONS
368 if (g_fullscreen.mode)
369 fullscreen_move(hWnd);
370 #endif
371 resize_frame_client(hWnd);
372 }
373
374 static BOOL cmd_drive_select(HWND hWnd, UINT cmd)
375 {
376 TCHAR drv[_MAX_DRIVE];
377 //TCHAR path[MAX_PATH];
378 //ChildWnd* pChildWnd;
379 LPCTSTR root = Globals.drives;
380 int i;
381 for (i = cmd - ID_DRIVE_FIRST; i--; root++)
382 while (*root)
383 root++;
384 if (activate_drive_window(root)) {
385 return TRUE;
386 }
387 _tsplitpath(root, drv, 0, 0, 0);
388 if (!SetCurrentDirectory(drv)) {
389 display_error(hWnd, GetLastError());
390 return TRUE;
391 }
392 //GetCurrentDirectory(MAX_PATH, path); //@@ letztes Verzeichnis pro Laufwerk speichern
393 //CreateChildWindow(path);
394 CreateChildWindow(cmd - ID_DRIVE_FIRST);
395 // pChildWnd = alloc_child_window(path);
396 // if (!create_child_window(pChildWnd))
397 // free(pChildWnd);
398 return FALSE;
399 }
400
401 static BOOL OnComboBoxCmd(HWND hWnd, WPARAM wParam)
402 {
403 int index;
404
405 switch (HIWORD(wParam)) {
406 case CBN_SELCHANGE:
407 index = SendMessage(Globals.hDriveCombo, CB_GETCURSEL, 0, 0);
408 cmd_drive_select(hWnd, index + ID_DRIVE_FIRST);
409 break;
410 default:
411 return FALSE;
412 }
413 return TRUE;
414 }
415
416 ////////////////////////////////////////////////////////////////////////////////
417 //
418 // FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
419 //
420 // PURPOSE: Processes WM_COMMAND messages for the main frame window.
421 //
422 //
423
424 static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
425 {
426 UINT cmd = LOWORD(wParam);
427 HWND hChildWnd;
428 // HWND hwndClient = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
429 // if (hwndClient)
430 // if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wParam, lParam))
431 // return 0;
432
433 if ((HWND)lParam == Globals.hDriveCombo) {
434 return OnComboBoxCmd(hWnd, wParam);
435 }
436 if (cmd >= ID_DRIVE_FIRST && cmd <= (ID_DRIVE_FIRST + 0xFF)) {
437 cmd_drive_select(hWnd, cmd);
438 } else {
439 switch (cmd) {
440 case ID_WINDOW_CLOSEALL:
441 EnumChildWindows(Globals.hMDIClient, &CloseEnumProc, 0);
442 break;
443 case ID_WINDOW_CLOSE:
444 hChildWnd = (HWND) SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
445 if (!SendMessage(hChildWnd, WM_QUERYENDSESSION, 0, 0))
446 SendMessage(Globals.hMDIClient, WM_MDIDESTROY, (WPARAM)hChildWnd, 0);
447 break;
448 case ID_DISK_COPY_DISK:
449 CopyDisk(hWnd);
450 break;
451 case ID_DISK_LABEL_DISK:
452 LabelDisk(hWnd);
453 break;
454 case ID_DISK_FORMAT_DISK:
455 FormatDisk(hWnd);
456 #if 0
457 // SHFormatDrive(hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
458 {
459 UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings.
460 SetErrorMode(OldMode & ~SEM_FAILCRITICALERRORS); // Force O/S to handle
461 // Call SHFormatDrive here.
462 SHFormatDrive(hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);
463 SetErrorMode(OldMode); // Put it back the way it was.
464 }
465 #endif
466 break;
467 case ID_DISK_CONNECT_NETWORK_DRIVE:
468 MapNetworkDrives(hWnd, TRUE);
469 break;
470 case ID_DISK_DISCONNECT_NETWORK_DRIVE:
471 MapNetworkDrives(hWnd, FALSE);
472 break;
473 case ID_DISK_SHARE_AS:
474 ModifySharing(hWnd, TRUE);
475 break;
476 case ID_DISK_STOP_SHARING:
477 ModifySharing(hWnd, FALSE);
478 break;
479 case ID_DISK_SELECT_DRIVE:
480 break;
481
482 case ID_VIEW_BY_FILE_TYPE:
483 {
484 struct ExecuteDialog dlg = {{0}};
485 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hWnd, ViewFileTypeWndProc, (LPARAM)&dlg) == IDOK) {
486 }
487 }
488 break;
489 case ID_OPTIONS_CONFIRMATION:
490 {
491 struct ExecuteDialog dlg = {{0}};
492 if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_OPTIONS_CONFIRMATON), hWnd, OptionsConfirmationWndProc, (LPARAM)&dlg) == IDOK) {
493 }
494 }
495 break;
496 case ID_OPTIONS_FONT:
497 break;
498 case ID_OPTIONS_CUSTOMISE_TOOLBAR:
499 SendMessage(Globals.hToolBar, TB_CUSTOMIZE, 0, 0);
500 break;
501 case ID_OPTIONS_TOOLBAR:
502 toggle_child(hWnd, cmd, Globals.hToolBar);
503 break;
504 case ID_OPTIONS_DRIVEBAR:
505 toggle_child(hWnd, cmd, Globals.hDriveBar);
506 break;
507 case ID_OPTIONS_STATUSBAR:
508 toggle_child(hWnd, cmd, Globals.hStatusBar);
509 break;
510 case ID_OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT:
511 if (Globals.Options & OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT) {
512 Globals.Options &= ~OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT;
513 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
514 } else {
515 Globals.Options |= OPTIONS_OPEN_NEW_WINDOW_ON_CONNECT;
516 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
517 }
518 break;
519 case ID_OPTIONS_MINIMISE_ON_USE:
520 if (Globals.Options & ID_OPTIONS_MINIMISE_ON_USE) {
521 Globals.Options &= ~ID_OPTIONS_MINIMISE_ON_USE;
522 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
523 } else {
524 Globals.Options |= ID_OPTIONS_MINIMISE_ON_USE;
525 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
526 }
527 break;
528 case ID_OPTIONS_SAVE_ON_EXIT:
529 if (Globals.Options & OPTIONS_SAVE_ON_EXIT) {
530 Globals.Options &= ~OPTIONS_SAVE_ON_EXIT;
531 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND);
532 } else {
533 Globals.Options |= OPTIONS_SAVE_ON_EXIT;
534 CheckMenuItem(Globals.hMenuOptions, cmd, MF_BYCOMMAND | MF_CHECKED);
535 }
536 break;
537 case ID_WINDOW_NEW_WINDOW:
538 CreateChildWindow(-1);
539 break;
540 case ID_WINDOW_CASCADE:
541 SendMessage(Globals.hMDIClient, WM_MDICASCADE, 0, 0);
542 break;
543 case ID_WINDOW_TILE_HORZ:
544 SendMessage(Globals.hMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
545 break;
546 case ID_WINDOW_TILE_VERT:
547 SendMessage(Globals.hMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0);
548 break;
549 case ID_WINDOW_ARRANGE_ICONS:
550 SendMessage(Globals.hMDIClient, WM_MDIICONARRANGE, 0, 0);
551 break;
552 case ID_WINDOW_REFRESH:
553 // TODO:
554 break;
555 case ID_HELP_CONTENTS:
556 WinHelp(hWnd, _T("winfile"), HELP_CONTENTS, 0);
557 break;
558 case ID_HELP_SEARCH_HELP:
559 WinHelp(hWnd, _T("winfile"), HELP_FINDER, 0);
560 break;
561 case ID_HELP_HOW_TO_USE_HELP:
562 WinHelp(hWnd, _T("winfile"), HELP_HELPONHELP, 0);
563 break;
564 case ID_HELP_ABOUT:
565 #ifdef WINSHELLAPI
566 ShellAbout(hWnd, szTitle, "", LoadIcon(Globals.hInstance, (LPCTSTR)IDI_WINFILE));
567 #else
568 ShowAboutBox(hWnd);
569 #endif
570 break;
571 default:
572 /*
573 if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
574 (cmd<SC_SIZE || cmd>SC_RESTORE)) {
575 MessageBox(hWnd, _T("Not yet implemented"), _T("Winefile"), MB_OK);
576 }
577 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
578 */
579 /*
580 hChildWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
581 if (IsWindow(hChildWnd))
582 SendMessage(hChildWnd, WM_COMMAND, wParam, lParam);
583 else
584 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
585 */
586 return FALSE;
587 }
588 }
589 return TRUE;
590 }
591
592
593 static TBBUTTON tbButtonNew[] = {
594 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
595 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
596 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
597 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
598 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
599 };
600
601 static LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
602 {
603 LPNMHDR lpnmhdr;
604
605 //LPNMHDR lpnmhdr;
606 static int nResetCount;
607 static LPTBBUTTON lpSaveButtons;
608 //LPARAM lParam;
609
610
611 lpnmhdr = (LPNMHDR)lparam;
612 /*
613 // The following code allows the toolbar to be customized.
614 // If you return FALSE the Customize Toolbar dialog flashes
615 // and goes away.
616
617 if (lpnmhdr->code == TBN_QUERYINSERT || lpnmhdr->code == TBN_QUERYDELETE) {
618 return TRUE;
619 }
620
621 if (lpnmhdr->code == TBN_GETBUTTONINFO) {
622 LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
623 TCHAR szBuffer[20];
624
625 // int tbButtonNew[20] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
626 TBBUTTON tbButtonNew[] = {
627 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
628 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
629 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
630 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
631 {0, ID_WINDOW_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON},
632 };
633
634 // 20 = total number of buttons.
635 // tbButton and tbButtonNew send information about
636 // the other 12 buttons in tbButtonNew.
637 if (lpTbNotify->iItem < 5) {
638 lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];
639 // LoadString(hInst, 4000+lpTbNotify->iItem, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
640 LoadString(hInst, lpTbNotify->iItem, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
641 lstrcpy (lpTbNotify->pszText, szBuffer);
642 lpTbNotify->cchText = sizeof(szBuffer)/sizeof(TCHAR);
643 return TRUE;
644 } else {
645 return 0;
646 }
647 }
648 */
649 switch (lpnmhdr->code) {
650 case TBN_QUERYINSERT:
651 case TBN_QUERYDELETE:
652 return TRUE;
653
654 case TBN_GETBUTTONINFO:
655 {
656 LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
657 TCHAR szBuffer[20];
658 /*
659 typedef struct _TBBUTTON {
660 int iBitmap;
661 int idCommand;
662 BYTE fsState;
663 BYTE fsStyle;
664 DWORD dwData;
665 INT_PTR iString;
666 } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;
667 */
668 // 20 = total number of buttons.
669 // tbButton and tbButtonNew send information about
670 // the other 12 buttons in tbButtonNew.
671 if (lpTbNotify->iItem < 12) {
672 lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];
673 LoadString(hInst, lpTbNotify->iItem + 32769, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
674 lstrcpy(lpTbNotify->pszText, szBuffer);
675 lpTbNotify->cchText = sizeof(szBuffer)/sizeof(TCHAR);
676 return TRUE;
677 } else {
678 return 0;
679 }
680 }
681 break;
682
683 case TBN_BEGINADJUST: // Start customizing the toolbar.
684 {
685 LPTBNOTIFY lpTB = (LPTBNOTIFY)lparam;
686 int i;
687
688 // Allocate memory to store the button information.
689 nResetCount = SendMessage(lpTB->hdr.hwndFrom, TB_BUTTONCOUNT, 0, 0);
690 lpSaveButtons = (LPTBBUTTON)GlobalAlloc(GPTR, sizeof(TBBUTTON) * nResetCount);
691
692 // Save the current configuration so if the user presses
693 // reset, the original toolbar can be restored.
694 for (i = 0; i < nResetCount; i++) {
695 SendMessage(lpTB->hdr.hwndFrom, TB_GETBUTTON, i, (LPARAM)(lpSaveButtons + i));
696 }
697 }
698 return TRUE;
699
700 case TBN_RESET:
701 {
702 LPTBNOTIFY lpTB = (LPTBNOTIFY)lparam;
703 int nCount, i;
704
705 // Remove all of the existing buttons starting with the last and working down.
706 nCount = SendMessage(lpTB->hdr.hwndFrom, TB_BUTTONCOUNT, 0, 0);
707 for (i = nCount - 1; i >= 0; i--) {
708 SendMessage(lpTB->hdr.hwndFrom, TB_DELETEBUTTON, i, 0);
709 }
710
711 // Restore the buttons that were saved.
712 SendMessage(lpTB->hdr.hwndFrom, TB_ADDBUTTONS, (WPARAM)nResetCount, (LPARAM)lpSaveButtons);
713 }
714 return TRUE;
715
716 case TBN_ENDADJUST:
717 // Free the memory allocated during TBN_BEGINADJUST
718 GlobalFree((HGLOBAL)lpSaveButtons);
719 return TRUE;
720 }
721 return 0;
722 }
723
724 static LRESULT OnDriveBoxNotify(HWND hWnd, WPARAM wParam, LPARAM lParam)
725 {
726 LPNMHDR nmhdr = (LPNMHDR)lParam;
727
728 // if (nmhdr->code == NM_HOVER || nmhdr->code == NM_NCHITTEST) return 0;
729
730 // switch (((LPNMHDR)lParam)->code) {
731 switch (nmhdr->code) {
732 case NM_OUTOFMEMORY:
733 case NM_CLICK:
734 case NM_DBLCLK:
735 case NM_RETURN:
736 case NM_RCLICK:
737 case NM_RDBLCLK:
738 case NM_SETFOCUS:
739 case NM_KILLFOCUS:
740 break;
741
742 #if (_WIN32_IE >= 0x0300)
743 case NM_CUSTOMDRAW:
744 case NM_HOVER:
745 break;
746 #endif
747
748 #if (_WIN32_IE >= 0x0400)
749 case NM_NCHITTEST:
750 case NM_KEYDOWN:
751 case NM_RELEASEDCAPTURE:
752 case NM_SETCURSOR:
753 case NM_CHAR:
754 break;
755 #endif
756 default:
757 break;
758 }
759 return 0;
760 }
761
762 ////////////////////////////////////////////////////////////////////////////////
763 //
764 // FUNCTION: FrameWndProc(HWND, unsigned, WORD, LONG)
765 //
766 // PURPOSE: Processes messages for the main frame window.
767 //
768 // WM_COMMAND - process the application menu
769 // WM_DESTROY - post a quit message and return
770 //
771 //
772
773 LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
774 {
775 switch (message) {
776 case WM_CREATE:
777 {
778 HMENU hMenuWindow = GetSubMenu(Globals.hMenuFrame, GetMenuItemCount(Globals.hMenuFrame)-2);
779 CLIENTCREATESTRUCT ccs = { hMenuWindow, IDW_FIRST_CHILD };
780 Globals.hMDIClient = CreateWindowEx(0, _T("MDICLIENT"), NULL,
781 WS_EX_MDICHILD|WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
782 0, 0, 0, 0,
783 hWnd, (HMENU)0, hInst, &ccs);
784 }
785 CheckShellAvailable();
786 CreateNetworkMonitorThread(hWnd);
787 CreateMonitorThread(hWnd);
788 CreateChildWindow(-1);
789 SetTimer(hWnd, 1, 5000, NULL);
790 break;
791
792 case WM_NOTIFY:
793
794 if (((LPNMHDR)lParam)->idFrom == IDW_DRIVEBOX) {
795 // return OnDriveBoxNotify(hWnd, wParam, lParam);
796 return OnDriveBoxNotify(hWnd, wParam, lParam);
797 //return TRUE;
798 }
799
800 if (((LPNMHDR)lParam)->idFrom == IDW_TOOLBAR) {
801 if (MsgNotify(hWnd, message, wParam, lParam)) return TRUE;
802 }
803 // return MsgNotify(hWnd, message, wParam, lParam);
804 switch (((LPNMHDR)lParam)->code) {
805 #ifdef _MSC_VER
806 case TTN_GETDISPINFO:
807 {
808 LPTOOLTIPTEXT lpttt;
809 lpttt = (LPTOOLTIPTEXT)lParam;
810 lpttt->hinst = hInst;
811 // load appropriate string
812 lpttt->lpszText = MAKEINTRESOURCE(lpttt->hdr.idFrom);
813 }
814 break;
815 #endif
816 default:
817 break;
818 }
819 break;
820
821 case WM_COMMAND:
822 if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
823 // if (LOWORD(wParam) > ID_CMD_FIRST && LOWORD(wParam) < ID_CMD_LAST) {
824 HWND hChildWnd = (HWND)SendMessage(Globals.hMDIClient, WM_MDIGETACTIVE, 0, 0);
825 if (IsWindow(hChildWnd))
826 if (SendMessage(hChildWnd, WM_DISPATCH_COMMAND, wParam, lParam))
827 break;
828 // }
829 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
830 }
831 break;
832
833 case WM_TIMER:
834 SignalMonitorEvent();
835 SignalNetworkMonitorEvent();
836 break;
837
838 case WM_SIZE:
839 resize_frame_client(hWnd);
840 break;
841 case WM_ENTERMENULOOP:
842 OnEnterMenuLoop(hWnd);
843 break;
844 case WM_EXITMENULOOP:
845 OnExitMenuLoop(hWnd);
846 break;
847 case WM_MENUSELECT:
848 OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
849 break;
850 case WM_DESTROY:
851 WinHelp(hWnd, _T("winfile"), HELP_QUIT, 0);
852 KillTimer(hWnd, 1);
853 DestryMonitorThread();
854 DestryNetworkMonitorThread();
855 PostQuitMessage(0);
856 break;
857 case WM_QUERYENDSESSION:
858 case WM_CLOSE:
859 SendMessage(hWnd, WM_COMMAND, ID_WINDOW_CLOSEALL, 0);
860 if (GetWindow(Globals.hMDIClient, GW_CHILD) != NULL)
861 return 0;
862 // else fall thru...
863 default: //def:
864 return DefFrameProc(hWnd, Globals.hMDIClient, message, wParam, lParam);
865 }
866 return 0;
867 }
868
869