From ad0162453e48fb729d1793eca40ac137e1e3451e Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 17 Jul 2021 14:54:31 +1000 Subject: Add SCI_AUTOCSETOPTIONS to allow choosing a non-resizeable autocompletion list on Win32. This also avoids a header rectangle above the list. --- call/ScintillaCall.cxx | 8 ++++++++ doc/ScintillaDoc.html | 40 +++++++++++++++++++++++++++++++++++++++- doc/ScintillaHistory.html | 5 +++++ include/Scintilla.h | 4 ++++ include/Scintilla.iface | 12 ++++++++++++ include/ScintillaCall.h | 2 ++ include/ScintillaMessages.h | 2 ++ include/ScintillaTypes.h | 5 +++++ src/AutoComplete.cxx | 4 +++- src/AutoComplete.h | 4 +++- src/Platform.h | 1 + src/ScintillaBase.cxx | 16 ++++++++++++---- win32/PlatWin.cxx | 12 +++++++----- 13 files changed, 103 insertions(+), 12 deletions(-) diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index bec5ccfed..23de3f004 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -936,6 +936,14 @@ bool ScintillaCall::AutoCGetAutoHide() { return Call(Message::AutoCGetAutoHide); } +void ScintillaCall::AutoCSetOptions(Scintilla::AutoCompleteOption options) { + Call(Message::AutoCSetOptions, static_cast(options)); +} + +AutoCompleteOption ScintillaCall::AutoCGetOptions() { + return static_cast(Call(Message::AutoCGetOptions)); +} + void ScintillaCall::AutoCSetDropRestOfWord(bool dropRestOfWord) { Call(Message::AutoCSetDropRestOfWord, dropRestOfWord); } diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 03fe95ea9..531fca5aa 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -128,7 +128,7 @@

Scintilla Documentation

-

Last edited 25 June 2021 NH

+

Last edited 17 July 2021 NH

