From ec5ed25b70902e573f8413bf16ebcbe3534f7b9c Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Tue, 3 Jan 2023 19:27:49 +0100 Subject: [PATCH 1/3] +chg: move DefaultWindowPosition to Window section (deprecated: Settings2 section) (cherry picked from commit d5ae772ea5693caba02617069c243c35ac8f2f5b) --- src/Config/Config.cpp | 54 +++++++++++++++++++++---------------------- src/Notepad3.c | 29 +++++++++++++++++------ src/TypeDefs.h | 4 ++-- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index c58dfb83c..7c57bbf5c 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1140,6 +1140,8 @@ extern "C" bool CreateIniFile(const HPATHL hini_pth, DWORD* pdwFileSize_out) // void LoadSettings() { + WCHAR tchKeyName[MIDSZ_BUFFER] = { L'\0' }; + CFG_VERSION const _ver = Path_IsEmpty(Paths.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE; auto* const pPathBuffer = (wchar_t*)AllocMem(PATHLONG_MAX_CCH * sizeof(wchar_t), HEAP_ZERO_MEMORY); @@ -1364,12 +1366,11 @@ void LoadSettings() StrgReset(Settings2.HyperlinkShellExURLCmdLnArgs, pPathBuffer); const static WCHAR *const allowedVerbs[7] = { L"edit", L"explore", L"find", L"open", L"print", L"properties", L"runas" }; - WCHAR cfgVerb[MICRO_BUFFER] = { L'\0' }; Settings2.HyperlinkFileProtocolVerb[0] = L'\0'; - IniSectionGetStringNoQuotes(IniSecSettings2, L"HyperlinkFileProtocolVerb", L"", cfgVerb, COUNTOF(cfgVerb)); + IniSectionGetStringNoQuotes(IniSecSettings2, L"HyperlinkFileProtocolVerb", L"", tchKeyName, COUNTOF(tchKeyName)); for (auto allowedVerb : allowedVerbs) { - if (StrStr(cfgVerb, allowedVerb)) { - StringCchCopy(Settings2.HyperlinkFileProtocolVerb, COUNTOF(Settings2.HyperlinkFileProtocolVerb), cfgVerb); + if (StrStr(tchKeyName, allowedVerb)) { + StringCchCopy(Settings2.HyperlinkFileProtocolVerb, COUNTOF(Settings2.HyperlinkFileProtocolVerb), tchKeyName); break; } } @@ -1378,11 +1379,10 @@ void LoadSettings() unsigned int iValue = 0; WCHAR color[32] = { L'\0' }; - WCHAR wchBuffer[MIDSZ_BUFFER] = { L'\0' }; StringCchPrintf(color, COUNTOF(color), L"%#08x", rgbDarkBkgColorRef); - IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeBkgColor", color, wchBuffer, COUNTOF(wchBuffer)); - if (swscanf_s(wchBuffer, L"%x", &iValue) == 1) { + IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeBkgColor", color, tchKeyName, COUNTOF(tchKeyName)); + if (swscanf_s(tchKeyName, L"%x", &iValue) == 1) { Settings2.DarkModeBkgColor = RGB((iValue & 0xFF0000) >> 16, (iValue & 0xFF00) >> 8, iValue & 0xFF); } else { Settings2.DarkModeBkgColor = rgbDarkBkgColorRef; @@ -1397,8 +1397,8 @@ void LoadSettings() Globals.hbrDarkModeBkgBrush = CreateSolidBrush(Settings2.DarkModeBkgColor); StringCchPrintf(color, COUNTOF(color), L"%#08x", rgbDarkBtnFcColorRef); - IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeBtnFaceColor", color, wchBuffer, COUNTOF(wchBuffer)); - if (swscanf_s(wchBuffer, L"%x", &iValue) == 1) { + IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeBtnFaceColor", color, tchKeyName, COUNTOF(tchKeyName)); + if (swscanf_s(tchKeyName, L"%x", &iValue) == 1) { Settings2.DarkModeBtnFaceColor = RGB((iValue & 0xFF0000) >> 16, (iValue & 0xFF00) >> 8, iValue & 0xFF); } else { Settings2.DarkModeBtnFaceColor = rgbDarkBtnFcColorRef; @@ -1406,8 +1406,8 @@ void LoadSettings() Globals.hbrDarkModeBtnFcBrush = CreateSolidBrush(Settings2.DarkModeBtnFaceColor); StringCchPrintf(color, COUNTOF(color), L"%#08x", rgbDarkTxtColorRef); - IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeTxtColor", color, wchBuffer, COUNTOF(wchBuffer)); - if (swscanf_s(wchBuffer, L"%x", &iValue) == 1) { + IniSectionGetStringNoQuotes(IniSecSettings2, L"DarkModeTxtColor", color, tchKeyName, COUNTOF(tchKeyName)); + if (swscanf_s(tchKeyName, L"%x", &iValue) == 1) { Settings2.DarkModeTxtColor = RGB((iValue & 0xFF0000) >> 16, (iValue & 0xFF00) >> 8, iValue & 0xFF); } else { Settings2.DarkModeTxtColor = rgbDarkTxtColorRef; @@ -1590,9 +1590,8 @@ void LoadSettings() } Settings.PrintZoom = clampi(iPrintZoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL); - WCHAR localeInfo[SMALL_BUFFER]; - GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, COUNTOF(localeInfo)); - LONG const _margin = (localeInfo[0] == L'0') ? 2000L : 1000L; // Metric system. L'1' is US System + GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, tchKeyName, COUNTOF(tchKeyName)); + LONG const _margin = (tchKeyName[0] == L'0') ? 2000L : 1000L; // Metric system. L'1' is US System Defaults.PrintMargin.left = _margin; Settings.PrintMargin.left = clampi(IniSectionGetInt(IniSecSettings, L"PrintMarginLeft", Defaults.PrintMargin.left), 0, 40000); Defaults.PrintMargin.top = _margin; @@ -1674,9 +1673,8 @@ void LoadSettings() const WCHAR *const StatusBar_Section = L"Statusbar Settings"; // -------------------------------------------------------------------------- - WCHAR tchStatusBar[MIDSZ_BUFFER] = { L'\0' }; - IniSectionGetStringNoQuotes(StatusBar_Section, L"VisibleSections", STATUSBAR_DEFAULT_IDS, tchStatusBar, COUNTOF(tchStatusBar)); - ReadVectorFromString(tchStatusBar, s_iStatusbarSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1, false); + IniSectionGetStringNoQuotes(StatusBar_Section, L"VisibleSections", STATUSBAR_DEFAULT_IDS, tchKeyName, COUNTOF(tchKeyName)); + ReadVectorFromString(tchKeyName, s_iStatusbarSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1, false); // cppcheck-suppress useStlAlgorithm for (bool &sbv : g_iStatusbarVisible) { @@ -1692,8 +1690,8 @@ void LoadSettings() } } - IniSectionGetStringNoQuotes(StatusBar_Section, L"SectionWidthSpecs", STATUSBAR_SECTION_WIDTH_SPECS, tchStatusBar, COUNTOF(tchStatusBar)); - ReadVectorFromString(tchStatusBar, g_iStatusbarWidthSpec, STATUS_SECTOR_COUNT, -4096, 4096, 0, false); + IniSectionGetStringNoQuotes(StatusBar_Section, L"SectionWidthSpecs", STATUSBAR_SECTION_WIDTH_SPECS, tchKeyName, COUNTOF(tchKeyName)); + ReadVectorFromString(tchKeyName, g_iStatusbarWidthSpec, STATUS_SECTOR_COUNT, -4096, 4096, 0, false); Globals.bZeroBasedColumnIndex = IniSectionGetBool(StatusBar_Section, L"ZeroBasedColumnIndex", false); Globals.bZeroBasedCharacterCount = IniSectionGetBool(StatusBar_Section, L"ZeroBasedCharacterCount", false); @@ -1731,8 +1729,12 @@ void LoadSettings() // startup window (ignore window position if /p was specified) // -------------------------------------------------------------- - IniSectionGetString(IniSecSettings2, Constants.DefaultWindowPosition, L"", - Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition)); + StringCchPrintf(tchKeyName, COUNTOF(tchKeyName), L"%ix%i " DEF_WIN_POSITION_STRG, ResX, ResY); + if (!IniSectionGetString(IniSecWindow, tchKeyName, L"", + Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition))) { + IniSectionGetString(IniSecSettings2, DEF_WIN_POSITION_STRG, L"", + Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition)); + } if (!Globals.CmdLnFlag_PosParam /*|| g_bStickyWinPos*/) { @@ -1775,13 +1777,11 @@ void LoadSettings() // ------------------------------------------------------------------------ // --- override by resolution specific settings --- - WCHAR tchSciDirectWriteTech[64]; - StringCchPrintf(tchSciDirectWriteTech, COUNTOF(tchSciDirectWriteTech), L"%ix%i RenderingTechnology", ResX, ResY); - Settings.RenderingTechnology = clampi(IniSectionGetInt(IniSecWindow, tchSciDirectWriteTech, Settings.RenderingTechnology), 0, 3); + StringCchPrintf(tchKeyName, COUNTOF(tchKeyName), L"%ix%i RenderingTechnology", ResX, ResY); + Settings.RenderingTechnology = clampi(IniSectionGetInt(IniSecWindow, tchKeyName, Settings.RenderingTechnology), 0, 3); - WCHAR tchSciFontQuality[64]; - StringCchPrintf(tchSciFontQuality, COUNTOF(tchSciFontQuality), L"%ix%i SciFontQuality", ResX, ResY); - Settings2.SciFontQuality = clampi(IniSectionGetInt(IniSecWindow, tchSciFontQuality, Settings2.SciFontQuality), SC_EFF_QUALITY_DEFAULT, SC_EFF_QUALITY_LCD_OPTIMIZED); + StringCchPrintf(tchKeyName, COUNTOF(tchKeyName), L"%ix%i SciFontQuality", ResX, ResY); + Settings2.SciFontQuality = clampi(IniSectionGetInt(IniSecWindow, tchKeyName, Settings2.SciFontQuality), SC_EFF_QUALITY_DEFAULT, SC_EFF_QUALITY_LCD_OPTIMIZED); // ------------------------------------------------------------------------ diff --git a/src/Notepad3.c b/src/Notepad3.c index f98307c11..615fc6aff 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -88,7 +88,6 @@ CONSTANTS_T const Constants = { , L"Window" // Inifile Section "Window" , L"Styles" // Inifile Section "Styles" , L"Suppressed Messages" // Inifile Section "SuppressedMessages" - , L"DefaultWindowPosition" // Strg DefaultWindowPosition }; @@ -1381,9 +1380,13 @@ static WININFO _GetDefaultWinInfoByStrg(HWND hwnd, LPCWSTR strDefaultWinPos) else { wi = wiDef; // overwrite bad defined default position + WCHAR tchScrnDim[64] = { L'\0' }; + StringCchPrintf(tchScrnDim, COUNTOF(tchScrnDim), L"%ix%i " DEF_WIN_POSITION_STRG, + GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)); StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), - WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, wi.max); - IniSectionSetString(Constants.Settings2_Section, Constants.DefaultWindowPosition, Settings2.DefaultWindowPosition); + WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, wi.max); + IniFileSetString(Paths.IniFile, Constants.Window_Section, tchScrnDim, Settings2.DefaultWindowPosition); + IniFileDelete(Paths.IniFile, Constants.Settings2_Section, DEF_WIN_POSITION_STRG, true); } return wi; } @@ -7086,10 +7089,17 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_SAVEASDEFWINPOS: { WININFO const wi = GetMyWindowPlacement(hwnd, NULL, 0); - WCHAR tchDefWinPos[80]; - StringCchPrintf(tchDefWinPos, COUNTOF(tchDefWinPos), WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, (int)wi.max); + StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), + WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, (int)wi.max); if (Globals.bCanSaveIniFile) { - IniFileSetString(Paths.IniFile, Constants.Settings2_Section, Constants.DefaultWindowPosition, tchDefWinPos); + // overwrite bad defined default position + WCHAR tchScrnDim[64] = { L'\0' }; + StringCchPrintf(tchScrnDim, COUNTOF(tchScrnDim), L"%ix%i " DEF_WIN_POSITION_STRG, + GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)); + StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), + WINDOWPOS_STRGFORMAT, wi.x, wi.y, wi.cx, wi.cy, wi.dpi, wi.max); + IniFileSetString(Paths.IniFile, Constants.Window_Section, tchScrnDim, Settings2.DefaultWindowPosition); + IniFileDelete(Paths.IniFile, Constants.Settings2_Section, DEF_WIN_POSITION_STRG, true); } g_DefWinInfo = wi; //~GetWinInfoByFlag(-1); // use current win pos as new default } @@ -7097,7 +7107,12 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_CLEARSAVEDWINPOS: g_DefWinInfo = GetFactoryDefaultWndPos(hwnd, 2); - IniFileDelete(Paths.IniFile, Constants.Settings2_Section, Constants.DefaultWindowPosition, false); + StringCchCopy(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), L""); + WCHAR tchScrnDim[64] = { L'\0' }; + StringCchPrintf(tchScrnDim, COUNTOF(tchScrnDim), L"%ix%i " DEF_WIN_POSITION_STRG, + GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)); + IniFileDelete(Paths.IniFile, Constants.Window_Section, tchScrnDim, true); + IniFileDelete(Paths.IniFile, Constants.Settings2_Section, DEF_WIN_POSITION_STRG, true); break; case CMD_OPENINIFILE: diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 4594cf4c1..4c2f92e97 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -450,13 +450,13 @@ typedef struct CONSTANTS_T { const WCHAR* const Window_Section; const WCHAR* const Styles_Section; const WCHAR* const SectionSuppressedMessages; - const WCHAR* const DefaultWindowPosition; } CONSTANTS_T, *PCONSTANTS_T; extern CONSTANTS_T const Constants; -#define WINDOWPOS_STRGFORMAT L"%i,%i,%i,%i,%i,%i" +#define DEF_WIN_POSITION_STRG L"DefaultWindowPosition" +#define WINDOWPOS_STRGFORMAT L"%i,%i,%i,%i,%i,%i" // ------------------------------------ From ff1f8b2b8df814e7ab924720235fe1699944fc0c Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Wed, 4 Jan 2023 00:55:58 +0100 Subject: [PATCH 2/3] +fix: path to module relative representation --- src/Notepad3.c | 21 +++++++------------- src/PathLib.c | 53 +++++++++++++++++--------------------------------- 2 files changed, 25 insertions(+), 49 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 615fc6aff..a777cea2c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2764,7 +2764,7 @@ bool SelectExternalToolBar(HWND hwnd) if (GetOpenFileNameW(&ofn)) { Path_Sanitize(hfile_pth); - Path_CanonicalizeEx(hfile_pth, Paths.WorkingDirectory); + Path_CanonicalizeEx(hfile_pth, Paths.ModuleDirectory); Path_Reset(g_tchToolbarBitmap, Path_Get(hfile_pth)); Path_RelativeToApp(g_tchToolbarBitmap, true, true, true); if (Globals.bCanSaveIniFile) { @@ -2833,14 +2833,8 @@ bool SelectExternalToolBar(HWND hwnd) // // LoadBitmapFile() // -static HBITMAP LoadBitmapFile(LPCWSTR path) +static HBITMAP LoadBitmapFile(const HPATHL hpath) { - HPATHL hpath = Path_Allocate(path); - if (Path_IsRelative(hpath)) { - Path_GetAppDirectory(hpath); - Path_Append(hpath, path); - } - HBITMAP hbmp = NULL; if (Path_IsExistingFile(hpath)) { @@ -2855,7 +2849,7 @@ static HBITMAP LoadBitmapFile(LPCWSTR path) bDimOK = (bmp.bmWidth >= (height * NUMTOOLBITMAPS)); } if (!bDimOK) { - InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_BITMAP, path, + InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_BITMAP, Path_Get(hpath), (height * NUMTOOLBITMAPS), height, NUMTOOLBITMAPS); if (hbmp) { DeleteObject(hbmp); @@ -2864,10 +2858,9 @@ static HBITMAP LoadBitmapFile(LPCWSTR path) } } else { - InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_LOADFILE, path); + InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_LOADFILE, Path_Get(hpath)); } - Path_Release(hpath); return hbmp; } @@ -2987,7 +2980,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if ((Settings.ToolBarTheme == 2) && Path_IsNotEmpty(g_tchToolbarBitmap)) { HPATHL hfile_pth = Path_Copy(g_tchToolbarBitmap); Path_AbsoluteFromApp(hfile_pth, true); - hbmp = LoadBitmapFile(Path_Get(hfile_pth)); + hbmp = LoadBitmapFile(hfile_pth); if (!hbmp) { Path_Reset(g_tchToolbarBitmap, L""); IniSectionDelete(L"Toolbar Images", L"BitmapDefault", false); @@ -3019,7 +3012,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if ((Settings.ToolBarTheme == 2) && Path_IsNotEmpty(g_tchToolbarBitmapHot)) { HPATHL hfile_pth = Path_Copy(g_tchToolbarBitmapHot); Path_AbsoluteFromApp(hfile_pth, true); - hbmp = Path_IsExistingFile(hfile_pth) ? LoadBitmapFile(Path_Get(hfile_pth)) : NULL; + hbmp = Path_IsExistingFile(hfile_pth) ? LoadBitmapFile(hfile_pth) : NULL; if (!hbmp) { Path_Reset(g_tchToolbarBitmapHot, L""); IniSectionDelete(L"Toolbar Images", L"BitmapHot", false); @@ -3048,7 +3041,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if ((Settings.ToolBarTheme == 2) && Path_IsNotEmpty(g_tchToolbarBitmapDisabled)) { HPATHL hfile_pth = Path_Copy(g_tchToolbarBitmapDisabled); Path_AbsoluteFromApp(hfile_pth, true); - hbmp = Path_IsExistingFile(hfile_pth) ? LoadBitmapFile(Path_Get(hfile_pth)) : NULL; + hbmp = Path_IsExistingFile(hfile_pth) ? LoadBitmapFile(hfile_pth) : NULL; if (!hbmp) { Path_Reset(g_tchToolbarBitmapDisabled, L""); IniSectionDelete(L"Toolbar Images", L"BitmapDisabled", false); diff --git a/src/PathLib.c b/src/PathLib.c index 49a634d3b..9811298f2 100644 --- a/src/PathLib.c +++ b/src/PathLib.c @@ -766,9 +766,7 @@ bool PTHAPI Path_Append(HPATHL hpth_in_out, LPCWSTR more) StringCchCatW(wbuf, cch, more); StrgSanitize(hstr_io); - Path_Canonicalize(hpth_in_out); - - return true; + return Path_Canonicalize(hpth_in_out); } // ---------------------------------------------------------------------------- @@ -1095,14 +1093,13 @@ void PTHAPI Path_GetModuleFilePath(HPATHL hpth_out) { static HPATHL mod_path = NULL; - HSTRINGW hstr = ToHStrgW(hpth_out); - if (!hstr) { + if (!hpth_out) { if (mod_path) { Path_Release(mod_path); mod_path = NULL; } else { - assert(hstr != NULL); + assert(hpth_out != NULL); } return; } @@ -1810,15 +1807,13 @@ bool PTHAPI Path_CanonicalizeEx(HPATHL hpth_in_out, const HPATHL hdir_rel_base) bool res = false; if (!Path_IsEmpty(hdir_rel_base) && _Path_IsRelative(hpth_in_out)) { HPATHL hmod_pth = Path_Copy(hdir_rel_base); - Path_Append(hmod_pth, Path_Get(hpth_in_out)); - res = Path_Canonicalize(hmod_pth); + res = Path_Append(hmod_pth, Path_Get(hpth_in_out)); Path_Swap(hpth_in_out, hmod_pth); Path_Release(hmod_pth); } else { res = Path_Canonicalize(hpth_in_out); } - Path_RemoveBackslash(hpth_in_out); return res; @@ -1927,16 +1922,6 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr bool from_is_dir = (attr_from & FILE_ATTRIBUTE_DIRECTORY); bool to_is_dir = (attr_to & FILE_ATTRIBUTE_DIRECTORY); -#if 0 - // DEBUG - { - Path_Reset(hfrom, L"\\FolderA\\FolderB\\FolderC\\abab"); - //from_is_dir = true; - Path_Reset(hto, L"\\FolderA\\FolderD\\FolderE\\blah"); - //to_is_dir = false; - } -#endif - // ensure comparable paths (no relatives(..\) HPATHL hfrom_cpy = Path_Allocate(PathGet(hfrom)); Path_Canonicalize(hfrom_cpy); @@ -1947,11 +1932,13 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr if (from_is_dir) { HSTRINGW hstr_from = ToHStrgW(hfrom_cpy); StrgTrimRight(hstr_from, L'\\'); + StrgTrimRight(hstr_from, L'/'); StrgCat(hstr_from, L"\\"); } if (to_is_dir) { HSTRINGW hstr_cpy = ToHStrgW(hto_cpy); StrgTrimRight(hstr_cpy, L'\\'); + StrgTrimRight(hstr_cpy, L'/'); StrgCat(hstr_cpy, L"\\"); } @@ -1983,8 +1970,8 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr // back to prev sync point LPCWSTR p = &hfrom_buf[i]; while (p > r) { - if ((*p == L'\\') || (*p == L':')) { - break; + if ((*p == L'\\') || (*p == L'/') || (*p == L':')) { + ++p; break; } --p; } @@ -1993,29 +1980,26 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr // count dirs of from-path reverse to sync point size_t dir_cnt = 0; while (*p != L'\0') { - if ((*p == L'\\')) { - // ignore trailing backslash - if (*(p + 1)) { - ++dir_cnt; - } + if ((*p == L'\\') || (*p == L'/')) { + ++dir_cnt; } ++p; } // prepare buffer for prefix "..\" x dir_cnt - size_t const alloc_add = wcslen(&hto_buf[prefix]) + 1; - size_t const len = (wcslen(PATHPARENT_PREFIX) * dir_cnt) + alloc_add; - LPWSTR const out_buf = StrgWriteAccessBuf(hrecv_str, len); + size_t const alloc_add = wcslen(&hto_buf[prefix]) + 1; + size_t const len = (wcslen(PATHPARENT_PREFIX) * dir_cnt) + alloc_add; + LPWSTR const hrecv_buf = StrgWriteAccessBuf(hrecv_str, len); for (size_t d = 0; d < dir_cnt; ++d) { - StringCchCatW(out_buf, len, PATHPARENT_PREFIX); + StringCchCatW(hrecv_buf, len, PATHPARENT_PREFIX); } //~Path_RemoveBackslash(hpath_in_out); - if (hto_buf[prefix] == L'\\') { + if ((hto_buf[prefix] == L'\\') || (hto_buf[prefix] == L'/')) { ++prefix; } // copy rest of to-path (excluding first seperator) - StringCchCatW(out_buf, len, &hto_buf[prefix]); + StringCchCatW(hrecv_buf, len, &hto_buf[prefix]); } else { Path_Swap(hrecv, hto_cpy); @@ -2230,15 +2214,14 @@ void PTHAPI Path_AbsoluteFromApp(HPATHL hpth_in_out, bool bExpandEnv) if (_Path_IsRelative(htmp_pth)) { Path_GetAppDirectory(hpth_in_out); - Path_Append(hpth_in_out, Path_Get(htmp_pth)); + Path_Append(hpth_in_out, Path_Get(htmp_pth)); // does Path_Canonicalize() } else { Path_Swap(hpth_in_out, htmp_pth); + Path_Canonicalize(hpth_in_out); } Path_Release(htmp_pth); - Path_Canonicalize(hpth_in_out); - // TODO: //if (PathGetDriveNumber(wchResult) != -1) { // CharUpperBuff(wchResult, 1); From 4f992f7aac9be5556f0e334daacec5f3013fb9bd Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Wed, 4 Jan 2023 10:37:41 +0100 Subject: [PATCH 3/3] +rfc: minor refactoring on UpdateUI --- src/Dialogs.c | 4 +-- src/Notepad3.c | 70 ++++++++++++++++++++++++++++---------------------- src/Notepad3.h | 7 +++-- src/PathLib.c | 1 - src/SciCall.h | 16 ++++++++++++ src/Styles.c | 2 +- 6 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index 2886d7c38..21d1ff68a 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -4703,8 +4703,8 @@ void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode) Settings.AlwaysOnTop = true; s_bPrevFullScreenFlag = true; } - SendWMSize(hwnd, NULL); - UpdateToolbar(); + + UpdateUI(hwnd); } diff --git a/src/Notepad3.c b/src/Notepad3.c index a777cea2c..5c1ed3fcd 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -103,9 +103,13 @@ SETTINGS2_T Settings2; FOCUSEDVIEW_T FocusedView; FILEWATCHING_T FileWatching; +// set by InitScintillaHandle() +HWND g_hwndEditWindow = NULL; +HANDLE g_hndlScintilla = NULL; + +// window positioning WININFO g_IniWinInfo = INIT_WININFO; WININFO g_DefWinInfo = INIT_WININFO; -HANDLE g_hndlScintilla = NULL; COLORREF g_colorCustom[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -3334,10 +3338,7 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam,LPARAM lParam) EditUpdateVisibleIndicators(); - UpdateToolbar(); - UpdateStatusbar(true); - UpdateMargins(true); - UpdateUI(); + UpdateUI(hwnd); } UpdateWindowEx(hwnd); @@ -3395,7 +3396,7 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) DeferWindowPos(hdwp,s_hwndEditFrame,NULL,x,y,cx,cy, SWP_NOZORDER | SWP_NOACTIVATE); - DeferWindowPos(hdwp, Globals.hwndEdit, s_hwndEditFrame, + DeferWindowPos(hdwp, g_hwndEditWindow, s_hwndEditFrame, x+s_cxEditFrame,y+s_cyEditFrame, cx-2*s_cxEditFrame,cy-2*s_cyEditFrame, SWP_NOZORDER | SWP_NOACTIVATE); @@ -3407,12 +3408,37 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) UpdateStatusbar(true); UpdateMargins(true); UpdateTitlebar(hwnd); - //~UpdateUI(); + //~UpdateUI(); ~ recursion return FALSE; } +//============================================================================= +// +// UpdateContentArea() +// +void UpdateContentArea() +{ + Sci_ForceNotifyUpdateUI(Globals.hwndMain, IDC_EDIT); +} + + +//============================================================================= +// +// UpdateUI() +// +void UpdateUI(HWND hwnd) +{ + //if (hwnd == Globals.hwndMain) { + // UpdateContentArea() + //} + SendWMSize(hwnd, NULL); + PostMessage(hwnd, WM_NCACTIVATE, FALSE, -1); // (!) + PostMessage(hwnd, WM_NCACTIVATE, TRUE, 0); +} + + //============================================================================= // // MsgDrawItem() - Handles WM_DRAWITEM (needs SBT_OWNERDRAW) @@ -5810,7 +5836,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) SetForegroundWindow(Globals.hwndDlgCustomizeSchemes); } SendWMCommand(Globals.hwndDlgCustomizeSchemes, IDC_SETCURLEXERTV); - UpdateUI(); + UpdateUI(hwnd); break; @@ -5820,7 +5846,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) Style_SetDefaultFont(Globals.hwndEdit, (iLoWParam == IDM_VIEW_FONT)); } UpdateMargins(true); - UpdateUI(); + UpdateUI(hwnd); break; @@ -6248,7 +6274,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_TOOLBAR: Settings.ShowToolbar = !Settings.ShowToolbar; ShowWindow(Globals.hwndRebar, (Settings.ShowToolbar ? SW_SHOW : SW_HIDE)); - SendWMSize(hwnd, NULL); + UpdateUI(hwnd); break; case IDM_VIEW_CUSTOMIZETB: @@ -6258,13 +6284,13 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_TOGGLETB: Settings.ToolBarTheme = (Settings.ToolBarTheme + 1) % 3; CreateBars(hwnd, Globals.hInstance); - UpdateUI(); + UpdateUI(hwnd); break; case IDM_VIEW_LOADTHEMETB: if (SelectExternalToolBar(hwnd)) { CreateBars(hwnd, Globals.hInstance); - UpdateUI(); + UpdateUI(hwnd); } break; @@ -6276,8 +6302,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_STATUSBAR: Settings.ShowStatusbar = !Settings.ShowStatusbar; ShowWindow(Globals.hwndStatus, (Settings.ShowStatusbar ? SW_SHOW : SW_HIDE)); - UpdateStatusbar(Settings.ShowStatusbar); - SendWMSize(hwnd, NULL); + UpdateUI(hwnd); break; @@ -10377,23 +10402,6 @@ void UpdateSaveSettingsCmds() } -//============================================================================= -// -// UpdateUI() -// -void UpdateUI() { - struct SCNotification scn = { 0 }; - scn.nmhdr.hwndFrom = Globals.hwndEdit; - scn.nmhdr.idFrom = IDC_EDIT; - scn.nmhdr.code = SCN_UPDATEUI; - scn.updated = SC_UPDATE_CONTENT; - SendMessage(Globals.hwndMain, WM_NOTIFY, IDC_EDIT, (LPARAM)&scn); - SendWMSize(Globals.hwndMain, NULL); - PostMessage(Globals.hwndMain, WM_NCACTIVATE, FALSE, -1); // (!) - PostMessage(Globals.hwndMain, WM_NCACTIVATE, TRUE, 0); -} - - //============================================================================= // // UndoRedoRecordingStart() diff --git a/src/Notepad3.h b/src/Notepad3.h index 03739217c..5a99ce486 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -127,13 +127,16 @@ void ShowZoomCallTip(); void ShowWrapAroundCallTip(bool forwardSearch); void MarkAllOccurrences(const int delay, const bool bForceClear); -void UpdateUI(); + void UpdateToolbar(); void UpdateStatusbar(const bool bForceRedraw); void UpdateMargins(const bool bForce); void UpdateSaveSettingsCmds(); -void ResetMouseDWellTime(); void UpdateTitlebar(const HWND hwnd); +void UpdateContentArea(); +void UpdateUI(HWND hwnd); + +void ResetMouseDWellTime(); void UndoRedoReset(); LONG BeginUndoActionSelection(); diff --git a/src/PathLib.c b/src/PathLib.c index 9811298f2..41dac7a43 100644 --- a/src/PathLib.c +++ b/src/PathLib.c @@ -1987,7 +1987,6 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr } // prepare buffer for prefix "..\" x dir_cnt - size_t const alloc_add = wcslen(&hto_buf[prefix]) + 1; size_t const len = (wcslen(PATHPARENT_PREFIX) * dir_cnt) + alloc_add; LPWSTR const hrecv_buf = StrgWriteAccessBuf(hrecv_str, len); diff --git a/src/SciCall.h b/src/SciCall.h index ddc842191..e3340056d 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -62,12 +62,16 @@ // Scintilla Window Handle // #if defined(__cplusplus) +extern "C" HWND g_hwndEditWindow; extern "C" HANDLE g_hndlScintilla; #else +extern HWND g_hwndEditWindow; extern HANDLE g_hndlScintilla; #endif + __forceinline void InitScintillaHandle(HWND hwnd) { + g_hwndEditWindow = hwnd; g_hndlScintilla = (HANDLE)SendMessage(hwnd, SCI_GETDIRECTPOINTER, 0, 0); } @@ -933,6 +937,18 @@ inline DocPos Sci_ReplaceTargetEx(const int mode, const DocPos length, const cha // ---------------------------------------------------------------------------- +inline LRESULT Sci_ForceNotifyUpdateUI(HWND hwnd, uptr_t idc) +{ + struct SCNotification scn = { 0 }; + scn.nmhdr.hwndFrom = g_hwndEditWindow; + scn.nmhdr.idFrom = idc; + scn.nmhdr.code = SCN_UPDATEUI; + scn.updated = SC_UPDATE_CONTENT; + return SendMessageW(hwnd, WM_NOTIFY, idc, (LPARAM)&scn); +} + +// ---------------------------------------------------------------------------- + //============================================================================= #endif //_NP3_SCICALL_H_ diff --git a/src/Styles.c b/src/Styles.c index 50f66a636..2db517079 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -569,7 +569,7 @@ bool Style_DynamicThemesMenuCmd(int cmd) Style_ResetCurrentLexer(Globals.hwndEdit); } UpdateMargins(true); - UpdateUI(); + UpdateUI(Globals.hwndMain); } return result; }