aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2013-02-05 09:28:07 +1100
committernyamatongwe <devnull@localhost>2013-02-05 09:28:07 +1100
commit9162c73355b47219d24ddba152fe931fdfabbcfc (patch)
tree40f963ff3a3e36ee8f3a4fdeb679a8c9881f8db8
parent4d129be11ee453b135d16c78dfdff8d176b3cd7f (diff)
downloadscintilla-mirror-9162c73355b47219d24ddba152fe931fdfabbcfc.tar.gz
Add allocation of extended styles.
-rw-r--r--doc/ScintillaDoc.html22
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface6
-rw-r--r--src/Editor.cxx9
-rw-r--r--src/ViewStyle.cxx13
-rw-r--r--src/ViewStyle.h3
-rw-r--r--test/simpleTests.py12
7 files changed, 66 insertions, 1 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index 6e9b11cc7..8d429f95e 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -401,6 +401,8 @@
*tr)</a><br />
<a class="message" href="#SCI_SETSTYLEBITS">SCI_SETSTYLEBITS(int bits)</a><br />
<a class="message" href="#SCI_GETSTYLEBITS">SCI_GETSTYLEBITS</a><br />
+ <a class="message" href="#SCI_RELEASEALLEXTENDEDSTYLES">SCI_RELEASEALLEXTENDEDSTYLES</a><br />
+ <a class="message" href="#SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles)</a><br />
<a class="message" href="#SCI_TARGETASUTF8">SCI_TARGETASUTF8(&lt;unused&gt;, char *s)</a><br />
<a class="message" href="#SCI_ENCODEDFROMUTF8">SCI_ENCODEDFROMUTF8(const char *utf8, char *encoded)</a><br />
<a class="message" href="#SCI_SETLENGTHFORENCODE">SCI_SETLENGTHFORENCODE(int bytes)</a><br />
@@ -550,6 +552,18 @@
The number of styling bits needed by the current lexer can be found with
<a class="message" href="#SCI_GETSTYLEBITSNEEDED">SCI_GETSTYLEBITSNEEDED</a>.</p>
+ <p><b id="SCI_RELEASEALLEXTENDEDSTYLES">SCI_RELEASEALLEXTENDEDSTYLES</b><br />
+ <b id="SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles)</b><br />
+ 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.
+ <code>SCI_RELEASEALLEXTENDEDSTYLES</code> releases any extended styles allocated by the container.
+ <code>SCI_ALLOCATEEXTENDEDSTYLES</code> 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
+ <a class="message" href="#SCI_MARGINSETSTYLEOFFSET">SCI_MARGINSETSTYLEOFFSET</a> or
+ <a class="message" href="#SCI_ANNOTATIONSETSTYLEOFFSET">SCI_ANNOTATIONSETSTYLEOFFSET</a>.</p>
+
<p><b id="Sci_TextRange">Sci_TextRange</b> and <b id="Sci_CharacterRange">Sci_CharacterRange</b><br />
These structures are defined to be exactly the same shape as the Win32 <code>TEXTRANGE</code>
and <code>CHARRANGE</code>, so that older code that treats Scintilla as a RichEdit will
@@ -2969,6 +2983,10 @@ struct Sci_TextToFind {
or <code>SCI_MARGINSETSTYLES</code> has the offset added before looking up the style.
</p>
<p>
+ Always call <a class="message" href="#SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES</a>
+ before <code>SCI_MARGINSETSTYLEOFFSET</code> and use the result as the argument to <code>SCI_MARGINSETSTYLEOFFSET</code>.
+ </p>
+ <p>
<b id="SCI_SETMARGINOPTIONS">SCI_SETMARGINOPTIONS(int marginOptions)</b><br />
<b id="SCI_GETMARGINOPTIONS">SCI_GETMARGINOPTIONS</b><br />
Define margin options by enabling appropriate bit flags. At the moment, only one flag is available
@@ -3077,6 +3095,10 @@ struct Sci_TextToFind {
Each style number set with <code>SCI_ANNOTATIONSETSTYLE</code>
or <code>SCI_ANNOTATIONSETSTYLES</code> has the offset added before looking up the style.
</p>
+ <p>
+ Always call <a class="message" href="#SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES</a>
+ before <code>SCI_ANNOTATIONSETSTYLEOFFSET</code> and use the result as the argument to <code>SCI_ANNOTATIONSETSTYLEOFFSET</code>.
+ </p>
<h2 id="OtherSettings">Other settings</h2>
<code><a class="message" href="#SCI_SETUSEPALETTE">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<int>(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)