From b7ad639fa6e576db2df04ce72e2b69f409f386bd Mon Sep 17 00:00:00 2001 From: zufuliu Date: Sat, 28 Jul 2018 20:58:57 +0800 Subject: [PATCH] Add "Rendering Technology" Settings menu to switch between GDI and Direct2D. See https://github.com/XhmikosR/notepad2-mod/issues/121, https://github.com/XhmikosR/notepad2-mod/pull/122, https://github.com/rizonesoft/Notepad3/issues/191 and https://github.com/XhmikosR/notepad2-mod/issues/228. --- src/Edit.c | 2 ++ src/Notepad2.c | 18 ++++++++++++++++++ src/Notepad2.rc | 7 +++++++ src/resource.h | 5 +++++ 4 files changed, 32 insertions(+) diff --git a/src/Edit.c b/src/Edit.c index 1e104ce766..e1bb3b8806 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -51,6 +51,7 @@ extern int iLineEndings[3]; extern BOOL bFixLineEndings; extern BOOL bAutoStripBlanks; +extern int iRenderingTechnology; // Default Codepage and Character Set extern int iDefaultCodePage; //extern int iDefaultCharSet; @@ -82,6 +83,7 @@ HWND EditCreate(HWND hwndParent) { g_hInstance, NULL); + SendMessage(hwnd, SCI_SETTECHNOLOGY, iRenderingTechnology, 0); SendMessage(hwnd, SCI_SETCODEPAGE, iDefaultCodePage, 0); SendMessage(hwnd, SCI_SETEOLMODE, SC_EOL_CRLF, 0); SendMessage(hwnd, SCI_SETPASTECONVERTENDINGS, 1, 0); diff --git a/src/Notepad2.c b/src/Notepad2.c index db62e76bb6..ecbbc61ddb 100644 --- a/src/Notepad2.c +++ b/src/Notepad2.c @@ -178,6 +178,7 @@ int iEscFunction; BOOL bAlwaysOnTop; BOOL bMinimizeToTray; BOOL bTransparentMode; +int iRenderingTechnology; BOOL bShowToolbar; BOOL bShowStatusbar; @@ -1421,6 +1422,8 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) { hwndEdit = EditCreate(hwnd); InitScintillaHandle(hwndEdit); + iRenderingTechnology = (int)SendMessage(hwndEdit, SCI_GETTECHNOLOGY, 0, 0); + SendMessage(hwndEdit, SCI_SETZOOM, iZoomLevel, 0); // Tabs SendMessage(hwndEdit, SCI_SETUSETABS, !bTabsAsSpaces, 0); @@ -2249,6 +2252,9 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) { CheckCmd(hmenu, IDM_VIEW_TRANSPARENT, bTransparentMode && i); EnableCmd(hmenu, IDM_VIEW_TRANSPARENT, i); + i = IDM_SET_RENDER_TECH_DEFAULT + iRenderingTechnology; + CheckMenuRadioItem(hmenu, IDM_SET_RENDER_TECH_DEFAULT, IDM_SET_RENDER_TECH_D2DDC, i, MF_BYCOMMAND); + CheckCmd(hmenu, IDM_VIEW_NOSAVERECENT, bSaveRecentFiles); CheckCmd(hmenu, IDM_VIEW_NOSAVEFINDREPL, bSaveFindReplace); CheckCmd(hmenu, IDM_VIEW_SAVEBEFORERUNNINGTOOLS, bSaveBeforeRunningTools); @@ -4122,6 +4128,14 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) { SetWindowTransparentMode(hwnd, bTransparentMode); break; + case IDM_SET_RENDER_TECH_DEFAULT: + case IDM_SET_RENDER_TECH_D2D: + case IDM_SET_RENDER_TECH_D2DRETAIN: + case IDM_SET_RENDER_TECH_D2DDC: + SendMessage(hwndEdit, SCI_SETTECHNOLOGY, LOWORD(wParam) - IDM_SET_RENDER_TECH_DEFAULT, 0); + iRenderingTechnology = (int)SendMessage(hwndEdit, SCI_GETTECHNOLOGY, 0, 0); + break; + case IDM_VIEW_SHOWFILENAMEONLY: iPathNameFormat = 0; lstrcpy(szTitleExcerpt, L""); @@ -5333,6 +5347,9 @@ void LoadSettings(void) { bMinimizeToTray = IniSectionGetBool(pIniSection, L"MinimizeToTray", 0); bTransparentMode = IniSectionGetBool(pIniSection, L"TransparentMode", 0); + iRenderingTechnology = IniSectionGetInt(pIniSection, L"RenderingTechnology", 0); + iRenderingTechnology = clamp_i(iRenderingTechnology, SC_TECHNOLOGY_DEFAULT, SC_TECHNOLOGY_DIRECTWRITEDC); + IniSectionGetString(pIniSection, L"ToolbarButtons", L"", tchToolbarButtons, COUNTOF(tchToolbarButtons)); bShowToolbar = IniSectionGetBool(pIniSection, L"ShowToolbar", 1); @@ -5562,6 +5579,7 @@ void SaveSettings(BOOL bSaveSettingsNow) { IniSectionSetBool(pIniSection, L"AlwaysOnTop", bAlwaysOnTop); IniSectionSetBool(pIniSection, L"MinimizeToTray", bMinimizeToTray); IniSectionSetBool(pIniSection, L"TransparentMode", bTransparentMode); + IniSectionSetInt(pIniSection, L"RenderingTechnology", iRenderingTechnology); Toolbar_GetButtons(hwndToolbar, IDT_FILE_NEW, tchToolbarButtons, COUNTOF(tchToolbarButtons)); IniSectionSetString(pIniSection, L"ToolbarButtons", tchToolbarButtons); IniSectionSetBool(pIniSection, L"ShowToolbar", bShowToolbar); diff --git a/src/Notepad2.rc b/src/Notepad2.rc index 88f1894b32..306ebe5c93 100644 --- a/src/Notepad2.rc +++ b/src/Notepad2.rc @@ -454,6 +454,13 @@ BEGIN MENUITEM "&Always On Top\tAlt+Shift+T", IDM_VIEW_ALWAYSONTOP MENUITEM "Minimi&ze to Tray", IDM_VIEW_MINTOTRAY MENUITEM "Transparent &Mode\tCtrl+0", IDM_VIEW_TRANSPARENT + POPUP "Rendering Technology" + BEGIN + MENUITEM "Default GDI", IDM_SET_RENDER_TECH_DEFAULT + MENUITEM "Direct2D", IDM_SET_RENDER_TECH_D2D + MENUITEM "Direct2D Retain", IDM_SET_RENDER_TECH_D2DRETAIN + MENUITEM "Direct2D GDI DC", IDM_SET_RENDER_TECH_D2DDC + END MENUITEM SEPARATOR MENUITEM "Single &File Instance", IDM_VIEW_SINGLEFILEINSTANCE MENUITEM "File &Change Notification...\tAlt+F5", IDM_VIEW_CHANGENOTIFY diff --git a/src/resource.h b/src/resource.h index 9cb363e134..e811c5d3da 100644 --- a/src/resource.h +++ b/src/resource.h @@ -403,6 +403,11 @@ #define IDM_VIEW_AUTOCWITHDOCWORDS 40466 #define IDM_VIEW_FOLD_CURRENT 40467 // Alt+C #define IDM_VIEW_SHOWCALLTIPS 40047 +#define IDM_SET_RENDER_TECH_DEFAULT 40048 +#define IDM_SET_RENDER_TECH_D2D 40049 +#define IDM_SET_RENDER_TECH_D2DRETAIN 40050 +#define IDM_SET_RENDER_TECH_D2DDC 40051 + #define IDM_LANG_DEFAULT 41000 #define IDM_LANG_NULL 41060