From 9162c73355b47219d24ddba152fe931fdfabbcfc Mon Sep 17 00:00:00 2001
From: nyamatongwe
+
+
@@ -550,6 +552,18 @@
The number of styling bits needed by the current lexer can be found with
.
SCI_RELEASEALLEXTENDEDSTYLES
+ SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles)
+ Extended styles are used for features like textual margins and annotations as well as internally by Scintilla.
+ They are outside the range 0..255 used for the styles bytes associated with document bytes.
+ These functions manage the use of extended styles to ensures that components cooperate in defining styles.
+ SCI_RELEASEALLEXTENDEDSTYLES releases any extended styles allocated by the container.
+ SCI_ALLOCATEEXTENDEDSTYLES allocates a range of style numbers after the byte style values and returns
+ the number of the first allocated style.
+ Ranges for magin and annotation styles should be allocated before calling
+ or
+ .
Sci_TextRange and Sci_CharacterRange
These structures are defined to be exactly the same shape as the Win32 TEXTRANGE
and CHARRANGE, so that older code that treats Scintilla as a RichEdit will
@@ -2968,6 +2982,10 @@ struct Sci_TextToFind {
256 upto 511 so they do not overlap styles set by lexers. Each style number set with SCI_MARGINSETSTYLE
or SCI_MARGINSETSTYLES has the offset added before looking up the style.
+ Always call
+ before SCI_MARGINSETSTYLEOFFSET and use the result as the argument to SCI_MARGINSETSTYLEOFFSET.
+
SCI_SETMARGINOPTIONS(int marginOptions)
SCI_GETMARGINOPTIONS
@@ -3077,6 +3095,10 @@ struct Sci_TextToFind {
Each style number set with SCI_ANNOTATIONSETSTYLE
or SCI_ANNOTATIONSETSTYLES has the offset added before looking up the style.
+ Always call
+ before SCI_ANNOTATIONSETSTYLEOFFSET and use the result as the argument to SCI_ANNOTATIONSETSTYLEOFFSET.
+
SCI_SETUSEPALETTE(bool
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 32956e6ba..717a6895f 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -775,6 +775,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_ANNOTATIONGETVISIBLE 2549
#define SCI_ANNOTATIONSETSTYLEOFFSET 2550
#define SCI_ANNOTATIONGETSTYLEOFFSET 2551
+#define SCI_RELEASEALLEXTENDEDSTYLES 2552
+#define SCI_ALLOCATEEXTENDEDSTYLES 2553
#define UNDO_MAY_COALESCE 1
#define SCI_ADDUNDOACTION 2560
#define SCI_CHARPOSITIONFROMPOINT 2561
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index db4adbde9..6ee29a601 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2062,6 +2062,12 @@ set void AnnotationSetStyleOffset=2550(int style,)
# Get the start of the range of style numbers used for annotations
get int AnnotationGetStyleOffset=2551(,)
+# Release all extended (>255) style numbers
+fun void ReleaseAllExtendedStyles=2552(,)
+
+# Allocate some extended (>255) style numbers and return the start of the range
+fun int AllocateExtendedStyles=2553(int numberStyles,)
+
val UNDO_MAY_COALESCE=1
# Add a container action to the undo stack
diff --git a/src/Editor.cxx b/src/Editor.cxx
index f150aa202..7d449663e 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -6824,6 +6824,8 @@ void Editor::SetDocPointer(Document *document) {
braces[0] = invalidPosition;
braces[1] = invalidPosition;
+ vs.ReleaseAllExtendedStyles();
+
// Reset the contraction state to fully shown.
cs.Clear();
cs.InsertLines(0, pdoc->LinesTotal() - 1);
@@ -9161,6 +9163,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_ANNOTATIONGETSTYLEOFFSET:
return vs.annotationStyleOffset;
+ case SCI_RELEASEALLEXTENDEDSTYLES:
+ vs.ReleaseAllExtendedStyles();
+ break;
+
+ case SCI_ALLOCATEEXTENDEDSTYLES:
+ return vs.AllocateExtendedStyles(wParam);
+
case SCI_ADDUNDOACTION:
pdoc->AddUndoAction(wParam, lParam & UNDO_MAY_COALESCE);
break;
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 059f885f7..b9284c05e 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -141,6 +141,7 @@ ViewStyle::ViewStyle(const ViewStyle &source) {
// Can't just copy fontname as its lifetime is relative to its owning ViewStyle
styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
}
+ nextExtendedStyle = source.nextExtendedStyle;
for (int mrk=0; mrk<=MARKER_MAX; mrk++) {
markers[mrk] = source.markers[mrk];
}
@@ -226,6 +227,7 @@ void ViewStyle::Init(size_t stylesSize_) {
stylesSize = 0;
styles = NULL;
AllocStyles(stylesSize_);
+ nextExtendedStyle = 256;
fontNames.Clear();
ResetDefaultStyle();
@@ -413,6 +415,16 @@ void ViewStyle::AllocStyles(size_t sizeNew) {
stylesSize = sizeNew;
}
+void ViewStyle::ReleaseAllExtendedStyles() {
+ nextExtendedStyle = 256;
+}
+
+int ViewStyle::AllocateExtendedStyles(int numberStyles) {
+ int startRange = static_cast(nextExtendedStyle);
+ nextExtendedStyle += numberStyles;
+ return startRange;
+}
+
void ViewStyle::EnsureStyle(size_t index) {
if (index >= stylesSize) {
size_t sizeNew = stylesSize * 2;
@@ -471,4 +483,3 @@ void ViewStyle::CalcLargestMarkerHeight() {
}
}
}
-
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 676aee7da..5a623986b 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -67,6 +67,7 @@ public:
FontRealised *frFirst;
size_t stylesSize;
Style *styles;
+ size_t nextExtendedStyle;
LineMarker markers[MARKER_MAX + 1];
int largestMarkerHeight;
Indicator indicators[INDIC_MAX + 1];
@@ -144,6 +145,8 @@ public:
void CreateFont(const FontSpecification &fs);
void Refresh(Surface &surface);
void AllocStyles(size_t sizeNew);
+ void ReleaseAllExtendedStyles();
+ int AllocateExtendedStyles(int numberStyles);
void EnsureStyle(size_t index);
void ResetDefaultStyle();
void ClearStyles();
diff --git a/test/simpleTests.py b/test/simpleTests.py
index 04c9ed145..4d397261a 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -1181,6 +1181,18 @@ class TestAnnotation(unittest.TestCase):
self.assertEquals(result, styles)
self.ed.AnnotationClearAll()
+ def testExtendedStyles(self):
+ start0 = self.ed.AllocateExtendedStyles(0)
+ self.assertEquals(start0, 256)
+ start1 = self.ed.AllocateExtendedStyles(10)
+ self.assertEquals(start1, 256)
+ start2 = self.ed.AllocateExtendedStyles(20)
+ self.assertEquals(start2, start1 + 10)
+ # Reset by changing lexer
+ self.ed.ReleaseAllExtendedStyles()
+ start0 = self.ed.AllocateExtendedStyles(0)
+ self.assertEquals(start0, 256)
+
def testTextAnnotationStyleOffset(self):
self.ed.AnnotationSetStyleOffset(300)
self.assertEquals(self.ed.AnnotationGetStyleOffset(), 300)
--
cgit v1.2.3