diff --git a/src/Notepad3.c b/src/Notepad3.c index 7b4ed2710..7f08ecdc8 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1220,6 +1220,26 @@ WININFO GetWinInfoByFlag(const int flagsPos) } +//============================================================================= +// +// _StatusCalcPaneSizeh() +// +static SIZE _StatusCalcPaneSize(HWND hwnd, LPCWSTR lpsz) { + HDC const hdc = GetDC(hwnd); + HGDIOBJ const hfont = (HGDIOBJ)SendMessage(hwnd, WM_GETFONT, 0, 0); + HGDIOBJ const hfold = SelectObject(hdc, hfont); + int const mmode = SetMapMode(hdc, MM_TEXT); + + SIZE size = { 0L, 0L }; + GetTextExtentPoint32(hdc, lpsz, (int)StringCchLenW(lpsz, 0), &size); + + SetMapMode(hdc, mmode); + SelectObject(hdc, hfold); + ReleaseDC(hwnd, hdc); + + return size; +} + //============================================================================= // @@ -1715,6 +1735,11 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case WM_ENDSESSION: return MsgEndSession(hwnd, umsg, wParam, lParam); + case WM_SYSCOLORCHANGE: + // update Scintilla colors + SendMessage(Globals.hwndEdit, WM_SYSCOLORCHANGE, wParam, lParam); + // [[FallThrough]] + // Reinitialize theme-dependent values and resize windows case WM_THEMECHANGED: return MsgThemeChanged(hwnd, wParam, lParam); @@ -1725,18 +1750,12 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case WM_SIZE: return MsgSize(hwnd, wParam, lParam); - // update Scintilla colors - case WM_SYSCOLORCHANGE: - Style_ResetCurrentLexer(Globals.hwndEdit); - UpdateUI(); - SendMessage(Globals.hwndEdit, WM_SYSCOLORCHANGE, wParam, lParam); - break; #ifdef D_NP3_WIN10_DARK_MODE case WM_SETTINGCHANGE: { if (IsColorSchemeChangeMessage(lParam)) { RefreshTitleBarThemeColor(hwnd); - SendMessage(Globals.hwndEdit, WM_THEMECHANGED, 0, 0); + PostMessage(Globals.hwndEdit, WM_THEMECHANGED, 0, 0); } } break; @@ -2738,11 +2757,11 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) s_cyReBar = (rc.bottom - rc.top); s_cyReBarFrame = s_bIsAppThemed ? 0 : 2; // (!) frame color is same as INITIAL title-bar ??? - // ------------------- // Create Statusbar // ------------------- - DWORD const dwStatusbarStyle = SBT_NOBORDERS | (Settings.ShowStatusbar ? (WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE) : (WS_CHILD | WS_CLIPSIBLINGS)); + DWORD const dwStatusbarStyle = SBT_NOBORDERS | SBT_OWNERDRAW | + (Settings.ShowStatusbar ? (WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE) : (WS_CHILD | WS_CLIPSIBLINGS)); if (Globals.hwndStatus) { DestroyWindow(Globals.hwndStatus); @@ -2750,15 +2769,15 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) //~Globals.hwndStatus = CreateStatusWindow(dwStatusbarStyle, NULL, hwnd, IDC_STATUSBAR); Globals.hwndStatus = CreateWindowEx( - WS_EX_COMPOSITED, // => double-buffering avoids flickering - STATUSCLASSNAME, // name of status bar class - (PCTSTR)NULL, // no text when first created - dwStatusbarStyle, // creates a visible child window - 0, 0, 0, 0, // ignores size and position - hwnd, // handle to parent window - (HMENU)IDC_STATUSBAR, // child window identifier - hInstance, // handle to application instance - NULL); // no window creation data + WS_EX_COMPOSITED, // => double-buffering avoids flickering + STATUSCLASSNAME, // name of status bar class + (PCTSTR)NULL, // no text when first created + dwStatusbarStyle, // creates a visible child window + 0, 0, 0, 0, // ignores size and position + hwnd, // handle to parent window + (HMENU)IDC_STATUSBAR, // child window identifier + hInstance, // handle to application instance + NULL); // no window creation data InitWindowCommon(Globals.hwndStatus, true); // (!) themed = true : resize grip @@ -6412,7 +6431,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_COPYPATHNAME: { - WCHAR *pszCopy; WCHAR tchUntitled[32] = { L'\0' }; if (StrIsNotEmpty(Paths.CurrentFile)) { @@ -8629,28 +8647,6 @@ static void _UpdateToolbarDelayed() -//============================================================================= -// -// _StatusCalcPaneWidth() -// -static LONG _StatusCalcPaneWidth(HWND hwnd, LPCWSTR lpsz) -{ - HDC const hdc = GetDC(hwnd); - HGDIOBJ const hfont = (HGDIOBJ)SendMessage(hwnd, WM_GETFONT, 0, 0); - HGDIOBJ const hfold = SelectObject(hdc, hfont); - int const mmode = SetMapMode(hdc, MM_TEXT); - - SIZE size = { 0L, 0L }; - GetTextExtentPoint32(hdc, lpsz, (int)StringCchLenW(lpsz,0), &size); - - SetMapMode(hdc, mmode); - SelectObject(hdc, hfold); - ReleaseDC(hwnd, hdc); - - return (size.cx + 8L); -} - - //============================================================================= // // _CalculateStatusbarSections @@ -8676,7 +8672,8 @@ static void _CalculateStatusbarSections(int vSectionWidth[], sectionTxt_t tchSt for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { if (g_iStatusbarVisible[i]) { if (g_iStatusbarWidthSpec[i] == 0) { // dynamic optimized - vSectionWidth[i] = _StatusCalcPaneWidth(Globals.hwndStatus, tchStatusBar[i]); + SIZE const size = _StatusCalcPaneSize(Globals.hwndStatus, tchStatusBar[i]); + vSectionWidth[i] = (size.cx + 8L); } else if (g_iStatusbarWidthSpec[i] < -1) { // fixed pixel count vSectionWidth[i] = -(g_iStatusbarWidthSpec[i]); } @@ -8704,7 +8701,8 @@ static void _CalculateStatusbarSections(int vSectionWidth[], sectionTxt_t tchSt int iTotalMinWidth = 0; for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { if (bIsPropSection[i]) { - int const iMinWidth = _StatusCalcPaneWidth(Globals.hwndStatus, tchStatusBar[i]); + SIZE const size = _StatusCalcPaneSize(Globals.hwndStatus, tchStatusBar[i]); + int const iMinWidth = (size.cx + 8L); vMinWidth[i] = iMinWidth; iTotalMinWidth += iMinWidth; } @@ -9281,8 +9279,10 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) Settings.ShowStatusbar = false; } - SendMessage(Globals.hwndStatus, SB_SETPARTS, (WPARAM)cnt, (LPARAM)aStatusbarSections); + SIZE const size = _StatusCalcPaneSize(Globals.hwndStatus, L"X"); + SendMessage(Globals.hwndStatus, SB_SETMINHEIGHT, MAKEWPARAM(size.cy + 2, 0), 0); + SendMessage(Globals.hwndStatus, SB_SETPARTS, (WPARAM)cnt, (LPARAM)aStatusbarSections); cnt = 0; for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { int const id = g_vSBSOrder[i]; @@ -9290,6 +9290,8 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) StatusSetText(Globals.hwndStatus, cnt++, tchStatusBar[id]); } } + + PostMessage(Globals.hwndStatus, WM_SIZE, 0, 0); } // --------------------------------------------------------------------------