[EXPLORER] CTrayNotifyWnd: Simplify how it interacts with its parent and children. Clean up.

This commit is contained in:
Giannis Adamopoulos 2018-01-27 01:27:24 +02:00
parent 78664ebe15
commit 7f35908ad2
7 changed files with 174 additions and 299 deletions

View file

@ -337,8 +337,6 @@ CreateStartMenuSite(IN OUT ITrayWindow *Tray, const IID & riid, PVOID * ppv);
/* TrayNotifyWnd */ /* TrayNotifyWnd */
#define TNWM_GETMINIMUMSIZE (WM_USER + 0x100) #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_SHOWTRAY (WM_USER + 0x103)
#define TNWM_CHANGETRAYPOS (WM_USER + 0x104) #define TNWM_CHANGETRAYPOS (WM_USER + 0x104)
@ -346,20 +344,7 @@ CreateStartMenuSite(IN OUT ITrayWindow *Tray, const IID & riid, PVOID * ppv);
class CTrayNotifyWnd; class CTrayNotifyWnd;
BOOL HWND CreateTrayNotifyWnd(IN HWND hwndParent, CTrayNotifyWnd** ppinstance);
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);
/* /*
* taskswnd.c * taskswnd.c
@ -368,15 +353,8 @@ TrayNotify_GetClockRect(CTrayNotifyWnd* pTrayNotify, OUT PRECT rcClock);
#define TSWM_ENABLEGROUPING (WM_USER + 1) #define TSWM_ENABLEGROUPING (WM_USER + 1)
#define TSWM_UPDATETASKBARPOS (WM_USER + 2) #define TSWM_UPDATETASKBARPOS (WM_USER + 2)
BOOL
RegisterTaskSwitchWndClass(VOID);
VOID
UnregisterTaskSwitchWndClass(VOID);
HWND HWND
CreateTaskSwitchWnd(IN HWND hWndParent, CreateTaskSwitchWnd(IN HWND hWndParent, IN OUT ITrayWindow *Tray);
IN OUT ITrayWindow *Tray);
HRESULT HRESULT
Tray_OnStartMenuDismissed(ITrayWindow* Tray); Tray_OnStartMenuDismissed(ITrayWindow* Tray);

View file

@ -93,7 +93,7 @@ void CIconWatcher::Uninitialize()
LeaveCriticalSection(&m_ListLock); LeaveCriticalSection(&m_ListLock);
} }
bool CIconWatcher::AddIconToWatcher(_In_ NOTIFYICONDATA *iconData) bool CIconWatcher::AddIconToWatcher(_In_ CONST NOTIFYICONDATA *iconData)
{ {
DWORD ProcessId; DWORD ProcessId;
(void)GetWindowThreadProcessId(iconData->hWnd, &ProcessId); (void)GetWindowThreadProcessId(iconData->hWnd, &ProcessId);
@ -132,7 +132,7 @@ bool CIconWatcher::AddIconToWatcher(_In_ NOTIFYICONDATA *iconData)
return Added; return Added;
} }
bool CIconWatcher::RemoveIconFromWatcher(_In_ NOTIFYICONDATA *iconData) bool CIconWatcher::RemoveIconFromWatcher(_In_ CONST NOTIFYICONDATA *iconData)
{ {
EnterCriticalSection(&m_ListLock); EnterCriticalSection(&m_ListLock);
@ -146,7 +146,7 @@ bool CIconWatcher::RemoveIconFromWatcher(_In_ NOTIFYICONDATA *iconData)
return true; 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; IconWatcherData *Entry = NULL;
POSITION NextPosition = m_WatcherList.GetHeadPosition(); POSITION NextPosition = m_WatcherList.GetHeadPosition();
@ -236,9 +236,7 @@ UINT WINAPI CIconWatcher::WatcherThread(_In_opt_ LPVOID lpParam)
data.lpData = pnotify_data; data.lpData = pnotify_data;
BOOL Success = FALSE; BOOL Success = FALSE;
HWND parentHWND = ::GetParent(GetParent(This->m_hwndSysTray)); ::SendMessage(This->m_hwndSysTray, WM_COPYDATA, (WPARAM)&Icon->IconData, (LPARAM)&data);
if (parentHWND)
Success = ::SendMessage(parentHWND, WM_COPYDATA, (WPARAM)&Icon->IconData, (LPARAM)&data);
delete pnotify_data; delete pnotify_data;
@ -477,7 +475,7 @@ int CNotifyToolbar::FindExistingSharedIcon(HICON handle)
return -1; return -1;
} }
BOOL CNotifyToolbar::AddButton(IN CONST NOTIFYICONDATA *iconData) BOOL CNotifyToolbar::AddButton(_In_ CONST NOTIFYICONDATA *iconData)
{ {
TBBUTTON tbBtn; TBBUTTON tbBtn;
InternalIconData * notifyItem; InternalIconData * notifyItem;
@ -575,7 +573,7 @@ BOOL CNotifyToolbar::AddButton(IN CONST NOTIFYICONDATA *iconData)
return TRUE; return TRUE;
} }
BOOL CNotifyToolbar::SwitchVersion(IN CONST NOTIFYICONDATA *iconData) BOOL CNotifyToolbar::SwitchVersion(_In_ CONST NOTIFYICONDATA *iconData)
{ {
InternalIconData * notifyItem; InternalIconData * notifyItem;
int index = FindItem(iconData->hWnd, iconData->uID, &notifyItem); int index = FindItem(iconData->hWnd, iconData->uID, &notifyItem);
@ -598,7 +596,7 @@ BOOL CNotifyToolbar::SwitchVersion(IN CONST NOTIFYICONDATA *iconData)
return TRUE; return TRUE;
} }
BOOL CNotifyToolbar::UpdateButton(IN CONST NOTIFYICONDATA *iconData) BOOL CNotifyToolbar::UpdateButton(_In_ CONST NOTIFYICONDATA *iconData)
{ {
InternalIconData * notifyItem; InternalIconData * notifyItem;
TBBUTTONINFO tbbi = { 0 }; TBBUTTONINFO tbbi = { 0 };
@ -703,7 +701,7 @@ BOOL CNotifyToolbar::UpdateButton(IN CONST NOTIFYICONDATA *iconData)
return TRUE; return TRUE;
} }
BOOL CNotifyToolbar::RemoveButton(IN CONST NOTIFYICONDATA *iconData) BOOL CNotifyToolbar::RemoveButton(_In_ CONST NOTIFYICONDATA *iconData)
{ {
InternalIconData * notifyItem; InternalIconData * notifyItem;
@ -819,8 +817,9 @@ VOID CNotifyToolbar::SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wPar
RemoveButton(notifyItem); RemoveButton(notifyItem);
HWND parentHWND = ::GetParent(::GetParent(GetParent())); /* Ask the parent to resize */
::SendMessage(parentHWND, WM_SIZE, 0, 0); NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN};
GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
return; return;
} }
@ -975,16 +974,6 @@ const WCHAR szSysPagerWndClass[] = L"SysPager";
CSysPagerWnd::CSysPagerWnd() {} CSysPagerWnd::CSysPagerWnd() {}
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) LRESULT CSysPagerWnd::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
HDC hdc = (HDC) wParam; HDC hdc = (HDC) wParam;
@ -995,7 +984,11 @@ LRESULT CSysPagerWnd::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam,
return 0; 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) LRESULT CSysPagerWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@ -1038,22 +1031,14 @@ LRESULT CSysPagerWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b
return TRUE; 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; BOOL ret = FALSE;
int VisibleButtonCount = Toolbar.GetVisibleButtonCount(); int VisibleButtonCount = Toolbar.GetVisibleButtonCount();
data = (PSYS_PAGER_COPY_DATA) cpData->lpData; TRACE("NotifyIcon received. Code=%d\n", notify_code);
iconData = &data->nicon_data; switch (notify_code)
TRACE("NotifyIconCmd received. Code=%d\n", data->notify_code);
switch (data->notify_code)
{ {
case NIM_ADD: case NIM_ADD:
ret = Toolbar.AddButton(iconData); ret = Toolbar.AddButton(iconData);
@ -1078,20 +1063,18 @@ BOOL CSysPagerWnd::NotifyIconCmd(WPARAM wParam, LPARAM lParam)
case NIM_SETVERSION: case NIM_SETVERSION:
ret = Toolbar.SwitchVersion(iconData); ret = Toolbar.SwitchVersion(iconData);
default: default:
TRACE("NotifyIconCmd received with unknown code %d.\n", data->notify_code); TRACE("NotifyIcon received with unknown code %d.\n", notify_code);
return FALSE; return FALSE;
} }
if (VisibleButtonCount != Toolbar.GetVisibleButtonCount()) if (VisibleButtonCount != Toolbar.GetVisibleButtonCount())
{ {
HWND parentHWND = ::GetParent(GetParent()); /* Ask the parent to resize */
::SendMessage(parentHWND, WM_SIZE, 0, 0); NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN};
GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
} }
return ret; return ret;
}
return TRUE;
} }
void CSysPagerWnd::GetSize(IN BOOL IsHorizontal, IN PSIZE size) 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; 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;
} }
HWND CSysPagerWnd::_Init(IN HWND hWndParent, IN BOOL bVisible) 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)
{ {
DWORD dwStyle; DWORD dwStyle;
/* Create the window. The tray window is going to move it to the correct /* Create the window. The tray window is going to move it to the correct
position and resize it as needed. */ position and resize it as needed. */
dwStyle = WS_CHILD | WS_CLIPSIBLINGS; dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE;
if (bVisible)
dwStyle |= WS_VISIBLE;
Create(hWndParent, 0, NULL, dwStyle); Create(hWndParent, 0, NULL, dwStyle);

View file

@ -12,7 +12,7 @@ struct IconWatcherData
DWORD ProcessId; DWORD ProcessId;
NOTIFYICONDATA IconData; NOTIFYICONDATA IconData;
IconWatcherData(NOTIFYICONDATA *iconData) : IconWatcherData(CONST NOTIFYICONDATA *iconData) :
hProcess(NULL), ProcessId(0) hProcess(NULL), ProcessId(0)
{ {
IconData.cbSize = sizeof(NOTIFYICONDATA); IconData.cbSize = sizeof(NOTIFYICONDATA);
@ -47,10 +47,10 @@ public:
bool Initialize(_In_ HWND hWndParent); bool Initialize(_In_ HWND hWndParent);
void Uninitialize(); void Uninitialize();
bool AddIconToWatcher(_In_ NOTIFYICONDATA *iconData); bool AddIconToWatcher(_In_ CONST NOTIFYICONDATA *iconData);
bool RemoveIconFromWatcher(_In_ 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: private:
@ -179,11 +179,13 @@ public:
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnBalloonPop(UINT uCode, LPNMHDR hdr, BOOL& bHandled); LRESULT OnBalloonPop(UINT uCode, LPNMHDR hdr, BOOL& bHandled);
LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, 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: 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 GetSize(IN BOOL IsHorizontal, IN PSIZE size);
void ResizeImagelist();
DECLARE_WND_CLASS_EX(szSysPagerWndClass, CS_DBLCLKS, COLOR_3DFACE) DECLARE_WND_CLASS_EX(szSysPagerWndClass, CS_DBLCLKS, COLOR_3DFACE)
@ -194,10 +196,12 @@ public:
MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu) MESSAGE_HANDLER(WM_CONTEXTMENU, OnCtxMenu)
MESSAGE_HANDLER(WM_TIMER, OnTimer) MESSAGE_HANDLER(WM_TIMER, OnTimer)
MESSAGE_HANDLER(WM_COPYDATA, OnCopyData)
MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged)
NOTIFY_CODE_HANDLER(TTN_POP, OnBalloonPop) NOTIFY_CODE_HANDLER(TTN_POP, OnBalloonPop)
NOTIFY_CODE_HANDLER(TBN_GETINFOTIPW, OnGetInfoTip) NOTIFY_CODE_HANDLER(TBN_GETINFOTIPW, OnGetInfoTip)
NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw) NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
END_MSG_MAP() END_MSG_MAP()
HWND _Init(IN HWND hWndParent, IN BOOL bVisible); HWND _Init(IN HWND hWndParent);
}; };

