diff options
author | Neil <nyamatongwe@gmail.com> | 2016-09-29 13:36:43 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2016-09-29 13:36:43 +1000 |
commit | de7dccbae50c839869017a30cd5e57d6ef639242 (patch) | |
tree | 6bedd6676770b1381104cddea9d4f0ff17ca5402 | |
parent | cfe3c049555422cbc7dcf3fd2fadad2f08487dd7 (diff) | |
download | scintilla-mirror-de7dccbae50c839869017a30cd5e57d6ef639242.tar.gz |
The number of margins can be changed with SCI_SETMARGINS.
-rw-r--r-- | doc/ScintillaDoc.html | 22 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 3 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 6 | ||||
-rw-r--r-- | src/EditView.cxx | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 18 | ||||
-rw-r--r-- | src/Editor.h | 1 | ||||
-rw-r--r-- | src/MarginView.cxx | 2 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 7 | ||||
-rw-r--r-- | src/ViewStyle.h | 2 |
10 files changed, 47 insertions, 20 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 3ebf00919..a4e5ef20c 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3132,10 +3132,12 @@ struct Sci_TextToFind { <h2 id="Margins">Margins</h2> - <p>There may be up to five margins, numbered 0 to <code>SC_MAX_MARGIN</code> (4) - to the left of the text display, plus a gap either side of - the text. Each margin can be set to display only symbols, line numbers, or text with <a - class="message" href="#SCI_SETMARGINTYPEN"><code>SCI_SETMARGINTYPEN</code></a>. + <p>There may be multiple margins to the left of the text display plus a gap either side of the text. + 5 margins are allocated initially numbered from 0 to <code>SC_MAX_MARGIN</code> (4) + but this may be changed by calling + <a class="message" href="#SCI_SETMARGINS"><code>SCI_SETMARGINS</code></a>. + Each margin can be set to display only symbols, line numbers, or text with + <a class="message" href="#SCI_SETMARGINTYPEN"><code>SCI_SETMARGINTYPEN</code></a>. Textual margins may also display symbols. The markers that can be displayed in each margin are set with <a class="message" @@ -3146,7 +3148,7 @@ struct Sci_TextToFind { href="#SCN_MARGINCLICK"><code>SCN_MARGINCLICK</code></a> notification to the container or selects a line of text.</p> - <p>The margins are numbered 0 to 4. Using a margin number outside the valid range has no + <p>Using a margin number outside the valid range has no effect. By default, margin 0 is set to display line numbers, but is given a width of 0, so it is hidden. Margin 1 is set to display non-folding symbols and is given a width of 16 pixels, so it is visible. Margin 2 is set to display the folding symbols, but is given a width of 0, so it @@ -3155,8 +3157,10 @@ struct Sci_TextToFind { <p>Styled text margins used to show revision and blame information:</p> <p><img src="styledmargin.png" alt="Styled text margins used to show revision and blame information" /></p> - <code><a class="message" href="#SCI_SETMARGINTYPEN">SCI_SETMARGINTYPEN(int margin, int - type)</a><br /> + <code> + <a class="message" href="#SCI_SETMARGINS">SCI_SETMARGINS(int margins)</a><br /> + <a class="message" href="#SCI_GETMARGINS">SCI_GETMARGINS</a><br /> + <a class="message" href="#SCI_SETMARGINTYPEN">SCI_SETMARGINTYPEN(int margin, int type)</a><br /> <a class="message" href="#SCI_GETMARGINTYPEN">SCI_GETMARGINTYPEN(int margin)</a><br /> <a class="message" href="#SCI_SETMARGINWIDTHN">SCI_SETMARGINWIDTHN(int margin, int pixelWidth)</a><br /> @@ -3195,6 +3199,10 @@ struct Sci_TextToFind { <a class="message" href="#SCI_GETMARGINOPTIONS">SCI_GETMARGINOPTIONS</a><br /> </code> +<p><b id="SCI_SETMARGINS">SCI_SETMARGINS(int margins)</b><br /> + <b id="SCI_GETMARGINS">SCI_GETMARGINS</b><br /> + Allocate the number of margins or find the number of margins currently allocated.</p> + <p><b id="SCI_SETMARGINTYPEN">SCI_SETMARGINTYPEN(int margin, int iType)</b><br /> <b id="SCI_GETMARGINTYPEN">SCI_GETMARGINTYPEN(int margin)</b><br /> These two routines set and get the type of a margin. The margin argument should be 0, 1, 2, 3 or 4. diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 96de2872e..9627ab5fe 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -531,6 +531,9 @@ vertical edges simultaneously. <li> <li> + The number of margins can be changed with SCI_SETMARGINS. + <li> + <li> Margin type SC_MARGIN_COLOUR added so that the application may choose any colour for a margin with SCI_SETMARGINBACKN. <li> diff --git a/include/Scintilla.h b/include/Scintilla.h index 77f4d5c7a..9fd519f6d 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -180,6 +180,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETMARGINCURSORN 2249 #define SCI_SETMARGINBACKN 2250 #define SCI_GETMARGINBACKN 2251 +#define SCI_SETMARGINS 2252 +#define SCI_GETMARGINS 2253 #define STYLE_DEFAULT 32 #define STYLE_LINENUMBER 33 #define STYLE_BRACELIGHT 34 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index fdc90807e..7aa00c201 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -398,6 +398,12 @@ set void SetMarginBackN=2250(int margin, colour back) # Retrieve the background colour of a margin get colour GetMarginBackN=2251(int margin,) +# Allocate a non-standard number of margins. +set void SetMargins=2252(int margins,) + +# How many margins are there?. +get int GetMargins=2253(,) + # Styles in range 32..38 are predefined for parts of the UI and are not used as normal styles. # Style 39 is for future use. enu StylesCommon=STYLE_ diff --git a/src/EditView.cxx b/src/EditView.cxx index 074c23fc9..92c341d8f 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1982,9 +1982,9 @@ long EditView::FormatRange(bool draw, Sci_RangeToFormat *pfr, Surface *surface, // Modify the view style for printing as do not normally want any of the transient features to be printed // Printing supports only the line number margin. int lineNumberIndex = -1; - for (int margin = 0; margin <= SC_MAX_MARGIN; margin++) { + for (size_t margin = 0; margin < vs.ms.size(); margin++) { if ((vsPrint.ms[margin].style == SC_MARGIN_NUMBER) && (vsPrint.ms[margin].width > 0)) { - lineNumberIndex = margin; + lineNumberIndex = static_cast<int>(margin); } else { vsPrint.ms[margin].width = 0; } diff --git a/src/Editor.cxx b/src/Editor.cxx index 0e686e101..9fcd01fbb 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2426,9 +2426,9 @@ void Editor::NotifyIndicatorClick(bool click, int position, bool shift, bool ctr bool Editor::NotifyMarginClick(Point pt, int modifiers) { int marginClicked = -1; int x = vs.textStart - vs.fixedColumnWidth; - for (int margin = 0; margin <= SC_MAX_MARGIN; margin++) { + for (size_t margin = 0; margin < vs.ms.size(); margin++) { if ((pt.x >= x) && (pt.x < x + vs.ms[margin].width)) - marginClicked = margin; + marginClicked = static_cast<int>(margin); x += vs.ms[margin].width; } if ((marginClicked >= 0) && vs.ms[marginClicked].sensitive) { @@ -4289,7 +4289,7 @@ bool Editor::PointInSelMargin(Point pt) const { Window::Cursor Editor::GetMarginCursor(Point pt) const { int x = 0; - for (int margin = 0; margin <= SC_MAX_MARGIN; margin++) { + for (size_t margin = 0; margin < vs.ms.size(); margin++) { if ((pt.x >= x) && (pt.x < x + vs.ms[margin].width)) return static_cast<Window::Cursor>(vs.ms[margin].cursor); x += vs.ms[margin].width; @@ -5569,8 +5569,8 @@ void Editor::AddStyledText(char *buffer, int appendLength) { SetEmptySelection(sel.MainCaret() + lengthInserted); } -static bool ValidMargin(uptr_t wParam) { - return wParam <= SC_MAX_MARGIN; +bool Editor::ValidMargin(uptr_t wParam) { + return wParam < vs.ms.size(); } static char *CharPtrFromSPtr(sptr_t lParam) { @@ -6897,6 +6897,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { else return 0; + case SCI_SETMARGINS: + if (wParam < 1000) + vs.ms.resize(wParam); + break; + + case SCI_GETMARGINS: + return vs.ms.size(); + case SCI_STYLECLEARALL: vs.ClearStyles(); InvalidateStyleRedraw(); diff --git a/src/Editor.h b/src/Editor.h index ee56700dd..5fdcbffb9 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -571,6 +571,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void AddStyledText(char *buffer, int appendLength); virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0; + bool ValidMargin(uptr_t wParam); void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); diff --git a/src/MarginView.cxx b/src/MarginView.cxx index ab8cbf4f8..3ec70f01e 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -193,7 +193,7 @@ void MarginView::PaintMargin(Surface *surface, int topLine, PRectangle rc, PRect Point ptOrigin = model.GetVisibleOriginInMain(); FontAlias fontLineNumber = vs.styles[STYLE_LINENUMBER].font; - for (int margin = 0; margin <= SC_MAX_MARGIN; margin++) { + for (size_t margin = 0; margin < vs.ms.size(); margin++) { if (vs.ms[margin].width > 0) { rcSelMargin.left = rcSelMargin.right; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 33be28422..58dbf167b 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -145,9 +145,7 @@ ViewStyle::ViewStyle(const ViewStyle &source) { someStylesForceCase = false; leftMarginWidth = source.leftMarginWidth; rightMarginWidth = source.rightMarginWidth; - for (int margin=0; margin <= SC_MAX_MARGIN; margin++) { - ms[margin] = source.ms[margin]; - } + ms = source.ms; maskInLine = source.maskInLine; maskDrawInText = source.maskDrawInText; fixedColumnWidth = source.fixedColumnWidth; @@ -196,7 +194,7 @@ void ViewStyle::CalculateMarginWidthAndMask() { fixedColumnWidth = marginInside ? leftMarginWidth : 0; maskInLine = 0xffffffff; int maskDefinedMarkers = 0; - for (int margin = 0; margin <= SC_MAX_MARGIN; margin++) { + for (size_t margin = 0; margin < ms.size(); margin++) { fixedColumnWidth += ms[margin].width; if (ms[margin].width > 0) maskInLine &= ~ms[margin].mask; @@ -280,6 +278,7 @@ void ViewStyle::Init(size_t stylesSize_) { leftMarginWidth = 1; rightMarginWidth = 1; + ms.resize(SC_MAX_MARGIN + 1); ms[0].style = SC_MARGIN_NUMBER; ms[0].width = 0; ms[0].mask = 0; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 7a2c26f63..3b812693e 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -127,7 +127,7 @@ public: int rightMarginWidth; ///< Spacing margin on right of text int maskInLine; ///< Mask for markers to be put into text because there is nowhere for them to go in margin int maskDrawInText; ///< Mask for markers that always draw in text - MarginStyle ms[SC_MAX_MARGIN+1]; + std::vector<MarginStyle> ms; int fixedColumnWidth; ///< Total width of margins bool marginInside; ///< true: margin included in text view, false: separate views int textStart; ///< Starting x position of text within the view |