#include "precomp.h"
-#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
-#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
-
/*
* SysPagerWnd
*/
-static const WCHAR szSysPagerWndClass [] = TEXT("SysPager");
+static const WCHAR szSysPagerWndClass [] = L"SysPager";
// Data comes from shell32/systray.cpp -> TrayNotifyCDS_Dummy
typedef struct _SYS_PAGER_COPY_DATA
} SYS_PAGER_COPY_DATA, *PSYS_PAGER_COPY_DATA;
class CNotifyToolbar :
- public CToolbar<NOTIFYICONDATA>
+ public CWindowImplBaseT< CToolbar<NOTIFYICONDATA>, CControlWinTraits >
{
- static const int ICON_SIZE = 16;
-
HIMAGELIST m_ImageList;
int m_VisibleButtonCount;
return -1;
}
- VOID AddButton(IN CONST NOTIFYICONDATA *iconData)
+ BOOL AddButton(IN CONST NOTIFYICONDATA *iconData)
{
TBBUTTON tbBtn;
NOTIFYICONDATA * notifyItem;
- WCHAR text [] = TEXT("");
+ WCHAR text[] = L"";
int index = FindItemByIconData(iconData, ¬ifyItem);
if (index >= 0)
{
- UpdateButton(iconData);
- return;
+ return UpdateButton(iconData);
}
notifyItem = new NOTIFYICONDATA();
if (iconData->uFlags & NIF_ICON)
{
+ notifyItem->hIcon = (HICON)CopyImage(iconData->hIcon, IMAGE_ICON, 0, 0, 0);
tbBtn.iBitmap = ImageList_AddIcon(m_ImageList, iconData->hIcon);
}
/* TODO: support NIF_INFO, NIF_GUID, NIF_REALTIME, NIF_SHOWTIP */
CToolbar::AddButton(&tbBtn);
- SetButtonSize(ICON_SIZE, ICON_SIZE);
+ SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
+
+ 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);
if (iconData->uFlags & NIF_ICON)
{
+ DestroyIcon(notifyItem->hIcon);
+ notifyItem->hIcon = (HICON)CopyImage(iconData->hIcon, IMAGE_ICON, 0, 0, 0);
tbbi.dwMask |= TBIF_IMAGE;
- tbbi.iImage = ImageList_AddIcon(m_ImageList, iconData->hIcon);
+ tbbi.iImage = ImageList_ReplaceIcon(m_ImageList, index, iconData->hIcon);
}
if (iconData->uFlags & NIF_TIP)
/* 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;
-
- DeleteButton(index);
+ return FALSE;
if (!(notifyItem->dwState & NIS_HIDDEN))
{
m_VisibleButtonCount--;
}
+ DestroyIcon(notifyItem->hIcon);
+
delete notifyItem;
+
+ ImageList_Remove(m_ImageList, index);
+
+ int count = GetButtonCount();
+
+ /* shift all buttons one index to the left -- starting one index right
+ from item to delete -- to preserve their correct icon and tip */
+ for (int i = index; i < count - 1; i++)
+ {
+ notifyItem = GetItemData(i + 1);
+ SetItemData(i, notifyItem);
+ UpdateButton(notifyItem);
+ }
+
+ /* Delete the right-most, now obsolete button */
+ DeleteButton(count - 1);
+
+ return TRUE;
}
VOID GetTooltipText(int index, LPTSTR szTip, DWORD cchTip)
}
}
+ VOID ResizeImagelist()
+ {
+ int cx, cy;
+ HIMAGELIST iml;
+
+ if (!ImageList_GetIconSize(m_ImageList, &cx, &cy))
+ return;
+
+ if (cx == GetSystemMetrics(SM_CXSMICON) && cy == GetSystemMetrics(SM_CYSMICON))
+ return;
+
+ iml = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 0, 1000);
+ if (!iml)
+ return;
+
+ ImageList_Destroy(m_ImageList);
+ m_ImageList = iml;
+ SetImageList(m_ImageList);
+
+ int count = GetButtonCount();
+ for (int i = 0; i < count; i++)
+ {
+ NOTIFYICONDATA * data = GetItemData(i);
+ INT iIcon = ImageList_AddIcon(iml, data->hIcon);
+ TBBUTTONINFO tbbi = { sizeof(tbbi), TBIF_BYINDEX | TBIF_IMAGE, 0, iIcon};
+ SetButtonInfo(i, &tbbi);
+ }
+
+ SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
+ }
+
private:
VOID SendMouseEvent(IN WORD wIndex, IN UINT uMsg, IN WPARAM wParam)
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)
{
if (pid == GetCurrentProcessId() ||
(uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST))
{
- PostMessage(notifyItem->hWnd,
- notifyItem->uCallbackMessage,
- notifyItem->uID,
- uMsg);
+ ::PostMessage(notifyItem->hWnd,
+ notifyItem->uCallbackMessage,
+ notifyItem->uID,
+ uMsg);
}
else
{
LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
-
+
INT iBtn = HitTest(&pt);
if (iBtn >= 0)
LRESULT OnTooltipShow(INT uCode, LPNMHDR hdr, BOOL& bHandled)
{
RECT rcTip, rcItem;
- GetWindowRect(hdr->hwndFrom, &rcTip);
+ ::GetWindowRect(hdr->hwndFrom, &rcTip);
SIZE szTip = { rcTip.right - rcTip.left, rcTip.bottom - rcTip.top };
if (hMon)
GetMonitorInfo(hMon, &monInfo);
else
- GetWindowRect(GetDesktopWindow(), &monInfo.rcMonitor);
+ ::GetWindowRect(GetDesktopWindow(), &monInfo.rcMonitor);
GetItemRect(iBtn, &rcItem);
POINT ptItem = { rcItem.left, rcItem.top };
SIZE szItem = { rcItem.right - rcItem.left, rcItem.bottom - rcItem.top };
- ClientToScreen(m_hWnd, &ptItem);
+ ClientToScreen(&ptItem);
ptItem.x += szItem.cx / 2;
ptItem.y -= szTip.cy;
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);
- m_ImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1000);
+ m_ImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 0, 1000);
SetImageList(m_ImageList);
- SetButtonSize(ICON_SIZE, ICON_SIZE);
+ TBMETRICS tbm = {sizeof(tbm)};
+ tbm.dwMask = TBMF_BARPAD | TBMF_BUTTONSPACING | TBMF_PAD;
+ tbm.cxPad = 1;
+ tbm.cyPad = 1;
+ tbm.cxButtonSpacing = 1;
+ tbm.cyButtonSpacing = 1;
+ SetMetrics(&tbm);
+
+ SetButtonSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
}
};
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
Toolbar.Initialize(m_hWnd);
+
+ // Explicitly request running applications to re-register their systray icons
+ ::SendNotifyMessageW(HWND_BROADCAST,
+ RegisterWindowMessageW(L"TaskbarCreated"),
+ 0, 0);
+
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;
}
- void GetSize(IN WPARAM wParam, IN PSIZE size)
+ void GetSize(IN BOOL IsHorizontal, IN PSIZE size)
{
+ /* Get the ideal height or width */
+#if 0
+ /* Unfortunately this doens't work correctly in ros */
+ Toolbar.GetIdealSize(!IsHorizontal, size);
+
+ /* Make the reference dimension an exact multiple of the icon size */
+ if (IsHorizontal)
+ size->cy -= size->cy % GetSystemMetrics(SM_CYSMICON);
+ else
+ size->cx -= size->cx % GetSystemMetrics(SM_CXSMICON);
+
+#else
INT rows = 0;
+ INT columns = 0;
+ INT cyButton = GetSystemMetrics(SM_CYSMICON) + 2;
+ INT cxButton = GetSystemMetrics(SM_CXSMICON) + 2;
int VisibleButtonCount = Toolbar.GetVisibleButtonCount();
- if (wParam) /* horizontal */
+ if (IsHorizontal)
{
- rows = size->cy / 24;
- if (rows == 0)
- rows++;
- size->cx = (VisibleButtonCount + rows - 1) / rows * 24;
+ rows = max(size->cy / cyButton, 1);
+ columns = (VisibleButtonCount + rows - 1) / rows;
}
else
{
- rows = size->cx / 24;
- if (rows == 0)
- rows++;
- size->cy = (VisibleButtonCount + rows - 1) / rows * 24;
+ columns = max(size->cx / cxButton, 1);
+ rows = (VisibleButtonCount + columns - 1) / columns;
}
+ size->cx = columns * cxButton;
+ size->cy = rows * cyButton;
+#endif
}
LRESULT OnGetInfoTip(INT uCode, LPNMHDR hdr, BOOL& bHandled)
if (Toolbar)
{
- TBMETRICS tbm;
- tbm.cbSize = sizeof(tbm);
- tbm.dwMask = TBMF_BARPAD | TBMF_BUTTONSPACING;
- tbm.cxBarPad = tbm.cyBarPad = 0;
- tbm.cxButtonSpacing = 0;
- tbm.cyButtonSpacing = 0;
-
- Toolbar.SetMetrics(&tbm);
-
Toolbar.SetWindowPos(NULL, 0, 0, szClient.cx, szClient.cy, SWP_NOZORDER);
Toolbar.AutoSize();
return 0;
}
+ void ResizeImagelist()
+ {
+ Toolbar.ResizeImagelist();
+ }
+
DECLARE_WND_CLASS_EX(szSysPagerWndClass, CS_DBLCLKS, COLOR_3DFACE)
- BEGIN_MSG_MAP(CTaskSwitchWnd)
+ BEGIN_MSG_MAP(CSysPagerWnd)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
MESSAGE_HANDLER(WM_SIZE, OnSize)
* TrayClockWnd
*/
-static const WCHAR szTrayClockWndClass [] = TEXT("TrayClockWClass");
+static const WCHAR szTrayClockWndClass[] = L"TrayClockWClass";
#define ID_TRAYCLOCK_TIMER 0
#define ID_TRAYCLOCK_TIMER_INIT 1
{
BOOL IsTime;
DWORD dwFormatFlags;
- LPCTSTR lpFormat;
+ LPCWSTR lpFormat;
} ClockWndFormats [] = {
- { TRUE, 0, NULL },
- { FALSE, 0, TEXT("dddd") },
- { FALSE, DATE_SHORTDATE, NULL }
+ { TRUE, 0, NULL },
+ { FALSE, 0, L"dddd" },
+ { FALSE, DATE_SHORTDATE, NULL }
};
-#define CLOCKWND_FORMAT_COUNT (sizeof(ClockWndFormats) / sizeof(ClockWndFormats[0]))
+#define CLOCKWND_FORMAT_COUNT (_ARRAYSIZE(ClockWndFormats))
#define TRAY_CLOCK_WND_SPACING_X 0
#define TRAY_CLOCK_WND_SPACING_Y 0
ZeroMemory(&LocalTime, sizeof(LocalTime));
ZeroMemory(&CurrentSize, sizeof(CurrentSize));
ZeroMemory(LineSizes, sizeof(LineSizes));
- ZeroMemory(szLines, sizeof(LineSizes));
+ ZeroMemory(szLines, sizeof(szLines));
}
virtual ~CTrayClockWnd() { }
0,
TMT_TEXTCOLOR,
&textColor);
+
+ if (this->hFont != NULL)
+ DeleteObject(this->hFont);
+
+ SetFont(hFont, FALSE);
}
else
{
- NONCLIENTMETRICS ncm = { 0 };
- ncm.cbSize = sizeof(ncm);
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, FALSE);
-
- hFont = CreateFontIndirectW(&ncm.lfMessageFont);
-
+ /* We don't need to set a font here, our parent will use
+ * WM_SETFONT to set the right one when themes are not enabled. */
textColor = RGB(0, 0, 0);
}
- SetFont(hFont, FALSE);
-
CloseThemeData(clockTheme);
return TRUE;
{
HDC hDC;
HFONT hPrevFont;
- INT c, i;
+ UINT c, i;
BOOL bRet = TRUE;
- hDC = GetDC(m_hWnd);
+ hDC = GetDC();
if (hDC != NULL)
{
if (hFont)
hPrevFont = (HFONT) SelectObject(hDC, hFont);
- for (i = 0; i != CLOCKWND_FORMAT_COUNT && bRet; i++)
+ for (i = 0; i < CLOCKWND_FORMAT_COUNT && bRet; i++)
{
- if (szLines[i][0] != TEXT('\0') &&
- !GetTextExtentPoint(hDC, szLines[i], _tcslen(szLines[i]),
- &LineSizes[i]))
+ if (szLines[i][0] != L'\0' &&
+ !GetTextExtentPointW(hDC, szLines[i], wcslen(szLines[i]),
+ &LineSizes[i]))
{
bRet = FALSE;
break;
if (hFont)
SelectObject(hDC, hPrevFont);
- ReleaseDC(m_hWnd, hDC);
+ ReleaseDC(hDC);
if (bRet)
{
LineSpacing = 0;
/* calculate the line spacing */
- for (i = 0, c = 0; i != CLOCKWND_FORMAT_COUNT; i++)
+ for (i = 0, c = 0; i < CLOCKWND_FORMAT_COUNT; i++)
{
if (LineSizes[i].cx > 0)
{
if (c > 0)
{
- /* We want a spaceing of 1/2 line */
+ /* We want a spacing of 1/2 line */
LineSpacing = (LineSpacing / c) / 2;
}
WORD GetMinimumSize(IN BOOL Horizontal, IN OUT PSIZE pSize)
{
WORD iLinesVisible = 0;
- INT i;
+ UINT i;
SIZE szMax = { 0, 0 };
if (!LinesMeasured)
if (!LinesMeasured)
return 0;
- for (i = 0;
- i != CLOCKWND_FORMAT_COUNT;
- i++)
+ for (i = 0; i < CLOCKWND_FORMAT_COUNT; i++)
{
if (LineSizes[i].cx != 0)
{
}
- VOID UpdateWnd()
+ VOID UpdateWnd()
{
SIZE szPrevCurrent;
- INT BufSize, iRet, i;
+ UINT BufSize, i;
+ INT iRet;
RECT rcClient;
- ZeroMemory(LineSizes,
- sizeof(LineSizes));
+ ZeroMemory(LineSizes, sizeof(LineSizes));
szPrevCurrent = CurrentSize;
- for (i = 0;
- i != CLOCKWND_FORMAT_COUNT;
- i++)
+ for (i = 0; i < CLOCKWND_FORMAT_COUNT; i++)
{
- szLines[i][0] = TEXT('\0');
- BufSize = sizeof(szLines[0]) / sizeof(szLines[0][0]);
+ szLines[i][0] = L'\0';
+ BufSize = _countof(szLines[0]);
if (ClockWndFormats[i].IsTime)
{
iRet = GetTimeFormat(LOCALE_USER_DEFAULT,
- AdvancedSettings.bShowSeconds ? ClockWndFormats[i].dwFormatFlags : TIME_NOSECONDS,
+ TaskBarSettings.bShowSeconds ? ClockWndFormats[i].dwFormatFlags : TIME_NOSECONDS,
&LocalTime,
ClockWndFormats[i].lpFormat,
szLines[i],
CurrentSize = szWnd;
}
- if (IsWindowVisible(m_hWnd))
+ if (IsWindowVisible())
{
InvalidateRect(NULL, TRUE);
NMHDR nmh;
nmh.hwndFrom = m_hWnd;
- nmh.idFrom = GetWindowLongPtr(m_hWnd, GWLP_ID);
+ nmh.idFrom = GetWindowLongPtr(GWLP_ID);
nmh.code = NTNWM_REALIGN;
SendMessage(hWndNotify,
}
}
- VOID Update()
+ VOID Update()
{
GetLocalTime(&LocalTime);
UpdateWnd();
}
- UINT CalculateDueTime()
+ UINT CalculateDueTime()
{
UINT uiDueTime;
/* Calculate the due time */
GetLocalTime(&LocalTime);
uiDueTime = 1000 - (UINT) LocalTime.wMilliseconds;
- if (AdvancedSettings.bShowSeconds)
+ if (TaskBarSettings.bShowSeconds)
uiDueTime += (UINT) LocalTime.wSecond * 100;
else
uiDueTime += (59 - (UINT) LocalTime.wSecond) * 1000;
return uiDueTime;
}
- BOOL ResetTime()
+ BOOL ResetTime()
{
UINT uiDueTime;
BOOL Ret;
return Ret;
}
- VOID CalibrateTimer()
+ VOID CalibrateTimer()
{
UINT uiDueTime;
BOOL Ret;
uiDueTime = CalculateDueTime();
- if (AdvancedSettings.bShowSeconds)
+ if (TaskBarSettings.bShowSeconds)
{
uiWait1 = 1000 - 200;
uiWait2 = 1000;
{
RECT rcClient;
HFONT hPrevFont;
- int iPrevBkMode, i, line;
+ INT iPrevBkMode;
+ UINT i, line;
PAINTSTRUCT ps;
HDC hDC = (HDC) wParam;
rcClient.bottom = rcClient.top + CurrentSize.cy;
for (i = 0, line = 0;
- i != CLOCKWND_FORMAT_COUNT && line < VisibleLines;
- i++)
+ i < CLOCKWND_FORMAT_COUNT && line < VisibleLines;
+ i++)
{
if (LineSizes[i].cx != 0)
{
TRAY_CLOCK_WND_SPACING_X,
rcClient.top + TRAY_CLOCK_WND_SPACING_Y,
szLines[i],
- _tcslen(szLines[i]));
+ wcslen(szLines[i]));
rcClient.top += LineSizes[i].cy + LineSpacing;
line++;
DECLARE_WND_CLASS_EX(szTrayClockWndClass, CS_DBLCLKS, COLOR_3DFACE)
- BEGIN_MSG_MAP(CTaskSwitchWnd)
+ BEGIN_MSG_MAP(CTrayClockWnd)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)
+ MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)
+ MESSAGE_HANDLER(WM_SETFONT, OnSetFont)
MESSAGE_HANDLER(TCWM_GETMINIMUMSIZE, OnGetMinimumSize)
MESSAGE_HANDLER(TCWM_UPDATETIME, OnUpdateTime)
Create(hWndParent, 0, NULL, dwStyle);
if (m_hWnd != NULL)
- {
SetWindowTheme(m_hWnd, L"TrayNotify", NULL);
- OnThemeChanged();
- }
return m_hWnd;
static const WCHAR szTrayNotifyWndClass [] = TEXT("TrayNotifyWnd");
-#define TRAY_NOTIFY_WND_SPACING_X 2
-#define TRAY_NOTIFY_WND_SPACING_Y 2
+#define TRAY_NOTIFY_WND_SPACING_X 1
+#define TRAY_NOTIFY_WND_SPACING_Y 1
class CTrayNotifyWnd :
public CComObjectRootEx<CComMultiThreadModelNoCS>,
{
SetWindowExStyle(m_hWnd, WS_EX_STATICEDGE, WS_EX_STATICEDGE);
- ContentMargin.cxLeftWidth = 0;
- ContentMargin.cxRightWidth = 0;
- ContentMargin.cyTopHeight = 0;
- ContentMargin.cyBottomHeight = 0;
+ ContentMargin.cxLeftWidth = 2;
+ ContentMargin.cxRightWidth = 2;
+ ContentMargin.cyTopHeight = 2;
+ ContentMargin.cyBottomHeight = 2;
}
return TRUE;
m_pager = new CSysPagerWnd();
m_pager->_Init(m_hWnd, !HideClock);
- OnThemeChanged();
-
return TRUE;
}
- BOOL GetMinimumSize(IN BOOL Horizontal, IN OUT PSIZE pSize)
+ BOOL GetMinimumSize(IN OUT PSIZE pSize)
{
SIZE szClock = { 0, 0 };
SIZE szTray = { 0, 0 };
- IsHorizontal = Horizontal;
- if (IsHorizontal)
- SetWindowTheme(m_hWnd, L"TrayNotifyHoriz", NULL);
- else
- SetWindowTheme(m_hWnd, L"TrayNotifyVert", NULL);
-
if (!HideClock)
{
- if (Horizontal)
+ if (IsHorizontal)
{
szClock.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
if (szClock.cy <= 0)
goto NoClock;
}
- m_clock->SendMessage(TCWM_GETMINIMUMSIZE, (WPARAM) Horizontal, (LPARAM) &szClock);
+ m_clock->SendMessage(TCWM_GETMINIMUMSIZE, (WPARAM) IsHorizontal, (LPARAM) &szClock);
szTrayClockMin = szClock;
}
NoClock:
szTrayClockMin = szClock;
- if (Horizontal)
+ if (IsHorizontal)
{
szTray.cy = pSize->cy - 2 * TRAY_NOTIFY_WND_SPACING_Y;
}
szTray.cx = pSize->cx - 2 * TRAY_NOTIFY_WND_SPACING_X;
}
- m_pager->GetSize(Horizontal, &szTray);
+ m_pager->GetSize(IsHorizontal, &szTray);
szTrayNotify = szTray;
- if (Horizontal)
+ if (IsHorizontal)
{
pSize->cx = 2 * TRAY_NOTIFY_WND_SPACING_X;
if (IsHorizontal)
{
- ptClock.x = pszClient->cx - TRAY_NOTIFY_WND_SPACING_X - szTrayClockMin.cx;
- ptClock.y = TRAY_NOTIFY_WND_SPACING_Y;
+ ptClock.x = pszClient->cx - szTrayClockMin.cx - ContentMargin.cxRightWidth;
+ ptClock.y = ContentMargin.cyTopHeight;
szClock.cx = szTrayClockMin.cx;
- szClock.cy = pszClient->cy - (2 * TRAY_NOTIFY_WND_SPACING_Y);
+ szClock.cy = pszClient->cy - ContentMargin.cyTopHeight - ContentMargin.cyBottomHeight;
}
else
{
- ptClock.x = TRAY_NOTIFY_WND_SPACING_X;
- ptClock.y = pszClient->cy - TRAY_NOTIFY_WND_SPACING_Y - szTrayClockMin.cy;
- szClock.cx = pszClient->cx - (2 * TRAY_NOTIFY_WND_SPACING_X);
+ ptClock.x = ContentMargin.cxLeftWidth;
+ ptClock.y = pszClient->cy - szTrayClockMin.cy;
+ szClock.cx = pszClient->cx - ContentMargin.cxLeftWidth - ContentMargin.cxRightWidth;
szClock.cy = szTrayClockMin.cy;
}
szClock.cy,
SWP_NOZORDER);
+ POINT ptPager;
+
if (IsHorizontal)
{
- ptClock.x -= szTrayNotify.cx;
+ ptPager.x = ContentMargin.cxLeftWidth;
+ ptPager.y = (pszClient->cy - szTrayNotify.cy)/2;
}
else
{
- ptClock.y -= szTrayNotify.cy;
+ ptPager.x = (pszClient->cx - szTrayNotify.cx)/2;
+ ptPager.y = ContentMargin.cyTopHeight;
}
m_pager->SetWindowPos(
NULL,
- ptClock.x,
- ptClock.y,
+ ptPager.x,
+ ptPager.y,
szTrayNotify.cx,
szTrayNotify.cy,
SWP_NOZORDER);
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;
BOOL GetClockRect(OUT PRECT rcClock)
{
- if (!IsWindowVisible(m_clock->m_hWnd))
+ if (!m_clock->IsWindowVisible())
return FALSE;
- return GetWindowRect(m_clock->m_hWnd, rcClock);
+ return m_clock->GetWindowRect(rcClock);
}
LRESULT OnGetMinimumSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
- return (LRESULT) GetMinimumSize((BOOL) wParam, (PSIZE) lParam);
+ BOOL Horizontal = (BOOL) wParam;
+
+ if (Horizontal != IsHorizontal)
+ {
+ IsHorizontal = Horizontal;
+ if (IsHorizontal)
+ SetWindowTheme(m_hWnd, L"TrayNotifyHoriz", NULL);
+ else
+ SetWindowTheme(m_hWnd, L"TrayNotifyVert", NULL);
+ }
+
+ return (LRESULT) GetMinimumSize((PSIZE) lParam);
}
LRESULT OnUpdateTime(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
return 0;
}
+ LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+ {
+ if (wParam == SPI_SETNONCLIENTMETRICS)
+ {
+ m_pager->ResizeImagelist();
+ }
+ return 0;
+ }
+
DECLARE_WND_CLASS_EX(szTrayNotifyWndClass, CS_DBLCLKS, COLOR_3DFACE)
- BEGIN_MSG_MAP(CTaskSwitchWnd)
+ BEGIN_MSG_MAP(CTrayNotifyWnd)
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)
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