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