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
27 #include <shlobj_undoc.h>
29 #include <shlguid_undoc.h>
37 #include "brandband.h"
41 Add Exec command handlers
42 Properly implement GetBandInfo
43 Fix SetSite to revoke brand band service when site is cleared
46 inline void FillSolidRect(HDC dc
, const RECT
*bounds
)
48 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
51 inline void FillSolidRect(HDC dc
, const RECT
*bounds
, COLORREF clr
)
53 ::SetBkColor(dc
, clr
);
54 ::ExtTextOut(dc
, 0, 0, ETO_OPAQUE
, bounds
, NULL
, 0, NULL
);
63 depth
= GetDeviceCaps(tempDC
, BITSPIXEL
) * GetDeviceCaps(tempDC
, PLANES
);
64 ReleaseDC(NULL
, tempDC
);
68 static const int gSmallImageSize
= 22;
69 static const int gMediumImageSize
= 26;
70 static const int gLargeImageSize
= 38;
72 static const int gTrueColorResourceBase
= 240;
73 static const int g256ColorResourceBase
= 245;
75 CBrandBand::CBrandBand()
84 CBrandBand::~CBrandBand()
86 DeleteObject(fImageBitmap
);
89 void CBrandBand::StartAnimation()
92 SetTimer(5678, 30, NULL
);
95 void CBrandBand::StopAnimation()
102 void CBrandBand::SelectImage()
109 HINSTANCE shell32Instance
;
113 screenDepth
= GetScreenDepth();
114 GetClientRect(&clientRect
);
115 clientWidth
= clientRect
.right
- clientRect
.left
;
116 clientHeight
= clientRect
.bottom
- clientRect
.top
;
117 clientSize
= min(clientWidth
, clientHeight
);
119 resourceID
= gTrueColorResourceBase
;
121 resourceID
= g256ColorResourceBase
;
122 if (clientSize
>= gLargeImageSize
)
124 else if (clientSize
>= gMediumImageSize
)
126 shell32Instance
= GetModuleHandle(L
"shell32.dll");
127 fImageBitmap
= LoadBitmap(shell32Instance
, MAKEINTRESOURCE(resourceID
));
128 GetObjectW(fImageBitmap
, sizeof(bitmapInfo
), &bitmapInfo
);
129 fBitmapSize
= bitmapInfo
.bmWidth
;
130 fMaxFrameCount
= bitmapInfo
.bmHeight
/ fBitmapSize
;
133 HRESULT STDMETHODCALLTYPE
CBrandBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
* pdbi
)
135 if (pdbi
->dwMask
& DBIM_MINSIZE
)
137 pdbi
->ptMinSize
.x
= 38;
138 pdbi
->ptMinSize
.y
= 22;
140 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
142 pdbi
->ptMaxSize
.x
= 38;
143 pdbi
->ptMaxSize
.y
= 38;
145 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
147 pdbi
->ptIntegral
.x
= 38;
148 pdbi
->ptIntegral
.y
= 38;
150 if (pdbi
->dwMask
& DBIM_ACTUAL
)
152 pdbi
->ptActual
.x
= 38;
153 pdbi
->ptActual
.y
= 38;
155 if (pdbi
->dwMask
& DBIM_TITLE
)
156 wcscpy(pdbi
->wszTitle
, L
"");
157 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
158 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
159 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
164 HRESULT STDMETHODCALLTYPE
CBrandBand::SetSite(IUnknown
* pUnkSite
)
166 CComPtr
<IBrowserService
> browserService
;
167 CComPtr
<IOleWindow
> oleWindow
;
168 CComPtr
<IServiceProvider
> serviceProvider
;
169 CComPtr
<IProfferService
> profferService
;
175 if (pUnkSite
== NULL
)
177 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
178 // TODO: revoke brand band service
181 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, (void **)&fSite
);
185 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, (void **)&oleWindow
);
186 if (SUCCEEDED(hResult
))
187 hResult
= oleWindow
->GetWindow(&parentWindow
);
188 if (!::IsWindow(parentWindow
))
191 hwnd
= SHCreateWorkerWindowW(0, parentWindow
, 0, WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, NULL
, 0);
194 SubclassWindow(hwnd
);
195 hResult
= pUnkSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
196 if (SUCCEEDED(hResult
))
198 hResult
= serviceProvider
->QueryService(SID_SBrandBand
, IID_IProfferService
, (void **)&profferService
);
199 if (SUCCEEDED(hResult
))
200 hResult
= profferService
->ProfferService(SID_SBrandBand
, (IServiceProvider
*)this, &fProfferCookie
);
201 hResult
= serviceProvider
->QueryService(SID_SShellBrowser
, IID_IBrowserService
, (void **)&browserService
);
202 if (SUCCEEDED(hResult
))
203 hResult
= AtlAdvise(browserService
, (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(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(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
315 HRESULT STDMETHODCALLTYPE
CBrandBand::IsWindowOwner(HWND hWnd
)
322 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryStatus(const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
327 HRESULT STDMETHODCALLTYPE
CBrandBand::Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
329 if (IsEqualIID(*pguidCmdGroup
, CGID_PrivCITCommands
))
332 else if (IsEqualIID(*pguidCmdGroup
, CGID_BrandCmdGroup
))
336 case BBID_STARTANIMATION
:
339 case BBID_STOPANIMATION
:
347 HRESULT STDMETHODCALLTYPE
CBrandBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
349 CComPtr
<IServiceProvider
> serviceProvider
;
352 if (IsEqualIID(guidService
, SID_SBrandBand
))
353 return this->QueryInterface(riid
, ppvObject
);
354 hResult
= fSite
->QueryInterface(IID_IServiceProvider
, (void **)&serviceProvider
);
355 if (FAILED (hResult
))
357 return serviceProvider
->QueryService(guidService
, riid
, ppvObject
);
360 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfoCount(UINT
*pctinfo
)
365 HRESULT STDMETHODCALLTYPE
CBrandBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
370 HRESULT STDMETHODCALLTYPE
CBrandBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
375 HRESULT STDMETHODCALLTYPE
CBrandBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
377 if (pDispParams
== NULL
)
379 switch (dispIdMember
)
381 case DISPID_DOWNLOADCOMPLETE
:
384 case DISPID_DOWNLOADBEGIN
:
391 LRESULT
CBrandBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
397 LRESULT
CBrandBand::OnEraseBkgnd (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
402 LRESULT
CBrandBand::OnPaint(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
404 PAINTSTRUCT paintInfo
;
406 POINT destinationPoint
;
412 dc
= BeginPaint(&paintInfo
);
413 GetClientRect(&clientRect
);
415 destinationPoint
.x
= (clientRect
.right
- clientRect
.left
- fBitmapSize
) / 2;
416 destinationPoint
.y
= (clientRect
.bottom
- clientRect
.top
- fBitmapSize
) / 2;
418 ::SetBkColor(dc
, RGB(255, 255, 255));
422 tempRect
.right
= clientRect
.right
;
423 tempRect
.bottom
= destinationPoint
.y
;
424 FillSolidRect(dc
, &tempRect
, RGB(255, 255, 255));
427 tempRect
.top
= destinationPoint
.y
+ fBitmapSize
;
428 tempRect
.right
= clientRect
.right
;
429 tempRect
.bottom
= clientRect
.bottom
;
430 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
433 tempRect
.top
= destinationPoint
.y
;
434 tempRect
.right
= destinationPoint
.x
;
435 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
436 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
438 tempRect
.left
= destinationPoint
.x
+ fBitmapSize
;
439 tempRect
.top
= destinationPoint
.y
;
440 tempRect
.right
= clientRect
.right
;
441 tempRect
.bottom
= destinationPoint
.y
+ fBitmapSize
;
442 FillSolidRect(dc
, &paintInfo
.rcPaint
, RGB(255, 255, 255));
444 sourceDC
= CreateCompatibleDC(dc
);
445 oldBitmap
= (HBITMAP
)SelectObject(sourceDC
, fImageBitmap
);
447 BitBlt(dc
, destinationPoint
.x
, destinationPoint
.y
, fBitmapSize
, fBitmapSize
, sourceDC
, 0, fCurrentFrame
* fBitmapSize
, SRCCOPY
);
449 SelectObject(sourceDC
, oldBitmap
);
452 EndPaint(&paintInfo
);
456 LRESULT
CBrandBand::OnTimer(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
459 if (fCurrentFrame
>= fMaxFrameCount
)
465 HRESULT
CreateBrandBand(REFIID riid
, void **ppv
)
467 CComObject
<CBrandBand
> *theMenuBar
;
473 ATLTRY (theMenuBar
= new CComObject
<CBrandBand
>);
474 if (theMenuBar
== NULL
)
475 return E_OUTOFMEMORY
;
476 hResult
= theMenuBar
->QueryInterface (riid
, (void **)ppv
);
477 if (FAILED (hResult
))