} SYS_PAGER_COPY_DATA, *PSYS_PAGER_COPY_DATA;
class CNotifyToolbar :
- public CToolbar<NOTIFYICONDATA>
+ public CWindowImplBaseT< CToolbar<NOTIFYICONDATA>, CControlWinTraits >
{
static const int ICON_SIZE = 16;
return -1;
}
- VOID AddButton(IN CONST NOTIFYICONDATA *iconData)
+ BOOL AddButton(IN CONST NOTIFYICONDATA *iconData)
{
TBBUTTON tbBtn;
NOTIFYICONDATA * notifyItem;
int index = FindItemByIconData(iconData, ¬ifyItem);
if (index >= 0)
{
- UpdateButton(iconData);
- return;
+ return UpdateButton(iconData);
}
notifyItem = new NOTIFYICONDATA();
tbBtn.fsState |= TBSTATE_HIDDEN;
m_VisibleButtonCount--;
}
-
}
/* TODO: support NIF_INFO, NIF_GUID, NIF_REALTIME, NIF_SHOWTIP */
CToolbar::AddButton(&tbBtn);
SetButtonSize(ICON_SIZE, ICON_SIZE);
+
+ return TRUE;
}
- VOID UpdateButton(IN CONST NOTIFYICONDATA *iconData)
+ BOOL UpdateButton(IN CONST NOTIFYICONDATA *iconData)
{
NOTIFYICONDATA * notifyItem;
TBBUTTONINFO tbbi = { 0 };
int index = FindItemByIconData(iconData, ¬ifyItem);
if (index < 0)
{
- AddButton(iconData);
- return;
+ return AddButton(iconData);
}
tbbi.cbSize = sizeof(tbbi);
/* TODO: support NIF_INFO, NIF_GUID, NIF_REALTIME, NIF_SHOWTIP */
SetButtonInfo(index, &tbbi);
+
+ return TRUE;
}
- VOID RemoveButton(IN CONST NOTIFYICONDATA *iconData)
+ BOOL RemoveButton(IN CONST NOTIFYICONDATA *iconData)
{
NOTIFYICONDATA * notifyItem;
int index = FindItemByIconData(iconData, ¬ifyItem);
if (index < 0)
- return;
+ return FALSE;
DeleteButton(index);
+
+ if (!(notifyItem->dwState & NIS_HIDDEN))
+ {
+ m_VisibleButtonCount--;
+ }
+
delete notifyItem;
+
+ return TRUE;
}
VOID GetTooltipText(int index, LPTSTR szTip, DWORD cchTip)
NOTIFYICONDATA * notifyItem = GetItemData(wIndex);
if (!::IsWindow(notifyItem->hWnd))
+ {
+ // We detect and destroy icons with invalid handles only on mouse move over systray, same as MS does.
+ // Alternatively we could search for them periodically (would waste more resources).
+ TRACE("destroying icon with invalid handle\n");
+
+ HWND parentHWND = GetParent();
+ parentHWND = ::GetParent(parentHWND);
+
+ RECT windowRect;
+ ::GetClientRect(parentHWND, &windowRect);
+
+ RemoveButton(notifyItem);
+
+ SendMessage(parentHWND,
+ WM_SIZE,
+ 0,
+ MAKELONG(windowRect.right - windowRect.left,
+ windowRect.bottom - windowRect.top));
+
return;
+ }
if (uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST)
{
TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | TBSTYLE_TRANSPARENT |
CCS_TOP | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER;
- SubclassWindow(Create(hWndParent, styles));
+ SubclassWindow(CToolbar::Create(hWndParent, styles));
SetWindowTheme(m_hWnd, L"TrayNotify", NULL);
return TRUE;
}
- LRESULT NotifyMsg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+ BOOL NotifyIconCmd(WPARAM wParam, LPARAM lParam)
{
PCOPYDATASTRUCT cpData = (PCOPYDATASTRUCT) lParam;
if (cpData->dwData == 1)
NOTIFYICONDATA *iconData;
HWND parentHWND;
RECT windowRect;
+ BOOL ret = FALSE;
parentHWND = GetParent();
parentHWND = ::GetParent(parentHWND);
::GetClientRect(parentHWND, &windowRect);
data = (PSYS_PAGER_COPY_DATA) cpData->lpData;
iconData = &data->nicon_data;
+ TRACE("NotifyIconCmd received. Code=%d\n", data->notify_code);
switch (data->notify_code)
{
case NIM_ADD:
- {
- Toolbar.AddButton(iconData);
+ ret = Toolbar.AddButton(iconData);
break;
- }
case NIM_MODIFY:
- {
- Toolbar.UpdateButton(iconData);
+ ret = Toolbar.UpdateButton(iconData);
break;
- }
case NIM_DELETE:
- {
- Toolbar.RemoveButton(iconData);
+ ret = Toolbar.RemoveButton(iconData);
break;
- }
default:
- TRACE("NotifyMessage received with unknown code %d.\n", data->notify_code);
- break;
+ TRACE("NotifyIconCmd received with unknown code %d.\n", data->notify_code);
+ return FALSE;
}
+
SendMessage(parentHWND,
WM_SIZE,
0,
MAKELONG(windowRect.right - windowRect.left,
- windowRect.bottom - windowRect.top));
+ windowRect.bottom - windowRect.top));
+
+ return ret;
}
return TRUE;
LRESULT DrawBackground(HDC hdc)
{
+ HRESULT res;
RECT rect;
GetClientRect(&rect);
DrawThemeParentBackground(m_hWnd, hdc, &rect);
}
- DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0);
+ res = DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0);
}
- return TRUE;
+ return res;
}
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
return DrawBackground(hdc);
}
- LRESULT NotifyMsg(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+ BOOL NotifyIconCmd(WPARAM wParam, LPARAM lParam)
{
if (m_pager)
{
- m_pager->NotifyMsg(uMsg, wParam, lParam, bHandled);
+ return m_pager->NotifyIconCmd(wParam, lParam);
}
return TRUE;
return pTrayNotify->_Init(Tray, bHideClock);
}
-VOID
-TrayNotify_NotifyMsg(CTrayNotifyWnd* pTrayNotify, WPARAM wParam, LPARAM lParam)
+BOOL
+TrayNotify_NotifyIconCmd(CTrayNotifyWnd* pTrayNotify, WPARAM wParam, LPARAM lParam)
{
- BOOL bDummy;
- pTrayNotify->NotifyMsg(0, wParam, lParam, bDummy);
+ return pTrayNotify->NotifyIconCmd(wParam, lParam);
}
BOOL