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
30 Add Exec command handlers
31 Properly implement GetBandInfo
32 Fix SetSite to revoke brand band service when site is cleared
35 inline void FillSolidRect(HDC dc
, const RECT
*bounds
)
37 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
40 inline void FillSolidRect(HDC dc
, const RECT
*bounds
, COLORREF clr
)
42 ::SetBkColor(dc
, clr
);
43 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
52 depth
= GetDeviceCaps(tempDC
, BITSPIXEL
) * GetDeviceCaps(tempDC
, PLANES
);
53 ReleaseDC(NULL
, tempDC
);
57 static const int gSmallImageSize
= 22;
58 static const int gMediumImageSize
= 26;
59 static const int gLargeImageSize
= 38;
61 static const int gTrueColorResourceBase
= 240;
62 static const int g256ColorResourceBase
= 245;
64 CBrandBand::CBrandBand()
74 CBrandBand::~CBrandBand()
76 DeleteObject(fImageBitmap
);
79 void CBrandBand::StartAnimation()
82 SetTimer(5678, 30, NULL
);
85 void CBrandBand::StopAnimation()
92 void CBrandBand::SelectImage()
99 HINSTANCE shell32Instance
;
103 screenDepth
= GetScreenDepth();
104 GetClientRect(&clientRect
);
105 clientWidth
= clientRect
.right
- clientRect
.left
;
106 clientHeight
= clientRect
.bottom
- clientRect
.top
;
107 clientSize
= min(clientWidth
, clientHeight
);
109 resourceID
= gTrueColorResourceBase
;
111 resourceID
= g256ColorResourceBase
;
112 if (clientSize
>= gLargeImageSize
)
114 else if (clientSize
>= gMediumImageSize
)
116 shell32Instance
= GetModuleHandle(L
"shell32.dll");
117 fImageBitmap
= LoadBitmap(shell32Instance
, MAKEINTRESOURCE(resourceID
));
118 GetObjectW(fImageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
119 fBitmapSize
= bitmapInfo
.bmWidth
;
120 fMaxFrameCount
= bitmapInfo
.bmHeight
/ fBitmapSize
;
123 HRESULT STDMETHODCALLTYPE
CBrandBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
125 if (pdbi
->dwMask
& DBIM_MINSIZE
)
127 pdbi
->ptMinSize
.x
= 38;
128 pdbi
->ptMinSize
.y
= 22;
130 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
132 pdbi
->ptMaxSize
.x
= 38;
133 pdbi
->ptMaxSize
.y
= 38;
135 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
137 pdbi
->ptIntegral
.x
= 38;
138 pdbi
->ptIntegral
.y
= 38;
140 if (pdbi
->dwMask
& DBIM_ACTUAL
)
142 pdbi
->ptActual
.x
= 38;
143 pdbi
->ptActual
.y
= 38;
145 if (pdbi
->dwMask
& DBIM_TITLE
)
146 wcscpy(pdbi
->wszTitle
, L
"");
147 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
148 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
149 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
154 HRESULT STDMETHODCALLTYPE
CBrandBand::SetSite(IUnknown
* pUnkSite
)
156 CComPtr
<IBrowserService
> browserService
;
157 CComPtr
<IOleWindow
> oleWindow
;
158 CComPtr
<IServiceProvider
> serviceProvider
;
159 CComPtr
<IProfferService
> profferService
;
165 if (pUnkSite
== NULL
)
167 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
168 // TODO: revoke brand band service
172 // get window handle of parent
173 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
174 if (FAILED_UNEXPECTEDLY(hResult
))
177 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IOleWindow
, &oleWindow
));
178 if (SUCCEEDED(hResult
))
179 hResult
= oleWindow
->GetWindow(&parentWindow
);
180 if (!::IsWindow(parentWindow
))
183 // create worker window in parent window
184 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0,
185 WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
188 SubclassWindow(hwnd
);
190 // take advice to watch events
191 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IServiceProvider
, &serviceProvider
));
192 if (SUCCEEDED(hResult
))
194 hResult
= serviceProvider
->QueryService(
195 SID_SBrandBand
, IID_PPV_ARG(IProfferService
, &profferService
));
196 if (SUCCEEDED(hResult
))
197 hResult
= profferService
->ProfferService(SID_SBrandBand
,
198 static_cast<IServiceProvider
*>(this), &fProfferCookie
);
199 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
,
200 IID_PPV_ARG(IBrowserService
, &browserService
));
201 if (SUCCEEDED(hResult
))
202 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
205 // ignore any hResult errors up to here - they are nonfatal
211 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSite(REFIID riid
, void **ppvSite
)
220 return fSite
.p
->QueryInterface(riid
, ppvSite
);
223 HRESULT STDMETHODCALLTYPE
CBrandBand::GetWindow(HWND
*lphwnd
)
231 HRESULT STDMETHODCALLTYPE
CBrandBand::ContextSensitiveHelp(BOOL fEnterMode
)
236 HRESULT STDMETHODCALLTYPE
CBrandBand::CloseDW(DWORD dwReserved
)
248 HRESULT STDMETHODCALLTYPE
CBrandBand::ResizeBorderDW(
249 const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
254 HRESULT STDMETHODCALLTYPE
CBrandBand::ShowDW(BOOL fShow
)
266 HRESULT STDMETHODCALLTYPE
CBrandBand::HasFocusIO()
268 if (GetFocus() == m_hWnd
)
273 HRESULT STDMETHODCALLTYPE
CBrandBand::TranslateAcceleratorIO(LPMSG lpMsg
)
278 HRESULT STDMETHODCALLTYPE
CBrandBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
283 HRESULT STDMETHODCALLTYPE
CBrandBand::GetClassID(CLSID
*pClassID
)
285 if (pClassID
== NULL
)
287 *pClassID
= CLSID_BrandBand
;
291 HRESULT STDMETHODCALLTYPE
CBrandBand::IsDirty()
296 HRESULT STDMETHODCALLTYPE
CBrandBand::Load(IStream
*pStm
)
301 HRESULT STDMETHODCALLTYPE
CBrandBand::Save(IStream
*pStm
, BOOL fClearDirty
)
306 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
311 HRESULT STDMETHODCALLTYPE
CBrandBand::OnWinEvent(
312 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
317 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
324 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(
325 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
330 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
,
331 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
333 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
336 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
340 case BBID_STARTANIMATION
:
343 case BBID_STOPANIMATION
:
351 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
353 CComPtr
<IServiceProvider
> serviceProvider
;
356 if (IsEqualIID(guidService
, SID_SBrandBand
))
357 return this->QueryInterface(riid
, ppvObject
);
358 hResult
= fSite
->QueryInterface(IID_PPV_ARG(IServiceProvider
, &serviceProvider
));
359 if (FAILED_UNEXPECTEDLY(hResult
))
361 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
364 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
369 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
374 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
375 LCID lcid
, DISPID
*rgDispId
)
380 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
381 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
383 if (pDispParams
== NULL
)
385 switch (dispIdMember
)
387 case DISPID_DOWNLOADCOMPLETE
:
390 case DISPID_DOWNLOADBEGIN
:
397 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
403 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
408 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
410 PAINTSTRUCT paintInfo
;
412 POINT destinationPoint
;
418 dc
= BeginPaint(&paintInfo
);
419 GetClientRect(&clientRect
);
421 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
422 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
424 ::SetBkColor(dc
, RGB(255, 255, 255));
428 tempRect
.right
= clientRect
.right
;
429 tempRect
.bottom
= destinationPoint
.y
;
430 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
433 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
434 tempRect
.right
= clientRect
.right
;
435 tempRect
.bottom
= clientRect
.bottom
;
436 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
439 tempRect
.top
= destinationPoint
.y
;
440 tempRect
.right
= destinationPoint
.x
;
441 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
442 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
444 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
445 tempRect
.top
= destinationPoint
.y
;
446 tempRect
.right
= clientRect
.right
;
447 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
448 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
450 sourceDC
= CreateCompatibleDC(dc
);
451 oldBitmap
= reinterpret_cast<HBITMAP
>(SelectObject(sourceDC
, fImageBitmap
));
453 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
455 SelectObject(sourceDC
, oldBitmap
);
458 EndPaint(&paintInfo
);
462 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
465 if (fCurrentFrame
>= fMaxFrameCount
)
471 HRESULT
CreateBrandBand(REFIID riid
, void **ppv
)
473 CComObject
<CBrandBand
> *theMenuBar
;
479 ATLTRY (theMenuBar
= new CComObject
<CBrandBand
>);
480 if (theMenuBar
== NULL
)
481 return E_OUTOFMEMORY
;
482 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));
483 if (FAILED_UNEXPECTEDLY(hResult
))