diff options
author | Martijn Laan <unknown> | 2024-07-03 09:44:24 +1000 |
---|---|---|
committer | Martijn Laan <unknown> | 2024-07-03 09:44:24 +1000 |
commit | ed0aed7dc463ee5c0f2b7c0989e231cce2c835b8 (patch) | |
tree | 8126eeae8b3bee2a00b9a2df89a23c4f2763cb4f | |
parent | 2b69fbaf70f6a05269d96b2703acfe49ef7f03a1 (diff) | |
download | scintilla-mirror-ed0aed7dc463ee5c0f2b7c0989e231cce2c835b8.tar.gz |
Feature [feature-requests:#1523]. SCI_AUTOCSETSTYLE sets autocompletion font.
-rw-r--r-- | call/ScintillaCall.cxx | 8 | ||||
-rw-r--r-- | doc/ScintillaDoc.html | 18 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 6 | ||||
-rw-r--r-- | include/ScintillaCall.h | 2 | ||||
-rw-r--r-- | include/ScintillaMessages.h | 2 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 23 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 5 | ||||
-rw-r--r-- | src/ViewStyle.h | 1 | ||||
-rw-r--r-- | test/simpleTests.py | 4 |
11 files changed, 68 insertions, 7 deletions
diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index d6c9ece4d..8f48a5256 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -1095,6 +1095,14 @@ int ScintillaCall::AutoCGetMaxHeight() { return static_cast<int>(Call(Message::AutoCGetMaxHeight)); } +void ScintillaCall::AutoCSetStyle(int style) { + Call(Message::AutoCSetStyle, style); +} + +int ScintillaCall::AutoCGetStyle() { + return static_cast<int>(Call(Message::AutoCGetStyle)); +} + void ScintillaCall::SetIndent(int indentSize) { Call(Message::SetIndent, indentSize); } diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 8f9e22290..bc282f50f 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -667,15 +667,17 @@ <p><b id="SCI_RELEASEALLEXTENDEDSTYLES">SCI_RELEASEALLEXTENDEDSTYLES</b><br /> <b id="SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(int numberStyles) → int</b><br /> - Extended styles are used for features like textual margins and annotations as well as internally by Scintilla. + Extended styles are used for features like textual margins and annotations and autocompletion lists 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 margin and annotation styles should be allocated before calling + Ranges for margin, annotation, and autocompletion list styles should be allocated before calling <a class="seealso" href="#SCI_MARGINSETSTYLEOFFSET">SCI_MARGINSETSTYLEOFFSET</a> or - <a class="seealso" href="#SCI_ANNOTATIONSETSTYLEOFFSET">SCI_ANNOTATIONSETSTYLEOFFSET</a>.</p> + <a class="seealso" href="#SCI_ANNOTATIONSETSTYLEOFFSET">SCI_ANNOTATIONSETSTYLEOFFSET</a> or + <a class="seealso" href="#SCI_AUTOCSETSTYLE">SCI_AUTOCSETSTYLE</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> @@ -6508,6 +6510,16 @@ struct Sci_TextToFindFull { </p> <p> + <b id="SCI_AUTOCSETSTYLE">SCI_AUTOCSETSTYLE</b><br /> + <b id="SCI_AUTOCGETSTYLE">SCI_AUTOCGETSTYLE → int</b><br /> + + Get or set the style used by autocompletion lists to determine the font facename, size and character set used to display characters. Defaults + to <code><a class="message" href="#StyleDefinition">STYLE_DEFAULT</a></code>. Always call + <a class="seealso" href="#SCI_ALLOCATEEXTENDEDSTYLES">SCI_ALLOCATEEXTENDEDSTYLES(1)</a> before <code>SCI_AUTOCSETSTYLE</code> and use the + result as the argument to <code>SCI_AUTOCSETSTYLE</code> and <code>SCI_STYLESETFONT</code> and others. + </p> + + <p> <b id="SC_ELEMENT_LIST">SC_ELEMENT_LIST : colouralpha</b><br /> <b id="SC_ELEMENT_LIST_BACK">SC_ELEMENT_LIST_BACK : colouralpha</b><br /> <b id="SC_ELEMENT_LIST_SELECTED">SC_ELEMENT_LIST_SELECTED : colouralpha</b><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 049a9bd56..22cd4fe44 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -597,6 +597,10 @@ <a href="https://sourceforge.net/p/scintilla/feature-requests/1518/">Feature #1518</a>. </li> <li> + Can set font used for autocompletion lists with SCI_AUTOCSETSTYLE. + <a href="https://sourceforge.net/p/scintilla/feature-requests/1523/">Feature #1523</a>. + </li> + <li> Increase maximum zoom set interactively to +60 points. <a href="https://sourceforge.net/p/scintilla/feature-requests/1517/">Feature #1517</a>. </li> diff --git a/include/Scintilla.h b/include/Scintilla.h index c25dc5ed9..8ef2532c2 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -461,6 +461,8 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_AUTOCGETMAXWIDTH 2209 #define SCI_AUTOCSETMAXHEIGHT 2210 #define SCI_AUTOCGETMAXHEIGHT 2211 +#define SCI_AUTOCSETSTYLE 2109 +#define SCI_AUTOCGETSTYLE 2120 #define SCI_SETINDENT 2122 #define SCI_GETINDENT 2123 #define SCI_SETUSETABS 2124 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 4dec3579f..85ab84324 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1148,6 +1148,12 @@ set void AutoCSetMaxHeight=2210(int rowCount,) # Set the maximum height, in rows, of auto-completion and user lists. get int AutoCGetMaxHeight=2211(,) +# Set the style number used for auto-completion and user lists fonts. +set void AutoCSetStyle=2109(int style,) + +# Get the style number used for auto-completion and user lists fonts. +get int AutoCGetStyle=2120(,) + # Set the number of spaces used for one level of indentation. set void SetIndent=2122(int indentSize,) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index 5db9c38d7..201e31ecc 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -319,6 +319,8 @@ public: int AutoCGetMaxWidth(); void AutoCSetMaxHeight(int rowCount); int AutoCGetMaxHeight(); + void AutoCSetStyle(int style); + int AutoCGetStyle(); void SetIndent(int indentSize); int Indent(); void SetUseTabs(bool useTabs); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index a2e91c92f..ccaa2a8d6 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -244,6 +244,8 @@ enum class Message { AutoCGetMaxWidth = 2209, AutoCSetMaxHeight = 2210, AutoCGetMaxHeight = 2211, + AutoCSetStyle = 2109, + AutoCGetStyle = 2120, SetIndent = 2122, GetIndent = 2123, SetUseTabs = 2124, diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index c66a689b7..1b19802f9 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -10,6 +10,7 @@ #include <cstdint> #include <cassert> #include <cstring> +#include <cmath> #include <stdexcept> #include <string> @@ -273,8 +274,16 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list ac.options, }; + int lineHeight; + if (vs.autocStyle != StyleDefault) { + AutoSurface surfaceMeasure(this); + lineHeight = static_cast<int>(std::lround(surfaceMeasure->Height(vs.styles[vs.autocStyle].font.get()))); + } else { + lineHeight = vs.lineHeight; + } + ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(), - lenEntered, vs.lineHeight, IsUnicodeMode(), technology, options); + lenEntered, lineHeight, IsUnicodeMode(), technology, options); const PRectangle rcClient = GetClientRectangle(); Point pt = LocationFromPosition(sel.MainCaret() - lenEntered); @@ -307,8 +316,8 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list rcac.right = rcac.left + widthLB; rcac.bottom = static_cast<XYPOSITION>(std::min(static_cast<int>(rcac.top) + heightLB, static_cast<int>(rcPopupBounds.bottom))); ac.lb->SetPositionRelative(rcac, &wMain); - ac.lb->SetFont(vs.styles[StyleDefault].font.get()); - const int aveCharWidth = static_cast<int>(vs.styles[StyleDefault].aveCharWidth); + ac.lb->SetFont(vs.styles[vs.autocStyle].font.get()); + const int aveCharWidth = static_cast<int>(vs.styles[vs.autocStyle].aveCharWidth); ac.lb->SetAverageCharWidth(aveCharWidth); ac.lb->SetDelegate(this); @@ -941,6 +950,14 @@ sptr_t ScintillaBase::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::AutoCGetMaxWidth: return maxListWidth; + case Message::AutoCSetStyle: + vs.autocStyle = static_cast<int>(wParam); + InvalidateStyleRedraw(); + break; + + case Message::AutoCGetStyle: + return vs.autocStyle; + case Message::RegisterImage: ac.lb->RegisterImage(static_cast<int>(wParam), ConstCharPtrFromSPtr(lParam)); break; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index b22666cf0..f20645251 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -252,6 +252,8 @@ ViewStyle::ViewStyle(size_t stylesSize_) : ctrlCharPadding = 3; // +3 For a blank on front and rounded edge each side lastSegItalicsOffset = 2; + autocStyle = StyleDefault; + localeName = localeNameDefault; } @@ -792,7 +794,8 @@ FontRealised *ViewStyle::Find(const FontSpecification &fs) { void ViewStyle::FindMaxAscentDescent() noexcept { for (size_t i = 0; i < styles.size(); i++) { - if (i == StyleCallTip) + if (i == StyleCallTip || + (autocStyle != StyleDefault && i == static_cast<size_t>(autocStyle))) continue; const auto &style = styles[i]; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 19a853121..6985e3f03 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -179,6 +179,7 @@ public: int marginNumberPadding; // the right-side padding of the number margin int ctrlCharPadding; // the padding around control character text blobs int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs + int autocStyle; using ElementMap = std::map<Scintilla::Element, ColourOptional>; ElementMap elementColours; diff --git a/test/simpleTests.py b/test/simpleTests.py index afd7de328..67d8d4749 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -3106,6 +3106,10 @@ class TestAutoComplete(unittest.TestCase): self.assertEqual(self.ed.AutoCGetDropRestOfWord(), 1) self.ed.AutoCSetDropRestOfWord(0) + self.ed.AutoCSetStyle(13) + self.assertEqual(self.ed.AutoCGetStyle(), 13) + self.ed.AutoCSetStyle(self.ed.STYLE_DEFAULT) + def testAutoShow(self): self.assertEqual(self.ed.AutoCActive(), 0) self.ed.SetSel(0, 0) |