Skip to content

Commit

Permalink
Introduce a flat status bar without separator lines. (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka authored Jul 13, 2024
1 parent e11cdc8 commit 56ea106
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 113 deletions.
145 changes: 145 additions & 0 deletions Src/BasicFlatStatusBar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* @file BasicFlatStatusBar.cpp
*
* @brief Implementation of the CBasicFlatStatusBar class
*/

#include "StdAfx.h"
#include "BasicFlatStatusBar.h"
#include "RoundedRectWithShadow.h"

BEGIN_MESSAGE_MAP(CBasicFlatStatusBar, CStatusBar)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
ON_WM_SETCURSOR()
END_MESSAGE_MAP()

CBasicFlatStatusBar::CBasicFlatStatusBar() : m_bMouseTracking(false), m_nTrackingPane(-1)
{
}

CPoint CBasicFlatStatusBar::GetClientCursorPos() const
{
CPoint pt;
GetCursorPos(&pt);
ScreenToClient(&pt);
return pt;
}

int CBasicFlatStatusBar::GetIndexFromPoint(const CPoint& pt) const
{
CStatusBarCtrl& ctrl = GetStatusBarCtrl();
int parts[32];
const int nParts = ctrl.GetParts(32, parts);
for (int i = 0; i < nParts; i++)
{
const unsigned style = GetPaneStyle(i);
CRect rcPart;
ctrl.GetRect(i, &rcPart);
if (PtInRect(rcPart, pt))
return i;
}
return -1;
}

COLORREF CBasicFlatStatusBar::LightenColor(COLORREF color, double amount)
{
BYTE red = GetRValue(color);
BYTE green = GetGValue(color);
BYTE blue = GetBValue(color);
red = static_cast<BYTE>(red + (255 - red) * amount);
green = static_cast<BYTE>(green + (255 - green) * amount);
blue = static_cast<BYTE>(blue + (255 - blue) * amount);
return RGB(red, green, blue);
}

void CBasicFlatStatusBar::OnPaint()
{
const COLORREF clr3DFace = GetSysColor(COLOR_3DFACE);
const COLORREF clr3DFaceLight = LightenColor(clr3DFace, 0.5);
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CStatusBarCtrl& ctrl = GetStatusBarCtrl();
int parts[32];
const int nParts = ctrl.GetParts(32, parts);
dc.FillSolidRect(&rect, clr3DFace);
dc.SetTextColor(GetSysColor(COLOR_BTNTEXT));
dc.SetBkMode(TRANSPARENT);
CFont* pFont = GetFont();
CFont* pOldFont = pFont ? dc.SelectObject(pFont) : nullptr;
const int radius = MulDiv (3, dc.GetDeviceCaps (LOGPIXELSY), 72);
for (int i = 0; i < nParts; i++)
{
const unsigned style = GetPaneStyle(i);
CRect rcPart;
ctrl.GetRect(i, &rcPart);
if (m_bMouseTracking && (style & SBPS_CLICKABLE) != 0 && i == m_nTrackingPane)
DrawRoundedRectWithShadow(dc.m_hDC, rcPart.left, rcPart.top, rcPart.Width(), rcPart.Height(), radius, 0,
clr3DFaceLight, clr3DFace, clr3DFace);
const bool disabled = (style & SBPS_DISABLED) != 0;
if (!disabled)
{
CRect rcText = rcPart;
rcText.left += radius;
CString text = ctrl.GetText(i);
text.Replace(_T("\t"), _T(" "));
dc.DrawText(text, &rcText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
}
if (pOldFont)
dc.SelectObject(pOldFont);
}

BOOL CBasicFlatStatusBar::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
GetClientRect(&rc);
pDC->FillSolidRect(&rc, ::GetSysColor(COLOR_BTNFACE));
return TRUE;
}

void CBasicFlatStatusBar::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bMouseTracking)
{
TRACKMOUSEEVENT tme = { sizeof TRACKMOUSEEVENT, TME_LEAVE, m_hWnd };
TrackMouseEvent(&tme);
m_bMouseTracking = true;
}
int i = GetIndexFromPoint(GetClientCursorPos());
for (int pane : {i, m_nTrackingPane})
{
if (pane >= 0 && (GetPaneStyle(pane) & SBPS_CLICKABLE) != 0)
{
CRect rcPart;
GetStatusBarCtrl().GetRect(pane, &rcPart);
InvalidateRect(&rcPart, false);
}
}
m_nTrackingPane = i;
}

