4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /*****************************************************************************
24 ** ITaskBand ****************************************************************
25 *****************************************************************************/
27 const GUID CLSID_ITaskBand
= { 0x68284FAA, 0x6A48, 0x11D0, { 0x8C, 0x78, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0xB4 } };
30 public CComCoClass
<CTaskBand
>,
31 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
32 public IObjectWithSite
,
36 public IPersistStream
,
37 public IWinEventHandler
,
38 public IOleCommandTarget
40 CComPtr
<ITrayWindow
> m_Tray
;
41 CComPtr
<IUnknown
> m_Site
;
54 virtual ~CTaskBand() { }
56 virtual HRESULT STDMETHODCALLTYPE
GetRebarBandID(
59 if (m_BandID
!= (DWORD
) -1)
61 if (pdwBandID
!= NULL
)
62 *pdwBandID
= m_BandID
;
70 /*****************************************************************************/
72 virtual HRESULT STDMETHODCALLTYPE
GetWindow(
76 /* NOTE: We have to return the tray window here so that ITaskBarClient
77 knows the parent window of the Rebar control it creates when
78 calling ITaskBarClient::SetDeskBarSite()! However, once we
79 created a window we return the task switch window! */
83 *phwnd
= m_Tray
->GetHWND();
85 TRACE("ITaskBand::GetWindow(0x%p->0x%p)\n", phwnd
, *phwnd
);
93 virtual HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(
96 /* FIXME: Implement */
100 virtual HRESULT STDMETHODCALLTYPE
ShowDW(
103 /* We don't do anything... */
107 virtual HRESULT STDMETHODCALLTYPE
CloseDW(
110 /* We don't do anything... */
114 virtual HRESULT STDMETHODCALLTYPE
ResizeBorderDW(
116 IUnknown
*punkToolbarSite
,
119 /* No need to implement this method */
123 virtual HRESULT STDMETHODCALLTYPE
GetBandInfo(
126 IN OUT DESKBANDINFO
*pdbi
)
128 TRACE("ITaskBand::GetBandInfo(0x%x,0x%x,0x%p) hWnd=0x%p\n", dwBandID
, dwViewMode
, pdbi
, m_hWnd
);
132 /* The task band never has a title */
133 pdbi
->dwMask
&= ~DBIM_TITLE
;
135 /* NOTE: We don't return DBIMF_UNDELETEABLE here, the band site will
136 handle us differently and add this flag for us. The reason for
137 this is future changes that might allow it to be deletable.
138 We want the band site to be in charge of this decision rather
140 /* FIXME: What about DBIMF_NOGRIPPER and DBIMF_ALWAYSGRIPPER */
141 pdbi
->dwModeFlags
= DBIMF_VARIABLEHEIGHT
;
143 if (dwViewMode
& DBIF_VIEWMODE_VERTICAL
)
145 pdbi
->ptIntegral
.y
= 1;
146 pdbi
->ptMinSize
.y
= 1;
147 /* FIXME: Get the button metrics from the task bar object!!! */
148 pdbi
->ptMinSize
.x
= (3 * GetSystemMetrics(SM_CXEDGE
) / 2) + /* FIXME: Might be wrong if only one column! */
149 GetSystemMetrics(SM_CXSIZE
) + (2 * GetSystemMetrics(SM_CXEDGE
)); /* FIXME: Min button size, query!!! */
153 pdbi
->ptMinSize
.y
= GetSystemMetrics(SM_CYSIZE
) + (2 * GetSystemMetrics(SM_CYEDGE
)); /* FIXME: Query */
154 pdbi
->ptIntegral
.y
= pdbi
->ptMinSize
.y
+ (3 * GetSystemMetrics(SM_CYEDGE
) / 2); /* FIXME: Query metrics */
155 /* We're not going to allow task bands where not even the minimum button size fits into the band */
156 pdbi
->ptMinSize
.x
= pdbi
->ptIntegral
.y
;
159 /* Ignored: pdbi->ptMaxSize.x */
160 pdbi
->ptMaxSize
.y
= -1;
162 /* FIXME: We should query the height from the task bar object!!! */
163 pdbi
->ptActual
.y
= GetSystemMetrics(SM_CYSIZE
) + (2 * GetSystemMetrics(SM_CYEDGE
));
165 /* Save the band ID for future use in case we need to check whether a given band
169 TRACE("H: %d, Min: %d,%d, Integral.y: %d Actual: %d,%d\n", (dwViewMode
& DBIF_VIEWMODE_VERTICAL
) == 0,
170 pdbi
->ptMinSize
.x
, pdbi
->ptMinSize
.y
, pdbi
->ptIntegral
.y
,
171 pdbi
->ptActual
.x
, pdbi
->ptActual
.y
);
179 /*****************************************************************************/
180 // *** IOleCommandTarget methods ***
181 virtual HRESULT STDMETHODCALLTYPE
QueryStatus(const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
187 virtual HRESULT STDMETHODCALLTYPE
Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
189 if (IsEqualIID(*pguidCmdGroup
, IID_IBandSite
))
194 if (IsEqualIID(*pguidCmdGroup
, IID_IDeskBand
))
203 /*****************************************************************************/
205 virtual HRESULT STDMETHODCALLTYPE
SetClient(
206 IN IUnknown
*punkClient
)
208 TRACE("IDeskBar::SetClient(0x%p)\n", punkClient
);
212 virtual HRESULT STDMETHODCALLTYPE
GetClient(
213 OUT IUnknown
**ppunkClient
)
215 TRACE("IDeskBar::GetClient(0x%p)\n", ppunkClient
);
219 virtual HRESULT STDMETHODCALLTYPE
OnPosRectChangeDB(
222 TRACE("IDeskBar::OnPosRectChangeDB(0x%p=(%d,%d,%d,%d))\n", prc
, prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
223 if (prc
->bottom
- prc
->top
== 0)
229 /*****************************************************************************/
231 virtual HRESULT STDMETHODCALLTYPE
GetClassID(
234 TRACE("ITaskBand::GetClassID(0x%p)\n", pClassID
);
235 /* We're going to return the (internal!) CLSID of the task band interface */
236 *pClassID
= CLSID_ITaskBand
;
240 virtual HRESULT STDMETHODCALLTYPE
IsDirty()
242 /* The object hasn't changed since the last save! */
246 virtual HRESULT STDMETHODCALLTYPE
Load(
249 TRACE("ITaskBand::Load called\n");
254 virtual HRESULT STDMETHODCALLTYPE
Save(
262 virtual HRESULT STDMETHODCALLTYPE
GetSizeMax(
263 OUT ULARGE_INTEGER
*pcbSize
)
265 TRACE("ITaskBand::GetSizeMax called\n");
266 /* We don't need any space for the task band */
267 pcbSize
->QuadPart
= 0;
271 /*****************************************************************************/
273 virtual HRESULT STDMETHODCALLTYPE
SetSite(IUnknown
*pUnkSite
)
275 HRESULT hRet
= E_FAIL
;
277 TRACE("ITaskBand::SetSite(0x%p)\n", pUnkSite
);
279 /* Release the current site */
288 if (pUnkSite
!= NULL
)
290 CComPtr
<IOleWindow
> OleWindow
;
292 /* Check if the site supports IOleWindow */
293 hRet
= pUnkSite
->QueryInterface(IID_PPV_ARG(IOleWindow
, &OleWindow
));
296 HWND hWndParent
= NULL
;
298 hRet
= OleWindow
->GetWindow(&hWndParent
);
301 /* Attempt to create the task switch window */
303 TRACE("CreateTaskSwitchWnd(Parent: 0x%p)\n", hWndParent
);
304 m_hWnd
= CreateTaskSwitchWnd(hWndParent
, m_Tray
);
312 TRACE("CreateTaskSwitchWnd() failed!\n");
319 TRACE("Querying IOleWindow failed: 0x%x\n", hRet
);
326 virtual HRESULT STDMETHODCALLTYPE
GetSite(
330 TRACE("ITaskBand::GetSite(0x%p,0x%p)\n", riid
, ppvSite
);
334 return m_Site
->QueryInterface(riid
, ppvSite
);
341 /*****************************************************************************/
343 virtual HRESULT STDMETHODCALLTYPE
ProcessMessage(
348 OUT LRESULT
*plrResult
)
350 TRACE("ITaskBand: IWinEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p)\n", hWnd
, uMsg
, wParam
, lParam
, plrResult
);
354 virtual HRESULT STDMETHODCALLTYPE
ContainsWindow(
357 if (hWnd
== m_hWnd
||
358 IsChild(m_hWnd
, hWnd
))
360 TRACE("ITaskBand::ContainsWindow(0x%p) returns S_OK\n", hWnd
);
367 virtual HRESULT STDMETHODCALLTYPE
OnWinEvent(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
373 virtual HRESULT STDMETHODCALLTYPE
IsWindowOwner(HWND hWnd
)
375 return (hWnd
== m_hWnd
) ? S_OK
: S_FALSE
;
378 /*****************************************************************************/
380 HRESULT STDMETHODCALLTYPE
_Init(IN OUT ITrayWindow
*tray
)
383 m_BandID
= (DWORD
) -1;
387 DECLARE_NOT_AGGREGATABLE(CTaskBand
)
389 DECLARE_PROTECT_FINAL_CONSTRUCT()
390 BEGIN_COM_MAP(CTaskBand
)
391 COM_INTERFACE_ENTRY2_IID(IID_IOleWindow
, IOleWindow
, IDeskBand
)
392 COM_INTERFACE_ENTRY_IID(IID_IDeskBand
, IDeskBand
)
393 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite
, IObjectWithSite
)
394 COM_INTERFACE_ENTRY_IID(IID_IPersist
, IPersist
)
395 COM_INTERFACE_ENTRY_IID(IID_IPersistStream
, IPersistStream
)
396 COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler
, IWinEventHandler
)
397 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget
, IOleCommandTarget
)
401 ITaskBand
* CreateTaskBand(IN OUT ITrayWindow
*Tray
)
405 CTaskBand
* tb
= new CComObject
<CTaskBand
>();
412 hr
= tb
->_Init(Tray
);
414 if (FAILED_UNEXPECTEDLY(hr
))