From 9dc0a56c859efa79f7392c2e584bb389c8c1d5d7 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 22 Nov 2017 11:04:51 +0100 Subject: [PATCH 1/4] + fix: transform backslash issues + fix: C/C++ keywords and types + timer call for mark occurrences during find/repl --- src/Edit.c | 122 +++++++++++++++++++++++++++--------------------- src/Helpers.c | 3 +- src/Notepad3.rc | Bin 183184 -> 183202 bytes src/Styles.c | 38 ++++++++------- src/resource.h | 2 + 5 files changed, 94 insertions(+), 71 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 123736637..92385e910 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -22,9 +22,10 @@ #if !defined(NTDDI_VERSION) #define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif -#define VC_EXTRALEAN 1 +#define VC_EXTRALEAN 1 #include + #include #include #include @@ -48,6 +49,9 @@ #define DEFAULT_SCROLL_WIDTH 4096 // 4K +// find free bits in scintilla.h SCFIND_ defines +#define SCFIND_NP3_REGEX (SCFIND_REGEXP | SCFIND_POSIX) + extern HWND hwndMain; extern HWND hwndEdit; extern HINSTANCE g_hInstance; @@ -85,6 +89,7 @@ extern int iMarkOccurrencesMaxCount; extern NP2ENCODING mEncoding[]; + #define DELIM_BUFFER 258 char DelimChars[DELIM_BUFFER] = { '\0' }; char DelimCharsAccel[DELIM_BUFFER] = { '\0' }; @@ -95,6 +100,7 @@ char WordCharsAccelerated[DELIM_BUFFER] = { '\0' }; char WhiteSpaceCharsAccelerated[DELIM_BUFFER] = { '\0' }; char PunctuationCharsAccelerated[1] = { '\0' }; // empty! + enum AlignMask { ALIGN_LEFT = 0, ALIGN_RIGHT = 1, @@ -116,7 +122,6 @@ enum SortOrderMask { }; - extern LPMRULIST mruFind; extern LPMRULIST mruReplace; @@ -3280,7 +3285,7 @@ void EditStripTrailingBlanks(HWND hwnd,BOOL bIgnoreSelection) { if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) { - EDITFINDREPLACE efrTrim = { "[ \t]+$", "", "", "", (SCFIND_REGEXP | SCFIND_POSIX), 0, 0, 0, 0, 0, 0, NULL }; + EDITFINDREPLACE efrTrim = { "[ \t]+$", "", "", "", SCFIND_NP3_REGEX, 0, 0, 0, 0, 0, 0, NULL }; efrTrim.hwnd = hwnd; EditReplaceAllInSelection(hwnd,&efrTrim,FALSE); @@ -4339,14 +4344,14 @@ void __fastcall EditSetSearchFlags(HWND hwnd, LPEDITFINDREPLACE lpefr) lpefr->fuFlags |= SCFIND_WORDSTART; if (IsDlgButtonChecked(hwnd, IDC_FINDREGEXP) == BST_CHECKED) - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; if (IsDlgButtonChecked(hwnd, IDC_WILDCARDSEARCH) == BST_CHECKED) { lpefr->bWildcardSearch = TRUE; - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; } - if (!(lpefr->bWildcardSearch || (lpefr->fuFlags & SCFIND_REGEXP))) + if (!(lpefr->fuFlags & SCFIND_REGEXP)) lpefr->bTransformBS = (IsDlgButtonChecked(hwnd, IDC_FINDTRANSFORMBS) == BST_CHECKED) ? TRUE : FALSE; lpefr->bNoFindWrap = (IsDlgButtonChecked(hwnd, IDC_NOWRAP) == BST_CHECKED) ? TRUE : FALSE; @@ -4362,7 +4367,7 @@ void __fastcall EscapeWildcards(char* szFind2, LPCEDITFINDREPLACE lpefr) int iSource = 0; int iDest = 0; - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; while (szFind2[iSource] != '\0') { @@ -4418,17 +4423,12 @@ int __fastcall EditGetFindStrg(HWND hwnd, LPCEDITFINDREPLACE lpefr, LPSTR szFind if (lpefr->bTransformBS || bIsRegEx) TransformBackslashes(szFind, bIsRegEx, Encoding_SciGetCodePage(hwnd),NULL); - int slen = StringCchLenA(szFind, FNDRPL_BUFFER); - - if (slen == 0) { - InfoBox(0, L"MsgNotFound", IDS_NOTFOUND); - } - else { + if (StringCchLenA(szFind, FNDRPL_BUFFER) > 0) { if (lpefr->bWildcardSearch) EscapeWildcards(szFind, lpefr); - } - return slen; + + return StringCchLenA(szFind, FNDRPL_BUFFER); } @@ -4497,6 +4497,7 @@ RegExResult_t __fastcall EditFindHasMatch(HWND hwnd, LPCEDITFINDREPLACE lpefr, B } + //============================================================================= // // EditFindReplaceDlgProcW() @@ -4637,7 +4638,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA CheckDlgButton(hwnd,IDC_FINDREGEXP,BST_UNCHECKED); } - if ((lpefr->fuFlags & SCFIND_REGEXP) || (lpefr->bWildcardSearch)) { + if (lpefr->fuFlags & SCFIND_REGEXP) { CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, BST_CHECKED); DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, FALSE); } @@ -4696,7 +4697,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA EditSetSearchFlags(hwnd, lpefr); bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 200, NULL); } return TRUE; @@ -4711,14 +4712,25 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SendMessage(hwndMain, WM_COMMAND, (WPARAM)MAKELONG(IDM_VIEW_MARKOCCURRENCES_ONOFF, 1), 0); } } + KillTimer(hwnd, IDT_TIMER_MRKALL); } return FALSE; + case WM_TIMER: + { + if (LOWORD(wParam) == IDT_TIMER_MRKALL) + { + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_MARKALL_OCC, 1), 0); + return TRUE; + } + } + return FALSE; + case WM_ACTIVATE: if (bDoCheckAllOccurrences) { bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); } else { DialogEnableWindow(hwnd, IDC_REPLACEINSEL, !(BOOL)SendMessage(hwndEdit, SCI_GETSELECTIONEMPTY, 0, 0)); @@ -4754,27 +4766,33 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETEDITSEL, 0, (LPARAM)&lSelEnd); SendDlgItemMessage(hwnd, LOWORD(wParam), CB_SETEDITSEL, 0, MAKELPARAM(lSelEnd, lSelEnd)); } - - if (bDoCheckAllOccurrences) { - EditSetSearchFlags(hwnd, lpefr); - if (bFlagsChanged || (StringCchCompareXA(lastFind, lpefr->szFind) != 0)) { - BeginWaitCursor(); - StringCchCopyA(lastFind, COUNTOF(lastFind), lpefr->szFind); - RegExResult_t match = NO_MATCH; - match = EditFindHasMatch(hwndEdit, lpefr, (iSaveMarkOcc > 0), FALSE); - if (regexMatch != match) { - regexMatch = match; - InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); - } - // we have to set Sci's regex instance to first find (have substitution in place) - EditFindHasMatch(hwndEdit, lpefr, FALSE, TRUE); - bFlagsChanged = FALSE; - EndWaitCursor(); - } - } + bFlagsChanged = TRUE; + SetTimer(hwnd, IDT_TIMER_MRKALL, 200, NULL); } break; + case IDC_MARKALL_OCC: + { + if (bDoCheckAllOccurrences) { + EditSetSearchFlags(hwnd, lpefr); + if (bFlagsChanged || (StringCchCompareXA(lastFind, lpefr->szFind) != 0)) { + BeginWaitCursor(); + StringCchCopyA(lastFind, COUNTOF(lastFind), lpefr->szFind); + RegExResult_t match = NO_MATCH; + match = EditFindHasMatch(hwndEdit, lpefr, (iSaveMarkOcc > 0), FALSE); + if (regexMatch != match) { + regexMatch = match; + InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); + } + // we have to set Sci's regex instance to first find (have substitution in place) + EditFindHasMatch(hwndEdit, lpefr, FALSE, TRUE); + bFlagsChanged = FALSE; + EndWaitCursor(); + } + } + } + break; + case IDC_FINDREGEXP: if (IsDlgButtonChecked(hwnd, IDC_FINDREGEXP) == BST_CHECKED) { @@ -4782,23 +4800,23 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, FALSE); CheckDlgButton(hwnd, IDC_WILDCARDSEARCH, BST_UNCHECKED); // Can not use wildcard search together with regexp - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; lpefr->bWildcardSearch = FALSE; } else { if (IsDlgButtonChecked(hwnd, IDC_WILDCARDSEARCH) == BST_CHECKED) { - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, BST_CHECKED); DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, FALSE); } else { - lpefr->fuFlags ^= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags ^= SCFIND_NP3_REGEX; DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, TRUE); CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, (lpefr->bTransformBS) ? BST_CHECKED : BST_UNCHECKED); } } bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; case IDC_WILDCARDSEARCH: @@ -4808,25 +4826,25 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, FALSE); CheckDlgButton(hwnd, IDC_FINDREGEXP, BST_UNCHECKED); - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; lpefr->bWildcardSearch = TRUE; } else { if (IsDlgButtonChecked(hwnd, IDC_FINDREGEXP) == BST_CHECKED) { - lpefr->fuFlags |= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags |= SCFIND_NP3_REGEX; CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, BST_CHECKED); DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, FALSE); } else { DialogEnableWindow(hwnd, IDC_FINDTRANSFORMBS, TRUE); CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, (lpefr->bTransformBS) ? BST_CHECKED : BST_UNCHECKED); - lpefr->fuFlags ^= (SCFIND_REGEXP | SCFIND_POSIX); + lpefr->fuFlags ^= SCFIND_NP3_REGEX; } lpefr->bWildcardSearch = FALSE; } bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; case IDC_FINDTRANSFORMBS: @@ -4837,22 +4855,22 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA lpefr->bTransformBS = FALSE; } bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; case IDC_FINDCASE: bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; case IDC_FINDWORD: bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; case IDC_FINDSTART: bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; @@ -4989,7 +5007,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA } } bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); break; @@ -5007,7 +5025,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SetDlgItemTextW(hwnd, IDC_FINDTEXT, wszRepl); SetDlgItemTextW(hwnd, IDC_REPLACETEXT, wszFind); bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); } break; @@ -5031,7 +5049,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA iSaveMarkOcc = -1; } bFlagsChanged = TRUE; - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_FINDTEXT, 1), 0); + SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); } break; @@ -5160,7 +5178,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA return hBrush; } } - return DefWindowProc(hwnd, umsg, wParam, lParam); + return FALSE; } // WM_COMMAND: break; diff --git a/src/Helpers.c b/src/Helpers.c index a1fdc472a..925a3fc74 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -2461,12 +2461,11 @@ void TransformBackslashes(char* pszInput, BOOL bRegEx, UINT cpEdit, int* iReplac replTarget = CheckRegExReplTarget(pszInput); } - if (SCI_REPLACETARGET == replTarget) + if ((SCI_REPLACETARGET == replTarget) && !bRegEx) UnSlash(pszInput, cpEdit); if (iReplaceMsg) *iReplaceMsg = replTarget; - } diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 7548eb4d6d9a0b302a4ee095b92f522b19d08093..eaede8a2dde1233c31939ebad716afd2a8639795 100644 GIT binary patch delta 87 zcmV-d0I2_vmkXko3xI?Hv;yiZx1cQoq6N2bNdle-m#RMk5SMUC0tA=d6aog9@GJtH txBM~!bQYI>OachETv7s@ZVht)F91UTYye>Za{zOfVY~tvw+z7ogbH1+9V`F< delta 78 zcmZ29oqNJ`?uHh|EljU;rrTLFEt;<7$s{nnA&`k>`zsx$MXcM^Y?$=KKmtPB=NU2e ia7_28VzQea$HBz0JtT-}N#68H` Date: Wed, 22 Nov 2017 12:56:42 +0100 Subject: [PATCH 2/4] + fix: issue with update of line number margin width --- src/Notepad3.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 79d347773..214b3aa52 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1013,6 +1013,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) UpdateToolbar(); UpdateStatusbar(); + UpdateLineNumberWidth(); // print file immediately and quit if (flagPrintFileAndLeave) @@ -1039,6 +1040,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) PostMessage(hwndMain, WM_CLOSE, 0, 0); } + UNUSED(pszCmdLine); return(hwndMain); @@ -1151,9 +1153,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) case WM_SETFOCUS: SetFocus(hwndEdit); - UpdateToolbar(); UpdateStatusbar(); + UpdateLineNumberWidth(); //if (bPendingChangeNotify) // PostMessage(hwnd,WM_CHANGENOTIFY,0,0); @@ -1312,7 +1314,6 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) // Margins Style_SetCurrentMargin(hwndEdit, bShowSelectionMargin); - UpdateLineNumberWidth(); // Code folding SciCall_SetMarginType(MARGIN_FOLD_INDEX, SC_MARGIN_SYMBOL); @@ -1422,7 +1423,6 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) return(-1); UNUSED(wParam); - return(0); } @@ -4221,19 +4221,16 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_ZOOMIN: SendMessage(hwndEdit,SCI_ZOOMIN,0,0); - //UpdateLineNumberWidth(); break; case IDM_VIEW_ZOOMOUT: SendMessage(hwndEdit,SCI_ZOOMOUT,0,0); - //UpdateLineNumberWidth(); break; case IDM_VIEW_RESETZOOM: SendMessage(hwndEdit,SCI_SETZOOM,0,0); - //UpdateLineNumberWidth(); break; @@ -5305,9 +5302,9 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) if (bMatchBraces) { EditMatchBrace(hwndEdit); } - UpdateToolbar(); UpdateStatusbar(); + UpdateLineNumberWidth(); } break; @@ -5460,7 +5457,9 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } } bModified = TRUE; - // fall through + UpdateLineNumberWidth(); + break; + case SCN_ZOOM: UpdateLineNumberWidth(); break; @@ -5473,6 +5472,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_MARGINCLICK: if (scn->margin == MARGIN_FOLD_INDEX) FoldClick(SciCall_LineFromPosition(scn->position), scn->modifiers); + UpdateLineNumberWidth(); break; case SCN_KEY: @@ -6947,19 +6947,24 @@ void UpdateStatusbar() // void UpdateLineNumberWidth() { - char chLines[32] = { '\0' }; - int iLineMarginWidthNow; - int iLineMarginWidthFit; + static int lastLineCnt = -1; if (bShowLineNumbers) { - StringCchPrintfA(chLines,COUNTOF(chLines),"_%i_",SendMessage(hwndEdit,SCI_GETLINECOUNT,0,0)); + int iLineCnt = (int)SendMessage(hwndEdit, SCI_GETLINECOUNT, 0, 0); - iLineMarginWidthNow = (int)SendMessage(hwndEdit,SCI_GETMARGINWIDTHN, MARGIN_NP3_LINENUM, 0); - iLineMarginWidthFit = (int)SendMessage(hwndEdit,SCI_TEXTWIDTH,STYLE_LINENUMBER,(LPARAM)chLines); + if (lastLineCnt != iLineCnt) + { + char chLines[32] = { '\0' }; + StringCchPrintfA(chLines, COUNTOF(chLines), "_%i_", iLineCnt); - if (iLineMarginWidthNow != iLineMarginWidthFit) { - SendMessage(hwndEdit,SCI_SETMARGINWIDTHN, MARGIN_NP3_LINENUM, iLineMarginWidthFit); + int iLineMarginWidthNow = (int)SendMessage(hwndEdit, SCI_GETMARGINWIDTHN, MARGIN_NP3_LINENUM, 0); + int iLineMarginWidthFit = (int)SendMessage(hwndEdit, SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)chLines); + + if (iLineMarginWidthNow != iLineMarginWidthFit) { + SendMessage(hwndEdit, SCI_SETMARGINWIDTHN, MARGIN_NP3_LINENUM, iLineMarginWidthFit); + } + lastLineCnt = iLineCnt; } } else @@ -7245,7 +7250,6 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp FileVars_Init(NULL,0,&fvCurFile); EditSetNewText(hwndEdit,"",0); Style_SetLexer(hwndEdit,NULL); - UpdateLineNumberWidth(); bModified = FALSE; bReadOnly = FALSE; iEOLMode = iLineEndings[iDefaultEOLMode]; @@ -7254,7 +7258,10 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp Encoding_HasChanged(iDefaultEncoding); Encoding_SciSetCodePage(hwndEdit,iDefaultEncoding); EditSetNewText(hwndEdit,"",0); + UpdateToolbar(); + UpdateStatusbar(); + UpdateLineNumberWidth(); // Terminate file watching if (bResetFileWatching) From 2a54c5375048b419d1bad4b35034246471d77aba Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 22 Nov 2017 13:19:01 +0100 Subject: [PATCH 3/4] + adapt: C/C++ styles - keyword vs. typedefs --- src/Styles.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Styles.c b/src/Styles.c index 252d3c7c2..3bb2b8e1f 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -358,12 +358,12 @@ EDITLEXER lexCSS = { SCLEX_CSS, 63003, L"CSS Style Sheets", L"css; less; sass; s KEYWORDLIST KeyWords_CPP = { // Primary keywords - "alignas auto bool break case catch char class const constexpr const_cast " + "alignas auto bool break case catch char char16_t char32_t class const constexpr const_cast " "continue decltype default delete do double dynamic_cast else enum explicit export extern false float " - "for friend goto if inline int long mutable namespace new noexcept nullptr operator private protected " - "public register reinterpret_cast restrict return short signed sizeof static static_assert static_cast struct " - "switch template this thread_local throw true try typedef typeid typename " - "union unsigned using virtual void volatile while " + "for friend goto if inline int long mutable namespace new noexcept nullptr operator " + "private protected public register reinterpret_cast restrict return short signed sizeof static " + "static_assert static_cast struct switch template this thread_local throw true try typedef typeid typename " + "union unsigned using virtual void volatile wchar_t while " "alignof defined naked noreturn", // Secondary keywords "asm __abstract __alignof __asm __assume __based __box __cdecl __declspec __delegate __event " @@ -375,8 +375,8 @@ KEYWORDLIST KeyWords_CPP = { // Documentation comment keywords "", // Global classes and typedefs - "complex imaginary char16_t char32_t int8_t int16_t int32_t int64_t intptr_t intmax_t ptrdiff_t size_t " - "uint8_t uint16_t uint32_t uint64_t uintptr_t uintmax_t wchar_t " + "complex imaginary int8_t int16_t int32_t int64_t intptr_t intmax_t ptrdiff_t size_t " + "uint8_t uint16_t uint32_t uint64_t uintptr_t uintmax_t" "__int16 __int32 __int64 __int8 __m128 __m128d __m128i __m64 __wchar_t " "_Alignas _Alignof _Atomic _Bool _Complex _Generic _Imaginary _Noreturn _Pragma _Static_assert _Thread_local", // Preprocessor definitions From b6f1b92e050aef20c63002b6396c32300518943e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 23 Nov 2017 11:53:17 +0100 Subject: [PATCH 4/4] + fix: cleanup UpdateLineNumberWidth() triggers --- src/Edit.c | 2 +- src/Notepad3.c | 71 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 92385e910..aaae5faef 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5178,7 +5178,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA return hBrush; } } - return FALSE; + return DefWindowProc(hwnd, umsg, wParam, lParam); } // WM_COMMAND: break; diff --git a/src/Notepad3.c b/src/Notepad3.c index 214b3aa52..f903125f6 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -651,6 +651,8 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n hAccMain = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_MAINWND)); hAccFindReplace = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCFINDREPLACE)); + + UpdateLineNumberWidth(); while (GetMessage(&msg,NULL,0,0)) { @@ -867,6 +869,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) Style_SetLexerFromFile(hwndEdit,szCurFile); bModified = TRUE; UpdateToolbar(); + UpdateLineNumberWidth(); // check for temp file and delete if (flagIsElevated && PathFileExists(szBufferFile)) { @@ -1141,11 +1144,12 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) { extern PEDITLEXER pLexCurrent; Style_SetLexer(hwndEdit,pLexCurrent); + UpdateLineNumberWidth(); return DefWindowProc(hwnd,umsg,wParam,lParam); } //case WM_TIMER: - // break; + // return DefWindowProc(hwnd,umsg,wParam,lParam); case WM_SIZE: MsgSize(hwnd,wParam,lParam); @@ -1153,10 +1157,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) case WM_SETFOCUS: SetFocus(hwndEdit); - UpdateToolbar(); - UpdateStatusbar(); - UpdateLineNumberWidth(); - + //UpdateToolbar(); + //UpdateStatusbar(); + //UpdateLineNumberWidth(); //if (bPendingChangeNotify) // PostMessage(hwnd,WM_CHANGENOTIFY,0,0); break; @@ -1329,6 +1332,8 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) SciCall_MarkerDefine(SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER); SciCall_SetFoldFlags(16); + UpdateLineNumberWidth(); + // Nonprinting characters SendMessage(hwndEdit,SCI_SETVIEWWS,(bViewWhiteSpace)?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE,0); SendMessage(hwndEdit,SCI_SETVIEWEOL,bViewEOLs,0); @@ -1730,11 +1735,14 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) DestroyWindow(hwndReBar); DestroyWindow(hwndStatus); CreateBars(hwnd,hInstance); - UpdateToolbar(); GetClientRect(hwnd,&rc); SendMessage(hwnd,WM_SIZE,SIZE_RESTORED,MAKELONG(rc.right,rc.bottom)); + + UpdateToolbar(); UpdateStatusbar(); + UpdateLineNumberWidth(); + UNUSED(lParam); UNUSED(wParam); @@ -1813,7 +1821,8 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) SendMessage(hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth); - //UpdateStatusbar(); + UpdateStatusbar(); + UpdateLineNumberWidth(); UNUSED(hwnd); UNUSED(lParam); @@ -1962,6 +1971,8 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); + UpdateLineNumberWidth(); + } UNUSED(wParam); @@ -3857,6 +3868,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetCurrentMargin(hwndEdit, bShowSelectionMargin); // set SendMessage(hwndEdit, SCI_MARKERADD, iLine, MARKER_NP3_BOOKMARK); + UpdateLineNumberWidth(); } break; } @@ -4101,6 +4113,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_MARGIN: bShowSelectionMargin = (bShowSelectionMargin) ? FALSE : TRUE; Style_SetCurrentMargin(hwndEdit, bShowSelectionMargin); + UpdateLineNumberWidth(); break; case IDM_VIEW_AUTOCOMPLETEWORDS: @@ -4146,9 +4159,9 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_FOLDING: bShowCodeFolding = (bShowCodeFolding) ? FALSE : TRUE; SciCall_SetMarginWidth(MARGIN_FOLD_INDEX, (bShowCodeFolding) ? 11 : 0); - UpdateToolbar(); if (!bShowCodeFolding) FoldToggleAll(EXPAND); + UpdateToolbar(); break; @@ -4221,16 +4234,19 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_ZOOMIN: SendMessage(hwndEdit,SCI_ZOOMIN,0,0); + UpdateLineNumberWidth(); break; case IDM_VIEW_ZOOMOUT: SendMessage(hwndEdit,SCI_ZOOMOUT,0,0); + UpdateLineNumberWidth(); break; case IDM_VIEW_RESETZOOM: SendMessage(hwndEdit,SCI_SETZOOM,0,0); + UpdateLineNumberWidth(); break; @@ -5304,7 +5320,6 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } UpdateToolbar(); UpdateStatusbar(); - UpdateLineNumberWidth(); } break; @@ -5456,8 +5471,10 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) RestoreSelectionAction(scn->token,REDO); } } + if (scn->linesAdded != 0) { + UpdateLineNumberWidth(); + } bModified = TRUE; - UpdateLineNumberWidth(); break; case SCN_ZOOM: @@ -5472,7 +5489,6 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_MARGINCLICK: if (scn->margin == MARGIN_FOLD_INDEX) FoldClick(SciCall_LineFromPosition(scn->position), scn->modifiers); - UpdateLineNumberWidth(); break; case SCN_KEY: @@ -6947,24 +6963,18 @@ void UpdateStatusbar() // void UpdateLineNumberWidth() { - static int lastLineCnt = -1; - - if (bShowLineNumbers) { - + if (bShowLineNumbers) + { int iLineCnt = (int)SendMessage(hwndEdit, SCI_GETLINECOUNT, 0, 0); - if (lastLineCnt != iLineCnt) - { - char chLines[32] = { '\0' }; - StringCchPrintfA(chLines, COUNTOF(chLines), "_%i_", iLineCnt); + char chLines[32] = { '\0' }; + StringCchPrintfA(chLines, COUNTOF(chLines), "_%i_", iLineCnt); - int iLineMarginWidthNow = (int)SendMessage(hwndEdit, SCI_GETMARGINWIDTHN, MARGIN_NP3_LINENUM, 0); - int iLineMarginWidthFit = (int)SendMessage(hwndEdit, SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)chLines); + int iLineMarginWidthNow = (int)SendMessage(hwndEdit, SCI_GETMARGINWIDTHN, MARGIN_NP3_LINENUM, 0); + int iLineMarginWidthFit = (int)SendMessage(hwndEdit, SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)chLines); - if (iLineMarginWidthNow != iLineMarginWidthFit) { - SendMessage(hwndEdit, SCI_SETMARGINWIDTHN, MARGIN_NP3_LINENUM, iLineMarginWidthFit); - } - lastLineCnt = iLineCnt; + if (iLineMarginWidthNow != iLineMarginWidthFit) { + SendMessage(hwndEdit, SCI_SETMARGINWIDTHN, MARGIN_NP3_LINENUM, iLineMarginWidthFit); } } else @@ -7360,11 +7370,13 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp StringCchCopy(szCurFile,COUNTOF(szCurFile),szFileName); SetDlgItemText(hwndMain,IDC_FILENAME,szCurFile); SetDlgItemInt(hwndMain,IDC_REUSELOCK,GetTickCount(),FALSE); + if (!fKeepTitleExcerpt) StringCchCopy(szTitleExcerpt,COUNTOF(szTitleExcerpt),L""); + if (!flagLexerSpecified) // flag will be cleared Style_SetLexerFromFile(hwndEdit,szCurFile); - UpdateLineNumberWidth(); + bModified = FALSE; //bReadOnly = FALSE; SendMessage(hwndEdit,SCI_SETEOLMODE,iEOLMode,0); @@ -7383,8 +7395,6 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp if (flagUseSystemMRU == 2) SHAddToRecentDocs(SHARD_PATHW,szFileName); - UpdateToolbar(); - // Install watching of the current file if (!bReload && bResetFileWatching) iFileWatchingMode = 0; @@ -7416,6 +7426,11 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp EditJumpTo(hwndEdit, iLine+1, iCol+1); } } + + UpdateToolbar(); + UpdateStatusbar(); + UpdateLineNumberWidth(); + // consistent settings file handling (if loaded in editor) bEnableSaveSettings = (StringCchCompareINW(szCurFile, COUNTOF(szCurFile), szIniFile, COUNTOF(szIniFile)) == 0) ? FALSE : TRUE; UpdateSettingsCmds();