ReactOS  0.4.13-dev-982-g9853eab
toolsband.cpp
Go to the documentation of this file.
1 /*
2  * ReactOS Explorer
3  *
4  * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 /*
22 Implements the toolbar band of a cabinet window
23 */
24 
25 #include "precomp.h"
26 
27 class CToolsBand :
28  public CWindowImpl<CToolsBand, CWindow, CControlWinTraits>,
29  public CComObjectRootEx<CComMultiThreadModelNoCS>,
30  public IDeskBand,
31  public IObjectWithSite,
32  public IInputObject,
33  public IPersistStream
34 {
35 private:
39 public:
40  CToolsBand();
41  virtual ~CToolsBand();
42 public:
43  // *** IDeskBand methods ***
44  virtual HRESULT STDMETHODCALLTYPE GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi);
45 
46  // *** IObjectWithSite methods ***
47  virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown* pUnkSite);
48  virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite);
49 
50  // *** IOleWindow methods ***
51  virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd);
53 
54  // *** IDockingWindow methods ***
56  virtual HRESULT STDMETHODCALLTYPE ResizeBorderDW(const RECT* prcBorder, IUnknown* punkToolbarSite, BOOL fReserved);
57  virtual HRESULT STDMETHODCALLTYPE ShowDW(BOOL fShow);
58 
59  // *** IInputObject methods ***
62  virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg);
63 
64  // *** IPersist methods ***
65  virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID);
66 
67  // *** IPersistStream methods ***
69  virtual HRESULT STDMETHODCALLTYPE Load(IStream *pStm);
70  virtual HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty);
72 
73  // message handlers
74  LRESULT OnGetButtonInfo(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
75 
77 // MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
78 // MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
81 
83  COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
86  COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
87  COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
91 };
92 
94  : fDockSite(NULL)
95 {
96 }
97 
99 {
100 }
101 
103 {
104  RECT actualRect;
105  POINTL actualSize;
106  POINTL idealSize;
107  POINTL maxSize;
108  POINTL itemSize;
109 
110  ::GetWindowRect(m_hWnd, &actualRect);
111  actualSize.x = actualRect.right - actualRect.left;
112  actualSize.y = actualRect.bottom - actualRect.top;
113 
114  /* Obtain the ideal size, to be used as min and max */
116  SendMessageW(m_hWnd, TB_GETMAXSIZE, 0, reinterpret_cast<LPARAM>(&maxSize));
117 
118  idealSize = maxSize;
119  SendMessageW(m_hWnd, TB_GETIDEALSIZE, FALSE, reinterpret_cast<LPARAM>(&idealSize));
120 
121  /* Obtain the button size, to be used as the integral size */
123  itemSize.x = GET_X_LPARAM(size);
124  itemSize.y = GET_Y_LPARAM(size);
125 
126  if (pdbi->dwMask & DBIM_MINSIZE)
127  {
128  pdbi->ptMinSize = idealSize;
129  }
130  if (pdbi->dwMask & DBIM_MAXSIZE)
131  {
132  pdbi->ptMaxSize = maxSize;
133  }
134  if (pdbi->dwMask & DBIM_INTEGRAL)
135  {
136  pdbi->ptIntegral = itemSize;
137  }
138  if (pdbi->dwMask & DBIM_ACTUAL)
139  {
140  pdbi->ptActual = actualSize;
141  }
142  if (pdbi->dwMask & DBIM_TITLE)
143  wcscpy(pdbi->wszTitle, L"");
144  if (pdbi->dwMask & DBIM_MODEFLAGS)
145  pdbi->dwModeFlags = DBIMF_UNDELETEABLE;
146  if (pdbi->dwMask & DBIM_BKCOLOR)
147  pdbi->crBkgnd = 0;
148  return S_OK;
149 }
150 
151 static const int backImageIndex = 0;
152 static const int forwardImageIndex = 1;
153 static const int favoritesImageIndex = 2;
154 // 3
155 // 4
156 static const int cutImageIndex = 5;
157 static const int copyImageIndex = 6;
158 static const int pasteImageIndex = 7;
159 static const int undoImageIndex = 8;
160 //static const int redoImageIndex = 9;
161 static const int deleteImageIndex = 10;
162 // 11
163 // 12
164 // 13
165 // 14
166 static const int propertiesImageIndex = 15;
167 // 16
168 static const int searchImageIndex = 17;
169 // 18
170 // 19
171 // 20
172 // 21
173 static const int viewsImageIndex = 22;
174 // 23
175 // 24
176 // 25
177 // 26
178 // 27
179 static const int upImageIndex = 28;
180 static const int mapDriveImageIndex = 29;
181 static const int disconnectImageIndex = 30;
182 // 31
183 //static const int viewsAltImageIndex = 32; // same image as viewsImageIndex
184 // 33
185 // 34
186 // 35
187 // 36
188 // 37
189 //static const int viewsAlt2ImageIndex = 38; // same image as viewsAltImageIndex & viewsImageIndex
190 // 39
191 // 40
192 // 41
193 // 42
194 static const int foldersImageIndex = 43;
195 static const int moveToImageIndex = 44;
196 static const int copyToImageIndex = 45;
197 static const int folderOptionsImageIndex = 46;
198 
223 };
224 
225 const int numShownButtons = 13;
226 const int numHiddenButtons = 13;
228 {
232  { 6, -1, TBSTATE_ENABLED, BTNS_SEP },
235  { 6, -1, TBSTATE_ENABLED, BTNS_SEP },
240  { 6, -1, TBSTATE_ENABLED, BTNS_SEP },
242 
256 };
257 
259  HWND parentWindow;
260  HWND toolbar;
261  HRESULT hResult;
262 
264 
265  if (pUnkSite == NULL)
266  return S_OK;
267  hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IDockingWindowSite, &fDockSite));
268  if (FAILED_UNEXPECTEDLY(hResult))
269  return hResult;
270  parentWindow = NULL;
271  hResult = IUnknown_GetWindow(pUnkSite, &parentWindow);
272  if (FAILED(hResult) || !::IsWindow(parentWindow))
273  return E_FAIL;
274 
275  toolbar = CreateWindowEx(
281  0, 0, 500, 20, parentWindow, NULL, _AtlBaseModule.GetModuleInstance(), 0);
282  if (toolbar == NULL)
283  return E_FAIL;
284  SubclassWindow(toolbar);
286 
291 
292  m_himlNormal = ImageList_LoadImageW(_AtlBaseModule.GetResourceInstance(),
294  0, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_DEFAULTSIZE | LR_CREATEDIBSECTION);
295 
296  m_himlHot = ImageList_LoadImageW(_AtlBaseModule.GetResourceInstance(),
298  0, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_DEFAULTSIZE | LR_CREATEDIBSECTION);
299 
303 
304  return hResult;
305 }
306 
308 {
309  if (fDockSite == NULL)
310  return E_FAIL;
311  return fDockSite->QueryInterface(riid, ppvSite);
312 }
313 
315 {
316  if (lphwnd == NULL)
317  return E_POINTER;
318  *lphwnd = m_hWnd;
319  return S_OK;
320 }
321 
323 {
324  return E_NOTIMPL;
325 }
326 
328 {
329  ShowDW(FALSE);
330 
331  if (IsWindow())
332  DestroyWindow();
333 
334  m_hWnd = NULL;
335 
336  if (fDockSite)
337  fDockSite.Release();
338 
339  if (m_himlNormal)
341 
342  if (m_himlHot)
344 
345  return S_OK;
346 }
347 
348 HRESULT STDMETHODCALLTYPE CToolsBand::ResizeBorderDW(const RECT* prcBorder, IUnknown* punkToolbarSite, BOOL fReserved)
349 {
350  return E_NOTIMPL;
351 }
352 
354 {
355  if (m_hWnd)
356  {
357  if (fShow)
359  else
361  }
362  return S_OK;
363 }
364 
366 {
367  return S_FALSE;
368 }
369 
371 {
372  return S_FALSE;
373 }
374 
376 {
377  return E_NOTIMPL;
378 }
379 
381 {
382  return E_NOTIMPL;
383 }
384 
386 {
387  return E_NOTIMPL;
388 }
389 
391 {
392  return E_NOTIMPL;
393 }
394 
396 {
397  return E_NOTIMPL;
398 }
399 
401 {
402  return E_NOTIMPL;
403 }
404 
405 LRESULT CToolsBand::OnGetButtonInfo(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled)
406 {
407  TBNOTIFYW *pTBntf = reinterpret_cast<TBNOTIFYW *>(pNMHDR);
408 
409  if (pTBntf->iItem >= 0 && pTBntf->iItem < (numShownButtons + numHiddenButtons))
410  {
411  pTBntf->tbButton = tbButtonsAdd[pTBntf->iItem];
412  return TRUE;
413  }
414  else
415  return FALSE;
416  return 0;
417 }
418 
420 {
421  return ShellObjectCreator<CToolsBand>(riid, ppv);
422 }
423 
DBIM_BKCOLOR struct tagDESKBANDINFO DESKBANDINFO
static const int gHistoryCommandID
#define TBSTYLE_EX_DOUBLEBUFFER
Definition: commctrl.h:986
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define TB_SETHOTIMAGELIST
Definition: commctrl.h:1126
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IDS_STANDARD_TOOLBAR
Definition: resource.h:120
#define TB_BUTTONSTRUCTSIZE
Definition: commctrl.h:1106
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define IDM_GOTO_UPONELEVEL
Definition: resource.h:47
virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite)
Definition: toolsband.cpp:258
#define IDM_GOTO_FORWARD
Definition: resource.h:46
virtual HRESULT STDMETHODCALLTYPE GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi)
Definition: toolsband.cpp:102
virtual HRESULT STDMETHODCALLTYPE Load(IStream *pStm)
Definition: toolsband.cpp:390
#define TBSTYLE_EX_HIDECLIPPEDBUTTONS
Definition: commctrl.h:985
#define BTNS_WHOLEDROPDOWN
Definition: commctrl.h:979
#define NOTIFY_HANDLER(id, cd, func)
Definition: atlwin.h:1861
static const int viewsImageIndex
Definition: toolsband.cpp:173
#define SW_HIDE
Definition: winuser.h:762
REFIID riid
Definition: precomp.h:44
#define TB_ADDSTRINGW
Definition: commctrl.h:1104
#define TBSTYLE_TRANSPARENT
Definition: commctrl.h:968
static const int gMoveToCommandID
HIMAGELIST m_himlNormal
Definition: toolsband.cpp:37
const GUID IID_IPersist
Definition: proxy.cpp:14
virtual ~CToolsBand()
Definition: toolsband.cpp:98
virtual HRESULT STDMETHODCALLTYPE ShowDW(BOOL fShow)
Definition: toolsband.cpp:353
static const int copyImageIndex
Definition: toolsband.cpp:157
static const int gSearchCommandID
#define IDM_TOOLS_MAPNETWORKDRIVE
Definition: resource.h:53
BOOL IsWindow() const
Definition: atlwin.h:879
static const int gCutCommandID
REFIID LPVOID * ppv
Definition: atlbase.h:39
virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode)
Definition: toolsband.cpp:322
#define TOOLBARCLASSNAMEW
Definition: commctrl.h:915
#define IDB_SHELL_EXPLORER_LG_HOT
Definition: resource.h:146
LONG top
Definition: windef.h:292
#define TBSTYLE_EX_DRAWDDARROWS
Definition: commctrl.h:981
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
static const int deleteImageIndex
Definition: toolsband.cpp:161
#define SM_CXEDGE
Definition: winuser.h:998
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
virtual HRESULT STDMETHODCALLTYPE ResizeBorderDW(const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved)
Definition: toolsband.cpp:348
LONG left
Definition: windef.h:291
#define TB_GETMAXSIZE
Definition: commctrl.h:1161
#define WS_CLIPCHILDREN
Definition: pedump.c:619
LONG right
Definition: windef.h:293
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
HRESULT WINAPI IUnknown_GetWindow(IUnknown *lpUnknown, HWND *lphWnd)
Definition: ordinal.c:1283
static const int gStopCommandID
LONG y
Definition: windef.h:315
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:928
#define IDM_GOTO_BACK
Definition: resource.h:45
#define TB_SETMAXTEXTROWS
Definition: commctrl.h:1134
#define TBNOTIFYW
Definition: commctrl.h:1403
#define CCS_NODIVIDER
Definition: commctrl.h:2220
#define BTNS_BUTTON
Definition: commctrl.h:970
static const int gHomeCommandID
#define TBSTYLE_REGISTERDROP
Definition: commctrl.h:967
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
static const int propertiesImageIndex
Definition: toolsband.cpp:166
#define TB_AUTOSIZE
Definition: commctrl.h:1109
static const int moveToImageIndex
Definition: toolsband.cpp:195
const int numShownButtons
Definition: toolsband.cpp:225
#define CreateWindowEx
Definition: winuser.h:5656
virtual HRESULT STDMETHODCALLTYPE CloseDW(DWORD dwReserved)
Definition: toolsband.cpp:327
#define S_FALSE
Definition: winerror.h:2357
BOOL GetWindowRect(LPRECT lpRect) const
Definition: atlwin.h:764
static const int gUndoCommandID
virtual HRESULT STDMETHODCALLTYPE HasFocusIO()
Definition: toolsband.cpp:365
#define IDM_TOOLS_FOLDEROPTIONS
Definition: resource.h:56
static const int gFoldersCommandID
smooth NULL
Definition: ftsmooth.c:416
static const int mapDriveImageIndex
Definition: toolsband.cpp:180
LONG_PTR LPARAM
Definition: windef.h:208
#define CCS_TOP
Definition: commctrl.h:2214
#define CCS_NOPARENTALIGN
Definition: commctrl.h:2218
static const int disconnectImageIndex
Definition: toolsband.cpp:181
#define BTNS_SHOWTEXT
Definition: commctrl.h:978
#define TB_GETIDEALSIZE
Definition: commctrl.h:1256
#define SW_SHOW
Definition: winuser.h:769
const int numHiddenButtons
Definition: toolsband.cpp:226
HIMAGELIST m_himlHot
Definition: toolsband.cpp:38
#define TBN_GETBUTTONINFOW
Definition: commctrl.h:1315
static const int gPropertiesCommandID
static const int gFullScreenCommandID
#define TB_SETIMAGELIST
Definition: commctrl.h:1122
#define TB_GETBUTTONSIZE
Definition: commctrl.h:1132
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:541
static const int searchImageIndex
Definition: toolsband.cpp:168
#define IDM_TOOLS_DISCONNECTNETWORKDRIVE
Definition: resource.h:54
GLsizeiptr size
Definition: glext.h:5919
#define BTNS_SEP
Definition: commctrl.h:971
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
virtual HRESULT STDMETHODCALLTYPE IsDirty()
Definition: toolsband.cpp:385
static const int pasteImageIndex
Definition: toolsband.cpp:158
LONG HRESULT
Definition: typedefs.h:77
#define END_MSG_MAP()
Definition: atlwin.h:1789
static const int forwardImageIndex
Definition: toolsband.cpp:152
static const int cutImageIndex
Definition: toolsband.cpp:156
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
#define RGB(r, g, b)
Definition: wingdi.h:2925
static const int backImageIndex
Definition: toolsband.cpp:151
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
const IID IID_IObjectWithSite
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG x
Definition: windef.h:314
virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize)
Definition: toolsband.cpp:400
#define TBSTYLE_TOOLTIPS
Definition: commctrl.h:961
static const int gCopyCommandID
LRESULT OnGetButtonInfo(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled)
Definition: toolsband.cpp:405
virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID)
Definition: toolsband.cpp:380
const GUID IID_IPersistStream
Definition: proxy.cpp:13
#define CCS_NORESIZE
Definition: commctrl.h:2217
virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg)
Definition: toolsband.cpp:370
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
HRESULT CToolsBand_CreateInstance(REFIID riid, void **ppv)
Definition: toolsband.cpp:419
#define BTNS_DROPDOWN
Definition: commctrl.h:975
static const int copyToImageIndex
Definition: toolsband.cpp:196
#define TB_ADDBUTTONSW
Definition: commctrl.h:1238
static const int gViewsCommandID
HWND m_hWnd
Definition: atlwin.h:268
BOOL DestroyWindow()
Definition: atlwin.h:428
#define WM_USER
Definition: winuser.h:1877
static const int gPasteCommandID
virtual HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty)
Definition: toolsband.cpp:395
#define S_OK
Definition: intsafe.h:59
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1265
#define GetModuleHandle
Definition: winbase.h:3641
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:561
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
void Release()
Definition: atlcomcli.h:140
#define E_NOTIMPL
Definition: ddrawi.h:99
#define LR_CREATEDIBSECTION
Definition: winuser.h:1088
#define IDB_SHELL_EXPLORER_LG
Definition: resource.h:145
static const int gFavoritesCommandID
StandardToolbarButtons
Definition: toolsband.cpp:199
unsigned int UINT
Definition: ndis.h:50
#define IMAGE_BITMAP
Definition: winuser.h:211
static const int foldersImageIndex
Definition: toolsband.cpp:194
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1770
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
static const int favoritesImageIndex
Definition: toolsband.cpp:153
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
HIMAGELIST WINAPI ImageList_LoadImageW(HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow, COLORREF clrMask, UINT uType, UINT uFlags)
Definition: imagelist.c:2208
#define IDM_VIEW_REFRESH
Definition: resource.h:49
#define TBSTATE_ENABLED
Definition: commctrl.h:946
static const int upImageIndex
Definition: toolsband.cpp:179
const GUID IID_IOleWindow
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1048
#define TBSTYLE_EX_MIXEDBUTTONS
Definition: commctrl.h:984
LONG bottom
Definition: windef.h:294
CComPtr< IDockingWindowSite > fDockSite
Definition: toolsband.cpp:36
virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite)
Definition: toolsband.cpp:307
#define END_COM_MAP()
Definition: atlcom.h:552
static const int folderOptionsImageIndex
Definition: toolsband.cpp:197
LONG_PTR LRESULT
Definition: windef.h:209
#define E_POINTER
Definition: winerror.h:2365
TBBUTTON tbButtonsAdd[numShownButtons+numHiddenButtons]
Definition: toolsband.cpp:227
#define WS_VISIBLE
Definition: pedump.c:620
static const int undoImageIndex
Definition: toolsband.cpp:159
#define TBSTYLE_LIST
Definition: commctrl.h:965
virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd)
Definition: toolsband.cpp:314
static const int gCopyToCommandID
#define TBSTYLE_FLAT
Definition: commctrl.h:964
#define TB_SETEXTENDEDSTYLE
Definition: commctrl.h:1162
static const int gDeleteCommandID
virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg)
Definition: toolsband.cpp:375