View file

@ -34,7 +34,6 @@ const WCHAR szTrayClockWndClass[] = L"TrayClockWClass";
#define TRAY_CLOCK_WND_SPACING_Y 0 #define TRAY_CLOCK_WND_SPACING_Y 0
CTrayClockWnd::CTrayClockWnd() : CTrayClockWnd::CTrayClockWnd() :
hWndNotify(NULL),
hFont(NULL), hFont(NULL),
dwFlags(0), dwFlags(0),
LineSpacing(0), LineSpacing(0),
@ -265,20 +264,12 @@ VOID CTrayClockWnd::UpdateWnd()
{ {
InvalidateRect(NULL, TRUE); InvalidateRect(NULL, TRUE);
if (hWndNotify != NULL && if (szPrevCurrent.cx != CurrentSize.cx ||
(szPrevCurrent.cx != CurrentSize.cx || szPrevCurrent.cy != CurrentSize.cy)
szPrevCurrent.cy != CurrentSize.cy))
{ {
NMHDR nmh; /* Ask the parent to resize */
NMHDR nmh = {GetParent(), 0, NTNWM_REALIGN};
nmh.hwndFrom = m_hWnd; GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM) &nmh);
nmh.idFrom = GetWindowLongPtr(GWLP_ID);
nmh.code = NTNWM_REALIGN;
::SendMessage(hWndNotify,
WM_NOTIFY,
(WPARAM) nmh.idFrom,
(LPARAM) &nmh);
} }
} }
} }
@ -518,11 +509,6 @@ LRESULT CTrayClockWnd::OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam,
return (LRESULT) GetMinimumSize((BOOL) wParam, (PSIZE) lParam) != 0; 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) LRESULT CTrayClockWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
return HTTRANSPARENT; return HTTRANSPARENT;
@ -554,16 +540,52 @@ LRESULT CTrayClockWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
return TRUE; return TRUE;
} }
HWND CTrayClockWnd::_Init(IN HWND hWndParent, IN BOOL bVisible) LRESULT CTrayClockWnd::OnTaskbarSettingsChanged(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 */
}
return 0;
}
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; IsHorizontal = TRUE;
hWndNotify = hWndParent;
/* Create the window. The tray window is going to move it to the correct /* Create the window. The tray window is going to move it to the correct
position and resize it as needed. */ position and resize it as needed. */
DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS; DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS;
if (bVisible) if (!g_TaskbarSettings.sr.HideClock)
dwStyle |= WS_VISIBLE; dwStyle |= WS_VISIBLE;
Create(hWndParent, 0, NULL, dwStyle); Create(hWndParent, 0, NULL, dwStyle);

