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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
41 HWND
MainFrameBase::Create(const ExplorerCmd
& cmd
)
47 hFrame
= MDIMainFrame::Create();
50 hFrame
= SDIMainFrame::Create();
53 HWND hwndOld
= g_Globals
._hMainWnd
;
55 g_Globals
._hMainWnd
= hFrame
;
58 DestroyWindow(hwndOld
);
60 ShowWindow(hFrame
, cmd
._cmdShow
);
63 // Open the first child window after initializing the application
64 if (cmd
.IsValidPath()) {
65 // We use the static s_path variable to store the path string in order
66 // to avoid accessing prematurely freed memory in the PostMessage handlers.
67 static String s_path
= cmd
._path
;
69 PostMessage(hFrame
, PM_OPEN_WINDOW
, cmd
._flags
, (LPARAM
)(LPCTSTR
)s_path
);
71 PostMessage(hFrame
, PM_OPEN_WINDOW
, OWM_EXPLORE
|OWM_DETAILS
, 0);
78 int MainFrameBase::OpenShellFolders(LPIDA pida
, HWND hFrameWnd
)
82 LPCITEMIDLIST parent_pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
83 ShellFolder
folder(parent_pidl
);
84 LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): parent_pidl=%s"), (LPCTSTR
)FileSysShellPath(parent_pidl
)));
86 for(int i
=pida
->cidl
; i
>0; --i
) {
87 LPCITEMIDLIST pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[i
]);
89 SFGAOF attribs
= SFGAO_FOLDER
;
90 HRESULT hr
= folder
->GetAttributesOf(1, &pidl
, &attribs
);
93 if (attribs
& SFGAO_FOLDER
) {
95 XMLPos explorer_options
= g_Globals
.get_cfg("general/explorer");
97 bool mdi
= XMLBool(explorer_options
, "mdi", true);
98 bool separateFolders
= XMLBool(explorer_options
, "separate-folders", true);
100 ShellPath pidl_abs
= ShellPath(pidl
).create_absolute_pidl(parent_pidl
);
101 LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): pidl_abs=%s"), (LPCTSTR
)FileSysShellPath(pidl_abs
)));
103 if (hFrameWnd
&& (mdi
|| !separateFolders
)) {
104 int flags
= OWM_PIDL
;
107 flags
|= OWM_SEPARATE
;
109 if (SendMessage(hFrameWnd
, PM_OPEN_WINDOW
, flags
, (LPARAM
)(LPCITEMIDLIST
)pidl_abs
))
115 hwnd
= MDIMainFrame::Create(pidl_abs
, 0);
118 hwnd
= SDIMainFrame::Create(pidl_abs
, 0);
123 } catch(COMException
& e
) {
124 HandleException(e
, g_Globals
._hMainWnd
);
127 else { // !(attribs & SFGAO_FOLDER))
128 SHELLEXECUTEINFOA shexinfo;
130 shexinfo.cbSize = sizeof(SHELLEXECUTEINFOA);
131 shexinfo.fMask = SEE_MASK_INVOKEIDLIST;
132 shexinfo.hwnd = NULL;
133 shexinfo.lpVerb = NULL;
134 shexinfo.lpFile = NULL;
135 shexinfo.lpParameters = NULL;
136 shexinfo.lpDirectory = NULL;
137 shexinfo.nShow = SW_NORMAL;
138 shexinfo.lpIDList = ILCombine(parent_pidl, pidl);
140 if (ShellExecuteExA(&shexinfo))
143 ILFree((LPITEMIDLIST)shexinfo.lpIDList);
151 MainFrameBase::MainFrameBase(HWND hwnd
)
154 _himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), ILC_MASK
|ILC_COLOR24
, 2, 0);
156 _hMenuFrame
= GetMenu(hwnd
);
157 _hMenuWindow
= GetSubMenu(_hMenuFrame
, GetMenuItemCount(_hMenuFrame
)-3);
159 _menu_info
._hMenuView
= GetSubMenu(_hMenuFrame
, 1);
161 _hAccel
= LoadAccelerators(g_Globals
._hInstance
, MAKEINTRESOURCE(IDA_EXPLORER
));
164 TBBUTTON toolbarBtns
[] = {
166 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
168 {7, ID_GO_BACK
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
169 {8, ID_GO_FORWARD
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
170 {9, ID_GO_UP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
171 {10, ID_GO_HOME
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
172 {11, ID_GO_SEARCH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
173 {12, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
174 {13, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0}
177 _htoolbar
= CreateToolbarEx(hwnd
,
179 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
181 WS_CHILD
|TBSTYLE_FLAT
|WS_VISIBLE
, IDW_TOOLBAR
, 2, g_Globals
._hInstance
, IDB_TOOLBAR
,
182 toolbarBtns
, sizeof(toolbarBtns
)/sizeof(TBBUTTON
),
183 16, 15, 16, 15, sizeof(TBBUTTON
));
185 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_TOOL_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
188 // address & command bar
189 WindowCanvas
canvas(hwnd
);
190 RECT rect
= {0, 0, 0, 0};
191 DrawText(canvas
, TEXT("My"), -1, &rect
, DT_SINGLELINE
|DT_NOPREFIX
|DT_CALCRECT
);
192 HFONT hfont
= GetStockFont(DEFAULT_GUI_FONT
);
194 _haddressedit
= CreateWindow(TEXT("EDIT"), NULL
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, rect
.bottom
,
195 hwnd
, (HMENU
)IDW_ADDRESSBAR
, g_Globals
._hInstance
, 0);
196 SetWindowFont(_haddressedit
, hfont
, FALSE
);
197 new EditController(_haddressedit
);
199 _hcommandedit
= CreateWindow(TEXT("EDIT"), TEXT("> "), WS_CHILD
|WS_VISIBLE
, 0, 0, 0, rect
.bottom
,
200 hwnd
, (HMENU
)IDW_COMMANDBAR
, g_Globals
._hInstance
, 0);
201 SetWindowFont(_hcommandedit
, hfont
, FALSE
);
202 new EditController(_hcommandedit
);
204 /* CreateStatusWindow does not accept WS_BORDER
205 _hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0,
206 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0,
207 hwnd, (HMENU)IDW_STATUSBAR, g_Globals._hInstance, 0);*/
209 _hstatusbar
= CreateStatusWindow(WS_CHILD
|WS_VISIBLE
, 0, hwnd
, IDW_STATUSBAR
);
210 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
212 _hsidebar
= CreateWindowEx(WS_EX_STATICEDGE
, WC_TREEVIEW
, TEXT("Sidebar"),
213 WS_CHILD
|WS_TABSTOP
|WS_BORDER
|/*WS_VISIBLE|*/WS_CHILD
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_SHOWSELALWAYS
|TVS_INFOTIP
,
214 -1, -1, 200, 0, _hwnd
, (HMENU
)IDW_SIDEBAR
, g_Globals
._hInstance
, 0);
216 _himl_old
= TreeView_SetImageList(_hsidebar
, _himl
, TVSIL_NORMAL
);
218 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_SIDE_BAR
, MF_BYCOMMAND
|MF_UNCHECKED
/*MF_CHECKED*/);
221 // create rebar window to manage toolbar and drivebar
223 _hwndrebar
= CreateWindowEx(WS_EX_TOOLWINDOW
, REBARCLASSNAME
, NULL
,
224 WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|
225 RBS_VARHEIGHT
|RBS_DBLCLKTOGGLE
|
226 WS_BORDER
|RBS_AUTOSIZE
|RBS_BANDBORDERS
,
227 0, 0, 0, 0, _hwnd
, 0, g_Globals
._hInstance
, 0);
229 int btn_hgt
= HIWORD(SendMessage(_htoolbar
, TB_GETBUTTONSIZE
, 0, 0));
231 REBARBANDINFO rbBand
;
233 rbBand
.cbSize
= sizeof(REBARBANDINFO
);
234 rbBand
.fMask
= RBBIM_TEXT
|RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
235 #ifndef RBBS_HIDETITLE // missing in MinGW headers as of 25.02.2004
236 #define RBBS_HIDETITLE 0x400
238 rbBand
.fStyle
= RBBS_CHILDEDGE
|RBBS_GRIPPERALWAYS
|RBBS_HIDETITLE
;
240 rbBand
.cxMinChild
= 0;
241 rbBand
.cyMinChild
= 0;
243 rbBand
.cyMaxChild
= 0;
244 rbBand
.cyIntegral
= btn_hgt
;
246 rbBand
.lpText
= NULL
;//TEXT("Toolbar");
247 rbBand
.hwndChild
= _htoolbar
;
248 rbBand
.cxMinChild
= 0;
249 rbBand
.cyMinChild
= btn_hgt
;
251 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)-1, (LPARAM
)&rbBand
);
256 MainFrameBase::~MainFrameBase()
258 (void)TreeView_SetImageList(_hsidebar
, _himl_old
, TVSIL_NORMAL
);
259 ImageList_Destroy(_himl
);
261 // don't exit desktop when closing file manager window
262 if (!g_Globals
._desktop_mode
)
263 if (g_Globals
._hMainWnd
== _hwnd
) // don't quit when switching between MDI and SDI mode
268 LRESULT
MainFrameBase::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
272 if (ProcessMessage(nmsg
, wparam
, lparam
, &res
))
275 return super::WndProc(nmsg
, wparam
, lparam
);
278 bool MainFrameBase::ProcessMessage(UINT nmsg
, WPARAM wparam
, LPARAM lparam
, LRESULT
* pres
)
281 case PM_TRANSLATE_MSG
:
282 *pres
= TranslateMsg((MSG
*)lparam
);
286 if (wparam
) { // trigger child resizing after window creation - now we can succesfully call IsWindowVisible()
287 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
288 MoveWindow(_hwndrebar
, 0, 0, LOWORD(lparam
), height
, TRUE
);
289 resize_frame_client();
291 return false; // goto def;
294 DestroyWindow(_hwnd
);
295 g_Globals
._hMainWnd
= 0;
302 #ifdef _ROS_ ///@todo Work around to display rebar in ROS (with flickering) as long as the control isn't fixed
303 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
304 MoveWindow(_hwndrebar
, 0, 0, LOWORD(lparam
), height
, TRUE
);
306 resize_frame(LOWORD(lparam
), HIWORD(lparam
));
308 } break; // do not pass message to DefFrameProc
310 case WM_GETMINMAXINFO
: {
311 LPMINMAXINFO lpmmi
= (LPMINMAXINFO
)lparam
;
313 lpmmi
->ptMaxTrackSize
.x
<<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
314 lpmmi
->ptMaxTrackSize
.y
<<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
317 case PM_FRM_CALC_CLIENT
:
318 frame_get_clientspace((PRECT
)lparam
);
322 case PM_FRM_GET_MENUINFO
:
323 *pres
= (LPARAM
)&_menu_info
;
326 case PM_GET_CONTROLWINDOW
:
327 if (wparam
== FCW_STATUS
) {
328 *pres
= (LRESULT
)(HWND
)_hstatusbar
;
333 case PM_SETSTATUSTEXT
:
334 SendMessage(_hstatusbar
, SB_SETTEXT
, 0, lparam
);
338 SetWindowText(_haddressedit
, (LPCTSTR
)lparam
);
349 BOOL
MainFrameBase::TranslateMsg(MSG
* pmsg
)
351 if (TranslateAccelerator(_hwnd
, _hAccel
, pmsg
))
358 int MainFrameBase::Command(int id
, int code
)
360 CONTEXT("MainFrameBase::Command()");
364 SendMessage(_hwnd
, WM_CLOSE
, 0, 0);
367 case ID_VIEW_TOOL_BAR
:
368 toggle_child(_hwnd
, id
, _htoolbar
, 0);
371 case ID_VIEW_STATUSBAR
:
372 toggle_child(_hwnd
, id
, _hstatusbar
);
375 case ID_VIEW_SIDE_BAR
:
376 // lazy initialization
377 if (!TreeView_GetCount(_hsidebar
))
380 toggle_child(_hwnd
, id
, _hsidebar
);
384 ExecuteDialog dlg
= {{0}, 0};
386 if (DialogBoxParam(g_Globals
._hInstance
, MAKEINTRESOURCE(IDD_EXECUTE
), _hwnd
, ExecuteDialog::WndProc
, (LPARAM
)&dlg
) == IDOK
) {
387 CONTEXT("ID_EXECUTE - ShellExecute()");
389 HINSTANCE hinst
= ShellExecute(_hwnd
, NULL
/*operation*/, dlg
.cmd
/*file*/, NULL
/*parameters*/, NULL
/*dir*/, dlg
.cmdshow
);
391 if ((int)hinst
<= 32)
392 display_error(_hwnd
, GetLastError());
397 WinHelp(_hwnd
, TEXT("explorer")/*file explorer.hlp*/, HELP_INDEX
, 0);
400 case ID_VIEW_FULLSCREEN
:
401 CheckMenuItem(_menu_info
._hMenuView
, id
, toggle_fullscreen()?MF_CHECKED
:0);
404 case ID_TOOLS_OPTIONS
:
405 Dialog::DoModal(IDD_MDI_SDI
, WINDOW_CREATOR(MdiSdiDlg
), _hwnd
);
408 case ID_ABOUT_WINDOWS
:
409 ShellAbout(_hwnd
, ResString(IDS_TITLE
), NULL
, 0);
412 case ID_ABOUT_EXPLORER
:
413 explorer_about(_hwnd
);
416 case ID_EXPLORER_FAQ
:
417 launch_file(_hwnd
, TEXT("http://www.sky.franken.de/explorer/"), SW_SHOW
);
422 TCHAR url
[BUFFER_LEN
];
424 if (GetWindowText(_haddressedit
, url
, BUFFER_LEN
))
431 ExecuteCommandbar(NULL
);
435 return 1; // no command handlers in Window::Command()
442 void MainFrameBase::ExecuteCommandbar(LPCTSTR dir
)
444 TCHAR cmd
[BUFFER_LEN
];
446 if (GetWindowText(_hcommandedit
, cmd
, BUFFER_LEN
)) {
447 CONTEXT("ExecuteCommandbar - ShellExecute()");
449 // remove command prompt from 'cmd' string
459 // remove "file://" from directory URL
460 if (!_tcsnicmp(dir
, TEXT("file://"), 7))
464 ///@todo use SHGetFileInfo() with SHGFI_EXETYPE flag to determine EXE type and open console window
466 HINSTANCE hinst
= ShellExecute(_hwnd
, NULL
, p
, NULL
, dir
, SW_SHOWNORMAL
);
468 if ((int)hinst
<= 32)
469 display_error(_hwnd
, GetLastError());
474 int MainFrameBase::Notify(int id
, NMHDR
* pnmh
)
477 // resize children windows when the rebar size changes
480 resize_frame_client();
483 case TVN_GETINFOTIP
: {
484 NMTVGETINFOTIP
* pnmgit
= (NMTVGETINFOTIP
*)pnmh
;
486 if (pnmgit
->lParam
) {
487 const BookmarkNode
& node
= *(BookmarkNode
*)pnmgit
->lParam
;
489 if (node
._type
== BookmarkNode::BMNT_FOLDER
) {
490 // display tooltips for bookmark folders
491 if (!node
._pfolder
->_description
.empty())
492 lstrcpyn(pnmgit
->pszText
, node
._pfolder
->_description
.c_str(), pnmgit
->cchTextMax
);
493 } else if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
494 // display tooltips for bookmark folders
495 String txt
= node
._pbookmark
->_description
;
497 if (!node
._pbookmark
->_url
.empty()) {
501 txt
+= node
._pbookmark
->_url
;
504 lstrcpyn(pnmgit
->pszText
, txt
.c_str(), pnmgit
->cchTextMax
);
510 HTREEITEM hitem
= TreeView_GetSelection(_hsidebar
);
511 LPARAM lparam
= TreeView_GetItemData(_hsidebar
, hitem
);
514 const BookmarkNode
& node
= *(BookmarkNode
*)lparam
;
516 if (node
._type
== BookmarkNode::BMNT_BOOKMARK
) {
517 bool new_window
= GetAsyncKeyState(VK_SHIFT
)<0;
519 go_to(node
._pbookmark
->_url
, new_window
);
529 void MainFrameBase::resize_frame(int cx
, int cy
)
532 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
534 RECT rect
= {0, 0, cx
, cy
};
537 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
541 if (IsWindowVisible(_htoolbar
)) {
542 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
543 WindowRect
rt(_htoolbar
);
544 rect
.top
= rt
.bottom
;
545 // rect.bottom -= rt.bottom;
549 if (IsWindowVisible(_hstatusbar
)) {
550 int parts
[] = {300, 500};
552 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
553 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
554 ClientRect
rt(_hstatusbar
);
555 rect
.bottom
-= rt
.bottom
;
558 if (IsWindowVisible(_haddressedit
) || IsWindowVisible(_hcommandedit
)) {
559 ClientRect
rt(_haddressedit
);
560 rect
.bottom
-= rt
.bottom
;
562 int mid
= (rect
.right
-rect
.left
) / 2; ///@todo use split bar
563 SetWindowPos(_haddressedit
, 0, 0, rect
.bottom
, mid
, rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
564 SetWindowPos(_hcommandedit
, 0, mid
+1, rect
.bottom
, rect
.right
-(mid
+1), rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
567 if (IsWindowVisible(_hsidebar
)) {
568 WindowRect
rt(_hsidebar
);
569 rect
.left
+= rt
.right
-rt
.left
;
571 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
575 void MainFrameBase::resize_frame_client()
577 ClientRect
rect(_hwnd
);
579 resize_frame(rect
.right
, rect
.bottom
);
582 void MainFrameBase::frame_get_clientspace(PRECT prect
)
584 if (!IsIconic(_hwnd
))
585 GetClientRect(_hwnd
, prect
);
589 GetWindowPlacement(_hwnd
, &wp
);
591 prect
->left
= prect
->top
= 0;
592 prect
->right
= wp
.rcNormalPosition
.right
-wp
.rcNormalPosition
.left
-
593 2*(GetSystemMetrics(SM_CXSIZEFRAME
)+GetSystemMetrics(SM_CXEDGE
));
594 prect
->bottom
= wp
.rcNormalPosition
.bottom
-wp
.rcNormalPosition
.top
-
595 2*(GetSystemMetrics(SM_CYSIZEFRAME
)+GetSystemMetrics(SM_CYEDGE
))-
596 GetSystemMetrics(SM_CYCAPTION
)-GetSystemMetrics(SM_CYMENUSIZE
);
599 if (IsWindowVisible(_htoolbar
)) {
600 ClientRect
rt(_htoolbar
);
601 prect
->top
+= rt
.bottom
+2;
604 if (IsWindowVisible(_hstatusbar
)) {
605 ClientRect
rt(_hstatusbar
);
606 prect
->bottom
-= rt
.bottom
;
610 BOOL
MainFrameBase::toggle_fullscreen()
614 if ((_fullscreen
._mode
=!_fullscreen
._mode
)) {
615 GetWindowRect(_hwnd
, &_fullscreen
._orgPos
);
616 _fullscreen
._wasZoomed
= IsZoomed(_hwnd
);
618 Frame_CalcFrameClient(_hwnd
, &rt
);
619 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.left
);
620 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.right
);
622 rt
.left
= _fullscreen
._orgPos
.left
-rt
.left
;
623 rt
.top
= _fullscreen
._orgPos
.top
-rt
.top
;
624 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+_fullscreen
._orgPos
.right
-rt
.right
;
625 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+_fullscreen
._orgPos
.bottom
-rt
.bottom
;
627 MoveWindow(_hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
629 MoveWindow(_hwnd
, _fullscreen
._orgPos
.left
, _fullscreen
._orgPos
.top
,
630 _fullscreen
._orgPos
.right
-_fullscreen
._orgPos
.left
,
631 _fullscreen
._orgPos
.bottom
-_fullscreen
._orgPos
.top
, TRUE
);
633 if (_fullscreen
._wasZoomed
)
634 ShowWindow(_hwnd
, WS_MAXIMIZE
);
637 return _fullscreen
._mode
;
640 void MainFrameBase::fullscreen_move()
643 GetWindowRect(_hwnd
, &pos
);
645 Frame_CalcFrameClient(_hwnd
, &rt
);
646 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.left
);
647 ClientToScreen(_hwnd
, (LPPOINT
)&rt
.right
);
649 rt
.left
= pos
.left
-rt
.left
;
650 rt
.top
= pos
.top
-rt
.top
;
651 rt
.right
= GetSystemMetrics(SM_CXSCREEN
)+pos
.right
-rt
.right
;
652 rt
.bottom
= GetSystemMetrics(SM_CYSCREEN
)+pos
.bottom
-rt
.bottom
;
654 MoveWindow(_hwnd
, rt
.left
, rt
.top
, rt
.right
-rt
.left
, rt
.bottom
-rt
.top
, TRUE
);
658 void MainFrameBase::toggle_child(HWND hwnd
, UINT cmd
, HWND hchild
, int band_idx
)
660 BOOL vis
= IsWindowVisible(hchild
);
662 CheckMenuItem(_menu_info
._hMenuView
, cmd
, vis
?MF_BYCOMMAND
:MF_BYCOMMAND
|MF_CHECKED
);
665 SendMessage(_hwndrebar
, RB_SHOWBAND
, band_idx
, !vis
);
667 ShowWindow(hchild
, vis
? SW_HIDE
: SW_SHOW
);
669 if (_fullscreen
._mode
)
672 resize_frame_client();
675 void MainFrameBase::FillBookmarks()
677 HiddenWindow
hide(_hsidebar
);
678 WindowCanvas
canvas(_hwnd
);
680 TreeView_DeleteAllItems(_hsidebar
);
682 g_Globals
._icon_cache
.get_icon(ICID_FAVORITES
).add_to_imagelist(_himl
, canvas
);
683 g_Globals
._icon_cache
.get_icon(ICID_BOOKMARK
).add_to_imagelist(_himl
, canvas
);
684 ImageList_AddAlphaIcon(_himl
, SmallIcon(IDI_DOT
), GetStockBrush(WHITE_BRUSH
), canvas
);
685 g_Globals
._icon_cache
.get_icon(ICID_FOLDER
).add_to_imagelist(_himl
, canvas
);
686 g_Globals
._icon_cache
.get_icon(ICID_FOLDER
).add_to_imagelist(_himl
, canvas
);
690 tvi
.hParent
= TVI_ROOT
;
691 tvi
.hInsertAfter
= TVI_LAST
;
692 tvi
.item
.mask
= TVIF_TEXT
|TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;
693 ResString
sFavorites(IDS_FAVORITES
);
694 tvi
.item
.pszText
= sFavorites
.str();
695 tvi
.item
.iSelectedImage
= tvi
.item
.iImage
= 0;
697 HTREEITEM hitem_bookmarks
= TreeView_InsertItem(_hsidebar
, &tvi
);
699 g_Globals
._favorites
.fill_tree(_hsidebar
, hitem_bookmarks
, _himl
, canvas
);
701 TreeView_Expand(_hsidebar
, hitem_bookmarks
, TVE_EXPAND
);
705 bool MainFrameBase::go_to(LPCTSTR url
, bool new_window
)
707 ///@todo SDI implementation
715 MDIMainFrame::MDIMainFrame(HWND hwnd
)
718 TBBUTTON mdiBtns
[] = {
719 {0, 0, 0, BTNS_SEP
, {0, 0}, 0, 0},
720 {0, ID_WINDOW_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
721 {1, ID_WINDOW_CASCADE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
722 {2, ID_WINDOW_TILE_HORZ
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0},
723 {3, ID_WINDOW_TILE_VERT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0, 0}, 0, 0}
726 SendMessage(_htoolbar
, TB_ADDBUTTONS
, sizeof(mdiBtns
)/sizeof(TBBUTTON
), (LPARAM
)&mdiBtns
);
728 CLIENTCREATESTRUCT ccs
;
730 ccs
.hWindowMenu
= _hMenuWindow
;
731 ccs
.idFirstChild
= IDW_FIRST_CHILD
;
733 _hmdiclient
= CreateWindowEx(WS_EX_CLIENTEDGE
, TEXT("MDICLIENT"), NULL
,
734 WS_CHILD
|WS_CLIPCHILDREN
|WS_VSCROLL
|WS_HSCROLL
|WS_VISIBLE
|WS_BORDER
,
736 hwnd
, 0, g_Globals
._hInstance
, &ccs
);
738 TBBUTTON extraBtns
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
741 _hextrabar
= CreateToolbarEx(hwnd
,
742 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
743 WS_CHILD
|TBSTYLE_FLAT
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,
744 IDW_EXTRABAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, NULL
, 0,
745 16, 15, 16, 15, sizeof(TBBUTTON
));
747 _hextrabar
= CreateToolbarEx(hwnd
,
748 WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
,CCS_NODIVIDER
|
749 IDW_EXTRABAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, &extraBtns
, 1,
750 16, 13, 16, 13, sizeof(TBBUTTON
));
753 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_EXTRA_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
756 extraBtns
.fsStyle
= BTNS_BUTTON
;
759 // insert unix file system button
760 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("/\0"));
761 extraBtns
.idCommand
= ID_DRIVE_UNIX_FS
;
762 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
765 // insert explorer window button
766 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Explore\0"));
767 extraBtns
.idCommand
= ID_DRIVE_DESKTOP
;
768 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
770 // insert shell namespace button
771 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Shell\0"));
772 extraBtns
.idCommand
= ID_DRIVE_SHELL_NS
;
773 extraBtns
.iBitmap
= 6;
774 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
776 // insert web control button
777 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Web\0"));
778 extraBtns
.idCommand
= ID_WEB_WINDOW
;
779 extraBtns
.iBitmap
= 7;
780 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
782 if ((HIWORD(GetVersion())>>14) == W_VER_NT
) {
783 // insert NT object namespace button
784 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("NT Obj\0"));
785 extraBtns
.idCommand
= ID_DRIVE_NTOBJ_NS
;
786 extraBtns
.iBitmap
= 8;
787 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
790 // insert Registry button
791 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("Reg.\0"));
792 extraBtns
.idCommand
= ID_DRIVE_REGISTRY
;
793 extraBtns
.iBitmap
= 9;
794 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
797 // insert FAT direct file system access button
798 extraBtns
.iString
= SendMessage(_hextrabar
, TB_ADDSTRING
, 0, (LPARAM
)TEXT("FAT\0"));
799 extraBtns
.idCommand
= ID_DRIVE_FAT
;
800 extraBtns
.iBitmap
= 10;
801 SendMessage(_hextrabar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&extraBtns
);
805 TBBUTTON drivebarBtn
= {0, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0, 0}, 0, 0};
810 _hdrivebar
= CreateToolbarEx(hwnd
,
811 CCS_NOPARENTALIGN
|CCS_NORESIZE
|CCS_NODIVIDER
|
812 WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
|CCS_NOMOVEY
|TBSTYLE_LIST
,
813 IDW_DRIVEBAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, NULL
, 0,
814 16, 15, 16, 15, sizeof(TBBUTTON
));
816 _hdrivebar
= CreateToolbarEx(hwnd
,
817 WS_CHILD
|WS_VISIBLE
|CCS_NOMOVEY
|TBSTYLE_LIST
|CCS_NODIVIDER
,
818 IDW_DRIVEBAR
, 2, g_Globals
._hInstance
, IDB_DRIVEBAR
, &drivebarBtn
, 1,
819 16, 13, 16, 13, sizeof(TBBUTTON
));
823 CheckMenuItem(_menu_info
._hMenuView
, ID_VIEW_DRIVE_BAR
, MF_BYCOMMAND
|MF_CHECKED
);
827 GetLogicalDriveStrings(BUFFER_LEN
, _drives
);
829 // register windows drive root strings
830 SendMessage(_hdrivebar
, TB_ADDSTRING
, 0, (LPARAM
)_drives
);
832 drivebarBtn
.fsStyle
= BTNS_BUTTON
;
833 drivebarBtn
.idCommand
= ID_DRIVE_FIRST
;
835 for(p
=_drives
; *p
; ) {
836 switch(GetDriveType(p
)) {
837 case DRIVE_REMOVABLE
: drivebarBtn
.iBitmap
= 1; break;
838 case DRIVE_CDROM
: drivebarBtn
.iBitmap
= 3; break;
839 case DRIVE_REMOTE
: drivebarBtn
.iBitmap
= 4; break;
840 case DRIVE_RAMDISK
: drivebarBtn
.iBitmap
= 5; break;
841 default:/*DRIVE_FIXED*/ drivebarBtn
.iBitmap
= 2;
844 SendMessage(_hdrivebar
, TB_INSERTBUTTON
, INT_MAX
, (LPARAM
)&drivebarBtn
);
845 ++drivebarBtn
.idCommand
;
846 ++drivebarBtn
.iString
;
854 int btn_hgt
= HIWORD(SendMessage(_htoolbar
, TB_GETBUTTONSIZE
, 0, 0));
856 REBARBANDINFO rbBand
;
858 rbBand
.cbSize
= sizeof(REBARBANDINFO
);
859 rbBand
.fMask
= RBBIM_TEXT
|RBBIM_STYLE
|RBBIM_CHILD
|RBBIM_CHILDSIZE
|RBBIM_SIZE
;
860 #ifndef RBBS_HIDETITLE // missing in MinGW headers as of 25.02.2004
861 #define RBBS_HIDETITLE 0x400
863 rbBand
.fStyle
= RBBS_CHILDEDGE
|RBBS_GRIPPERALWAYS
|RBBS_HIDETITLE
;
865 rbBand
.lpText
= TEXT("Extras");
866 rbBand
.hwndChild
= _hextrabar
;
867 rbBand
.cxMinChild
= 0;
868 rbBand
.cyMinChild
= btn_hgt
;
870 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)-1, (LPARAM
)&rbBand
);
873 rbBand
.fStyle
|= RBBS_BREAK
;
874 rbBand
.lpText
= TEXT("Drives");
875 rbBand
.hwndChild
= _hdrivebar
;
876 rbBand
.cxMinChild
= 0;
877 rbBand
.cyMinChild
= btn_hgt
;
879 SendMessage(_hwndrebar
, RB_INSERTBAND
, (WPARAM
)-1, (LPARAM
)&rbBand
);
885 HWND
MDIMainFrame::Create()
887 HMENU hMenuFrame
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(IDM_MDIFRAME
));
889 return Window::Create(WINDOW_CREATOR(MDIMainFrame
), 0,
890 (LPCTSTR
)(int)g_Globals
._hframeClass
, ResString(IDS_TITLE
), WS_OVERLAPPEDWINDOW
,
891 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
892 0/*hwndDesktop*/, hMenuFrame
);
895 HWND
MDIMainFrame::Create(LPCTSTR path
, int mode
)
897 HWND hFrame
= Create();
901 ShowWindow(hFrame
, SW_SHOW
);
903 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
906 pMainFrame
->CreateChild(path
, mode
);
911 HWND
MDIMainFrame::Create(LPCITEMIDLIST pidl
, int mode
)
913 HWND hFrame
= Create();
917 ShowWindow(hFrame
, SW_SHOW
);
919 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
922 pMainFrame
->CreateChild(pidl
, mode
);
928 ChildWindow
* MDIMainFrame::CreateChild(LPCTSTR path
, int mode
)
930 return reinterpret_cast<ChildWindow
*>(SendMessage(_hwnd
, PM_OPEN_WINDOW
, mode
, (LPARAM
)path
));
933 ChildWindow
* MDIMainFrame::CreateChild(LPCITEMIDLIST pidl
, int mode
)
935 return reinterpret_cast<ChildWindow
*>(SendMessage(_hwnd
, PM_OPEN_WINDOW
, mode
|OWM_PIDL
, (LPARAM
)pidl
));
939 BOOL
MDIMainFrame::TranslateMsg(MSG
* pmsg
)
941 if (_hmdiclient
&& TranslateMDISysAccel(_hmdiclient
, pmsg
))
944 return super::TranslateMsg(pmsg
);
947 LRESULT
MDIMainFrame::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
950 case PM_OPEN_WINDOW
: {
951 CONTEXT("MDIMainFrame PM_OPEN_WINDOW");
953 TCHAR buffer
[MAX_PATH
];
955 ShellPath shell_path
= DesktopFolderPath();
958 if (wparam
& OWM_PIDL
) {
959 // take over PIDL from lparam
960 shell_path
.assign((LPCITEMIDLIST
)lparam
); // create as "rooted" window
961 FileSysShellPath
fsp(shell_path
);
965 LOG(FmtString(TEXT("MDIMainFrame PM_OPEN_WINDOW: path=%s"), path
));
966 lstrcpy(buffer
, path
);
970 // take over path from lparam
971 path
= (LPCTSTR
)lparam
;
972 shell_path
= path
; // create as "rooted" window
975 ///@todo read paths and window placements from registry
976 if (!GetCurrentDirectory(MAX_PATH
, buffer
))
982 if (path
&& _tcsstr(path
, TEXT("://"))) { // "http://...", "ftp://", ...
983 OBJ_CONTEXT("create WebChild window", path
);
985 return (LRESULT
)GET_WINDOW(ChildWindow
, create_webchildwindow(WebChildWndInfo(_hmdiclient
, path
)));
987 OBJ_CONTEXT("create ShellChildWndInfo", path
);
989 // Shell Namespace as default view
990 ShellChildWndInfo
create_info(_hmdiclient
, path
, shell_path
);
992 if (wparam
& OWM_ROOTED
)
993 create_info
._root_shell_path
= shell_path
;
995 create_info
._root_shell_path
= DesktopFolderPath(); //SpecialFolderPath(CSIDL_DRIVES, _hwnd);
997 create_info
._pos
.showCmd
= wparam
&OWM_SEPARATE
? SW_SHOWNORMAL
: SW_SHOWMAXIMIZED
;
998 create_info
._pos
.rcNormalPosition
.left
= CW_USEDEFAULT
;
999 create_info
._pos
.rcNormalPosition
.top
= CW_USEDEFAULT
;
1000 create_info
._pos
.rcNormalPosition
.right
= CW_USEDEFAULT
;
1001 create_info
._pos
.rcNormalPosition
.bottom
= CW_USEDEFAULT
;
1003 create_info
._open_mode
= wparam
;
1005 // FileChildWindow::create(_hmdiclient, create_info);
1006 return (LRESULT
)MDIShellBrowserChild::create(create_info
);
1008 return TRUE
;} // success
1013 if (super::ProcessMessage(nmsg
, wparam
, lparam
, &res
))
1016 return DefFrameProc(_hwnd
, _hmdiclient
, nmsg
, wparam
, lparam
);
1023 int MDIMainFrame::Command(int id
, int code
)
1025 CONTEXT("MDIMainFrame::Command()");
1027 HWND hwndClient
= (HWND
) SendMessage(_hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1030 if (SendMessage(hwndClient
, PM_DISPATCH_COMMAND
, MAKELONG(id
,code
), 0))
1034 if (id
>=ID_DRIVE_FIRST
&& id
<=ID_DRIVE_FIRST
+0xFF) {
1035 TCHAR drv
[_MAX_DRIVE
], path
[MAX_PATH
];
1036 LPCTSTR root
= _drives
;
1038 for(int i
=id
-ID_DRIVE_FIRST
; i
--; root
++)
1042 if (activate_drive_window(root
))
1045 _tsplitpath_s(root
, drv
, COUNTOF(drv
), NULL
, 0, NULL
, 0, NULL
, 0);
1047 if (!SetCurrentDirectory(drv
)) {
1048 display_error(_hwnd
, GetLastError());
1052 GetCurrentDirectory(MAX_PATH
, path
); ///@todo store last directory per drive
1054 FileChildWindow::create(FileChildWndInfo(_hmdiclient
, path
));
1061 case ID_WINDOW_NEW
: {
1062 TCHAR path
[MAX_PATH
];
1064 GetCurrentDirectory(MAX_PATH
, path
);
1066 FileChildWindow::create(FileChildWndInfo(_hmdiclient
, path
));
1069 case ID_WINDOW_CASCADE
:
1070 SendMessage(_hmdiclient
, WM_MDICASCADE
, 0, 0);
1073 case ID_WINDOW_TILE_HORZ
:
1074 SendMessage(_hmdiclient
, WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
1077 case ID_WINDOW_TILE_VERT
:
1078 SendMessage(_hmdiclient
, WM_MDITILE
, MDITILE_VERTICAL
, 0);
1081 case ID_WINDOW_ARRANGE
:
1082 SendMessage(_hmdiclient
, WM_MDIICONARRANGE
, 0, 0);
1085 case ID_VIEW_EXTRA_BAR
:
1086 toggle_child(_hwnd
, id
, _hextrabar
, 1);
1090 case ID_VIEW_DRIVE_BAR
:
1091 toggle_child(_hwnd
, id
, _hdrivebar
, 2);
1096 case ID_DRIVE_UNIX_FS
: {
1097 TCHAR path
[MAX_PATH
];
1098 FileChildWindow
* child
;
1100 getcwd(path
, COUNTOF(path
));
1102 if (activate_child_window(TEXT("unixfs")))
1105 FileChildWindow::create(_hmdiclient
, FileChildWndInfo(path
));
1109 case ID_DRIVE_DESKTOP
: {
1110 TCHAR path
[MAX_PATH
];
1112 if (activate_child_window(TEXT("Desktop")))
1115 GetCurrentDirectory(MAX_PATH
, path
);
1117 MDIShellBrowserChild::create(ShellChildWndInfo(_hmdiclient
, path
, DesktopFolderPath()));
1120 case ID_DRIVE_SHELL_NS
: {
1121 TCHAR path
[MAX_PATH
];
1122 GetCurrentDirectory(MAX_PATH
, path
);
1124 if (activate_child_window(TEXT("Shell")))
1127 FileChildWindow::create(ShellChildWndInfo(_hmdiclient
, path
, DesktopFolderPath()));
1130 case ID_DRIVE_NTOBJ_NS
: {
1131 if (activate_child_window(TEXT("NTOBJ")))
1134 FileChildWindow::create(NtObjChildWndInfo(_hmdiclient
, TEXT("\\")));
1137 case ID_DRIVE_REGISTRY
: {
1138 if (activate_child_window(TEXT("Registry")))
1141 FileChildWindow::create(RegistryChildWndInfo(_hmdiclient
, TEXT("\\")));
1144 case ID_DRIVE_FAT
: {
1146 ///@todo prompt for image file
1148 if (activate_child_window(TEXT("FAT")))
1151 FileChildWindow::create(FATChildWndInfo(_hmdiclient
, TEXT("FAT Image"))); //@@
1156 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://localhost")));
1158 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://www.reactos.org")));
1162 case ID_EXPLORER_FAQ
:
1163 create_webchildwindow(WebChildWndInfo(_hmdiclient
, TEXT("http://www.sky.franken.de/explorer/")));
1167 MainFrameBase::Create(ExplorerCmd());
1170 case IDW_COMMANDBAR
:
1172 TCHAR url
[BUFFER_LEN
];
1175 if (GetWindowText(_haddressedit
, url
, BUFFER_LEN
))
1180 ExecuteCommandbar(dir
);
1184 ///@todo There are even more menu items!
1187 if (super::Command(id
, code
) == 0)
1190 return DefFrameProc(_hwnd
, _hmdiclient
, WM_COMMAND
, MAKELONG(id
,code
), 0);
1197 void MDIMainFrame::frame_get_clientspace(PRECT prect
)
1199 super::frame_get_clientspace(prect
);
1202 if (IsWindowVisible(_hdrivebar
)) {
1203 ClientRect
rt(_hdrivebar
);
1204 prect
->top
+= rt
.bottom
+2;
1209 void MDIMainFrame::resize_frame(int cx
, int cy
)
1212 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1214 RECT rect
= {0, 0, cx
, cy
};
1217 int height
= SendMessage(_hwndrebar
, RB_GETBARHEIGHT
, 0, 0);
1221 if (IsWindowVisible(_htoolbar
)) {
1222 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
1223 WindowRect
rt(_htoolbar
);
1224 rect
.top
= rt
.bottom
;
1225 // rect.bottom -= rt.bottom;
1228 if (IsWindowVisible(_hextrabar
)) {
1229 SendMessage(_hextrabar
, WM_SIZE
, 0, 0);
1230 WindowRect
rt(_hextrabar
);
1231 int new_top
= --rect
.top
+ rt
.bottom
;
1232 MoveWindow(_hextrabar
, 0, rect
.top
, rt
.right
, new_top
, TRUE
);
1234 // rect.bottom -= rt.bottom;
1238 if (IsWindowVisible(_hdrivebar
)) {
1239 SendMessage(_hdrivebar
, WM_SIZE
, 0, 0);
1240 WindowRect
rt(_hdrivebar
);
1241 int new_top
= --rect
.top
+ rt
.bottom
;
1242 MoveWindow(_hdrivebar
, 0, rect
.top
, rt
.right
, new_top
, TRUE
);
1244 // rect.bottom -= rt.bottom;
1249 if (IsWindowVisible(_hstatusbar
)) {
1250 int parts
[] = {300, 500};
1252 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
1253 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1254 ClientRect
rt(_hstatusbar
);
1255 rect
.bottom
-= rt
.bottom
;
1258 if (IsWindowVisible(_haddressedit
) || IsWindowVisible(_hcommandedit
)) {
1259 ClientRect
rt(_haddressedit
);
1260 rect
.bottom
-= rt
.bottom
;
1262 int mid
= (rect
.right
-rect
.left
) / 2; ///@todo use split bar
1263 SetWindowPos(_haddressedit
, 0, 0, rect
.bottom
, mid
, rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
1264 SetWindowPos(_hcommandedit
, 0, mid
+1, rect
.bottom
, rect
.right
-(mid
+1), rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
1267 if (IsWindowVisible(_hsidebar
)) {
1268 WindowRect
rt(_hsidebar
);
1269 rect
.left
+= rt
.right
-rt
.left
;
1271 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
1274 MoveWindow(_hmdiclient
, rect
.left
-1, rect
.top
-1, rect
.right
-rect
.left
+1, rect
.bottom
-rect
.top
+1, TRUE
);
1277 bool MDIMainFrame::activate_drive_window(LPCTSTR path
)
1279 TCHAR drv1
[_MAX_DRIVE
], drv2
[_MAX_DRIVE
];
1282 _tsplitpath_s(path
, drv1
, COUNTOF(drv1
), NULL
, 0, NULL
, 0, NULL
, 0);
1284 // search for a already open window for the same drive
1285 for(child_wnd
=::GetNextWindow(_hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=::GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1286 FileChildWindow
* child
= (FileChildWindow
*) SendMessage(child_wnd
, PM_GET_FILEWND_PTR
, 0, 0);
1289 _tsplitpath_s(child
->get_root()._path
, drv2
, COUNTOF(drv2
), NULL
, 0, NULL
, 0, NULL
, 0);
1291 if (!lstrcmpi(drv2
, drv1
)) {
1292 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1294 if (IsMinimized(child_wnd
))
1295 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1305 bool MDIMainFrame::activate_child_window(LPCTSTR filesys
)
1309 // search for a already open window of the given file system name
1310 for(child_wnd
=::GetNextWindow(_hmdiclient
,GW_CHILD
); child_wnd
; child_wnd
=::GetNextWindow(child_wnd
, GW_HWNDNEXT
)) {
1311 FileChildWindow
* child
= (FileChildWindow
*) SendMessage(child_wnd
, PM_GET_FILEWND_PTR
, 0, 0);
1314 if (!lstrcmpi(child
->get_root()._fs
, filesys
)) {
1315 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1317 if (IsMinimized(child_wnd
))
1318 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1323 ShellBrowser
* shell_child
= (ShellBrowser
*) SendMessage(child_wnd
, PM_GET_SHELLBROWSER_PTR
, 0, 0);
1326 if (!lstrcmpi(shell_child
->get_root()._fs
, filesys
)) {
1327 SendMessage(_hmdiclient
, WM_MDIACTIVATE
, (WPARAM
)child_wnd
, 0);
1329 if (IsMinimized(child_wnd
))
1330 ShowWindow(child_wnd
, SW_SHOWNORMAL
);
1341 bool MDIMainFrame::go_to(LPCTSTR url
, bool new_window
)
1344 HWND hwndClient
= (HWND
) SendMessage(_hmdiclient
, WM_MDIGETACTIVE
, 0, 0);
1347 if (SendMessage(hwndClient
, PM_JUMP_TO_URL
, 0, (LPARAM
)url
))
1351 if (CreateChild(url
))
1354 return super::go_to(url
, new_window
);
1360 SDIMainFrame::SDIMainFrame(HWND hwnd
)
1363 _split_pos
= DEFAULT_SPLIT_POS
;
1364 _last_split
= DEFAULT_SPLIT_POS
;
1366 /* wait for PM_OPEN_WINDOW message before creating a shell view
1367 update_shell_browser();*/
1370 HWND
SDIMainFrame::Create()
1372 HMENU hMenuFrame
= LoadMenu(g_Globals
._hInstance
, MAKEINTRESOURCE(IDM_SDIFRAME
));
1374 return Window::Create(WINDOW_CREATOR(SDIMainFrame
), 0,
1375 (LPCTSTR
)(int)g_Globals
._hframeClass
, ResString(IDS_TITLE
), WS_OVERLAPPEDWINDOW
,
1376 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
1377 0/*hwndDesktop*/, hMenuFrame
);
1380 HWND
SDIMainFrame::Create(LPCITEMIDLIST pidl
, int mode
)
1382 HWND hFrame
= Create();
1386 ShowWindow(hFrame
, SW_SHOW
);
1388 SDIMainFrame
* pFrame
= GET_WINDOW(SDIMainFrame
, hFrame
);
1391 pFrame
->jump_to(pidl
, mode
);
1396 HWND
SDIMainFrame::Create(LPCTSTR path
, int mode
)
1398 HWND hFrame
= Create();
1402 ShowWindow(hFrame
, SW_SHOW
);
1404 MDIMainFrame
* pMainFrame
= GET_WINDOW(MDIMainFrame
, hFrame
);
1407 pMainFrame
->CreateChild(path
, mode
);
1412 LRESULT
SDIMainFrame::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
1416 resize_frame(LOWORD(lparam
), HIWORD(lparam
));
1420 PaintCanvas
canvas(_hwnd
);
1423 ClientRect
rt(_hwnd
);
1424 rt
.left
= _split_pos
-SPLIT_WIDTH
/2;
1425 rt
.right
= _split_pos
+SPLIT_WIDTH
/2+1;
1428 WindowRect
right_rect(_right_hwnd
);
1429 ScreenToClient(_hwnd
, &right_rect
);
1430 rt
.top
= right_rect
.top
;
1431 rt
.bottom
= right_rect
.bottom
;
1434 HBRUSH lastBrush
= SelectBrush(canvas
, GetStockBrush(COLOR_SPLITBAR
));
1435 Rectangle(canvas
, rt
.left
, rt
.top
-1, rt
.right
, rt
.bottom
+1);
1436 SelectObject(canvas
, lastBrush
);
1442 if (LOWORD(lparam
) == HTCLIENT
) {
1445 ScreenToClient(_hwnd
, &pt
);
1447 if (pt
.x
>=_split_pos
-SPLIT_WIDTH
/2 && pt
.x
<_split_pos
+SPLIT_WIDTH
/2+1) {
1448 SetCursor(LoadCursor(0, IDC_SIZEWE
));
1454 case WM_LBUTTONDOWN
:
1456 int x
= GET_X_LPARAM(lparam
);
1458 ClientRect
rt(_hwnd
);
1460 if (x
>=_split_pos
-SPLIT_WIDTH
/2 && x
<_split_pos
+SPLIT_WIDTH
/2+1) {
1461 _last_split
= _split_pos
;
1468 if (GetCapture() == _hwnd
)
1473 if (wparam
== VK_ESCAPE
)
1474 if (GetCapture() == _hwnd
) {
1475 _split_pos
= _last_split
;
1479 SetCursor(LoadCursor(0, IDC_ARROW
));
1484 if (GetCapture() == _hwnd
) {
1485 int x
= GET_X_LPARAM(lparam
);
1487 ClientRect
rt(_hwnd
);
1489 if (x
>=0 && x
<rt
.right
) {
1492 rt
.left
= x
-SPLIT_WIDTH
/2;
1493 rt
.right
= x
+SPLIT_WIDTH
/2+1;
1494 InvalidateRect(_hwnd
, &rt
, FALSE
);
1495 UpdateWindow(_left_hwnd
);
1496 UpdateWindow(_hwnd
);
1497 UpdateWindow(_right_hwnd
);
1502 case PM_OPEN_WINDOW
: {
1503 CONTEXT("SDIMainFrame PM_OPEN_WINDOW");
1505 TCHAR buffer
[MAX_PATH
];
1507 ShellPath shell_path
= DesktopFolderPath();
1510 if (wparam
& OWM_PIDL
) {
1511 // take over PIDL from lparam
1512 shell_path
.assign((LPCITEMIDLIST
)lparam
); // create as "rooted" window
1513 FileSysShellPath
fsp(shell_path
);
1517 LOG(FmtString(TEXT("SDIMainFrame PM_OPEN_WINDOW: path=%s"), path
));
1518 lstrcpy(buffer
, path
);
1522 // take over path from lparam
1523 path
= (LPCTSTR
)lparam
;
1524 shell_path
= path
; // create as "rooted" window
1527 ///@todo read paths and window placements from registry
1528 if (!GetCurrentDirectory(MAX_PATH
, buffer
))
1535 if (wparam
& OWM_ROOTED
)
1536 _shellpath_info
._root_shell_path
= shell_path
;
1538 _shellpath_info
._root_shell_path
= DesktopFolderPath(); //SpecialFolderPath(CSIDL_DRIVES, _hwnd);
1540 jump_to(shell_path
, wparam
); //@todo content of 'path' not used any more
1541 return TRUE
;} // success
1544 return super::WndProc(nmsg
, wparam
, lparam
);
1550 int SDIMainFrame::Command(int id
, int code
)
1554 MainFrameBase::Create(ExplorerCmd(_url
, true));
1557 case IDW_COMMANDBAR
:
1559 ExecuteCommandbar(_url
);
1563 return super::Command(id
, code
);
1569 void SDIMainFrame::resize_frame(int cx
, int cy
)
1572 return; // avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1574 RECT rect
= {0, 0, cx
, cy
};
1577 int height
= ClientRect(_hwndrebar
).bottom
;
1581 if (IsWindowVisible(_htoolbar
)) {
1582 SendMessage(_htoolbar
, WM_SIZE
, 0, 0);
1583 WindowRect
rt(_htoolbar
);
1584 rect
.top
= rt
.bottom
;
1585 // rect.bottom -= rt.bottom;
1589 if (IsWindowVisible(_hstatusbar
)) {
1590 int parts
[] = {300, 500};
1592 SendMessage(_hstatusbar
, WM_SIZE
, 0, 0);
1593 SendMessage(_hstatusbar
, SB_SETPARTS
, 2, (LPARAM
)&parts
);
1594 ClientRect
rt(_hstatusbar
);
1595 rect
.bottom
-= rt
.bottom
;
1598 if (IsWindowVisible(_haddressedit
) || IsWindowVisible(_hcommandedit
)) {
1599 ClientRect
rt(_haddressedit
);
1600 rect
.bottom
-= rt
.bottom
;
1602 int mid
= (rect
.right
-rect
.left
) / 2; ///@todo use split bar
1603 SetWindowPos(_haddressedit
, 0, 0, rect
.bottom
, mid
, rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
1604 SetWindowPos(_hcommandedit
, 0, mid
+1, rect
.bottom
, rect
.right
-(mid
+1), rt
.bottom
, SWP_NOACTIVATE
|SWP_NOZORDER
);
1607 if (IsWindowVisible(_hsidebar
)) {
1608 WindowRect
rt(_hsidebar
);
1609 rect
.left
+= rt
.right
-rt
.left
;
1611 SetWindowPos(_hsidebar
, 0, -1, rect
.top
-1, rt
.right
-rt
.left
, rect
.bottom
-rect
.top
+1, SWP_NOACTIVATE
|SWP_NOZORDER
);
1619 void SDIMainFrame::resize_children()
1621 HDWP hdwp
= BeginDeferWindowPos(2);
1623 int cx
= _clnt_rect
.left
;
1626 cx
= _split_pos
+ SPLIT_WIDTH
/2;
1628 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
);
1635 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
);
1637 EndDeferWindowPos(hdwp
);
1640 void SDIMainFrame::update_clnt_rect()
1642 ClientRect
rect(_hwnd
);
1644 resize_frame(rect
.right
, rect
.bottom
);
1647 void SDIMainFrame::update_shell_browser()
1649 int split_pos
= DEFAULT_SPLIT_POS
;
1651 if (_shellBrowser
.get()) {
1652 split_pos
= _split_pos
;
1653 delete _shellBrowser
.release();
1656 // create explorer treeview
1657 if (_shellpath_info
._open_mode
& OWM_EXPLORE
) {
1659 ClientRect
rect(_hwnd
);
1661 _left_hwnd
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_TREEVIEW
, NULL
,
1662 WS_CHILD
|WS_TABSTOP
|WS_VISIBLE
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
|TVS_NOTOOLTIPS
|TVS_SHOWSELALWAYS
,
1663 0, rect
.top
, split_pos
-SPLIT_WIDTH
/2, rect
.bottom
-rect
.top
,
1664 _hwnd
, (HMENU
)IDC_FILETREE
, g_Globals
._hInstance
, 0);
1666 // display tree window as long as the shell view is not yet visible
1667 resize_frame(rect
.right
, rect
.bottom
);
1668 MoveWindow(_left_hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
, TRUE
);
1672 DestroyWindow(_left_hwnd
);
1677 _shellBrowser
= auto_ptr
<ShellBrowser
>(new ShellBrowser(_hwnd
, _hwnd
, _left_hwnd
, _right_hwnd
,
1678 _shellpath_info
, this, _cm_ifs
));
1681 _shellBrowser
->Init();
1683 // update _clnt_rect and set size of new created shell view windows
1687 void SDIMainFrame::entry_selected(Entry
* entry
)
1690 _shellBrowser
->select_folder(entry
, false);
1692 _shellBrowser
->UpdateFolderView(entry
->get_shell_folder());
1694 // set size of new created shell view windows
1697 TCHAR path
[MAX_PATH
];
1699 if (entry
->get_path(path
, COUNTOF(path
))) {
1703 url
.printf(TEXT("shell://%s"), path
);
1705 url
.printf(TEXT("file://%s"), path
);
1711 void SDIMainFrame::set_url(LPCTSTR url
)
1716 SetWindowText(_haddressedit
, url
); //SendMessage(_hwndFrame, PM_URL_CHANGED, 0, (LPARAM)url);
1720 void SDIMainFrame::jump_to(LPCTSTR path
, int mode
)
1722 if (_shellBrowser.get() && (_shellpath_info._open_mode&~OWM_PIDL)==(mode&~OWM_PIDL)) {
1723 _shellBrowser->jump_to(path);
1725 _shellpath_info._shell_path = path;
1727 _shellpath_info
._open_mode
= mode
;
1728 _shellpath_info
._shell_path
= path
;
1730 update_shell_browser();
1734 void SDIMainFrame::jump_to(LPCITEMIDLIST path
, int mode
)
1736 if (_shellBrowser
.get() && (_shellpath_info
._open_mode
&~OWM_PIDL
)==(mode
&~OWM_PIDL
)) {
1737 ShellPath shell_path
= path
;
1739 _shellBrowser
->jump_to(shell_path
);
1741 _shellpath_info
._shell_path
= shell_path
;
1743 _shellpath_info
._open_mode
= mode
;
1744 _shellpath_info
._shell_path
= path
;
1746 update_shell_browser();