diff options
| -rw-r--r-- | doc/ScintillaDoc.html | 8 | ||||
| -rw-r--r-- | doc/ScintillaHistory.html | 2 | ||||
| -rw-r--r-- | include/Scintilla.h | 4 | ||||
| -rw-r--r-- | include/Scintilla.iface | 4 | ||||
| -rw-r--r-- | src/EditView.cxx | 11 | ||||
| -rw-r--r-- | src/Editor.cxx | 4 | ||||
| -rw-r--r-- | src/ViewStyle.cxx | 13 | ||||
| -rw-r--r-- | src/ViewStyle.h | 4 | 
8 files changed, 36 insertions, 14 deletions
| diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 1e274a138..3c6da6772 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3213,10 +3213,10 @@ struct Sci_TextToFind {      <p><b id="SCI_SETCARETSTYLE">SCI_SETCARETSTYLE(int caretStyle)</b><br />       <b id="SCI_GETCARETSTYLE">SCI_GETCARETSTYLE → int</b><br />       The style of the caret can be set with <code>SCI_SETCARETSTYLE</code> to be a line caret -    (CARETSTYLE_LINE=1, insert mode), a block caret (CARETSTYLE_BLOCK=2, insert mode), -    a block caret in both insert and overtype mode (CARETSTYLE_BLOCK_ALWAYS=3) or to not draw at all -    (CARETSTYLE_INVISIBLE=0, insert mode). The default value for insert mode is the line caret (CARETSTYLE_LINE=1), -    for overtype mode is the bar caret. +    (CARETSTYLE_LINE=1) or a block caret (CARETSTYLE_BLOCK=2) for insert mode combined with +    a bar caret (CARETSTYLE_OVERSTRIKE_BAR=0) or a block caret (CARETSTYLE_OVERSTRIKE_BLOCK=16) for overtype mode, +    or to not draw at all (CARETSTYLE_INVISIBLE=0). The default value for insert mode is the line caret (CARETSTYLE_LINE=1), +    for overtype mode is the bar caret (CARETSTYLE_OVERSTRIKE_BAR=0).      You can determine the current caret style setting using <code>SCI_GETCARETSTYLE</code>.</p>      <p>The block caret draws most combining and multibyte character sequences successfully, diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 4ce3afd68..1ca0150bf 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -564,7 +564,7 @@  	<a href="https://sourceforge.net/p/scintilla/bugs/1548/">Bug #1548</a>.  	</li>   	<li> -	Block caret in both insert and overtype mode SCI_SETCARETSTYLE(CARETSTYLE_BLOCK_ALWAYS). +	Block caret in overtype mode SCI_SETCARETSTYLE(caretStyle | CARETSTYLE_OVERSTRIKE_BLOCK).  	<a href="https://sourceforge.net/p/scintilla/feature-requests/1217/">Feature #1217</a>.  	</li>   	<li> diff --git a/include/Scintilla.h b/include/Scintilla.h index 8128c55a1..dc0a73b7e 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -827,7 +827,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/include/Scintilla.iface b/include/Scintilla.iface index 13ba1cbef..8faae600e 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2171,7 +2171,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/src/EditView.cxx b/src/EditView.cxx index b5dce037b..4417525b8 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1421,7 +1421,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 @@ -1452,7 +1452,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; @@ -1476,16 +1476,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/src/Editor.cxx b/src/Editor.cxx index 800037501..483d51799 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1354,7 +1354,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran  			newXY.xOffset = static_cast<int>(pt.x + xOffset - rcClient.left) - 2;  		} else if (pt.x + xOffset >= rcClient.right + newXY.xOffset) {  			newXY.xOffset = static_cast<int>(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<int>(vs.aveCharWidth);  			} @@ -7290,7 +7290,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<int>(wParam);  		else  			/* Default to the line caret */ diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index ec923c382..148163bec 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -572,6 +572,19 @@ bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) {  	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<CaretShape>(caret) : CaretShape::line; +} +  void ViewStyle::AllocStyles(size_t sizeNew) {  	size_t i=styles.size();  	styles.resize(sizeNew); diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 800d8cb67..4ef82c393 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -212,6 +212,10 @@ public:  	bool WhiteSpaceVisible(bool inIndent) const; +	enum class CaretShape { invisible, line, block, bar }; +	bool IsBlockCaretStyle() const noexcept; +	CaretShape CaretShapeForMode(bool inOverstrike) const noexcept; +  private:  	void AllocStyles(size_t sizeNew);  	void CreateAndAddFont(const FontSpecification &fs); | 
