From 33fa3b619885fcfcb4e25a1103e3406f53f9ce5a Mon Sep 17 00:00:00 2001 From: ozone10 Date: Thu, 15 Jul 2021 21:29:27 +0200 Subject: [PATCH] Edge Enhancement Make changing edge color dynamic. Apply color on docking panels caption, color button. Add status bar separators. Fix #10166, close #10167 --- PowerEditor/src/NppDarkMode.cpp | 35 ++++++++++++++--- PowerEditor/src/NppDarkMode.h | 2 + .../WinControls/ColourPicker/ColourPicker.cpp | 7 ++-- .../WinControls/DockingWnd/DockingCont.cpp | 36 +++++++++--------- .../src/WinControls/StatusBar/StatusBar.cpp | 34 +++++++++++------ PowerEditor/src/WinControls/TabBar/TabBar.cpp | 38 +++++++++---------- 6 files changed, 94 insertions(+), 58 deletions(-) diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index ce2ed20ba..6bbd69685 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -42,9 +42,9 @@ namespace NppDarkMode void change(const Colors& colors) { - ::DeleteObject(background); + ::DeleteObject(background); ::DeleteObject(softerBackground); - ::DeleteObject(hotBackground); + ::DeleteObject(hotBackground); ::DeleteObject(pureBackground); ::DeleteObject(errorBackground); @@ -56,6 +56,28 @@ namespace NppDarkMode } }; + struct Pens + { + HPEN edgePen = nullptr; + + Pens(const Colors& colors) + : edgePen(::CreatePen(PS_SOLID, 1, colors.edge)) + {} + + ~Pens() + { + ::DeleteObject(edgePen); edgePen = nullptr; + } + + void change(const Colors& colors) + { + ::DeleteObject(edgePen); + + edgePen = ::CreatePen(PS_SOLID, 1, colors.edge); + } + + }; + // black (default) static const Colors darkColors{ HEXRGB(0x202020), // background @@ -172,16 +194,19 @@ namespace NppDarkMode { Colors _colors; Brushes _brushes; + Pens _pens; Theme(const Colors& colors) : _colors(colors) , _brushes(colors) + , _pens(colors) {} void change(const Colors& colors) { _colors = colors; _brushes.change(colors); + _pens.change(colors); } }; @@ -345,6 +370,8 @@ namespace NppDarkMode HBRUSH getDarkerBackgroundBrush() { return getTheme()._brushes.pureBackground; } HBRUSH getErrorBackgroundBrush() { return getTheme()._brushes.errorBackground; } + HPEN getEdgePen() { return getTheme()._pens.edgePen; } + void setBackgroundColor(COLORREF c) { Colors clrs = getTheme()._colors; @@ -1100,9 +1127,7 @@ namespace NppDarkMode HDC hdc = BeginPaint(hWnd, &ps); FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush()); - static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor()); - - HPEN holdPen = (HPEN)SelectObject(hdc, g_hpen); + auto holdPen = static_cast(::SelectObject(hdc, NppDarkMode::getEdgePen())); HRGN holdClip = CreateRectRgn(0, 0, 0, 0); if (1 != GetClipRgn(hdc, holdClip)) diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index 6505efe44..6f513b409 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -81,6 +81,8 @@ namespace NppDarkMode HBRUSH getHotBackgroundBrush(); HBRUSH getErrorBackgroundBrush(); + HPEN getEdgePen(); + void setBackgroundColor(COLORREF c); void setSofterBackgroundColor(COLORREF c); void setHotBackgroundColor(COLORREF c); diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp index 28df80178..5426da460 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp @@ -13,13 +13,12 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . + #include #include #include "ColourPicker.h" #include "ColourPopup.h" - - - +#include "NppDarkMode.h" void ColourPicker::init(HINSTANCE hInst, HWND parent) { @@ -60,7 +59,9 @@ void ColourPicker::drawBackground(HDC hDC) getClientRect(rc); hbrush = ::CreateSolidBrush(_currentColour); HGDIOBJ oldObj = ::SelectObject(hDC, hbrush); + auto holdPen = static_cast(::SelectObject(hDC, NppDarkMode::getEdgePen())); ::Rectangle(hDC, 0, 0, rc.right, rc.bottom); + ::SelectObject(hDC, holdPen); ::SelectObject(hDC, oldObj); //FillRect(hDC, &rc, hbrush); ::DeleteObject(hbrush); diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp index ddf108377..861d14147 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp @@ -20,7 +20,6 @@ #include "SplitterContainer.h" #include "ToolTip.h" #include "Parameters.h" -#include "NppDarkMode.h" #include "localization.h" using namespace std; @@ -138,7 +137,7 @@ tTbData* DockingCont::createToolbar(tTbData data) } // set attached child window - ::SetParent(pTbData->hClient, ::GetDlgItem(_hSelf, IDC_CLIENT_TAB)); + ::SetParent(pTbData->hClient, ::GetDlgItem(_hSelf, IDC_CLIENT_TAB)); // set names for captions and view toolbar viewToolbar(pTbData); @@ -345,21 +344,21 @@ LRESULT DockingCont::runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPAR { if (_isMouseClose == FALSE) { - // keep sure that button is still down and within caption - if ((wParam == MK_LBUTTON) && (isInRect(hwnd, pt.x, pt.y) == posCaption)) - { - _dragFromTab = FALSE; - NotifyParent(DMM_MOVE); - _isMouseDown = FALSE; - } - else - { - _isMouseDown = FALSE; - } + // keep sure that button is still down and within caption + if ((wParam == MK_LBUTTON) && (isInRect(hwnd, pt.x, pt.y) == posCaption)) + { + _dragFromTab = FALSE; + NotifyParent(DMM_MOVE); + _isMouseDown = FALSE; + } + else + { + _isMouseDown = FALSE; + } } else { - BOOL isMouseOver = _isMouseOver; + BOOL isMouseOver = _isMouseOver; _isMouseOver = (isInRect(hwnd, pt.x, pt.y) == posClose ? TRUE : FALSE); // if state is changed draw new @@ -456,7 +455,9 @@ void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) // begin with paint ::SetBkMode(hDc, TRANSPARENT); - if (NppDarkMode::isEnabled()) + auto holdPen = static_cast(::SelectObject(hDc, NppDarkMode::isEnabled() ? NppDarkMode::getEdgePen() : hPen)); + + if (NppDarkMode::isEnabled()) { bgbrush = ::CreateSolidBrush(_isActive ? NppDarkMode::getSofterBackgroundColor() : NppDarkMode::getBackgroundColor()); SetTextColor(hDc, NppDarkMode::getTextColor()); @@ -566,6 +567,7 @@ void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) ::SelectObject(hDc, hOldFont); ::DeleteObject(hFont); } + ::SelectObject(hDc, holdPen); ::DeleteObject(hPen); ::DeleteObject(bgbrush); @@ -700,9 +702,7 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l UINT id = ::GetDlgCtrlID(hwnd); - static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor()); - - HPEN holdPen = (HPEN)SelectObject(hdc, g_hpen); + auto holdPen = static_cast(::SelectObject(hdc, NppDarkMode::getEdgePen())); HRGN holdClip = CreateRectRgn(0, 0, 0, 0); if (1 != GetClipRgn(hdc, holdClip)) diff --git a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp index 5abe5c224..d3fe1ad50 100644 --- a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp +++ b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include #include #include @@ -29,15 +28,12 @@ //#define IDC_STATUSBAR 789 - enum { defaultPartWidth = 5, }; - - StatusBar::~StatusBar() { delete[] _lpParts; @@ -49,6 +45,7 @@ void StatusBar::init(HINSTANCE, HWND) assert(false and "should never be called"); } + struct StatusBarSubclassInfo { HTHEME hTheme = nullptr; @@ -77,8 +74,10 @@ struct StatusBarSubclassInfo } }; + constexpr UINT_PTR g_statusBarSubclassID = 42; + LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { UNREFERENCED_PARAMETER(uIdSubclass); @@ -121,6 +120,8 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); + auto holdPen = static_cast(::SelectObject(hdc, NppDarkMode::getEdgePen())); + HFONT holdFont = (HFONT)::SelectObject(hdc, NppParameters::getInstance().getDefaultUIFont()); RECT rcClient; @@ -140,6 +141,15 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l continue; } + if (nParts > 2) //to not apply on status bar in find dialog + { + POINT edges[] = { + {rcPart.right - 2, rcPart.top + 1}, + {rcPart.right - 2, rcPart.bottom - 3} + }; + Polyline(hdc, edges, _countof(edges)); + } + RECT rcDivider = { rcPart.right - borders.vertical, rcPart.top, rcPart.right, rcPart.bottom }; DWORD cchText = 0; @@ -198,6 +208,7 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l } ::SelectObject(hdc, holdFont); + ::SelectObject(hdc, holdPen); EndPaint(hWnd, &ps); return FALSE; @@ -214,10 +225,11 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l return DefSubclassProc(hWnd, uMsg, wParam, lParam); } + void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts) { Window::init(hInst, hPere); - InitCommonControls(); + InitCommonControls(); // _hSelf = CreateStatusWindow(WS_CHILD | WS_CLIPSIBLINGS, NULL, _hParent, IDC_STATUSBAR); _hSelf = ::CreateWindowEx( @@ -240,7 +252,7 @@ void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts) if (nbParts > 0) _partWidthArray.resize(nbParts, defaultPartWidth); - // Allocate an array for holding the right edge coordinates. + // Allocate an array for holding the right edge coordinates. if (_partWidthArray.size()) _lpParts = new int[_partWidthArray.size()]; @@ -285,17 +297,17 @@ int StatusBar::getHeight() const void StatusBar::adjustParts(int clientWidth) { - // Calculate the right edge coordinate for each part, and - // copy the coordinates to the array. - int nWidth = std::max(clientWidth - 20, 0); + // Calculate the right edge coordinate for each part, and + // copy the coordinates to the array. + int nWidth = std::max(clientWidth - 20, 0); for (int i = static_cast(_partWidthArray.size()) - 1; i >= 0; i--) - { + { _lpParts[i] = nWidth; nWidth -= _partWidthArray[i]; } - // Tell the status bar to create the window parts. + // Tell the status bar to create the window parts. ::SendMessage(_hSelf, SB_SETPARTS, _partWidthArray.size(), reinterpret_cast(_lpParts)); } diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 4acda4873..5cc45948c 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - - #include #include "TabBar.h" #include "Parameters.h" @@ -58,7 +56,7 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin int multiLine = isMultiLine ? TCS_MULTILINE : 0; int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ - TCS_FOCUSNEVER | TCS_TABS | WS_TABSTOP | vertical | multiLine; + TCS_FOCUSNEVER | TCS_TABS | WS_TABSTOP | vertical | multiLine; _hSelf = ::CreateWindowEx( 0, @@ -127,12 +125,12 @@ void TabBar::setFont(const TCHAR *fontName, int fontSize) ::DeleteObject(_hFont); _hFont = ::CreateFont( fontSize, 0, - (_isVertical) ? 900:0, - (_isVertical) ? 900:0, - FW_NORMAL, - 0, 0, 0, 0, - 0, 0, 0, 0, - fontName); + (_isVertical) ? 900:0, + (_isVertical) ? 900:0, + FW_NORMAL, + 0, 0, 0, 0, + 0, 0, 0, 0, + fontName); if (_hFont) ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), 0); } @@ -606,20 +604,20 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara } } - ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); + ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); int currentTabOn = static_cast(::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0)); if (wParam == 2) return TRUE; - if (_doDragNDrop) - { + if (_doDragNDrop) + { _mightBeDragging = true; - } + } notify(NM_CLICK, currentTabOn); - return TRUE; + return TRUE; } case WM_RBUTTONDOWN : //rightclick selects tab aswell @@ -673,13 +671,13 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara if (_isDragging) { - exchangeItemData(p); + exchangeItemData(p); // Get cursor position of "Screen" // For using the function "WindowFromPoint" afterward!!! ::GetCursorPos(&_draggingPoint); draggingCursor(_draggingPoint); - return TRUE; + return TRUE; } else { @@ -898,9 +896,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara UINT id = ::GetDlgCtrlID(hwnd); - static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor()); - - HPEN holdPen = (HPEN)SelectObject(hdc, g_hpen); + auto holdPen = static_cast(::SelectObject(hdc, NppDarkMode::getEdgePen())); HRGN holdClip = CreateRectRgn(0, 0, 0, 0); if (1 != GetClipRgn(hdc, holdClip)) @@ -1276,8 +1272,8 @@ void TabBarPlus::draggingCursor(POINT screenPoint) } else if (isPointInParentZone(screenPoint)) ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_INTERDIT_TAB))); - else // drag out of application - ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_OUT_TAB))); + else // drag out of application + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_OUT_TAB))); } }