ReactOS 0.4.15-dev-8428-g6910fa6
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
24/*
25 * TrayNotifyWnd
26 */
27
28static const WCHAR szTrayNotifyWndClass[] = L"TrayNotifyWnd";
29
30#define TRAY_NOTIFY_WND_SPACING_X 1
31#define TRAY_NOTIFY_WND_SPACING_Y 1
32
34 public CComCoClass<CTrayNotifyWnd>,
35 public CComObjectRootEx<CComMultiThreadModelNoCS>,
36 public CWindowImpl < CTrayNotifyWnd, CWindow, CControlWinTraits >,
37 public IOleWindow
38{
41
44
50
51public:
57 {
61 }
62 virtual ~CTrayNotifyWnd() { }
63
65 {
66 if (TrayTheme)
68
69 if (IsThemeActive())
70 TrayTheme = OpenThemeData(m_hWnd, L"TrayNotify");
71 else
73
74 if (TrayTheme)
75 {
77
79 NULL,
81 0,
83 NULL,
85 }
86 else
87 {
89
94 }
95
96 return TRUE;
97 }
98
100 {
101 return OnThemeChanged();
102 }
103
105 {
106 HRESULT hr;
107
110 return FALSE;
111
114 return FALSE;
115
118 return FALSE;
119
122 return FALSE;
123
124 return TRUE;
125 }
126
128 {
129 SIZE szClock = { 0, 0 };
130 SIZE szTray = { 0, 0 };
131
133 {
134 if (IsHorizontal)
135 {
136 szClock.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
137 if (szClock.cy <= 0)
138 goto NoClock;
139 }
140 else
141 {
142 szClock.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
143 if (szClock.cx <= 0)
144 goto NoClock;
145 }
146
148
149 szTrayClockMin = szClock;
150 }
151 else
152 NoClock:
153 szTrayClockMin = szClock;
154
155 if (IsHorizontal)
156 {
157 szTray.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
158 }
159 else
160 {
161 szTray.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
162 }
163
165
166 szTrayNotify = szTray;
167
168 if (IsHorizontal)
169 {
170 pSize->cx = 2 * TRAY_NOTIFY_WND_SPACING_X;
171
174
175 pSize->cx += szTray.cx;
177 }
178 else
179 {
180 pSize->cy = 2 * TRAY_NOTIFY_WND_SPACING_Y;
181
184
185 pSize->cy += szTray.cy;
187 }
188
189 return TRUE;
190 }
191
192 VOID Size(IN const SIZE *pszClient)
193 {
195 {
196 POINT ptClock;
197 SIZE szClock;
198
199 if (IsHorizontal)
200 {
201 ptClock.x = pszClient->cx - szTrayClockMin.cx - ContentMargin.cxRightWidth;
202 ptClock.y = ContentMargin.cyTopHeight;
203 szClock.cx = szTrayClockMin.cx;
204 szClock.cy = pszClient->cy - ContentMargin.cyTopHeight - ContentMargin.cyBottomHeight;
205 }
206 else
207 {
208 ptClock.x = ContentMargin.cxLeftWidth;
209 ptClock.y = pszClient->cy - szTrayClockMin.cy;
210 szClock.cx = pszClient->cx - ContentMargin.cxLeftWidth - ContentMargin.cxRightWidth;
211 szClock.cy = szTrayClockMin.cy;
212 }
213
215 NULL,
216 ptClock.x,
217 ptClock.y,
218 szClock.cx,
219 szClock.cy,
221 }
222
223 POINT ptPager;
224
225 if (IsHorizontal)
226 {
227 ptPager.x = ContentMargin.cxLeftWidth;
228 ptPager.y = (pszClient->cy - szTrayNotify.cy)/2;
229 }
230 else
231 {
232 ptPager.x = (pszClient->cx - szTrayNotify.cx)/2;
233 ptPager.y = ContentMargin.cyTopHeight;
234 }
235
237 NULL,
238 ptPager.x,
239 ptPager.y,
243 }
244
246 {
247 HDC hdc = (HDC) wParam;
248
249 if (!TrayTheme)
250 {
251 bHandled = FALSE;
252 return 0;
253 }
254
255 RECT rect;
259
261
262 return TRUE;
263 }
264
266 {
267 BOOL Horizontal = (BOOL) wParam;
268
269 if (Horizontal != IsHorizontal)
270 {
271 IsHorizontal = Horizontal;
272 if (IsHorizontal)
273 SetWindowTheme(m_hWnd, L"TrayNotifyHoriz", NULL);
274 else
275 SetWindowTheme(m_hWnd, L"TrayNotifyVert", NULL);
276 }
277
279 }
280
282 {
283 SIZE szClient;
284
285 szClient.cx = LOWORD(lParam);
286 szClient.cy = HIWORD(lParam);
287
288 Size(&szClient);
289
290 return TRUE;
291 }
292
294 {
295 return HTTRANSPARENT;
296 }
297
299 {
300 bHandled = TRUE;
301
302 if (reinterpret_cast<HWND>(wParam) == m_hwndClock)
303 return GetParent().SendMessage(uMsg, wParam, lParam);
304 else
305 return 0;
306 }
307
309 {
310 return SendMessageW(m_hwndClock, uMsg, wParam, lParam);
311 }
312
314 {
315 return SendMessageW(m_hwndPager, uMsg, wParam, lParam);
316 }
317
318 LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled)
319 {
320 hdr->hwndFrom = m_hWnd;
322 }
323
325 {
326 if (!phwnd)
327 return E_INVALIDARG;
328 *phwnd = m_hWnd;
329 return S_OK;
330 }
331
333 {
334 return E_NOTIMPL;
335 }
336
338
343
345
348 MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
361
363 {
365 Create(hwndParent, 0, NULL, dwStyle, WS_EX_STATICEDGE);
366 if (!m_hWnd)
367 return E_FAIL;
368 return S_OK;
369 }
370};
371
373{
374 return ShellObjectCreatorInit<CTrayNotifyWnd>(hwndParent, riid, ppv);
375}
@ 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 NTNWM_REALIGN
Definition: precomp.h:373
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:318
HRESULT WINAPI GetWindow(HWND *phwnd)
Definition: trayntfy.cpp:324
CComPtr< IUnknown > m_pager
Definition: trayntfy.cpp:40
LRESULT OnClockMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:308
BOOL GetMinimumSize(IN OUT PSIZE pSize)
Definition: trayntfy.cpp:127
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:245
BOOL IsHorizontal
Definition: trayntfy.cpp:49
LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:313
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:293
SIZE szTrayClockMin
Definition: trayntfy.cpp:46
LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:265
CComPtr< IUnknown > m_clock
Definition: trayntfy.cpp:39
HTHEME TrayTheme
Definition: trayntfy.cpp:45
virtual ~CTrayNotifyWnd()
Definition: trayntfy.cpp:62
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:298
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:281
LRESULT OnThemeChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:99
LRESULT OnThemeChanged()
Definition: trayntfy.cpp:64
SIZE szTrayNotify
Definition: trayntfy.cpp:47
HWND m_hwndClock
Definition: trayntfy.cpp:42
HWND m_hwndPager
Definition: trayntfy.cpp:43
MARGINS ContentMargin
Definition: trayntfy.cpp:48
VOID Size(IN const SIZE *pszClient)
Definition: trayntfy.cpp:192
HRESULT WINAPI ContextSensitiveHelp(BOOL fEnterMode)
Definition: trayntfy.cpp:332
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:104
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
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
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 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
TW_STRUCKRECTS2 sr
Definition: precomp.h:225
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
static const WCHAR szTrayNotifyWndClass[]
Definition: trayntfy.cpp:28
#define TRAY_NOTIFY_WND_SPACING_Y
Definition: trayntfy.cpp:31
#define TRAY_NOTIFY_WND_SPACING_X
Definition: trayntfy.cpp:30
HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayntfy.cpp:372
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 WM_ERASEBKGND
Definition: winuser.h:1625
#define WS_EX_STATICEDGE
Definition: winuser.h:403
#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 WM_SIZE
Definition: winuser.h:1611
#define WM_NCHITTEST
Definition: winuser.h:1686
#define CS_DBLCLKS
Definition: winuser.h:651
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1694
#define WM_SETTINGCHANGE
Definition: winuser.h:1629
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WM_SETFONT
Definition: winuser.h:1650
#define WM_COPYDATA
Definition: winuser.h:1664
#define SendMessage
Definition: winuser.h:5852
#define HTTRANSPARENT
Definition: winuser.h:2473
#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
static void Initialize()
Definition: xlate.c:212
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180