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
27 /* FIXME, I can't include windowsx because it conflicts with some #defines */
28 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
29 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
32 public CWindowImpl
<CToolsBand
, CWindow
, CControlWinTraits
>,
33 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
35 public IObjectWithSite
,
40 IDockingWindowSite
*fDockSite
;
41 GUID fExecCommandCategory
;
42 CComPtr
<IOleCommandTarget
> fExecCommandTarget
;
47 // *** IDeskBand methods ***
48 virtual HRESULT STDMETHODCALLTYPE
GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
);
50 // *** IObjectWithSite methods ***
51 virtual HRESULT STDMETHODCALLTYPE
SetSite(IUnknown
* pUnkSite
);
52 virtual HRESULT STDMETHODCALLTYPE
GetSite(REFIID riid
, void **ppvSite
);
54 // *** IOleWindow methods ***
55 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
*lphwnd
);
56 virtual HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(BOOL fEnterMode
);
58 // *** IDockingWindow methods ***
59 virtual HRESULT STDMETHODCALLTYPE
CloseDW(DWORD dwReserved
);
60 virtual HRESULT STDMETHODCALLTYPE
ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
);
61 virtual HRESULT STDMETHODCALLTYPE
ShowDW(BOOL fShow
);
63 // *** IInputObject methods ***
64 virtual HRESULT STDMETHODCALLTYPE
HasFocusIO();
65 virtual HRESULT STDMETHODCALLTYPE
TranslateAcceleratorIO(LPMSG lpMsg
);
66 virtual HRESULT STDMETHODCALLTYPE
UIActivateIO(BOOL fActivate
, LPMSG lpMsg
);
68 // *** IPersist methods ***
69 virtual HRESULT STDMETHODCALLTYPE
GetClassID(CLSID
*pClassID
);
71 // *** IPersistStream methods ***
72 virtual HRESULT STDMETHODCALLTYPE
IsDirty();
73 virtual HRESULT STDMETHODCALLTYPE
Load(IStream
*pStm
);
74 virtual HRESULT STDMETHODCALLTYPE
Save(IStream
*pStm
, BOOL fClearDirty
);
75 virtual HRESULT STDMETHODCALLTYPE
GetSizeMax(ULARGE_INTEGER
*pcbSize
);
78 LRESULT
OnGetButtonInfo(UINT idControl
, NMHDR
*pNMHDR
, BOOL
&bHandled
);
80 BEGIN_MSG_MAP(CToolsBand
)
81 // MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
82 // MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
83 NOTIFY_HANDLER(0, TBN_GETBUTTONINFOW
, OnGetButtonInfo
)
86 BEGIN_COM_MAP(CToolsBand
)
87 COM_INTERFACE_ENTRY_IID(IID_IDeskBand
, IDeskBand
)
88 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite
, IObjectWithSite
)
89 COM_INTERFACE_ENTRY_IID(IID_IOleWindow
, IOleWindow
)
90 COM_INTERFACE_ENTRY_IID(IID_IDockingWindow
, IDockingWindow
)
91 COM_INTERFACE_ENTRY_IID(IID_IInputObject
, IInputObject
)
92 COM_INTERFACE_ENTRY_IID(IID_IPersist
, IPersist
)
93 COM_INTERFACE_ENTRY_IID(IID_IPersistStream
, IPersistStream
)
97 CToolsBand::CToolsBand()
102 CToolsBand::~CToolsBand()
105 fDockSite
->Release();
108 HRESULT STDMETHODCALLTYPE
CToolsBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
116 ::GetWindowRect(m_hWnd
, &actualRect
);
117 actualSize
.x
= actualRect
.right
- actualRect
.left
;
118 actualSize
.y
= actualRect
.bottom
- actualRect
.top
;
120 /* Obtain the ideal size, to be used as min and max */
121 SendMessageW(m_hWnd
, TB_AUTOSIZE
, 0, 0);
122 SendMessageW(m_hWnd
, TB_GETMAXSIZE
, 0, reinterpret_cast<LPARAM
>(&maxSize
));
125 SendMessageW(m_hWnd
, TB_GETIDEALSIZE
, FALSE
, reinterpret_cast<LPARAM
>(&idealSize
));
127 /* Obtain the button size, to be used as the integral size */
128 DWORD size
= SendMessageW(m_hWnd
, TB_GETBUTTONSIZE
, 0, 0);
129 itemSize
.x
= GET_X_LPARAM(size
);
130 itemSize
.y
= GET_Y_LPARAM(size
);
132 if (pdbi
->dwMask
& DBIM_MINSIZE
)
134 pdbi
->ptMinSize
= idealSize
;
136 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
138 pdbi
->ptMaxSize
= maxSize
;
140 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
142 pdbi
->ptIntegral
= itemSize
;
144 if (pdbi
->dwMask
& DBIM_ACTUAL
)
146 pdbi
->ptActual
= actualSize
;
148 if (pdbi
->dwMask
& DBIM_TITLE
)
149 wcscpy(pdbi
->wszTitle
, L
"");
150 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
151 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
152 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
157 static const int backImageIndex
= 0;
158 static const int forwardImageIndex
= 1;
159 static const int favoritesImageIndex
= 2;
162 static const int cutImageIndex
= 5;
163 static const int copyImageIndex
= 6;
164 static const int pasteImageIndex
= 7;
165 static const int undoImageIndex
= 8;
166 static const int redoImageIndex
= 9;
167 static const int deleteImageIndex
= 10;
172 static const int propertiesImageIndex
= 15;
174 static const int searchImageIndex
= 17;
179 static const int viewsImageIndex
= 22;
185 static const int upImageIndex
= 28;
186 static const int mapDriveImageIndex
= 29;
187 static const int disconnectImageIndex
= 30;
189 static const int viewsAltImageIndex
= 32; // same image as viewsImageIndex
195 static const int viewsAlt2ImageIndex
= 38; // same image as viewsAltImageIndex & viewsImageIndex
200 static const int foldersImageIndex
= 43;
201 static const int moveToImageIndex
= 44;
202 static const int copyToImageIndex
= 45;
203 static const int folderOptionsImageIndex
= 46;
205 const int numShownButtons
= 13;
206 const int numHiddenButtons
= 13;
207 TBBUTTON tbButtonsAdd
[numShownButtons
+ numHiddenButtons
] =
209 {backImageIndex
, gBackCommandID
, TBSTATE_ENABLED
, BTNS_DROPDOWN
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Back")},
210 {forwardImageIndex
, gForwardCommandID
, TBSTATE_ENABLED
, BTNS_DROPDOWN
, {0}, 0, (INT_PTR
)_T("Forward")},
211 {upImageIndex
, gUpLevelCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Up")},
212 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
213 {searchImageIndex
, gSearchCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Search")},
214 {foldersImageIndex
, gFoldersCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Folders")},
215 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
216 {moveToImageIndex
, gMoveToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Move To")},
217 {copyToImageIndex
, gCopyToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Copy To")},
218 {deleteImageIndex
, gDeleteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Delete")},
219 {undoImageIndex
, gUndoCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Undo")},
220 {6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
221 {viewsImageIndex
, gViewsCommandID
, TBSTATE_ENABLED
, BTNS_WHOLEDROPDOWN
, {0}, 0, (INT_PTR
)_T("Views")},
223 {0, gStopCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Stop")},
224 {0, gRefreshCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Refresh")},
225 {0, gHomeCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Home")},
226 {mapDriveImageIndex
, gMapDriveCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Map Drive")},
227 {disconnectImageIndex
, gDisconnectCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Disconnect")},
228 {favoritesImageIndex
, gFavoritesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, {0}, 0, (INT_PTR
)_T("Favorites")},
229 {0, gHistoryCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("History")},
230 {0, gFullScreenCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Full Screen")},
231 {propertiesImageIndex
, gPropertiesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Properties")},
232 {cutImageIndex
, gCutCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Cut")},
233 {copyImageIndex
, gCopyCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Copy")},
234 {pasteImageIndex
, gPasteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Paste")},
235 {folderOptionsImageIndex
, gFolderOptionsCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, (INT_PTR
)_T("Folder Options")},
238 HRESULT STDMETHODCALLTYPE
CToolsBand::SetSite(IUnknown
* pUnkSite
)
241 IOleWindow
*oleWindow
;
245 if (fDockSite
!= NULL
)
246 fDockSite
->Release();
247 if (pUnkSite
== NULL
)
249 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, reinterpret_cast<void **>(&fDockSite
));
253 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, reinterpret_cast<void **>(&oleWindow
));
254 if (SUCCEEDED(hResult
))
256 oleWindow
->GetWindow(&parentWindow
);
257 oleWindow
->Release();
259 if (!::IsWindow(parentWindow
))
262 toolbar
= CreateWindowEx(TBSTYLE_EX_DOUBLEBUFFER
, TOOLBARCLASSNAMEW
, NULL
, WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
|
263 WS_CLIPCHILDREN
| TBSTYLE_TOOLTIPS
| TBSTYLE_TRANSPARENT
| TBSTYLE_REGISTERDROP
| TBSTYLE_LIST
| TBSTYLE_FLAT
|
264 CCS_NODIVIDER
| CCS_NOPARENTALIGN
| CCS_NORESIZE
| CCS_TOP
, 0, 0, 500, 20, parentWindow
, NULL
,
265 _AtlBaseModule
.GetModuleInstance(), 0);
268 SubclassWindow(toolbar
);
270 SendMessage(WM_USER
+ 100, GetSystemMetrics(SM_CXEDGE
) / 2, 0);
271 SendMessage(TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
272 SendMessage(TB_SETMAXTEXTROWS
, 1, 0);
273 SendMessage(TB_SETEXTENDEDSTYLE
, TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_MIXEDBUTTONS
| TBSTYLE_EX_DRAWDDARROWS
,
274 TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_MIXEDBUTTONS
| TBSTYLE_EX_DRAWDDARROWS
);
276 HINSTANCE shell32Instance
= GetModuleHandle(_T("shell32.dll"));
277 HBITMAP imageBitmap
= reinterpret_cast<HBITMAP
>(
278 LoadImage(shell32Instance
, MAKEINTRESOURCE(214),
279 IMAGE_BITMAP
, 0, 0, LR_DEFAULTSIZE
| LR_CREATEDIBSECTION
));
281 DIBSECTION bitmapInfo
;
282 GetObjectW(imageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
283 HIMAGELIST imageList
= ImageList_Create(bitmapInfo
.dsBm
.bmHeight
, bitmapInfo
.dsBm
.bmHeight
, ILC_COLOR32
, 4, 4);
285 ImageList_Add(imageList
, imageBitmap
, NULL
);
286 DeleteObject(imageBitmap
);
288 SendMessage(TB_SETIMAGELIST
, 0, (LPARAM
)imageList
);
290 SendMessage(TB_ADDBUTTONSW
, numShownButtons
, (LPARAM
)&tbButtonsAdd
);
295 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSite(REFIID riid
, void **ppvSite
)
297 if (fDockSite
== NULL
)
299 return fDockSite
->QueryInterface(riid
, ppvSite
);
302 HRESULT STDMETHODCALLTYPE
CToolsBand::GetWindow(HWND
*lphwnd
)
310 HRESULT STDMETHODCALLTYPE
CToolsBand::ContextSensitiveHelp(BOOL fEnterMode
)
316 HRESULT STDMETHODCALLTYPE
CToolsBand::CloseDW(DWORD dwReserved
)
328 HRESULT STDMETHODCALLTYPE
CToolsBand::ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
333 HRESULT STDMETHODCALLTYPE
CToolsBand::ShowDW(BOOL fShow
)
345 HRESULT STDMETHODCALLTYPE
CToolsBand::HasFocusIO()
350 HRESULT STDMETHODCALLTYPE
CToolsBand::TranslateAcceleratorIO(LPMSG lpMsg
)
355 HRESULT STDMETHODCALLTYPE
CToolsBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
360 HRESULT STDMETHODCALLTYPE
CToolsBand::GetClassID(CLSID
*pClassID
)
365 HRESULT STDMETHODCALLTYPE
CToolsBand::IsDirty()
370 HRESULT STDMETHODCALLTYPE
CToolsBand::Load(IStream
*pStm
)
375 HRESULT STDMETHODCALLTYPE
CToolsBand::Save(IStream
*pStm
, BOOL fClearDirty
)
380 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
385 LRESULT
CToolsBand::OnGetButtonInfo(UINT idControl
, NMHDR
*pNMHDR
, BOOL
&bHandled
)
387 TBNOTIFYW
*pTBntf
= reinterpret_cast<TBNOTIFYW
*>(pNMHDR
);
389 if (pTBntf
->iItem
>= 0 && pTBntf
->iItem
< (numShownButtons
+ numHiddenButtons
))
391 pTBntf
->tbButton
= tbButtonsAdd
[pTBntf
->iItem
];
399 HRESULT
CreateToolsBar(REFIID riid
, void **ppv
)
401 CComObject
<CToolsBand
> *theMenuBar
;
407 ATLTRY (theMenuBar
= new CComObject
<CToolsBand
>);
408 if (theMenuBar
== NULL
)
409 return E_OUTOFMEMORY
;
410 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));