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
);
46 //static const int gSmallImageSize = 22;
47 static const int gMediumImageSize
= 26;
48 static const int gLargeImageSize
= 38;
50 static const int gTrueColorResourceBase
= 240;
51 static const int g256ColorResourceBase
= 245;
53 CBrandBand::CBrandBand()
63 CBrandBand::~CBrandBand()
65 DeleteObject(fImageBitmap
);
68 void CBrandBand::StartAnimation()
71 SetTimer(5678, 30, NULL
);
74 void CBrandBand::StopAnimation()
81 void CBrandBand::SelectImage()
91 screenDepth
= SHGetCurColorRes();
92 GetClientRect(&clientRect
);
93 clientWidth
= clientRect
.right
- clientRect
.left
;
94 clientHeight
= clientRect
.bottom
- clientRect
.top
;
95 clientSize
= min(clientWidth
, clientHeight
);
97 resourceID
= gTrueColorResourceBase
;
99 resourceID
= g256ColorResourceBase
;
100 if (clientSize
>= gLargeImageSize
)
102 else if (clientSize
>= gMediumImageSize
)
104 fImageBitmap
= LoadBitmap(_AtlBaseModule
.GetResourceInstance(), MAKEINTRESOURCE(resourceID
));
105 GetObjectW(fImageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
106 fBitmapSize
= bitmapInfo
.bmWidth
;
107 fMaxFrameCount
= bitmapInfo
.bmHeight
/ fBitmapSize
;
110 HRESULT STDMETHODCALLTYPE
CBrandBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
112 if (pdbi
->dwMask
& DBIM_MINSIZE
)
114 pdbi
->ptMinSize
.x
= 38;
115 pdbi
->ptMinSize
.y
= 22;
117 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
119 pdbi
->ptMaxSize
.x
= 38;
120 pdbi
->ptMaxSize
.y
= 38;
122 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
124 pdbi
->ptIntegral
.x
= 38;
125 pdbi
->ptIntegral
.y
= 38;
127 if (pdbi
->dwMask
& DBIM_ACTUAL
)
129 pdbi
->ptActual
.x
= 38;
130 pdbi
->ptActual
.y
= 38;
132 if (pdbi
->dwMask
& DBIM_TITLE
)
133 wcscpy(pdbi
->wszTitle
, L
"");
134 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
135 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
136 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
141 HRESULT STDMETHODCALLTYPE
CBrandBand::SetSite(IUnknown
* pUnkSite
)
143 CComPtr
<IBrowserService
> browserService
;
144 CComPtr
<IOleWindow
> oleWindow
;
145 CComPtr
<IServiceProvider
> serviceProvider
;
146 CComPtr
<IProfferService
> profferService
;
152 if (pUnkSite
== NULL
)
154 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
155 // TODO: revoke brand band service
159 // get window handle of parent
160 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
161 if (FAILED_UNEXPECTEDLY(hResult
))
164 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IOleWindow
, &oleWindow
));
165 if (SUCCEEDED(hResult
))
166 hResult
= oleWindow
->GetWindow(&parentWindow
);
167 if (!::IsWindow(parentWindow
))
170 // create worker window in parent window
171 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0,
172 WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
175 SubclassWindow(hwnd
);
177 // take advice to watch events
178 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IServiceProvider
, &serviceProvider
));
179 if (SUCCEEDED(hResult
))
181 hResult
= serviceProvider
->QueryService(
182 SID_SBrandBand
, IID_PPV_ARG(IProfferService
, &profferService
));
183 if (SUCCEEDED(hResult
))
184 hResult
= profferService
->ProfferService(SID_SBrandBand
,
185 static_cast<IServiceProvider
*>(this), &fProfferCookie
);
186 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
,
187 IID_PPV_ARG(IBrowserService
, &browserService
));
188 if (SUCCEEDED(hResult
))
189 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
192 // ignore any hResult errors up to here - they are nonfatal
198 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSite(REFIID riid
, void **ppvSite
)
207 return fSite
.p
->QueryInterface(riid
, ppvSite
);
210 HRESULT STDMETHODCALLTYPE
CBrandBand::GetWindow(HWND
*lphwnd
)
218 HRESULT STDMETHODCALLTYPE
CBrandBand::ContextSensitiveHelp(BOOL fEnterMode
)
223 HRESULT STDMETHODCALLTYPE
CBrandBand::CloseDW(DWORD dwReserved
)
235 HRESULT STDMETHODCALLTYPE
CBrandBand::ResizeBorderDW(
236 const RECT
* prcBorder
, IUnknown
* punkToolbarSite
, BOOL fReserved
)
241 HRESULT STDMETHODCALLTYPE
CBrandBand::ShowDW(BOOL fShow
)
253 HRESULT STDMETHODCALLTYPE
CBrandBand::HasFocusIO()
255 if (GetFocus() == m_hWnd
)
260 HRESULT STDMETHODCALLTYPE
CBrandBand::TranslateAcceleratorIO(LPMSG lpMsg
)
265 HRESULT STDMETHODCALLTYPE
CBrandBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
270 HRESULT STDMETHODCALLTYPE
CBrandBand::GetClassID(CLSID
*pClassID
)
272 if (pClassID
== NULL
)
274 *pClassID
= CLSID_BrandBand
;
278 HRESULT STDMETHODCALLTYPE
CBrandBand::IsDirty()
283 HRESULT STDMETHODCALLTYPE
CBrandBand::Load(IStream
*pStm
)
288 HRESULT STDMETHODCALLTYPE
CBrandBand::Save(IStream
*pStm
, BOOL fClearDirty
)
293 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
298 HRESULT STDMETHODCALLTYPE
CBrandBand::OnWinEvent(
299 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
304 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
311 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(
312 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
317 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
,
318 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
320 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
323 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
327 case BBID_STARTANIMATION
:
330 case BBID_STOPANIMATION
:
338 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
340 CComPtr
<IServiceProvider
> serviceProvider
;
343 if (IsEqualIID(guidService
, SID_SBrandBand
))
344 return this->QueryInterface(riid
, ppvObject
);
345 hResult
= fSite
->QueryInterface(IID_PPV_ARG(IServiceProvider
, &serviceProvider
));
346 if (FAILED_UNEXPECTEDLY(hResult
))
348 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
351 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
356 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
361 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
362 LCID lcid
, DISPID
*rgDispId
)
367 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
368 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
370 if (pDispParams
== NULL
)
372 switch (dispIdMember
)
374 case DISPID_DOWNLOADCOMPLETE
:
377 case DISPID_DOWNLOADBEGIN
:
384 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
390 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
395 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
397 PAINTSTRUCT paintInfo
;
399 POINT destinationPoint
;
405 dc
= BeginPaint(&paintInfo
);
406 GetClientRect(&clientRect
);
408 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
409 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
411 ::SetBkColor(dc
, RGB(255, 255, 255));
415 tempRect
.right
= clientRect
.right
;
416 tempRect
.bottom
= destinationPoint
.y
;
417 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
420 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
421 tempRect
.right
= clientRect
.right
;
422 tempRect
.bottom
= clientRect
.bottom
;
423 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
426 tempRect
.top
= destinationPoint
.y
;
427 tempRect
.right
= destinationPoint
.x
;
428 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
429 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
431 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
432 tempRect
.top
= destinationPoint
.y
;
433 tempRect
.right
= clientRect
.right
;
434 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
435 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
437 sourceDC
= CreateCompatibleDC(dc
);
438 oldBitmap
= reinterpret_cast<HBITMAP
>(SelectObject(sourceDC
, fImageBitmap
));
440 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
442 SelectObject(sourceDC
, oldBitmap
);
445 EndPaint(&paintInfo
);
449 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
452 if (fCurrentFrame
>= fMaxFrameCount
)