ReactOS  0.4.13-dev-563-g0561610
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 
28 static 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 
51 public:
55  TrayTheme(NULL),
57  {
61  }
62  virtual ~CTrayNotifyWnd() { }
63 
65  {
66  if (TrayTheme)
68 
69  if (IsThemeActive())
70  TrayTheme = OpenThemeData(m_hWnd, L"TrayNotify");
71  else
72  TrayTheme = NULL;
73 
74  if (TrayTheme)
75  {
77 
79  NULL,
81  0,
83  NULL,
84  &ContentMargin);
85  }
86  else
87  {
89 
94  }
95 
96  return TRUE;
97  }
98 
100  {
101  return OnThemeChanged();
102  }
103 
105  {
106  HRESULT hr;
107 
109  if (FAILED_UNEXPECTEDLY(hr))
110  return FALSE;
111 
113  if (FAILED_UNEXPECTEDLY(hr))
114  return FALSE;
115 
117  if (FAILED_UNEXPECTEDLY(hr))
118  return FALSE;
119 
121  if (FAILED_UNEXPECTEDLY(hr))
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,
220  SWP_NOZORDER);
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,
242  SWP_NOZORDER);
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 
278  return (LRESULT) GetMinimumSize((PSIZE) lParam);
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  return 0;
302  }
303 
305  {
306  return SendMessageW(m_hwndClock, uMsg, wParam, lParam);
307  }
308 
310  {
311  return SendMessageW(m_hwndPager, uMsg, wParam, lParam);
312  }
313 
314  LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled)
315  {
316  hdr->hwndFrom = m_hWnd;
317  return GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM)hdr);
318  }
319 
321  {
322  if (!phwnd)
323  return E_INVALIDARG;
324  *phwnd = m_hWnd;
325  return S_OK;
326  }
327 
329  {
330  return E_NOTIMPL;
331  }
332 
334 
338  END_COM_MAP()
339 
341 
344  MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
348  MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu) // FIXME: This handler is not necessary in Windows
356  END_MSG_MAP()
357 
359  {
361  Create(hwndParent, 0, NULL, dwStyle, WS_EX_STATICEDGE);
362  if (!m_hWnd)
363  return E_FAIL;
364  return S_OK;
365  }
366 };
367 
369 {
370  return ShellObjectCreatorInit<CTrayNotifyWnd>(hwndParent, riid, ppv);
371 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define TRAY_NOTIFY_WND_SPACING_X
Definition: trayntfy.cpp:30
#define IN
Definition: typedefs.h:38
#define HTTRANSPARENT
Definition: winuser.h:2427
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
DWORD HideClock
Definition: precomp.h:195
HWND m_hwndClock
Definition: trayntfy.cpp:42
char hdr[14]
Definition: iptest.cpp:33
long y
Definition: polytest.cpp:48
#define WM_CONTEXTMENU
Definition: richedit.h:64
MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu) HRESULT Initialize(IN HWND hwndParent)
Definition: trayntfy.cpp:348
HRESULT hr
Definition: shlfolder.c:183
BOOL IsHorizontal
Definition: trayntfy.cpp:49
long x
Definition: polytest.cpp:48
REFIID riid
Definition: precomp.h:44
HWND Create(HWND hWndParent, _U_RECT rect=NULL, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle=0, _U_MENUorID MenuOrID=0U, LPVOID lpCreateParam=NULL)
Definition: atlwin.h:1631
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:293
#define TNWM_GETMINIMUMSIZE
Definition: precomp.h:333
static HDC
Definition: imagelist.c:92
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd)
Definition: atlwin.h:1876
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags)
Definition: atlwin.h:1220
HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayntfy.cpp:368
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
#define ZeroMemory
Definition: winbase.h:1635
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:611
HWND m_hwndPager
Definition: trayntfy.cpp:43
#define WM_NCHITTEST
Definition: winuser.h:1668
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define SWP_NOZORDER
Definition: winuser.h:1232
HTHEME TrayTheme
Definition: trayntfy.cpp:45
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
#define BOOL
Definition: nt_native.h:43
HRESULT WINAPI IUnknown_GetWindow(IUnknown *lpUnknown, HWND *lphWnd)
Definition: ordinal.c:1283
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
Definition: draw.c:128
int32_t INT
Definition: typedefs.h:56
TW_STRUCKRECTS2 sr
Definition: precomp.h:209
Definition: misc.c:279
& rect
Definition: startmenu.cpp:1413
WPARAM wParam
Definition: combotst.c:138
HRESULT CTrayClockWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayclock.cpp:751
#define WM_SETTINGCHANGE
Definition: winuser.h:1611
VOID Size(IN const SIZE *pszClient)
Definition: trayntfy.cpp:192
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
static const WCHAR szTrayNotifyWndClass[]
Definition: trayntfy.cpp:28
LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:309
#define COLOR_3DFACE
Definition: winuser.h:919
#define TWM_SETTINGSCHANGED
Definition: precomp.h:132
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324
BOOL GetClientRect(LPRECT lpRect) const
Definition: atlwin.h:507
int cyBottomHeight
Definition: misc.c:283
SIZE szTrayClockMin
Definition: trayntfy.cpp:46
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
CComPtr< IUnknown > m_clock
Definition: trayntfy.cpp:39
TaskbarSettings g_TaskbarSettings
Definition: settings.cpp:23
static HWND hwndParent
Definition: cryptui.c:300
LONG cx
Definition: windef.h:319
LONG_PTR LPARAM
Definition: windef.h:208
#define TRAY_NOTIFY_WND_SPACING_Y
Definition: trayntfy.cpp:31
LRESULT OnThemeChanged()
Definition: trayntfy.cpp:64
MARGINS ContentMargin
Definition: trayntfy.cpp:48
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
Definition: draw.c:72
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:541
#define WM_COPYDATA
Definition: winuser.h:1646
#define NTNWM_REALIGN
Definition: precomp.h:336
int cyTopHeight
Definition: misc.c:282
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_SIZE
Definition: winuser.h:1593
LONG HRESULT
Definition: typedefs.h:77
#define END_MSG_MAP()
Definition: atlwin.h:1789
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
BOOL GetMinimumSize(IN OUT PSIZE pSize)
Definition: trayntfy.cpp:127
int cxLeftWidth
Definition: misc.c:280
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
Definition: system.c:835
HRESULT WINAPI GetWindow(HWND *phwnd)
Definition: trayntfy.cpp:320
#define SetWindowExStyle(h, val)
Definition: utility.h:154
HRESULT CSysPagerWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: syspager.cpp:1578
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
HWND m_hWnd
Definition: atlwin.h:268
#define CS_DBLCLKS
Definition: winuser.h:646
CComPtr< IUnknown > m_pager
Definition: trayntfy.cpp:40
HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
Definition: property.c:216
#define S_OK
Definition: intsafe.h:59
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:281
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:561
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define E_NOTIMPL
Definition: ddrawi.h:99
BOOL Initialize(HINSTANCE hInstance)
Definition: msconfig.c:341
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:298
virtual ~CTrayNotifyWnd()
Definition: trayntfy.cpp:62
unsigned int UINT
Definition: ndis.h:50
LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL &bHandled)
Definition: trayntfy.cpp:314
#define NOTIFY_CODE_HANDLER(cd, func)
Definition: atlwin.h:1852
#define WM_SETFONT
Definition: winuser.h:1632
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:245
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1770
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:639
SIZE szTrayNotify
Definition: trayntfy.cpp:47
#define OUT
Definition: typedefs.h:39
#define WM_CREATE
Definition: winuser.h:1590
HRESULT WINAPI ContextSensitiveHelp(BOOL fEnterMode)
Definition: trayntfy.cpp:328
const GUID IID_IOleWindow
#define HIWORD(l)
Definition: typedefs.h:246
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1048
BOOL WINAPI IsThemeActive(void)
Definition: system.c:606
int cxRightWidth
Definition: misc.c:281
CWindow GetParent() const
Definition: atlwin.h:654
#define END_COM_MAP()
Definition: atlcom.h:552
#define WM_ERASEBKGND
Definition: winuser.h:1607
LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:265
LONG_PTR LRESULT
Definition: windef.h:209
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:104
#define WS_VISIBLE
Definition: pedump.c:620
LRESULT OnClockMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:304
LONG cy
Definition: windef.h:320
#define WS_EX_STATICEDGE
Definition: winuser.h:403
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
Definition: system.c:950
LRESULT OnThemeChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:99
#define WM_NOTIFY
Definition: richedit.h:61
#define WM_NCLBUTTONDBLCLK
Definition: winuser.h:1676