1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Copyright 2003, 2004, 2005 Martin Fuchs
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck  *
9c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12c2c66affSColin Finck  * Lesser General Public License for more details.
13c2c66affSColin Finck  *
14c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17c2c66affSColin Finck  */
18c2c66affSColin Finck 
19c2c66affSColin Finck 
20c2c66affSColin Finck  //
21c2c66affSColin Finck  // Explorer clone
22c2c66affSColin Finck  //
23c2c66affSColin Finck  // mainframe.cpp
24c2c66affSColin Finck  //
25c2c66affSColin Finck  // Martin Fuchs, 23.07.2003
26c2c66affSColin Finck  //
27c2c66affSColin Finck 
28c2c66affSColin Finck 
29c2c66affSColin Finck #include <precomp.h>
30c2c66affSColin Finck 
31c2c66affSColin Finck /* We can't include webchild.h here - otherwise MinGW produces errors like: "multiple definition of `QACONTAINERFLAGS'"
32c2c66affSColin Finck #include "webchild.h"
33c2c66affSColin Finck */
34c2c66affSColin Finck extern HWND create_webchildwindow(const WebChildWndInfo& info);
35c2c66affSColin Finck 
36c2c66affSColin Finck #include "../dialogs/settings.h"	// for MdiSdiDlg
37c2c66affSColin Finck 
38c2c66affSColin Finck //#define _NO_REBAR
39c2c66affSColin Finck 
Create(const ExplorerCmd & cmd)40c2c66affSColin Finck HWND MainFrameBase::Create(const ExplorerCmd& cmd)
41c2c66affSColin Finck {
42c2c66affSColin Finck 	HWND hFrame;
43c2c66affSColin Finck 
44c2c66affSColin Finck #ifndef _NO_MDI
45c2c66affSColin Finck 	if (cmd._mdi)
46c2c66affSColin Finck 		hFrame = MDIMainFrame::Create();
47c2c66affSColin Finck 	else
48c2c66affSColin Finck #endif
49c2c66affSColin Finck 		hFrame = SDIMainFrame::Create();
50c2c66affSColin Finck 
51c2c66affSColin Finck 	if (hFrame) {
52c2c66affSColin Finck 		HWND hwndOld = g_Globals._hMainWnd;
53c2c66affSColin Finck 
54c2c66affSColin Finck 		g_Globals._hMainWnd = hFrame;
55c2c66affSColin Finck 
56c2c66affSColin Finck 		if (hwndOld)
57c2c66affSColin Finck 			DestroyWindow(hwndOld);
58c2c66affSColin Finck 
59c2c66affSColin Finck 		ShowWindow(hFrame, cmd._cmdShow);
60c2c66affSColin Finck 		UpdateWindow(hFrame);
61c2c66affSColin Finck 
62c2c66affSColin Finck 		 // Open the first child window after initializing the application
63c2c66affSColin Finck 		if (cmd.IsValidPath()) {
64c2c66affSColin Finck 			 // We use the static s_path variable to store the path string in order
65c2c66affSColin Finck 			 // to avoid accessing prematurely freed memory in the PostMessage handlers.
66c2c66affSColin Finck 			static String s_path = cmd._path;
67c2c66affSColin Finck 
68c2c66affSColin Finck 			PostMessage(hFrame, PM_OPEN_WINDOW, cmd._flags, (LPARAM)(LPCTSTR)s_path);
69c2c66affSColin Finck 		} else
70c2c66affSColin Finck 			PostMessage(hFrame, PM_OPEN_WINDOW, OWM_EXPLORE|OWM_DETAILS, 0);
71c2c66affSColin Finck 	}
72c2c66affSColin Finck 
73c2c66affSColin Finck 	return hFrame;
74c2c66affSColin Finck }
75c2c66affSColin Finck 
76c2c66affSColin Finck 
OpenShellFolders(LPIDA pida,HWND hFrameWnd)77c2c66affSColin Finck int MainFrameBase::OpenShellFolders(LPIDA pida, HWND hFrameWnd)
78c2c66affSColin Finck {
79c2c66affSColin Finck 	int cnt = 0;
80c2c66affSColin Finck 
81c2c66affSColin Finck 	LPCITEMIDLIST parent_pidl = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
82c2c66affSColin Finck 	ShellFolder folder(parent_pidl);
83c2c66affSColin Finck 	LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): parent_pidl=%s"), (LPCTSTR)FileSysShellPath(parent_pidl)));
84c2c66affSColin Finck 
85c2c66affSColin Finck 	for(int i=pida->cidl; i>0; --i) {
86c2c66affSColin Finck 		LPCITEMIDLIST pidl = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[i]);
87c2c66affSColin Finck 
88c2c66affSColin Finck 		SFGAOF attribs = SFGAO_FOLDER;
89c2c66affSColin Finck 		HRESULT hr = folder->GetAttributesOf(1, &pidl, &attribs);
90c2c66affSColin Finck 
91c2c66affSColin Finck 		if (SUCCEEDED(hr))
92c2c66affSColin Finck 			if (attribs & SFGAO_FOLDER) {
93c2c66affSColin Finck 				try {
94c2c66affSColin Finck 					XMLPos explorer_options = g_Globals.get_cfg("general/explorer");
95c2c66affSColin Finck 
96c2c66affSColin Finck 					bool mdi = XMLBool(explorer_options, "mdi", true);
97c2c66affSColin Finck 					bool separateFolders = XMLBool(explorer_options, "separate-folders", false);
98c2c66affSColin Finck 
99c2c66affSColin Finck 					ShellPath pidl_abs = ShellPath(pidl).create_absolute_pidl(parent_pidl);
100c2c66affSColin Finck 					LOG(FmtString(TEXT("MainFrameBase::OpenShellFolders(): pidl_abs=%s"), (LPCTSTR)FileSysShellPath(pidl_abs)));
101c2c66affSColin Finck 
102c2c66affSColin Finck 					if (hFrameWnd && (mdi || !separateFolders)) {
103c2c66affSColin Finck 						int flags = OWM_PIDL;
104c2c66affSColin Finck 
105c2c66affSColin Finck 						if (separateFolders)
106c2c66affSColin Finck 							flags |= OWM_SEPARATE;
107c2c66affSColin Finck 
108c2c66affSColin Finck 						if (SendMessage(hFrameWnd, PM_OPEN_WINDOW, flags, (LPARAM)(LPCITEMIDLIST)pidl_abs))
109c2c66affSColin Finck 							++cnt;
110c2c66affSColin Finck 					} else {
111c2c66affSColin Finck 						HWND hwnd;
112c2c66affSColin Finck #ifndef _NO_MDI
113c2c66affSColin Finck 						if (mdi)
114c2c66affSColin Finck 							hwnd = MDIMainFrame::Create(pidl_abs, 0);
115c2c66affSColin Finck 						else
116c2c66affSColin Finck #endif
117c2c66affSColin Finck 							hwnd = SDIMainFrame::Create(pidl_abs, 0);
118c2c66affSColin Finck 
119c2c66affSColin Finck 						if (hwnd)
120c2c66affSColin Finck 							++cnt;
121c2c66affSColin Finck 					}
122c2c66affSColin Finck 				} catch(COMException& e) {
123c2c66affSColin Finck 					HandleException(e, g_Globals._hMainWnd);
124c2c66affSColin Finck 				}
125c2c66affSColin Finck 			}/*TEST
126c2c66affSColin Finck 			else { // !(attribs & SFGAO_FOLDER))
127c2c66affSColin Finck 				SHELLEXECUTEINFOA shexinfo;
128c2c66affSColin Finck 
129c2c66affSColin Finck 				shexinfo.cbSize = sizeof(SHELLEXECUTEINFOA);
130c2c66affSColin Finck 				shexinfo.fMask = SEE_MASK_INVOKEIDLIST;
131c2c66affSColin Finck 				shexinfo.hwnd = NULL;
132c2c66affSColin Finck 				shexinfo.lpVerb = NULL;
133c2c66affSColin Finck 				shexinfo.lpFile = NULL;
134c2c66affSColin Finck 				shexinfo.lpParameters = NULL;
135c2c66affSColin Finck 				shexinfo.lpDirectory = NULL;
136c2c66affSColin Finck 				shexinfo.nShow = SW_NORMAL;
137c2c66affSColin Finck 				shexinfo.lpIDList = ILCombine(parent_pidl, pidl);
138c2c66affSColin Finck 
139c2c66affSColin Finck 				if (ShellExecuteExA(&shexinfo))
140c2c66affSColin Finck 					++cnt;
141c2c66affSColin Finck 
142c2c66affSColin Finck 				ILFree((LPITEMIDLIST)shexinfo.lpIDList);
143c2c66affSColin Finck 			}*/
144c2c66affSColin Finck 	}
145c2c66affSColin Finck 
146c2c66affSColin Finck 	return cnt;
147c2c66affSColin Finck }
148c2c66affSColin Finck 
149c2c66affSColin Finck 
MainFrameBase(HWND hwnd)150c2c66affSColin Finck MainFrameBase::MainFrameBase(HWND hwnd)
151c2c66affSColin Finck  :	super(hwnd)
152c2c66affSColin Finck {
153c2c66affSColin Finck     HDC hDC = GetDC(NULL);
154c2c66affSColin Finck #ifndef _NO_REBAR
155c2c66affSColin Finck 	//static TCHAR Title1[] = TEXT("Toolbar");
156c2c66affSColin Finck 	static TCHAR Title2[] = TEXT("Address :");
157c2c66affSColin Finck #endif
158c2c66affSColin Finck 
159c2c66affSColin Finck     if (hDC)
160c2c66affSColin Finck     {
161c2c66affSColin Finck         DWORD ilMask;
162c2c66affSColin Finck         INT bpp = GetDeviceCaps(hDC, BITSPIXEL);
163c2c66affSColin Finck         ReleaseDC(NULL, hDC);
164c2c66affSColin Finck 
165c2c66affSColin Finck         if (bpp <= 4)
166c2c66affSColin Finck             ilMask = ILC_COLOR4;
167c2c66affSColin Finck         else if (bpp <= 8)
168c2c66affSColin Finck             ilMask = ILC_COLOR8;
169c2c66affSColin Finck         else if (bpp <= 16)
170c2c66affSColin Finck             ilMask = ILC_COLOR16;
171c2c66affSColin Finck         else if (bpp <= 24)
172c2c66affSColin Finck             ilMask = ILC_COLOR24;
173c2c66affSColin Finck         else if (bpp <= 32)
174c2c66affSColin Finck             ilMask = ILC_COLOR32;
175c2c66affSColin Finck         else
176c2c66affSColin Finck             ilMask = ILC_COLOR;
177c2c66affSColin Finck 
178c2c66affSColin Finck         ilMask |= ILC_MASK;
179c2c66affSColin Finck 
180c2c66affSColin Finck         _himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ilMask, 2, 0);
181c2c66affSColin Finck     }
182c2c66affSColin Finck 
183c2c66affSColin Finck 	_hMenuFrame = GetMenu(hwnd);
184c2c66affSColin Finck 	_hMenuWindow = GetSubMenu(_hMenuFrame, GetMenuItemCount(_hMenuFrame)-3);
185c2c66affSColin Finck 
186c2c66affSColin Finck 	_menu_info._hMenuView = GetSubMenu(_hMenuFrame, 1);
187c2c66affSColin Finck 
188c2c66affSColin Finck 	_hAccel = LoadAccelerators(g_Globals._hInstance, MAKEINTRESOURCE(IDA_EXPLORER));
189c2c66affSColin Finck 
190c2c66affSColin Finck 
191c2c66affSColin Finck 	TBBUTTON toolbarBtns[] = {
192c2c66affSColin Finck #ifdef _NO_REBAR
193c2c66affSColin Finck 		{0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
194c2c66affSColin Finck #endif
195c2c66affSColin Finck 		{7, ID_GO_BACK, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
196c2c66affSColin Finck 		{8, ID_GO_FORWARD, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
197c2c66affSColin Finck 		{9, ID_GO_UP, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
198c2c66affSColin Finck 		{10, ID_GO_HOME, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
199c2c66affSColin Finck 		{11, ID_GO_SEARCH, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
200c2c66affSColin Finck 		{12, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
201c2c66affSColin Finck 		{13, ID_STOP, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}
202c2c66affSColin Finck 	};
203c2c66affSColin Finck 
204c2c66affSColin Finck 	_htoolbar = CreateToolbarEx(hwnd,
205c2c66affSColin Finck #ifndef _NO_REBAR
206c2c66affSColin Finck 		CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NODIVIDER|
207c2c66affSColin Finck #endif
208c2c66affSColin Finck 		WS_CHILD|TBSTYLE_FLAT|WS_VISIBLE, IDW_TOOLBAR, 2, g_Globals._hInstance, IDB_TOOLBAR,
209c2c66affSColin Finck 		toolbarBtns, sizeof(toolbarBtns)/sizeof(TBBUTTON),
210c2c66affSColin Finck 		16, 16, 16, 16, sizeof(TBBUTTON));
211c2c66affSColin Finck 
212c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
213c2c66affSColin Finck 
214c2c66affSColin Finck 
215c2c66affSColin Finck 	 // address bar
216c2c66affSColin Finck 	_haddrcombo = CreateWindowEx(0,
217c2c66affSColin Finck 								WC_COMBOBOX,
218c2c66affSColin Finck 								TEXT("Address"),
219c2c66affSColin Finck 								WS_CHILD|WS_TABSTOP|WS_BORDER|WS_VISIBLE|CBS_DROPDOWN|
220c2c66affSColin Finck 								CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NODIVIDER|CCS_NOMOVEY,
221c2c66affSColin Finck 								0, 0, 0, 0,
222c2c66affSColin Finck 								hwnd,
223c2c66affSColin Finck 								(HMENU)IDW_ADDRESSBAR,
224c2c66affSColin Finck 								g_Globals._hInstance,
225c2c66affSColin Finck 								0);
226c2c66affSColin Finck 
227c2c66affSColin Finck 	HFONT hFont = (HFONT)GetStockObject(ANSI_VAR_FONT);
228c2c66affSColin Finck 	SendMessageW(_haddrcombo, WM_SETFONT, (WPARAM)hFont, 0);
229c2c66affSColin Finck 
230c2c66affSColin Finck 
231c2c66affSColin Finck 	_hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, hwnd, IDW_STATUSBAR);
232c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
233c2c66affSColin Finck 
234c2c66affSColin Finck 	_hsidebar = CreateWindowEx(WS_EX_STATICEDGE, WC_TREEVIEW, TEXT("Sidebar"),
235c2c66affSColin Finck 					WS_CHILD|WS_TABSTOP|WS_BORDER|/*WS_VISIBLE|*/TVS_HASLINES|TVS_HASBUTTONS|TVS_SHOWSELALWAYS|TVS_INFOTIP,
236c2c66affSColin Finck 					-1, -1, 200, 0, _hwnd, (HMENU)IDW_SIDEBAR, g_Globals._hInstance, 0);
237c2c66affSColin Finck 
238c2c66affSColin Finck 	_himl_old = TreeView_SetImageList(_hsidebar, _himl, TVSIL_NORMAL);
239c2c66affSColin Finck 
240c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, ID_VIEW_SIDE_BAR, MF_BYCOMMAND|MF_UNCHECKED/*MF_CHECKED*/);
241c2c66affSColin Finck 
242c2c66affSColin Finck 
243c2c66affSColin Finck 	 // create rebar window to manage toolbar and drivebar
244c2c66affSColin Finck #ifndef _NO_REBAR
245c2c66affSColin Finck 	_hwndrebar = CreateWindowEx(WS_EX_TOOLWINDOW,
246c2c66affSColin Finck 								REBARCLASSNAME,
247c2c66affSColin Finck 								NULL,
248c2c66affSColin Finck 								WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|
249c2c66affSColin Finck 								 RBS_VARHEIGHT|RBS_DBLCLKTOGGLE| RBS_AUTOSIZE|RBS_BANDBORDERS,
250c2c66affSColin Finck 								0, 0, 0, 0,
251c2c66affSColin Finck 								_hwnd,
252c2c66affSColin Finck 								NULL,
253c2c66affSColin Finck 								g_Globals._hInstance,
254c2c66affSColin Finck 								0);
255c2c66affSColin Finck 
256c2c66affSColin Finck 	int btn_hgt = HIWORD(SendMessage(_htoolbar, TB_GETBUTTONSIZE, 0, 0));
257c2c66affSColin Finck 
258c2c66affSColin Finck 	REBARBANDINFO rbBand;
259c2c66affSColin Finck 
260c2c66affSColin Finck 	rbBand.cbSize = sizeof(REBARBANDINFO);
261c2c66affSColin Finck 	rbBand.fMask  = RBBIM_TEXT|RBBIM_STYLE|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_SIZE;
262c2c66affSColin Finck 	rbBand.fStyle = RBBS_CHILDEDGE|RBBS_GRIPPERALWAYS|RBBS_HIDETITLE;
263c2c66affSColin Finck 
264c2c66affSColin Finck 	rbBand.cxMinChild = 0;
265c2c66affSColin Finck 	rbBand.cyMinChild = 0;
266c2c66affSColin Finck 	rbBand.cyChild = 0;
267c2c66affSColin Finck 	rbBand.cyMaxChild = 0;
268c2c66affSColin Finck 	rbBand.cyIntegral = btn_hgt;
269c2c66affSColin Finck 
270c2c66affSColin Finck 	rbBand.lpText = NULL;//Title1
271c2c66affSColin Finck 	rbBand.hwndChild = _htoolbar;
272c2c66affSColin Finck 	rbBand.cxMinChild = 0;
273c2c66affSColin Finck 	rbBand.cyMinChild = btn_hgt;
274c2c66affSColin Finck 	rbBand.cx = 284;
275c2c66affSColin Finck 	SendMessage(_hwndrebar, RB_INSERTBAND, (WPARAM)0, (LPARAM)&rbBand);
276c2c66affSColin Finck 
277c2c66affSColin Finck 	rbBand.fStyle &= ~RBBS_HIDETITLE;
278c2c66affSColin Finck 	rbBand.fStyle |= RBBS_BREAK;
279c2c66affSColin Finck     rbBand.lpText = Title2;
280c2c66affSColin Finck 	rbBand.hwndChild = _haddrcombo;
281c2c66affSColin Finck 	rbBand.cxMinChild = 0;
282c2c66affSColin Finck 	rbBand.cyMinChild = btn_hgt;
283c2c66affSColin Finck 	rbBand.cx = 400;
284c2c66affSColin Finck 	SendMessage(_hwndrebar, RB_INSERTBAND, (WPARAM)3, (LPARAM)&rbBand);
285c2c66affSColin Finck #endif
286c2c66affSColin Finck }
287c2c66affSColin Finck 
288c2c66affSColin Finck 
~MainFrameBase()289c2c66affSColin Finck MainFrameBase::~MainFrameBase()
290c2c66affSColin Finck {
291c2c66affSColin Finck 	(void)TreeView_SetImageList(_hsidebar, _himl_old, TVSIL_NORMAL);
292c2c66affSColin Finck 	ImageList_Destroy(_himl);
293c2c66affSColin Finck 
294c2c66affSColin Finck 	 // don't exit desktop when closing file manager window
295c2c66affSColin Finck 	if (!g_Globals._desktop_mode)
296c2c66affSColin Finck 		if (g_Globals._hMainWnd == _hwnd)	// don't quit when switching between MDI and SDI mode
297c2c66affSColin Finck 			PostQuitMessage(0);
298c2c66affSColin Finck }
299c2c66affSColin Finck 
300c2c66affSColin Finck 
WndProc(UINT nmsg,WPARAM wparam,LPARAM lparam)301c2c66affSColin Finck LRESULT MainFrameBase::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
302c2c66affSColin Finck {
303c2c66affSColin Finck 	LRESULT res;
304c2c66affSColin Finck 
305c2c66affSColin Finck 	if (ProcessMessage(nmsg, wparam, lparam, &res))
306c2c66affSColin Finck 		return res;
307c2c66affSColin Finck 	else
308c2c66affSColin Finck 		return super::WndProc(nmsg, wparam, lparam);
309c2c66affSColin Finck }
310c2c66affSColin Finck 
ProcessMessage(UINT nmsg,WPARAM wparam,LPARAM lparam,LRESULT * pres)311c2c66affSColin Finck bool MainFrameBase::ProcessMessage(UINT nmsg, WPARAM wparam, LPARAM lparam, LRESULT* pres)
312c2c66affSColin Finck {
313c2c66affSColin Finck 	switch(nmsg) {
314c2c66affSColin Finck 	  case PM_TRANSLATE_MSG:
315c2c66affSColin Finck 		*pres = TranslateMsg((MSG*)lparam);
316c2c66affSColin Finck 		return true;
317c2c66affSColin Finck 
318c2c66affSColin Finck 	  case WM_SHOWWINDOW:
319c2c66affSColin Finck 		if (wparam) {	// trigger child resizing after window creation - now we can succesfully call IsWindowVisible()
320c2c66affSColin Finck             int height = SendMessage(_hwndrebar, RB_GETBARHEIGHT, 0, 0);
321c2c66affSColin Finck     		MoveWindow(_hwndrebar, 0, 0, LOWORD(lparam), height, TRUE);
322c2c66affSColin Finck 			resize_frame_client();
323c2c66affSColin Finck         }
324c2c66affSColin Finck 		return false; // goto def;
325c2c66affSColin Finck 
326c2c66affSColin Finck 	  case WM_CLOSE:
327c2c66affSColin Finck 		DestroyWindow(_hwnd);
328c2c66affSColin Finck 		g_Globals._hMainWnd = 0;
329c2c66affSColin Finck 		break;
330c2c66affSColin Finck 
331c2c66affSColin Finck 	  case WM_DESTROY:
332c2c66affSColin Finck 		break;
333c2c66affSColin Finck 
334c2c66affSColin Finck 	  case WM_SIZE: {
335c2c66affSColin Finck 		resize_frame(LOWORD(lparam), HIWORD(lparam));
336c2c66affSColin Finck 		SendMessage(_hwndrebar, WM_SIZE, 0, 0);
337c2c66affSColin Finck 		break;}	// do not pass message to DefFrameProc
338c2c66affSColin Finck 
339c2c66affSColin Finck 	  case WM_GETMINMAXINFO: {
340c2c66affSColin Finck 		LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
341c2c66affSColin Finck 
342c2c66affSColin Finck 		lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
343c2c66affSColin Finck 		lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
344c2c66affSColin Finck 		break;}
345c2c66affSColin Finck 
346c2c66affSColin Finck 	  case PM_FRM_CALC_CLIENT:
347c2c66affSColin Finck 		frame_get_clientspace((PRECT)lparam);
348c2c66affSColin Finck 		*pres = TRUE;
349c2c66affSColin Finck 		return true;
350c2c66affSColin Finck 
351c2c66affSColin Finck 	  case PM_FRM_GET_MENUINFO:
352c2c66affSColin Finck 		*pres = (LPARAM)&_menu_info;
353c2c66affSColin Finck 		return true;
354c2c66affSColin Finck 
355c2c66affSColin Finck 	  case PM_GET_CONTROLWINDOW:
356c2c66affSColin Finck 		if (wparam == FCW_STATUS) {
357c2c66affSColin Finck 			*pres = (LRESULT)(HWND)_hstatusbar;
358c2c66affSColin Finck 			return true;
359c2c66affSColin Finck 		}
360c2c66affSColin Finck 		break;
361c2c66affSColin Finck 
362c2c66affSColin Finck 	  case PM_SETSTATUSTEXT:
363c2c66affSColin Finck 		SendMessage(_hstatusbar, SB_SETTEXT, 0, lparam);
364c2c66affSColin Finck 		break;
365c2c66affSColin Finck 
366c2c66affSColin Finck 	  case WM_SYSCOLORCHANGE:
367c2c66affSColin Finck 		SendMessage(_hwndrebar, WM_SYSCOLORCHANGE, 0, 0);
368c2c66affSColin Finck 		SendMessage(_htoolbar, WM_SYSCOLORCHANGE, 0, 0);
369c2c66affSColin Finck 		break;
370c2c66affSColin Finck 
371c2c66affSColin Finck 	  default:
372c2c66affSColin Finck 		return false;
373c2c66affSColin Finck 	}
374c2c66affSColin Finck 
375c2c66affSColin Finck 	*pres = 0;
376c2c66affSColin Finck 	return true;
377c2c66affSColin Finck }
378c2c66affSColin Finck 
TranslateMsg(MSG * pmsg)379c2c66affSColin Finck BOOL MainFrameBase::TranslateMsg(MSG* pmsg)
380c2c66affSColin Finck {
381c2c66affSColin Finck 	if (TranslateAccelerator(_hwnd, _hAccel, pmsg))
382c2c66affSColin Finck 		return TRUE;
383c2c66affSColin Finck 
384c2c66affSColin Finck 	return FALSE;
385c2c66affSColin Finck }
386c2c66affSColin Finck 
387c2c66affSColin Finck 
Command(int id,int code)388c2c66affSColin Finck int MainFrameBase::Command(int id, int code)
389c2c66affSColin Finck {
390c2c66affSColin Finck 	CONTEXT("MainFrameBase::Command()");
391c2c66affSColin Finck 
392c2c66affSColin Finck 	switch(id) {
393c2c66affSColin Finck 	  case ID_FILE_EXIT:
394c2c66affSColin Finck 		SendMessage(_hwnd, WM_CLOSE, 0, 0);
395c2c66affSColin Finck 		break;
396c2c66affSColin Finck 
397c2c66affSColin Finck 	  case ID_VIEW_TOOL_BAR:
398c2c66affSColin Finck 		toggle_child(_hwnd, id, _htoolbar, 0);
399c2c66affSColin Finck 		break;
400c2c66affSColin Finck 
401c2c66affSColin Finck 	  case ID_VIEW_STATUSBAR:
402c2c66affSColin Finck 		toggle_child(_hwnd, id, _hstatusbar);
403c2c66affSColin Finck 		break;
404c2c66affSColin Finck 
405c2c66affSColin Finck 	  case ID_VIEW_SIDE_BAR:
406c2c66affSColin Finck 		 // lazy initialization
407c2c66affSColin Finck 		if (!TreeView_GetCount(_hsidebar))
408c2c66affSColin Finck 			FillBookmarks();
409c2c66affSColin Finck 
410c2c66affSColin Finck 		toggle_child(_hwnd, id, _hsidebar);
411c2c66affSColin Finck 		break;
412c2c66affSColin Finck 
413c2c66affSColin Finck 	  case ID_EXECUTE: {
414c2c66affSColin Finck 		ExecuteDialog dlg = {{0}, 0};
415c2c66affSColin Finck 
416c2c66affSColin Finck 		if (DialogBoxParam(g_Globals._hInstance, MAKEINTRESOURCE(IDD_EXECUTE), _hwnd, ExecuteDialog::WndProc, (LPARAM)&dlg) == IDOK) {
417c2c66affSColin Finck 			CONTEXT("ID_EXECUTE - ShellExecute()");
418c2c66affSColin Finck 
419c2c66affSColin Finck 			HINSTANCE hinst = ShellExecute(_hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
420c2c66affSColin Finck 
421a2f7de7eSTimo Kreuzer 			if ((INT_PTR)hinst <= 32)
422c2c66affSColin Finck 				display_error(_hwnd, GetLastError());
423c2c66affSColin Finck 		}
424c2c66affSColin Finck 		break;}
425c2c66affSColin Finck 
426c2c66affSColin Finck 	  case ID_HELP:
427c2c66affSColin Finck 		WinHelp(_hwnd, TEXT("explorer")/*file explorer.hlp*/, HELP_INDEX, 0);
428c2c66affSColin Finck 		break;
429c2c66affSColin Finck 
430c2c66affSColin Finck 	  case ID_VIEW_FULLSCREEN:
431c2c66affSColin Finck 		CheckMenuItem(_menu_info._hMenuView, id, toggle_fullscreen()?MF_CHECKED:0);
432c2c66affSColin Finck 		break;
433c2c66affSColin Finck 
434c2c66affSColin Finck 	  case ID_TOOLS_OPTIONS:
435c2c66affSColin Finck 		Dialog::DoModal(IDD_MDI_SDI, WINDOW_CREATOR(MdiSdiDlg), _hwnd);
436c2c66affSColin Finck 		break;
437c2c66affSColin Finck 
438c2c66affSColin Finck 	  case ID_ABOUT_WINDOWS:
439c2c66affSColin Finck 		ShellAbout(_hwnd, ResString(IDS_TITLE), NULL, 0);
440c2c66affSColin Finck 		break;
441c2c66affSColin Finck 
442c2c66affSColin Finck 	  case ID_ABOUT_EXPLORER:
443c2c66affSColin Finck 		explorer_about(_hwnd);
444c2c66affSColin Finck 		break;
445c2c66affSColin Finck 
446c2c66affSColin Finck 	  case ID_EXPLORER_FAQ:
447c2c66affSColin Finck 		launch_file(_hwnd, TEXT("http://www.sky.franken.de/explorer/"), SW_SHOW);
448c2c66affSColin Finck 		break;
449c2c66affSColin Finck 
450c2c66affSColin Finck 	  default:
451c2c66affSColin Finck 		return 1;	// no command handlers in Window::Command()
452c2c66affSColin Finck 	}
453c2c66affSColin Finck 
454c2c66affSColin Finck 	return 0;
455c2c66affSColin Finck }
456c2c66affSColin Finck 
Notify(int id,NMHDR * pnmh)457c2c66affSColin Finck int MainFrameBase::Notify(int id, NMHDR* pnmh)
458c2c66affSColin Finck {
459c2c66affSColin Finck 	switch(pnmh->code) {
460c2c66affSColin Finck 		 // resize children windows when the rebar size changes
461c2c66affSColin Finck 
462c2c66affSColin Finck       case RBN_AUTOSIZE:
463c2c66affSColin Finck 		resize_frame_client();
464c2c66affSColin Finck 		break;
465c2c66affSColin Finck 
466c2c66affSColin Finck 	  case TVN_GETINFOTIP: {
467c2c66affSColin Finck 		NMTVGETINFOTIP* pnmgit = (NMTVGETINFOTIP*)pnmh;
468c2c66affSColin Finck 
469c2c66affSColin Finck 		if (pnmgit->lParam) {
470c2c66affSColin Finck 			const BookmarkNode& node = *(BookmarkNode*)pnmgit->lParam;
471c2c66affSColin Finck 
472c2c66affSColin Finck 			if (node._type == BookmarkNode::BMNT_FOLDER) {
473c2c66affSColin Finck 				 // display tooltips for bookmark folders
474c2c66affSColin Finck 				if (!node._pfolder->_description.empty())
475c2c66affSColin Finck 					lstrcpyn(pnmgit->pszText, node._pfolder->_description.c_str(), pnmgit->cchTextMax);
476c2c66affSColin Finck 			} else if (node._type == BookmarkNode::BMNT_BOOKMARK) {
477c2c66affSColin Finck 				 // display tooltips for bookmark folders
478c2c66affSColin Finck 				String txt = node._pbookmark->_description;
479c2c66affSColin Finck 
480c2c66affSColin Finck 				if (!node._pbookmark->_url.empty()) {
481c2c66affSColin Finck 					if (!txt.empty())
482c2c66affSColin Finck 						txt += TEXT("  -  ");
483c2c66affSColin Finck 
484c2c66affSColin Finck 					txt += node._pbookmark->_url;
485c2c66affSColin Finck 				}
486c2c66affSColin Finck 
487c2c66affSColin Finck 				lstrcpyn(pnmgit->pszText, txt.c_str(), pnmgit->cchTextMax);
488c2c66affSColin Finck 			}
489c2c66affSColin Finck 		}
490c2c66affSColin Finck 		break;}
491c2c66affSColin Finck 
492c2c66affSColin Finck 	  case NM_DBLCLK: {
493c2c66affSColin Finck 		HTREEITEM hitem = TreeView_GetSelection(_hsidebar);
494c2c66affSColin Finck 		LPARAM lparam = TreeView_GetItemData(_hsidebar, hitem);
495c2c66affSColin Finck 
496c2c66affSColin Finck 		if (lparam) {
497c2c66affSColin Finck 			const BookmarkNode& node = *(BookmarkNode*)lparam;
498c2c66affSColin Finck 
499c2c66affSColin Finck 			if (node._type == BookmarkNode::BMNT_BOOKMARK) {
500c2c66affSColin Finck 				bool new_window = GetAsyncKeyState(VK_SHIFT)<0;
501c2c66affSColin Finck 
502c2c66affSColin Finck 				go_to(node._pbookmark->_url, new_window);
503c2c66affSColin Finck 			}
504c2c66affSColin Finck 		}
505c2c66affSColin Finck 		break;}
506c2c66affSColin Finck 	}
507c2c66affSColin Finck 
508c2c66affSColin Finck 	return 0;
509c2c66affSColin Finck }
510c2c66affSColin Finck 
511c2c66affSColin Finck 
resize_frame(int cx,int cy)512c2c66affSColin Finck void MainFrameBase::resize_frame(int cx, int cy)
513c2c66affSColin Finck {
514c2c66affSColin Finck 	if (cy <= 0)
515c2c66affSColin Finck 		return;	// avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
516c2c66affSColin Finck 
517c2c66affSColin Finck 	RECT rect = {0, 0, cx, cy};
518c2c66affSColin Finck 
519c2c66affSColin Finck 	if (_hwndrebar) {
520c2c66affSColin Finck         int height = SendMessage(_hwndrebar, RB_GETBARHEIGHT, 0, 0);
521c2c66affSColin Finck 		rect.top += height;
522c2c66affSColin Finck         rect.top += 5;
523c2c66affSColin Finck 
524c2c66affSColin Finck 		SetWindowPos(_haddrcombo, NULL, 0, 0, cx, height, SWP_NOMOVE);
525c2c66affSColin Finck 	} else {
526c2c66affSColin Finck 		if (IsWindowVisible(_htoolbar)) {
527c2c66affSColin Finck 			SendMessage(_htoolbar, WM_SIZE, 0, 0);
528c2c66affSColin Finck 			WindowRect rt(_htoolbar);
529c2c66affSColin Finck 			rect.top = rt.bottom;
530c2c66affSColin Finck 		//	rect.bottom -= rt.bottom;
531c2c66affSColin Finck 		}
532c2c66affSColin Finck 	}
533c2c66affSColin Finck 
534c2c66affSColin Finck 	if (IsWindowVisible(_hstatusbar)) {
535c2c66affSColin Finck 		int parts[] = {300, 500};
536c2c66affSColin Finck 
537c2c66affSColin Finck 		SendMessage(_hstatusbar, WM_SIZE, 0, 0);
538c2c66affSColin Finck 		SendMessage(_hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
539c2c66affSColin Finck 		ClientRect rt(_hstatusbar);
540c2c66affSColin Finck 		rect.bottom -= rt.bottom;
541c2c66affSColin Finck 	}
542c2c66affSColin Finck 
543c2c66affSColin Finck 	if (IsWindowVisible(_hsidebar)) {
544c2c66affSColin Finck 		WindowRect rt(_hsidebar);
545c2c66affSColin Finck 		rect.left += rt.right-rt.left;
546c2c66affSColin Finck 
547c2c66affSColin Finck 		SetWindowPos(_hsidebar, 0, -1, rect.top-1, rt.right-rt.left, rect.bottom-rect.top+1, SWP_NOACTIVATE|SWP_NOZORDER);
548c2c66affSColin Finck 	}
549c2c66affSColin Finck }
550c2c66affSColin Finck 
resize_frame_client()551c2c66affSColin Finck void MainFrameBase::resize_frame_client()
552c2c66affSColin Finck {
553c2c66affSColin Finck 	ClientRect rect(_hwnd);
554c2c66affSColin Finck 
555c2c66affSColin Finck 	resize_frame(rect.right, rect.bottom);
556c2c66affSColin Finck }
557c2c66affSColin Finck 
frame_get_clientspace(PRECT prect)558c2c66affSColin Finck void MainFrameBase::frame_get_clientspace(PRECT prect)
559c2c66affSColin Finck {
560c2c66affSColin Finck 	if (!IsIconic(_hwnd))
561c2c66affSColin Finck 		GetClientRect(_hwnd, prect);
562c2c66affSColin Finck 	else {
563c2c66affSColin Finck 		WINDOWPLACEMENT wp;
564c2c66affSColin Finck 
565c2c66affSColin Finck 		GetWindowPlacement(_hwnd, &wp);
566c2c66affSColin Finck 
567c2c66affSColin Finck 		prect->left = prect->top = 0;
568c2c66affSColin Finck 		prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
569c2c66affSColin Finck 						2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
570c2c66affSColin Finck 		prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
571c2c66affSColin Finck 						2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
572c2c66affSColin Finck 						GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
573c2c66affSColin Finck 	}
574c2c66affSColin Finck 
575c2c66affSColin Finck 	if (IsWindowVisible(_htoolbar)) {
576c2c66affSColin Finck 		ClientRect rt(_htoolbar);
577c2c66affSColin Finck 		prect->top += rt.bottom+2;
578c2c66affSColin Finck 	}
579c2c66affSColin Finck 
580c2c66affSColin Finck 	if (IsWindowVisible(_hstatusbar)) {
581c2c66affSColin Finck 		ClientRect rt(_hstatusbar);
582c2c66affSColin Finck 		prect->bottom -= rt.bottom;
583c2c66affSColin Finck 	}
584c2c66affSColin Finck }
585c2c66affSColin Finck 
toggle_fullscreen()586c2c66affSColin Finck BOOL MainFrameBase::toggle_fullscreen()
587c2c66affSColin Finck {
588c2c66affSColin Finck 	RECT rt;
589c2c66affSColin Finck 
590c2c66affSColin Finck 	if ((_fullscreen._mode=!_fullscreen._mode)) {
591c2c66affSColin Finck 		GetWindowRect(_hwnd, &_fullscreen._orgPos);
592c2c66affSColin Finck 		_fullscreen._wasZoomed = IsZoomed(_hwnd);
593c2c66affSColin Finck 
594c2c66affSColin Finck 		Frame_CalcFrameClient(_hwnd, &rt);
595c2c66affSColin Finck 		ClientToScreen(_hwnd, (LPPOINT)&rt.left);
596c2c66affSColin Finck 		ClientToScreen(_hwnd, (LPPOINT)&rt.right);
597c2c66affSColin Finck 
598c2c66affSColin Finck 		rt.left = _fullscreen._orgPos.left-rt.left;
599c2c66affSColin Finck 		rt.top = _fullscreen._orgPos.top-rt.top;
600c2c66affSColin Finck 		rt.right = GetSystemMetrics(SM_CXSCREEN)+_fullscreen._orgPos.right-rt.right;
601c2c66affSColin Finck 		rt.bottom = GetSystemMetrics(SM_CYSCREEN)+_fullscreen._orgPos.bottom-rt.bottom;
602c2c66affSColin Finck 
603c2c66affSColin Finck 		MoveWindow(_hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
604c2c66affSColin Finck 	} else {
605c2c66affSColin Finck 		MoveWindow(_hwnd, _fullscreen._orgPos.left, _fullscreen._orgPos.top,
606c2c66affSColin Finck 							_fullscreen._orgPos.right-_fullscreen._orgPos.left,
607c2c66affSColin Finck 							_fullscreen._orgPos.bottom-_fullscreen._orgPos.top, TRUE);
608c2c66affSColin Finck 
609c2c66affSColin Finck 		if (_fullscreen._wasZoomed)
610c2c66affSColin Finck 			ShowWindow(_hwnd, WS_MAXIMIZE);
611c2c66affSColin Finck 	}
612c2c66affSColin Finck 
613c2c66affSColin Finck 	return _fullscreen._mode;
614c2c66affSColin Finck }
615c2c66affSColin Finck 
fullscreen_move()616c2c66affSColin Finck void MainFrameBase::fullscreen_move()
617c2c66affSColin Finck {
618c2c66affSColin Finck 	RECT rt, pos;
619c2c66affSColin Finck 	GetWindowRect(_hwnd, &pos);
620c2c66affSColin Finck 
621c2c66affSColin Finck 	Frame_CalcFrameClient(_hwnd, &rt);
622c2c66affSColin Finck 	ClientToScreen(_hwnd, (LPPOINT)&rt.left);
623c2c66affSColin Finck 	ClientToScreen(_hwnd, (LPPOINT)&rt.right);
624c2c66affSColin Finck 
625c2c66affSColin Finck 	rt.left = pos.left-rt.left;
626c2c66affSColin Finck 	rt.top = pos.top-rt.top;
627c2c66affSColin Finck 	rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
628c2c66affSColin Finck 	rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
629c2c66affSColin Finck 
630c2c66affSColin Finck 	MoveWindow(_hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
631c2c66affSColin Finck }
632c2c66affSColin Finck 
633c2c66affSColin Finck 
toggle_child(HWND hwnd,UINT cmd,HWND hchild,int band_idx)634c2c66affSColin Finck void MainFrameBase::toggle_child(HWND hwnd, UINT cmd, HWND hchild, int band_idx)
635c2c66affSColin Finck {
636c2c66affSColin Finck 	BOOL vis = IsWindowVisible(hchild);
637c2c66affSColin Finck 
638c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
639c2c66affSColin Finck 
640c2c66affSColin Finck 	if (band_idx != -1)
641c2c66affSColin Finck 		SendMessage(_hwndrebar, RB_SHOWBAND, band_idx, !vis);
642c2c66affSColin Finck 	else
643c2c66affSColin Finck 		ShowWindow(hchild, vis? SW_HIDE: SW_SHOW);
644c2c66affSColin Finck 
645c2c66affSColin Finck 	if (_fullscreen._mode)
646c2c66affSColin Finck 		fullscreen_move();
647c2c66affSColin Finck 
648c2c66affSColin Finck 	resize_frame_client();
649c2c66affSColin Finck }
650c2c66affSColin Finck 
FillBookmarks()651c2c66affSColin Finck void MainFrameBase::FillBookmarks()
652c2c66affSColin Finck {
653c2c66affSColin Finck 	HiddenWindow hide(_hsidebar);
654c2c66affSColin Finck 	WindowCanvas canvas(_hwnd);
655c2c66affSColin Finck 
656c2c66affSColin Finck 	TreeView_DeleteAllItems(_hsidebar);
657c2c66affSColin Finck 
658c2c66affSColin Finck 	g_Globals._icon_cache.get_icon(ICID_FAVORITES).add_to_imagelist(_himl, canvas);
659c2c66affSColin Finck 	g_Globals._icon_cache.get_icon(ICID_BOOKMARK).add_to_imagelist(_himl, canvas);
660c2c66affSColin Finck 	ImageList_AddAlphaIcon(_himl, SmallIcon(IDI_DOT), GetStockBrush(WHITE_BRUSH), canvas);
661c2c66affSColin Finck 	g_Globals._icon_cache.get_icon(ICID_FOLDER).add_to_imagelist(_himl, canvas);
662c2c66affSColin Finck 	g_Globals._icon_cache.get_icon(ICID_FOLDER).add_to_imagelist(_himl, canvas);
663c2c66affSColin Finck 
664c2c66affSColin Finck 	TV_INSERTSTRUCT tvi;
665c2c66affSColin Finck 
666c2c66affSColin Finck 	tvi.hParent = TVI_ROOT;
667c2c66affSColin Finck 	tvi.hInsertAfter = TVI_LAST;
668c2c66affSColin Finck 	tvi.item.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
669c2c66affSColin Finck 	ResString sFavorites(IDS_FAVORITES);
670c2c66affSColin Finck 	tvi.item.pszText = sFavorites.str();
671c2c66affSColin Finck 	tvi.item.iSelectedImage = tvi.item.iImage = 0;
672c2c66affSColin Finck 
673c2c66affSColin Finck 	HTREEITEM hitem_bookmarks = TreeView_InsertItem(_hsidebar, &tvi);
674c2c66affSColin Finck 
675c2c66affSColin Finck 	g_Globals._favorites.fill_tree(_hsidebar, hitem_bookmarks, _himl, canvas);
676c2c66affSColin Finck 
677c2c66affSColin Finck 	TreeView_Expand(_hsidebar, hitem_bookmarks, TVE_EXPAND);
678c2c66affSColin Finck }
679c2c66affSColin Finck 
680c2c66affSColin Finck 
go_to(LPCTSTR url,bool new_window)681c2c66affSColin Finck bool MainFrameBase::go_to(LPCTSTR url, bool new_window)
682c2c66affSColin Finck {
683c2c66affSColin Finck 	///@todo SDI implementation
684c2c66affSColin Finck 
685c2c66affSColin Finck 	return false;
686c2c66affSColin Finck }
687c2c66affSColin Finck 
688c2c66affSColin Finck 
689c2c66affSColin Finck #ifndef _NO_MDI
690c2c66affSColin Finck 
MDIMainFrame(HWND hwnd)691c2c66affSColin Finck MDIMainFrame::MDIMainFrame(HWND hwnd)
692c2c66affSColin Finck  :	super(hwnd)
693c2c66affSColin Finck {
694c2c66affSColin Finck 	TBBUTTON mdiBtns[] = {
695c2c66affSColin Finck 		{0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
696c2c66affSColin Finck 		{0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
697c2c66affSColin Finck 		{1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
698c2c66affSColin Finck 		{2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
699c2c66affSColin Finck 		{3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}
700c2c66affSColin Finck 	};
701c2c66affSColin Finck 
702c2c66affSColin Finck 	SendMessage(_htoolbar, TB_ADDBUTTONS, sizeof(mdiBtns)/sizeof(TBBUTTON), (LPARAM)&mdiBtns);
703c2c66affSColin Finck 
704c2c66affSColin Finck 	CLIENTCREATESTRUCT ccs;
705c2c66affSColin Finck 
706c2c66affSColin Finck 	ccs.hWindowMenu = _hMenuWindow;
707c2c66affSColin Finck 	ccs.idFirstChild = IDW_FIRST_CHILD;
708c2c66affSColin Finck 
709c2c66affSColin Finck 	_hmdiclient = CreateWindowEx(WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, TEXT("MDICLIENT"), NULL,
710c2c66affSColin Finck 					WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
711c2c66affSColin Finck 					0, 0, 0, 0,
712c2c66affSColin Finck 					hwnd, 0, g_Globals._hInstance, &ccs);
713c2c66affSColin Finck 
714c2c66affSColin Finck 	TBBUTTON extraBtns = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
715c2c66affSColin Finck 
716c2c66affSColin Finck #ifndef _NO_REBAR
717c2c66affSColin Finck 	_hextrabar = CreateToolbarEx(hwnd,
718c2c66affSColin Finck 				CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NODIVIDER|
719c2c66affSColin Finck 				WS_CHILD|TBSTYLE_FLAT|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
720c2c66affSColin Finck 				IDW_EXTRABAR, 2, g_Globals._hInstance, IDB_DRIVEBAR, NULL, 0,
721c2c66affSColin Finck 				16, 16, 16, 16, sizeof(TBBUTTON));
722c2c66affSColin Finck #else
723c2c66affSColin Finck 	_hextrabar = CreateToolbarEx(hwnd,
724c2c66affSColin Finck 				WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,CCS_NODIVIDER|
725c2c66affSColin Finck 				IDW_EXTRABAR, 2, g_Globals._hInstance, IDB_DRIVEBAR, &extraBtns, 1,
726c2c66affSColin Finck 				16, 13, 16, 13, sizeof(TBBUTTON));
727c2c66affSColin Finck #endif
728c2c66affSColin Finck 
729c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, ID_VIEW_EXTRA_BAR, MF_BYCOMMAND|MF_CHECKED);
730c2c66affSColin Finck 
731c2c66affSColin Finck 
732c2c66affSColin Finck 	extraBtns.fsStyle = BTNS_BUTTON;
733c2c66affSColin Finck 
734c2c66affSColin Finck #ifdef __WINE__
735c2c66affSColin Finck 	 // insert unix file system button
736c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("/\0"));
737c2c66affSColin Finck 	extraBtns.idCommand = ID_DRIVE_UNIX_FS;
738c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
739c2c66affSColin Finck #endif
740c2c66affSColin Finck 
741c2c66affSColin Finck 	 // insert explorer window button
742c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("Explore\0"));
743c2c66affSColin Finck 	extraBtns.idCommand = ID_DRIVE_DESKTOP;
744c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
745c2c66affSColin Finck 
746c2c66affSColin Finck 	 // insert shell namespace button
747c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("Shell\0"));
748c2c66affSColin Finck 	extraBtns.idCommand = ID_DRIVE_SHELL_NS;
749c2c66affSColin Finck 	extraBtns.iBitmap = 6;
750c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
751c2c66affSColin Finck 
752c2c66affSColin Finck 	 // insert web control button
753c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("Web\0"));
754c2c66affSColin Finck 	extraBtns.idCommand = ID_WEB_WINDOW;
755c2c66affSColin Finck 	extraBtns.iBitmap = 7;
756c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
757c2c66affSColin Finck 
758c2c66affSColin Finck 	if ((HIWORD(GetVersion())>>14) == W_VER_NT) {
759c2c66affSColin Finck 		 // insert NT object namespace button
760c2c66affSColin Finck 		extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("NT Obj\0"));
761c2c66affSColin Finck 		extraBtns.idCommand = ID_DRIVE_NTOBJ_NS;
762c2c66affSColin Finck 		extraBtns.iBitmap = 8;
763c2c66affSColin Finck 		SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
764c2c66affSColin Finck 	}
765c2c66affSColin Finck 
766c2c66affSColin Finck 	 // insert Registry button
767c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("Reg.\0"));
768c2c66affSColin Finck 	extraBtns.idCommand = ID_DRIVE_REGISTRY;
769c2c66affSColin Finck 	extraBtns.iBitmap = 9;
770c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
771c2c66affSColin Finck 
772c2c66affSColin Finck #ifdef _DEBUG
773c2c66affSColin Finck 	 // insert FAT direct file system access button
774c2c66affSColin Finck 	extraBtns.iString = SendMessage(_hextrabar, TB_ADDSTRING, 0, (LPARAM)TEXT("FAT\0"));
775c2c66affSColin Finck 	extraBtns.idCommand = ID_DRIVE_FAT;
776c2c66affSColin Finck 	extraBtns.iBitmap = 10;
777c2c66affSColin Finck 	SendMessage(_hextrabar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&extraBtns);
778c2c66affSColin Finck #endif
779c2c66affSColin Finck 
780c2c66affSColin Finck 
781c2c66affSColin Finck 	TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0};
782c2c66affSColin Finck #ifndef _NO_WIN_FS
783c2c66affSColin Finck 	PTSTR p;
784c2c66affSColin Finck 
785c2c66affSColin Finck #ifndef _NO_REBAR
786c2c66affSColin Finck 	_hdrivebar = CreateToolbarEx(hwnd,
787c2c66affSColin Finck 				CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NODIVIDER|
788c2c66affSColin Finck 				WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT|CCS_NOMOVEY|TBSTYLE_LIST,
789c2c66affSColin Finck 				IDW_DRIVEBAR, 2, g_Globals._hInstance, IDB_DRIVEBAR, NULL, 0,
790c2c66affSColin Finck 				16, 16, 16, 16, sizeof(TBBUTTON));
791c2c66affSColin Finck #else
792c2c66affSColin Finck 	_hdrivebar = CreateToolbarEx(hwnd,
793c2c66affSColin Finck 				WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST|CCS_NODIVIDER,
794c2c66affSColin Finck 				IDW_DRIVEBAR, 2, g_Globals._hInstance, IDB_DRIVEBAR, &drivebarBtn, 1,
795c2c66affSColin Finck 				16, 13, 16, 13, sizeof(TBBUTTON));
796c2c66affSColin Finck #endif
797c2c66affSColin Finck #endif
798c2c66affSColin Finck 
799c2c66affSColin Finck 	CheckMenuItem(_menu_info._hMenuView, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_UNCHECKED);
800c2c66affSColin Finck 
801c2c66affSColin Finck 
802c2c66affSColin Finck #ifndef _NO_WIN_FS
803c2c66affSColin Finck 	GetLogicalDriveStrings(BUFFER_LEN, _drives);
804c2c66affSColin Finck 
805c2c66affSColin Finck 	 // register windows drive root strings
806c2c66affSColin Finck 	SendMessage(_hdrivebar, TB_ADDSTRING, 0, (LPARAM)_drives);
807c2c66affSColin Finck 
808c2c66affSColin Finck 	drivebarBtn.fsStyle = BTNS_BUTTON;
809c2c66affSColin Finck 	drivebarBtn.idCommand = ID_DRIVE_FIRST;
810c2c66affSColin Finck 
811c2c66affSColin Finck 	for(p=_drives; *p; ) {
812c2c66affSColin Finck 		switch(GetDriveType(p)) {
813c2c66affSColin Finck 			case DRIVE_REMOVABLE:	drivebarBtn.iBitmap = 1;	break;
814c2c66affSColin Finck 			case DRIVE_CDROM:		drivebarBtn.iBitmap = 3;	break;
815c2c66affSColin Finck 			case DRIVE_REMOTE:		drivebarBtn.iBitmap = 4;	break;
816c2c66affSColin Finck 			case DRIVE_RAMDISK: 	drivebarBtn.iBitmap = 5;	break;
817c2c66affSColin Finck 			default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
818c2c66affSColin Finck 		}
819c2c66affSColin Finck 
820c2c66affSColin Finck 		SendMessage(_hdrivebar, TB_INSERTBUTTON, INT_MAX, (LPARAM)&drivebarBtn);
821c2c66affSColin Finck 		++drivebarBtn.idCommand;
822c2c66affSColin Finck 		++drivebarBtn.iString;
823c2c66affSColin Finck 
824c2c66affSColin Finck 		while(*p++);
825c2c66affSColin Finck 	}
826c2c66affSColin Finck #endif
827c2c66affSColin Finck 
828c2c66affSColin Finck 
829c2c66affSColin Finck #ifndef _NO_REBAR
830c2c66affSColin Finck 	int btn_hgt = HIWORD(SendMessage(_htoolbar, TB_GETBUTTONSIZE, 0, 0));
831c2c66affSColin Finck 
832c2c66affSColin Finck 	REBARBANDINFO rbBand;
833c2c66affSColin Finck 
834c2c66affSColin Finck 	rbBand.cbSize = sizeof(REBARBANDINFO);
835c2c66affSColin Finck 	rbBand.fMask  = RBBIM_TEXT|RBBIM_STYLE|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_SIZE;
836c2c66affSColin Finck #ifndef RBBS_HIDETITLE // missing in MinGW headers as of 25.02.2004
837c2c66affSColin Finck #define RBBS_HIDETITLE	0x400
838c2c66affSColin Finck #endif
839c2c66affSColin Finck 	rbBand.fStyle = RBBS_CHILDEDGE|RBBS_GRIPPERALWAYS|RBBS_HIDETITLE;
840c2c66affSColin Finck 
841c2c66affSColin Finck 	TCHAR ExtrasBand[] = _T("Extras");
842c2c66affSColin Finck 	rbBand.lpText = ExtrasBand;
843c2c66affSColin Finck 	rbBand.hwndChild = _hextrabar;
844c2c66affSColin Finck 	rbBand.cxMinChild = 0;
845c2c66affSColin Finck 	rbBand.cyMinChild = btn_hgt;
846c2c66affSColin Finck 	rbBand.cx = 284;
847c2c66affSColin Finck 	SendMessage(_hwndrebar, RB_INSERTBAND, (WPARAM)1, (LPARAM)&rbBand);
848c2c66affSColin Finck 
849c2c66affSColin Finck #ifndef _NO_WIN_FS
850c2c66affSColin Finck 	rbBand.fStyle |= RBBS_BREAK;
851c2c66affSColin Finck 	TCHAR DrivesBand[] = _T("Drives");
852c2c66affSColin Finck 	rbBand.lpText = DrivesBand;
853c2c66affSColin Finck 	rbBand.hwndChild = _hdrivebar;
854c2c66affSColin Finck 	rbBand.cxMinChild = 0;
855c2c66affSColin Finck 	rbBand.cyMinChild = btn_hgt;
856c2c66affSColin Finck 	rbBand.cx = 400;
857c2c66affSColin Finck 	SendMessage(_hwndrebar, RB_INSERTBAND, (WPARAM)2, (LPARAM)&rbBand);
858c2c66affSColin Finck 
859c2c66affSColin Finck 	// hide the drivebar by default
860c2c66affSColin Finck 	SendMessage(_hwndrebar, RB_SHOWBAND, 2, FALSE);
861c2c66affSColin Finck #endif
862c2c66affSColin Finck #endif
863c2c66affSColin Finck }
864c2c66affSColin Finck 
865c2c66affSColin Finck 
Create()866c2c66affSColin Finck HWND MDIMainFrame::Create()
867c2c66affSColin Finck {
868c2c66affSColin Finck 	HMENU hMenuFrame = LoadMenu(g_Globals._hInstance, MAKEINTRESOURCE(IDM_MDIFRAME));
869c2c66affSColin Finck 
870c2c66affSColin Finck 	return Window::Create(WINDOW_CREATOR(MDIMainFrame), 0,
871c2c66affSColin Finck 				(LPCTSTR)(int)g_Globals._hframeClass, ResString(IDS_TITLE), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
872c2c66affSColin Finck 				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
873c2c66affSColin Finck 				0/*hwndDesktop*/, hMenuFrame);
874c2c66affSColin Finck }
875c2c66affSColin Finck 
Create(LPCTSTR path,int mode)876c2c66affSColin Finck HWND MDIMainFrame::Create(LPCTSTR path, int mode)
877c2c66affSColin Finck {
878c2c66affSColin Finck 	HWND hFrame = Create();
879c2c66affSColin Finck 	if (!hFrame)
880c2c66affSColin Finck 		return 0;
881c2c66affSColin Finck 
882c2c66affSColin Finck 	ShowWindow(hFrame, SW_SHOW);
883c2c66affSColin Finck 
884c2c66affSColin Finck 	MDIMainFrame* pMainFrame = GET_WINDOW(MDIMainFrame, hFrame);
885c2c66affSColin Finck 
886c2c66affSColin Finck 	if (pMainFrame)
887c2c66affSColin Finck 		pMainFrame->CreateChild(path, mode);
888c2c66affSColin Finck 
889c2c66affSColin Finck 	return hFrame;
890c2c66affSColin Finck }
891c2c66affSColin Finck 
Create(LPCITEMIDLIST pidl,int mode)892c2c66affSColin Finck HWND MDIMainFrame::Create(LPCITEMIDLIST pidl, int mode)
893c2c66affSColin Finck {
894c2c66affSColin Finck 	HWND hFrame = Create();
895c2c66affSColin Finck 	if (!hFrame)
896c2c66affSColin Finck 		return 0;
897c2c66affSColin Finck 
898c2c66affSColin Finck 	ShowWindow(hFrame, SW_SHOW);
899c2c66affSColin Finck 
900c2c66affSColin Finck 	MDIMainFrame* pMainFrame = GET_WINDOW(MDIMainFrame, hFrame);
901c2c66affSColin Finck 
902c2c66affSColin Finck 	if (pMainFrame)
903c2c66affSColin Finck 		pMainFrame->CreateChild(pidl, mode);
904c2c66affSColin Finck 
905c2c66affSColin Finck 	return hFrame;
906c2c66affSColin Finck }
907c2c66affSColin Finck 
908c2c66affSColin Finck 
CreateChild(LPCTSTR path,int mode)909c2c66affSColin Finck ChildWindow* MDIMainFrame::CreateChild(LPCTSTR path, int mode)
910c2c66affSColin Finck {
911c2c66affSColin Finck 	return reinterpret_cast<ChildWindow*>(SendMessage(_hwnd, PM_OPEN_WINDOW, mode, (LPARAM)path));
912c2c66affSColin Finck }
913c2c66affSColin Finck 
CreateChild(LPCITEMIDLIST pidl,int mode)914c2c66affSColin Finck ChildWindow* MDIMainFrame::CreateChild(LPCITEMIDLIST pidl, int mode)
915c2c66affSColin Finck {
916c2c66affSColin Finck 	return reinterpret_cast<ChildWindow*>(SendMessage(_hwnd, PM_OPEN_WINDOW, mode|OWM_PIDL, (LPARAM)pidl));
917c2c66affSColin Finck }
918c2c66affSColin Finck 
919c2c66affSColin Finck 
TranslateMsg(MSG * pmsg)920c2c66affSColin Finck BOOL MDIMainFrame::TranslateMsg(MSG* pmsg)
921c2c66affSColin Finck {
922c2c66affSColin Finck 	if (_hmdiclient && TranslateMDISysAccel(_hmdiclient, pmsg))
923c2c66affSColin Finck 		return TRUE;
924c2c66affSColin Finck 
925c2c66affSColin Finck 	return super::TranslateMsg(pmsg);
926c2c66affSColin Finck }
927c2c66affSColin Finck 
WndProc(UINT nmsg,WPARAM wparam,LPARAM lparam)928c2c66affSColin Finck LRESULT MDIMainFrame::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
929c2c66affSColin Finck {
930c2c66affSColin Finck 	switch(nmsg) {
931c2c66affSColin Finck 	  case PM_OPEN_WINDOW: {
932c2c66affSColin Finck 		CONTEXT("MDIMainFrame PM_OPEN_WINDOW");
933c2c66affSColin Finck 
934c2c66affSColin Finck 		TCHAR buffer[MAX_PATH];
935c2c66affSColin Finck 		LPCTSTR path;
936c2c66affSColin Finck 		ShellPath shell_path = DesktopFolderPath();
937c2c66affSColin Finck 
938c2c66affSColin Finck 		if (lparam) {
939c2c66affSColin Finck 			if (wparam & OWM_PIDL) {
940c2c66affSColin Finck 				 // take over PIDL from lparam
941c2c66affSColin Finck 				shell_path.assign((LPCITEMIDLIST)lparam);	// create as "rooted" window
942c2c66affSColin Finck 				FileSysShellPath fsp(shell_path);
943c2c66affSColin Finck 				path = fsp;
944c2c66affSColin Finck 
945c2c66affSColin Finck 				if (path) {
946c2c66affSColin Finck 					LOG(FmtString(TEXT("MDIMainFrame PM_OPEN_WINDOW: path=%s"), path));
947c2c66affSColin Finck 					lstrcpy(buffer, path);
948c2c66affSColin Finck 					path = buffer;
949c2c66affSColin Finck 				}
950c2c66affSColin Finck 			} else {
951c2c66affSColin Finck 				 // take over path from lparam
952c2c66affSColin Finck 				path = (LPCTSTR)lparam;
953c2c66affSColin Finck 				shell_path = path;	// create as "rooted" window
954c2c66affSColin Finck 			}
955c2c66affSColin Finck 		} else {
956c2c66affSColin Finck 			///@todo read paths and window placements from registry
957c2c66affSColin Finck 			if (!GetCurrentDirectory(MAX_PATH, buffer))
958c2c66affSColin Finck 				*buffer = '\0';
959c2c66affSColin Finck 
960c2c66affSColin Finck 			path = buffer;
961c2c66affSColin Finck 		}
962c2c66affSColin Finck 
963c2c66affSColin Finck 		if (path && _tcsstr(path, TEXT("://"))) {	// "http://...", "ftp://", ...
964c2c66affSColin Finck 			OBJ_CONTEXT("create WebChild window", path);
965c2c66affSColin Finck 
966c2c66affSColin Finck 			return (LRESULT)GET_WINDOW(ChildWindow, create_webchildwindow(WebChildWndInfo(_hmdiclient, path)));
967c2c66affSColin Finck 		} else {
968c2c66affSColin Finck 			OBJ_CONTEXT("create ShellChildWndInfo", path);
969c2c66affSColin Finck 
970c2c66affSColin Finck 			 // Shell Namespace as default view
971c2c66affSColin Finck 			ShellChildWndInfo create_info(_hmdiclient, path, shell_path);
972c2c66affSColin Finck 
973c2c66affSColin Finck 			if (wparam & OWM_ROOTED)
974c2c66affSColin Finck 				create_info._root_shell_path = shell_path;
975c2c66affSColin Finck 			else
976c2c66affSColin Finck 				create_info._root_shell_path = DesktopFolderPath();	//SpecialFolderPath(CSIDL_DRIVES, _hwnd);
977c2c66affSColin Finck 
978c2c66affSColin Finck 			create_info._pos.showCmd = wparam&OWM_SEPARATE? SW_SHOWNORMAL: SW_SHOWMAXIMIZED;
979c2c66affSColin Finck 			create_info._pos.rcNormalPosition.left = CW_USEDEFAULT;
980c2c66affSColin Finck 			create_info._pos.rcNormalPosition.top = CW_USEDEFAULT;
981c2c66affSColin Finck 			create_info._pos.rcNormalPosition.right = CW_USEDEFAULT;
982c2c66affSColin Finck 			create_info._pos.rcNormalPosition.bottom = CW_USEDEFAULT;
983c2c66affSColin Finck 
984c2c66affSColin Finck 			create_info._open_mode = wparam;
985c2c66affSColin Finck 
986c2c66affSColin Finck 		//	FileChildWindow::create(_hmdiclient, create_info);
987c2c66affSColin Finck 			return (LRESULT)MDIShellBrowserChild::create(create_info);
988c2c66affSColin Finck 		}
989c2c66affSColin Finck 		return TRUE;}	// success
990c2c66affSColin Finck 
991c2c66affSColin Finck 	  case WM_SYSCOLORCHANGE: {
992c2c66affSColin Finck 		LRESULT res;
993c2c66affSColin Finck 		HWND hChild;
994c2c66affSColin Finck 
995c2c66affSColin Finck 		/* Forward WM_SYSCOLORCHANGE to common controls */
996c2c66affSColin Finck 		SendMessage(_hextrabar, WM_SYSCOLORCHANGE, 0, 0);
997c2c66affSColin Finck 		SendMessage(_hdrivebar, WM_SYSCOLORCHANGE, 0, 0);
998c2c66affSColin Finck 
999c2c66affSColin Finck 		for(hChild = GetNextWindow(_hmdiclient,GW_CHILD); hChild; hChild = GetNextWindow(hChild, GW_HWNDNEXT))
1000c2c66affSColin Finck 			SendMessage(hChild, WM_SYSCOLORCHANGE, 0, 0);
1001c2c66affSColin Finck 
1002c2c66affSColin Finck 		super::ProcessMessage(nmsg, wparam, lparam, &res);
1003c2c66affSColin Finck 		break; }
1004c2c66affSColin Finck 
1005c2c66affSColin Finck 	  default: {
1006c2c66affSColin Finck 		LRESULT res;
1007c2c66affSColin Finck 
1008c2c66affSColin Finck 		if (super::ProcessMessage(nmsg, wparam, lparam, &res))
1009c2c66affSColin Finck 			return res;
1010c2c66affSColin Finck 		else
1011c2c66affSColin Finck 			return DefFrameProc(_hwnd, _hmdiclient, nmsg, wparam, lparam);
1012c2c66affSColin Finck 	  }
1013c2c66affSColin Finck 	}
1014c2c66affSColin Finck 
1015c2c66affSColin Finck 	return 0;
1016c2c66affSColin Finck }
1017c2c66affSColin Finck 
Command(int id,int code)1018c2c66affSColin Finck int MDIMainFrame::Command(int id, int code)
1019c2c66affSColin Finck {
1020c2c66affSColin Finck 	CONTEXT("MDIMainFrame::Command()");
1021c2c66affSColin Finck 
1022c2c66affSColin Finck 	HWND hwndClient = (HWND) SendMessage(_hmdiclient, WM_MDIGETACTIVE, 0, 0);
1023c2c66affSColin Finck 
1024c2c66affSColin Finck 	if (hwndClient)
1025c2c66affSColin Finck 		if (SendMessage(hwndClient, PM_DISPATCH_COMMAND, MAKELONG(id,code), 0))
1026c2c66affSColin Finck 			return 0;
1027c2c66affSColin Finck 
1028c2c66affSColin Finck #ifndef _NO_WIN_FS
1029c2c66affSColin Finck 	if (id>=ID_DRIVE_FIRST && id<=ID_DRIVE_FIRST+0xFF) {
1030c2c66affSColin Finck 		TCHAR drv[_MAX_DRIVE], path[MAX_PATH];
1031c2c66affSColin Finck 		LPCTSTR root = _drives;
1032c2c66affSColin Finck 
1033c2c66affSColin Finck 		for(int i=id-ID_DRIVE_FIRST; i--; root++)
1034c2c66affSColin Finck 			while(*root)
1035c2c66affSColin Finck 				++root;
1036c2c66affSColin Finck 
1037c2c66affSColin Finck 		if (activate_drive_window(root))
1038c2c66affSColin Finck 			return 0;
1039c2c66affSColin Finck 
1040c2c66affSColin Finck 		_tsplitpath_s(root, drv, COUNTOF(drv), NULL, 0, NULL, 0, NULL, 0);
1041c2c66affSColin Finck 
1042c2c66affSColin Finck 		if (!SetCurrentDirectory(drv)) {
1043c2c66affSColin Finck 			display_error(_hwnd, GetLastError());
1044c2c66affSColin Finck 			return 0;
1045c2c66affSColin Finck 		}
1046c2c66affSColin Finck 
1047c2c66affSColin Finck 		GetCurrentDirectory(MAX_PATH, path); ///@todo store last directory per drive
1048c2c66affSColin Finck 
1049c2c66affSColin Finck 		FileChildWindow::create(FileChildWndInfo(_hmdiclient, path));
1050c2c66affSColin Finck 
1051c2c66affSColin Finck 		return 1;
1052c2c66affSColin Finck 	}
1053c2c66affSColin Finck #endif
1054c2c66affSColin Finck 
1055c2c66affSColin Finck 	switch(id) {
1056c2c66affSColin Finck 	  case ID_WINDOW_NEW: {
1057c2c66affSColin Finck 		TCHAR path[MAX_PATH];
1058c2c66affSColin Finck 
1059c2c66affSColin Finck 		GetCurrentDirectory(MAX_PATH, path);
1060c2c66affSColin Finck 
1061c2c66affSColin Finck 		FileChildWindow::create(FileChildWndInfo(_hmdiclient, path));
1062c2c66affSColin Finck 		break;}
1063c2c66affSColin Finck 
1064c2c66affSColin Finck 	  case ID_WINDOW_CASCADE:
1065c2c66affSColin Finck 		SendMessage(_hmdiclient, WM_MDICASCADE, 0, 0);
1066c2c66affSColin Finck 		break;
1067c2c66affSColin Finck 
1068c2c66affSColin Finck 	  case ID_WINDOW_TILE_HORZ:
1069c2c66affSColin Finck 		SendMessage(_hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
1070c2c66affSColin Finck 		break;
1071c2c66affSColin Finck 
1072c2c66affSColin Finck 	  case ID_WINDOW_TILE_VERT:
1073c2c66affSColin Finck 		SendMessage(_hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
1074c2c66affSColin Finck 		break;
1075c2c66affSColin Finck 
1076c2c66affSColin Finck 	  case ID_WINDOW_ARRANGE:
1077c2c66affSColin Finck 		SendMessage(_hmdiclient, WM_MDIICONARRANGE, 0, 0);
1078c2c66affSColin Finck 		break;
1079c2c66affSColin Finck 
1080c2c66affSColin Finck 	  case ID_VIEW_EXTRA_BAR:
1081c2c66affSColin Finck 		toggle_child(_hwnd, id, _hextrabar, 1);
1082c2c66affSColin Finck 		break;
1083c2c66affSColin Finck 
1084c2c66affSColin Finck #ifndef _NO_WIN_FS
1085c2c66affSColin Finck 	  case ID_VIEW_DRIVE_BAR:
1086c2c66affSColin Finck 		toggle_child(_hwnd, id, _hdrivebar, 2);
1087c2c66affSColin Finck 		break;
1088c2c66affSColin Finck #endif
1089c2c66affSColin Finck 
1090c2c66affSColin Finck #ifdef __WINE__
1091c2c66affSColin Finck 	  case ID_DRIVE_UNIX_FS: {
1092c2c66affSColin Finck 		TCHAR path[MAX_PATH];
1093c2c66affSColin Finck 		FileChildWindow* child;
1094c2c66affSColin Finck 
1095c2c66affSColin Finck 		getcwd(path, COUNTOF(path));
1096c2c66affSColin Finck 
1097c2c66affSColin Finck 		if (activate_child_window(TEXT("unixfs")))
1098c2c66affSColin Finck 			break;
1099c2c66affSColin Finck 
1100c2c66affSColin Finck 		FileChildWindow::create(_hmdiclient, FileChildWndInfo(path));
1101c2c66affSColin Finck 		break;}
1102c2c66affSColin Finck #endif
1103c2c66affSColin Finck 
1104c2c66affSColin Finck 	  case ID_DRIVE_DESKTOP: {
1105c2c66affSColin Finck 		TCHAR path[MAX_PATH];
1106c2c66affSColin Finck 
1107c2c66affSColin Finck 		if (activate_child_window(TEXT("Desktop")))
1108c2c66affSColin Finck 			break;
1109c2c66affSColin Finck 
1110c2c66affSColin Finck 		GetCurrentDirectory(MAX_PATH, path);
1111c2c66affSColin Finck 
1112c2c66affSColin Finck 		MDIShellBrowserChild::create(ShellChildWndInfo(_hmdiclient, path, DesktopFolderPath()));
1113c2c66affSColin Finck 		break;}
1114c2c66affSColin Finck 
1115c2c66affSColin Finck 	  case ID_DRIVE_SHELL_NS: {
1116c2c66affSColin Finck 		TCHAR path[MAX_PATH];
1117c2c66affSColin Finck 		GetCurrentDirectory(MAX_PATH, path);
1118c2c66affSColin Finck 
1119c2c66affSColin Finck 		if (activate_child_window(TEXT("Shell")))
1120c2c66affSColin Finck 			break;
1121c2c66affSColin Finck 
1122c2c66affSColin Finck 		FileChildWindow::create(ShellChildWndInfo(_hmdiclient, path, DesktopFolderPath()));
1123c2c66affSColin Finck 		break;}
1124c2c66affSColin Finck 
1125c2c66affSColin Finck 	  case ID_DRIVE_NTOBJ_NS: {
1126c2c66affSColin Finck 		if (activate_child_window(TEXT("NTOBJ")))
1127c2c66affSColin Finck 			break;
1128c2c66affSColin Finck 
1129c2c66affSColin Finck 		FileChildWindow::create(NtObjChildWndInfo(_hmdiclient, TEXT("\\")));
1130c2c66affSColin Finck 	  break;}
1131c2c66affSColin Finck 
1132c2c66affSColin Finck 	  case ID_DRIVE_REGISTRY: {
1133c2c66affSColin Finck 		if (activate_child_window(TEXT("Registry")))
1134c2c66affSColin Finck 			break;
1135c2c66affSColin Finck 
1136c2c66affSColin Finck 		FileChildWindow::create(RegistryChildWndInfo(_hmdiclient, TEXT("\\")));
1137c2c66affSColin Finck 	  break;}
1138c2c66affSColin Finck 
1139c2c66affSColin Finck 	  case ID_DRIVE_FAT: {
1140c2c66affSColin Finck 
1141c2c66affSColin Finck 	  	///@todo prompt for image file
1142c2c66affSColin Finck 
1143c2c66affSColin Finck 		if (activate_child_window(TEXT("FAT")))
1144c2c66affSColin Finck 			break;
1145c2c66affSColin Finck 
1146c2c66affSColin Finck 		FileChildWindow::create(FATChildWndInfo(_hmdiclient, TEXT("FAT Image")));	//@@
1147c2c66affSColin Finck 	  break;}
1148c2c66affSColin Finck 
1149c2c66affSColin Finck 	  case ID_WEB_WINDOW:
1150c2c66affSColin Finck #ifdef _DEBUG
1151c2c66affSColin Finck 		create_webchildwindow(WebChildWndInfo(_hmdiclient, TEXT("http://localhost")));
1152c2c66affSColin Finck #else
1153*09dde2cfSJoachim Henze 		create_webchildwindow(WebChildWndInfo(_hmdiclient, TEXT("https://reactos.org")));
1154c2c66affSColin Finck #endif
1155c2c66affSColin Finck 		break;
1156c2c66affSColin Finck 
1157c2c66affSColin Finck 	  case ID_EXPLORER_FAQ:
1158c2c66affSColin Finck 		create_webchildwindow(WebChildWndInfo(_hmdiclient, TEXT("http://www.sky.franken.de/explorer/")));
1159c2c66affSColin Finck 		break;
1160c2c66affSColin Finck 
1161c2c66affSColin Finck 	  case ID_VIEW_SDI:
1162c2c66affSColin Finck 		MainFrameBase::Create(ExplorerCmd());
1163c2c66affSColin Finck 		break;
1164c2c66affSColin Finck 
1165c2c66affSColin Finck 	///@todo There are even more menu items!
1166c2c66affSColin Finck 
1167c2c66affSColin Finck 	  default:
1168c2c66affSColin Finck 		if (super::Command(id, code) == 0)
1169c2c66affSColin Finck 			return 0;
1170c2c66affSColin Finck 		else
1171c2c66affSColin Finck 			return DefFrameProc(_hwnd, _hmdiclient, WM_COMMAND, MAKELONG(id,code), 0);
1172c2c66affSColin Finck 	}
1173c2c66affSColin Finck 
1174c2c66affSColin Finck 	return 0;
1175c2c66affSColin Finck }
1176c2c66affSColin Finck 
1177c2c66affSColin Finck 
frame_get_clientspace(PRECT prect)1178c2c66affSColin Finck void MDIMainFrame::frame_get_clientspace(PRECT prect)
1179c2c66affSColin Finck {
1180c2c66affSColin Finck 	super::frame_get_clientspace(prect);
1181c2c66affSColin Finck 
1182c2c66affSColin Finck #ifndef _NO_WIN_FS
1183c2c66affSColin Finck 	if (IsWindowVisible(_hdrivebar)) {
1184c2c66affSColin Finck 		ClientRect rt(_hdrivebar);
1185c2c66affSColin Finck 		prect->top += rt.bottom+2;
1186c2c66affSColin Finck 	}
1187c2c66affSColin Finck #endif
1188c2c66affSColin Finck }
1189c2c66affSColin Finck 
resize_frame(int cx,int cy)1190c2c66affSColin Finck void MDIMainFrame::resize_frame(int cx, int cy)
1191c2c66affSColin Finck {
1192c2c66affSColin Finck 	if (cy <= 0)
1193c2c66affSColin Finck 		return;	// avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1194c2c66affSColin Finck 
1195c2c66affSColin Finck 	RECT rect = {0, 0, cx, cy};
1196c2c66affSColin Finck 
1197c2c66affSColin Finck 	if (_hwndrebar) {
1198c2c66affSColin Finck         int height = SendMessage(_hwndrebar, RB_GETBARHEIGHT, 0, 0);
1199c2c66affSColin Finck 		rect.top += height;
1200c2c66affSColin Finck         rect.top += 5;
1201c2c66affSColin Finck 	} else {
1202c2c66affSColin Finck 		if (IsWindowVisible(_htoolbar)) {
1203c2c66affSColin Finck 			SendMessage(_htoolbar, WM_SIZE, 0, 0);
1204c2c66affSColin Finck 			WindowRect rt(_htoolbar);
1205c2c66affSColin Finck 			rect.top = rt.bottom;
1206c2c66affSColin Finck 		//	rect.bottom -= rt.bottom;
1207c2c66affSColin Finck 		}
1208c2c66affSColin Finck 
1209c2c66affSColin Finck 		if (IsWindowVisible(_hextrabar)) {
1210c2c66affSColin Finck 			SendMessage(_hextrabar, WM_SIZE, 0, 0);
1211c2c66affSColin Finck 			WindowRect rt(_hextrabar);
1212c2c66affSColin Finck 			int new_top = --rect.top + rt.bottom;
1213c2c66affSColin Finck 			MoveWindow(_hextrabar, 0, rect.top, rt.right, new_top, TRUE);
1214c2c66affSColin Finck 			rect.top = new_top;
1215c2c66affSColin Finck 		//	rect.bottom -= rt.bottom;
1216c2c66affSColin Finck 		}
1217c2c66affSColin Finck 
1218c2c66affSColin Finck #ifndef _NO_WIN_FS
1219c2c66affSColin Finck 		if (IsWindowVisible(_hdrivebar)) {
1220c2c66affSColin Finck 			SendMessage(_hdrivebar, WM_SIZE, 0, 0);
1221c2c66affSColin Finck 			WindowRect rt(_hdrivebar);
1222c2c66affSColin Finck 			int new_top = --rect.top + rt.bottom;
1223c2c66affSColin Finck 			MoveWindow(_hdrivebar, 0, rect.top, rt.right, new_top, TRUE);
1224c2c66affSColin Finck 			rect.top = new_top;
1225c2c66affSColin Finck 		//	rect.bottom -= rt.bottom;
1226c2c66affSColin Finck 		}
1227c2c66affSColin Finck #endif
1228c2c66affSColin Finck 	}
1229c2c66affSColin Finck 
1230c2c66affSColin Finck 	if (IsWindowVisible(_hstatusbar)) {
1231c2c66affSColin Finck 		int parts[] = {300, 500};
1232c2c66affSColin Finck 
1233c2c66affSColin Finck 		SendMessage(_hstatusbar, WM_SIZE, 0, 0);
1234c2c66affSColin Finck 		SendMessage(_hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1235c2c66affSColin Finck 		ClientRect rt(_hstatusbar);
1236c2c66affSColin Finck 		rect.bottom -= rt.bottom;
1237c2c66affSColin Finck 	}
1238c2c66affSColin Finck 
1239c2c66affSColin Finck 	if (IsWindowVisible(_hsidebar)) {
1240c2c66affSColin Finck 		WindowRect rt(_hsidebar);
1241c2c66affSColin Finck 		rect.left += rt.right-rt.left;
1242c2c66affSColin Finck 
1243c2c66affSColin Finck 		SetWindowPos(_hsidebar, 0, -1, rect.top-1, rt.right-rt.left, rect.bottom-rect.top+1, SWP_NOACTIVATE|SWP_NOZORDER);
1244c2c66affSColin Finck 	}
1245c2c66affSColin Finck 
1246c2c66affSColin Finck 	MoveWindow(_hmdiclient, rect.left-1, rect.top-1, rect.right-rect.left+1, rect.bottom-rect.top+1, TRUE);
1247c2c66affSColin Finck }
1248c2c66affSColin Finck 
activate_drive_window(LPCTSTR path)1249c2c66affSColin Finck bool MDIMainFrame::activate_drive_window(LPCTSTR path)
1250c2c66affSColin Finck {
1251c2c66affSColin Finck 	TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
1252c2c66affSColin Finck 	HWND child_wnd;
1253c2c66affSColin Finck 
1254c2c66affSColin Finck 	_tsplitpath_s(path, drv1, COUNTOF(drv1), NULL, 0, NULL, 0, NULL, 0);
1255c2c66affSColin Finck 
1256c2c66affSColin Finck 	 // search for a already open window for the same drive
1257c2c66affSColin Finck 	for(child_wnd=GetNextWindow(_hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1258c2c66affSColin Finck 		FileChildWindow* child = (FileChildWindow*) SendMessage(child_wnd, PM_GET_FILEWND_PTR, 0, 0);
1259c2c66affSColin Finck 
1260c2c66affSColin Finck 		if (child) {
1261c2c66affSColin Finck 			_tsplitpath_s(child->get_root()._path, drv2, COUNTOF(drv2), NULL, 0, NULL, 0, NULL, 0);
1262c2c66affSColin Finck 
1263c2c66affSColin Finck 			if (!lstrcmpi(drv2, drv1)) {
1264c2c66affSColin Finck 				SendMessage(_hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1265c2c66affSColin Finck 
1266c2c66affSColin Finck 				if (IsMinimized(child_wnd))
1267c2c66affSColin Finck 					ShowWindow(child_wnd, SW_SHOWNORMAL);
1268c2c66affSColin Finck 
1269c2c66affSColin Finck 				return true;
1270c2c66affSColin Finck 			}
1271c2c66affSColin Finck 		}
1272c2c66affSColin Finck 	}
1273c2c66affSColin Finck 
1274c2c66affSColin Finck 	return false;
1275c2c66affSColin Finck }
1276c2c66affSColin Finck 
activate_child_window(LPCTSTR filesys)1277c2c66affSColin Finck bool MDIMainFrame::activate_child_window(LPCTSTR filesys)
1278c2c66affSColin Finck {
1279c2c66affSColin Finck 	HWND child_wnd;
1280c2c66affSColin Finck 
1281c2c66affSColin Finck 	 // search for a already open window of the given file system name
1282c2c66affSColin Finck 	for(child_wnd=GetNextWindow(_hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
1283c2c66affSColin Finck 		FileChildWindow* child = (FileChildWindow*) SendMessage(child_wnd, PM_GET_FILEWND_PTR, 0, 0);
1284c2c66affSColin Finck 
1285c2c66affSColin Finck 		if (child) {
1286c2c66affSColin Finck 			if (!lstrcmpi(child->get_root()._fs, filesys)) {
1287c2c66affSColin Finck 				SendMessage(_hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1288c2c66affSColin Finck 
1289c2c66affSColin Finck 				if (IsMinimized(child_wnd))
1290c2c66affSColin Finck 					ShowWindow(child_wnd, SW_SHOWNORMAL);
1291c2c66affSColin Finck 
1292c2c66affSColin Finck 				return true;
1293c2c66affSColin Finck 			}
1294c2c66affSColin Finck 		} else {
1295c2c66affSColin Finck 			ShellBrowser* shell_child = (ShellBrowser*) SendMessage(child_wnd, PM_GET_SHELLBROWSER_PTR, 0, 0);
1296c2c66affSColin Finck 
1297c2c66affSColin Finck 			if (shell_child) {
1298c2c66affSColin Finck 				if (!lstrcmpi(shell_child->get_root()._fs, filesys)) {
1299c2c66affSColin Finck 					SendMessage(_hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
1300c2c66affSColin Finck 
1301c2c66affSColin Finck 					if (IsMinimized(child_wnd))
1302c2c66affSColin Finck 						ShowWindow(child_wnd, SW_SHOWNORMAL);
1303c2c66affSColin Finck 
1304c2c66affSColin Finck 					return true;
1305c2c66affSColin Finck 				}
1306c2c66affSColin Finck 			}
1307c2c66affSColin Finck 		}
1308c2c66affSColin Finck 	}
1309c2c66affSColin Finck 
1310c2c66affSColin Finck 	return false;
1311c2c66affSColin Finck }
1312c2c66affSColin Finck 
go_to(LPCTSTR url,bool new_window)1313c2c66affSColin Finck bool MDIMainFrame::go_to(LPCTSTR url, bool new_window)
1314c2c66affSColin Finck {
1315c2c66affSColin Finck 	if (!new_window) {
1316c2c66affSColin Finck 		HWND hwndClient = (HWND) SendMessage(_hmdiclient, WM_MDIGETACTIVE, 0, 0);
1317c2c66affSColin Finck 
1318c2c66affSColin Finck 		if (hwndClient)
1319c2c66affSColin Finck 			if (SendMessage(hwndClient, PM_JUMP_TO_URL, 0, (LPARAM)url))
1320c2c66affSColin Finck 				return true;
1321c2c66affSColin Finck 	}
1322c2c66affSColin Finck 
1323c2c66affSColin Finck 	if (CreateChild(url))
1324c2c66affSColin Finck 		return true;
1325c2c66affSColin Finck 
1326c2c66affSColin Finck 	return super::go_to(url, new_window);
1327c2c66affSColin Finck }
1328c2c66affSColin Finck 
1329c2c66affSColin Finck #endif // _NO_MDI
1330c2c66affSColin Finck 
1331c2c66affSColin Finck 
SDIMainFrame(HWND hwnd)1332c2c66affSColin Finck SDIMainFrame::SDIMainFrame(HWND hwnd)
1333c2c66affSColin Finck  :	super(hwnd)
1334c2c66affSColin Finck {
1335c2c66affSColin Finck 	_split_pos = DEFAULT_SPLIT_POS;
1336c2c66affSColin Finck 	_last_split = DEFAULT_SPLIT_POS;
1337c2c66affSColin Finck 
1338c2c66affSColin Finck 	/* wait for PM_OPEN_WINDOW message before creating a shell view
1339c2c66affSColin Finck 	update_shell_browser();*/
1340c2c66affSColin Finck }
1341c2c66affSColin Finck 
Create()1342c2c66affSColin Finck HWND SDIMainFrame::Create()
1343c2c66affSColin Finck {
1344c2c66affSColin Finck 	HMENU hMenuFrame = LoadMenu(g_Globals._hInstance, MAKEINTRESOURCE(IDM_SDIFRAME));
1345c2c66affSColin Finck 
1346c2c66affSColin Finck 	return Window::Create(WINDOW_CREATOR(SDIMainFrame), 0,
1347c2c66affSColin Finck 				(LPCTSTR)(int)g_Globals._hframeClass, ResString(IDS_TITLE), WS_OVERLAPPEDWINDOW,
1348c2c66affSColin Finck 				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1349c2c66affSColin Finck 				0/*hwndDesktop*/, hMenuFrame);
1350c2c66affSColin Finck }
1351c2c66affSColin Finck 
Create(LPCITEMIDLIST pidl,int mode)1352c2c66affSColin Finck HWND SDIMainFrame::Create(LPCITEMIDLIST pidl, int mode)
1353c2c66affSColin Finck {
1354c2c66affSColin Finck 	HWND hFrame = Create();
1355c2c66affSColin Finck 	if (!hFrame)
1356c2c66affSColin Finck 		return 0;
1357c2c66affSColin Finck 
1358c2c66affSColin Finck 	ShowWindow(hFrame, SW_SHOW);
1359c2c66affSColin Finck 
1360c2c66affSColin Finck 	SDIMainFrame* pFrame = GET_WINDOW(SDIMainFrame, hFrame);
1361c2c66affSColin Finck 
1362c2c66affSColin Finck 	if (pFrame)
1363c2c66affSColin Finck 		pFrame->jump_to(pidl, mode);
1364c2c66affSColin Finck 
1365c2c66affSColin Finck 	return hFrame;
1366c2c66affSColin Finck }
1367c2c66affSColin Finck 
Create(LPCTSTR path,int mode)1368c2c66affSColin Finck HWND SDIMainFrame::Create(LPCTSTR path, int mode)
1369c2c66affSColin Finck {
1370c2c66affSColin Finck 	HWND hFrame = Create();
1371c2c66affSColin Finck 	if (!hFrame)
1372c2c66affSColin Finck 		return 0;
1373c2c66affSColin Finck 
1374c2c66affSColin Finck 	ShowWindow(hFrame, SW_SHOW);
1375c2c66affSColin Finck 
1376c2c66affSColin Finck 	MDIMainFrame* pMainFrame = GET_WINDOW(MDIMainFrame, hFrame);
1377c2c66affSColin Finck 
1378c2c66affSColin Finck 	if (pMainFrame)
1379c2c66affSColin Finck 		pMainFrame->CreateChild(path, mode);
1380c2c66affSColin Finck 
1381c2c66affSColin Finck 	return hFrame;
1382c2c66affSColin Finck }
1383c2c66affSColin Finck 
WndProc(UINT nmsg,WPARAM wparam,LPARAM lparam)1384c2c66affSColin Finck LRESULT SDIMainFrame::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
1385c2c66affSColin Finck {
1386c2c66affSColin Finck 	switch(nmsg) {
1387c2c66affSColin Finck 	  case WM_SIZE:
1388c2c66affSColin Finck 		resize_frame(LOWORD(lparam), HIWORD(lparam));
1389c2c66affSColin Finck 		break;
1390c2c66affSColin Finck 
1391c2c66affSColin Finck 	  case WM_PAINT: {
1392c2c66affSColin Finck 		PaintCanvas canvas(_hwnd);
1393c2c66affSColin Finck 
1394c2c66affSColin Finck 		if (_left_hwnd) {
1395c2c66affSColin Finck 			ClientRect rt(_hwnd);
1396c2c66affSColin Finck 			rt.left = _split_pos-SPLIT_WIDTH/2;
1397c2c66affSColin Finck 			rt.right = _split_pos+SPLIT_WIDTH/2+1;
1398c2c66affSColin Finck 
1399c2c66affSColin Finck 			if (_right_hwnd) {
1400c2c66affSColin Finck 				WindowRect right_rect(_right_hwnd);
1401c2c66affSColin Finck 				ScreenToClient(_hwnd, &right_rect);
1402c2c66affSColin Finck 				rt.top = right_rect.top;
1403c2c66affSColin Finck 				rt.bottom = right_rect.bottom;
1404c2c66affSColin Finck 			}
1405c2c66affSColin Finck 
1406c2c66affSColin Finck 			HBRUSH lastBrush = SelectBrush(canvas, GetStockBrush(COLOR_SPLITBAR));
1407c2c66affSColin Finck 			Rectangle(canvas, rt.left, rt.top-1, rt.right, rt.bottom+1);
1408c2c66affSColin Finck 			SelectObject(canvas, lastBrush);
1409c2c66affSColin Finck 		}
1410c2c66affSColin Finck 		break;}
1411c2c66affSColin Finck 
1412c2c66affSColin Finck 	  case WM_SETCURSOR:
1413c2c66affSColin Finck   		if (_left_hwnd)
1414c2c66affSColin Finck 			if (LOWORD(lparam) == HTCLIENT) {
1415c2c66affSColin Finck 				POINT pt;
1416c2c66affSColin Finck 				GetCursorPos(&pt);
1417c2c66affSColin Finck 				ScreenToClient(_hwnd, &pt);
1418c2c66affSColin Finck 
1419c2c66affSColin Finck 				if (pt.x>=_split_pos-SPLIT_WIDTH/2 && pt.x<_split_pos+SPLIT_WIDTH/2+1) {
1420c2c66affSColin Finck 					SetCursor(LoadCursor(0, IDC_SIZEWE));
1421c2c66affSColin Finck 					return TRUE;
1422c2c66affSColin Finck 				}
1423c2c66affSColin Finck 			}
1424c2c66affSColin Finck 		goto def;
1425c2c66affSColin Finck 
1426c2c66affSColin Finck 	  case WM_LBUTTONDOWN:
1427c2c66affSColin Finck 		if (_left_hwnd) {
1428c2c66affSColin Finck 			int x = GET_X_LPARAM(lparam);
1429c2c66affSColin Finck 
1430c2c66affSColin Finck 			ClientRect rt(_hwnd);
1431c2c66affSColin Finck 
1432c2c66affSColin Finck 			if (x>=_split_pos-SPLIT_WIDTH/2 && x<_split_pos+SPLIT_WIDTH/2+1) {
1433c2c66affSColin Finck 				_last_split = _split_pos;
1434c2c66affSColin Finck 				SetCapture(_hwnd);
1435c2c66affSColin Finck 			}
1436c2c66affSColin Finck 		}
1437c2c66affSColin Finck 		break;
1438c2c66affSColin Finck 
1439c2c66affSColin Finck 	  case WM_LBUTTONUP:
1440c2c66affSColin Finck 		if (GetCapture() == _hwnd)
1441c2c66affSColin Finck 			ReleaseCapture();
1442c2c66affSColin Finck 		break;
1443c2c66affSColin Finck 
1444c2c66affSColin Finck 	  case WM_KEYDOWN:
1445c2c66affSColin Finck 		if (wparam == VK_ESCAPE)
1446c2c66affSColin Finck 			if (GetCapture() == _hwnd) {
1447c2c66affSColin Finck 				_split_pos = _last_split;
1448c2c66affSColin Finck 				resize_children();
1449c2c66affSColin Finck 				_last_split = -1;
1450c2c66affSColin Finck 				ReleaseCapture();
1451c2c66affSColin Finck 				SetCursor(LoadCursor(0, IDC_ARROW));
1452c2c66affSColin Finck 			}
1453c2c66affSColin Finck 		break;
1454c2c66affSColin Finck 
1455c2c66affSColin Finck 	  case WM_MOUSEMOVE:
1456c2c66affSColin Finck 		if (GetCapture() == _hwnd) {
1457c2c66affSColin Finck 			int x = GET_X_LPARAM(lparam);
1458c2c66affSColin Finck 
1459c2c66affSColin Finck 			ClientRect rt(_hwnd);
1460c2c66affSColin Finck 
1461c2c66affSColin Finck 			if (x>=0 && x<rt.right) {
1462c2c66affSColin Finck 				_split_pos = x;
1463c2c66affSColin Finck 				resize_children();
1464c2c66affSColin Finck 				rt.left = x-SPLIT_WIDTH/2;
1465c2c66affSColin Finck 				rt.right = x+SPLIT_WIDTH/2+1;
1466c2c66affSColin Finck 				InvalidateRect(_hwnd, &rt, FALSE);
1467c2c66affSColin Finck 				UpdateWindow(_left_hwnd);
1468c2c66affSColin Finck 				UpdateWindow(_hwnd);
1469c2c66affSColin Finck 				UpdateWindow(_right_hwnd);
1470c2c66affSColin Finck 			}
1471c2c66affSColin Finck 		}
1472c2c66affSColin Finck 		break;
1473c2c66affSColin Finck 
1474c2c66affSColin Finck 	  case PM_OPEN_WINDOW: {
1475c2c66affSColin Finck 		CONTEXT("SDIMainFrame PM_OPEN_WINDOW");
1476c2c66affSColin Finck 
1477c2c66affSColin Finck 		TCHAR buffer[MAX_PATH];
1478c2c66affSColin Finck 		LPCTSTR path;
1479c2c66affSColin Finck 		ShellPath shell_path = DesktopFolderPath();
1480c2c66affSColin Finck 
1481c2c66affSColin Finck 		if (lparam) {
1482c2c66affSColin Finck 			if (wparam & OWM_PIDL) {
1483c2c66affSColin Finck 				 // take over PIDL from lparam
1484c2c66affSColin Finck 				shell_path.assign((LPCITEMIDLIST)lparam);	// create as "rooted" window
1485c2c66affSColin Finck 				FileSysShellPath fsp(shell_path);
1486c2c66affSColin Finck 				path = fsp;
1487c2c66affSColin Finck 
1488c2c66affSColin Finck 				if (path) {
1489c2c66affSColin Finck 					LOG(FmtString(TEXT("SDIMainFrame PM_OPEN_WINDOW: path=%s"), path));
1490c2c66affSColin Finck 					lstrcpy(buffer, path);
1491c2c66affSColin Finck 					path = buffer;
1492c2c66affSColin Finck 				}
1493c2c66affSColin Finck 			} else {
1494c2c66affSColin Finck 				 // take over path from lparam
1495c2c66affSColin Finck 				path = (LPCTSTR)lparam;
1496c2c66affSColin Finck 				shell_path = path;	// create as "rooted" window
1497c2c66affSColin Finck 			}
1498c2c66affSColin Finck 		} else {
1499c2c66affSColin Finck 			///@todo read paths and window placements from registry
1500c2c66affSColin Finck 			if (!GetCurrentDirectory(MAX_PATH, buffer))
1501c2c66affSColin Finck 				*buffer = '\0';
1502c2c66affSColin Finck 
1503c2c66affSColin Finck 			path = buffer;
1504c2c66affSColin Finck 			shell_path = path;
1505c2c66affSColin Finck 		}
1506c2c66affSColin Finck 
1507c2c66affSColin Finck 		if (wparam & OWM_ROOTED)
1508c2c66affSColin Finck 			_shellpath_info._root_shell_path = shell_path;
1509c2c66affSColin Finck 		else
1510c2c66affSColin Finck 			_shellpath_info._root_shell_path = DesktopFolderPath();	//SpecialFolderPath(CSIDL_DRIVES, _hwnd);
1511c2c66affSColin Finck 
1512c2c66affSColin Finck 		jump_to(shell_path, wparam);	///@todo content of 'path' not used any more
1513c2c66affSColin Finck 		return TRUE;}	// success
1514c2c66affSColin Finck 
1515c2c66affSColin Finck 	  default: def:
1516c2c66affSColin Finck 		return super::WndProc(nmsg, wparam, lparam);
1517c2c66affSColin Finck 	}
1518c2c66affSColin Finck 
1519c2c66affSColin Finck 	return 0;
1520c2c66affSColin Finck }
1521c2c66affSColin Finck 
Command(int id,int code)1522c2c66affSColin Finck int SDIMainFrame::Command(int id, int code)
1523c2c66affSColin Finck {
1524c2c66affSColin Finck 	switch(id) {
1525c2c66affSColin Finck 	  case ID_VIEW_MDI:
1526c2c66affSColin Finck 		MainFrameBase::Create(ExplorerCmd(_url, true));
1527c2c66affSColin Finck 		break;
1528c2c66affSColin Finck 
1529c2c66affSColin Finck 	  default:
1530c2c66affSColin Finck 		return super::Command(id, code);
1531c2c66affSColin Finck 	}
1532c2c66affSColin Finck 
1533c2c66affSColin Finck 	return 0;
1534c2c66affSColin Finck }
1535c2c66affSColin Finck 
resize_frame(int cx,int cy)1536c2c66affSColin Finck void SDIMainFrame::resize_frame(int cx, int cy)
1537c2c66affSColin Finck {
1538c2c66affSColin Finck 	if (cy <= 0)
1539c2c66affSColin Finck 		return;	// avoid resizing children when receiving RBN_AUTOSIZE while getting minimized
1540c2c66affSColin Finck 
1541c2c66affSColin Finck 	RECT rect = {0, 0, cx, cy};
1542c2c66affSColin Finck 
1543c2c66affSColin Finck 	if (_hwndrebar) {
1544c2c66affSColin Finck 		int height = ClientRect(_hwndrebar).bottom;
1545c2c66affSColin Finck 		rect.top += height;
1546c2c66affSColin Finck         rect.top += 5;
1547c2c66affSColin Finck 	} else {
1548c2c66affSColin Finck 		if (IsWindowVisible(_htoolbar)) {
1549c2c66affSColin Finck 			SendMessage(_htoolbar, WM_SIZE, 0, 0);
1550c2c66affSColin Finck 			WindowRect rt(_htoolbar);
1551c2c66affSColin Finck 			rect.top = rt.bottom;
1552c2c66affSColin Finck 		//	rect.bottom -= rt.bottom;
1553c2c66affSColin Finck 		}
1554c2c66affSColin Finck 	}
1555c2c66affSColin Finck 
1556c2c66affSColin Finck 	if (IsWindowVisible(_hstatusbar)) {
1557c2c66affSColin Finck 		int parts[] = {300, 500};
1558c2c66affSColin Finck 
1559c2c66affSColin Finck 		SendMessage(_hstatusbar, WM_SIZE, 0, 0);
1560c2c66affSColin Finck 		SendMessage(_hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
1561c2c66affSColin Finck 		ClientRect rt(_hstatusbar);
1562c2c66affSColin Finck 		rect.bottom -= rt.bottom;
1563c2c66affSColin Finck 	}
1564c2c66affSColin Finck 
1565c2c66affSColin Finck 	if (IsWindowVisible(_hsidebar)) {
1566c2c66affSColin Finck 		WindowRect rt(_hsidebar);
1567c2c66affSColin Finck 		rect.left += rt.right-rt.left;
1568c2c66affSColin Finck 
1569c2c66affSColin Finck 		SetWindowPos(_hsidebar, 0, -1, rect.top-1, rt.right-rt.left, rect.bottom-rect.top+1, SWP_NOACTIVATE|SWP_NOZORDER);
1570c2c66affSColin Finck 	}
1571c2c66affSColin Finck 
1572c2c66affSColin Finck 	_clnt_rect = rect;
1573c2c66affSColin Finck 
1574c2c66affSColin Finck 	resize_children();
1575c2c66affSColin Finck }
1576c2c66affSColin Finck 
resize_children()1577c2c66affSColin Finck void SDIMainFrame::resize_children()
1578c2c66affSColin Finck {
1579c2c66affSColin Finck 	HDWP hdwp = BeginDeferWindowPos(2);
1580c2c66affSColin Finck 
1581c2c66affSColin Finck 	int cx = _clnt_rect.left;
1582c2c66affSColin Finck 
1583c2c66affSColin Finck 	if (_left_hwnd) {
1584c2c66affSColin Finck 		cx = _split_pos + SPLIT_WIDTH/2;
1585c2c66affSColin Finck 
1586c2c66affSColin Finck 		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);
1587c2c66affSColin Finck 	} else {
1588c2c66affSColin Finck 		//_split_pos = -1;
1589c2c66affSColin Finck 		cx = 0;
1590c2c66affSColin Finck 	}
1591c2c66affSColin Finck 
1592c2c66affSColin Finck 	if (_right_hwnd)
1593c2c66affSColin Finck 		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);
1594c2c66affSColin Finck 
1595c2c66affSColin Finck 	EndDeferWindowPos(hdwp);
1596c2c66affSColin Finck }
1597c2c66affSColin Finck 
update_clnt_rect()1598c2c66affSColin Finck void SDIMainFrame::update_clnt_rect()
1599c2c66affSColin Finck {
1600c2c66affSColin Finck 	ClientRect rect(_hwnd);
1601c2c66affSColin Finck 
1602c2c66affSColin Finck 	resize_frame(rect.right, rect.bottom);
1603c2c66affSColin Finck }
1604c2c66affSColin Finck 
update_shell_browser()1605c2c66affSColin Finck void SDIMainFrame::update_shell_browser()
1606c2c66affSColin Finck {
1607c2c66affSColin Finck 	int split_pos = DEFAULT_SPLIT_POS;
1608c2c66affSColin Finck 
1609c2c66affSColin Finck 	if (_shellBrowser.get()) {
1610c2c66affSColin Finck 		split_pos = _split_pos;
1611c2c66affSColin Finck 		delete _shellBrowser.release();
1612c2c66affSColin Finck 	}
1613c2c66affSColin Finck 
1614c2c66affSColin Finck 	 // create explorer treeview
1615c2c66affSColin Finck 	if (_shellpath_info._open_mode & OWM_EXPLORE) {
1616c2c66affSColin Finck 		if (!_left_hwnd) {
1617c2c66affSColin Finck 			ClientRect rect(_hwnd);
1618c2c66affSColin Finck 
1619c2c66affSColin Finck 			_left_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
1620c2c66affSColin Finck 							WS_CHILD|WS_TABSTOP|WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_NOTOOLTIPS|TVS_SHOWSELALWAYS,
1621c2c66affSColin Finck 							0, rect.top, split_pos-SPLIT_WIDTH/2, rect.bottom-rect.top,
1622c2c66affSColin Finck 							_hwnd, (HMENU)IDC_FILETREE, g_Globals._hInstance, 0);
1623c2c66affSColin Finck 
1624c2c66affSColin Finck 			 // display tree window as long as the shell view is not yet visible
1625c2c66affSColin Finck 			resize_frame(rect.right, rect.bottom);
1626c2c66affSColin Finck 			MoveWindow(_left_hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE);
1627c2c66affSColin Finck 		}
1628c2c66affSColin Finck 	} else {
1629c2c66affSColin Finck 		if (_left_hwnd) {
1630c2c66affSColin Finck 			DestroyWindow(_left_hwnd);
1631c2c66affSColin Finck 			_left_hwnd = 0;
1632c2c66affSColin Finck 		}
1633c2c66affSColin Finck 	}
1634c2c66affSColin Finck 
1635c2c66affSColin Finck 	_shellBrowser = auto_ptr<ShellBrowser>(new ShellBrowser(_hwnd, _hwnd, _left_hwnd, _right_hwnd,
1636c2c66affSColin Finck 												_shellpath_info, this, _cm_ifs));
1637c2c66affSColin Finck 
1638c2c66affSColin Finck 	if (_left_hwnd)
1639c2c66affSColin Finck 		_shellBrowser->Init();
1640c2c66affSColin Finck 
1641c2c66affSColin Finck 	 // update _clnt_rect and set size of new created shell view windows
1642c2c66affSColin Finck 	update_clnt_rect();
1643c2c66affSColin Finck }
1644c2c66affSColin Finck 
entry_selected(Entry * entry)1645c2c66affSColin Finck void SDIMainFrame::entry_selected(Entry* entry)
1646c2c66affSColin Finck {
1647c2c66affSColin Finck 	if (_left_hwnd)
1648c2c66affSColin Finck 		_shellBrowser->select_folder(entry, false);
1649c2c66affSColin Finck 
1650c2c66affSColin Finck 	_shellBrowser->UpdateFolderView(entry->get_shell_folder());
1651c2c66affSColin Finck 
1652c2c66affSColin Finck 	 // set size of new created shell view windows
1653c2c66affSColin Finck 	resize_children();
1654c2c66affSColin Finck }
1655c2c66affSColin Finck 
set_url(LPCTSTR url)1656c2c66affSColin Finck void SDIMainFrame::set_url(LPCTSTR url)
1657c2c66affSColin Finck {
1658c2c66affSColin Finck 	if (_url != url) {
1659c2c66affSColin Finck 		_url = url;
1660c2c66affSColin Finck 		SetWindowText(_haddrcombo, url);
1661c2c66affSColin Finck 	}
1662c2c66affSColin Finck }
1663c2c66affSColin Finck 
1664c2c66affSColin Finck 
jump_to(LPCTSTR path,int mode)1665c2c66affSColin Finck void SDIMainFrame::jump_to(LPCTSTR path, int mode)
1666c2c66affSColin Finck {/*@@todo
1667c2c66affSColin Finck 	if (_shellBrowser.get() && (_shellpath_info._open_mode&~OWM_PIDL)==(mode&~OWM_PIDL)) {
1668c2c66affSColin Finck 		_shellBrowser->jump_to(path);
1669c2c66affSColin Finck 
1670c2c66affSColin Finck 		_shellpath_info._shell_path = path;
1671c2c66affSColin Finck 	} else */{
1672c2c66affSColin Finck 		_shellpath_info._open_mode = mode;
1673c2c66affSColin Finck 		_shellpath_info._shell_path = path;
1674c2c66affSColin Finck 
1675c2c66affSColin Finck 		update_shell_browser();
1676c2c66affSColin Finck 	}
1677c2c66affSColin Finck }
1678c2c66affSColin Finck 
jump_to(LPCITEMIDLIST path,int mode)1679c2c66affSColin Finck void SDIMainFrame::jump_to(LPCITEMIDLIST path, int mode)
1680c2c66affSColin Finck {
1681c2c66affSColin Finck 	if (_shellBrowser.get() && (_shellpath_info._open_mode&~OWM_PIDL)==(mode&~OWM_PIDL)) {
1682c2c66affSColin Finck 		ShellPath shell_path = path;
1683c2c66affSColin Finck 
1684c2c66affSColin Finck 		_shellBrowser->jump_to(shell_path);
1685c2c66affSColin Finck 
1686c2c66affSColin Finck 		_shellpath_info._shell_path = shell_path;
1687c2c66affSColin Finck 	} else {
1688c2c66affSColin Finck 		_shellpath_info._open_mode = mode;
1689c2c66affSColin Finck 		_shellpath_info._shell_path = path;
1690c2c66affSColin Finck 
1691c2c66affSColin Finck 		update_shell_browser();
1692c2c66affSColin Finck 	}
1693c2c66affSColin Finck }
1694