ReactOS  0.4.15-dev-5137-g826bd41
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  return MA_NOACTIVATE;
130  }
131 
133  {
134  SIZE szClock = { 0, 0 };
135  SIZE szTray = { 0, 0 };
136 
138  {
139  if (IsHorizontal)
140  {
141  szClock.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
142  if (szClock.cy <= 0)
143  goto NoClock;
144  }
145  else
146  {
147  szClock.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
148  if (szClock.cx <= 0)
149  goto NoClock;
150  }
151 
153 
154  szTrayClockMin = szClock;
155  }
156  else
157  NoClock:
158  szTrayClockMin = szClock;
159 
160  if (IsHorizontal)
161  {
162  szTray.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
163  }
164  else
165  {
166  szTray.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
167  }
168 
170 
171  szTrayNotify = szTray;
172 
173  if (IsHorizontal)
174  {
175  pSize->cx = 2 * TRAY_NOTIFY_WND_SPACING_X;
176 
179 
180  pSize->cx += szTray.cx;
182  }
183  else
184  {
185  pSize->cy = 2 * TRAY_NOTIFY_WND_SPACING_Y;
186 
189 
190  pSize->cy += szTray.cy;
192  }
193 
194  return TRUE;
195  }
196 
197  VOID Size(IN const SIZE *pszClient)
198  {
200  {
201  POINT ptClock;
202  SIZE szClock;
203 
204  if (IsHorizontal)
205  {
206  ptClock.x = pszClient->cx - szTrayClockMin.cx - ContentMargin.cxRightWidth;
207  ptClock.y = ContentMargin.cyTopHeight;
208  szClock.cx = szTrayClockMin.cx;
209  szClock.cy = pszClient->cy - ContentMargin.cyTopHeight - ContentMargin.cyBottomHeight;
210  }
211  else
212  {
213  ptClock.x = ContentMargin.cxLeftWidth;
214  ptClock.y = pszClient->cy - szTrayClockMin.cy;
215  szClock.cx = pszClient->cx - ContentMargin.cxLeftWidth - ContentMargin.cxRightWidth;
216  szClock.cy = szTrayClockMin.cy;
217  }
218 
220  NULL,
221  ptClock.x,
222  ptClock.y,
223  szClock.cx,
224  szClock.cy,
225  SWP_NOZORDER);
226  }
227 
228  POINT ptPager;
229 
230  if (IsHorizontal)
231  {
232  ptPager.x = ContentMargin.cxLeftWidth;
233  ptPager.y = (pszClient->cy - szTrayNotify.cy)/2;
234  }
235  else
236  {
237  ptPager.x = (pszClient->cx - szTrayNotify.cx)/2;
238  ptPager.y = ContentMargin.cyTopHeight;
239  }
240 
242  NULL,
243  ptPager.x,
244  ptPager.y,
247  SWP_NOZORDER);
248  }
249 
251  {
252  HDC hdc = (HDC) wParam;
253 
254  if (!TrayTheme)
255  {
256  bHandled = FALSE;
257  return 0;
258  }
259 
260  RECT rect;
264 
266 
267  return TRUE;
268  }
269 
271  {
272  BOOL Horizontal = (BOOL) wParam;
273 
274  if (Horizontal != IsHorizontal)
275  {
276  IsHorizontal = Horizontal;
277  if (IsHorizontal)
278  SetWindowTheme(m_hWnd, L"TrayNotifyHoriz", NULL);
279  else
280  SetWindowTheme(m_hWnd, L"TrayNotifyVert", NULL);
281  }
282 
283  return (LRESULT) GetMinimumSize((PSIZE) lParam);
284  }
285 
287  {
288  SIZE szClient;
289 
290  szClient.cx = LOWORD(lParam);
291  szClient.cy = HIWORD(lParam);
292 
293  Size(&szClient);
294 
295  return TRUE;
296  }
297 
299  {
300  return HTTRANSPARENT;
301  }
302 
304  {
305  bHandled = TRUE;
306 
307  if (reinterpret_cast<HWND>(wParam) == m_hwndClock)
308  return GetParent().SendMessage(uMsg, wParam, lParam);
309  else
310  return 0;
311  }
312 
314  {
315  return SendMessageW(m_hwndClock, uMsg, wParam, lParam);
316  }
317 
319  {
320  return SendMessageW(m_hwndPager, uMsg, wParam, lParam);
321  }
322 
323  LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled)
324  {
325  hdr->hwndFrom = m_hWnd;
326  return GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM)hdr);
327  }
328 
330  {
331  if (!phwnd)
332  return E_INVALIDARG;
333  *phwnd = m_hWnd;
334  return S_OK;
335  }
336 
338  {
339  return E_NOTIMPL;
340  }
341 
343 
347  END_COM_MAP()
348 
350 
354  MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
366  END_MSG_MAP()
367 
369  {
371  Create(hwndParent, 0, NULL, dwStyle, WS_EX_STATICEDGE);
372  if (!m_hWnd)
373  return E_FAIL;
374  return S_OK;
375  }
376 };
377 
379 {
380  return ShellObjectCreatorInit<CTrayNotifyWnd>(hwndParent, riid, ppv);
381 }
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define TRAY_NOTIFY_WND_SPACING_X
Definition: trayntfy.cpp:30
#define IN
Definition: typedefs.h:39
#define HTTRANSPARENT
Definition: winuser.h:2463
#define REFIID
Definition: guiddef.h:118
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
HRESULT hr
Definition: shlfolder.c:183
BOOL IsHorizontal
Definition: trayntfy.cpp:49
long x
Definition: polytest.cpp:48
#define TRUE
Definition: types.h:120
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:1728
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:298
#define TNWM_GETMINIMUMSIZE
Definition: precomp.h:333
static HDC
Definition: imagelist.c:92
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd)
Definition: atlwin.h:1998
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL SetWindowPos(HWND hWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags)
Definition: atlwin.h:1282
HRESULT CTrayNotifyWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: trayntfy.cpp:378
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
#define ZeroMemory
Definition: winbase.h:1667
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:612
HWND m_hwndPager
Definition: trayntfy.cpp:43
#define WM_NCHITTEST
Definition: winuser.h:1676
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
#define SWP_NOZORDER
Definition: winuser.h:1237
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:1329
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:58
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:764
#define WM_SETTINGCHANGE
Definition: winuser.h:1619
VOID Size(IN const SIZE *pszClient)
Definition: trayntfy.cpp:197
BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
Definition: draw.c:1883
static const WCHAR szTrayNotifyWndClass[]
Definition: trayntfy.cpp:28
#define L(x)
Definition: ntvdm.h:50
LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:318
#define COLOR_3DFACE
Definition: winuser.h:923
#define FALSE
Definition: types.h:117
#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:535
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
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:334
LONG_PTR LPARAM
Definition: windef.h:208
#define TRAY_NOTIFY_WND_SPACING_Y
Definition: trayntfy.cpp:31
#define WM_MOUSEACTIVATE
Definition: winuser.h:1627
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:542
#define WM_COPYDATA
Definition: winuser.h:1654
#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:1601
LONG HRESULT
Definition: typedefs.h:79
#define END_MSG_MAP()
Definition: atlwin.h:1911
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
BOOL GetMinimumSize(IN OUT PSIZE pSize)
Definition: trayntfy.cpp:132
int cxLeftWidth
Definition: misc.c:280
#define WINAPI
Definition: msvc.h:6
LRESULT OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:127
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:329
#define SetWindowExStyle(h, val)
Definition: utility.h:154
HRESULT CSysPagerWnd_CreateInstance(HWND hwndParent, REFIID riid, void **ppv)
Definition: syspager.cpp:1584
HDC hdc
Definition: main.c:9
HWND m_hWnd
Definition: atlwin.h:267
#define CS_DBLCLKS
Definition: winuser.h:646
#define MA_NOACTIVATE
Definition: winuser.h:2493
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:52
HRESULT Initialize(IN HWND hwndParent)
Definition: trayntfy.cpp:368
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:286
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:562
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define E_NOTIMPL
Definition: ddrawi.h:99
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:303
virtual ~CTrayNotifyWnd()
Definition: trayntfy.cpp:62
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL &bHandled)
Definition: trayntfy.cpp:323
#define NOTIFY_CODE_HANDLER(cd, func)
Definition: atlwin.h:1974
#define WM_SETFONT
Definition: winuser.h:1640
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:250
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1892
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:640
#define MESSAGE_HANDLER(msg, func)
Definition: atlwin.h:1920
SIZE szTrayNotify
Definition: trayntfy.cpp:47
#define OUT
Definition: typedefs.h:40
#define WM_CREATE
Definition: winuser.h:1598
HRESULT WINAPI ContextSensitiveHelp(BOOL fEnterMode)
Definition: trayntfy.cpp:337
const GUID IID_IOleWindow
#define HIWORD(l)
Definition: typedefs.h:247
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1110
BOOL WINAPI IsThemeActive(void)
Definition: system.c:606
int cxRightWidth
Definition: misc.c:281
CWindow GetParent() const
Definition: atlwin.h:694
#define END_COM_MAP()
Definition: atlcom.h:553
#define WM_ERASEBKGND
Definition: winuser.h:1615
LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: trayntfy.cpp:270
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:313
LONG cy
Definition: windef.h:335
#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:1684