diff --git a/src/DarkMode/DarkMode.cpp b/src/DarkMode/DarkMode.cpp index 5f64060ba..56644d3ca 100644 --- a/src/DarkMode/DarkMode.cpp +++ b/src/DarkMode/DarkMode.cpp @@ -46,7 +46,7 @@ extern "C" DWORD GetWindowsBuildNumber(LPDWORD major, LPDWORD minor) if (minor) { *minor = _minor; } return _dwWindowsBuildNumber; } - +// ============================================================================ #ifdef D_NP3_WIN10_DARK_MODE @@ -117,6 +117,7 @@ enum WINDOWCOMPOSITIONATTRIB { WCA_USEDARKMODECOLORS = 26, WCA_LAST = 27 }; +// ============================================================================ struct WINDOWCOMPOSITIONATTRIBDATA { @@ -124,6 +125,7 @@ struct WINDOWCOMPOSITIONATTRIBDATA { PVOID pvData; SIZE_T cbData; }; +// ============================================================================ using fnSetWindowCompositionAttribute = BOOL(WINAPI *)(HWND hWnd, WINDOWCOMPOSITIONATTRIBDATA *); // 1809 17763 diff --git a/src/Dialogs.c b/src/Dialogs.c index cd29e5263..fb2a09094 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -831,7 +831,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam // --- Rich Edit Control --- //SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETBKGNDCOLOR, 0, (LPARAM)GetBackgroundColor(hwnd)); - SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETBKGNDCOLOR, 0, (LPARAM)GetSysColor(COLOR_3DFACE)); + SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETBKGNDCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNFACE)); SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SHOWSCROLLBAR, SB_VERT, TRUE); SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETZOOM, 1, 1); //, 0, 0); // OFF diff --git a/src/Edit.c b/src/Edit.c index 09247a66d..5474186e4 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5597,8 +5597,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd,UINT umsg,WPARAM wParam // the global static Find/Replace data structure SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); - SetDialogIconNP3(hwnd); + SetDialogIconNP3(hwnd); InitWindowCommon(hwnd, true); #ifdef D_NP3_WIN10_DARK_MODE @@ -5921,7 +5921,8 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd,UINT umsg,WPARAM wParam case WM_CTLCOLOREDIT: case WM_CTLCOLORLISTBOX: { - if (sg_pefrData->bMarkOccurences) { + if (sg_pefrData->bMarkOccurences) + { HWND hCheck = (HWND)lParam; HDC hDC = (HDC)wParam; diff --git a/src/Helpers.h b/src/Helpers.h index 21bcdba35..3fb11a4c7 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -202,6 +202,15 @@ inline int SetModeBkColor(const HDC hdc, const bool bDarkMode) { #endif } +inline COLORREF GetModeBkColor(const bool bDarkMode) { +#ifdef D_NP3_WIN10_DARK_MODE + return bDarkMode ? Settings2.DarkModeBkgColor : (COLORREF)( + IsWindows10OrGreater() ? GetSysColor(COLOR_WINDOW) : GetSysColor(COLOR_BTNFACE)); +#else + return (COLORREF)GetSysColor(COLOR_BTNFACE); +#endif +} + inline int SetModeTextColor(const HDC hdc, const bool bDarkMode) { #ifdef D_NP3_WIN10_DARK_MODE return SetTextColor(hdc, bDarkMode ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_BTNTEXT)); @@ -210,19 +219,12 @@ inline int SetModeTextColor(const HDC hdc, const bool bDarkMode) { #endif } -inline COLORREF GetModeWndBkColor(const bool bDarkMode) { +inline COLORREF GetModeTextColor(const bool bDarkMode) { #ifdef D_NP3_WIN10_DARK_MODE - return bDarkMode ? Settings2.DarkModeBkgColor : (COLORREF)GetSysColor(COLOR_WINDOW); + return bDarkMode ? Settings2.DarkModeTxtColor : (COLORREF)( + IsWindows10OrGreater() ? GetSysColor(COLOR_WINDOWTEXT) : GetSysColor(COLOR_BTNTEXT)); #else - return (COLORREF)GetSysColor(COLOR_WINDOW); -#endif -} - -inline COLORREF GetModeWndTextColor(const bool bDarkMode) { -#ifdef D_NP3_WIN10_DARK_MODE - return bDarkMode ? Settings2.DarkModeTxtColor : (COLORREF)GetSysColor(COLOR_WINDOWTEXT); -#else - return (COLORREF)GetSysColor(COLOR_WINDOWTEXT); + return (COLORREF)GetSysColor(COLOR_BTNTEXT); #endif } @@ -238,6 +240,13 @@ inline INT_PTR SetDarkModeCtlColors(const HDC hdc) { return (INT_PTR)Globals.hbrDarkModeBkgBrush; } +inline void SetModeCtlColors(HWND hwnd, const bool bDarkMode) { + HDC const hdc = GetDC(hwnd); + SetBkColor(hdc, bDarkMode ? Settings2.DarkModeBkgColor : GetSysColor(COLOR_BTNFACE)); + SetTextColor(hdc, bDarkMode ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_BTNTEXT)); + ReleaseDC(hwnd, hdc); +} + #endif // ---------------------------------------------------------------------------- diff --git a/src/Notepad3.c b/src/Notepad3.c index 81a30b0cd..b56e4c2f9 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -446,7 +446,9 @@ static int msgcmp(void* mqc1, void* mqc2) // ---------------------------------------------------------------------------- #define _MQ_IMMEDIATE (2 * USER_TIMER_MINIMUM - 1) -#define _MQ_FAST (4 * USER_TIMER_MINIMUM) +#define _MQ_FAST (USER_TIMER_MINIMUM << 2) +#define _MQ_STD (USER_TIMER_MINIMUM << 3) +#define _MQ_LAZY (USER_TIMER_MINIMUM << 4) #define _MQ_ms(T) ((T) / USER_TIMER_MINIMUM) static void _MQ_AppendCmd(CmdMessageQueue_t* const pMsgQCmd, int cycles) @@ -564,27 +566,34 @@ static void _UpdateToolbarDelayed(); // static bool s_DocNeedSaving = false; // dirty-flag -bool GetDocModified() -{ - return (SciCall_GetModify() || s_DocNeedSaving); -} - static void SetSaveNeeded() { - if (!GetDocModified()) { - if (IsWindow(Globals.hwndDlgFindReplace)) { - PostWMCommand(Globals.hwndDlgFindReplace, IDC_DOC_MODIFIED); - } + if (!s_DocNeedSaving) { + s_DocNeedSaving = true; + UpdateTitleBar(); } - s_DocNeedSaving = true; UpdateToolbar(); + + if (IsWindow(Globals.hwndDlgFindReplace)) { + PostWMCommand(Globals.hwndDlgFindReplace, IDC_DOC_MODIFIED); + } } void SetSavePoint() { + if (SciCall_GetModify()) { + SciCall_SetSavePoint(); + } s_DocNeedSaving = false; - if (SciCall_GetModify()) { SciCall_SetSavePoint(); } UpdateToolbar(); + UpdateTitleBar(); +} + +inline static bool GetDocModified() { + if (SciCall_GetModify() && !s_DocNeedSaving) { + SetSaveNeeded(); + } + return s_DocNeedSaving; } //============================================================================== @@ -2494,7 +2503,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) // hInstance, // handle to application instance // NULL); // no window creation data - InitWindowCommon(Globals.hwndToolbar, true); + InitWindowCommon(Globals.hwndToolbar, true); // (!) themed = true : glow effects #ifdef D_NP3_WIN10_DARK_MODE if (IsDarkModeSupported()) { @@ -2662,7 +2671,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) Globals.hwndRebar = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, dwReBarStyle, 0,0,0,0,hwnd,(HMENU)IDC_REBAR,hInstance,NULL); - // No Theme = false(!) ~ you cannot change a toolbar's color when a visual style is active + // Theme = false (!) ~ you cannot change a toolbar's color when a visual style is active InitWindowCommon(Globals.hwndRebar, false); #ifdef D_NP3_WIN10_DARK_MODE @@ -2689,18 +2698,19 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) rbBand.fStyle = s_bIsAppThemed ? (RBBS_FIXEDSIZE | RBBS_CHILDEDGE) : RBBS_FIXEDSIZE; rbBand.hbmBack = NULL; rbBand.lpText = L"Toolbar"; - rbBand.clrFore = GetModeWndTextColor(UseDarkMode()); - rbBand.clrBack = GetModeWndBkColor(UseDarkMode()); + rbBand.clrFore = GetModeTextColor(UseDarkMode()); + rbBand.clrBack = GetModeBkColor(UseDarkMode()); rbBand.hwndChild = Globals.hwndToolbar; rbBand.cxMinChild = (rc.right - rc.left) * COUNTOF(s_tbbMainWnd); - rbBand.cyMinChild = (rc.bottom - rc.top) + 2 * rc.top; + rbBand.cyMinChild = (rc.bottom - rc.top) + (2 * rc.top); rbBand.cx = 0; SendMessage(Globals.hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); SetWindowPos(Globals.hwndRebar, NULL, 0, 0, 0, 0, SWP_NOZORDER); GetWindowRect(Globals.hwndRebar, &rc); s_cyReBar = (rc.bottom - rc.top); - s_cyReBarFrame = s_bIsAppThemed ? 0 : 2; + s_cyReBarFrame = s_bIsAppThemed ? 0 : 2; // (!) frame color is same as INITIAL title-bar ??? + // ------------------- // Create Statusbar @@ -2721,13 +2731,15 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) //~ hInstance, // handle to application instance //~ NULL); // no window creation data - InitWindowCommon(Globals.hwndStatus, true); + InitWindowCommon(Globals.hwndStatus, true); // (!) themed = true : resize grip #ifdef D_NP3_WIN10_DARK_MODE if (IsDarkModeSupported()) { AllowDarkModeForWindow(Globals.hwndStatus, CheckDarkModeEnabled()); } + //SetModeCtlColors(Globals.hwndStatus, UseDarkMode()); #endif + } @@ -2821,6 +2833,7 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam ,LPARAM lParam) AllowDarkModeForWindow(hwnd, UseDarkMode()); RefreshTitleBarThemeColor(hwnd); #endif + UpdateTitleBar(); // reinitialize edit frame _HandleEditWndFrame(); @@ -2830,7 +2843,6 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam ,LPARAM lParam) Style_ResetCurrentLexer(Globals.hwndEdit); - UpdateTitleBar(); Sci_RedrawScrollbars(); SetMenu(hwnd, (Settings.ShowMenubar ? Globals.hMainMenu : NULL)); @@ -2870,7 +2882,6 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam ,LPARAM lParam) LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) { UNUSED(hwnd); - UNUSED(lParam); if (wParam == SIZE_MINIMIZED) { return FALSE; } @@ -2882,14 +2893,16 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) if (Settings.ShowToolbar) { -/* SendMessage(Globals.hwndToolbar,WM_SIZE,0,0); - RECT rc; - GetWindowRect(Globals.hwndToolbar,&rc); - y = (rc.bottom - rc.top); - cy -= (rc.bottom - rc.top);*/ + //~SendMessage(Globals.hwndToolbar,WM_SIZE,0,0); + //~RECT rc; + //~GetWindowRect(Globals.hwndToolbar,&rc); + //~y = (rc.bottom - rc.top); + //~cy -= (rc.bottom - rc.top); + + //~SendMessage(Globals.hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc); - //SendMessage(Globals.hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc); SetWindowPos(Globals.hwndRebar, NULL, 0, 0, LOWORD(lParam), s_cyReBar, SWP_NOZORDER); + // the ReBar automatically sets the correct height // calling SetWindowPos() with the height of one toolbar button // causes the control not to temporarily use the whole client area @@ -2923,6 +2936,7 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) UpdateToolbar(); UpdateStatusbar(true); UpdateMarginWidth(); + UpdateTitleBar(); return FALSE; } @@ -2954,10 +2968,12 @@ LRESULT MsgDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam) #ifdef D_NP3_WIN10_DARK_MODE - HWND const hWndItem = pDIS->hwndItem; + SetModeBkColor(hdc, UseDarkMode()); + SetModeTextColor(hdc, UseDarkMode()); if (UseDarkMode()) { // overpaint part frames + HWND const hWndItem = pDIS->hwndItem; int const bdh = GetSystemMetrics(SM_CYFRAME); HDC const hdcFrm = GetWindowDC(hWndItem); RECT rcf = rc; @@ -2971,8 +2987,6 @@ LRESULT MsgDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam) FrameRect(hdcFrm, &rcf, GetSysColorBrush(COLOR_3DDKSHADOW)); ReleaseDC(hWndItem, hdcFrm); } - SetModeBkColor(hdc, UseDarkMode()); - SetModeTextColor(hdc, UseDarkMode()); #endif @@ -8619,7 +8633,7 @@ void MarkAllOccurrences(int delay, bool bForceClear) // void UpdateToolbar() { - _DelayUpdateToolbar(_MQ_FAST); + _DelayUpdateToolbar(_MQ_LAZY); } @@ -8627,8 +8641,6 @@ void UpdateToolbar() static void _UpdateToolbarDelayed() { - UpdateTitleBar(); // (!) DocModified or Undo/Redo - if (!Settings.ShowToolbar) { return; } EnableTool(Globals.hwndToolbar, IDT_FILE_ADDTOFAV, StrIsNotEmpty(Globals.CurrentFile)); @@ -8879,7 +8891,7 @@ static double _InterpMultiSelectionTinyExpr(te_xint_t* piExprError) // void UpdateStatusbar(bool bForceRedraw) { - _DelayUpdateStatusbar(_MQ_FAST, bForceRedraw); + _DelayUpdateStatusbar(_MQ_STD, bForceRedraw); } //============================================================================= diff --git a/src/Notepad3.h b/src/Notepad3.h index 1bdba3347..60cb556b9 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -115,7 +115,7 @@ void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode); void ShowNotifyIcon(HWND hwnd, bool bAdd); void SetNotifyIconTitle(HWND hwnd); void InstallFileWatching(LPCWSTR lpszFile); -bool GetDocModified(); +//bool GetDocModified(); void SetSavePoint(); void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); void CALLBACK PasteBoardTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); diff --git a/src/Styles.c b/src/Styles.c index 888897ec6..bfbca42d7 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -1398,7 +1398,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) // caret fore if (!Style_StrGetColor(pCurrentStandard->Styles[STY_CARET].szValue, FOREGROUND_LAYER, &rgb, false)) { - rgb = GetModeWndTextColor(UseDarkMode()); + rgb = GetModeTextColor(UseDarkMode()); } else { WCHAR wch[32] = { L'\0' }; @@ -1815,11 +1815,11 @@ void Style_SetBookmark(HWND hwnd, bool bShowMargin) // void Style_SetMargin(HWND hwnd, LPCWSTR lpszStyle) // iStyle = STYLE_LINENUMBER { - COLORREF clrBack = UseDarkMode() ? Settings2.DarkModeBkgColor : GetSysColor(COLOR_3DFACE); - Style_SetStyles(hwnd, STYLE_LINENUMBER, lpszStyle, false); // line numbers + + COLORREF clrBack = GetModeBkColor(UseDarkMode()); if (!Style_StrGetColor(lpszStyle, BACKGROUND_LAYER, &clrBack, false)) { - clrBack = UseDarkMode() ? (clrBack + RGB(0x10, 0x10, 0x10)) : GetSysColor(COLOR_3DFACE); + clrBack = UseDarkMode() ? (clrBack + RGB(0x10, 0x10, 0x10)) : GetSysColor(COLOR_BTNFACE); } SciCall_StyleSetBack(STYLE_LINENUMBER, clrBack); SciCall_SetMarginBackN(MARGIN_SCI_LINENUM, clrBack); @@ -3221,6 +3221,7 @@ static INT_PTR CALLBACK Style_FontDialogHook( #ifdef D_NP3_WIN10_DARK_MODE + //#define IDCS_COMBOX1 0x3E8 #define IDCS_STRKOUT 0x410 #define IDCS_UNDERLN 0x411 #define IDCS_EFFECTS 0x430 @@ -3238,7 +3239,7 @@ static INT_PTR CALLBACK Style_FontDialogHook( } } #endif - + const CHOOSEFONT* const pChooseFont = ((CHOOSEFONT*)lParam); if (pChooseFont->lCustData) { @@ -3798,12 +3799,7 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle, bool bInitDefault SciCall_StyleSetFore(iStyle, dColor); } else if (bInitDefault) { -#ifdef D_NP3_WIN10_DARK_MODE - COLORREF const rgbFore = UseDarkMode() ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_WINDOWTEXT); - SciCall_StyleSetFore(iStyle, rgbFore); -#else - SciCall_StyleSetFore(iStyle, GetSysColor(COLOR_WINDOWTEXT)); // default text color -#endif + SciCall_StyleSetFore(iStyle, GetModeTextColor(UseDarkMode())); } else { // fallback: SCI default Style_StrGetColor(lpszStyle, FOREGROUND_LAYER, &dColor, true); @@ -3815,12 +3811,7 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle, bool bInitDefault SciCall_StyleSetBack(iStyle, dColor); } else if (bInitDefault) { -#ifdef D_NP3_WIN10_DARK_MODE - COLORREF const rgbBack = UseDarkMode() ? Settings2.DarkModeBkgColor : GetSysColor(COLOR_WINDOW); - SciCall_StyleSetBack(iStyle, rgbBack); -#else - SciCall_StyleSetBack(iStyle, GetSysColor(COLOR_WINDOW)); // default window color -#endif + SciCall_StyleSetBack(iStyle, GetModeBkColor(UseDarkMode())); } else { // fallback: SCI default Style_StrGetColor(lpszStyle, BACKGROUND_LAYER, &dColor, true); SciCall_StyleSetBack(iStyle, dColor);