https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7f35908ad27b76a7e1d965...
commit 7f35908ad27b76a7e1d9653fb7fe55abaf7f5c83 Author: Giannis Adamopoulos gadamopoulos@reactos.org AuthorDate: Sat Jan 27 01:27:24 2018 +0200 Commit: Giannis Adamopoulos gadamopoulos@reactos.org CommitDate: Sat Jan 27 19:41:09 2018 +0200
[EXPLORER] CTrayNotifyWnd: Simplify how it interacts with its parent and children. Clean up. --- base/shell/explorer/precomp.h | 26 +----- base/shell/explorer/syspager.cpp | 143 ++++++++++++++++---------------- base/shell/explorer/syspager.h | 18 ++-- base/shell/explorer/trayclock.cpp | 68 +++++++++------ base/shell/explorer/trayclock.h | 10 +-- base/shell/explorer/trayntfy.cpp | 169 +++++++------------------------------- base/shell/explorer/traywnd.cpp | 25 ++---- 7 files changed, 167 insertions(+), 292 deletions(-)
diff --git a/base/shell/explorer/precomp.h b/base/shell/explorer/precomp.h index 1aacb42ce3..2473096233 100644 --- a/base/shell/explorer/precomp.h +++ b/base/shell/explorer/precomp.h @@ -337,8 +337,6 @@ CreateStartMenuSite(IN OUT ITrayWindow *Tray, const IID & riid, PVOID * ppv);
/* TrayNotifyWnd */ #define TNWM_GETMINIMUMSIZE (WM_USER + 0x100) -#define TNWM_UPDATETIME (WM_USER + 0x101) -#define TNWM_SHOWCLOCK (WM_USER + 0x102) #define TNWM_SHOWTRAY (WM_USER + 0x103) #define TNWM_CHANGETRAYPOS (WM_USER + 0x104)
@@ -346,20 +344,7 @@ CreateStartMenuSite(IN OUT ITrayWindow *Tray, const IID & riid, PVOID * ppv);
class CTrayNotifyWnd;
-BOOL -RegisterTrayNotifyWndClass(VOID); - -VOID -UnregisterTrayNotifyWndClass(VOID); - -HWND -CreateTrayNotifyWnd(IN OUT ITrayWindow *TrayWindow, CTrayNotifyWnd** ppTrayNotify); - -BOOL -TrayNotify_NotifyIconCmd(CTrayNotifyWnd* pTrayNotify, IN WPARAM wParam, IN LPARAM lParam); - -BOOL -TrayNotify_GetClockRect(CTrayNotifyWnd* pTrayNotify, OUT PRECT rcClock); +HWND CreateTrayNotifyWnd(IN HWND hwndParent, CTrayNotifyWnd** ppinstance);
/* * taskswnd.c @@ -368,15 +353,8 @@ TrayNotify_GetClockRect(CTrayNotifyWnd* pTrayNotify, OUT PRECT rcClock); #define TSWM_ENABLEGROUPING (WM_USER + 1) #define TSWM_UPDATETASKBARPOS (WM_USER + 2)
-BOOL -RegisterTaskSwitchWndClass(VOID); - -VOID -UnregisterTaskSwitchWndClass(VOID); - HWND -CreateTaskSwitchWnd(IN HWND hWndParent, -IN OUT ITrayWindow *Tray); +CreateTaskSwitchWnd(IN HWND hWndParent, IN OUT ITrayWindow *Tray);
HRESULT Tray_OnStartMenuDismissed(ITrayWindow* Tray); diff --git a/base/shell/explorer/syspager.cpp b/base/shell/explorer/syspager.cpp index 7a55360853..c404d3a57f 100644 --- a/base/shell/explorer/syspager.cpp +++ b/base/shell/explorer/syspager.cpp @@ -93,7 +93,7 @@ void CIconWatcher::Uninitialize() LeaveCriticalSection(&m_ListLock); }
-bool CIconWatcher::AddIconToWatcher(_In_ NOTIFYICONDATA *iconData) +bool CIconWatcher::AddIconToWatcher(_In_ CONST NOTIFYICONDATA *iconData) { DWORD ProcessId; (void)GetWindowThreadProcessId(iconData->hWnd, &ProcessId); @@ -132,7 +132,7 @@ bool CIconWatcher::AddIconToWatcher(_In_ NOTIFYICONDATA *iconData) return Added; }
-bool CIconWatcher::RemoveIconFromWatcher(_In_ NOTIFYICONDATA *iconData) +bool CIconWatcher::RemoveIconFromWatcher(_In_ CONST NOTIFYICONDATA *iconData) { EnterCriticalSection(&m_ListLock);
@@ -146,7 +146,7 @@ bool CIconWatcher::RemoveIconFromWatcher(_In_ NOTIFYICONDATA *iconData) return true; }
-IconWatcherData* CIconWatcher::GetListEntry(_In_opt_ NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove) +IconWatcherData* CIconWatcher::GetListEntry(_In_opt_ CONST NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove) { IconWatcherData *Entry = NULL; POSITION NextPosition = m_WatcherList.GetHeadPosition(); @@ -236,9 +236,7 @@ UINT WINAPI CIconWatcher::WatcherThread(_In_opt_ LPVOID lpParam) data.lpData = pnotify_data;
BOOL Success = FALSE; - HWND parentHWND = ::GetParent(GetParent(This->m_hwndSysTray)); - if (parentHWND) - Success = ::SendMessage(parentHWND, WM_COPYDATA, (WPARAM)&Icon->IconData, (LPARAM)&data); + ::SendMessage(This->m_hwndSysTray, WM_COPYDATA, (WPARAM)&Icon->IconData, (LPARAM)&data);
delete pnotify_data;
@@ -477,7 +475,7 @@ int CNotifyToolbar::FindExistingSharedIcon(HICON handle) return -1; }
-BOOL CNotifyToolbar::AddButton(IN CONST NOTIFYICONDATA *iconData) +BOOL CNotifyToolbar::AddButton(_In_ CONST NOTIFYICONDATA *iconData) { TBBUTTON tbBtn; InternalIconData * notifyItem; @@ -575,7 +573,7 @@ BOOL CNotifyToolbar::AddButton(IN CONST NOTIFYICONDATA *iconData) return TRUE; }
-BOOL CNotifyToolbar::SwitchVersion(IN CONST NOTIFYICONDATA *iconData) +BOOL CNotifyToolbar::SwitchVersion(_In_ CONST NOTIFYICONDATA *iconData) { InternalIconData * notifyItem; int index = FindItem(iconData->hWnd, iconData->uID, ¬ifyItem); @@ -598,7 +596,7 @@ BOOL CNotifyToolbar::SwitchVersion(IN CONST NOTIFYICONDATA *iconData) return TRUE; }
-BOOL CNotifyToolbar::UpdateButton(IN CONST NOTIFYICONDATA *iconData) +BOOL CNotifyToolbar::UpdateButton(_In_ CONST NOTIFYICONDATA *iconData) { InternalIconData * notifyItem; TBBUTTONINFO tbbi = { 0 }; @@ -703,7 +701,7 @@ BOOL CNotifyToolbar::UpdateButton(IN CONST NOTIFYICONDATA *iconData) return TRUE; }
-BOOL CNotifyToolbar::RemoveButton(IN CONST NOTIFYICONDATA *iconData) +BOOL CNotifyToolbar::RemoveButton(_In_ CONST NOTIFYICONDATA *iconData) { InternalIconData * notifyItem;
@@ -819,8 +817,9 @@ VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wPar
RemoveButton(notifyItem);
- HWND parentHWND = ::GetParent(::GetParent(GetParent())); - ::SendMessage(parentHWND, WM_SIZE, 0, 0); + /* Ask the parent to resize */ + NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN}; + GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
return; } @@ -975,16 +974,6 @@ const WCHAR szSysPagerWndClass[] = L"SysPager"; CSysPagerWnd::CSysPagerWnd() {} CSysPagerWnd::~CSysPagerWnd() {}
-LRESULT CSysPagerWnd::DrawBackground(HDC hdc) -{ - RECT rect; - - GetClientRect(&rect); - DrawThemeParentBackground(m_hWnd, hdc, &rect); - - return TRUE; -} - LRESULT CSysPagerWnd::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hdc = (HDC) wParam; @@ -995,7 +984,11 @@ LRESULT CSysPagerWnd::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, return 0; }
- return DrawBackground(hdc); + RECT rect; + GetClientRect(&rect); + DrawThemeParentBackground(m_hWnd, hdc, &rect); + + return TRUE; }
LRESULT CSysPagerWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) @@ -1038,60 +1031,50 @@ LRESULT CSysPagerWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b return TRUE; }
-BOOL CSysPagerWnd::NotifyIconCmd(WPARAM wParam, LPARAM lParam) +BOOL CSysPagerWnd::NotifyIcon(DWORD notify_code, _In_ CONST NOTIFYICONDATA *iconData) { - PCOPYDATASTRUCT cpData = (PCOPYDATASTRUCT) lParam; - if (cpData->dwData == 1) - { - SYS_PAGER_COPY_DATA * data; - NOTIFYICONDATA *iconData; - BOOL ret = FALSE; - - int VisibleButtonCount = Toolbar.GetVisibleButtonCount(); + BOOL ret = FALSE;
- data = (PSYS_PAGER_COPY_DATA) cpData->lpData; - iconData = &data->nicon_data; + int VisibleButtonCount = Toolbar.GetVisibleButtonCount();
- TRACE("NotifyIconCmd received. Code=%d\n", data->notify_code); - switch (data->notify_code) + TRACE("NotifyIcon received. Code=%d\n", notify_code); + switch (notify_code) + { + case NIM_ADD: + ret = Toolbar.AddButton(iconData); + if (ret == TRUE) { - case NIM_ADD: - ret = Toolbar.AddButton(iconData); - if (ret == TRUE) - { - (void)AddIconToWatcher(iconData); - } - break; - case NIM_MODIFY: - ret = Toolbar.UpdateButton(iconData); - break; - case NIM_DELETE: - ret = Toolbar.RemoveButton(iconData); - if (ret == TRUE) - { - (void)RemoveIconFromWatcher(iconData); - } - break; - case NIM_SETFOCUS: - Toolbar.SetFocus(); - ret = TRUE; - case NIM_SETVERSION: - ret = Toolbar.SwitchVersion(iconData); - default: - TRACE("NotifyIconCmd received with unknown code %d.\n", data->notify_code); - return FALSE; + (void)AddIconToWatcher(iconData); } - - if (VisibleButtonCount != Toolbar.GetVisibleButtonCount()) + break; + case NIM_MODIFY: + ret = Toolbar.UpdateButton(iconData); + break; + case NIM_DELETE: + ret = Toolbar.RemoveButton(iconData); + if (ret == TRUE) { - HWND parentHWND = ::GetParent(GetParent()); - ::SendMessage(parentHWND, WM_SIZE, 0, 0); + (void)RemoveIconFromWatcher(iconData); } + break; + case NIM_SETFOCUS: + Toolbar.SetFocus(); + ret = TRUE; + case NIM_SETVERSION: + ret = Toolbar.SwitchVersion(iconData); + default: + TRACE("NotifyIcon received with unknown code %d.\n", notify_code); + return FALSE; + }
- return ret; + if (VisibleButtonCount != Toolbar.GetVisibleButtonCount()) + { + /* Ask the parent to resize */ + NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN}; + GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh); }
- return TRUE; + return ret; }
void CSysPagerWnd::GetSize(IN BOOL IsHorizontal, IN PSIZE size) @@ -1200,20 +1183,34 @@ LRESULT CSysPagerWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa return 0; }
-void CSysPagerWnd::ResizeImagelist() +LRESULT CSysPagerWnd::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - Toolbar.ResizeImagelist(); + PCOPYDATASTRUCT cpData = (PCOPYDATASTRUCT)lParam; + if (cpData->dwData == 1) + { + PSYS_PAGER_COPY_DATA pData = (PSYS_PAGER_COPY_DATA)cpData->lpData; + return NotifyIcon(pData->notify_code, &pData->nicon_data); + } + + return FALSE; +} + +LRESULT CSysPagerWnd::OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (wParam == SPI_SETNONCLIENTMETRICS) + { + Toolbar.ResizeImagelist(); + } + return 0; }
-HWND CSysPagerWnd::_Init(IN HWND hWndParent, IN BOOL bVisible) +HWND CSysPagerWnd::_Init(IN HWND hWndParent) { DWORD dwStyle;
/* Create the window. The tray window is going to move it to the correct position and resize it as needed. */ - dwStyle = WS_CHILD | WS_CLIPSIBLINGS; - if (bVisible) - dwStyle |= WS_VISIBLE; + dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE;
Create(hWndParent, 0, NULL, dwStyle);
diff --git a/base/shell/explorer/syspager.h b/base/shell/explorer/syspager.h index 381c143a32..1df0798ebd 100644 --- a/base/shell/explorer/syspager.h +++ b/base/shell/explorer/syspager.h @@ -12,7 +12,7 @@ struct IconWatcherData DWORD ProcessId; NOTIFYICONDATA IconData;
- IconWatcherData(NOTIFYICONDATA *iconData) : + IconWatcherData(CONST NOTIFYICONDATA *iconData) : hProcess(NULL), ProcessId(0) { IconData.cbSize = sizeof(NOTIFYICONDATA); @@ -47,10 +47,10 @@ public: bool Initialize(_In_ HWND hWndParent); void Uninitialize();
- bool AddIconToWatcher(_In_ NOTIFYICONDATA *iconData); - bool RemoveIconFromWatcher(_In_ NOTIFYICONDATA *iconData); + bool AddIconToWatcher(_In_ CONST NOTIFYICONDATA *iconData); + bool RemoveIconFromWatcher(_In_ CONST NOTIFYICONDATA *iconData);
- IconWatcherData* GetListEntry(_In_opt_ NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove); + IconWatcherData* GetListEntry(_In_opt_ CONST NOTIFYICONDATA *iconData, _In_opt_ HANDLE hProcess, _In_ bool Remove);
private:
@@ -179,11 +179,13 @@ public: LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnBalloonPop(UINT uCode, LPNMHDR hdr, BOOL& bHandled); LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public: - BOOL NotifyIconCmd(WPARAM wParam, LPARAM lParam); + + BOOL NotifyIcon(DWORD notify_code, _In_ CONST NOTIFYICONDATA *iconData); void GetSize(IN BOOL IsHorizontal, IN PSIZE size); - void ResizeImagelist();
DECLARE_WND_CLASS_EX(szSysPagerWndClass, CS_DBLCLKS, COLOR_3DFACE)
@@ -194,10 +196,12 @@ public: MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu) MESSAGE_HANDLER(WM_TIMER, OnTimer) + MESSAGE_HANDLER(WM_COPYDATA, OnCopyData) + MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged) NOTIFY_CODE_HANDLER(TTN_POP, OnBalloonPop) NOTIFY_CODE_HANDLER(TBN_GETINFOTIPW, OnGetInfoTip) NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw) END_MSG_MAP()
- HWND _Init(IN HWND hWndParent, IN BOOL bVisible); + HWND _Init(IN HWND hWndParent); }; diff --git a/base/shell/explorer/trayclock.cpp b/base/shell/explorer/trayclock.cpp index 125fc73b7d..1042214731 100644 --- a/base/shell/explorer/trayclock.cpp +++ b/base/shell/explorer/trayclock.cpp @@ -34,7 +34,6 @@ const WCHAR szTrayClockWndClass[] = L"TrayClockWClass"; #define TRAY_CLOCK_WND_SPACING_Y 0
CTrayClockWnd::CTrayClockWnd() : - hWndNotify(NULL), hFont(NULL), dwFlags(0), LineSpacing(0), @@ -265,20 +264,12 @@ VOID CTrayClockWnd::UpdateWnd() { InvalidateRect(NULL, TRUE);
- if (hWndNotify != NULL && - (szPrevCurrent.cx != CurrentSize.cx || - szPrevCurrent.cy != CurrentSize.cy)) + if (szPrevCurrent.cx != CurrentSize.cx || + szPrevCurrent.cy != CurrentSize.cy) { - NMHDR nmh; - - nmh.hwndFrom = m_hWnd; - nmh.idFrom = GetWindowLongPtr(GWLP_ID); - nmh.code = NTNWM_REALIGN; - - ::SendMessage(hWndNotify, - WM_NOTIFY, - (WPARAM) nmh.idFrom, - (LPARAM) &nmh); + /* Ask the parent to resize */ + NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN}; + GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh); } } } @@ -518,11 +509,6 @@ LRESULT CTrayClockWnd::OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, return (LRESULT) GetMinimumSize((BOOL) wParam, (PSIZE) lParam) != 0; }
-LRESULT CTrayClockWnd::OnUpdateTime(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) -{ - return (LRESULT) ResetTime(); -} - LRESULT CTrayClockWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return HTTRANSPARENT; @@ -554,16 +540,52 @@ LRESULT CTrayClockWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa return TRUE; }
-HWND CTrayClockWnd::_Init(IN HWND hWndParent, IN BOOL bVisible) +LRESULT CTrayClockWnd::OnTaskbarSettingsChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - IsHorizontal = TRUE; + TaskbarSettings* newSettings = (TaskbarSettings*)lParam; + if (newSettings->bShowSeconds != g_TaskbarSettings.bShowSeconds) + { + g_TaskbarSettings.bShowSeconds = newSettings->bShowSeconds; + /* TODO: Toggle showing seconds */ + } + + if (newSettings->sr.HideClock != g_TaskbarSettings.sr.HideClock) + { + g_TaskbarSettings.sr.HideClock = newSettings->sr.HideClock; + /* TODO: Toggle hiding the clock */ + } + + return 0; +}
- hWndNotify = hWndParent; +LRESULT CTrayClockWnd::OnNcLButtonDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (IsWindowVisible()) + { + RECT rcClock; + if (GetWindowRect(&rcClock)) + { + POINT ptClick; + ptClick.x = MAKEPOINTS(lParam).x; + ptClick.y = MAKEPOINTS(lParam).y; + if (PtInRect(&rcClock, ptClick)) + { + //FIXME: use SHRunControlPanel + ShellExecuteW(m_hWnd, NULL, L"timedate.cpl", NULL, NULL, SW_NORMAL); + } + } + } + return TRUE; +} + +HWND CTrayClockWnd::_Init(IN HWND hWndParent) +{ + IsHorizontal = TRUE;
/* Create the window. The tray window is going to move it to the correct position and resize it as needed. */ DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS; - if (bVisible) + if (!g_TaskbarSettings.sr.HideClock) dwStyle |= WS_VISIBLE;
Create(hWndParent, 0, NULL, dwStyle); diff --git a/base/shell/explorer/trayclock.h b/base/shell/explorer/trayclock.h index 23911dfae9..4c152098cd 100644 --- a/base/shell/explorer/trayclock.h +++ b/base/shell/explorer/trayclock.h @@ -68,8 +68,8 @@ private: LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); -public: - LRESULT OnUpdateTime(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnTaskbarSettingsChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnNcLButtonDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public: DECLARE_WND_CLASS_EX(szTrayClockWndClass, CS_DBLCLKS, COLOR_3DFACE) @@ -86,9 +86,9 @@ public: MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest) MESSAGE_HANDLER(WM_SETFONT, OnSetFont) MESSAGE_HANDLER(TCWM_GETMINIMUMSIZE, OnGetMinimumSize) - MESSAGE_HANDLER(TCWM_UPDATETIME, OnUpdateTime) - + MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnTaskbarSettingsChanged) + MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, OnNcLButtonDblClick) END_MSG_MAP()
- HWND _Init(IN HWND hWndParent, IN BOOL bVisible); + HWND _Init(IN HWND hWndParent); }; \ No newline at end of file diff --git a/base/shell/explorer/trayntfy.cpp b/base/shell/explorer/trayntfy.cpp index 9a0294e500..4004184a94 100644 --- a/base/shell/explorer/trayntfy.cpp +++ b/base/shell/explorer/trayntfy.cpp @@ -34,13 +34,9 @@ class CTrayNotifyWnd : public CComObjectRootEx<CComMultiThreadModelNoCS>, public CWindowImpl < CTrayNotifyWnd, CWindow, CControlWinTraits > { - HWND hWndNotify; - CSysPagerWnd * m_pager; CTrayClockWnd * m_clock;
- CComPtr<ITrayWindow> TrayWindow; - HTHEME TrayTheme; SIZE szTrayClockMin; SIZE szTrayNotify; @@ -49,7 +45,6 @@ class CTrayNotifyWnd :
public: CTrayNotifyWnd() : - hWndNotify(NULL), m_pager(NULL), m_clock(NULL), TrayTheme(NULL), @@ -104,10 +99,10 @@ public: LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { m_clock = new CTrayClockWnd(); - m_clock->_Init(m_hWnd, !g_TaskbarSettings.sr.HideClock); + m_clock->_Init(m_hWnd);
m_pager = new CSysPagerWnd(); - m_pager->_Init(m_hWnd, !g_TaskbarSettings.sr.HideClock); + m_pager->_Init(m_hWnd);
return TRUE; } @@ -231,26 +226,6 @@ public: } }
- LRESULT DrawBackground(HDC hdc) - { - HRESULT res; - RECT rect; - - GetClientRect(&rect); - - if (TrayTheme) - { - if (IsThemeBackgroundPartiallyTransparent(TrayTheme, TNP_BACKGROUND, 0)) - { - DrawThemeParentBackground(m_hWnd, hdc, &rect); - } - - res = DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0); - } - - return res; - } - LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hdc = (HDC) wParam; @@ -261,27 +236,16 @@ public: return 0; }
- return DrawBackground(hdc); - } + RECT rect; + GetClientRect(&rect); + if (IsThemeBackgroundPartiallyTransparent(TrayTheme, TNP_BACKGROUND, 0)) + DrawThemeParentBackground(m_hWnd, hdc, &rect);
- BOOL NotifyIconCmd(WPARAM wParam, LPARAM lParam) - { - if (m_pager) - { - return m_pager->NotifyIconCmd(wParam, lParam); - } + DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0);
return TRUE; }
- BOOL GetClockRect(OUT PRECT rcClock) - { - if (!m_clock->IsWindowVisible()) - return FALSE; - - return m_clock->GetWindowRect(rcClock); - } - LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { BOOL Horizontal = (BOOL) wParam; @@ -298,16 +262,6 @@ public: return (LRESULT) GetMinimumSize((PSIZE) lParam); }
- LRESULT OnUpdateTime(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) - { - if (m_clock != NULL) - { - /* Forward the message to the tray clock window procedure */ - return m_clock->OnUpdateTime(uMsg, wParam, lParam, bHandled); - } - return FALSE; - } - LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { SIZE szClient; @@ -325,74 +279,30 @@ public: return HTTRANSPARENT; }
- LRESULT OnShowClock(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) - { - BOOL PrevHidden = g_TaskbarSettings.sr.HideClock; - g_TaskbarSettings.sr.HideClock = (wParam == 0); - - if (m_clock != NULL && PrevHidden != g_TaskbarSettings.sr.HideClock) - { - m_clock->ShowWindow(g_TaskbarSettings.sr.HideClock ? SW_HIDE : SW_SHOW); - } - - return (LRESULT) (!PrevHidden); - } - - LRESULT OnTaskbarSettingsChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) + LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - TaskbarSettings* newSettings = (TaskbarSettings*)lParam; - if (newSettings->bShowSeconds != g_TaskbarSettings.bShowSeconds) - { - g_TaskbarSettings.bShowSeconds = newSettings->bShowSeconds; - /* TODO: Toggle showing seconds */ - } - - if (newSettings->sr.HideClock != g_TaskbarSettings.sr.HideClock) - { - g_TaskbarSettings.sr.HideClock = newSettings->sr.HideClock; - /* TODO: Toggle hiding the clock */ - } - + bHandled = TRUE; return 0; }
- LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) - { - const NMHDR *nmh = (const NMHDR *) lParam; - - if (nmh->hwndFrom == m_clock->m_hWnd) - { - /* Pass down notifications */ - return m_clock->SendMessage(WM_NOTIFY, wParam, lParam); - } - - return FALSE; - } - - LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) + LRESULT OnClockMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (m_clock != NULL) - { - m_clock->SendMessageW(WM_SETFONT, wParam, lParam); - } - - bHandled = FALSE; - return FALSE; + return m_clock->SendMessageW(uMsg, wParam, lParam); + return TRUE; }
- LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) + LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - bHandled = TRUE; - return 0; + if (m_pager) + return m_pager->SendMessage(uMsg, wParam, lParam); + return TRUE; }
- LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) + LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled) { - if (wParam == SPI_SETNONCLIENTMETRICS) - { - m_pager->ResizeImagelist(); - } - return 0; + hdr->hwndFrom = m_hWnd; + return GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM)hdr); }
DECLARE_WND_CLASS_EX(szTrayNotifyWndClass, CS_DBLCLKS, COLOR_3DFACE) @@ -401,51 +311,30 @@ public: MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged) MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) - MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged) MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest) - MESSAGE_HANDLER(WM_NOTIFY, OnNotify) - MESSAGE_HANDLER(WM_SETFONT, OnSetFont) MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu) // FIXME: This handler is not necessary in Windows + MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, OnClockMessage) + MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnClockMessage) + MESSAGE_HANDLER(WM_SETFONT, OnClockMessage) + MESSAGE_HANDLER(WM_SETTINGCHANGE, OnPagerMessage) + MESSAGE_HANDLER(WM_COPYDATA, OnPagerMessage) + NOTIFY_CODE_HANDLER(NTNWM_REALIGN, OnRealign) MESSAGE_HANDLER(TNWM_GETMINIMUMSIZE, OnGetMinimumSize) - MESSAGE_HANDLER(TNWM_UPDATETIME, OnUpdateTime) - MESSAGE_HANDLER(TNWM_SHOWCLOCK, OnShowClock) - MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnTaskbarSettingsChanged) END_MSG_MAP()
- HWND _Init(IN OUT ITrayWindow *TrayWindow) + HWND _Init(IN HWND hwndParent) { - HWND hWndTrayWindow; - - hWndTrayWindow = TrayWindow->GetHWND(); - if (hWndTrayWindow == NULL) - return NULL; - - this->TrayWindow = TrayWindow; - this->hWndNotify = hWndTrayWindow; - DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; - return Create(hWndTrayWindow, 0, NULL, dwStyle, WS_EX_STATICEDGE); + return Create(hwndParent, 0, NULL, dwStyle, WS_EX_STATICEDGE); } };
-HWND CreateTrayNotifyWnd(IN OUT ITrayWindow *Tray, CTrayNotifyWnd** ppinstance) +HWND CreateTrayNotifyWnd(IN HWND hwndParent, CTrayNotifyWnd** ppinstance) { CTrayNotifyWnd * pTrayNotify = new CTrayNotifyWnd(); // TODO: Destroy after the window is destroyed *ppinstance = pTrayNotify;
- return pTrayNotify->_Init(Tray); -} - -BOOL -TrayNotify_NotifyIconCmd(CTrayNotifyWnd* pTrayNotify, WPARAM wParam, LPARAM lParam) -{ - return pTrayNotify->NotifyIconCmd(wParam, lParam); -} - -BOOL -TrayNotify_GetClockRect(CTrayNotifyWnd* pTrayNotify, OUT PRECT rcClock) -{ - return pTrayNotify->GetClockRect(rcClock); + return pTrayNotify->_Init(hwndParent); } diff --git a/base/shell/explorer/traywnd.cpp b/base/shell/explorer/traywnd.cpp index d1f30e3b42..ac449131b5 100644 --- a/base/shell/explorer/traywnd.cpp +++ b/base/shell/explorer/traywnd.cpp @@ -2061,7 +2061,7 @@ ChangePos: SetWindowTheme(m_Rebar, L"TaskBar", NULL);
/* Create the tray notification window */ - m_TrayNotify = CreateTrayNotifyWnd(this, &m_TrayNotifyInstance); + m_TrayNotify = CreateTrayNotifyWnd(m_hWnd, &m_TrayNotifyInstance);
UpdateFonts();
@@ -2150,10 +2150,7 @@ ChangePos: LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (m_TrayNotify) - { - TRACE("WM_COPYDATA notify message received. Handling...\n"); - return TrayNotify_NotifyIconCmd(m_TrayNotifyInstance, wParam, lParam); - } + ::SendMessageW(m_TrayNotify, uMsg, wParam, lParam); return TRUE; }
@@ -2556,23 +2553,11 @@ HandleTrayContextMenu:
LRESULT OnNcLButtonDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + /* Let the clock handle the double click */ + ::SendMessageW(m_TrayNotify, uMsg, wParam, lParam); + /* We "handle" this message so users can't cause a weird maximize/restore window animation when double-clicking the tray window! */ - - /* We should forward mouse messages to child windows here. - Right now, this is only clock double-click */ - RECT rcClock; - if (TrayNotify_GetClockRect(m_TrayNotifyInstance, &rcClock)) - { - POINT ptClick; - ptClick.x = MAKEPOINTS(lParam).x; - ptClick.y = MAKEPOINTS(lParam).y; - if (PtInRect(&rcClock, ptClick)) - { - //FIXME: use SHRunControlPanel - ShellExecuteW(m_hWnd, NULL, L"timedate.cpl", NULL, NULL, SW_NORMAL); - } - } return TRUE; }