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
170 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, (void **)&fSite
);
174 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, (void **)&oleWindow
);
175 if (SUCCEEDED(hResult
))
176 hResult
= oleWindow
->GetWindow(&parentWindow
);
177 if (!::IsWindow(parentWindow
))
180 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0, WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
183 SubclassWindow(hwnd
);
184 hResult
= pUnkSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
185 if (SUCCEEDED(hResult
))
187 hResult
= serviceProvider
->QueryService(SID_SBrandBand
, IID_IProfferService
, (void **)&profferService
);
188 if (SUCCEEDED(hResult
))
189 hResult
= profferService
->ProfferService(SID_SBrandBand
, (IServiceProvider
*)this, &fProfferCookie
);
190 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
, IID_IBrowserService
, (void **)&browserService
);
191 if (SUCCEEDED(hResult
))
192 hResult
= AtlAdvise(browserService
, (IDispatch
*)this, DIID_DWebBrowserEvents
, &fAdviseCookie
);
194 // ignore any hResult errors up to here - they are nonfatal
200 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSite(REFIID riid
, void **ppvSite
)
209 return fSite
.p
->QueryInterface(riid
, ppvSite
);
212 HRESULT STDMETHODCALLTYPE
CBrandBand::GetWindow(HWND
*lphwnd
)
220 HRESULT STDMETHODCALLTYPE
CBrandBand::ContextSensitiveHelp(BOOL fEnterMode
)
225 HRESULT STDMETHODCALLTYPE
CBrandBand::CloseDW(DWORD dwReserved
)
237 HRESULT STDMETHODCALLTYPE
CBrandBand::ResizeBorderDW(const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
242 HRESULT STDMETHODCALLTYPE
CBrandBand::ShowDW(BOOL fShow
)
254 HRESULT STDMETHODCALLTYPE
CBrandBand::HasFocusIO()
256 if (GetFocus() == m_hWnd
)
261 HRESULT STDMETHODCALLTYPE
CBrandBand::TranslateAcceleratorIO(LPMSG lpMsg
)
266 HRESULT STDMETHODCALLTYPE
CBrandBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
271 HRESULT STDMETHODCALLTYPE
CBrandBand::GetClassID(CLSID
*pClassID
)
273 if (pClassID
== NULL
)
275 *pClassID
= CLSID_BrandBand
;
279 HRESULT STDMETHODCALLTYPE
CBrandBand::IsDirty()
284 HRESULT STDMETHODCALLTYPE
CBrandBand::Load(IStream
*pStm
)
289 HRESULT STDMETHODCALLTYPE
CBrandBand::Save(IStream
*pStm
, BOOL fClearDirty
)
294 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
299 HRESULT STDMETHODCALLTYPE
CBrandBand::OnWinEvent(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
304 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
311 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
316 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
318 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
321 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
325 case BBID_STARTANIMATION
:
328 case BBID_STOPANIMATION
:
336 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
338 CComPtr
<IServiceProvider
> serviceProvider
;
341 if (IsEqualIID(guidService
, SID_SBrandBand
))
342 return this->QueryInterface(riid
, ppvObject
);
343 hResult
= fSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
344 if (FAILED (hResult
))
346 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
349 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
354 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
359 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
364 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
366 if (pDispParams
== NULL
)
368 switch (dispIdMember
)
370 case DISPID_DOWNLOADCOMPLETE
:
373 case DISPID_DOWNLOADBEGIN
:
380 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
386 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
391 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
393 PAINTSTRUCT paintInfo
;
395 POINT destinationPoint
;
401 dc
= BeginPaint(&paintInfo
);
402 GetClientRect(&clientRect
);
404 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
405 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
407 ::SetBkColor(dc
, RGB(255, 255, 255));
411 tempRect
.right
= clientRect
.right
;
412 tempRect
.bottom
= destinationPoint
.y
;
413 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
416 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
417 tempRect
.right
= clientRect
.right
;
418 tempRect
.bottom
= clientRect
.bottom
;
419 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
422 tempRect
.top
= destinationPoint
.y
;
423 tempRect
.right
= destinationPoint
.x
;
424 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
425 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
427 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
428 tempRect
.top
= destinationPoint
.y
;
429 tempRect
.right
= clientRect
.right
;
430 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
431 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
433 sourceDC
= CreateCompatibleDC(dc
);
434 oldBitmap
= (HBITMAP
)SelectObject(sourceDC
, fImageBitmap
);
436 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
438 SelectObject(sourceDC
, oldBitmap
);
441 EndPaint(&paintInfo
);
445 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
448 if (fCurrentFrame
>= fMaxFrameCount
)
454 HRESULT
CreateBrandBand(REFIID riid
, void **ppv
)
456 CComObject
<CBrandBand
> *theMenuBar
;
462 ATLTRY (theMenuBar
= new CComObject
<CBrandBand
>);
463 if (theMenuBar
== NULL
)
464 return E_OUTOFMEMORY
;
465 hResult
= theMenuBar
->QueryInterface (riid
, (void **)ppv
);
466 if (FAILED (hResult
))