2 * Copyright 2003 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, 09.08.2003
29 #include "../utility/utility.h"
31 #include "../explorer.h" // for MainFrame::OpenShellFolders()
34 #include "../globals.h"
35 #include "../externals.h"
37 #include "../taskbar/desktopbar.h"
39 #include "../explorer_intres.h"
42 static BOOL (WINAPI
*SetShellWindow
)(HWND
);
43 static BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
53 // show all hidden windows
54 for(iterator it_dsk
=begin(); it_dsk
!=end(); ++it_dsk
)
55 for(WindowSet::iterator it
=it_dsk
->_windows
.begin(); it
!=it_dsk
->_windows
.end(); ++it
)
56 ShowWindowAsync(*it
, SW_SHOW
);
61 resize(DESKTOP_COUNT
);
64 static BOOL CALLBACK
DesktopEnumFct(HWND hwnd
, LPARAM lparam
)
66 WindowSet
& windows
= *(WindowSet
*)lparam
;
68 if (IsWindowVisible(hwnd
))
69 if (hwnd
!=g_Globals
._hwndDesktopBar
&& hwnd
!=g_Globals
._hwndDesktop
)
75 void Desktops::SwitchToDesktop(int idx
)
77 if (_current_desktop
== idx
)
80 Desktop
& desktop
= (*this)[idx
];
82 // save currently visible application windows
83 Desktop
& old_desktop
= (*this)[_current_desktop
];
84 WindowSet
& windows
= old_desktop
._windows
;
87 EnumWindows(DesktopEnumFct
, (LPARAM
)&windows
);
89 // hide all windows we found
90 for(WindowSet::iterator it
=windows
.begin(); it
!=windows
.end(); ++it
)
91 ShowWindowAsync(*it
, SW_HIDE
);
93 // show all windows of the new desktop
94 for(WindowSet::iterator it
=desktop
._windows
.begin(); it
!=desktop
._windows
.end(); ++it
)
95 ShowWindowAsync(*it
, SW_SHOW
);
97 desktop
._windows
.clear();
99 _current_desktop
= idx
;
103 BOOL
IsAnyDesktopRunning()
105 HINSTANCE hUser32
= GetModuleHandle(TEXT("user32"));
107 SetShellWindow
= (BOOL(WINAPI
*)(HWND
)) GetProcAddress(hUser32
, "SetShellWindow");
108 SetShellWindowEx
= (BOOL(WINAPI
*)(HWND
,HWND
)) GetProcAddress(hUser32
, "SetShellWindowEx");
110 return GetShellWindow() != 0;
114 static void draw_desktop_background(HWND hwnd
, HDC hdc
)
116 ClientRect
rect(hwnd
);
120 HBRUSH bkgndBrush = CreateSolidBrush(RGB(0,32,160)); // dark blue
121 FillRect(hdc, &rect, bkgndBrush);
122 DeleteBrush(bkgndBrush);
125 rect
.left
= rect
.right
- 280;
126 rect
.top
= rect
.bottom
- 56 - DESKTOPBARBAR_HEIGHT
;
127 rect
.right
= rect
.left
+ 250;
128 rect
.bottom
= rect
.top
+ 40;
130 #include "../buildno.h"
131 static const LPCTSTR BkgndText
= TEXT("ReactOS ")TEXT(KERNEL_VERSION_STR
)TEXT(" Explorer\nby Martin Fuchs");
133 BkMode
bkMode(hdc
, TRANSPARENT
);
135 TextColor
textColor(hdc
, RGB(128,128,192));
136 DrawText(hdc
, BkgndText
, -1, &rect
, DT_RIGHT
);
138 SetTextColor(hdc
, RGB(255,255,255));
141 DrawText(hdc
, BkgndText
, -1, &rect
, DT_RIGHT
);
145 BackgroundWindow::BackgroundWindow(HWND hwnd
)
148 // set background brush for the short moment of displaying the
149 // background color while moving foreground windows
150 SetClassLong(hwnd
, GCL_HBRBACKGROUND
, COLOR_BACKGROUND
+1);
153 LRESULT
BackgroundWindow::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
157 PaintDesktop((HDC
)wparam
);
160 case WM_MBUTTONDBLCLK
:
161 explorer_show_frame(SW_SHOWNORMAL
);
165 return super::WndProc(nmsg
, wparam
, lparam
);
172 DesktopWindow::DesktopWindow(HWND hwnd
)
178 DesktopWindow::~DesktopWindow()
181 _pShellView
->Release();
185 HWND
DesktopWindow::Create()
187 static IconWindowClass
wcDesktop(TEXT("Progman"), IDI_REACTOS
, CS_DBLCLKS
);
188 wcDesktop
.hbrBackground
= (HBRUSH
)(COLOR_BACKGROUND
+1);
190 int width
= GetSystemMetrics(SM_CXSCREEN
);
191 int height
= GetSystemMetrics(SM_CYSCREEN
);
193 HWND hwndDesktop
= Window::Create(WINDOW_CREATOR(DesktopWindow
),
194 WS_EX_TOOLWINDOW
, wcDesktop
, TEXT("Program Manager"), WS_POPUP
|WS_VISIBLE
|WS_CLIPCHILDREN
,
195 0, 0, width
, height
, 0);
197 // work around to display desktop bar in Wine
198 ShowWindow(GET_WINDOW(DesktopWindow
, hwndDesktop
)->_desktopBar
, SW_SHOW
);
200 // work around for Windows NT, Win 98, ...
201 // Without this the desktop has mysteriously only a size of 800x600 pixels.
202 MoveWindow(hwndDesktop
, 0, 0, width
, height
, TRUE
);
208 LRESULT
DesktopWindow::Init(LPCREATESTRUCT pcs
)
210 if (super::Init(pcs
))
213 HRESULT hr
= GetDesktopFolder()->CreateViewObject(_hwnd
, IID_IShellView
, (void**)&_pShellView
);
215 SFV_CREATE sfv_create;
217 sfv_create.cbSize = sizeof(SFV_CREATE);
218 sfv_create.pshf = GetDesktopFolder();
219 sfv_create.psvOuter = NULL;
220 sfv_create.psfvcb = NULL;
222 HRESULT hr = SHCreateShellFolderView(&sfv_create, &_pShellView);
229 fs
.ViewMode
= FVM_ICON
;
230 fs
.fFlags
= FWF_DESKTOP
|FWF_NOCLIENTEDGE
|FWF_NOSCROLL
|FWF_BESTFITWINDOW
|FWF_SNAPTOGRID
; //|FWF_AUTOARRANGE;
232 ClientRect
rect(_hwnd
);
234 hr
= _pShellView
->CreateViewWindow(NULL
, &fs
, this, &rect
, &hWndView
);
236 ///@todo use IShellBrowser::GetViewStateStream() to restore previous view state -> see SHOpenRegStream()
239 g_Globals
._hwndShellView
= hWndView
;
241 // subclass shellview window
242 new DesktopShellView(hWndView
, _pShellView
);
244 _pShellView
->UIActivate(SVUIA_ACTIVATE_FOCUS
);
247 IShellView2* pShellView2;
249 hr = _pShellView->QueryInterface(IID_IShellView2, (void**)&pShellView2);
251 SV2CVW2_PARAMS params;
252 params.cbSize = sizeof(SV2CVW2_PARAMS);
253 params.psvPrev = _pShellView;
255 params.psbOwner = this;
256 params.prcView = ▭
257 params.pvid = params.pvid;//@@
259 hr = pShellView2->CreateViewWindow2(¶ms);
264 IFolderView* pFolderView;
266 hr = _pShellView->QueryInterface(IID_IFolderView, (void**)&pFolderView);
269 hr = pFolderView->GetAutoArrange();
270 hr = pFolderView->SetCurrentViewMode(FVM_DETAILS);
276 if (hWndView
&& SetShellWindowEx
)
277 SetShellWindowEx(_hwnd
, hWndView
);
278 else if (SetShellWindow
)
279 SetShellWindow(_hwnd
);
281 // create the explorer bar
282 _desktopBar
= DesktopBar::Create();
283 g_Globals
._hwndDesktopBar
= _desktopBar
;
289 LRESULT
DesktopWindow::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
293 draw_desktop_background(_hwnd
, PaintCanvas(_hwnd
));
296 case WM_LBUTTONDBLCLK
:
297 case WM_RBUTTONDBLCLK
:
298 case WM_MBUTTONDBLCLK
:
299 explorer_show_frame(SW_SHOWNORMAL
);
302 case WM_GETISHELLBROWSER
:
303 return (LRESULT
)static_cast<IShellBrowser
*>(this);
307 ///@todo use IShellBrowser::GetViewStateStream() and _pShellView->SaveViewState() to store view state
314 ShowExitWindowsDialog(_hwnd
);
318 if (wparam
== SC_TASKLIST
) {
320 SendMessage(_desktopBar
, nmsg
, wparam
, lparam
);
325 return super::WndProc(nmsg
, wparam
, lparam
);
332 HRESULT
DesktopWindow::OnDefaultCommand(LPIDA pida
)
334 if (MainFrame::OpenShellFolders(pida
, 0))
341 DesktopShellView::DesktopShellView(HWND hwnd
, IShellView
* pShellView
)
343 _pShellView(pShellView
)
345 _hwndListView
= ::GetNextWindow(hwnd
, GW_CHILD
);
347 SetWindowStyle(_hwndListView
, GetWindowStyle(_hwndListView
)&~LVS_ALIGNMASK
);//|LVS_ALIGNTOP|LVS_AUTOARRANGE);
349 // work around for Windows NT, Win 98, ...
350 // Without this the desktop has mysteriously only a size of 800x600 pixels.
351 ClientRect
rect(hwnd
);
352 MoveWindow(_hwndListView
, 0, 0, rect
.right
, rect
.bottom
, TRUE
);
354 // subclass background window
355 new BackgroundWindow(_hwndListView
);
360 bool DesktopShellView::InitDragDrop()
362 CONTEXT("DesktopShellView::InitDragDrop()");
364 _pDropTarget
= new DesktopDropTarget(_hwnd
);
369 _pDropTarget
->AddRef();
371 if (FAILED(RegisterDragDrop(_hwnd
, _pDropTarget
))) {
372 _pDropTarget
->Release();
377 _pDropTarget
->Release();
381 ftetc
.dwAspect
= DVASPECT_CONTENT
;
383 ftetc
.tymed
= TYMED_HGLOBAL
;
384 ftetc
.cfFormat
= CF_HDROP
;
386 _pDropTarget
->AddSuportedFormat(ftetc
);
391 LRESULT
DesktopShellView::WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
395 if (!DoContextMenu(GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)))
396 DoDesktopContextMenu(GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
));
400 return super::WndProc(nmsg
, wparam
, lparam
);
406 int DesktopShellView::Command(int id
, int code
)
408 return super::Command(id
, code
);
411 int DesktopShellView::Notify(int id
, NMHDR
* pnmh
)
413 return super::Notify(id
, pnmh
);
416 bool DesktopShellView::DoContextMenu(int x
, int y
)
418 IDataObject
* selection
;
420 HRESULT hr
= _pShellView
->GetItemObject(SVGIO_SELECTION
, IID_IDataObject
, (void**)&selection
);
426 hr
= pidList
.GetData(selection
);
428 selection
->Release();
433 LPIDA pida
= pidList
;
435 selection
->Release();
439 LPCITEMIDLIST parent_pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
441 LPCITEMIDLIST
* apidl
= (LPCITEMIDLIST
*) alloca(pida
->cidl
*sizeof(LPCITEMIDLIST
));
443 for(int i
=pida
->cidl
; i
>0; --i
)
444 apidl
[i
-1] = (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[i
]);
446 hr
= ShellFolderContextMenu(ShellFolder(parent_pidl
), _hwnd
, pida
->cidl
, apidl
, x
, y
);
448 selection
->Release();
455 HRESULT
DesktopShellView::DoDesktopContextMenu(int x
, int y
)
459 HRESULT hr
= DesktopFolder()->GetUIObjectOf(_hwnd
, 0, NULL
, IID_IContextMenu
, NULL
, (LPVOID
*)&pcm
);
462 HMENU hmenu
= CreatePopupMenu();
465 hr
= pcm
->QueryContextMenu(hmenu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
-1, CMF_NORMAL
|CMF_EXPLORE
);
468 AppendMenu(hmenu
, MF_SEPARATOR
, 0, NULL
);
469 AppendMenu(hmenu
, 0, FCIDM_SHVIEWLAST
-1, ResString(IDS_ABOUT_EXPLORER
));
471 UINT idCmd
= TrackPopupMenu(hmenu
, TPM_LEFTALIGN
|TPM_RETURNCMD
|TPM_RIGHTBUTTON
, x
, y
, 0, _hwnd
, NULL
);
473 if (idCmd
== FCIDM_SHVIEWLAST
-1) {
474 explorer_about(_hwnd
);
476 CMINVOKECOMMANDINFO cmi
;
478 cmi
.cbSize
= sizeof(CMINVOKECOMMANDINFO
);
481 cmi
.lpVerb
= (LPCSTR
)(INT_PTR
)(idCmd
- FCIDM_SHVIEWFIRST
);
482 cmi
.lpParameters
= NULL
;
483 cmi
.lpDirectory
= NULL
;
484 cmi
.nShow
= SW_SHOWNORMAL
;
488 hr
= pcm
->InvokeCommand(&cmi
);