ReactOS 0.4.15-dev-8614-gbc76250
traydeskbtn.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Explorer
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Show Desktop tray button implementation
5 * COPYRIGHT: Copyright 2006-2007 Thomas Weidenmueller <w3seek@reactos.org>
6 * Copyright 2018-2022 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7 * Copyright 2023 Ethan Rodensky <splitwirez@gmail.com>
8 */
9
10#include "precomp.h"
11#include <commoncontrols.h>
12#include <uxtheme.h>
13
14#define IDI_SHELL32_DESKTOP 35
15#define IDI_IMAGERES_DESKTOP 110
16
17#define SHOW_DESKTOP_TIMER_ID 999
18#define SHOW_DESKTOP_TIMER_INTERVAL 200
19
21 m_nClickedTime(0),
22 m_inset({2, 2}),
23 m_icon(NULL),
24 m_highContrastMode(FALSE),
25 m_drawWithDedicatedBackground(FALSE),
26 m_bHovering(FALSE),
27 m_hWndTaskbar(NULL),
28 m_bPressed(FALSE),
29 m_bHorizontal(FALSE)
30{
31}
32
34{
36 {
38 {
39 if (GetSystemMetrics(SM_TABLETPC))
40 {
41 //TODO: DPI scaling - return logical-to-physical conversion of 24, not fixed value
42 return 24;
43 }
44 else
45 return 15;
46 }
47 else
48 {
49 INT CurMargin = m_bHorizontal
52 return max(16 + CurMargin, 18) + 6;
53 }
54 }
55 else
56 {
59 }
60}
61
63{
66
67 if (!m_hWnd)
68 return E_FAIL;
69
70 // Get desktop icon
71 bool bIconRetrievalFailed = ExtractIconExW(L"imageres.dll", -IDI_IMAGERES_DESKTOP, NULL, &m_icon, 1) == UINT_MAX;
72 if (bIconRetrievalFailed || !m_icon)
73 ExtractIconExW(L"shell32.dll", -IDI_SHELL32_DESKTOP, NULL, &m_icon, 1);
74
75 // Get appropriate size at which to display desktop icon
78
79 // Prep visual style
81
82 // Get HWND of Taskbar
85 return E_FAIL;
86
87 return S_OK;
88}
89
91{
92 // The actual action can be delayed as an expected behaviour.
93 // But a too late action is an unexpected behaviour.
94 LONG nTime0 = m_nClickedTime;
95 LONG nTime1 = ::GetMessageTime();
96 if (nTime1 - nTime0 >= 600) // Ignore after 0.6 sec
97 return 0;
98
99 // Show/Hide Desktop
101
102 return 0;
103}
104
105// This function is called from OnLButtonDown and parent.
107{
108 // The actual action can be delayed as an expected behaviour.
110 PostMessage(TSDB_CLICK, 0, 0);
111}
112
114{
117 Invalidate(TRUE);
118
119 POINT pt;
121 if (PtInButton(&pt))
122 Click(); // Left-click
123 return 0;
124}
125
127{
129 SetCapture();
130 Invalidate(TRUE);
131 return 0;
132}
133
135{
136 LRESULT ret = OnThemeChanged(uMsg, wParam, lParam, bHandled);
138 return ret;
139}
140
142{
143 HIGHCONTRAST hcInfo;
144 hcInfo.cbSize = sizeof(hcInfo);
145 if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(hcInfo), &hcInfo, FALSE))
147
148 if (m_hTheme)
149 {
151 m_hTheme = NULL;
152 }
154 {
157 }
158
160
161 Invalidate(TRUE);
162 return 0;
163}
164
166{
168 return 0;
169}
170
172{
173 if (setTheme)
174 SetWindowTheme(m_hWnd, m_bHorizontal ? L"ShowDesktop" : L"VerticalShowDesktop", NULL);
175
177 {
180 }
181 else
182 {
184 }
185
186 MARGINS contentMargins;
187 if (GetThemeMargins(GetWindowTheme(GetParent().m_hWnd), NULL, TNP_BACKGROUND, 0, TMT_CONTENTMARGINS, NULL, &contentMargins) == S_OK)
188 {
189 m_inset.cx = max(0, contentMargins.cxRightWidth - 5);
190 m_inset.cy = max(0, contentMargins.cyBottomHeight - 5);
191 }
192 else
193 {
194 m_inset.cx = 2;
195 m_inset.cy = 2;
196 }
197
199 if (IsThemeActive())
200 {
201 m_hTheme = OpenThemeData(m_hWnd, L"Button");
202 if (m_hTheme != NULL)
204 }
205}
206
208{
209 RECT rc;
210 GetClientRect(&rc);
211
212 PAINTSTRUCT ps;
213 HDC hdc = BeginPaint(&ps);
214 OnDraw(hdc, &rc);
215 EndPaint(&ps);
216
217 return 0;
218}
219
221{
223 return 0;
224
225 RECT rc;
226 GetClientRect(&rc);
227
228 HDC hdc = (HDC)wParam;
229 OnDraw(hdc, &rc);
230
231 return 0;
232}
233
235{
236 if (!ppt || !IsWindow())
237 return FALSE;
238
239 RECT rc;
240 GetWindowRect(&rc);
242 ::InflateRect(&rc, max(cxEdge, 1), max(cyEdge, 1));
243
244 return m_bHorizontal
245 ? (ppt->x > rc.left)
246 : (ppt->y > rc.top);
247}
248
250{
251 if (m_bHovering)
252 return;
253
255 Invalidate(TRUE);
256
258
260}
261
263{
265 return 0;
266}
267
269{
271 return 0;
272
273 POINT pt;
275 if (!PtInButton(&pt)) // The end of hovering?
276 {
279 Invalidate(TRUE);
280
282 }
283
284 return 0;
285}
286
288{
289 if (m_hTheme)
290 {
292 m_hTheme = NULL;
293 }
295 {
298 }
299
300 return 0;
301}
302
304{
305 RECT rc = { prc->left, prc->top, prc->right, prc->bottom };
306 LPRECT lpRc = &rc;
307 HBRUSH hbrBackground = NULL;
308
309 if (m_hTheme)
310 {
311 HTHEME theme;
312 int part = 0;
313 int state = 0;
315 {
316 theme = m_hTheme;
317
318 if (m_bPressed)
320 else if (m_bHovering)
321 state = PBS_HOT;
322 else
324 }
325 else
326 {
327 part = TP_BUTTON;
328 theme = m_hFallbackTheme;
329
330 if (m_bPressed)
332 else if (m_bHovering)
333 state = TS_HOT;
334 else
336
337 if (m_bHorizontal)
338 rc.right -= m_inset.cx;
339 else
340 rc.bottom -= m_inset.cy;
341 }
342
345
346 ::DrawThemeBackground(theme, hdc, part, state, lpRc, lpRc);
347 }
348 else
349 {
352
353 if (m_bPressed || m_bHovering)
354 {
356 DrawEdge(hdc, lpRc, edge, BF_RECT);
357 }
358 }
359
361 {
362 /* Prepare to draw icon */
363
364 // Determine X-position of icon's top-left corner
365 int iconX = rc.left;
366 iconX += (rc.right - iconX) / 2;
367 iconX -= m_szIcon.cx / 2;
368
369 // Determine Y-position of icon's top-left corner
370 int iconY = rc.top;
371 iconY += (rc.bottom - iconY) / 2;
372 iconY -= m_szIcon.cy / 2;
373
374 // Ok now actually draw the icon itself
375 if (m_icon)
376 {
377 DrawIconEx(hdc, iconX, iconY,
378 m_icon, 0, 0,
380 }
381 }
382}
Arabic default style
Definition: afstyles.h:94
static int state
Definition: maze.c:121
@ Create
Definition: registry.c:563
LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
VOID EnsureWindowTheme(BOOL setTheme)
LRESULT OnClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
Definition: traydeskbtn.cpp:90
LRESULT OnWindowPosChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
BOOL PtInButton(LPPOINT pt) const
HRESULT DoCreate(HWND hwndParent)
Definition: traydeskbtn.cpp:62
LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnPrintClient(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
BOOL m_drawWithDedicatedBackground
Definition: traydeskbtn.h:28
VOID OnDraw(HDC hdc, LPRECT prc)
LRESULT OnThemeChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
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_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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 IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
Definition: system.c:987
HTHEME WINAPI GetWindowTheme(HWND hwnd)
Definition: system.c:851
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
HBRUSH hbrBackground
Definition: enumwnd.c:12
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
#define UINT_MAX
Definition: limits.h:41
#define S_OK
Definition: intsafe.h:52
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
static HTHEME(WINAPI *pOpenThemeDataEx)(HWND
unsigned int UINT
Definition: ndis.h:50
_Out_ LPRECT prc
Definition: ntgdi.h:1658
#define L(x)
Definition: ntvdm.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
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
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
#define max(a, b)
Definition: svc.c:63
#define SHOW_DESKTOP_TIMER_INTERVAL
Definition: traydeskbtn.cpp:18
#define IDI_SHELL32_DESKTOP
Definition: traydeskbtn.cpp:14
#define SHOW_DESKTOP_TIMER_ID
Definition: traydeskbtn.cpp:17
#define IDI_IMAGERES_DESKTOP
Definition: traydeskbtn.cpp:15
#define TSDB_CLICK
Definition: traydeskbtn.h:14
int32_t INT
Definition: typedefs.h:58
#define TRAYCMD_TOGGLE_DESKTOP
Definition: undocshell.h:867
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
@ TP_BUTTON
Definition: vsstyle.h:1394
@ PBS_PRESSED
Definition: vsstyle.h:88
@ PBS_NORMAL
Definition: vsstyle.h:86
@ PBS_HOT
Definition: vsstyle.h:87
@ BP_PUSHBUTTON
Definition: vsstyle.h:74
@ TS_PRESSED
Definition: vsstyle.h:1407
@ TS_NORMAL
Definition: vsstyle.h:1405
@ TS_HOT
Definition: vsstyle.h:1406
#define TMT_CONTENTMARGINS
Definition: vssym32.h:324
@ TNP_BACKGROUND
Definition: vssym32.h:543
int ret
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define DI_NORMAL
Definition: wingdi.h:72
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HWND WINAPI SetCapture(_In_ HWND hWnd)
BOOL WINAPI IsWindow(_In_opt_ HWND)
#define HCF_HIGHCONTRASTON
Definition: winuser.h:2137
#define BDR_SUNKENOUTER
Definition: winuser.h:443
#define SM_CYEDGE
Definition: winuser.h:1012
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890
#define SM_CXEDGE
Definition: winuser.h:1011
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define WM_COMMAND
Definition: winuser.h:1743
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2714
#define SM_CYSMICON
Definition: winuser.h:1016
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define SM_CYBORDER
Definition: winuser.h:968
#define SM_CXSMICON
Definition: winuser.h:1015
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define SM_CXBORDER
Definition: winuser.h:967
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2072
#define BDR_RAISEDINNER
Definition: winuser.h:444
#define SendMessage
Definition: winuser.h:5855
LONG WINAPI GetMessageTime(void)
Definition: message.c:1361
#define PostMessage
Definition: winuser.h:5844
HWND WINAPI GetParent(_In_ HWND)
#define PRF_CHECKVISIBLE
Definition: winuser.h:2526
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SystemParametersInfo
Definition: winuser.h:5870
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define BF_RECT
Definition: winuser.h:462
BOOL WINAPI IsWindowVisible(_In_ HWND)
int WINAPI GetSystemMetrics(_In_ int)
#define WM_NCPAINT
Definition: winuser.h:1690
#define COLOR_3DFACE
Definition: winuser.h:932