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 CComPtr
<IDockingWindowSite
> fDockSite
;
41 GUID fExecCommandCategory
;
42 CComPtr
<IOleCommandTarget
> fExecCommandTarget
;
45 virtual ~CToolsBand();
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()
106 HRESULT STDMETHODCALLTYPE
CToolsBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
114 ::GetWindowRect(m_hWnd
, &actualRect
);
115 actualSize
.x
= actualRect
.right
- actualRect
.left
;
116 actualSize
.y
= actualRect
.bottom
- actualRect
.top
;
118 /* Obtain the ideal size, to be used as min and max */
119 SendMessageW(m_hWnd
, TB_AUTOSIZE
, 0, 0);
120 SendMessageW(m_hWnd
, TB_GETMAXSIZE
, 0, reinterpret_cast<LPARAM
>(&maxSize
));
123 SendMessageW(m_hWnd
, TB_GETIDEALSIZE
, FALSE
, reinterpret_cast<LPARAM
>(&idealSize
));
125 /* Obtain the button size, to be used as the integral size */
126 DWORD size
= SendMessageW(m_hWnd
, TB_GETBUTTONSIZE
, 0, 0);
127 itemSize
.x
= GET_X_LPARAM(size
);
128 itemSize
.y
= GET_Y_LPARAM(size
);
130 if (pdbi
->dwMask
& DBIM_MINSIZE
)
132 pdbi
->ptMinSize
= idealSize
;
134 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
136 pdbi
->ptMaxSize
= maxSize
;
138 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
140 pdbi
->ptIntegral
= itemSize
;
142 if (pdbi
->dwMask
& DBIM_ACTUAL
)
144 pdbi
->ptActual
= actualSize
;
146 if (pdbi
->dwMask
& DBIM_TITLE
)
147 wcscpy(pdbi
->wszTitle
, L
"");
148 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
149 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
150 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
155 static const int backImageIndex
= 0;
156 static const int forwardImageIndex
= 1;
157 static const int favoritesImageIndex
= 2;
160 static const int cutImageIndex
= 5;
161 static const int copyImageIndex
= 6;
162 static const int pasteImageIndex
= 7;
163 static const int undoImageIndex
= 8;
164 static const int redoImageIndex
= 9;
165 static const int deleteImageIndex
= 10;
170 static const int propertiesImageIndex
= 15;
172 static const int searchImageIndex
= 17;
177 static const int viewsImageIndex
= 22;
183 static const int upImageIndex
= 28;
184 static const int mapDriveImageIndex
= 29;
185 static const int disconnectImageIndex
= 30;
187 static const int viewsAltImageIndex
= 32; // same image as viewsImageIndex
193 static const int viewsAlt2ImageIndex
= 38; // same image as viewsAltImageIndex & viewsImageIndex
198 static const int foldersImageIndex
= 43;
199 static const int moveToImageIndex
= 44;
200 static const int copyToImageIndex
= 45;
201 static const int folderOptionsImageIndex
= 46;
203 enum StandardToolbarButtons
{
226 BtnIdx_FolderOptions
,
229 const int numShownButtons
= 13;
230 const int numHiddenButtons
= 13;
231 TBBUTTON tbButtonsAdd
[numShownButtons
+ numHiddenButtons
] =
233 { backImageIndex
, IDM_GOTO_BACK
, TBSTATE_ENABLED
, BTNS_DROPDOWN
| BTNS_SHOWTEXT
, { 0 }, 0, BtnIdx_Back
},
234 { forwardImageIndex
, IDM_GOTO_FORWARD
, TBSTATE_ENABLED
, BTNS_DROPDOWN
, { 0 }, 0, BtnIdx_Forward
},
235 { upImageIndex
, IDM_GOTO_UPONELEVEL
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Up
},
236 { 6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
237 { searchImageIndex
, gSearchCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, { 0 }, 0, BtnIdx_Search
},
238 { foldersImageIndex
, gFoldersCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, { 0 }, 0, BtnIdx_Folders
},
239 { 6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
240 { moveToImageIndex
, gMoveToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_MoveTo
},
241 { copyToImageIndex
, gCopyToCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_CopyTo
},
242 { deleteImageIndex
, gDeleteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Delete
},
243 { undoImageIndex
, gUndoCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Undo
},
244 { 6, -1, TBSTATE_ENABLED
, BTNS_SEP
},
245 { viewsImageIndex
, gViewsCommandID
, TBSTATE_ENABLED
, BTNS_WHOLEDROPDOWN
, { 0 }, 0, BtnIdx_Views
},
247 { 0, gStopCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Stop
},
248 { 0, IDM_VIEW_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Refresh
},
249 { 0, gHomeCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Home
},
250 { mapDriveImageIndex
, IDM_TOOLS_MAPNETWORKDRIVE
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_MapDrive
},
251 { disconnectImageIndex
, IDM_TOOLS_DISCONNECTNETWORKDRIVE
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Disconnect
},
252 { favoritesImageIndex
, gFavoritesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
| BTNS_SHOWTEXT
, { 0 }, 0, BtnIdx_Favorites
},
253 { 0, gHistoryCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_History
},
254 { 0, gFullScreenCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_FullScreen
},
255 { propertiesImageIndex
, gPropertiesCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Properties
},
256 { cutImageIndex
, gCutCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Cut
},
257 { copyImageIndex
, gCopyCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Copy
},
258 { pasteImageIndex
, gPasteCommandID
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_Paste
},
259 { folderOptionsImageIndex
, IDM_TOOLS_FOLDEROPTIONS
, TBSTATE_ENABLED
, BTNS_BUTTON
, { 0 }, 0, BtnIdx_FolderOptions
},
262 HRESULT STDMETHODCALLTYPE
CToolsBand::SetSite(IUnknown
* pUnkSite
){
264 IOleWindow
*oleWindow
;
268 if(fDockSite
) fDockSite
.Release();
270 if (pUnkSite
== NULL
)
272 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fDockSite
));
276 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IOleWindow
, &oleWindow
));
277 if (SUCCEEDED(hResult
))
279 oleWindow
->GetWindow(&parentWindow
);
280 oleWindow
->Release();
282 if (!::IsWindow(parentWindow
))
285 toolbar
= CreateWindowEx(
286 TBSTYLE_EX_DOUBLEBUFFER
,
287 TOOLBARCLASSNAMEW
, NULL
,
288 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
|
289 TBSTYLE_TOOLTIPS
| TBSTYLE_TRANSPARENT
| TBSTYLE_REGISTERDROP
| TBSTYLE_LIST
| TBSTYLE_FLAT
|
290 CCS_NODIVIDER
| CCS_NOPARENTALIGN
| CCS_NORESIZE
| CCS_TOP
,
291 0, 0, 500, 20, parentWindow
, NULL
, _AtlBaseModule
.GetModuleInstance(), 0);
294 SubclassWindow(toolbar
);
295 SendMessage(TB_ADDSTRINGW
, (WPARAM
) GetModuleHandle(L
"browseui.dll"), IDS_STANDARD_TOOLBAR
);
297 SendMessage(WM_USER
+ 100, GetSystemMetrics(SM_CXEDGE
) / 2, 0);
298 SendMessage(TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
299 SendMessage(TB_SETMAXTEXTROWS
, 1, 0);
300 SendMessage(TB_SETEXTENDEDSTYLE
, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS
| TBSTYLE_EX_MIXEDBUTTONS
| TBSTYLE_EX_DRAWDDARROWS
);
302 HINSTANCE shell32Instance
= GetModuleHandle(_T("shell32.dll"));
303 HBITMAP imgNormal
= reinterpret_cast<HBITMAP
>(
304 LoadImage(shell32Instance
, MAKEINTRESOURCE(214),
305 IMAGE_BITMAP
, 0, 0, LR_DEFAULTSIZE
| LR_CREATEDIBSECTION
));
307 HBITMAP imgHot
= reinterpret_cast<HBITMAP
>(
308 LoadImage(shell32Instance
, MAKEINTRESOURCE(215),
309 IMAGE_BITMAP
, 0, 0, LR_DEFAULTSIZE
| LR_CREATEDIBSECTION
));
311 if (imgNormal
&& imgHot
)
314 GetObjectW(imgNormal
, sizeof(bitmapInfo
), &bitmapInfo
);
315 HIMAGELIST himlNormal
= ImageList_Create(bitmapInfo
.bmHeight
, bitmapInfo
.bmHeight
, ILC_COLOR32
, 4, 4);
317 ImageList_Add(himlNormal
, imgNormal
, NULL
);
318 DeleteObject(imgNormal
);
320 GetObjectW(imgHot
, sizeof(bitmapInfo
), &bitmapInfo
);
321 HIMAGELIST himlHot
= ImageList_Create(bitmapInfo
.bmHeight
, bitmapInfo
.bmHeight
, ILC_COLOR32
, 4, 4);
323 ImageList_Add(himlHot
, imgHot
, NULL
);
324 DeleteObject(imgHot
);
326 SendMessage(TB_SETIMAGELIST
, 0, (LPARAM
) himlNormal
);
327 SendMessage(TB_SETHOTIMAGELIST
, 0, (LPARAM
) himlHot
);
330 SendMessage(TB_ADDBUTTONSW
, numShownButtons
, (LPARAM
)&tbButtonsAdd
);
335 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSite(REFIID riid
, void **ppvSite
)
337 if (fDockSite
== NULL
)
339 return fDockSite
->QueryInterface(riid
, ppvSite
);
342 HRESULT STDMETHODCALLTYPE
CToolsBand::GetWindow(HWND
*lphwnd
)
350 HRESULT STDMETHODCALLTYPE
CToolsBand::ContextSensitiveHelp(BOOL fEnterMode
)
356 HRESULT STDMETHODCALLTYPE
CToolsBand::CloseDW(DWORD dwReserved
)
365 if (fDockSite
) fDockSite
.Release();
370 HRESULT STDMETHODCALLTYPE
CToolsBand::ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
375 HRESULT STDMETHODCALLTYPE
CToolsBand::ShowDW(BOOL fShow
)
387 HRESULT STDMETHODCALLTYPE
CToolsBand::HasFocusIO()
392 HRESULT STDMETHODCALLTYPE
CToolsBand::TranslateAcceleratorIO(LPMSG lpMsg
)
397 HRESULT STDMETHODCALLTYPE
CToolsBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
402 HRESULT STDMETHODCALLTYPE
CToolsBand::GetClassID(CLSID
*pClassID
)
407 HRESULT STDMETHODCALLTYPE
CToolsBand::IsDirty()
412 HRESULT STDMETHODCALLTYPE
CToolsBand::Load(IStream
*pStm
)
417 HRESULT STDMETHODCALLTYPE
CToolsBand::Save(IStream
*pStm
, BOOL fClearDirty
)
422 HRESULT STDMETHODCALLTYPE
CToolsBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
427 LRESULT
CToolsBand::OnGetButtonInfo(UINT idControl
, NMHDR
*pNMHDR
, BOOL
&bHandled
)
429 TBNOTIFYW
*pTBntf
= reinterpret_cast<TBNOTIFYW
*>(pNMHDR
);
431 if (pTBntf
->iItem
>= 0 && pTBntf
->iItem
< (numShownButtons
+ numHiddenButtons
))
433 pTBntf
->tbButton
= tbButtonsAdd
[pTBntf
->iItem
];
441 HRESULT
CreateToolsBar(REFIID riid
, void **ppv
)
443 CToolsBand
*theToolbar
;
449 ATLTRY(theToolbar
= new CComObject
<CToolsBand
>);
450 if (theToolbar
== NULL
)
451 return E_OUTOFMEMORY
;
452 hResult
= theToolbar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));