Scintilla 5 has moved the lexers from Scintilla into a new Lexilla project.
@@ -5741,6 +5741,8 @@ struct Sci_TextToFind { SCI_AUTOCSETDROPRESTOFWORD(bool dropRestOfWord)
SCI_AUTOCGETDROPRESTOFWORD → bool
+ SCI_AUTOCSETOPTIONS(int options)
+ SCI_AUTOCGETOPTIONS → int
SCI_REGISTERIMAGE(int type, const char *xpmData)
SCI_REGISTERRGBAIMAGE(int type, const char *pixels)
SCI_CLEARREGISTEREDIMAGES
@@ -5887,6 +5889,42 @@ struct Sci_TextToFind { When an item is selected, any word characters following the caret are first erased if dropRestOfWord is set true. The default is false.

+

SCI_AUTOCSETOPTIONS(int options)
+ SCI_AUTOCGETOPTIONS → int
+ Set options for autocompletion from the following list.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SymbolValuePurpose
SC_AUTOCOMPLETE_NORMAL0Display autocompletion using default settings.
SC_AUTOCOMPLETE_FIXED_SIZE1On Win32 only, use a fixed size list instead of one that can be resized by the user. + This also avoids a header rectangle above the list.
+

SCI_REGISTERIMAGE(int type, const char *xpmData)
SCI_REGISTERRGBAIMAGE(int type, const char *pixels)
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 84710410d..8fddafc03 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -590,6 +590,11 @@ Feature #1370.

  • + Add SCI_AUTOCSETOPTIONS to allow choosing a non-resizeable autocompletion list + on Win32. + Feature #1284. +
  • +
  • On Win32, when technology is changed, buffering is set to a reasonable value for the technology: on for GDI and off for Direct2D as Direct2D performs its own buffering. Feature #1400. diff --git a/include/Scintilla.h b/include/Scintilla.h index 088abc0d8..97fbd3be0 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -405,6 +405,10 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_USERLISTSHOW 2117 #define SCI_AUTOCSETAUTOHIDE 2118 #define SCI_AUTOCGETAUTOHIDE 2119 +#define SC_AUTOCOMPLETE_NORMAL 0 +#define SC_AUTOCOMPLETE_FIXED_SIZE 1 +#define SCI_AUTOCSETOPTIONS 2638 +#define SCI_AUTOCGETOPTIONS 2639 #define SCI_AUTOCSETDROPRESTOFWORD 2270 #define SCI_AUTOCGETDROPRESTOFWORD 2271 #define SCI_REGISTERIMAGE 2405 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index b59cda663..cc7dedf36 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1009,6 +1009,18 @@ set void AutoCSetAutoHide=2118(bool autoHide,) # Retrieve whether or not autocompletion is hidden automatically when nothing matches. get bool AutoCGetAutoHide=2119(,) +# Define option flags for autocompletion lists +enu AutoCompleteOption=SC_AUTOCOMPLETE_ +val SC_AUTOCOMPLETE_NORMAL=0 +# Win32 specific: +val SC_AUTOCOMPLETE_FIXED_SIZE=1 + +# Set autocompletion options. +set void AutoCSetOptions=2638(AutoCompleteOption options,) + +# Retrieve autocompletion options. +get AutoCompleteOption AutoCGetOptions=2639(,) + # Set whether or not autocompletion deletes any word characters # after the inserted text upon completion. set void AutoCSetDropRestOfWord=2270(bool dropRestOfWord,) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index e0cfdd052..098b9ec1d 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -274,6 +274,8 @@ public: void UserListShow(int listType, const char *itemList); void AutoCSetAutoHide(bool autoHide); bool AutoCGetAutoHide(); + void AutoCSetOptions(Scintilla::AutoCompleteOption options); + Scintilla::AutoCompleteOption AutoCGetOptions(); void AutoCSetDropRestOfWord(bool dropRestOfWord); bool AutoCGetDropRestOfWord(); void RegisterImage(int type, const char *xpmData); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index a0c641a39..9293a5a6b 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -210,6 +210,8 @@ enum class Message { UserListShow = 2117, AutoCSetAutoHide = 2118, AutoCGetAutoHide = 2119, + AutoCSetOptions = 2638, + AutoCGetOptions = 2639, AutoCSetDropRestOfWord = 2270, AutoCGetDropRestOfWord = 2271, RegisterImage = 2405, diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index ca0a07527..830ccadba 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -230,6 +230,11 @@ enum class IndicFlag { ValueFore = 1, }; +enum class AutoCompleteOption { + Normal = 0, + FixedSize = 1, +}; + enum class IndentView { None = 0, Real = 1, diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index fec0f20e9..87077e92a 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -39,6 +39,7 @@ AutoComplete::AutoComplete() : typesep('?'), ignoreCase(false), chooseSingle(false), + options(AutoCompleteOption::Normal), posStart(0), startLen(0), cancelAtStartPos(true), @@ -63,10 +64,11 @@ bool AutoComplete::Active() const noexcept { void AutoComplete::Start(Window &parent, int ctrlID, Sci::Position position, Point location, Sci::Position startLen_, - int lineHeight, bool unicodeMode, Technology technology) { + int lineHeight, bool unicodeMode, Technology technology, ListOptions listOptions) { if (active) { Cancel(); } + lb->SetOptions(listOptions); lb->Create(parent, ctrlID, location, lineHeight, unicodeMode, technology); lb->Clear(); active = true; diff --git a/src/AutoComplete.h b/src/AutoComplete.h index c46530771..fa8f57287 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -25,6 +25,7 @@ public: bool ignoreCase; bool chooseSingle; + AutoCompleteOption options; std::unique_ptr lb; Sci::Position posStart; Sci::Position startLen; @@ -49,7 +50,8 @@ public: /// Display the auto completion list positioned to be near a character position void Start(Window &parent, int ctrlID, Sci::Position position, Point location, - Sci::Position startLen_, int lineHeight, bool unicodeMode, Scintilla::Technology technology); + Sci::Position startLen_, int lineHeight, bool unicodeMode, Scintilla::Technology technology, + ListOptions listOptions); /// The stop chars are characters which, when typed, cause the auto completion list to disappear void SetStopChars(const char *stopChars_); diff --git a/src/Platform.h b/src/Platform.h index 10c63dd23..ce04d9b22 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -313,6 +313,7 @@ struct ListOptions { std::optional back; std::optional foreSelected; std::optional backSelected; + AutoCompleteOption options=AutoCompleteOption::Normal; }; class ListBox : public Window { diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 0adca2f6f..238299734 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -257,16 +257,17 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list return; } } - ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(), - lenEntered, vs.lineHeight, IsUnicodeMode(), technology); ListOptions options{ vs.ElementColour(Element::List), vs.ElementColour(Element::ListBack), vs.ElementColour(Element::ListSelected), - vs.ElementColour(Element::ListSelectedBack) + vs.ElementColour(Element::ListSelectedBack), + ac.options, }; - ac.lb->SetOptions(options); + + ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(), + lenEntered, vs.lineHeight, IsUnicodeMode(), technology, options); const PRectangle rcClient = GetClientRectangle(); Point pt = LocationFromPosition(sel.MainCaret() - lenEntered); @@ -942,6 +943,13 @@ sptr_t ScintillaBase::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::AutoCGetAutoHide: return ac.autoHide; + case Message::AutoCSetOptions: + ac.options = static_cast(wParam); + break; + + case Message::AutoCGetOptions: + return static_cast(ac.options); + case Message::AutoCSetDropRestOfWord: ac.dropRestOfWord = wParam != 0; break; diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 371edc957..3e966b4d3 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2932,10 +2932,11 @@ class ListBoxX : public ListBox { Point location; // Caret location at which the list is opened int wheelDelta; // mouse wheel residue ListOptions options; + DWORD frameStyle = WS_THICKFRAME; HWND GetHWND() const noexcept; void AppendListItem(const char *text, const char *numword); - static void AdjustWindowRect(PRectangle *rc, UINT dpi) noexcept; + void AdjustWindowRect(PRectangle *rc, UINT dpiAdjust) const noexcept; int ItemHeight() const; int MinClientWidth() const noexcept; int TextOffset() const; @@ -3014,7 +3015,7 @@ void ListBoxX::Create(Window &parent_, int ctrlID_, Point location_, int lineHei // Window created as popup so not clipped within parent client area wid = ::CreateWindowEx( WS_EX_WINDOWEDGE, ListBoxX_ClassName, TEXT(""), - WS_POPUP | WS_THICKFRAME, + WS_POPUP | frameStyle, 100,100, 150,80, hwndParent, NULL, hinstanceParent, @@ -3318,14 +3319,15 @@ void ListBoxX::SetList(const char *list, char separator, char typesep) { void ListBoxX::SetOptions(ListOptions options_) { options = options_; + frameStyle = FlagSet(options.options, AutoCompleteOption::FixedSize) ? WS_BORDER : WS_THICKFRAME; } -void ListBoxX::AdjustWindowRect(PRectangle *rc, UINT dpi) noexcept { +void ListBoxX::AdjustWindowRect(PRectangle *rc, UINT dpiAdjust) const noexcept { RECT rcw = RectFromPRectangle(*rc); if (fnAdjustWindowRectExForDpi) { - fnAdjustWindowRectExForDpi(&rcw, WS_THICKFRAME, false, WS_EX_WINDOWEDGE, dpi); + fnAdjustWindowRectExForDpi(&rcw, frameStyle, false, WS_EX_WINDOWEDGE, dpiAdjust); } else { - ::AdjustWindowRectEx(&rcw, WS_THICKFRAME, false, WS_EX_WINDOWEDGE); + ::AdjustWindowRectEx(&rcw, frameStyle, false, WS_EX_WINDOWEDGE); } *rc = PRectangle::FromInts(rcw.left, rcw.top, rcw.right, rcw.bottom); } -- cgit v1.2.3