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 logo band of a cabinet window. Most remarkable feature is the
29 Add Exec command handlers
30 Properly implement GetBandInfo
31 Fix SetSite to revoke brand band service when site is cleared
34 inline void FillSolidRect(HDC dc
, const RECT
*bounds
)
36 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
39 inline void FillSolidRect(HDC dc
, const RECT
*bounds
, COLORREF clr
)
41 ::SetBkColor(dc
, clr
);
42 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
51 depth
= GetDeviceCaps(tempDC
, BITSPIXEL
) * GetDeviceCaps(tempDC
, PLANES
);
52 ReleaseDC(NULL
, tempDC
);
56 static const int gSmallImageSize
= 22;
57 static const int gMediumImageSize
= 26;
58 static const int gLargeImageSize
= 38;
60 static const int gTrueColorResourceBase
= 240;
61 static const int g256ColorResourceBase
= 245;
63 CBrandBand::CBrandBand()
73 CBrandBand::~CBrandBand()
75 DeleteObject(fImageBitmap
);
78 void CBrandBand::StartAnimation()
81 SetTimer(5678, 30, NULL
);
84 void CBrandBand::StopAnimation()
91 void CBrandBand::SelectImage()
98 HINSTANCE shell32Instance
;
102 screenDepth
= GetScreenDepth();
103 GetClientRect(&clientRect
);
104 clientWidth
= clientRect
.right
- clientRect
.left
;
105 clientHeight
= clientRect
.bottom
- clientRect
.top
;
106 clientSize
= min(clientWidth
, clientHeight
);
108 resourceID
= gTrueColorResourceBase
;
110 resourceID
= g256ColorResourceBase
;
111 if (clientSize
>= gLargeImageSize
)
113 else if (clientSize
>= gMediumImageSize
)
115 shell32Instance
= GetModuleHandle(L
"shell32.dll");
116 fImageBitmap
= LoadBitmap(shell32Instance
, MAKEINTRESOURCE(resourceID
));
117 GetObjectW(fImageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
118 fBitmapSize
= bitmapInfo
.bmWidth
;
119 fMaxFrameCount
= bitmapInfo
.bmHeight
/ fBitmapSize
;
122 HRESULT STDMETHODCALLTYPE
CBrandBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
124 if (pdbi
->dwMask
& DBIM_MINSIZE
)
126 pdbi
->ptMinSize
.x
= 38;
127 pdbi
->ptMinSize
.y
= 22;
129 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
131 pdbi
->ptMaxSize
.x
= 38;
132 pdbi
->ptMaxSize
.y
= 38;
134 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
136 pdbi
->ptIntegral
.x
= 38;
137 pdbi
->ptIntegral
.y
= 38;
139 if (pdbi
->dwMask
& DBIM_ACTUAL
)
141 pdbi
->ptActual
.x
= 38;
142 pdbi
->ptActual
.y
= 38;
144 if (pdbi
->dwMask
& DBIM_TITLE
)
145 wcscpy(pdbi
->wszTitle
, L
"");
146 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
147 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
148 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
153 HRESULT STDMETHODCALLTYPE
CBrandBand::SetSite(IUnknown
* pUnkSite
)
155 CComPtr
<IBrowserService
> browserService
;
156 CComPtr
<IOleWindow
> oleWindow
;
157 CComPtr
<IServiceProvider
> serviceProvider
;
158 CComPtr
<IProfferService
> profferService
;
164 if (pUnkSite
== NULL
)
166 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
167 // TODO: revoke brand band service
171 // get window handle of parent
172 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, reinterpret_cast<void **>(&fSite
));
176 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, reinterpret_cast<void **>(&oleWindow
));
177 if (SUCCEEDED(hResult
))
178 hResult
= oleWindow
->GetWindow(&parentWindow
);
179 if (!::IsWindow(parentWindow
))
182 // create worker window in parent window
183 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0,
184 WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
187 SubclassWindow(hwnd
);
189 // take advice to watch events
190 hResult
= pUnkSite
->QueryInterface(IID_IServiceProvider
, reinterpret_cast<void **>(&serviceProvider
));
191 if (SUCCEEDED(hResult
))
193 hResult
= serviceProvider
->QueryService(
194 SID_SBrandBand
, IID_IProfferService
, reinterpret_cast<void **>(&profferService
));
195 if (SUCCEEDED(hResult
))
196 hResult
= profferService
->ProfferService(SID_SBrandBand
,
197 static_cast<IServiceProvider
*>(this), &fProfferCookie
);
198 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
,
199 IID_IBrowserService
, reinterpret_cast<void **>(&browserService
));
200 if (SUCCEEDED(hResult
))
201 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
204 // ignore any hResult errors up to here - they are nonfatal
210 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSite(REFIID riid
, void **ppvSite
)
219 return fSite
.p
->QueryInterface(riid
, ppvSite
);
222 HRESULT STDMETHODCALLTYPE
CBrandBand::GetWindow(HWND
*lphwnd
)
230 HRESULT STDMETHODCALLTYPE
CBrandBand::ContextSensitiveHelp(BOOL fEnterMode
)
235 HRESULT STDMETHODCALLTYPE
CBrandBand::CloseDW(DWORD dwReserved
)
247 HRESULT STDMETHODCALLTYPE
CBrandBand::ResizeBorderDW(
248 const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
253 HRESULT STDMETHODCALLTYPE
CBrandBand::ShowDW(BOOL fShow
)
265 HRESULT STDMETHODCALLTYPE
CBrandBand::HasFocusIO()
267 if (GetFocus() == m_hWnd
)
272 HRESULT STDMETHODCALLTYPE
CBrandBand::TranslateAcceleratorIO(LPMSG lpMsg
)
277 HRESULT STDMETHODCALLTYPE
CBrandBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
282 HRESULT STDMETHODCALLTYPE
CBrandBand::GetClassID(CLSID
*pClassID
)
284 if (pClassID
== NULL
)
286 *pClassID
= CLSID_BrandBand
;
290 HRESULT STDMETHODCALLTYPE
CBrandBand::IsDirty()
295 HRESULT STDMETHODCALLTYPE
CBrandBand::Load(IStream
*pStm
)
300 HRESULT STDMETHODCALLTYPE
CBrandBand::Save(IStream
*pStm
, BOOL fClearDirty
)
305 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
310 HRESULT STDMETHODCALLTYPE
CBrandBand::OnWinEvent(
311 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
316 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
323 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(
324 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
329 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
,
330 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
332 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
335 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
339 case BBID_STARTANIMATION
:
342 case BBID_STOPANIMATION
:
350 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
352 CComPtr
<IServiceProvider
> serviceProvider
;
355 if (IsEqualIID(guidService
, SID_SBrandBand
))
356 return this->QueryInterface(riid
, ppvObject
);
357 hResult
= fSite
->QueryInterface(IID_IServiceProvider
, reinterpret_cast<void **>(&serviceProvider
));
360 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
363 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
368 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
373 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
374 LCID lcid
, DISPID
*rgDispId
)
379 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
380 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
382 if (pDispParams
== NULL
)
384 switch (dispIdMember
)
386 case DISPID_DOWNLOADCOMPLETE
:
389 case DISPID_DOWNLOADBEGIN
:
396 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
402 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
407 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
409 PAINTSTRUCT paintInfo
;
411 POINT destinationPoint
;
417 dc
= BeginPaint(&paintInfo
);
418 GetClientRect(&clientRect
);
420 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
421 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
423 ::SetBkColor(dc
, RGB(255, 255, 255));
427 tempRect
.right
= clientRect
.right
;
428 tempRect
.bottom
= destinationPoint
.y
;
429 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
432 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
433 tempRect
.right
= clientRect
.right
;
434 tempRect
.bottom
= clientRect
.bottom
;
435 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
438 tempRect
.top
= destinationPoint
.y
;
439 tempRect
.right
= destinationPoint
.x
;
440 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
441 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
443 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
444 tempRect
.top
= destinationPoint
.y
;
445 tempRect
.right
= clientRect
.right
;
446 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
447 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
449 sourceDC
= CreateCompatibleDC(dc
);
450 oldBitmap
= reinterpret_cast<HBITMAP
>(SelectObject(sourceDC
, fImageBitmap
));
452 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
454 SelectObject(sourceDC
, oldBitmap
);
457 EndPaint(&paintInfo
);
461 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
464 if (fCurrentFrame
>= fMaxFrameCount
)
470 HRESULT
CreateBrandBand(REFIID riid
, void **ppv
)
472 CComObject
<CBrandBand
> *theMenuBar
;
478 ATLTRY (theMenuBar
= new CComObject
<CBrandBand
>);
479 if (theMenuBar
== NULL
)
480 return E_OUTOFMEMORY
;
481 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));