2 * Copyright 2003, 2004, 2005 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 // Martin Fuchs, 23.07.2003
31 /* We can't include webchild.h here - otherwise MinGW produces errors like: "multiple definition of `QACONTAINERFLAGS'"
34 extern HWND
create_webchildwindow(const WebChildWndInfo
& info
);
36 #include "../resource.h"
38 #include "../dialogs/settings.h" // for MdiSdiDlg
42 HWND
MainFrameBase::Create(const ExplorerCmd
& cmd
)
48 hFrame
= MDIMainFrame::Create();
51 hFrame
= SDIMainFrame::Create();
54 HWND hwndOld
= g_Globals
._hMainWnd
;
56 g_Globals
._hMainWnd
= hFrame
;
59 DestroyWindow(hwndOld
);
61 ShowWindow(hFrame
, cmd
._cmdShow
);
64 // Open the first child window after initializing the application
65 if (cmd
.IsValidPath()) {
66 // We use the static s_path variable to store the path string in order
67 // to avoid accessing prematurely freed memory in the PostMessage handlers.
68 static String s_path
= cmd
._path
;
70 PostMessage(hFrame
, PM_OPEN_WINDOW
, cmd
._flags
, (LPARAM
)(LPCTSTR
)s_path
);
72 PostMessage(hFrame
, PM_OPEN_WINDOW
, OWM_EXPLORE
|OWM_DETAILS
, 0);
79 int MainFrameBase::OpenShellFolders(LPIDA pida
, HWND hFrameWnd
)
83 LPCITEMIDLIST parent_pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
84 ShellFolder
folder(parent_pidl
);
85 LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): parent_pidl=%s"), (LPCTSTR
)FileSysShellPath(parent_pidl
)));
87 for(int i
=pida
->cidl
; i
>0; --i
) {
88 LPCITEMIDLIST pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[i
]);
90 SFGAOF attribs
= SFGAO_FOLDER
;
91 HRESULT hr
= folder
->GetAttributesOf(1, &pidl
, &attribs
);
94 if (attribs
& SFGAO_FOLDER
) {
96 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
98 bool mdi
= XMLBool(explorer_options
, "mdi", true);
99 bool separateFolders
= XMLBool(explorer_options
, "separate-folders", false);
101 ShellPath pidl_abs
= ShellPath(pidl
).create_absolute_pidl(parent_pidl
);
102 LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): pidl_abs=%s"), (LPCTSTR
)FileSysShellPath(pidl_abs
)));
104 if (hFrameWnd
&& (mdi
|| !separateFolders
)) {
105 int flags
= OWM_PIDL
;
108 flags
|= OWM_SEPARATE
;
110 if (SendMessage(hFrameWnd
, PM_OPEN_WINDOW
, flags
, (LPARAM
)(LPCITEMIDLIST
)pidl_abs
))
116 hwnd
= MDIMainFrame::Create(pidl_abs
, 0);
119 hwnd
= SDIMainFrame::Create(pidl_abs
, 0);
124 } catch(COMException
& e
) {
125 HandleException(e
, g_Globals
._hMainWnd
);
128 else { // !(attribs & SFGAO_FOLDER))
129 SHELLEXECUTEINFOA shexinfo;
131 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOA);
132 shexinfo.fMask = SEE_MASK_INVOKEIDLIST;
133 shexinfo.hwnd = NULL;
134 shexinfo.lpVerb = NULL;
135 shexinfo.lpFile = NULL;
136 shexinfo.lpParameters = NULL;
137 shexinfo.lpDirectory = NULL;
138 shexinfo.nShow = SW_NORMAL;
139 shexinfo.lpIDList = ILCombine(parent_pidl, pidl);
141 if (ShellExecuteExA(&shexinfo))
144 ILFree((LPITEMIDLIST)shexinfo.lpIDList);
152 MainFrameBase::MainFrameBase(HWND hwnd
)
155 HDC hDC
= GetDC(NULL
);
157 //static TCHAR Title1[] = TEXT("Toolbar");
158 static TCHAR Title2
[] = TEXT("Address :");
164 INT bpp
= GetDeviceCaps(hDC
, BITSPIXEL
);
165 ReleaseDC(NULL
, hDC
);
172 ilMask
= ILC_COLOR16
;
174 ilMask
= ILC_COLOR24
;
176 ilMask
= ILC_COLOR32
;
182 _himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), ilMask
, 2, 0);
185 _hMenuFrame
= GetMenu(hwnd
);
186 _hMenuWindow
= GetSubMenu(_hMenuFrame
, GetMenuItemCount(_hMenuFrame
)-3);
188 _menu_info
._hMenuView
= GetSubMenu(_hMenuFrame
, 1);
190 _hAccel
= LoadAccelerators(g_Globals
._hInstance
, MAKEINTRESOURCE(IDA_EXPLORER
));
193 TBBUTTON toolbarBtns
[] = {
195 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
197 {7, ID_GO_BACK
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
198 {8, ID_GO_FORWARD
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
199 {9, ID_GO_UP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
200 {10, ID_GO_HOME
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
201 {11, ID_GO_SEARCH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
202 {12, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
203 {13, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0}
206 _htoolbar
= CreateToolbarEx(hwnd
,
208 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
210 WS_CHILD
|TBSTYLE_FLAT
|WS_VISIBLE
, IDW_TOOLBAR
, 2, g_Globals
._hInstance
, IDB_TOOLBAR
,
211 toolbarBtns
, sizeof(toolbarBtns
)/sizeof(TBBUTTON
),
212 16, 16, 16, 16, sizeof(TBBUTTON
));
214 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
218 _haddrcombo
= CreateWindowEx(0,
221 WS_CHILD
|WS_TABSTOP
|WS_BORDER
|WS_VISIBLE
|CBS_DROPDOWN
|
222 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|CCS_NOMOVEY
,
225 (HMENU
)IDW_ADDRESSBAR
,
226 g_Globals
._hInstance
,
229 HFONT hFont
= (HFONT
)GetStockObject(ANSI_VAR_FONT
);
230 SendMessageW(_haddrcombo
, WM_SETFONT
, (WPARAM
)hFont
, 0);
233 _hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, hwnd
, IDW_STATUSBAR
);
234 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
236 _hsidebar
= CreateWindowEx(WS_EX_STATICEDGE
, WC_TREEVIEW
, TEXT("Sidebar"),
237 WS_CHILD
|WS_TABSTOP
|WS_BORDER
|/*WS_VISIBLE|*/WS_CHILD
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_SHOWSELALWAYS
|TVS_INFOTIP
,
238 -1, -1, 200, 0, _hwnd
, (HMENU
)IDW_SIDEBAR
, g_Globals
._hInstance
, 0);
240 _himl_old
= TreeView_SetImageList(_hsidebar
, _himl
, TVSIL_NORMAL
);
242 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_SIDE_BAR
, MF_BYCOMMAND
|MF_UNCHECKED
/*MF_CHECKED*/);
245 // create rebar window to manage toolbar and drivebar
247 _hwndrebar
= CreateWindowEx(WS_EX_TOOLWINDOW
,
250 WS_CHILD
|WS_VISIBLE
|WS_BORDER
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|
251 RBS_VARHEIGHT
|RBS_DBLCLKTOGGLE
| RBS_AUTOSIZE
|RBS_BANDBORDERS
,
255 g_Globals
._hInstance
,
258 int btn_hgt
= HIWORD(SendMessage(_htoolbar
, TB_GETBUTTONSIZE
, 0, 0));
260 REBARBANDINFO rbBand
;
262 rbBand
.cbSize
= sizeof(REBARBANDINFO
);
263 rbBand
.fMask
= RBBIM_TEXT
|RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
264 rbBand
.fStyle
= RBBS_CHILDEDGE
|RBBS_GRIPPERALWAYS
|RBBS_HIDETITLE
;
266 rbBand
.cxMinChild
= 0;
267 rbBand
.cyMinChild
= 0;
269 rbBand
.cyMaxChild
= 0;
270 rbBand
.cyIntegral
= btn_hgt
;
272 rbBand
.lpText
= NULL
;//Title1
273 rbBand
.hwndChild
= _htoolbar
;
274 rbBand
.cxMinChild
= 0;
275 rbBand
.cyMinChild
= btn_hgt
;
277 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)0, (LPARAM
)&rbBand
);
279 rbBand
.fStyle
&= ~RBBS_HIDETITLE
;
280 rbBand
.fStyle
|= RBBS_BREAK
;
281 rbBand
.lpText
= Title2
;
282 rbBand
.hwndChild
= _haddrcombo
;
283 rbBand
.cxMinChild
= 0;
284 rbBand
.cyMinChild
= btn_hgt
;
286 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)3, (LPARAM
)&rbBand
);
291 MainFrameBase::~MainFrameBase()
293 (void)TreeView_SetImageList(_hsidebar
, _himl_old
, TVSIL_NORMAL
);
294 ImageList_Destroy(_himl
);
296 // don't exit desktop when closing file manager window
297 if (!g_Globals
._desktop_mode
)
298 if (g_Globals
._hMainWnd
== _hwnd
) // don't quit when switching between MDI and SDI mode
303 LRESULT
MainFrameBase::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
307 if (ProcessMessage(nmsg
, wparam
, lparam
, &res
))
310 return super::WndProc(nmsg
, wparam
, lparam
);
313 bool MainFrameBase::ProcessMessage(UINT nmsg
, WPARAM wparam
, LPARAM lparam
, LRESULT
* pres
)
316 case PM_TRANSLATE_MSG
:
317 *pres
= TranslateMsg((MSG
*)lparam
);
321 if (wparam
) { // trigger child resizing after window creation - now we can succesfully call IsWindowVisible()
322 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
323 MoveWindow(_hwndrebar
, 0, 0, LOWORD(lparam
), height
, TRUE
);
324 resize_frame_client();
326 return false; // goto def;
329 DestroyWindow(_hwnd
);
330 g_Globals
._hMainWnd
= 0;
337 #ifdef __REACTOS__ ///@todo Work around to display rebar in ROS (with flickering) as long as the control isn't fixed
338 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
339 MoveWindow(_hwndrebar
, 0, 0, LOWORD(lparam
), height
, TRUE
);
341 resize_frame(LOWORD(lparam
), HIWORD(lparam
));
342 SendMessage(_hwndrebar
, WM_SIZE
, 0, 0);
346 break;} // do not pass message to DefFrameProc
348 case WM_GETMINMAXINFO
: {
349 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
351 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
352 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
355 case PM_FRM_CALC_CLIENT
:
356 frame_get_clientspace((PRECT
)lparam
);
360 case PM_FRM_GET_MENUINFO
:
361 *pres
= (LPARAM
)&_menu_info
;
364 case PM_GET_CONTROLWINDOW
:
365 if (wparam
== FCW_STATUS
) {
366 *pres
= (LRESULT
)(HWND
)_hstatusbar
;
371 case PM_SETSTATUSTEXT
:
372 SendMessage(_hstatusbar
, SB_SETTEXT
, 0, lparam
);
383 BOOL
MainFrameBase::TranslateMsg(MSG
* pmsg
)
385 if (TranslateAccelerator(_hwnd
, _hAccel
, pmsg
))
392 int MainFrameBase::Command(int id
, int code
)
394 CONTEXT("MainFrameBase::Command()");
398 SendMessage(_hwnd
, WM_CLOSE
, 0, 0);
401 case ID_VIEW_TOOL_BAR
:
402 toggle_child(_hwnd
, id
, _htoolbar
, 0);
405 case ID_VIEW_STATUSBAR
:
406 toggle_child(_hwnd
, id
, _hstatusbar
);
409 case ID_VIEW_SIDE_BAR
:
410 // lazy initialization
411 if (!TreeView_GetCount(_hsidebar
))
414 toggle_child(_hwnd
, id
, _hsidebar
);
418 ExecuteDialog dlg
= {{0}, 0};
420 if (DialogBoxParam(g_Globals
._hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), _hwnd
, ExecuteDialog::WndProc
, (LPARAM
)&dlg
) == IDOK
) {
421 CONTEXT("ID_EXECUTE - ShellExecute()");
423 HINSTANCE hinst
= ShellExecute(_hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
425 if ((int)hinst
<= 32)
426 display_error(_hwnd
, GetLastError());
431 WinHelp(_hwnd
, TEXT("explorer")/*file explorer.hlp*/, HELP_INDEX
, 0);
434 case ID_VIEW_FULLSCREEN
:
435 CheckMenuItem(_menu_info
._hMenuView
, id
, toggle_fullscreen()?MF_CHECKED
:0);
438 case ID_TOOLS_OPTIONS
:
439 Dialog::DoModal(IDD_MDI_SDI
, WINDOW_CREATOR(MdiSdiDlg
), _hwnd
);
442 case ID_ABOUT_WINDOWS
:
443 ShellAbout(_hwnd
, ResString(IDS_TITLE
), NULL
, 0);
446 case ID_ABOUT_EXPLORER
:
447 explorer_about(_hwnd
);
450 case ID_EXPLORER_FAQ
:
451 launch_file(_hwnd
, TEXT("http://www.sky.franken.de/explorer/"), SW_SHOW
);
455 return 1; // no command handlers in Window::Command()
461 int MainFrameBase::Notify(int id
, NMHDR
* pnmh
)
464 // resize children windows when the rebar size changes
467 resize_frame_client();
470 case TVN_GETINFOTIP
: {
471 NMTVGETINFOTIP
* pnmgit
= (NMTVGETINFOTIP
*)pnmh
;
473 if (pnmgit
->lParam
) {
474 const BookmarkNode
& node
= *(BookmarkNode
*)pnmgit
->lParam
;
476 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
477 // display tooltips for bookmark folders
478 if (!node
._pfolder
->_description
.empty())
479 lstrcpyn(pnmgit
->pszText
, node
._pfolder
->_description
.c_str(), pnmgit
->cchTextMax
);
480 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
481 // display tooltips for bookmark folders
482 String txt
= node
._pbookmark
->_description
;
484 if (!node
._pbookmark
->_url
.empty()) {
488 txt
+= node
._pbookmark
->_url
;
491 lstrcpyn(pnmgit
->pszText
, txt
.c_str(), pnmgit
->cchTextMax
);
497 HTREEITEM hitem
= TreeView_GetSelection(_hsidebar
);
498 LPARAM lparam
= TreeView_GetItemData(_hsidebar
, hitem
);
501 const BookmarkNode
& node
= *(BookmarkNode
*)lparam
;
503 if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
504 bool new_window
= GetAsyncKeyState(VK_SHIFT
)<0;
506 go_to(node
._pbookmark
->_url
, new_window
);
516 void MainFrameBase::resize_frame(int cx
, int cy
)
519 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
521 RECT rect
= {0, 0, cx
, cy
};
524 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
528 SetWindowPos(_haddrcombo
, NULL
, 0, 0, cx
, height
, SWP_NOMOVE
);
530 if (IsWindowVisible(_htoolbar
)) {
531 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
532 WindowRect
rt(_htoolbar
);
533 rect
.top
= rt
.bottom
;
534 // rect.bottom -= rt.bottom;
538 if (IsWindowVisible(_hstatusbar
)) {
539 int parts
[] = {300, 500};
541 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
542 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
543 ClientRect
rt(_hstatusbar
);
544 rect
.bottom
-= rt
.bottom
;
547 if (IsWindowVisible(_hsidebar
)) {
548 WindowRect
rt(_hsidebar
);
549 rect
.left
+= rt
.right
-rt
.left
;
551 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
555 void MainFrameBase::resize_frame_client()
557 ClientRect
rect(_hwnd
);
559 resize_frame(rect
.right
, rect
.bottom
);
562 void MainFrameBase::frame_get_clientspace(PRECT prect
)
564 if (!IsIconic(_hwnd
))
565 GetClientRect(_hwnd
, prect
);
569 GetWindowPlacement(_hwnd
, &wp
);
571 prect
->left
= prect
->top
= 0;
572 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
573 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
574 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
575 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
576 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
579 if (IsWindowVisible(_htoolbar
)) {
580 ClientRect
rt(_htoolbar
);
581 prect
->top
+= rt
.bottom
+2;
584 if (IsWindowVisible(_hstatusbar
)) {
585 ClientRect
rt(_hstatusbar
);
586 prect
->bottom
-= rt
.bottom
;
590 BOOL
MainFrameBase::toggle_fullscreen()
594 if ((_fullscreen
._mode
=!_fullscreen
._mode
)) {
595 GetWindowRect(_hwnd
, &_fullscreen
._orgPos
);
596 _fullscreen
._wasZoomed
= IsZoomed(_hwnd
);
598 Frame_CalcFrameClient(_hwnd
, &rt
);
599 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.left
);
600 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.right
);
602 rt
.left
= _fullscreen
._orgPos
.left
-rt
.left
;
603 rt
.top
= _fullscreen
._orgPos
.top
-rt
.top
;
604 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+_fullscreen
._orgPos
.right
-rt
.right
;
605 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+_fullscreen
._orgPos
.bottom
-rt
.bottom
;
607 MoveWindow(_hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
609 MoveWindow(_hwnd
, _fullscreen
._orgPos
.left
, _fullscreen
._orgPos
.top
,
610 _fullscreen
._orgPos
.right
-_fullscreen
._orgPos
.left
,
611 _fullscreen
._orgPos
.bottom
-_fullscreen
._orgPos
.top
, TRUE
);
613 if (_fullscreen
._wasZoomed
)
614 ShowWindow(_hwnd
, WS_MAXIMIZE
);
617 return _fullscreen
._mode
;
620 void MainFrameBase::fullscreen_move()
623 GetWindowRect(_hwnd
, &pos
);
625 Frame_CalcFrameClient(_hwnd
, &rt
);
626 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.left
);
627 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.right
);
629 rt
.left
= pos
.left
-rt
.left
;
630 rt
.top
= pos
.top
-rt
.top
;
631 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
632 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
634 MoveWindow(_hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
638 void MainFrameBase::toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
, int band_idx
)
640 BOOL vis
= IsWindowVisible(hchild
);
642 CheckMenuItem(_menu_info
._hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
645 SendMessage(_hwndrebar
, RB_SHOWBAND
, band_idx
, !vis
);
647 ShowWindow(hchild
, vis
? SW_HIDE
: SW_SHOW
);
649 if (_fullscreen
._mode
)
652 resize_frame_client();
655 void MainFrameBase::FillBookmarks()
657 HiddenWindow
hide(_hsidebar
);
658 WindowCanvas
canvas(_hwnd
);
660 TreeView_DeleteAllItems(_hsidebar
);
662 g_Globals
._icon_cache
.get_icon(ICID_FAVORITES
).add_to_imagelist(_himl
, canvas
);
663 g_Globals
._icon_cache
.get_icon(ICID_BOOKMARK
).add_to_imagelist(_himl
, canvas
);
664 ImageList_AddAlphaIcon(_himl
, SmallIcon(IDI_DOT
), GetStockBrush(WHITE_BRUSH
), canvas
);
665 g_Globals
._icon_cache
.get_icon(ICID_FOLDER
).add_to_imagelist(_himl
, canvas
);
666 g_Globals
._icon_cache
.get_icon(ICID_FOLDER
).add_to_imagelist(_himl
, canvas
);
670 tvi
.hParent
= TVI_ROOT
;
671 tvi
.hInsertAfter
= TVI_LAST
;
672 tvi
.item
.mask
= TVIF_TEXT
|TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;
673 ResString
sFavorites(IDS_FAVORITES
);
674 tvi
.item
.pszText
= sFavorites
.str();
675 tvi
.item
.iSelectedImage
= tvi
.item
.iImage
= 0;
677 HTREEITEM hitem_bookmarks
= TreeView_InsertItem(_hsidebar
, &tvi
);
679 g_Globals
._favorites
.fill_tree(_hsidebar
, hitem_bookmarks
, _himl
, canvas
);
681 TreeView_Expand(_hsidebar
, hitem_bookmarks
, TVE_EXPAND
);
685 bool MainFrameBase::go_to(LPCTSTR url
, bool new_window
)
687 ///@todo SDI implementation
695 MDIMainFrame::MDIMainFrame(HWND hwnd
)
698 TBBUTTON mdiBtns
[] = {
699 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
700 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
701 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
702 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
703 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0}
706 SendMessage(_htoolbar
, TB_ADDBUTTONS
, sizeof(mdiBtns
)/sizeof(TBBUTTON
), (LPARAM
)&mdiBtns
);
708 CLIENTCREATESTRUCT ccs
;
710 ccs
.hWindowMenu
= _hMenuWindow
;
711 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
713 _hmdiclient
= CreateWindowEx(WS_EX_CLIENTEDGE
|WS_EX_NOPARENTNOTIFY
, TEXT("MDICLIENT"), NULL
,
714 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
716 hwnd
, 0, g_Globals
._hInstance
, &ccs
);
718 TBBUTTON extraBtns
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
721 _hextrabar
= CreateToolbarEx(hwnd
,
722 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
723 WS_CHILD
|TBSTYLE_FLAT
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
724 IDW_EXTRABAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, NULL
, 0,
725 16, 16, 16, 16, sizeof(TBBUTTON
));
727 _hextrabar
= CreateToolbarEx(hwnd
,
728 WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,CCS_NODIVIDER
|
729 IDW_EXTRABAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, &extraBtns
, 1,
730 16, 13, 16, 13, sizeof(TBBUTTON
));
733 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_EXTRA_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
736 extraBtns
.fsStyle
= BTNS_BUTTON
;
739 // insert unix file system button
740 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("/\0"));
741 extraBtns
.idCommand
= ID_DRIVE_UNIX_FS
;
742 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
745 // insert explorer window button
746 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Explore\0"));
747 extraBtns
.idCommand
= ID_DRIVE_DESKTOP
;
748 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
750 // insert shell namespace button
751 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Shell\0"));
752 extraBtns
.idCommand
= ID_DRIVE_SHELL_NS
;
753 extraBtns
.iBitmap
= 6;
754 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
756 // insert web control button
757 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Web\0"));
758 extraBtns
.idCommand
= ID_WEB_WINDOW
;
759 extraBtns
.iBitmap
= 7;
760 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
762 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
763 // insert NT object namespace button
764 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("NT Obj\0"));
765 extraBtns
.idCommand
= ID_DRIVE_NTOBJ_NS
;
766 extraBtns
.iBitmap
= 8;
767 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
769 #ifndef __REACTOS__ // don't insert reg button for ROS. Regedit should be used.
770 // insert Registry button
771 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Reg.\0"));
772 extraBtns
.idCommand
= ID_DRIVE_REGISTRY
;
773 extraBtns
.iBitmap
= 9;
774 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
778 // insert FAT direct file system access button
779 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("FAT\0"));
780 extraBtns
.idCommand
= ID_DRIVE_FAT
;
781 extraBtns
.iBitmap
= 10;
782 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
786 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
791 _hdrivebar
= CreateToolbarEx(hwnd
,
792 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
793 WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
|CCS_NOMOVEY
|TBSTYLE_LIST
,
794 IDW_DRIVEBAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, NULL
, 0,
795 16, 16, 16, 16, sizeof(TBBUTTON
));
797 _hdrivebar
= CreateToolbarEx(hwnd
,
798 WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
|CCS_NODIVIDER
,
799 IDW_DRIVEBAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, &drivebarBtn
, 1,
800 16, 13, 16, 13, sizeof(TBBUTTON
));
804 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_UNCHECKED
);
808 GetLogicalDriveStrings(BUFFER_LEN
, _drives
);
810 // register windows drive root strings
811 SendMessage(_hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)_drives
);
813 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
814 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
816 for(p
=_drives
; *p
; ) {
817 switch(GetDriveType(p
)) {
818 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
819 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
820 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
821 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
822 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
825 SendMessage(_hdrivebar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&drivebarBtn
);
826 ++drivebarBtn
.idCommand
;
827 ++drivebarBtn
.iString
;
835 int btn_hgt
= HIWORD(SendMessage(_htoolbar
, TB_GETBUTTONSIZE
, 0, 0));
837 REBARBANDINFO rbBand
;
839 rbBand
.cbSize
= sizeof(REBARBANDINFO
);
840 rbBand
.fMask
= RBBIM_TEXT
|RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
841 #ifndef RBBS_HIDETITLE // missing in MinGW headers as of 25.02.2004
842 #define RBBS_HIDETITLE 0x400
844 rbBand
.fStyle
= RBBS_CHILDEDGE
|RBBS_GRIPPERALWAYS
|RBBS_HIDETITLE
;
846 TCHAR ExtrasBand
[] = _T("Extras");
847 rbBand
.lpText
= ExtrasBand
;
848 rbBand
.hwndChild
= _hextrabar
;
849 rbBand
.cxMinChild
= 0;
850 rbBand
.cyMinChild
= btn_hgt
;
852 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)1, (LPARAM
)&rbBand
);
855 rbBand
.fStyle
|= RBBS_BREAK
;
856 TCHAR DrivesBand
[] = _T("Drives");
857 rbBand
.lpText
= DrivesBand
;
858 rbBand
.hwndChild
= _hdrivebar
;
859 rbBand
.cxMinChild
= 0;
860 rbBand
.cyMinChild
= btn_hgt
;
862 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)2, (LPARAM
)&rbBand
);
864 // hide the drivebar by default
865 SendMessage(_hwndrebar
, RB_SHOWBAND
, 2, FALSE
);
871 HWND
MDIMainFrame::Create()
873 HMENU hMenuFrame
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(IDM_MDIFRAME
));
875 return Window::Create(WINDOW_CREATOR(MDIMainFrame
), 0,
876 (LPCTSTR
)(int)g_Globals
._hframeClass
, ResString(IDS_TITLE
), WS_OVERLAPPEDWINDOW
,
877 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
878 0/*hwndDesktop*/, hMenuFrame
);
881 HWND
MDIMainFrame::Create(LPCTSTR path
, int mode
)
883 HWND hFrame
= Create();
887 ShowWindow(hFrame
, SW_SHOW
);
889 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
892 pMainFrame
->CreateChild(path
, mode
);
897 HWND
MDIMainFrame::Create(LPCITEMIDLIST pidl
, int mode
)
899 HWND hFrame
= Create();
903 ShowWindow(hFrame
, SW_SHOW
);
905 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
908 pMainFrame
->CreateChild(pidl
, mode
);
914 ChildWindow
* MDIMainFrame::CreateChild(LPCTSTR path
, int mode
)
916 return reinterpret_cast<ChildWindow
*>(SendMessage(_hwnd
, PM_OPEN_WINDOW
, mode
, (LPARAM
)path
));
919 ChildWindow
* MDIMainFrame::CreateChild(LPCITEMIDLIST pidl
, int mode
)
921 return reinterpret_cast<ChildWindow
*>(SendMessage(_hwnd
, PM_OPEN_WINDOW
, mode
|OWM_PIDL
, (LPARAM
)pidl
));
925 BOOL
MDIMainFrame::TranslateMsg(MSG
* pmsg
)
927 if (_hmdiclient
&& TranslateMDISysAccel(_hmdiclient
, pmsg
))
930 return super::TranslateMsg(pmsg
);
933 LRESULT
MDIMainFrame::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
936 case PM_OPEN_WINDOW
: {
937 CONTEXT("MDIMainFrame PM_OPEN_WINDOW");
939 TCHAR buffer
[MAX_PATH
];
941 ShellPath shell_path
= DesktopFolderPath();
944 if (wparam
& OWM_PIDL
) {
945 // take over PIDL from lparam
946 shell_path
.assign((LPCITEMIDLIST
)lparam
); // create as "rooted" window
947 FileSysShellPath
fsp(shell_path
);
951 LOG(FmtString(TEXT("MDIMainFrame PM_OPEN_WINDOW: path=%s"), path
));
952 lstrcpy(buffer
, path
);
956 // take over path from lparam
957 path
= (LPCTSTR
)lparam
;
958 shell_path
= path
; // create as "rooted" window
961 ///@todo read paths and window placements from registry
962 if (!GetCurrentDirectory(MAX_PATH
, buffer
))
968 if (path
&& _tcsstr(path
, TEXT("://"))) { // "http://...", "ftp://", ...
969 OBJ_CONTEXT("create WebChild window", path
);
971 return (LRESULT
)GET_WINDOW(ChildWindow
, create_webchildwindow(WebChildWndInfo(_hmdiclient
, path
)));
973 OBJ_CONTEXT("create ShellChildWndInfo", path
);
975 // Shell Namespace as default view
976 ShellChildWndInfo
create_info(_hmdiclient
, path
, shell_path
);
978 if (wparam
& OWM_ROOTED
)
979 create_info
._root_shell_path
= shell_path
;
981 create_info
._root_shell_path
= DesktopFolderPath(); //SpecialFolderPath(CSIDL_DRIVES, _hwnd);
983 create_info
._pos
.showCmd
= wparam
&OWM_SEPARATE
? SW_SHOWNORMAL
: SW_SHOWMAXIMIZED
;
984 create_info
._pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
985 create_info
._pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
986 create_info
._pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
987 create_info
._pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
989 create_info
._open_mode
= wparam
;
991 // FileChildWindow::create(_hmdiclient, create_info);
992 return (LRESULT
)MDIShellBrowserChild::create(create_info
);
994 return TRUE
;} // success
999 if (super::ProcessMessage(nmsg
, wparam
, lparam
, &res
))
1002 return DefFrameProc(_hwnd
, _hmdiclient
, nmsg
, wparam
, lparam
);
1009 int MDIMainFrame::Command(int id
, int code
)
1011 CONTEXT("MDIMainFrame::Command()");
1013 HWND hwndClient
= (HWND
) SendMessage(_hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1016 if (SendMessage(hwndClient
, PM_DISPATCH_COMMAND
, MAKELONG(id
,code
), 0))
1020 if (id
>=ID_DRIVE_FIRST
&& id
<=ID_DRIVE_FIRST
+0xFF) {
1021 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1022 LPCTSTR root
= _drives
;
1024 for(int i
=id
-ID_DRIVE_FIRST
; i
--; root
++)
1028 if (activate_drive_window(root
))
1031 _tsplitpath_s(root
, drv
, COUNTOF(drv
), NULL
, 0, NULL
, 0, NULL
, 0);
1033 if (!SetCurrentDirectory(drv
)) {
1034 display_error(_hwnd
, GetLastError());
1038 GetCurrentDirectory(MAX_PATH
, path
); ///@todo store last directory per drive
1040 FileChildWindow::create(FileChildWndInfo(_hmdiclient
, path
));
1047 case ID_WINDOW_NEW
: {
1048 TCHAR path
[MAX_PATH
];
1050 GetCurrentDirectory(MAX_PATH
, path
);
1052 FileChildWindow::create(FileChildWndInfo(_hmdiclient
, path
));
1055 case ID_WINDOW_CASCADE
:
1056 SendMessage(_hmdiclient
, WM_MDICASCADE
, 0, 0);
1059 case ID_WINDOW_TILE_HORZ
:
1060 SendMessage(_hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1063 case ID_WINDOW_TILE_VERT
:
1064 SendMessage(_hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1067 case ID_WINDOW_ARRANGE
:
1068 SendMessage(_hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1071 case ID_VIEW_EXTRA_BAR
:
1072 toggle_child(_hwnd
, id
, _hextrabar
, 1);
1076 case ID_VIEW_DRIVE_BAR
:
1077 toggle_child(_hwnd
, id
, _hdrivebar
, 2);
1082 case ID_DRIVE_UNIX_FS
: {
1083 TCHAR path
[MAX_PATH
];
1084 FileChildWindow
* child
;
1086 getcwd(path
, COUNTOF(path
));
1088 if (activate_child_window(TEXT("unixfs")))
1091 FileChildWindow::create(_hmdiclient
, FileChildWndInfo(path
));
1095 case ID_DRIVE_DESKTOP
: {
1096 TCHAR path
[MAX_PATH
];
1098 if (activate_child_window(TEXT("Desktop")))
1101 GetCurrentDirectory(MAX_PATH
, path
);
1103 MDIShellBrowserChild::create(ShellChildWndInfo(_hmdiclient
, path
, DesktopFolderPath()));
1106 case ID_DRIVE_SHELL_NS
: {
1107 TCHAR path
[MAX_PATH
];
1108 GetCurrentDirectory(MAX_PATH
, path
);
1110 if (activate_child_window(TEXT("Shell")))
1113 FileChildWindow::create(ShellChildWndInfo(_hmdiclient
, path
, DesktopFolderPath()));
1116 case ID_DRIVE_NTOBJ_NS
: {
1117 if (activate_child_window(TEXT("NTOBJ")))
1120 FileChildWindow::create(NtObjChildWndInfo(_hmdiclient
, TEXT("\\")));
1123 case ID_DRIVE_REGISTRY
: {
1124 if (activate_child_window(TEXT("Registry")))
1127 FileChildWindow::create(RegistryChildWndInfo(_hmdiclient
, TEXT("\\")));
1130 case ID_DRIVE_FAT
: {
1132 ///@todo prompt for image file
1134 if (activate_child_window(TEXT("FAT")))
1137 FileChildWindow::create(FATChildWndInfo(_hmdiclient
, TEXT("FAT Image"))); //@@
1142 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://localhost")));
1144 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://www.reactos.org")));
1148 case ID_EXPLORER_FAQ
:
1149 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://www.sky.franken.de/explorer/")));
1153 MainFrameBase::Create(ExplorerCmd());
1156 ///@todo There are even more menu items!
1159 if (super::Command(id
, code
) == 0)
1162 return DefFrameProc(_hwnd
, _hmdiclient
, WM_COMMAND
, MAKELONG(id
,code
), 0);
1169 void MDIMainFrame::frame_get_clientspace(PRECT prect
)
1171 super::frame_get_clientspace(prect
);
1174 if (IsWindowVisible(_hdrivebar
)) {
1175 ClientRect
rt(_hdrivebar
);
1176 prect
->top
+= rt
.bottom
+2;
1181 void MDIMainFrame::resize_frame(int cx
, int cy
)
1184 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1186 RECT rect
= {0, 0, cx
, cy
};
1189 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
1193 if (IsWindowVisible(_htoolbar
)) {
1194 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
1195 WindowRect
rt(_htoolbar
);
1196 rect
.top
= rt
.bottom
;
1197 // rect.bottom -= rt.bottom;
1200 if (IsWindowVisible(_hextrabar
)) {
1201 SendMessage(_hextrabar
, WM_SIZE
, 0, 0);
1202 WindowRect
rt(_hextrabar
);
1203 int new_top
= --rect
.top
+ rt
.bottom
;
1204 MoveWindow(_hextrabar
, 0, rect
.top
, rt
.right
, new_top
, TRUE
);
1206 // rect.bottom -= rt.bottom;
1210 if (IsWindowVisible(_hdrivebar
)) {
1211 SendMessage(_hdrivebar
, WM_SIZE
, 0, 0);
1212 WindowRect
rt(_hdrivebar
);
1213 int new_top
= --rect
.top
+ rt
.bottom
;
1214 MoveWindow(_hdrivebar
, 0, rect
.top
, rt
.right
, new_top
, TRUE
);
1216 // rect.bottom -= rt.bottom;
1221 if (IsWindowVisible(_hstatusbar
)) {
1222 int parts
[] = {300, 500};
1224 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
1225 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1226 ClientRect
rt(_hstatusbar
);
1227 rect
.bottom
-= rt
.bottom
;
1230 if (IsWindowVisible(_hsidebar
)) {
1231 WindowRect
rt(_hsidebar
);
1232 rect
.left
+= rt
.right
-rt
.left
;
1234 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
1237 MoveWindow(_hmdiclient
, rect
.left
-1, rect
.top
-1, rect
.right
-rect
.left
+1, rect
.bottom
-rect
.top
+1, TRUE
);
1240 bool MDIMainFrame::activate_drive_window(LPCTSTR path
)
1242 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1245 _tsplitpath_s(path
, drv1
, COUNTOF(drv1
), NULL
, 0, NULL
, 0, NULL
, 0);
1247 // search for a already open window for the same drive
1248 for(child_wnd
=GetNextWindow(_hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1249 FileChildWindow
* child
= (FileChildWindow
*) SendMessage(child_wnd
, PM_GET_FILEWND_PTR
, 0, 0);
1252 _tsplitpath_s(child
->get_root()._path
, drv2
, COUNTOF(drv2
), NULL
, 0, NULL
, 0, NULL
, 0);
1254 if (!lstrcmpi(drv2
, drv1
)) {
1255 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1257 if (IsMinimized(child_wnd
))
1258 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1268 bool MDIMainFrame::activate_child_window(LPCTSTR filesys
)
1272 // search for a already open window of the given file system name
1273 for(child_wnd
=GetNextWindow(_hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1274 FileChildWindow
* child
= (FileChildWindow
*) SendMessage(child_wnd
, PM_GET_FILEWND_PTR
, 0, 0);
1277 if (!lstrcmpi(child
->get_root()._fs
, filesys
)) {
1278 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1280 if (IsMinimized(child_wnd
))
1281 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1286 ShellBrowser
* shell_child
= (ShellBrowser
*) SendMessage(child_wnd
, PM_GET_SHELLBROWSER_PTR
, 0, 0);
1289 if (!lstrcmpi(shell_child
->get_root()._fs
, filesys
)) {
1290 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1292 if (IsMinimized(child_wnd
))
1293 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1304 bool MDIMainFrame::go_to(LPCTSTR url
, bool new_window
)
1307 HWND hwndClient
= (HWND
) SendMessage(_hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1310 if (SendMessage(hwndClient
, PM_JUMP_TO_URL
, 0, (LPARAM
)url
))
1314 if (CreateChild(url
))
1317 return super::go_to(url
, new_window
);
1323 SDIMainFrame::SDIMainFrame(HWND hwnd
)
1326 _split_pos
= DEFAULT_SPLIT_POS
;
1327 _last_split
= DEFAULT_SPLIT_POS
;
1329 /* wait for PM_OPEN_WINDOW message before creating a shell view
1330 update_shell_browser();*/
1333 HWND
SDIMainFrame::Create()
1335 HMENU hMenuFrame
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(IDM_SDIFRAME
));
1337 return Window::Create(WINDOW_CREATOR(SDIMainFrame
), 0,
1338 (LPCTSTR
)(int)g_Globals
._hframeClass
, ResString(IDS_TITLE
), WS_OVERLAPPEDWINDOW
,
1339 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1340 0/*hwndDesktop*/, hMenuFrame
);
1343 HWND
SDIMainFrame::Create(LPCITEMIDLIST pidl
, int mode
)
1345 HWND hFrame
= Create();
1349 ShowWindow(hFrame
, SW_SHOW
);
1351 SDIMainFrame
* pFrame
= GET_WINDOW(SDIMainFrame
, hFrame
);
1354 pFrame
->jump_to(pidl
, mode
);
1359 HWND
SDIMainFrame::Create(LPCTSTR path
, int mode
)
1361 HWND hFrame
= Create();
1365 ShowWindow(hFrame
, SW_SHOW
);
1367 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
1370 pMainFrame
->CreateChild(path
, mode
);
1375 LRESULT
SDIMainFrame::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1379 resize_frame(LOWORD(lparam
), HIWORD(lparam
));
1383 PaintCanvas
canvas(_hwnd
);
1386 ClientRect
rt(_hwnd
);
1387 rt
.left
= _split_pos
-SPLIT_WIDTH
/2;
1388 rt
.right
= _split_pos
+SPLIT_WIDTH
/2+1;
1391 WindowRect
right_rect(_right_hwnd
);
1392 ScreenToClient(_hwnd
, &right_rect
);
1393 rt
.top
= right_rect
.top
;
1394 rt
.bottom
= right_rect
.bottom
;
1397 HBRUSH lastBrush
= SelectBrush(canvas
, GetStockBrush(COLOR_SPLITBAR
));
1398 Rectangle(canvas
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
1399 SelectObject(canvas
, lastBrush
);
1405 if (LOWORD(lparam
) == HTCLIENT
) {
1408 ScreenToClient(_hwnd
, &pt
);
1410 if (pt
.x
>=_split_pos
-SPLIT_WIDTH
/2 && pt
.x
<_split_pos
+SPLIT_WIDTH
/2+1) {
1411 SetCursor(LoadCursor(0, IDC_SIZEWE
));
1417 case WM_LBUTTONDOWN
:
1419 int x
= GET_X_LPARAM(lparam
);
1421 ClientRect
rt(_hwnd
);
1423 if (x
>=_split_pos
-SPLIT_WIDTH
/2 && x
<_split_pos
+SPLIT_WIDTH
/2+1) {
1424 _last_split
= _split_pos
;
1431 if (GetCapture() == _hwnd
)
1436 if (wparam
== VK_ESCAPE
)
1437 if (GetCapture() == _hwnd
) {
1438 _split_pos
= _last_split
;
1442 SetCursor(LoadCursor(0, IDC_ARROW
));
1447 if (GetCapture() == _hwnd
) {
1448 int x
= GET_X_LPARAM(lparam
);
1450 ClientRect
rt(_hwnd
);
1452 if (x
>=0 && x
<rt
.right
) {
1455 rt
.left
= x
-SPLIT_WIDTH
/2;
1456 rt
.right
= x
+SPLIT_WIDTH
/2+1;
1457 InvalidateRect(_hwnd
, &rt
, FALSE
);
1458 UpdateWindow(_left_hwnd
);
1459 UpdateWindow(_hwnd
);
1460 UpdateWindow(_right_hwnd
);
1465 case PM_OPEN_WINDOW
: {
1466 CONTEXT("SDIMainFrame PM_OPEN_WINDOW");
1468 TCHAR buffer
[MAX_PATH
];
1470 ShellPath shell_path
= DesktopFolderPath();
1473 if (wparam
& OWM_PIDL
) {
1474 // take over PIDL from lparam
1475 shell_path
.assign((LPCITEMIDLIST
)lparam
); // create as "rooted" window
1476 FileSysShellPath
fsp(shell_path
);
1480 LOG(FmtString(TEXT("SDIMainFrame PM_OPEN_WINDOW: path=%s"), path
));
1481 lstrcpy(buffer
, path
);
1485 // take over path from lparam
1486 path
= (LPCTSTR
)lparam
;
1487 shell_path
= path
; // create as "rooted" window
1490 ///@todo read paths and window placements from registry
1491 if (!GetCurrentDirectory(MAX_PATH
, buffer
))
1498 if (wparam
& OWM_ROOTED
)
1499 _shellpath_info
._root_shell_path
= shell_path
;
1501 _shellpath_info
._root_shell_path
= DesktopFolderPath(); //SpecialFolderPath(CSIDL_DRIVES, _hwnd);
1503 jump_to(shell_path
, wparam
); ///@todo content of 'path' not used any more
1504 return TRUE
;} // success
1507 return super::WndProc(nmsg
, wparam
, lparam
);
1513 int SDIMainFrame::Command(int id
, int code
)
1517 MainFrameBase::Create(ExplorerCmd(_url
, true));
1521 return super::Command(id
, code
);
1527 void SDIMainFrame::resize_frame(int cx
, int cy
)
1530 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1532 RECT rect
= {0, 0, cx
, cy
};
1535 int height
= ClientRect(_hwndrebar
).bottom
;
1539 if (IsWindowVisible(_htoolbar
)) {
1540 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
1541 WindowRect
rt(_htoolbar
);
1542 rect
.top
= rt
.bottom
;
1543 // rect.bottom -= rt.bottom;
1547 if (IsWindowVisible(_hstatusbar
)) {
1548 int parts
[] = {300, 500};
1550 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
1551 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1552 ClientRect
rt(_hstatusbar
);
1553 rect
.bottom
-= rt
.bottom
;
1556 if (IsWindowVisible(_hsidebar
)) {
1557 WindowRect
rt(_hsidebar
);
1558 rect
.left
+= rt
.right
-rt
.left
;
1560 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
1568 void SDIMainFrame::resize_children()
1570 HDWP hdwp
= BeginDeferWindowPos(2);
1572 int cx
= _clnt_rect
.left
;
1575 cx
= _split_pos
+ SPLIT_WIDTH
/2;
1577 hdwp
= DeferWindowPos(hdwp
, _left_hwnd
, 0, _clnt_rect
.left
, _clnt_rect
.top
, _split_pos
-SPLIT_WIDTH
/2-_clnt_rect
.left
, _clnt_rect
.bottom
-_clnt_rect
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
1584 hdwp
= DeferWindowPos(hdwp
, _right_hwnd
, 0, _clnt_rect
.left
+cx
+1, _clnt_rect
.top
, _clnt_rect
.right
-cx
, _clnt_rect
.bottom
-_clnt_rect
.top
, SWP_NOZORDER
|SWP_NOACTIVATE
);
1586 EndDeferWindowPos(hdwp
);
1589 void SDIMainFrame::update_clnt_rect()
1591 ClientRect
rect(_hwnd
);
1593 resize_frame(rect
.right
, rect
.bottom
);
1596 void SDIMainFrame::update_shell_browser()
1598 int split_pos
= DEFAULT_SPLIT_POS
;
1600 if (_shellBrowser
.get()) {
1601 split_pos
= _split_pos
;
1602 delete _shellBrowser
.release();
1605 // create explorer treeview
1606 if (_shellpath_info
._open_mode
& OWM_EXPLORE
) {
1608 ClientRect
rect(_hwnd
);
1610 _left_hwnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_TREEVIEW
, NULL
,
1611 WS_CHILD
|WS_TABSTOP
|WS_VISIBLE
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
|TVS_NOTOOLTIPS
|TVS_SHOWSELALWAYS
,
1612 0, rect
.top
, split_pos
-SPLIT_WIDTH
/2, rect
.bottom
-rect
.top
,
1613 _hwnd
, (HMENU
)IDC_FILETREE
, g_Globals
._hInstance
, 0);
1615 // display tree window as long as the shell view is not yet visible
1616 resize_frame(rect
.right
, rect
.bottom
);
1617 MoveWindow(_left_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1621 DestroyWindow(_left_hwnd
);
1626 _shellBrowser
= auto_ptr
<ShellBrowser
>(new ShellBrowser(_hwnd
, _hwnd
, _left_hwnd
, _right_hwnd
,
1627 _shellpath_info
, this, _cm_ifs
));
1630 _shellBrowser
->Init();
1632 // update _clnt_rect and set size of new created shell view windows
1636 void SDIMainFrame::entry_selected(Entry
* entry
)
1639 _shellBrowser
->select_folder(entry
, false);
1641 _shellBrowser
->UpdateFolderView(entry
->get_shell_folder());
1643 // set size of new created shell view windows
1647 void SDIMainFrame::set_url(LPCTSTR url
)
1651 SetWindowText(_haddrcombo
, url
);
1656 void SDIMainFrame::jump_to(LPCTSTR path
, int mode
)
1658 if (_shellBrowser.get() && (_shellpath_info._open_mode&~OWM_PIDL)==(mode&~OWM_PIDL)) {
1659 _shellBrowser->jump_to(path);
1661 _shellpath_info._shell_path = path;
1663 _shellpath_info
._open_mode
= mode
;
1664 _shellpath_info
._shell_path
= path
;
1666 update_shell_browser();
1670 void SDIMainFrame::jump_to(LPCITEMIDLIST path
, int mode
)
1672 if (_shellBrowser
.get() && (_shellpath_info
._open_mode
&~OWM_PIDL
)==(mode
&~OWM_PIDL
)) {
1673 ShellPath shell_path
= path
;
1675 _shellBrowser
->jump_to(shell_path
);
1677 _shellpath_info
._shell_path
= shell_path
;
1679 _shellpath_info
._open_mode
= mode
;
1680 _shellpath_info
._shell_path
= path
;
1682 update_shell_browser();