Author: gadamopoulos
Date: Wed Mar 22 01:09:45 2017
New Revision: 74221
URL:
http://svn.reactos.org/svn/reactos?rev=74221&view=rev
Log:
[EXPLORER]
- Simplify the mess with the font handling in explorer. Make it respond to changes in the
system metrics and use the correct fonts.
- Make CheckTrayWndPosition resize the taskbar based on the optimal size that the rebar
returns.
- Without losing my sanity (yet), I managed to make it have exactly the same size as
windows explorer when I run it in windows with the classic theme.
- Themes still aren't sized perfectly. Running on ros shows lots of bugs in our common
controls.
Modified:
trunk/reactos/base/shell/explorer/precomp.h
trunk/reactos/base/shell/explorer/taskswnd.cpp
trunk/reactos/base/shell/explorer/trayntfy.cpp
trunk/reactos/base/shell/explorer/traywnd.cpp
Modified: trunk/reactos/base/shell/explorer/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/precom…
==============================================================================
--- trunk/reactos/base/shell/explorer/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer/precomp.h [iso-8859-1] Wed Mar 22 01:09:45 2017
@@ -135,7 +135,6 @@
STDMETHOD_(HWND, GetHWND) (THIS) PURE;
STDMETHOD_(BOOL, IsSpecialHWND) (THIS_ HWND hWnd) PURE;
STDMETHOD_(BOOL, IsHorizontal) (THIS) PURE;
- STDMETHOD_(HFONT, GetCaptionFonts) (THIS_ HFONT *phBoldCaption) PURE;
STDMETHOD_(HWND, DisplayProperties) (THIS) PURE;
STDMETHOD_(BOOL, ExecContextMenuCmd) (THIS_ UINT uiCmd) PURE;
STDMETHOD_(BOOL, Lock) (THIS_ BOOL bLock) PURE;
@@ -153,7 +152,6 @@
#define ITrayWindow_GetHWND(p) (p)->lpVtbl->GetHWND(p)
#define ITrayWindow_IsSpecialHWND(p,a) (p)->lpVtbl->IsSpecialHWND(p,a)
#define ITrayWindow_IsHorizontal(p) (p)->lpVtbl->IsHorizontal(p)
-#define ITrayWindow_GetCaptionFonts(p,a) (p)->lpVtbl->GetCaptionFonts(p,a)
#define ITrayWindow_DisplayProperties(p) (p)->lpVtbl->DisplayProperties(p)
#define ITrayWindow_ExecContextMenuCmd(p,a) (p)->lpVtbl->ExecContextMenuCmd(p,a)
#define ITrayWindow_Lock(p,a) (p)->lpVtbl->Lock(p,a)
Modified: trunk/reactos/base/shell/explorer/taskswnd.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/tasksw…
==============================================================================
--- trunk/reactos/base/shell/explorer/taskswnd.cpp [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer/taskswnd.cpp [iso-8859-1] Wed Mar 22 01:09:45 2017
@@ -241,8 +241,6 @@
}
virtual ~CTaskSwitchWnd() { }
- VOID TaskSwitchWnd_UpdateButtonsSize(IN BOOL bRedrawDisabled);
-
INT GetWndTextFromTaskItem(IN PTASK_ITEM TaskItem, LPWSTR szBuf, DWORD cchBuf)
{
/* Get the window text without sending a message so we don't hang if an
@@ -1146,6 +1144,10 @@
UINT uiRows, uiMax, uiMin, uiBtnsPerLine, ui;
LONG NewBtnSize;
BOOL Horizontal;
+
+ int cx = GetSystemMetrics(SM_CXMINIMIZED);
+ int cy = m_ButtonSize.cy = GetSystemMetrics(SM_CYSIZE) + (2 *
GetSystemMetrics(SM_CYEDGE));
+ m_TaskBar.SetButtonSize(cx, cy);
if (GetClientRect(&rcClient) && !IsRectEmpty(&rcClient))
{
@@ -1313,12 +1315,6 @@
m_ImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1000);
m_TaskBar.SetImageList(m_ImageList);
-
- /* Calculate the default button size. Don't save this in m_ButtonSize.cx so
that
- the actual button width gets updated correctly on the first recalculation */
- int cx = GetSystemMetrics(SM_CXMINIMIZED);
- int cy = m_ButtonSize.cy = GetSystemMetrics(SM_CYSIZE) + (2 *
GetSystemMetrics(SM_CYEDGE));
- m_TaskBar.SetButtonSize(cx, cy);
/* Set proper spacing between buttons */
m_TaskBar.UpdateTbButtonSpacing(m_Tray->IsHorizontal(), m_Theme != NULL);
@@ -1813,6 +1809,22 @@
return TRUE;
}
+ LRESULT OnSetFont(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+ {
+ return m_TaskBar.SendMessageW(uMsg, wParam, lParam);
+ }
+
+ LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
+ {
+ if (wParam == SPI_SETNONCLIENTMETRICS)
+ {
+ /* Don't update the font, this will be done when we get a WM_SETFONT
from our parent */
+ UpdateButtonsSize(FALSE);
+ }
+
+ return 0;
+ }
+
DECLARE_WND_CLASS_EX(szTaskSwitchWndClass, CS_DBLCLKS, COLOR_3DFACE)
BEGIN_MSG_MAP(CTaskSwitchWnd)
@@ -1828,6 +1840,8 @@
MESSAGE_HANDLER(TSWM_UPDATETASKBARPOS, OnUpdateTaskbarPos)
MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
+ MESSAGE_HANDLER(WM_SETFONT, OnSetFont)
+ MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged)
MESSAGE_HANDLER(m_ShellHookMsg, HandleShellHookMsg)
END_MSG_MAP()
Modified: trunk/reactos/base/shell/explorer/trayntfy.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/traynt…
==============================================================================
--- trunk/reactos/base/shell/explorer/trayntfy.cpp [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer/trayntfy.cpp [iso-8859-1] Wed Mar 22 01:09:45 2017
@@ -1208,6 +1208,7 @@
MESSAGE_HANDLER(WM_PRINTCLIENT, OnPaint)
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)
Modified: trunk/reactos/base/shell/explorer/traywnd.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer/traywn…
==============================================================================
--- trunk/reactos/base/shell/explorer/traywnd.cpp [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer/traywnd.cpp [iso-8859-1] Wed Mar 22 01:09:45 2017
@@ -53,8 +53,6 @@
#define IDHK_DESKTOP 0x1fe
#define IDHK_PAGER 0x1ff
-static LONG TrayWndCount = 0;
-
static const WCHAR szTrayWndClass[] = L"Shell_TrayWnd";
/*
@@ -88,17 +86,12 @@
DeleteObject(m_Font);
}
- HFONT GetFont()
- {
- return m_Font;
- }
-
SIZE GetSize()
{
return m_Size;
}
- VOID UpdateSize(IN HBITMAP hbmStart = NULL)
+ VOID UpdateSize()
{
SIZE Size = { 0, 0 };
@@ -106,26 +99,36 @@
!SendMessageW(BCM_GETIDEALSIZE, 0, (LPARAM) &Size))
{
Size.cx = 2 * GetSystemMetrics(SM_CXEDGE) + GetSystemMetrics(SM_CYCAPTION) *
3;
- Size.cy = 2 * GetSystemMetrics(SM_CYEDGE) + GetSystemMetrics(SM_CYCAPTION);
- }
+ }
+
+ if (GetWindowTheme(m_hWnd))
+ Size.cy = max(Size.cy, GetSystemMetrics(SM_CYCAPTION));
+ else
+ Size.cy = max(Size.cy, GetSystemMetrics(SM_CYSIZE) + (2 *
GetSystemMetrics(SM_CYEDGE)));
/* Save the size of the start button */
m_Size = Size;
}
- VOID Initialize()
- {
- SetWindowTheme(m_hWnd, L"Start", NULL);
-
+ VOID UpdateFont()
+ {
/* Get the system fonts, we use the caption font, always bold, though. */
NONCLIENTMETRICS ncm = {sizeof(ncm)};
- if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm,
FALSE))
- {
- ncm.lfCaptionFont.lfWeight = FW_BOLD;
- m_Font = CreateFontIndirect(&ncm.lfCaptionFont);
- }
+ if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm,
FALSE))
+ return;
+
+ if (m_Font)
+ DeleteObject(m_Font);
+
+ ncm.lfCaptionFont.lfWeight = FW_BOLD;
+ m_Font = CreateFontIndirect(&ncm.lfCaptionFont);
SetFont(m_Font, FALSE);
+ }
+
+ VOID Initialize()
+ {
+ SetWindowTheme(m_hWnd, L"Start", NULL);
m_ImageList = ImageList_LoadImageW(hExplorerInstance,
MAKEINTRESOURCEW(IDB_START),
@@ -183,7 +186,6 @@
HTHEME m_Theme;
- HFONT m_CaptionFont;
HFONT m_Font;
HWND m_DesktopWnd;
@@ -236,7 +238,6 @@
CTrayWindow() :
m_StartButton(),
m_Theme(NULL),
- m_CaptionFont(NULL),
m_Font(NULL),
m_DesktopWnd(NULL),
m_Rebar(NULL),
@@ -267,12 +268,6 @@
m_ShellServices = NULL;
}
- if (m_CaptionFont != NULL)
- {
- DeleteObject(m_CaptionFont);
- m_CaptionFont = NULL;
- }
-
if (m_Font != NULL)
{
DeleteObject(m_Font);
@@ -285,8 +280,7 @@
m_Theme = NULL;
}
- if (InterlockedDecrement(&TrayWndCount) == 0)
- PostQuitMessage(0);
+ PostQuitMessage(0);
}
@@ -734,28 +728,31 @@
* ##### moving and sizing handling #####
*/
- BOOL UpdateNonClientMetrics()
- {
- NONCLIENTMETRICS ncm;
- ncm.cbSize = sizeof(ncm);
- if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
- {
- if (m_Font != NULL)
- DeleteObject(m_Font);
-
- m_Font = CreateFontIndirect(&ncm.lfMessageFont);
- return TRUE;
- }
-
- return FALSE;
- }
-
- VOID SetWindowsFont()
- {
- if (m_TrayNotify != NULL)
- {
- SendMessage(m_TrayNotify, WM_SETFONT, (WPARAM) m_Font, TRUE);
- }
+ void UpdateFonts()
+ {
+ m_StartButton.UpdateFont();
+
+ NONCLIENTMETRICS ncm = {sizeof(ncm)};
+ if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm,
FALSE))
+ {
+ ERR("SPI_GETNONCLIENTMETRICS failed\n");
+ return;
+ }
+
+ if (m_Font != NULL)
+ DeleteObject(m_Font);
+
+ ncm.lfCaptionFont.lfWeight = FW_NORMAL;
+ m_Font = CreateFontIndirect(&ncm.lfCaptionFont);
+ if (!m_Font)
+ {
+ ERR("CreateFontIndirect failed\n");
+ return;
+ }
+
+ SendMessage(m_Rebar, WM_SETFONT, (WPARAM) m_Font, TRUE);
+ SendMessage(m_TaskSwitch, WM_SETFONT, (WPARAM) m_Font, TRUE);
+ SendMessage(m_TrayNotify, WM_SETFONT, (WPARAM) m_Font, TRUE);
}
HMONITOR GetScreenRectFromRect(
@@ -1318,6 +1315,16 @@
rcTray.bottom += m_AutoHideOffset.cy;
}
+ IUnknown_Exec(m_TrayBandSite,
+ IID_IDeskBand,
+ DBID_BANDINFOCHANGED,
+ 0,
+ NULL,
+ NULL);
+
+ FitToRebar(&rcTray);
+ m_TrayRects[m_Position] = rcTray;
+
/* Move the tray window */
SetWindowPos(NULL,
rcTray.left,
@@ -1605,6 +1612,42 @@
/* Update the task switch window configuration */
SendMessage(m_TaskSwitch, TSWM_UPDATETASKBARPOS, 0, 0);
}
+ }
+
+ void FitToRebar(PRECT pRect)
+ {
+ /* Get the rect of the rebar */
+ RECT rebarRect, taskbarRect;
+ ::GetWindowRect(m_Rebar, &rebarRect);
+ ::GetWindowRect(m_hWnd, &taskbarRect);
+ OffsetRect(&rebarRect, -taskbarRect.left, -taskbarRect.top);
+
+ /* Calculate the difference of size of the taskbar and the rebar */
+ SIZE margins;
+ margins.cx = taskbarRect.right - taskbarRect.left - rebarRect.right +
rebarRect.left;
+ margins.cy = taskbarRect.bottom - taskbarRect.top - rebarRect.bottom +
rebarRect.top;
+
+ /* Calculate the new size of the rebar and make it resize, then change the new
taskbar size */
+ switch (m_Position)
+ {
+ case ABE_TOP:
+ rebarRect.bottom = rebarRect.top + pRect->bottom - pRect->top -
margins.cy;
+ ::SendMessageW(m_Rebar, RB_SIZETORECT, RBSTR_CHANGERECT,
(LPARAM)&rebarRect);
+ pRect->bottom = pRect->top + rebarRect.bottom - rebarRect.top +
margins.cy;
+ break;
+ case ABE_BOTTOM:
+ rebarRect.top = rebarRect.bottom - (pRect->bottom - pRect->top -
margins.cy);
+ ::SendMessageW(m_Rebar, RB_SIZETORECT, RBSTR_CHANGERECT,
(LPARAM)&rebarRect);
+ ERR("rebarRect: %d, %d, %d,%d\n", rebarRect.top, rebarRect.left,
rebarRect.right, rebarRect.bottom);
+ pRect->top = pRect->bottom - (rebarRect.bottom - rebarRect.top +
margins.cy);
+ break;
+ case ABE_LEFT:
+ case ABE_RIGHT:
+ /* FIXME: what to do here? */
+ break;
+ }
+
+ CalculateValidSize(m_Position, pRect);
}
void PopupStartMenu()
@@ -1917,13 +1960,6 @@
If it was somehow destroyed just create a new tray window. */
if (m_hWnd != NULL && IsWindow())
{
- if (!IsWindowVisible())
- {
- CheckTrayWndPosition();
-
- ShowWindow(SW_SHOW);
- }
-
return S_OK;
}
@@ -1943,6 +1979,12 @@
if (!Create(NULL, rcWnd, NULL, dwStyle, dwExStyle))
return E_FAIL;
+
+ /* Align all controls on the tray window */
+ AlignControls(NULL);
+
+ /* Move the tray window to the right position and resize it if necessary */
+ CheckTrayWndPosition();
return S_OK;
}
@@ -1974,14 +2016,6 @@
BOOL STDMETHODCALLTYPE IsHorizontal()
{
return IsPosHorizontal();
- }
-
- HFONT STDMETHODCALLTYPE GetCaptionFonts(OUT HFONT *phBoldCaption OPTIONAL)
- {
- if (phBoldCaption != NULL)
- *phBoldCaption = m_StartButton.GetFont();
-
- return m_CaptionFont;
}
BOOL STDMETHODCALLTYPE Lock(IN BOOL bLock)
@@ -2027,6 +2061,8 @@
}
}
SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE
| SWP_NOZORDER | SWP_NOOWNERZORDER);
+ ResizeWorkArea();
+ ApplyClipping(TRUE);
}
return bPrevLock;
@@ -2047,25 +2083,6 @@
SetWindowTheme(m_hWnd, L"TaskBar", NULL);
- InterlockedIncrement(&TrayWndCount);
-
- if (m_CaptionFont == NULL)
- {
- NONCLIENTMETRICS ncm;
-
- /* Get the system fonts, we use the caption font,
- always bold, though. */
- ncm.cbSize = sizeof(ncm);
- if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm,
FALSE))
- {
- if (m_CaptionFont == NULL)
- {
- ncm.lfCaptionFont.lfWeight = FW_NORMAL;
- m_CaptionFont = CreateFontIndirect(&ncm.lfCaptionFont);
- }
- }
- }
-
/* Create the Start button */
m_StartButton.Create(m_hWnd);
@@ -2076,23 +2093,14 @@
HBITMAP hbmBanner = LoadBitmapW(hExplorerInstance,
MAKEINTRESOURCEW(IDB_STARTMENU));
m_StartMenuPopup = CreateStartMenu(this, &m_StartMenuBand, hbmBanner, 0);
- /* Load the tray band site */
+ /* Create the tray band site and its rebar */
m_TrayBandSite = CreateTrayBandSite(this, &m_Rebar, &m_TaskSwitch);
SetWindowTheme(m_Rebar, L"TaskBar", NULL);
/* Create the tray notification window */
m_TrayNotify = CreateTrayNotifyWnd(this, HideClock, &m_TrayNotifyInstance);
- if (UpdateNonClientMetrics())
- {
- SetWindowsFont();
- }
-
- /* Move the tray window to the right position and resize it if necessary */
- CheckTrayWndPosition();
-
- /* Align all controls on the tray window */
- AlignControls(NULL);
+ UpdateFonts();
InitShellServices(&m_ShellServices);
@@ -2141,6 +2149,19 @@
return TRUE;
}
+ LRESULT OnSettingChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
+ {
+ if (wParam == SPI_SETNONCLIENTMETRICS)
+ {
+ SendMessage(m_TaskSwitch, uMsg, wParam, lParam);
+ UpdateFonts();
+ AlignControls(NULL);
+ CheckTrayWndPosition();
+ }
+
+ return 0;
+ }
+
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
HDC hdc = (HDC) wParam;
@@ -2156,14 +2177,8 @@
LRESULT OnDisplayChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
- /* Load the saved tray window settings */
- RegLoadSettings();
-
/* Move the tray window to the right position and resize it if necessary */
CheckTrayWndPosition();
-
- /* Align all controls on the tray window */
- AlignControls(NULL);
return TRUE;
}
@@ -2285,37 +2300,7 @@
if (!Locked)
{
- /* Get the rect of the rebar */
- RECT rebarRect, taskbarRect;
- ::GetWindowRect(m_Rebar, &rebarRect);
- ::GetWindowRect(m_hWnd, &taskbarRect);
- OffsetRect(&rebarRect, -taskbarRect.left, -taskbarRect.top);
-
- /* Calculate the difference of size of the taskbar and the rebar */
- SIZE margins;
- margins.cx = taskbarRect.right - taskbarRect.left - rebarRect.right +
rebarRect.left;
- margins.cy = taskbarRect.bottom - taskbarRect.top - rebarRect.bottom +
rebarRect.top;
-
- /* Calculate the new size of the rebar and make it resize, then change the
new taskbar size */
- switch (m_Position)
- {
- case ABE_TOP:
- rebarRect.bottom = rebarRect.top + pRect->bottom - pRect->top -
margins.cy;
- ::SendMessageW(m_Rebar, RB_SIZETORECT, RBSTR_CHANGERECT,
(LPARAM)&rebarRect);
- pRect->bottom = pRect->top + rebarRect.bottom - rebarRect.top +
margins.cy;
- break;
- case ABE_BOTTOM:
- rebarRect.top = rebarRect.bottom - (pRect->bottom - pRect->top -
margins.cy);
- ::SendMessageW(m_Rebar, RB_SIZETORECT, RBSTR_CHANGERECT,
(LPARAM)&rebarRect);
- pRect->top = pRect->bottom - (rebarRect.bottom - rebarRect.top +
margins.cy);
- break;
- case ABE_LEFT:
- case ABE_RIGHT:
- /* FIXME: what to do here? */
- break;
- }
-
- CalculateValidSize(m_Position, pRect);
+ FitToRebar(pRect);
}
else
{
@@ -2341,7 +2326,6 @@
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
RECT rcClient;
- InvalidateRect(NULL, TRUE);
if (wParam == SIZE_RESTORED && lParam == 0)
{
ResizeWorkArea();
@@ -2782,6 +2766,7 @@
lParam = Msg.lParam;
}
MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
+ MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChanged)
NOTIFY_CODE_HANDLER(RBN_AUTOSIZE, OnRebarAutoSize) // Doesn't quite work ;P
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
MESSAGE_HANDLER(WM_SIZE, OnSize)