ReactOS 0.4.15-dev-8434-g155a7c7
trayntfy.cpp
Go to the documentation of this file.
1/*
2 * ReactOS Explorer
3 *
4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5 * Copyright 2018 Ged Murphy <gedmurphy@reactos.org>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "precomp.h"
23#include <commoncontrols.h>
24
25static const WCHAR szTrayNotifyWndClass[] = L"TrayNotifyWnd";
26
27#define TRAY_NOTIFY_WND_SPACING_X 1
28#define TRAY_NOTIFY_WND_SPACING_Y 1
29#define CLOCK_TEXT_HACK 4
30
31/*
32 * TrayNotifyWnd
33 */
34
36 public CComCoClass<CTrayNotifyWnd>,
37 public CComObjectRootEx<CComMultiThreadModelNoCS>,
38 public CWindowImpl < CTrayNotifyWnd, CWindow, CControlWinTraits >,
39 public IOleWindow
40{
44
48
55
56public:
62 {
67 }
69
71 {
72 if (TrayTheme)
74
75 if (IsThemeActive())
76 TrayTheme = OpenThemeData(m_hWnd, L"TrayNotify");
77 else
79
80 if (TrayTheme)
81 {
83
85 NULL,
87 0,
89 NULL,
91 }
92 else
93 {
95
100 }
101
102 return TRUE;
103 }
104
106 {
107 return OnThemeChanged();
108 }
109
111 {
112 HRESULT hr;
113
116 return FALSE;
117
120 return FALSE;
121
124 return FALSE;
125
128 return FALSE;
129
130 /* Create the 'Show Desktop' button */
133
134 return TRUE;
135 }
136
138 {
139 SIZE clockSize = { 0, 0 };
140 SIZE traySize = { 0, 0 };
141 SIZE showDesktopSize = { 0, 0 };
142
144 {
145 if (IsHorizontal)
146 {
147 clockSize.cy = pSize->cy;
148 if (clockSize.cy <= 0)
149 goto NoClock;
150 }
151 else
152 {
153 clockSize.cx = pSize->cx;
154 if (clockSize.cx <= 0)
155 goto NoClock;
156 }
157
159
160 trayClockMinSize = clockSize;
161 }
162 else
163 NoClock:
164 trayClockMinSize = clockSize;
165
166 if (IsHorizontal)
167 {
168 traySize.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
169 }
170 else
171 {
172 traySize.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
173 }
174
176
177 trayNotifySize = traySize;
178
179 INT showDesktopButtonExtent = 0;
181 {
182 showDesktopButtonExtent = m_ShowDesktopButton.WidthOrHeight();
183 if (IsHorizontal)
184 {
185 showDesktopSize.cx = showDesktopButtonExtent;
186 showDesktopSize.cy = pSize->cy;
187 }
188 else
189 {
190 showDesktopSize.cx = pSize->cx;
191 showDesktopSize.cy = showDesktopButtonExtent;
192 }
193 }
194 trayShowDesktopSize = showDesktopSize;
195
196 if (IsHorizontal)
197 {
198 pSize->cx = 2 * TRAY_NOTIFY_WND_SPACING_X;
199
202
204 pSize->cx += showDesktopButtonExtent;
205
206 pSize->cx += traySize.cx;
208 }
209 else
210 {
211 pSize->cy = 2 * TRAY_NOTIFY_WND_SPACING_Y;
212
215
217 pSize->cy += showDesktopButtonExtent;
218
219 pSize->cy += traySize.cy;
221 }
222
223 return TRUE;
224 }
225
226 VOID Size(IN OUT SIZE *pszClient)
227 {
228 RECT rcClient = {0, 0, pszClient->cx, pszClient->cy};
229 AlignControls(&rcClient);
230 pszClient->cx = rcClient.right - rcClient.left;
231 pszClient->cy = rcClient.bottom - rcClient.top;
232 }
233
235 {
236 RECT rcClient;
237 if (prcClient != NULL)
238 rcClient = *prcClient;
239 else
240 GetClientRect(&rcClient);
241
242 rcClient.left += ContentMargin.cxLeftWidth;
243 rcClient.top += ContentMargin.cyTopHeight;
244 rcClient.right -= ContentMargin.cxRightWidth;
246
248
250 {
251 POINT ptShowDesktop =
252 {
253 rcClient.left,
254 rcClient.top
255 };
256 SIZE showDesktopSize =
257 {
258 rcClient.right - rcClient.left,
259 rcClient.bottom - rcClient.top
260 };
261
262 INT cxyShowDesktop = m_ShowDesktopButton.WidthOrHeight();
263 if (IsHorizontal)
264 {
265 if (!TrayTheme)
266 {
267 ptShowDesktop.y -= ContentMargin.cyTopHeight;
269 }
270
271 rcClient.right -= (cxyShowDesktop - ContentMargin.cxRightWidth);
272
273 ptShowDesktop.x = rcClient.right;
274 showDesktopSize.cx = cxyShowDesktop;
275
276 // HACK: Clock has layout problems - remove this once addressed.
277 rcClient.right -= CLOCK_TEXT_HACK;
278 }
279 else
280 {
281 if (!TrayTheme)
282 {
283 ptShowDesktop.x -= ContentMargin.cxLeftWidth;
285 }
286
287 rcClient.bottom -= (cxyShowDesktop - ContentMargin.cyBottomHeight);
288
289 ptShowDesktop.y = rcClient.bottom;
290 showDesktopSize.cy = cxyShowDesktop;
291
292 // HACK: Clock has layout problems - remove this once addressed.
293 rcClient.bottom -= CLOCK_TEXT_HACK;
294 }
295
296 /* Resize and reposition the button */
298 NULL,
299 ptShowDesktop.x,
300 ptShowDesktop.y,
301 showDesktopSize.cx,
302 showDesktopSize.cy,
303 swpFlags);
304 }
305
307 {
308 POINT ptClock = { rcClient.left, rcClient.top };
309 SIZE clockSize = { rcClient.right - rcClient.left, rcClient.bottom - rcClient.top };
310
311 if (IsHorizontal)
312 {
313 rcClient.right -= trayClockMinSize.cx;
314
315 ptClock.x = rcClient.right;
316 clockSize.cx = trayClockMinSize.cx;
317 }
318 else
319 {
320 rcClient.bottom -= trayClockMinSize.cy;
321
322 ptClock.y = rcClient.bottom;
323 clockSize.cy = trayClockMinSize.cy;
324 }
325
327 NULL,
328 ptClock.x,
329 ptClock.y,
330 clockSize.cx,
331 clockSize.cy,
332 swpFlags);
333 }
334
335 POINT ptPager;
336 if (IsHorizontal)
337 {
338 ptPager.x = ContentMargin.cxLeftWidth;
339 ptPager.y = ((rcClient.bottom - rcClient.top) - trayNotifySize.cy) / 2;
341 ptPager.y += ContentMargin.cyTopHeight;
342 }
343 else
344 {
345 ptPager.x = ((rcClient.right - rcClient.left) - trayNotifySize.cx) / 2;
347 ptPager.x += ContentMargin.cxLeftWidth;
348 ptPager.y = ContentMargin.cyTopHeight;
349 }
350
352 NULL,
353 ptPager.x,
354 ptPager.y,
357 swpFlags);
358
359 if (prcClient != NULL)
360 {
361 prcClient->left = rcClient.left - ContentMargin.cxLeftWidth;
362 prcClient->top = rcClient.top - ContentMargin.cyTopHeight;
363 prcClient->right = rcClient.right + ContentMargin.cxRightWidth;
364 prcClient->bottom = rcClient.bottom + ContentMargin.cyBottomHeight;
365 }
366 }
367
369 {
370 HDC hdc = (HDC) wParam;
371
372 if (!TrayTheme)
373 {
374 bHandled = FALSE;
375 return 0;
376 }
377
378 RECT rect;
382
384
385 return TRUE;
386 }
387
389 {
390 BOOL Horizontal = (BOOL) wParam;
391
392 if (Horizontal != IsHorizontal)
393 IsHorizontal = Horizontal;
394
396 IsHorizontal ? L"TrayNotifyHoriz" : L"TrayNotifyVert",
397 NULL);
399
401 }
402
404 {
405 if (wParam == NULL)
406 return 0;
407
410 {
411 *ptr = NULL;
412 return 0;
413 }
414
416 bHandled = TRUE;
417 return 0;
418 }
419
421 {
422 SIZE clientSize;
423
424 clientSize.cx = LOWORD(lParam);
425 clientSize.cy = HIWORD(lParam);
426
427 Size(&clientSize);
428
429 return TRUE;
430 }
431
433 {
434 POINT pt;
437
439 return HTCLIENT;
440
441 return HTTRANSPARENT;
442 }
443
445 {
446 POINT pt;
448
451
452 return TRUE;
453 }
454
456 {
457 bHandled = TRUE;
458
459 if (reinterpret_cast<HWND>(wParam) == m_hwndClock)
460 return GetParent().SendMessage(uMsg, wParam, lParam);
461 else
462 return 0;
463 }
464
466 {
467 return SendMessageW(m_hwndClock, uMsg, wParam, lParam);
468 }
469
471 {
472 TaskbarSettings* newSettings = (TaskbarSettings*)lParam;
473
474 /* Toggle show desktop button */
476 {
479
480 /* Ask the parent to resize */
481 NMHDR nmh = {m_hWnd, 0, NTNWM_REALIGN};
482 SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
483 }
484
485 return OnClockMessage(uMsg, wParam, lParam, bHandled);
486 }
487
489 {
490 return SendMessageW(m_hwndPager, uMsg, wParam, lParam);
491 }
492
493 LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled)
494 {
495 hdr->hwndFrom = m_hWnd;
497 }
498
500 {
501 if (!phwnd)
502 return E_INVALIDARG;
503 *phwnd = m_hWnd;
504 return S_OK;
505 }
506
508 {
509 return E_NOTIMPL;
510 }
511
513 {
515 Create(hwndParent, 0, NULL, dwStyle, WS_EX_STATICEDGE);
516 return m_hWnd ? S_OK : E_FAIL;
517 }
518
520
525
527
530 MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
546};
547
549{
550 return ShellObjectCreatorInit<CTrayNotifyWnd>(hwndParent, riid, ppv);
551}
@ Create
Definition: registry.c:563
HRESULT CTrayClockWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayclock.cpp:779
HRESULT CSysPagerWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: syspager.cpp:1611
#define TNWM_GETMINIMUMSIZE
Definition: precomp.h:370
TaskbarSettings g_TaskbarSettings
Definition: settings.cpp:23
#define TWM_SETTINGSCHANGED
Definition: precomp.h:133
#define TNWM_GETSHOWDESKTOPBUTTON
Definition: precomp.h:372
#define NTNWM_REALIGN
Definition: precomp.h:374
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1116
CWindow GetParent() const
Definition: atlwin.h:700
HWND m_hWnd
Definition: atlwin.h:273
LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL &bHandled)
Definition: trayntfy.cpp:493
SIZE trayShowDesktopSize
Definition: trayntfy.cpp:51
HRESULT WINAPI GetWindow(HWND *phwnd)
Definition: trayntfy.cpp:499
SIZE trayNotifySize
Definition: trayntfy.cpp:52
CComPtr< IUnknown > m_pager
Definition: trayntfy.cpp:43
VOID Size(IN OUT SIZE *pszClient)
Definition: trayntfy.cpp:226
SIZE trayClockMinSize
Definition: trayntfy.cpp:50
LRESULT OnClockMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:465
BOOL GetMinimumSize(IN OUT PSIZE pSize)
Definition: trayntfy.cpp:137
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:368
BOOL IsHorizontal
Definition: trayntfy.cpp:54
LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:488
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:432
LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:388
CComPtr< IUnknown > m_clock
Definition: trayntfy.cpp:41
HTHEME TrayTheme
Definition: trayntfy.cpp:49
LRESULT OnTaskbarSettingsChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:470
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:444
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:455
HRESULT Initialize(IN HWND hwndParent)
Definition: trayntfy.cpp:512
HWND m_hwndShowDesktop
Definition: trayntfy.cpp:46
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:420
LRESULT OnThemeChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:105
LRESULT OnThemeChanged()
Definition: trayntfy.cpp:70
HWND m_hwndClock
Definition: trayntfy.cpp:45
VOID AlignControls(IN CONST PRECT prcClient OPTIONAL)
Definition: trayntfy.cpp:234
HWND m_hwndPager
Definition: trayntfy.cpp:47
LRESULT OnGetShowDesktopButton(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:403
CTrayShowDesktopButton m_ShowDesktopButton
Definition: trayntfy.cpp:42
MARGINS ContentMargin
Definition: trayntfy.cpp:53
HRESULT WINAPI ContextSensitiveHelp(BOOL fEnterMode)
Definition: trayntfy.cpp:507
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:110
BOOL PtInButton(LPPOINT pt) const
HRESULT DoCreate(HWND hwndParent)
Definition: traydeskbtn.cpp:62
INT WidthOrHeight() const
Definition: traydeskbtn.cpp:33
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static HWND hwndParent
Definition: cryptui.c:300
#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 TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
HRESULT WINAPI IUnknown_GetWindow(IUnknown *lpUnknown, HWND *lphWnd)
Definition: ordinal.c:1332
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
Definition: draw.c:128
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
Definition: draw.c:72
HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
Definition: property.c:216
HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
Definition: system.c:835
BOOL WINAPI IsThemeActive(void)
Definition: system.c:606
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
Definition: system.c:950
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
char hdr[14]
Definition: iptest.cpp:33
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
#define MESSAGE_HANDLER(msg, func)
Definition: atlwin.h:1926
#define NOTIFY_CODE_HANDLER(cd, func)
Definition: atlwin.h:1980
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1898
#define END_MSG_MAP()
Definition: atlwin.h:1917
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd)
Definition: atlwin.h:2004
#define SetWindowExStyle(h, val)
Definition: utility.h:154
static PVOID ptr
Definition: dispmode.c:27
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
#define L(x)
Definition: ntvdm.h:50
const GUID IID_IOleWindow
#define LOWORD(l)
Definition: pedump.c:82
#define WS_CHILD
Definition: pedump.c:617
#define CONST
Definition: pedump.c:81
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define REFIID
Definition: guiddef.h:118
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define WM_NOTIFY
Definition: richedit.h:61
HRESULT hr
Definition: shlfolder.c:183
& rect
Definition: startmenu.cpp:1413
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
BOOL bShowDesktopButton
Definition: precomp.h:224
TW_STRUCKRECTS2 sr
Definition: precomp.h:225
BOOL UseCompactTrayIcons()
Definition: precomp.h:229
Definition: misc.c:279
int cyBottomHeight
Definition: misc.c:283
int cyTopHeight
Definition: misc.c:282
int cxRightWidth
Definition: misc.c:281
int cxLeftWidth
Definition: misc.c:280
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
DWORD HideClock
Definition: precomp.h:207
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
static const WCHAR szTrayNotifyWndClass[]
Definition: trayntfy.cpp:25
#define TRAY_NOTIFY_WND_SPACING_Y
Definition: trayntfy.cpp:28
#define TRAY_NOTIFY_WND_SPACING_X
Definition: trayntfy.cpp:27
#define CLOCK_TEXT_HACK
Definition: trayntfy.cpp:29
HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayntfy.cpp:548
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define HIWORD(l)
Definition: typedefs.h:247
#define OUT
Definition: typedefs.h:40
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324
@ TNP_BACKGROUND
Definition: vssym32.h:543
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define ZeroMemory
Definition: winbase.h:1712
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
#define WM_ERASEBKGND
Definition: winuser.h:1625
#define WS_EX_STATICEDGE
Definition: winuser.h:403
#define SW_HIDE
Definition: winuser.h:768
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define WM_CREATE
Definition: winuser.h:1608
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_DRAWFRAME
Definition: winuser.h:1239
#define WM_SIZE
Definition: winuser.h:1611
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2714
#define WM_NCHITTEST
Definition: winuser.h:1686
#define WM_MOUSEMOVE
Definition: winuser.h:1775
#define CS_DBLCLKS
Definition: winuser.h:651
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1694
#define WM_SETTINGCHANGE
Definition: winuser.h:1629
#define WM_NCMOUSEMOVE
Definition: winuser.h:1691
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define SWP_NOCOPYBITS
Definition: winuser.h:1243
#define WM_SETFONT
Definition: winuser.h:1650
#define HTCLIENT
Definition: winuser.h:2475
#define WM_COPYDATA
Definition: winuser.h:1664
#define SendMessage
Definition: winuser.h:5852
#define HTTRANSPARENT
Definition: winuser.h:2473
#define SW_SHOW
Definition: winuser.h:775
#define SWP_NOZORDER
Definition: winuser.h:1247
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define COLOR_3DFACE
Definition: winuser.h:929
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180