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()
72 CBrandBand::~CBrandBand()
74 DeleteObject(fImageBitmap
);
77 void CBrandBand::StartAnimation()
80 SetTimer(5678, 30, NULL
);
83 void CBrandBand::StopAnimation()
90 void CBrandBand::SelectImage()
97 HINSTANCE shell32Instance
;
101 screenDepth
= GetScreenDepth();
102 GetClientRect(&clientRect
);
103 clientWidth
= clientRect
.right
- clientRect
.left
;
104 clientHeight
= clientRect
.bottom
- clientRect
.top
;
105 clientSize
= min(clientWidth
, clientHeight
);
107 resourceID
= gTrueColorResourceBase
;
109 resourceID
= g256ColorResourceBase
;
110 if (clientSize
>= gLargeImageSize
)
112 else if (clientSize
>= gMediumImageSize
)
114 shell32Instance
= GetModuleHandle(L
"shell32.dll");
115 fImageBitmap
= LoadBitmap(shell32Instance
, MAKEINTRESOURCE(resourceID
));
116 GetObjectW(fImageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
117 fBitmapSize
= bitmapInfo
.bmWidth
;
118 fMaxFrameCount
= bitmapInfo
.bmHeight
/ fBitmapSize
;
121 HRESULT STDMETHODCALLTYPE
CBrandBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
123 if (pdbi
->dwMask
& DBIM_MINSIZE
)
125 pdbi
->ptMinSize
.x
= 38;
126 pdbi
->ptMinSize
.y
= 22;
128 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
130 pdbi
->ptMaxSize
.x
= 38;
131 pdbi
->ptMaxSize
.y
= 38;
133 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
135 pdbi
->ptIntegral
.x
= 38;
136 pdbi
->ptIntegral
.y
= 38;
138 if (pdbi
->dwMask
& DBIM_ACTUAL
)
140 pdbi
->ptActual
.x
= 38;
141 pdbi
->ptActual
.y
= 38;
143 if (pdbi
->dwMask
& DBIM_TITLE
)
144 wcscpy(pdbi
->wszTitle
, L
"");
145 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
146 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
147 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
152 HRESULT STDMETHODCALLTYPE
CBrandBand::SetSite(IUnknown
* pUnkSite
)
154 CComPtr
<IBrowserService
> browserService
;
155 CComPtr
<IOleWindow
> oleWindow
;
156 CComPtr
<IServiceProvider
> serviceProvider
;
157 CComPtr
<IProfferService
> profferService
;
163 if (pUnkSite
== NULL
)
165 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
166 // TODO: revoke brand band service
169 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, (void **)&fSite
);
173 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, (void **)&oleWindow
);
174 if (SUCCEEDED(hResult
))
175 hResult
= oleWindow
->GetWindow(&parentWindow
);
176 if (!::IsWindow(parentWindow
))
179 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0, WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
182 SubclassWindow(hwnd
);
183 hResult
= pUnkSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
184 if (SUCCEEDED(hResult
))
186 hResult
= serviceProvider
->QueryService(SID_SBrandBand
, IID_IProfferService
, (void **)&profferService
);
187 if (SUCCEEDED(hResult
))
188 hResult
= profferService
->ProfferService(SID_SBrandBand
, (IServiceProvider
*)this, &fProfferCookie
);
189 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
, IID_IBrowserService
, (void **)&browserService
);
190 if (SUCCEEDED(hResult
))
191 hResult
= AtlAdvise(browserService
, (IDispatch
*)this, DIID_DWebBrowserEvents
, &fAdviseCookie
);
193 // ignore any hResult errors up to here - they are nonfatal
199 HRESULT STDMETHODCALLTYPE
CBrandBand::GetSite(REFIID riid
, void **ppvSite
)
208 return fSite
.p
->QueryInterface(riid
, ppvSite
);
211 HRESULT STDMETHODCALLTYPE
CBrandBand::GetWindow(HWND
*lphwnd
)
219 HRESULT STDMETHODCALLTYPE
CBrandBand::ContextSensitiveHelp(BOOL fEnterMode
)
224 HRESULT STDMETHODCALLTYPE
CBrandBand::CloseDW(DWORD dwReserved
)
236 HRESULT STDMETHODCALLTYPE
CBrandBand::ResizeBorderDW(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(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
303 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
310 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
315 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
317 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
320 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
324 case BBID_STARTANIMATION
:
327 case BBID_STOPANIMATION
:
335 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
337 CComPtr
<IServiceProvider
> serviceProvider
;
340 if (IsEqualIID(guidService
, SID_SBrandBand
))
341 return this->QueryInterface(riid
, ppvObject
);
342 hResult
= fSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
343 if (FAILED (hResult
))
345 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
348 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
353 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
358 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
363 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
365 if (pDispParams
== NULL
)
367 switch (dispIdMember
)
369 case DISPID_DOWNLOADCOMPLETE
:
372 case DISPID_DOWNLOADBEGIN
:
379 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
385 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
390 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
392 PAINTSTRUCT paintInfo
;
394 POINT destinationPoint
;
400 dc
= BeginPaint(&paintInfo
);
401 GetClientRect(&clientRect
);
403 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
404 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
406 ::SetBkColor(dc
, RGB(255, 255, 255));
410 tempRect
.right
= clientRect
.right
;
411 tempRect
.bottom
= destinationPoint
.y
;
412 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
415 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
416 tempRect
.right
= clientRect
.right
;
417 tempRect
.bottom
= clientRect
.bottom
;
418 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
421 tempRect
.top
= destinationPoint
.y
;
422 tempRect
.right
= destinationPoint
.x
;
423 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
424 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
426 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
427 tempRect
.top
= destinationPoint
.y
;
428 tempRect
.right
= clientRect
.right
;
429 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
430 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
432 sourceDC
= CreateCompatibleDC(dc
);
433 oldBitmap
= (HBITMAP
)SelectObject(sourceDC
, fImageBitmap
);
435 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
437 SelectObject(sourceDC
, oldBitmap
);
440 EndPaint(&paintInfo
);
444 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
447 if (fCurrentFrame
>= fMaxFrameCount
)
453 HRESULT
CreateBrandBand(REFIID riid
, void **ppv
)
455 CComObject
<CBrandBand
> *theMenuBar
;
461 ATLTRY (theMenuBar
= new CComObject
<CBrandBand
>);
462 if (theMenuBar
== NULL
)
463 return E_OUTOFMEMORY
;
464 hResult
= theMenuBar
->QueryInterface (riid
, (void **)ppv
);
465 if (FAILED (hResult
))