void CBasicFlatStatusBar::OnMouseLeave()
{
TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT), TME_LEAVE | TME_CANCEL, m_hWnd };
TrackMouseEvent(&tme);
m_bMouseTracking = false;
if (m_nTrackingPane >= 0 && (GetPaneStyle(m_nTrackingPane) & SBPS_CLICKABLE) != 0)
{
CRect rcPart;
GetStatusBarCtrl().GetRect(m_nTrackingPane, &rcPart);
InvalidateRect(&rcPart, false);
}
m_nTrackingPane = -1;
}

BOOL CBasicFlatStatusBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
const int i = GetIndexFromPoint(GetClientCursorPos());
LPCTSTR icon = (i >= 0 && (GetPaneStyle(i) & SBPS_CLICKABLE) != 0) ? IDC_HAND : IDC_ARROW;
::SetCursor(::LoadCursor(nullptr, icon));
return TRUE;
}
33 changes: 33 additions & 0 deletions Src/BasicFlatStatusBar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file BasicFlatStatusBar.h
*
* @brief Declaration file for CBasicFlatStatusBar
*
*/
#pragma once

#include <afxwin.h>
#include <afxext.h>

#define SBPS_CLICKABLE 0x10000000

class CBasicFlatStatusBar : public CStatusBar
{
public:
CBasicFlatStatusBar();

protected:
CPoint CBasicFlatStatusBar::GetClientCursorPos() const;
int GetIndexFromPoint(const CPoint& pt) const;
static COLORREF LightenColor(COLORREF color, double amount);

afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnMouseLeave();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
DECLARE_MESSAGE_MAP()

bool m_bMouseTracking;
int m_nTrackingPane;
};
10 changes: 5 additions & 5 deletions Src/DirFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
const int lpx = CClientDC(this).GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); };
m_wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_NOBORDERS, 0);
m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, 0, pointToPixel(COMPMETHOD_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, 0, pointToPixel(FILTER_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_LEFT_RO, ID_STATUS_LEFTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_MIDDLE_RO, ID_STATUS_MIDDLEDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_RIGHT_RO, ID_STATUS_RIGHTDIR_RO, 0, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_COMPMETHOD, ID_STATUS_FILTER, SBPS_CLICKABLE, pointToPixel(COMPMETHOD_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_FILTER, ID_STATUS_FILTER, SBPS_CLICKABLE, pointToPixel(FILTER_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_LEFT_RO, ID_STATUS_LEFTDIR_RO, SBPS_CLICKABLE, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_MIDDLE_RO, ID_STATUS_MIDDLEDIR_RO, SBPS_CLICKABLE, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneInfo(PANE_RIGHT_RO, ID_STATUS_RIGHTDIR_RO, SBPS_CLICKABLE, pointToPixel(RO_PANEL_WIDTH));
m_wndStatusBar.SetPaneText(PANE_LEFT_RO, sText.c_str(), TRUE);
m_wndStatusBar.SetPaneText(PANE_MIDDLE_RO, sText.c_str(), TRUE);
m_wndStatusBar.SetPaneText(PANE_RIGHT_RO, sText.c_str(), TRUE);
Expand Down
4 changes: 2 additions & 2 deletions Src/DirFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#pragma once

#include "EditorFilepathBar.h"
#include "DirStatusBar.h"
#include "BasicFlatStatusBar.h"
#include "MergeFrameCommon.h"

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -37,7 +37,7 @@ class CDirFrame : public CMergeFrameCommon
void SetStatus(const tchar_t* szStatus);
void SetCompareMethodStatusDisplay(int nCompMethod);
void SetFilterStatusDisplay(const tchar_t* szFilter);
CDirStatusBar m_wndStatusBar;
CBasicFlatStatusBar m_wndStatusBar;
IHeaderBar * GetHeaderInterface();
void UpdateResources();

Expand Down
23 changes: 0 additions & 23 deletions Src/DirStatusBar.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions Src/DirStatusBar.h

This file was deleted.

6 changes: 3 additions & 3 deletions Src/HexMergeFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void CHexMergeFrame::CreateHexWndStatusBar(CStatusBar &wndStatusBar, CWnd *pwndP
auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); };
wndStatusBar.Create(pwndPane, WS_CHILD|WS_VISIBLE);
wndStatusBar.SetIndicators(0, 3);
wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH, 0);
wndStatusBar.SetPaneInfo(1, 0, 0, pointToPixel(60));
wndStatusBar.SetPaneInfo(2, 0, 0, pointToPixel(60));
wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH | SBPS_CLICKABLE, 0);
wndStatusBar.SetPaneInfo(1, 0, SBPS_CLICKABLE, pointToPixel(60));
wndStatusBar.SetPaneInfo(2, 0, SBPS_CLICKABLE, pointToPixel(60));
wndStatusBar.SetParent(this);
wndStatusBar.SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
Expand Down
3 changes: 2 additions & 1 deletion Src/HexMergeFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "SplitterWndEx.h"
#include "EditorFilepathBar.h"
#include "BasicFlatStatusBar.h"
#include "MergeFrameCommon.h"

#define HEKSEDIT_INTERFACE_VERSION 2
Expand Down Expand Up @@ -44,7 +45,7 @@ class CHexMergeFrame : public CMergeFrameCommon
protected:
CSplitterWndEx m_wndSplitter;
CEditorFilePathBar m_wndFilePathBar;
CStatusBar m_wndStatusBar[3];
CBasicFlatStatusBar m_wndStatusBar[3];
SCROLLINFO m_HScrollInfo[3];
SCROLLINFO m_VScrollInfo[3];
// Overrides
Expand Down
3 changes: 2 additions & 1 deletion Src/ImgMergeFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FileLocation.h"
#include "MergeFrameCommon.h"
#include "FileTransform.h"
#include "BasicFlatStatusBar.h"

struct IDirDoc;

Expand Down Expand Up @@ -80,7 +81,7 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc
// Attributes
protected:
CEditorFilePathBar m_wndFilePathBar;
CStatusBar m_wndStatusBar[3];
CBasicFlatStatusBar m_wndStatusBar[3];
// Overrides
public:
// ClassWizard generated virtual function overrides
Expand Down
3 changes: 2 additions & 1 deletion Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <memory>
#include <optional>
#include "MDITabBar.h"
#include "BasicFlatStatusBar.h"
#include "PathContext.h"
#include "OptionsDef.h"
#include "OptionsMgr.h"
Expand Down Expand Up @@ -246,7 +247,7 @@ class CMainFrame : public CMDIFrameWnd
// Implementation data
protected:
// control bar embedded members
CStatusBar m_wndStatusBar;
CBasicFlatStatusBar m_wndStatusBar;
CReBar m_wndReBar;
CToolBar m_wndToolBar;
CMDITabBar m_wndTabBar;
Expand Down
4 changes: 2 additions & 2 deletions Src/Merge.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@
</ClCompile>
<ClCompile Include="AboutDlg.cpp">
</ClCompile>
<ClCompile Include="BasicFlatStatusBar.cpp" />
<ClCompile Include="ClipboardHistory.cpp" />
<ClCompile Include="Common\cio.cpp">
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
Expand All @@ -934,7 +935,6 @@
</ClCompile>
<ClCompile Include="DirAdditionalPropertiesDlg.cpp" />
<ClCompile Include="DirSelectFilesDlg.cpp" />
<ClCompile Include="DirStatusBar.cpp" />
<ClCompile Include="DirWatcher.cpp">
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>
Expand Down Expand Up @@ -1446,6 +1446,7 @@
<ClInclude Include="..\Version.h" />
<ClInclude Include="7zCommon.h" />
<ClInclude Include="AboutDlg.h" />
<ClInclude Include="BasicFlatStatusBar.h" />
<ClInclude Include="ClipboardHistory.h" />
<ClInclude Include="Common\cio.h" />
<ClInclude Include="Common\DebugNew.h" />
Expand All @@ -1458,7 +1459,6 @@
<ClInclude Include="Common\Bitmap.h" />
<ClInclude Include="charsets.h" />
<ClInclude Include="DirAdditionalPropertiesDlg.h" />
<ClInclude Include="DirStatusBar.h" />
<ClInclude Include="DirWatcher.h" />
<ClInclude Include="DirItemIterator.h" />
<ClInclude Include="DirSelectFilesDlg.h" />
Expand Down
Loading

0 comments on commit 56ea106

Please sign in to comment.