diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index 2fb06b269a..0629eff8f3 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -841,7 +841,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define CARETSTYLE_INVISIBLE 0 #define CARETSTYLE_LINE 1 #define CARETSTYLE_BLOCK 2 -#define CARETSTYLE_BLOCK_ALWAYS 3 +#define CARETSTYLE_OVERSTRIKE_BAR 0 +#define CARETSTYLE_OVERSTRIKE_BLOCK 16 +#define CARETSTYLE_INS_MASK 0xF #define SCI_SETCARETSTYLE 2512 #define SCI_GETCARETSTYLE 2513 #define SCI_SETINDICATORCURRENT 2500 diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index 6e424e261f..81395f2520 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -2199,7 +2199,9 @@ enu CaretStyle=CARETSTYLE_ val CARETSTYLE_INVISIBLE=0 val CARETSTYLE_LINE=1 val CARETSTYLE_BLOCK=2 -val CARETSTYLE_BLOCK_ALWAYS=3 +val CARETSTYLE_OVERSTRIKE_BAR=0 +val CARETSTYLE_OVERSTRIKE_BLOCK=16 +val CARETSTYLE_INS_MASK=0xF # Set the style of the caret to be drawn. set void SetCaretStyle=2512(int caretStyle,) diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 1885fe3730..e0bc263b54 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -1422,7 +1422,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt for (size_t r = 0; (r < model.sel.Count()) || drawDrag; r++) { const bool mainCaret = r == model.sel.Main(); SelectionPosition posCaret = (drawDrag ? model.posDrag : model.sel.Range(r).caret); - if ((vsDraw.caretStyle == CARETSTYLE_BLOCK || vsDraw.caretStyle == CARETSTYLE_BLOCK_ALWAYS) && !drawDrag && posCaret > model.sel.Range(r).anchor) { + if ((vsDraw.IsBlockCaretStyle() || imeCaretBlockOverride) && !drawDrag && posCaret > model.sel.Range(r).anchor) { if (posCaret.VirtualSpace() > 0) posCaret.SetVirtualSpace(posCaret.VirtualSpace() - 1); else @@ -1453,7 +1453,7 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt const bool caretBlinkState = (model.caret.active && model.caret.on) || (!additionalCaretsBlink && !mainCaret); const bool caretVisibleState = additionalCaretsVisible || mainCaret; if ((xposCaret >= 0) && (vsDraw.caretWidth > 0) && (vsDraw.caretStyle != CARETSTYLE_INVISIBLE) && - ((model.posDrag.IsValid()) || (caretBlinkState && caretVisibleState))) { + (drawDrag || (caretBlinkState && caretVisibleState))) { bool caretAtEOF = false; bool caretAtEOL = false; bool drawBlockCaret = false; @@ -1477,16 +1477,17 @@ void EditView::DrawCarets(Surface *surface, const EditModel &model, const ViewSt if (xposCaret > 0) caretWidthOffset = 0.51f; // Move back so overlaps both character cells. xposCaret += xStart; - if (model.posDrag.IsValid()) { + const ViewStyle::CaretShape caretShape = drawDrag ? ViewStyle::CaretShape::line : vsDraw.CaretShapeForMode(model.inOverstrike); + if (drawDrag) { /* Dragging text, use a line caret */ rcCaret.left = round(xposCaret - caretWidthOffset); rcCaret.right = rcCaret.left + vsDraw.caretWidth; - } else if ((model.inOverstrike && vsDraw.caretStyle != CARETSTYLE_BLOCK_ALWAYS) && drawOverstrikeCaret) { + } else if ((caretShape == ViewStyle::CaretShape::bar) && drawOverstrikeCaret) { /* Overstrike (insert mode), use a modified bar caret */ rcCaret.top = rcCaret.bottom - 2; rcCaret.left = xposCaret + 1; rcCaret.right = rcCaret.left + widthOverstrikeCaret - 1; - } else if ((vsDraw.caretStyle == CARETSTYLE_BLOCK || vsDraw.caretStyle == CARETSTYLE_BLOCK_ALWAYS) || imeCaretBlockOverride) { + } else if ((caretShape == ViewStyle::CaretShape::block) || imeCaretBlockOverride) { /* Block caret */ rcCaret.left = xposCaret; if (!caretAtEOL && !caretAtEOF && (ll->chars[offset] != '\t') && !(IsControlCharacter(ll->chars[offset]))) { diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index cee4a177b0..cdcf2fbc4c 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -1358,7 +1358,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(SelectionRange range, con newXY.xOffset = static_cast(pt.x + xOffset - rcClient.left) - 2; } else if (pt.x + xOffset >= rcClient.right + newXY.xOffset) { newXY.xOffset = static_cast(pt.x + xOffset - rcClient.right) + 2; - if ((vs.caretStyle == CARETSTYLE_BLOCK || vs.caretStyle == CARETSTYLE_BLOCK_ALWAYS) || view.imeCaretBlockOverride) { + if (vs.IsBlockCaretStyle() || view.imeCaretBlockOverride) { // Ensure we can see a good portion of the block caret newXY.xOffset += static_cast(vs.aveCharWidth); } @@ -7336,7 +7336,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return vs.caretcolour.AsInteger(); case SCI_SETCARETSTYLE: - if (wParam <= CARETSTYLE_BLOCK_ALWAYS) + if (wParam <= (CARETSTYLE_BLOCK | CARETSTYLE_OVERSTRIKE_BLOCK)) vs.caretStyle = static_cast(wParam); else /* Default to the line caret */ diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx index 789b55b343..ee9b4d5c7d 100644 --- a/scintilla/src/ViewStyle.cxx +++ b/scintilla/src/ViewStyle.cxx @@ -567,6 +567,19 @@ bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) noexcept { return changed; } +bool ViewStyle::IsBlockCaretStyle() const noexcept { + return (caretStyle == CARETSTYLE_BLOCK) || (caretStyle & CARETSTYLE_OVERSTRIKE_BLOCK) != 0; +} + +ViewStyle::CaretShape ViewStyle::CaretShapeForMode(bool inOverstrike) const noexcept { + if (inOverstrike) { + return (caretStyle & CARETSTYLE_OVERSTRIKE_BLOCK) ? CaretShape::block : CaretShape::bar; + } + + const int caret = caretStyle & CARETSTYLE_INS_MASK; + return (caret <= CARETSTYLE_BLOCK) ? static_cast(caret) : CaretShape::line; +} + bool ViewStyle::ZoomIn() noexcept { if (zoomLevel < SC_MAX_ZOOM_LEVEL) { int level = zoomLevel; diff --git a/scintilla/src/ViewStyle.h b/scintilla/src/ViewStyle.h index e13aa506f9..389b30ba2b 100644 --- a/scintilla/src/ViewStyle.h +++ b/scintilla/src/ViewStyle.h @@ -215,6 +215,10 @@ class ViewStyle { bool WhiteSpaceVisible(bool inIndent) const noexcept; + enum class CaretShape { invisible, line, block, bar }; + bool IsBlockCaretStyle() const noexcept; + CaretShape CaretShapeForMode(bool inOverstrike) const noexcept; + bool ZoomIn() noexcept; bool ZoomOut() noexcept; diff --git a/src/Notepad2.c b/src/Notepad2.c index 5151a82510..0886fa79fa 100644 --- a/src/Notepad2.c +++ b/src/Notepad2.c @@ -288,6 +288,7 @@ static int iAlignMode = 0; int iMatchesCount = 0; extern int iFontQuality; extern int iCaretStyle; +extern int iOvrCaretStyle; extern int iCaretBlinkPeriod; static BOOL fIsElevated = FALSE; @@ -2328,6 +2329,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) { CheckCmd(hmenu, IDM_VIEW_WORDWRAP, fWordWrap); i = IDM_VIEW_FONTQUALITY_DEFAULT + iFontQuality; CheckMenuRadioItem(hmenu, IDM_VIEW_FONTQUALITY_DEFAULT, IDM_VIEW_FONTQUALITY_CLEARTYPE, i, MF_BYCOMMAND); + CheckCmd(hmenu, IDM_VIEW_CARET_STYLE_BLOCK_OVR, iOvrCaretStyle); i = IDM_VIEW_CARET_STYLE_BLOCK + iCaretStyle; CheckMenuRadioItem(hmenu, IDM_VIEW_CARET_STYLE_BLOCK, IDM_VIEW_CARET_STYLE_WIDTH3, i, MF_BYCOMMAND); CheckCmd(hmenu, IDM_VIEW_CARET_STYLE_NOBLINK, iCaretBlinkPeriod == 0); @@ -4120,7 +4122,10 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) { SendMessage(hwndEdit, SCI_SETFONTQUALITY, iFontQuality, 0); break; - case IDM_VIEW_CARET_STYLE_BLOCK_BOTH: + case IDM_VIEW_CARET_STYLE_BLOCK_OVR: + iOvrCaretStyle = !iOvrCaretStyle; + Style_UpdateCaret(hwndEdit); + break; case IDM_VIEW_CARET_STYLE_BLOCK: case IDM_VIEW_CARET_STYLE_WIDTH1: case IDM_VIEW_CARET_STYLE_WIDTH2: @@ -5311,7 +5316,8 @@ void LoadSettings(void) { iFontQuality = clamp_i(iValue, SC_EFF_QUALITY_DEFAULT, SC_EFF_QUALITY_LCD_OPTIMIZED); iValue = IniSectionGetInt(pIniSection, L"CaretStyle", 1); - iCaretStyle = clamp_i(iValue, -1, 3); + iOvrCaretStyle = clamp_i(iValue / 10, 0, 1); + iCaretStyle = clamp_i(iValue % 10, 0, 3); iCaretBlinkPeriod = IniSectionGetInt(pIniSection, L"CaretBlinkPeriod", -1); // Korean IME use inline mode (and block caret in inline mode) by default @@ -5563,7 +5569,7 @@ void SaveSettings(BOOL bSaveSettingsNow) { IniSectionSetIntEx(pIniSection, L"RenderingTechnology", iRenderingTechnology, (IsVistaAndAbove()? SC_TECHNOLOGY_DIRECTWRITE : SC_TECHNOLOGY_DEFAULT)); IniSectionSetIntEx(pIniSection, L"Bidirectional", iBidirectional, SC_BIDIRECTIONAL_DISABLED); IniSectionSetIntEx(pIniSection, L"FontQuality", iFontQuality, SC_EFF_QUALITY_LCD_OPTIMIZED); - IniSectionSetIntEx(pIniSection, L"CaretStyle", iCaretStyle, 1); + IniSectionSetIntEx(pIniSection, L"CaretStyle", iCaretStyle + iOvrCaretStyle*10, 1); IniSectionSetIntEx(pIniSection, L"CaretBlinkPeriod", iCaretBlinkPeriod, -1); IniSectionSetBool(pIniSection, L"UseInlineIME", bUseInlineIME); // keep result of auto detection IniSectionSetBoolEx(pIniSection, L"InlineIMEUseBlockCaret", bInlineIMEUseBlockCaret, 0); diff --git a/src/Notepad2.rc b/src/Notepad2.rc index aa2f3315c2..8323b1ef1c 100644 --- a/src/Notepad2.rc +++ b/src/Notepad2.rc @@ -372,9 +372,9 @@ BEGIN END POPUP "Caret Style" BEGIN - MENUITEM "Block (Both Mode)", IDM_VIEW_CARET_STYLE_BLOCK_BOTH - MENUITEM "Block (INS Mode)", IDM_VIEW_CARET_STYLE_BLOCK + MENUITEM "Block (OVR Mode)", IDM_VIEW_CARET_STYLE_BLOCK_OVR MENUITEM SEPARATOR + MENUITEM "Block (INS Mode)", IDM_VIEW_CARET_STYLE_BLOCK MENUITEM "Width 1", IDM_VIEW_CARET_STYLE_WIDTH1 MENUITEM "Width 2", IDM_VIEW_CARET_STYLE_WIDTH2 MENUITEM "Width 3", IDM_VIEW_CARET_STYLE_WIDTH3 diff --git a/src/Styles.c b/src/Styles.c index 4db3ed4e56..c027149270 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -255,7 +255,8 @@ static UINT fStylesModified = STYLESMODIFIED_NONE; static BOOL fWarnedNoIniFile = FALSE; static int iBaseFontSize = 11*SC_FONT_SIZE_MULTIPLIER; // 11 pt in lexDefault int iFontQuality = SC_EFF_QUALITY_LCD_OPTIMIZED; -int iCaretStyle = 1; // width 1, 0 for block, -1 for always block +int iCaretStyle = 1; // width 1, 0 for block +int iOvrCaretStyle = 0; // 0 for bar, 1 for block int iCaretBlinkPeriod = -1; // system default, 0 for noblink static int iDefaultLexer; static BOOL bAutoSelect; @@ -700,10 +701,10 @@ void Style_OnDPIChanged(HWND hwnd) { void Style_UpdateCaret(HWND hwnd) { // caret style and width - if (iCaretStyle <= 0) { - SendMessage(hwnd, SCI_SETCARETSTYLE, ((iCaretStyle == 0) ? CARETSTYLE_BLOCK : CARETSTYLE_BLOCK_ALWAYS), 0); - } else { - SendMessage(hwnd, SCI_SETCARETSTYLE, CARETSTYLE_LINE, 0); + const int style = (iCaretStyle ? CARETSTYLE_LINE : CARETSTYLE_BLOCK) + | (iOvrCaretStyle ? CARETSTYLE_OVERSTRIKE_BLOCK : CARETSTYLE_OVERSTRIKE_BAR); + SendMessage(hwnd, SCI_SETCARETSTYLE, style, 0); + if (iCaretStyle != 0) { SendMessage(hwnd, SCI_SETCARETWIDTH, iCaretStyle, 0); } diff --git a/src/resource.h b/src/resource.h index 52369ac8da..5cf650b756 100644 --- a/src/resource.h +++ b/src/resource.h @@ -610,7 +610,7 @@ #define IDM_VIEW_FONTQUALITY_NONE 40066 #define IDM_VIEW_FONTQUALITY_STANDARD 40067 #define IDM_VIEW_FONTQUALITY_CLEARTYPE 40068 -#define IDM_VIEW_CARET_STYLE_BLOCK_BOTH 40069 +#define IDM_VIEW_CARET_STYLE_BLOCK_OVR 40069 #define IDM_VIEW_CARET_STYLE_BLOCK 40070 #define IDM_VIEW_CARET_STYLE_WIDTH1 40071 #define IDM_VIEW_CARET_STYLE_WIDTH2 40072 diff --git a/version.txt b/version.txt index 625bcd63ce..e309d4ab25 100644 --- a/version.txt +++ b/version.txt @@ -5,12 +5,12 @@ git clone https://github.com/XhmikosR/notepad2-mod.git Scintilla hg clone http://hg.code.sf.net/p/scintilla/code scintilla 4.1.3 -2019-02-02 7245:aba09a1c7c63 +2019-02-05 7248:06b6a93d8e3f SciTE hg clone http://hg.code.sf.net/p/scintilla/scite 4.1.3 -2019-02-02 5122:d75981e484ee +2019-02-05 5123:ce6b6778a246 Notepad++ https://github.com/notepad-plus-plus/notepad-plus-plus.git