4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 Implements the toolbar band of a cabinet window
26 #include <shlobj_undoc.h>
28 #include <shlguid_undoc.h>
36 **Fix GetBandInfo to calculate size correctly
38 static const int gBackCommandID
= 0xa121;
39 static const int gForwardCommandID
= 0xa122;
40 static const int gUpLevelCommandID
= 0xa022;
41 static const int gSearchCommandID
= 1003;
42 static const int gFoldersCommandID
= 1004;
43 static const int gMoveToCommandID
= 0x701f;
44 static const int gCopyToCommandID
= 0x701e;
45 static const int gDeleteCommandID
= 0x7011;
46 static const int gUndoCommandID
= 0x701b;
47 static const int gViewsCommandID
= 0x7031;
48 static const int gStopCommandID
= 1010;
49 static const int gRefreshCommandID
= 0xa220;
50 static const int gHomeCommandID
= 1012;
51 static const int gMapDriveCommandID
= 41089;
52 static const int gDisconnectCommandID
= 41090;
53 static const int gFavoritesCommandID
= 1015;
54 static const int gHistoryCommandID
= 1016;
55 static const int gFullScreenCommandID
= 1017;
56 static const int gPropertiesCommandID
= 0x7013;
57 static const int gCutCommandID
= 0x7018;
58 static const int gCopyCommandID
= 0x7019;
59 static const int gPasteCommandID
= 0x701a;
60 static const int gFolderOptionsCommandID
= 41251;
63 public CWindowImpl
<CToolsBand
, CWindow
, CControlWinTraits
>,
64 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
66 public IObjectWithSite
,
71 IDockingWindowSite
*fDockSite
;
72 GUID fExecCommandCategory
;
73 CComPtr
<IOleCommandTarget
> fExecCommandTarget
;
78 // *** IDeskBand methods ***
79 virtual HRESULT STDMETHODCALLTYPE
GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
);
81 // *** IObjectWithSite methods ***
82 virtual HRESULT STDMETHODCALLTYPE
SetSite(IUnknown
* pUnkSite
);
83 virtual HRESULT STDMETHODCALLTYPE
GetSite(REFIID riid
, void **ppvSite
);
85 // *** IOleWindow methods ***
86 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
*lphwnd
);
87 virtual HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(BOOL fEnterMode
);
89 // *** IDockingWindow methods ***
90 virtual HRESULT STDMETHODCALLTYPE
CloseDW(DWORD dwReserved
);
91 virtual HRESULT STDMETHODCALLTYPE
ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
);
92 virtual HRESULT STDMETHODCALLTYPE
ShowDW(BOOL fShow
);
94 // *** IInputObject methods ***
95 virtual HRESULT STDMETHODCALLTYPE
HasFocusIO();
96 virtual HRESULT STDMETHODCALLTYPE
TranslateAcceleratorIO(LPMSG lpMsg
);
97 virtual HRESULT STDMETHODCALLTYPE
UIActivateIO(BOOL fActivate
, LPMSG lpMsg
);
99 // *** IPersist methods ***
100 virtual HRESULT STDMETHODCALLTYPE
GetClassID(CLSID
*pClassID
);
102 // *** IPersistStream methods ***
103 virtual HRESULT STDMETHODCALLTYPE
IsDirty();
104 virtual HRESULT STDMETHODCALLTYPE
Load(IStream
*pStm
);
105 virtual HRESULT STDMETHODCALLTYPE
Save(IStream
*pStm
, BOOL fClearDirty
);
106 virtual HRESULT STDMETHODCALLTYPE
GetSizeMax(ULARGE_INTEGER
*pcbSize
);
109 LRESULT
OnGetButtonInfo(UINT idControl
, NMHDR
*pNMHDR
, BOOL
&bHandled
);
111 BEGIN_MSG_MAP(CToolsBand
)
112 // MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
113 // MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
114 NOTIFY_HANDLER(0, TBN_GETBUTTONINFOW
, OnGetButtonInfo
)
117 BEGIN_COM_MAP(CToolsBand
)
118 COM_INTERFACE_ENTRY_IID(IID_IDeskBand
, IDeskBand
)
119 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite
, IObjectWithSite
)
120 COM_INTERFACE_ENTRY_IID(IID_IOleWindow
, IOleWindow
)
121 COM_INTERFACE_ENTRY_IID(IID_IDockingWindow
, IDockingWindow
)
122 COM_INTERFACE_ENTRY_IID(IID_IInputObject
, IInputObject
)
123 COM_INTERFACE_ENTRY_IID(IID_IPersist
, IPersist
)
124 COM_INTERFACE_ENTRY_IID(IID_IPersistStream
, IPersistStream
)
128 CToolsBand::CToolsBand()
133 CToolsBand::~CToolsBand()
136 fDockSite
->Release();
139 HRESULT STDMETHODCALLTYPE
CToolsBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
141 if (pdbi
->dwMask
& DBIM_MINSIZE
)
143 pdbi
->ptMinSize
.x
= 400;
144 pdbi
->ptMinSize
.y
= 38;
146 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
148 pdbi
->ptMaxSize
.x
= 0;
149 pdbi
->ptMaxSize
.y
= 0;
151 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
153 pdbi
->ptIntegral
.x
= 0;
154 pdbi
->ptIntegral
.y
= 0;
156 if (pdbi
->dwMask
& DBIM_ACTUAL
)
158 pdbi
->ptActual
.x
= 400;
159 pdbi
->ptActual
.y
= 38;
161 if (pdbi
->dwMask
& DBIM_TITLE
)
162 wcscpy(pdbi
->wszTitle
, L
"");
163 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
164 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
165 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
170 static const int backImageIndex
= 0;
171 static const int forwardImageIndex
= 1;
172 static const int favoritesImageIndex
= 2;
175 static const int cutImageIndex
= 5;
176 static const int copyImageIndex
= 6;
177 static const int pasteImageIndex
= 7;
178 static const int undoImageIndex
= 8;
179 static const int redoImageIndex
= 9;
180 static const int deleteImageIndex
= 10;
185 static const int propertiesImageIndex
= 15;
187 static const int searchImageIndex
= 17;
192 static const int viewsImageIndex
= 22;
198 static const int upImageIndex
= 28;
199 static const int mapDriveImageIndex
= 29;
200 static const int disconnectImageIndex
= 30;
202 static const int viewsAltImageIndex
= 32; // same image as viewsImageIndex
208 static const int viewsAlt2ImageIndex
= 38; // same image as viewsAltImageIndex & viewsImageIndex
213 static const int foldersImageIndex
= 43;
214 static const int moveToImageIndex
= 44;
215 static const int copyToImageIndex
= 45;
216 static const int folderOptionsImageIndex
= 46;
218 const int numShownButtons
= 13;
219 const int numHiddenButtons
= 13;
220 TBBUTTON tbButtonsAdd
[numShownButtons
+ numHiddenButtons
] =
222 {backImageIndex
, gBackCommandID
, TBSTATE_ENABLED
, BTNS_DROPDOWN
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Back")},
223 {forwardImageIndex
, gForwardCommandID
, TBSTATE_ENABLED
, BTNS_DROPDOWN
, {0}, 0, (INT_PTR
)_T("Forward")},
224 {upImageIndex
, gUpLevelCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Up")},
225 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
226 {searchImageIndex
, gSearchCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Search")},
227 {foldersImageIndex
, gFoldersCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Folders")},
228 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
229 {moveToImageIndex
, gMoveToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Move To")},
230 {copyToImageIndex
, gCopyToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Copy To")},
231 {deleteImageIndex
, gDeleteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Delete")},
232 {undoImageIndex
, gUndoCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Undo")},
233 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
234 {viewsImageIndex
, gViewsCommandID
, TBSTATE_ENABLED
, BTNS_WHOLEDROPDOWN
, {0}, 0, (INT_PTR
)_T("Views")},
236 {0, gStopCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Stop")},
237 {0, gRefreshCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Refresh")},
238 {0, gHomeCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Home")},
239 {mapDriveImageIndex
, gMapDriveCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Map Drive")},
240 {disconnectImageIndex
, gDisconnectCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Disconnect")},
241 {favoritesImageIndex
, gFavoritesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Favorites")},
242 {0, gHistoryCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("History")},
243 {0, gFullScreenCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Full Screen")},
244 {propertiesImageIndex
, gPropertiesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Properties")},
245 {cutImageIndex
, gCutCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Cut")},
246 {copyImageIndex
, gCopyCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Copy")},
247 {pasteImageIndex
, gPasteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Paste")},
248 {folderOptionsImageIndex
, gFolderOptionsCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Folder Options")},
251 HRESULT STDMETHODCALLTYPE
CToolsBand::SetSite(IUnknown
* pUnkSite
)
254 IOleWindow
*oleWindow
;
258 if (fDockSite
!= NULL
)
259 fDockSite
->Release();
260 if (pUnkSite
== NULL
)
262 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, (void **)&fDockSite
);
266 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, (void **)&oleWindow
);
267 if (SUCCEEDED(hResult
))
269 oleWindow
->GetWindow(&parentWindow
);
270 oleWindow
->Release();
272 if (!::IsWindow(parentWindow
))
275 toolbar
= CreateWindowEx(TBSTYLE_EX_DOUBLEBUFFER
, TOOLBARCLASSNAMEW
, _T(""), WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
|
276 WS_CLIPCHILDREN
| TBSTYLE_TOOLTIPS
| TBSTYLE_TRANSPARENT
| TBSTYLE_REGISTERDROP
| TBSTYLE_LIST
| TBSTYLE_FLAT
|
277 CCS_NODIVIDER
| CCS_NOPARENTALIGN
| CCS_NORESIZE
| CCS_TOP
, 0, 0, 500, 20, parentWindow
, NULL
,
278 _AtlBaseModule
.GetModuleInstance(), 0);
281 SubclassWindow(toolbar
);
283 SendMessage(WM_USER
+ 100, GetSystemMetrics(SM_CXEDGE
) / 2, 0);
284 SendMessage(TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
285 SendMessage(TB_SETMAXTEXTROWS
, 1, 0);
286 SendMessage(TB_SETEXTENDEDSTYLE
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_MIXEDBUTTONS
| TBSTYLE_EX_DRAWDDARROWS
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_MIXEDBUTTONS
| TBSTYLE_EX_DRAWDDARROWS
);
288 HINSTANCE shell32Instance
= GetModuleHandle(_T("shell32.dll"));
289 HBITMAP imageBitmap
= (HBITMAP
)LoadImage(shell32Instance
, MAKEINTRESOURCE(214), IMAGE_BITMAP
, 0, 0, LR_DEFAULTSIZE
| LR_CREATEDIBSECTION
);
291 DIBSECTION bitmapInfo
;
292 GetObjectW(imageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
293 HIMAGELIST imageList
= ImageList_Create(bitmapInfo
.dsBm
.bmHeight
, bitmapInfo
.dsBm
.bmHeight
, ILC_COLOR32
, 4, 4);
295 ImageList_Add(imageList
, imageBitmap
, NULL
);
296 DeleteObject(imageBitmap
);
298 SendMessage(TB_SETIMAGELIST
, 0, (LPARAM
)imageList
);
300 SendMessage(TB_ADDBUTTONSW
, numShownButtons
, (LPARAM
)&tbButtonsAdd
);
305 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSite(REFIID riid
, void **ppvSite
)
307 if (fDockSite
== NULL
)
309 return fDockSite
->QueryInterface(riid
, ppvSite
);
312 HRESULT STDMETHODCALLTYPE
CToolsBand::GetWindow(HWND
*lphwnd
)
320 HRESULT STDMETHODCALLTYPE
CToolsBand::ContextSensitiveHelp(BOOL fEnterMode
)
326 HRESULT STDMETHODCALLTYPE
CToolsBand::CloseDW(DWORD dwReserved
)
338 HRESULT STDMETHODCALLTYPE
CToolsBand::ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
343 HRESULT STDMETHODCALLTYPE
CToolsBand::ShowDW(BOOL fShow
)
355 HRESULT STDMETHODCALLTYPE
CToolsBand::HasFocusIO()
360 HRESULT STDMETHODCALLTYPE
CToolsBand::TranslateAcceleratorIO(LPMSG lpMsg
)
365 HRESULT STDMETHODCALLTYPE
CToolsBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
370 HRESULT STDMETHODCALLTYPE
CToolsBand::GetClassID(CLSID
*pClassID
)
375 HRESULT STDMETHODCALLTYPE
CToolsBand::IsDirty()
380 HRESULT STDMETHODCALLTYPE
CToolsBand::Load(IStream
*pStm
)
385 HRESULT STDMETHODCALLTYPE
CToolsBand::Save(IStream
*pStm
, BOOL fClearDirty
)
390 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
395 LRESULT
CToolsBand::OnGetButtonInfo(UINT idControl
, NMHDR
*pNMHDR
, BOOL
&bHandled
)
397 TBNOTIFYW
*pTBntf
= (TBNOTIFYW
*)pNMHDR
;
399 if (pTBntf
->iItem
>= 0 && pTBntf
->iItem
< (numShownButtons
+ numHiddenButtons
))
401 pTBntf
->tbButton
= tbButtonsAdd
[pTBntf
->iItem
];
409 HRESULT
CreateToolsBar(REFIID riid
, void **ppv
)
411 CComObject
<CToolsBand
> *theMenuBar
;
417 ATLTRY (theMenuBar
= new CComObject
<CToolsBand
>);
418 if (theMenuBar
== NULL
)
419 return E_OUTOFMEMORY
;
420 hResult
= theMenuBar
->QueryInterface (riid
, (void **)ppv
);
421 if (FAILED (hResult
))