View file

@ -68,8 +68,8 @@ private:
LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCreate(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); LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public: LRESULT OnTaskbarSettingsChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnUpdateTime(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnNcLButtonDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public: public:
DECLARE_WND_CLASS_EX(szTrayClockWndClass, CS_DBLCLKS, COLOR_3DFACE) DECLARE_WND_CLASS_EX(szTrayClockWndClass, CS_DBLCLKS, COLOR_3DFACE)
@ -86,9 +86,9 @@ public:
MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest) MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)
MESSAGE_HANDLER(WM_SETFONT, OnSetFont) MESSAGE_HANDLER(WM_SETFONT, OnSetFont)
MESSAGE_HANDLER(TCWM_GETMINIMUMSIZE, OnGetMinimumSize) MESSAGE_HANDLER(TCWM_GETMINIMUMSIZE, OnGetMinimumSize)
MESSAGE_HANDLER(TCWM_UPDATETIME, OnUpdateTime) MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnTaskbarSettingsChanged)
MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, OnNcLButtonDblClick)
END_MSG_MAP() END_MSG_MAP()
HWND _Init(IN HWND hWndParent, IN BOOL bVisible); HWND _Init(IN HWND hWndParent);
}; };

View file

@ -34,13 +34,9 @@ class CTrayNotifyWnd :
public CComObjectRootEx<CComMultiThreadModelNoCS>, public CComObjectRootEx<CComMultiThreadModelNoCS>,
public CWindowImpl < CTrayNotifyWnd, CWindow, CControlWinTraits > public CWindowImpl < CTrayNotifyWnd, CWindow, CControlWinTraits >
{ {
HWND hWndNotify;
CSysPagerWnd * m_pager; CSysPagerWnd * m_pager;
CTrayClockWnd * m_clock; CTrayClockWnd * m_clock;
CComPtr<ITrayWindow> TrayWindow;
HTHEME TrayTheme; HTHEME TrayTheme;
SIZE szTrayClockMin; SIZE szTrayClockMin;
SIZE szTrayNotify; SIZE szTrayNotify;
@ -49,7 +45,6 @@ class CTrayNotifyWnd :
public: public:
CTrayNotifyWnd() : CTrayNotifyWnd() :
hWndNotify(NULL),
m_pager(NULL), m_pager(NULL),
m_clock(NULL), m_clock(NULL),
TrayTheme(NULL), TrayTheme(NULL),
@ -104,10 +99,10 @@ public:
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
m_clock = new CTrayClockWnd(); m_clock = new CTrayClockWnd();
m_clock->_Init(m_hWnd, !g_TaskbarSettings.sr.HideClock); m_clock->_Init(m_hWnd);
m_pager = new CSysPagerWnd(); m_pager = new CSysPagerWnd();
m_pager->_Init(m_hWnd, !g_TaskbarSettings.sr.HideClock); m_pager->_Init(m_hWnd);
return TRUE; 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) LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
HDC hdc = (HDC) wParam; HDC hdc = (HDC) wParam;
@ -261,27 +236,16 @@ public:
return 0; 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) DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0);
{
if (m_pager)
{
return m_pager->NotifyIconCmd(wParam, lParam);
}
return TRUE; 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) LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
BOOL Horizontal = (BOOL) wParam; BOOL Horizontal = (BOOL) wParam;
@ -298,16 +262,6 @@ public:
return (LRESULT) GetMinimumSize((PSIZE) lParam); 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) LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
SIZE szClient; SIZE szClient;
@ -325,74 +279,30 @@ public:
return HTTRANSPARENT; 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)
{
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;
}
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)
{
if (m_clock != NULL)
{
m_clock->SendMessageW(WM_SETFONT, wParam, lParam);
}
bHandled = FALSE;
return FALSE;
}
LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT OnCtxMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
bHandled = TRUE; bHandled = TRUE;
return 0; return 0;
} }
LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT OnClockMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (wParam == SPI_SETNONCLIENTMETRICS) if (m_clock != NULL)
{ return m_clock->SendMessageW(uMsg, wParam, lParam);
m_pager->ResizeImagelist(); return TRUE;
} }
return 0;
LRESULT OnPagerMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (m_pager)
return m_pager->SendMessage(uMsg, wParam, lParam);
return TRUE;
}
LRESULT OnRealign(INT uCode, LPNMHDR hdr, BOOL& bHandled)
{
hdr->hwndFrom = m_hWnd;
return GetParent().SendMessage(WM_NOTIFY, 0, (LPARAM)hdr);
} }
DECLARE_WND_CLASS_EX(szTrayNotifyWndClass, CS_DBLCLKS, COLOR_3DFACE) DECLARE_WND_CLASS_EX(szTrayNotifyWndClass, CS_DBLCLKS, COLOR_3DFACE)
@ -401,51 +311,30 @@ public:
MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged) MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged)
MESSAGE_HANDLER(WM_SIZE, OnSize) MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest) 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_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_GETMINIMUMSIZE, OnGetMinimumSize)
MESSAGE_HANDLER(TNWM_UPDATETIME, OnUpdateTime)
MESSAGE_HANDLER(TNWM_SHOWCLOCK, OnShowClock)
MESSAGE_HANDLER(TWM_SETTINGSCHANGED, OnTaskbarSettingsChanged)
END_MSG_MAP() 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; 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(); CTrayNotifyWnd * pTrayNotify = new CTrayNotifyWnd();
// TODO: Destroy after the window is destroyed // TODO: Destroy after the window is destroyed
*ppinstance = pTrayNotify; *ppinstance = pTrayNotify;
return pTrayNotify->_Init(Tray); return pTrayNotify->_Init(hwndParent);
}
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);
} }

View file

@ -2061,7 +2061,7 @@ ChangePos:
SetWindowTheme(m_Rebar, L"TaskBar", NULL); SetWindowTheme(m_Rebar, L"TaskBar", NULL);
/* Create the tray notification window */ /* Create the tray notification window */
m_TrayNotify = CreateTrayNotifyWnd(this, &m_TrayNotifyInstance); m_TrayNotify = CreateTrayNotifyWnd(m_hWnd, &m_TrayNotifyInstance);
UpdateFonts(); UpdateFonts();
@ -2150,10 +2150,7 @@ ChangePos:
LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
if (m_TrayNotify) if (m_TrayNotify)
{ ::SendMessageW(m_TrayNotify, uMsg, wParam, lParam);
TRACE("WM_COPYDATA notify message received. Handling...\n");
return TrayNotify_NotifyIconCmd(m_TrayNotifyInstance, wParam, lParam);
}
return TRUE; return TRUE;
} }
@ -2556,23 +2553,11 @@ HandleTrayContextMenu:
LRESULT OnNcLButtonDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 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 /* We "handle" this message so users can't cause a weird maximize/restore
window animation when double-clicking the tray window! */ 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; return TRUE;
} }