aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-03-29 08:25:51 +1100
committerNeil <nyamatongwe@gmail.com>2021-03-29 08:25:51 +1100
commitab70e1041cb40c9d807a18ca7abb5c000adf2fdf (patch)
tree709d60718e9cf33924a625f82ff7999494027f6f
parent508d037ed3389c5678addebefb62485ebfc10bb7 (diff)
downloadscintilla-mirror-ab70e1041cb40c9d807a18ca7abb5c000adf2fdf.tar.gz
Add SCI_SETELEMENTCOLOUR and related APIs to change colours of visible elements.
Implement SC_ELEMENT_LIST* to change colours of autocompletion lists.
-rw-r--r--cocoa/ScintillaCocoa.h1
-rw-r--r--doc/ScintillaHistory.html4
-rwxr-xr-xgtk/ScintillaGTK.cxx1
-rw-r--r--gtk/ScintillaGTKAccessible.cxx1
-rw-r--r--include/Scintilla.h9
-rw-r--r--include/Scintilla.iface27
-rw-r--r--qt/ScintillaEdit/ScintillaDocument.cpp1
-rw-r--r--qt/ScintillaEditBase/ScintillaQt.h1
-rw-r--r--scripts/HeaderOrder.txt1
-rw-r--r--src/EditModel.cxx1
-rw-r--r--src/EditView.cxx1
-rw-r--r--src/Editor.cxx18
-rw-r--r--src/MarginView.cxx1
-rw-r--r--src/Platform.h4
-rw-r--r--src/PositionCache.cxx1
-rw-r--r--src/ScintillaBase.cxx9
-rw-r--r--src/ViewStyle.cxx15
-rw-r--r--src/ViewStyle.h6
-rw-r--r--win32/PlatWin.cxx38
-rw-r--r--win32/ScintillaWin.cxx1
20 files changed, 129 insertions, 12 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 8ea0f410f..2474ca6f1 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
#include <map>
+#include <set>
#include <memory>
#include "ILoader.h"
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index c518cd60e..d8aea7a2a 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -608,6 +608,10 @@
Add shapes with curved and rounded ends to EOL annotations as EOLANNOTATION_*.
</li>
<li>
+ Add SCI_SETELEMENTCOLOUR and related APIs to change colours of visible elements.
+ Implement SC_ELEMENT_LIST* to change colours of autocompletion lists.
+ </li>
+ <li>
Change graphics coordinates from float (32-bit) to double (64-bit).
Fixes uneven line heights in large documents on Cocoa.
Increases memory use.
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 312ad1f94..09a389677 100755
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -17,6 +17,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
diff --git a/gtk/ScintillaGTKAccessible.cxx b/gtk/ScintillaGTKAccessible.cxx
index 1aceddb8b..3023e5102 100644
--- a/gtk/ScintillaGTKAccessible.cxx
+++ b/gtk/ScintillaGTKAccessible.cxx
@@ -62,6 +62,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index dd1dd78e4..1ea5d3fa1 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -267,6 +267,15 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_STYLEGETWEIGHT 2064
#define SCI_STYLESETCHARACTERSET 2066
#define SCI_STYLESETHOTSPOT 2409
+#define SC_ELEMENT_LIST 0
+#define SC_ELEMENT_LIST_BACK 1
+#define SC_ELEMENT_LIST_SELECTED 2
+#define SC_ELEMENT_LIST_SELECTED_BACK 3
+#define SCI_SETELEMENTCOLOUR 2753
+#define SCI_GETELEMENTCOLOUR 2754
+#define SCI_RESETELEMENTCOLOUR 2755
+#define SCI_GETELEMENTISSET 2756
+#define SCI_GETELEMENTALLOWSTRANSLUCENT 2757
#define SCI_SETSELFORE 2067
#define SCI_SETSELBACK 2068
#define SCI_GETSELALPHA 2477
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index d0b8213e8..8cce965cc 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -53,8 +53,8 @@
## bool -> integer, 1=true, 0=false
## position -> intptr_t position in a document
## line -> intptr_t line in a document
-## colour -> colour integer containing red, green, and blue bytes.
-## colouralpha -> colour integer containing red, green, blue, and alpha bytes.
+## colour -> colour integer containing red, green, and blue bytes with red as least-significant and blue as most.
+## colouralpha -> colour integer containing red, green, blue, and alpha bytes with red as least-significant and alpha as most.
## string -> pointer to const character
## stringresult -> pointer to character, NULL-> return size of result
## cells -> pointer to array of cells, each cell containing a style byte and character byte
@@ -665,6 +665,29 @@ set void StyleSetCharacterSet=2066(int style, CharacterSet characterSet)
# Set a style to be a hotspot or not.
set void StyleSetHotSpot=2409(int style, bool hotspot)
+enu Element=SC_ELEMENT_
+val SC_ELEMENT_LIST=0
+val SC_ELEMENT_LIST_BACK=1
+val SC_ELEMENT_LIST_SELECTED=2
+val SC_ELEMENT_LIST_SELECTED_BACK=3
+
+# Set the colour of an element. Translucency (alpha) may or may not be significant
+# and this may depend on the platform. The alpha byte should commonly be 0xff for opaque.
+set void SetElementColour=2753(Element element, colouralpha colourElement)
+
+# Get the colour of an element.
+get colouralpha GetElementColour=2754(Element element,)
+
+# Use the default or platform-defined colour for an element.
+fun void ResetElementColour=2755(Element element,)
+
+# Get whether an element has been set by SetElementColour.
+# When false, a platform-defined or default colour is used.
+get bool GetElementIsSet=2756(Element element,)
+
+# Get whether an element supports translucency.
+get bool GetElementAllowsTranslucent=2757(Element element,)
+
# Set the foreground colour of the main and additional selections and whether to use this setting.
fun void SetSelFore=2067(bool useSetting, colour fore)
diff --git a/qt/ScintillaEdit/ScintillaDocument.cpp b/qt/ScintillaEdit/ScintillaDocument.cpp
index daa212130..c1605dbd2 100644
--- a/qt/ScintillaEdit/ScintillaDocument.cpp
+++ b/qt/ScintillaEdit/ScintillaDocument.cpp
@@ -6,6 +6,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <memory>
diff --git a/qt/ScintillaEditBase/ScintillaQt.h b/qt/ScintillaEditBase/ScintillaQt.h
index 72d78f589..617635e55 100644
--- a/qt/ScintillaEditBase/ScintillaQt.h
+++ b/qt/ScintillaEditBase/ScintillaQt.h
@@ -24,6 +24,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
diff --git a/scripts/HeaderOrder.txt b/scripts/HeaderOrder.txt
index a5cb6a2e8..a45d798de 100644
--- a/scripts/HeaderOrder.txt
+++ b/scripts/HeaderOrder.txt
@@ -42,6 +42,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <forward_list>
#include <optional>
#include <algorithm>
diff --git a/src/EditModel.cxx b/src/EditModel.cxx
index 58b9306a2..11827c471 100644
--- a/src/EditModel.cxx
+++ b/src/EditModel.cxx
@@ -16,6 +16,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
diff --git a/src/EditView.cxx b/src/EditView.cxx
index f22b281c5..b2714f7ac 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -17,6 +17,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <forward_list>
#include <optional>
#include <algorithm>
diff --git a/src/Editor.cxx b/src/Editor.cxx
index ad56a8eb8..fa356fe15 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -17,6 +17,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <forward_list>
#include <optional>
#include <algorithm>
@@ -7185,6 +7186,23 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
InvalidateStyleRedraw();
break;
+ case SCI_SETELEMENTCOLOUR:
+ vs.elementColours[static_cast<int>(wParam)] = ColourAlpha(static_cast<int>(lParam));
+ break;
+
+ case SCI_GETELEMENTCOLOUR:
+ return vs.ElementColour(static_cast<int>(wParam)).value_or(ColourAlpha()).AsInteger();
+
+ case SCI_RESETELEMENTCOLOUR:
+ vs.elementColours[static_cast<int>(wParam)].reset();
+ break;
+
+ case SCI_GETELEMENTISSET:
+ return vs.ElementColour(static_cast<int>(wParam)).has_value();
+
+ case SCI_GETELEMENTALLOWSTRANSLUCENT:
+ return vs.ElementAllowsTranslucent(static_cast<int>(wParam));
+
#ifdef INCLUDE_DEPRECATED_FEATURES
case SCI_SETSTYLEBITS:
vs.EnsureStyle(0xff);
diff --git a/src/MarginView.cxx b/src/MarginView.cxx
index 7c7998e07..8b6f80695 100644
--- a/src/MarginView.cxx
+++ b/src/MarginView.cxx
@@ -17,6 +17,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
diff --git a/src/Platform.h b/src/Platform.h
index 98e6440aa..ffe52446c 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -304,6 +304,10 @@ public:
};
struct ListOptions {
+ std::optional<ColourAlpha> fore;
+ std::optional<ColourAlpha> back;
+ std::optional<ColourAlpha> foreSelected;
+ std::optional<ColourAlpha> backSelected;
};
class ListBox : public Window {
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 50858edd7..c9b886119 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -15,6 +15,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <iterator>
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 1e55fcfbf..e2fb58206 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -15,6 +15,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
@@ -260,6 +261,14 @@ void ScintillaBase::AutoCompleteStart(Sci::Position lenEntered, const char *list
ac.Start(wMain, idAutoComplete, sel.MainCaret(), PointMainCaret(),
lenEntered, vs.lineHeight, IsUnicodeMode(), technology);
+ ListOptions options{
+ vs.ElementColour(SC_ELEMENT_LIST),
+ vs.ElementColour(SC_ELEMENT_LIST_BACK),
+ vs.ElementColour(SC_ELEMENT_LIST_SELECTED),
+ vs.ElementColour(SC_ELEMENT_LIST_SELECTED_BACK)
+ };
+ ac.lb->SetOptions(options);
+
const PRectangle rcClient = GetClientRectangle();
Point pt = LocationFromPosition(sel.MainCaret() - lenEntered);
PRectangle rcPopupBounds = wMain.GetMonitorRect(pt);
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index d1f866906..6aa459895 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -13,6 +13,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
@@ -517,6 +518,20 @@ void ViewStyle::AddMultiEdge(uptr_t wParam, sptr_t lParam) {
EdgeProperties(column, lParam));
}
+std::optional<ColourAlpha> ViewStyle::ElementColour(int index) const noexcept {
+ auto search = elementColours.find(index);
+ if (search != elementColours.end()) {
+ if (search->second.has_value()) {
+ return search->second;
+ }
+ }
+ return {};
+}
+
+bool ViewStyle::ElementAllowsTranslucent(int index) const noexcept {
+ return elementAllowsTranslucent.count(index) > 0;
+}
+
bool ViewStyle::SetWrapState(int wrapState_) noexcept {
WrapMode wrapStateWanted;
switch (wrapState_) {
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index b07c34a08..d33feb485 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -158,6 +158,9 @@ public:
int ctrlCharPadding; // the padding around control character text blobs
int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs
+ std::map<int, std::optional<ColourAlpha>> elementColours;
+ std::set<int> elementAllowsTranslucent;
+
// Wrapping support
WrapMode wrapState;
int wrapVisualFlags;
@@ -195,6 +198,9 @@ public:
void AddMultiEdge(uptr_t wParam, sptr_t lParam);
+ std::optional<ColourAlpha> ElementColour(int index) const noexcept;
+ bool ElementAllowsTranslucent(int index) const noexcept;
+
bool SetWrapState(int wrapState_) noexcept;
bool SetWrapVisualFlags(int wrapVisualFlags_) noexcept;
bool SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation_) noexcept;
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 064871463..b2b188cb6 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -2934,7 +2934,7 @@ class ListBoxX : public ListBox {
void StartResize(WPARAM);
LRESULT NcHitTest(WPARAM, LPARAM) const;
void CentreItem(int n);
- void Paint(HDC) noexcept;
+ void Paint(HDC);
static LRESULT PASCAL ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
static constexpr Point ItemInset {0, 0}; // Padding around whole item
@@ -3141,6 +3141,24 @@ void ListBoxX::ClearRegisteredImages() {
images.Clear();
}
+namespace {
+
+int ColourOfElement(std::optional<ColourAlpha> colour, int nIndex) {
+ if (colour.has_value()) {
+ return colour.value().GetColour().AsInteger();
+ } else {
+ return ::GetSysColor(nIndex);
+ }
+}
+
+void FillRectColour(HDC hdc, const RECT *lprc, int colour) noexcept {
+ const HBRUSH brush = ::CreateSolidBrush(colour);
+ ::FillRect(hdc, lprc, brush);
+ ::DeleteObject(brush);
+}
+
+}
+
void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) {
if ((pDrawItem->itemAction == ODA_SELECT) || (pDrawItem->itemAction == ODA_DRAWENTIRE)) {
RECT rcBox = pDrawItem->rcItem;
@@ -3149,14 +3167,14 @@ void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) {
RECT rcImage = pDrawItem->rcItem;
rcImage.right = rcBox.left;
// The image is not highlighted
- ::FillRect(pDrawItem->hDC, &rcImage, reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
- ::FillRect(pDrawItem->hDC, &rcBox, reinterpret_cast<HBRUSH>(COLOR_HIGHLIGHT+1));
- ::SetBkColor(pDrawItem->hDC, ::GetSysColor(COLOR_HIGHLIGHT));
- ::SetTextColor(pDrawItem->hDC, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
+ FillRectColour(pDrawItem->hDC, &rcImage, ColourOfElement(options.back, COLOR_WINDOW));
+ FillRectColour(pDrawItem->hDC, &rcBox, ColourOfElement(options.backSelected, COLOR_HIGHLIGHT));
+ ::SetBkColor(pDrawItem->hDC, ColourOfElement(options.backSelected, COLOR_HIGHLIGHT));
+ ::SetTextColor(pDrawItem->hDC, ColourOfElement(options.foreSelected, COLOR_HIGHLIGHTTEXT));
} else {
- ::FillRect(pDrawItem->hDC, &pDrawItem->rcItem, reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
- ::SetBkColor(pDrawItem->hDC, ::GetSysColor(COLOR_WINDOW));
- ::SetTextColor(pDrawItem->hDC, ::GetSysColor(COLOR_WINDOWTEXT));
+ FillRectColour(pDrawItem->hDC, &pDrawItem->rcItem, ColourOfElement(options.back, COLOR_WINDOW));
+ ::SetBkColor(pDrawItem->hDC, ColourOfElement(options.back, COLOR_WINDOW));
+ ::SetTextColor(pDrawItem->hDC, ColourOfElement(options.fore, COLOR_WINDOWTEXT));
}
const ListItemData item = lti.Get(pDrawItem->itemID);
@@ -3503,7 +3521,7 @@ void ListBoxX::CentreItem(int n) {
}
// Performs a double-buffered paint operation to avoid flicker
-void ListBoxX::Paint(HDC hDC) noexcept {
+void ListBoxX::Paint(HDC hDC) {
const POINT extent = GetClientExtent();
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, extent.x, extent.y);
HDC bitmapDC = ::CreateCompatibleDC(hDC);
@@ -3512,7 +3530,7 @@ void ListBoxX::Paint(HDC hDC) noexcept {
// unpainted area when at the end of a non-integrally sized list with a
// vertical scroll bar
const RECT rc = { 0, 0, extent.x, extent.y };
- ::FillRect(bitmapDC, &rc, reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
+ FillRectColour(bitmapDC, &rc, ColourOfElement(options.back, COLOR_WINDOWTEXT));
// Paint the entire client area and vertical scrollbar
::SendMessage(lb, WM_PRINT, reinterpret_cast<WPARAM>(bitmapDC), PRF_CLIENT|PRF_NONCLIENT);
::BitBlt(hDC, 0, 0, extent.x, extent.y, bitmapDC, 0, 0, SRCCOPY);
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 4a8d1c5e9..8779a3c20 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -19,6 +19,7 @@
#include <string_view>
#include <vector>
#include <map>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>