diff --git a/distrib/Notepad3.ini b/distrib/Notepad3.ini index ea9752cf9..051fb93b5 100644 Binary files a/distrib/Notepad3.ini and b/distrib/Notepad3.ini differ diff --git a/doc/Notepad3.txt b/doc/Notepad3.txt index 8e75c450e..01e276d13 100644 --- a/doc/Notepad3.txt +++ b/doc/Notepad3.txt @@ -159,6 +159,10 @@ MarkOccurrencesMaxCount The maximum number of counts for marking occurences, if this option is active. The default is 2000. +UseOldStyleBraceMatching +Switch back to (not recommended) old style brace matching. +The default is 0. + Notepad2 already existing settings: ----------------------------------- diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 162a86425..a631f5cfc 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -643,6 +643,23 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci:: return rangeSubLine; } +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + +XYPOSITION EditView::EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line) { + int styleEnd = ll->EndLineStyle(); + const bool bracesIgnoreStyle = ((vs.braceHighlightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACELIGHT)) || + (vs.braceBadLightIndicatorSet && (model.bracesMatchStyle == STYLE_BRACEBAD))); + if (!bracesIgnoreStyle) { + const Sci::Position lineLastCharacter = static_cast(model.pdoc->LineEnd(line)) - 1; + if ((lineLastCharacter == model.braces[0]) || (lineLastCharacter == model.braces[1])) { + styleEnd = model.bracesMatchStyle; + } + } + return vs.styles[styleEnd].spaceWidth; +} +#endif + + SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { pt.x = pt.x - vs.textStart; Sci::Line visibleLine = static_cast(floor(pt.y / vs.lineHeight)); @@ -671,7 +688,11 @@ SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditMo return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } if (virtualSpace) { - const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + const XYPOSITION spaceWidth = EndSpaceWidth(model,vs,ll,lineDoc); +#else + const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#endif const int spaceOffset = static_cast( (pt.x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); @@ -705,7 +726,11 @@ SelectionPosition EditView::SPositionFromLineX(Surface *surface, const EditModel if (positionInLine < rangeSubLine.end) { return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } - const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + const XYPOSITION spaceWidth = EndSpaceWidth(model,vs,ll,lineDoc); +#else + const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; +#endif const int spaceOffset = static_cast( (x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth); return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset); diff --git a/scintilla/src/EditView.h b/scintilla/src/EditView.h index a842ac63a..3f2a9042f 100644 --- a/scintilla/src/EditView.h +++ b/scintilla/src/EditView.h @@ -12,6 +12,8 @@ namespace Scintilla { #endif +#undef NP3_MATCH_BRACE_RECT_SEL_PATCH + struct PrintParameters { int magnification; int colourMode; @@ -117,7 +119,10 @@ public: Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine, const ViewStyle &vs, PointEnd pe); Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs); - SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + XYPOSITION EndSpaceWidth(const EditModel &model, const ViewStyle &vs, LineLayout *ll, Sci::Line line); +#endif + SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs); SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs); Sci::Line DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index dde6c7ebc..b4472b6a9 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -5131,6 +5131,9 @@ void Editor::SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int match Redraw(); } } +#ifdef NP3_MATCH_BRACE_RECT_SEL_PATCH + SetRectangularRange(); +#endif } void Editor::SetAnnotationHeights(Sci::Line start, Sci::Line end) { diff --git a/src/Edit.c b/src/Edit.c index 72ecf7e82..6440db3e7 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -48,7 +48,6 @@ #define DEFAULT_SCROLL_WIDTH 4096 // 4K - extern HWND hwndMain; extern HWND hwndEdit; extern HINSTANCE g_hInstance; @@ -56,6 +55,7 @@ extern HINSTANCE g_hInstance; extern DWORD dwLastIOError; extern UINT cpLastFind; extern BOOL bReplaceInitialized; +extern BOOL bUseOldStyleBraceMatching; static EDITFINDREPLACE efrSave; static BOOL bSwitchedFindReplace = FALSE; @@ -77,7 +77,9 @@ extern BOOL bLoadASCIIasUTF8; extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; -extern BOOL bVirtualSpaceInRectSelection; +extern BOOL bDenyVirtualSpaceAccess; + +extern int iMarkOccurrences; extern int iMarkOccurrencesCount; extern int iMarkOccurrencesMaxCount; @@ -156,12 +158,11 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_SETMOUSESELECTIONRECTANGULARSWITCH,TRUE,0); SendMessage(hwnd,SCI_SETMULTIPLESELECTION,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALSELECTIONTYPING,FALSE,0); - SendMessage(hwnd,SCI_SETVIRTUALSPACEOPTIONS, - (bVirtualSpaceInRectSelection ? (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE | SCVS_NOWRAPLINESTART) : SCVS_NONE),0); SendMessage(hwnd,SCI_SETADDITIONALCARETSBLINK,FALSE,0); SendMessage(hwnd,SCI_SETADDITIONALCARETSVISIBLE,FALSE,0); SendMessage(hwnd,SCI_SETMOUSEWHEELCAPTURES,FALSE,0); - + SendMessage(hwnd, SCI_SETVIRTUALSPACEOPTIONS, (bDenyVirtualSpaceAccess ? SCVS_NONE : SCVS_NP3_SPACE_OPT), 0); + SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_NEXT + (SCMOD_CTRL << 16)),SCI_PARADOWN); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_PRIOR + (SCMOD_CTRL << 16)),SCI_PARAUP); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_NEXT + ((SCMOD_CTRL | SCMOD_SHIFT) << 16)),SCI_PARADOWNEXTEND); @@ -171,6 +172,23 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_HOME + (SCMOD_SHIFT << 16)),SCI_VCHOMEWRAPEXTEND); SendMessage(hwnd,SCI_ASSIGNCMDKEY,(SCK_END + (SCMOD_SHIFT << 16)),SCI_LINEENDWRAPEXTEND); + // set indicator styles + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_MARK_OCCURANCE, 220); + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MARK_OCCURANCE, 100); + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MARK_OCCURANCE, INDIC_ROUNDBOX); + + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, 220); + SendMessage(hwnd, SCI_INDICSETALPHA,INDIC_NP3_MATCH_BRACE, 120); + SendMessage(hwnd, SCI_INDICSETFORE,INDIC_NP3_MATCH_BRACE, 0xff << (1 << 3)); // overriden by style + SendMessage(hwnd, SCI_INDICSETSTYLE,INDIC_NP3_MATCH_BRACE, INDIC_FULLBOX); + + SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, 220); + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, 120); + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_BAD_BRACE, 0xff ); // overriden by style + SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_BAD_BRACE, INDIC_FULLBOX); + + // word delimiter handling EditInitWordDelimiter(hwnd); EditSetAccelWordNav(hwnd,bAccelWordNavigation); @@ -5237,12 +5255,74 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) LocalFree(pRoot); } + +BOOL __fastcall EditHighlightIfBrace(HWND hwnd, int iPos) +{ + if (iPos < 0) { + // clear indicator + SendMessage(hwnd, SCI_BRACEBADLIGHT, (WPARAM)INVALID_POSITION, 0); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); + if (!bUseOldStyleBraceMatching) + SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 0, INDIC_NP3_BAD_BRACE); + return TRUE; + } + char c = (char)SendMessage(hwnd, SCI_GETCHARAT, iPos, 0); + if (StrChrA("()[]{}", c)) { + int iBrace2 = (int)SendMessage(hwnd, SCI_BRACEMATCH, iPos, 0); + if (iBrace2 != -1) { + int col1 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iPos, 0); + int col2 = (int)SendMessage(hwnd, SCI_GETCOLUMN, iBrace2, 0); + SendMessage(hwnd, SCI_BRACEHIGHLIGHT, iPos, iBrace2); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, min(col1, col2), 0); + if (!bUseOldStyleBraceMatching) + SendMessage(hwnd, SCI_BRACEHIGHLIGHTINDICATOR, 1, INDIC_NP3_MATCH_BRACE); + } + else { + SendMessage(hwnd, SCI_BRACEBADLIGHT, iPos, 0); + SendMessage(hwnd, SCI_SETHIGHLIGHTGUIDE, 0, 0); + if (!bUseOldStyleBraceMatching) + SendMessage(hwnd, SCI_BRACEBADLIGHTINDICATOR, 1, INDIC_NP3_BAD_BRACE); + } + return TRUE; + } + return FALSE; +} + + + +//============================================================================= +// +// EditMatchBrace() +// +void EditMatchBrace(HWND hwnd) +{ + int iEndStyled = (int)SendMessage(hwnd, SCI_GETENDSTYLED, 0, 0); + if (iEndStyled < (int)SendMessage(hwnd, SCI_GETLENGTH, 0, 0)) { + int iLine = (int)SendMessage(hwnd, SCI_LINEFROMPOSITION, iEndStyled, 0); + int iEndStyled2 = (int)SendMessage(hwnd, SCI_POSITIONFROMLINE, iLine, 0); + SendMessage(hwnd, SCI_COLOURISE, iEndStyled2, -1); + } + + int iPos = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); + + if (!EditHighlightIfBrace(hwnd, iPos)) { + // try one before + iPos = (int)SendMessage(hwnd, SCI_POSITIONBEFORE, iPos, 0); + if (!EditHighlightIfBrace(hwnd, iPos)) { + // clear mark + EditHighlightIfBrace(hwnd, -1); + } + } +} + + + //============================================================================= // // EditMarkAll() // Mark all occurrences of the text currently selected (by Aleksandar Lekov) // -void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase, BOOL bMarkOccurrencesMatchWords) +void EditMarkAll(HWND hwnd, BOOL bMarkOccurrencesMatchCase, BOOL bMarkOccurrencesMatchWords) { struct Sci_TextToFind ttf; int iPos; @@ -5269,8 +5349,8 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase iSelLength = (int)SendMessage(hwnd,SCI_GETSELTEXT,0,0); iSelCount = iSelEnd - iSelStart; - // clear existing indicator - SendMessage(hwnd, SCI_SETINDICATORCURRENT, 1, 0); + // clear existing marker indicators + SendMessage(hwnd, SCI_SETINDICATORCURRENT, INDIC_NP3_MARK_OCCURANCE, 0); SendMessage(hwnd, SCI_INDICATORCLEARRANGE, 0, iTextLen); // if nothing selected or multiple lines are selected exit @@ -5306,11 +5386,6 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase ttf.chrg.cpMax = iTextLen; ttf.lpstrText = pszText; - // set style - SendMessage(hwnd, SCI_INDICSETALPHA, 1, 100); - SendMessage(hwnd, SCI_INDICSETFORE, 1, 0xff << ((iMarkOccurrences - 1) << 3)); - SendMessage(hwnd, SCI_INDICSETSTYLE, 1, INDIC_ROUNDBOX); - iMarkOccurrencesCount = 0; while ((iPos = (int)SendMessage(hwnd, SCI_FINDTEXT, (bMarkOccurrencesMatchCase ? SCFIND_MATCHCASE : 0) | (bMarkOccurrencesMatchWords ? SCFIND_WHOLEWORD : 0), diff --git a/src/Edit.h b/src/Edit.h index 321b07f6f..094691bc9 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -44,6 +44,11 @@ typedef struct _editfindreplace #define IDMSG_SWITCHTOFIND 300 #define IDMSG_SWITCHTOREPLACE 301 + +#define INDIC_NP3_MARK_OCCURANCE 1 +#define INDIC_NP3_MATCH_BRACE 2 +#define INDIC_NP3_BAD_BRACE 3 + HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); void EditSetNewText(HWND,char*,DWORD); @@ -108,7 +113,8 @@ BOOL EditAlignDlg(HWND,int*); BOOL EditPrint(HWND,LPCWSTR,LPCWSTR); void EditPrintSetup(HWND); void EditPrintInit(); -void EditMarkAll(HWND,int,BOOL,BOOL); +void EditMatchBrace(HWND); +void EditMarkAll(HWND,BOOL,BOOL); void EditSetAccelWordNav(HWND,BOOL); void CompleteWord(HWND,BOOL); diff --git a/src/Helpers.h b/src/Helpers.h index 240b6af9f..441aae1f3 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -33,26 +33,30 @@ extern WCHAR szIniFile[MAX_PATH]; #define IniGetString(lpSection,lpName,lpDefault,lpReturnedStr,nSize) \ - GetPrivateProfileString(lpSection,lpName,lpDefault,lpReturnedStr,nSize,szIniFile) + GetPrivateProfileString(lpSection,lpName,(lpDefault),(lpReturnedStr),(nSize),szIniFile) #define IniGetInt(lpSection,lpName,nDefault) \ - GetPrivateProfileInt(lpSection,lpName,nDefault,szIniFile) + GetPrivateProfileInt(lpSection,lpName,(nDefault),szIniFile) +#define IniGetBool(lpSection,lpName,nDefault) \ + (GetPrivateProfileInt(lpSection,lpName,(int)(nDefault),szIniFile) ? TRUE : FALSE) #define IniSetString(lpSection,lpName,lpString) \ - WritePrivateProfileString(lpSection,lpName,lpString,szIniFile) + WritePrivateProfileString(lpSection,lpName,(lpString),szIniFile) #define IniDeleteSection(lpSection) \ WritePrivateProfileSection(lpSection,NULL,szIniFile) __inline BOOL IniSetInt(LPCWSTR lpSection, LPCWSTR lpName, int i) { WCHAR tch[32] = { L'\0' }; StringCchPrintf(tch, COUNTOF(tch), L"%i", i); return IniSetString(lpSection, lpName, tch); } +#define IniSetBool(lpSection,lpName,nValue) \ + IniSetInt(lpSection,lpName,((nValue) ? 1 : 0)) #define LoadIniSection(lpSection,lpBuf,cchBuf) \ - GetPrivateProfileSection(lpSection,lpBuf,cchBuf,szIniFile) + GetPrivateProfileSection(lpSection,lpBuf,(cchBuf),szIniFile) #define SaveIniSection(lpSection,lpBuf) \ WritePrivateProfileSection(lpSection,lpBuf,szIniFile) int IniSectionGetString(LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, int); int IniSectionGetInt(LPCWSTR, LPCWSTR, int); UINT IniSectionGetUInt(LPCWSTR, LPCWSTR, UINT); __inline BOOL IniSectionGetBool(LPCWSTR lpCachedIniSection, LPCWSTR lpName, BOOL bDefault) { - return (IniSectionGetInt(lpCachedIniSection, lpName, (bDefault ? 1 : 0)) ? TRUE : FALSE); + return (IniSectionGetInt(lpCachedIniSection, lpName, ((bDefault) ? 1 : 0)) ? TRUE : FALSE); } BOOL IniSectionSetString(LPWSTR,LPCWSTR,LPCWSTR); __inline BOOL IniSectionSetInt(LPWSTR lpCachedIniSection,LPCWSTR lpName,int i) { @@ -93,6 +97,8 @@ __inline BOOL IniSectionSetBool(LPWSTR lpCachedIniSection, LPCWSTR lpName, BOOL #define IsWinServer() IsWindowsServer() // Indicates if the current OS is a Windows Server release. // Applications that need to distinguish between server and client versions of Windows should call this function. +#define SCVS_NP3_SPACE_OPT (SCVS_RECTANGULARSELECTION | SCVS_NOWRAPLINESTART) + enum BufferSizes { MICRO_BUFFER = 32, diff --git a/src/Notepad3.c b/src/Notepad3.c index 8fd474239..20b28e04e 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -152,9 +152,10 @@ int iMarkOccurrencesCount; int iMarkOccurrencesMaxCount; BOOL bMarkOccurrencesMatchCase; BOOL bMarkOccurrencesMatchWords; +BOOL bUseOldStyleBraceMatching; BOOL bAutoCompleteWords; BOOL bAccelWordNavigation; -BOOL bVirtualSpaceInRectSelection; +BOOL bDenyVirtualSpaceAccess; BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; @@ -1145,11 +1146,23 @@ WININFO GetMyWindowPlacement(HWND hwnd,MONITORINFO* hMonitorInfo) // LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) { + if (!bDenyVirtualSpaceAccess) + { + if (GetAsyncKeyState(VK_MENU) & SHRT_MIN) { // ALT-KEY DOWN + //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, (SCVS_NP3_SPACE_OPT | SCVS_USERACCESSIBLE), 0); + } + else { + SendMessage(hwndEdit, SCI_SETVIRTUALSPACEOPTIONS, SCVS_NP3_SPACE_OPT, 0); + } + } + switch(umsg) { // Quickly handle painting and sizing messages, found in ScintillaWin.cxx // Cool idea, don't know if this has any effect... ;-) case WM_MOVE: + case WM_MOUSEWHEEL: case WM_MOUSEACTIVATE: case WM_NCHITTEST: case WM_NCCALCSIZE: @@ -1165,7 +1178,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) case WM_CREATE: return MsgCreate(hwnd,wParam,lParam); - case WM_DESTROY: case WM_ENDSESSION: MsgEndSession(hwnd,umsg); @@ -1176,14 +1188,12 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) DestroyWindow(hwnd); break; - case WM_QUERYENDSESSION: if (FileSave(FALSE,TRUE,FALSE,FALSE)) return TRUE; else return FALSE; - // Reinitialize theme-dependent values and resize windows case WM_THEMECHANGED: MsgThemeChanged(hwnd,wParam,lParam); @@ -1198,16 +1208,13 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) return DefWindowProc(hwnd,umsg,wParam,lParam); } - //case WM_TIMER: // break; - case WM_SIZE: MsgSize(hwnd,wParam,lParam); break; - case WM_SETFOCUS: SetFocus(hwndEdit); @@ -1218,7 +1225,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) // PostMessage(hwnd,WM_CHANGENOTIFY,0,0); break; - case WM_DROPFILES: MsgDropFiles(hwnd, wParam, lParam); break; @@ -1234,13 +1240,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) MsgInitMenu(hwnd,wParam,lParam); break; - case WM_MOUSEWHEEL: - return DefWindowProc(hwnd,umsg,wParam,lParam); - case WM_NOTIFY: return MsgNotify(hwnd,wParam,lParam); - //case WM_PARENTNOTIFY: // if (LOWORD(wParam) & WM_DESTROY) { // if (IsWindow(hDlgFindReplace) && (hDlgFindReplace == (HWND)lParam)) { @@ -1249,7 +1251,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) // } // break; - case WM_COMMAND: return MsgCommand(hwnd,wParam,lParam); @@ -1260,13 +1261,11 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) MsgChangeNotify(hwnd, wParam, lParam); break; - //// This message is posted before Notepad3 reactivates itself //case WM_CHANGENOTIFYCLEAR: // bPendingChangeNotify = FALSE; // break; - case WM_DRAWCLIPBOARD: if (!bLastCopyFromMe) dwLastCopyTime = GetTickCount(); @@ -1277,7 +1276,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) SendMessage(hwndNextCBChain,WM_DRAWCLIPBOARD,wParam,lParam); break; - case WM_CHANGECBCHAIN: if ((HWND)wParam == hwndNextCBChain) hwndNextCBChain = (HWND)lParam; @@ -1285,11 +1283,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) SendMessage(hwndNextCBChain,WM_CHANGECBCHAIN,lParam,wParam); break; - case WM_TRAYMESSAGE: return MsgTrayMessage(hwnd, wParam, lParam); - default: if (umsg == msgTaskbarCreated) { if (!IsWindowVisible(hwnd)) @@ -1298,8 +1294,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) } return DefWindowProc(hwnd, umsg, wParam, lParam); } - - return 0; + return 0; // swallow message } @@ -2372,7 +2367,6 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) EnableCmd(hmenu,IDM_EDIT_COMPLETEWORD,i); CheckCmd(hmenu,IDM_VIEW_AUTOCOMPLETEWORDS,bAutoCompleteWords); CheckCmd(hmenu,IDM_VIEW_ACCELWORDNAV,bAccelWordNavigation); - CheckCmd(hmenu,IDM_VIEW_VIRTSPACERECTSEL,bVirtualSpaceInRectSelection); switch (iMarkOccurrences) { @@ -4222,46 +4216,42 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_ACCELWORDNAV: bAccelWordNavigation = (bAccelWordNavigation) ? FALSE : TRUE; // toggle EditSetAccelWordNav(hwndEdit,bAccelWordNavigation); - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; - case IDM_VIEW_VIRTSPACERECTSEL: - bVirtualSpaceInRectSelection = (bVirtualSpaceInRectSelection) ? FALSE : TRUE; // toggle - //SendMessage(hwndEdit,SCI_CLEARSELECTIONS,0,0); - SendMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS, - (bVirtualSpaceInRectSelection ? (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE | SCVS_NOWRAPLINESTART) : SCVS_NONE),0); - break; - case IDM_VIEW_MARKOCCURRENCES_OFF: iMarkOccurrences = 0; // clear all marks - SendMessage(hwndEdit, SCI_SETINDICATORCURRENT, 1, 0); + SendMessage(hwndEdit, SCI_SETINDICATORCURRENT, INDIC_NP3_MARK_OCCURANCE, 0); SendMessage(hwndEdit, SCI_INDICATORCLEARRANGE, 0, (int)SendMessage(hwndEdit,SCI_GETLENGTH,0,0)); break; case IDM_VIEW_MARKOCCURRENCES_RED: iMarkOccurrences = 1; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_GREEN: iMarkOccurrences = 2; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_BLUE: iMarkOccurrences = 3; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + SendMessage(hwndEdit, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, 0xff << ((iMarkOccurrences - 1) << 3)); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_CASE: bMarkOccurrencesMatchCase = (bMarkOccurrencesMatchCase) ? FALSE : TRUE; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_MARKOCCURRENCES_WORD: bMarkOccurrencesMatchWords = (bMarkOccurrencesMatchWords) ? FALSE : TRUE; - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); break; case IDM_VIEW_FOLDING: @@ -5406,69 +5396,19 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) switch(pnmh->code) { case SCN_UPDATEUI: - - if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) { - - UpdateStatusbar(); - UpdateToolbar(); - + if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) + { InvalidateSelections(); // mark occurrences of text currently selected - EditMarkAll(hwndEdit, iMarkOccurrences, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); + EditMarkAll(hwndEdit, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords); // Brace Match - if (bMatchBraces) - { - int iPos; - char c; - - int iEndStyled = (int)SendMessage(hwndEdit,SCI_GETENDSTYLED,0,0); - if (iEndStyled < (int)SendMessage(hwndEdit,SCI_GETLENGTH,0,0)) { - int iLine = (int)SendMessage(hwndEdit,SCI_LINEFROMPOSITION,iEndStyled,0); - int iEndStyled2 = (int)SendMessage(hwndEdit,SCI_POSITIONFROMLINE,iLine,0); - SendMessage(hwndEdit,SCI_COLOURISE,iEndStyled2,-1); - } - - iPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0); - c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0); - if (StrChrA("()[]{}",c)) { - int iBrace2 = (int)SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0); - if (iBrace2 != -1) { - int col1 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iPos,0); - int col2 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iBrace2,0); - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,iPos,iBrace2); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,min(col1,col2),0); - } - else { - SendMessage(hwndEdit,SCI_BRACEBADLIGHT,iPos,0); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } - // Try one before - else - { - iPos = (int)SendMessage(hwndEdit,SCI_POSITIONBEFORE,iPos,0); - c = (char)SendMessage(hwndEdit,SCI_GETCHARAT,iPos,0); - if (StrChrA("()[]{}",c)) { - int iBrace2 = (int)SendMessage(hwndEdit,SCI_BRACEMATCH,iPos,0); - if (iBrace2 != -1) { - int col1 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iPos,0); - int col2 = (int)SendMessage(hwndEdit,SCI_GETCOLUMN,iBrace2,0); - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,iPos,iBrace2); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,min(col1,col2),0); - } - else { - SendMessage(hwndEdit,SCI_BRACEBADLIGHT,iPos,0); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } - else { - SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,(WPARAM)-1,(LPARAM)-1); - SendMessage(hwndEdit,SCI_SETHIGHLIGHTGUIDE,0,0); - } - } + if (bMatchBraces) { + EditMatchBrace(hwndEdit); } + UpdateToolbar(); + UpdateStatusbar(); } break; @@ -5854,8 +5794,6 @@ void LoadSettings() bAccelWordNavigation = IniSectionGetBool(pIniSection, L"AccelWordNavigation", FALSE); - bVirtualSpaceInRectSelection = IniSectionGetBool(pIniSection,L"VirtualSpaceInRectSelection",FALSE); - bShowIndentGuides = IniSectionGetBool(pIniSection,L"ShowIndentGuides",FALSE); bTabsAsSpaces = IniSectionGetBool(pIniSection,L"TabsAsSpaces",TRUE); @@ -6031,6 +5969,9 @@ void LoadSettings() iMarkOccurrencesMaxCount = IniSectionGetInt(pIniSection,L"MarkOccurrencesMaxCount",2000); iMarkOccurrencesMaxCount = max(min(iMarkOccurrencesMaxCount,100000),2); + bDenyVirtualSpaceAccess = IniSectionGetBool(pIniSection, L"DenyVirtualSpaceAccess", FALSE); + bUseOldStyleBraceMatching = IniSectionGetBool(pIniSection, L"UseOldStyleBraceMatching", FALSE); + LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection); IniSectionGetString(pIniSection,L"BitmapDefault",L"", @@ -6168,7 +6109,6 @@ void SaveSettings(BOOL bSaveSettingsNow) { IniSectionSetInt(pIniSection, L"AutoIndent", bAutoIndent); IniSectionSetInt(pIniSection, L"AutoCompleteWords", bAutoCompleteWords); IniSectionSetInt(pIniSection, L"AccelWordNavigation", bAccelWordNavigation); - IniSectionSetInt(pIniSection, L"VirtualSpaceInRectSelection",bVirtualSpaceInRectSelection); IniSectionSetInt(pIniSection, L"ShowIndentGuides", bShowIndentGuides); IniSectionSetInt(pIniSection, L"TabsAsSpaces", bTabsAsSpacesG); IniSectionSetInt(pIniSection, L"TabIndents", bTabIndentsG); @@ -7182,8 +7122,8 @@ int BeginSelUndoAction() sel.anchorPos_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHOR, 0, 0); sel.currPos_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARET, 0, 0); if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { - sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); - sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); + sel.anchorVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0); + sel.currVS_undo = (int)SendMessage(hwndEdit, SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0); } } else @@ -7258,17 +7198,17 @@ void RestoreSelectionAction(int token, DoAction doAct) PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHOR, (WPARAM)anchorPos, 0); PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARET, (WPARAM)currPos, 0); if ((sel.rectSelVS & SCVS_RECTANGULARSELECTION) != 0) { - int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo); - int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo); - PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0); - PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0); + int anchorVS = (doAct == UNDO ? sel.anchorVS_undo : sel.anchorVS_redo); + int currVS = (doAct == UNDO ? sel.currVS_undo : sel.currVS_redo); + PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, (WPARAM)anchorVS, 0); + PostMessage(hwndEdit, SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, (WPARAM)currVS, 0); } } else { PostMessage(hwndEdit,SCI_SETSELECTION,(WPARAM)currPos,(LPARAM)anchorPos); } PostMessage(hwndEdit,SCI_SETVIRTUALSPACEOPTIONS,(WPARAM)currRectType,0); - PostMessage(hwndEdit,SCI_CANCEL,0,0); + PostMessage(hwndEdit, SCI_CANCEL, 0, 0); } } @@ -7418,7 +7358,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp iFileWatchingMode = 0; InstallFileWatching(NULL); bEnableSaveSettings = TRUE; - UpdateSettingsCmds(hwndMain); + UpdateSettingsCmds(); return TRUE; } diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 8f56f566a..d0cb0633d 100644 Binary files a/src/Notepad3.rc and b/src/Notepad3.rc differ diff --git a/src/Styles.c b/src/Styles.c index a2d057687..50331431c 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -46,6 +46,9 @@ extern HINSTANCE g_hInstance; extern int iSciFontQuality; extern const int FontQuality[4]; +extern BOOL bUseOldStyleBraceMatching; + + #define MULTI_STYLE(a,b,c,d) ((a)|(b<<8)|(c<<16)|(d<<24)) @@ -2998,8 +3001,26 @@ void Style_SetLexer(HWND hwnd,PEDITLEXER pLexNew) SendMessage(hwnd,SCI_STYLECLEARALL,0,0); Style_SetStyles(hwnd,lexDefault.Styles[1+iIdx].iStyle,lexDefault.Styles[1+iIdx].szValue); // linenumber + + if (bUseOldStyleBraceMatching) { Style_SetStyles(hwnd,lexDefault.Styles[2+iIdx].iStyle,lexDefault.Styles[2+iIdx].szValue); // brace light + } + else { + if (Style_StrGetColor(TRUE, lexDefault.Styles[2 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MATCH_BRACE, iValue); + if (Style_StrGetAlpha(lexDefault.Styles[2 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MATCH_BRACE, iValue); + } + if (bUseOldStyleBraceMatching) { Style_SetStyles(hwnd,lexDefault.Styles[3+iIdx].iStyle,lexDefault.Styles[3+iIdx].szValue); // brace bad + } + else { + if (Style_StrGetColor(TRUE, lexDefault.Styles[3 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_BAD_BRACE, iValue); + if (Style_StrGetAlpha(lexDefault.Styles[3 + iIdx].szValue, &iValue)) + SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, iValue); + } + if (pLexNew != &lexANSI) Style_SetStyles(hwnd,lexDefault.Styles[4+iIdx].iStyle,lexDefault.Styles[4+iIdx].szValue); // control char Style_SetStyles(hwnd,lexDefault.Styles[5+iIdx].iStyle,lexDefault.Styles[5+iIdx].szValue); // indent guide @@ -3927,9 +3948,33 @@ BOOL Style_StrGetColor(BOOL bFore,LPCWSTR lpszStyle,int *rgb) // // Style_StrGetCase() // +BOOL Style_StrGetAlpha(LPCWSTR lpszStyle, int *i) { + WCHAR tch[256] = { L'\0' }; + WCHAR *p = StrStrI(lpszStyle, L"alpha:"); + if (p) { + StringCchCopy(tch, COUNTOF(tch), p + CSTRLEN(L"alpha:")); + p = StrChr(tch, L';'); + if (p) + *p = L'\0'; + TrimString(tch); + int iValue = 0; + int itok = swscanf_s(tch, L"%i", &iValue); + if (itok == 1) { + *i = min(max(SC_ALPHA_TRANSPARENT, iValue), SC_ALPHA_OPAQUE); + return TRUE; + } + } + return FALSE; +} + + +//============================================================================= +// +// Style_StrGetAlpha() +// BOOL Style_StrGetCase(LPCWSTR lpszStyle,int *i) { - WCHAR tch[256] = { L'\0' }; + WCHAR tch[max(BUFSIZE_STYLE_VALUE, BUFZIZE_STYLE_EXTENTIONS)] = { L'\0' }; WCHAR *p = StrStrI(lpszStyle, L"case:"); if (p) { @@ -3945,34 +3990,7 @@ BOOL Style_StrGetCase(LPCWSTR lpszStyle,int *i) else if (tch[0] == L'l' || tch[0] == L'L') { *i = SC_CASE_LOWER; return TRUE; - } } - return FALSE; -} - - -//============================================================================= -// -// Style_StrGetAlpha() -// -BOOL Style_StrGetAlpha(LPCWSTR lpszStyle,int *i) -{ - WCHAR tch[max(BUFSIZE_STYLE_VALUE, BUFZIZE_STYLE_EXTENTIONS)] = { L'\0' }; - WCHAR *p = StrStrI(lpszStyle, L"alpha:"); - if (p) - { - StringCchCopy(tch,COUNTOF(tch),p + CSTRLEN(L"alpha:")); - p = StrChr(tch, L';'); - if (p) - *p = L'\0'; - TrimString(tch); - int iValue = 0; - int itok = swscanf_s(tch,L"%i",&iValue); - if (itok == 1) - { - *i = min(max(SC_ALPHA_TRANSPARENT,iValue),SC_ALPHA_OPAQUE); - return TRUE; - } } return FALSE; } diff --git a/src/Styles.h b/src/Styles.h index 5bde5938d..1e461d924 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -16,8 +16,8 @@ #ifndef _NP3_STYLES_H_ #define _NP3_STYLES_H_ -#define BUFSIZE_STYLE_VALUE 256 -#define BUFZIZE_STYLE_EXTENTIONS 1024 +#define BUFSIZE_STYLE_VALUE 128 +#define BUFZIZE_STYLE_EXTENTIONS 512 typedef struct _editstyle { diff --git a/src/resource.h b/src/resource.h index 26c243f63..b8f6cc227 100644 --- a/src/resource.h +++ b/src/resource.h @@ -382,8 +382,7 @@ #define IDM_VIEW_MARKOCCURRENCES_WORD 40452 #define IDM_VIEW_AUTOCOMPLETEWORDS 40453 #define IDM_VIEW_ACCELWORDNAV 40454 -#define IDM_VIEW_VIRTSPACERECTSEL 40455 -#define IDM_VIEW_NOPRESERVECARET 40456 +#define IDM_VIEW_NOPRESERVECARET 40455 #define IDM_HELP_ABOUT 40500 #define IDM_HELP_CMD 40501 #define IDM_TRAY_RESTORE 40600