ReactOS 0.4.15-dev-7961-gdcf9eb0
brandband.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Explorer
3 *
4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5 *
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.
10 *
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.
15 *
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
19 */
20
21/*
22Implements the logo band of a cabinet window. Most remarkable feature is the
23animation.
24*/
25
26#include "precomp.h"
27
28/*
29TODO:
30 Add Exec command handlers
31 Properly implement GetBandInfo
32 Fix SetSite to revoke brand band service when site is cleared
33*/
34
35inline void FillSolidRect(HDC dc, const RECT *bounds)
36{
37 ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, bounds, NULL, 0, NULL);
38}
39
40inline void FillSolidRect(HDC dc, const RECT *bounds, COLORREF clr)
41{
42 ::SetBkColor(dc, clr);
43 ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, bounds, NULL, 0, NULL);
44}
45
46//static const int gSmallImageSize = 22;
47static const int gMediumImageSize = 26;
48static const int gLargeImageSize = 38;
49
50static const int gTrueColorResourceBase = 240;
51static const int g256ColorResourceBase = 245;
52
54{
56 fCurrentFrame = 0;
59 fBitmapSize = 0;
60 fAdviseCookie = 0;
61}
62
64{
66}
67
69{
70 fCurrentFrame = 0;
71 SetTimer(5678, 30, NULL);
72}
73
75{
76 KillTimer(5678);
77 fCurrentFrame = 0;
78 Invalidate(FALSE);
79}
80
82{
83 int screenDepth;
84 RECT clientRect;
85 int clientWidth;
86 int clientHeight;
87 int clientSize;
88 BITMAP bitmapInfo;
89 int resourceID;
90
91 screenDepth = SHGetCurColorRes();
92 GetClientRect(&clientRect);
93 clientWidth = clientRect.right - clientRect.left;
94 clientHeight = clientRect.bottom - clientRect.top;
95 clientSize = min(clientWidth, clientHeight);
96 if (screenDepth > 8)
97 resourceID = gTrueColorResourceBase;
98 else
99 resourceID = g256ColorResourceBase;
100 if (clientSize >= gLargeImageSize)
101 resourceID += 2;
102 else if (clientSize >= gMediumImageSize)
103 resourceID += 1;
104 fImageBitmap = LoadBitmap(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(resourceID));
105 GetObjectW(fImageBitmap, sizeof(bitmapInfo), &bitmapInfo);
106 fBitmapSize = bitmapInfo.bmWidth;
107 fMaxFrameCount = bitmapInfo.bmHeight / fBitmapSize;
108}
109
111{
112 if (pdbi->dwMask & DBIM_MINSIZE)
113 {
114 pdbi->ptMinSize.x = 38;
115 pdbi->ptMinSize.y = 22;
116 }
117 if (pdbi->dwMask & DBIM_MAXSIZE)
118 {
119 pdbi->ptMaxSize.x = 38;
120 pdbi->ptMaxSize.y = 38;
121 }
122 if (pdbi->dwMask & DBIM_INTEGRAL)
123 {
124 pdbi->ptIntegral.x = 38;
125 pdbi->ptIntegral.y = 38;
126 }
127 if (pdbi->dwMask & DBIM_ACTUAL)
128 {
129 pdbi->ptActual.x = 38;
130 pdbi->ptActual.y = 38;
131 }
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)
137 pdbi->crBkgnd = 0;
138 return S_OK;
139}
140
142{
143 CComPtr<IBrowserService> browserService;
144 CComPtr<IOleWindow> oleWindow;
145 CComPtr<IServiceProvider> serviceProvider;
146 CComPtr<IProfferService> profferService;
147 HWND parentWindow;
148 HWND hwnd;
149 HRESULT hResult;
150
151 fSite.Release();
152 if (pUnkSite == NULL)
153 {
154 hResult = AtlUnadvise(fSite, DIID_DWebBrowserEvents, fAdviseCookie);
155 // TODO: revoke brand band service
156 return S_OK;
157 }
158
159 // get window handle of parent
160 hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IDockingWindowSite, &fSite));
161 if (FAILED_UNEXPECTEDLY(hResult))
162 return hResult;
163 parentWindow = NULL;
164 hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IOleWindow, &oleWindow));
165 if (SUCCEEDED(hResult))
166 hResult = oleWindow->GetWindow(&parentWindow);
167 if (!::IsWindow(parentWindow))
168 return E_FAIL;
169
170 // create worker window in parent window
171 hwnd = SHCreateWorkerWindowW(0, parentWindow, 0,
173 if (hwnd == NULL)
174 return E_FAIL;
176
177 // take advice to watch events
178 hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IServiceProvider, &serviceProvider));
179 if (SUCCEEDED(hResult))
180 {
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);
190 }
191
192 // ignore any hResult errors up to here - they are nonfatal
193 hResult = S_OK;
194 SelectImage();
195 return hResult;
196}
197
199{
200 if (ppvSite == NULL)
201 return E_POINTER;
202 if (fSite.p == NULL)
203 {
204 *ppvSite = NULL;
205 return E_FAIL;
206 }
207 return fSite.p->QueryInterface(riid, ppvSite);
208}
209
211{
212 if (lphwnd == NULL)
213 return E_POINTER;
214 *lphwnd = m_hWnd;
215 return S_OK;
216}
217
219{
220 return E_NOTIMPL;
221}
222
224{
225 ShowDW(FALSE);
226
227 if (IsWindow())
229
230 m_hWnd = NULL;
231
232 return S_OK;
233}
234
236 const RECT* prcBorder, IUnknown* punkToolbarSite, BOOL fReserved)
237{
238 return E_NOTIMPL;
239}
240
242{
243 if (m_hWnd)
244 {
245 if (fShow)
247 else
249 }
250 return S_OK;
251}
252
254{
255 if (GetFocus() == m_hWnd)
256 return S_OK;
257 return S_FALSE;
258}
259
261{
262 return E_NOTIMPL;
263}
264
266{
267 return E_NOTIMPL;
268}
269
271{
272 if (pClassID == NULL)
273 return E_POINTER;
274 *pClassID = CLSID_BrandBand;
275 return S_OK;
276}
277
279{
280 return S_FALSE;
281}
282
284{
285 return E_NOTIMPL;
286}
287
289{
290 return E_NOTIMPL;
291}
292
294{
295 return E_NOTIMPL;
296}
297
299 HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
300{
301 return E_NOTIMPL;
302}
303
305{
306 if (hWnd == m_hWnd)
307 return S_OK;
308 return S_FALSE;
309}
310
312 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText)
313{
314 return E_NOTIMPL;
315}
316
318 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
319{
320 if (IsEqualIID(*pguidCmdGroup, CGID_PrivCITCommands))
321 {
322 }
323 else if (IsEqualIID(*pguidCmdGroup, CGID_BrandCmdGroup))
324 {
325 switch (nCmdID)
326 {
329 return S_OK;
332 return S_OK;
333 }
334 }
335 return E_FAIL;
336}
337
339{
340 CComPtr<IServiceProvider> serviceProvider;
341 HRESULT hResult;
342
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))
347 return hResult;
348 return serviceProvider->QueryService(guidService, riid, ppvObject);
349}
350
352{
353 return E_NOTIMPL;
354}
355
357{
358 return E_NOTIMPL;
359}
360
362 LCID lcid, DISPID *rgDispId)
363{
364 return E_NOTIMPL;
365}
366
368 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
369{
370 if (pDispParams == NULL)
371 return E_INVALIDARG;
372 switch (dispIdMember)
373 {
376 break;
379 break;
380 }
381 return E_INVALIDARG;
382}
383
385{
386 Invalidate(FALSE);
387 return 0;
388}
389
391{
392 return 1;
393}
394
396{
397 PAINTSTRUCT paintInfo;
398 HDC dc;
399 POINT destinationPoint;
400 HDC sourceDC;
401 HBITMAP oldBitmap;
402 RECT clientRect;
403 RECT tempRect;
404
405 dc = BeginPaint(&paintInfo);
406 GetClientRect(&clientRect);
407
408 destinationPoint.x = (clientRect.right - clientRect.left - fBitmapSize) / 2;
409 destinationPoint.y = (clientRect.bottom - clientRect.top - fBitmapSize) / 2;
410
411 ::SetBkColor(dc, RGB(255, 255, 255));
412
413 tempRect.left = 0;
414 tempRect.top = 0;
415 tempRect.right = clientRect.right;
416 tempRect.bottom = destinationPoint.y;
417 FillSolidRect(dc, &tempRect, RGB(255, 255, 255));
418
419 tempRect.left = 0;
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));
424
425 tempRect.left = 0;
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));
430
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));
436
437 sourceDC = CreateCompatibleDC(dc);
438 oldBitmap = reinterpret_cast<HBITMAP>(SelectObject(sourceDC, fImageBitmap));
439
440 BitBlt(dc, destinationPoint.x, destinationPoint.y, fBitmapSize, fBitmapSize, sourceDC, 0, fCurrentFrame * fBitmapSize, SRCCOPY);
441
442 SelectObject(sourceDC, oldBitmap);
443 DeleteDC(sourceDC);
444
445 EndPaint(&paintInfo);
446 return 0;
447}
448
450{
453 fCurrentFrame = 0;
454 Invalidate(FALSE);
455 return 0;
456}
HWND hWnd
Definition: settings.c:17
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
static const int gMediumImageSize
Definition: brandband.cpp:47
void FillSolidRect(HDC dc, const RECT *bounds)
Definition: brandband.cpp:35
static const int gTrueColorResourceBase
Definition: brandband.cpp:50
static const int gLargeImageSize
Definition: brandband.cpp:48
static const int g256ColorResourceBase
Definition: brandband.cpp:51
void Release()
Definition: atlcomcli.h:170
HBITMAP fImageBitmap
Definition: brandband.h:41
STDMETHOD() QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText) override
Definition: brandband.cpp:311
STDMETHOD() Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
Definition: brandband.cpp:367
STDMETHOD() GetSizeMax(ULARGE_INTEGER *pcbSize) override
Definition: brandband.cpp:293
STDMETHOD() SetSite(IUnknown *pUnkSite) override
Definition: brandband.cpp:141
DWORD fProfferCookie
Definition: brandband.h:38
int fBitmapSize
Definition: brandband.h:42
STDMETHOD() GetWindow(HWND *lphwnd) override
Definition: brandband.cpp:210
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: brandband.cpp:384
void SelectImage()
Definition: brandband.cpp:81
STDMETHOD() OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override
Definition: brandband.cpp:298
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
Definition: brandband.cpp:361
LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: brandband.cpp:449
STDMETHOD() CloseDW(DWORD dwReserved) override
Definition: brandband.cpp:223
STDMETHOD() GetSite(REFIID riid, void **ppvSite) override
Definition: brandband.cpp:198
STDMETHOD() Save(IStream *pStm, BOOL fClearDirty) override
Definition: brandband.cpp:288
STDMETHOD() UIActivateIO(BOOL fActivate, LPMSG lpMsg) override
Definition: brandband.cpp:265
STDMETHOD() IsDirty() override
Definition: brandband.cpp:278
STDMETHOD() Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override
Definition: brandband.cpp:317
STDMETHOD() IsWindowOwner(HWND hWnd) override
Definition: brandband.cpp:304
int fMaxFrameCount
Definition: brandband.h:40
CComPtr< IDockingWindowSite > fSite
Definition: brandband.h:37
void StopAnimation()
Definition: brandband.cpp:74
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: brandband.cpp:395
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: brandband.cpp:390
DWORD fAdviseCookie
Definition: brandband.h:43
STDMETHOD() HasFocusIO() override
Definition: brandband.cpp:253
int fCurrentFrame
Definition: brandband.h:39
STDMETHOD() ResizeBorderDW(const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) override
Definition: brandband.cpp:235
STDMETHOD() Load(IStream *pStm) override
Definition: brandband.cpp:283
STDMETHOD() QueryService(REFGUID guidService, REFIID riid, void **ppvObject) override
Definition: brandband.cpp:338
STDMETHOD() ShowDW(BOOL fShow) override
Definition: brandband.cpp:241
STDMETHOD() GetClassID(CLSID *pClassID) override
Definition: brandband.cpp:270
STDMETHOD() TranslateAcceleratorIO(LPMSG lpMsg) override
Definition: brandband.cpp:260
STDMETHOD() GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
Definition: brandband.cpp:356
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
Definition: brandband.cpp:351
STDMETHOD() ContextSensitiveHelp(BOOL fEnterMode) override
Definition: brandband.cpp:218
void StartAnimation()
Definition: brandband.cpp:68
STDMETHOD() GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi) override
Definition: brandband.cpp:110
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HRESULT WINAPI AtlAdvise(IUnknown *pUnkCP, IUnknown *pUnk, const IID *iid, DWORD *pdw)
Definition: atl.c:45
HRESULT WINAPI AtlUnadvise(IUnknown *pUnkCP, const IID *iid, DWORD dw)
Definition: atl.c:73
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
DWORD WINAPI SHGetCurColorRes(void)
Definition: ordinal.c:2019
HWND WINAPI SHCreateWorkerWindowW(WNDPROC wndProc, HWND hWndParent, DWORD dwExStyle, DWORD dwStyle, HMENU hMenu, LONG_PTR wnd_extra)
Definition: ordinal.c:3000
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
#define RGB(r, g, b)
Definition: precomp.h:71
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
REFIID riid
Definition: atlbase.h:39
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static const WCHAR dc[]
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static LPOLESTR
Definition: stg_prop.c:27
static VARIANTARG static DISPID
Definition: ordinal.c:52
#define min(a, b)
Definition: monoChain.cc:55
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:95
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
DWORD LCID
Definition: nls.h:13
#define SID_SShellBrowser
Definition: shlguid.h:128
Definition: bl.h:1331
Definition: scsiwmi.h:51
LONG y
Definition: windef.h:330
LONG x
Definition: windef.h:329
COLORREF crBkgnd
Definition: shobjidl.idl:2424
WCHAR wszTitle[256]
Definition: shobjidl.idl:2422
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
Definition: taskmgr.c:491
uint32_t ULONG
Definition: typedefs.h:59
#define BBID_STARTANIMATION
Definition: undocshell.h:821
#define BBID_STOPANIMATION
Definition: undocshell.h:822
#define DISPID_DOWNLOADCOMPLETE
Definition: webchild.h:39
#define DISPID_DOWNLOADBEGIN
Definition: webchild.h:41
_In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon.h:531
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#define SubclassWindow(hwnd, lpfn)
Definition: windowsx.h:542
#define S_FALSE
Definition: winerror.h:2357
#define E_POINTER
Definition: winerror.h:2365
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:999
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
#define ExtTextOut
Definition: wingdi.h:4454
#define ETO_OPAQUE
Definition: wingdi.h:647
BOOL WINAPI DeleteDC(_In_ HDC)
HWND WINAPI GetFocus(void)
Definition: window.c:1893
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define SW_HIDE
Definition: winuser.h:768
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define LoadBitmap
Definition: winuser.h:5811
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define SW_SHOW
Definition: winuser.h:775
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IID_PPV_ARG(Itype, ppType)