From 002f1a013736a89223dc1ede2724f8492e12ce1f Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 11 May 2021 10:06:28 +1000 Subject: Implement SCI_GETELEMENTBASECOLOUR to return the default values for element colours. --- doc/ScintillaDoc.html | 15 ++++++++++++++- doc/ScintillaHistory.html | 3 +++ include/Scintilla.h | 1 + include/Scintilla.iface | 3 +++ src/Editor.cxx | 3 +++ test/simpleTests.py | 28 ++++++++++++++++++++++------ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 7e120c44c..fcce51dd0 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -128,7 +128,7 @@

Scintilla Documentation

-

Last edited 10 May 2021 NH

+

Last edited 11 May 2021 NH

Scintilla 5 has moved the lexers from Scintilla into a new Lexilla project.
@@ -3247,6 +3247,7 @@ struct Sci_TextToFind { SCI_RESETELEMENTCOLOUR(int element)
SCI_GETELEMENTISSET(int element) → bool
SCI_GETELEMENTALLOWSTRANSLUCENT(int element) → bool
+ SCI_GETELEMENTBASECOLOUR(int element) → colouralpha

@@ -3275,6 +3276,18 @@ struct Sci_TextToFind { and newer versions of Scintilla may implement translucency for elements that did not previously support it.

+

+ SCI_GETELEMENTBASECOLOUR(int element) → colouralpha
+ Returns the default colour of an element. + This may be a value defined by Scintilla or it may be derived from the operating system or platform. + Which values are set from the operating system may differ between operating systems and operating system versions. + When undefined the return value is 0 which is equivalent to completely transparent black. + These colours may be useful when defining styles with similarities such as synthesizing dark + mode styles that use the same colours as the system

+

On Win32, autocompletion list colours like SC_ELEMENT_LIST are currently available. + On Cocoa, selection background colours like SC_ELEMENT_SELECTION_BACK are currently available. +

+ diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index bf43a17b6..64260aa88 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -586,6 +586,9 @@ translucently over text or opaquely underneath other drawing.
  • + Add SCI_GETELEMENTBASECOLOUR to return the default values for element colours. +
  • +
  • Make idle actions wrapping and background styling smoother by measuring per-byte instead of per-line and allowing just one line to be processed in a time slice. diff --git a/include/Scintilla.h b/include/Scintilla.h index 1a352ae85..820dc470a 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -289,6 +289,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_RESETELEMENTCOLOUR 2755 #define SCI_GETELEMENTISSET 2756 #define SCI_GETELEMENTALLOWSTRANSLUCENT 2757 +#define SCI_GETELEMENTBASECOLOUR 2758 #define SCI_SETSELFORE 2067 #define SCI_SETSELBACK 2068 #define SCI_GETSELALPHA 2477 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index ac5a72346..a51c0d611 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -705,6 +705,9 @@ get bool GetElementIsSet=2756(Element element,) # Get whether an element supports translucency. get bool GetElementAllowsTranslucent=2757(Element element,) +# Get the colour of an element. +get colouralpha GetElementBaseColour=2758(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/src/Editor.cxx b/src/Editor.cxx index 17749d799..458d34ccf 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7212,6 +7212,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETELEMENTALLOWSTRANSLUCENT: return vs.ElementAllowsTranslucent(static_cast(wParam)); + case SCI_GETELEMENTBASECOLOUR: + return vs.elementBaseColours[static_cast(wParam)].value_or(ColourAlpha()).AsInteger(); + case SCI_SETFONTLOCALE: if (lParam) { vs.SetFontLocaleName(CharPtrFromSPtr(lParam)); diff --git a/test/simpleTests.py b/test/simpleTests.py index d6c00170c..0f3516553 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1938,7 +1938,7 @@ class TestElements(unittest.TestCase): pass def testIsSet(self): - self.assertEquals(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_LIST), 0) + self.assertEquals(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_SELECTION_TEXT), 0) def testAllowsTranslucent(self): self.assertEquals(self.ed.GetElementAllowsTranslucent(self.ed.SC_ELEMENT_LIST), 0) @@ -1950,11 +1950,27 @@ class TestElements(unittest.TestCase): self.assertEquals(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_LIST_BACK), 1) def testReset(self): - self.ed.SetElementColour(self.ed.SC_ELEMENT_LIST_BACK, self.testColourAlpha) - self.assertEquals(self.ed.GetElementColour(self.ed.SC_ELEMENT_LIST_BACK), self.testColourAlpha) - self.ed.ResetElementColour(self.ed.SC_ELEMENT_LIST_BACK) - self.assertEquals(self.ed.GetElementColour(self.ed.SC_ELEMENT_LIST_BACK), 0) - self.assertEquals(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_LIST_BACK), 0) + self.ed.SetElementColour(self.ed.SC_ELEMENT_SELECTION_ADDITIONAL_TEXT, self.testColourAlpha) + self.assertEquals(self.ed.GetElementColour(self.ed.SC_ELEMENT_SELECTION_ADDITIONAL_TEXT), self.testColourAlpha) + self.ed.ResetElementColour(self.ed.SC_ELEMENT_SELECTION_ADDITIONAL_TEXT) + self.assertEquals(self.ed.GetElementColour(self.ed.SC_ELEMENT_SELECTION_ADDITIONAL_TEXT), 0) + self.assertEquals(self.ed.GetElementIsSet(self.ed.SC_ELEMENT_SELECTION_ADDITIONAL_TEXT), 0) + + def testBaseColour(self): + if sys.platform == "win32": + # SC_ELEMENT_LIST* base colours only currently implemented on Win32 + opaque = 0xff000000 + dropAlpha = 0x00ffffff + text = self.ed.GetElementBaseColour(self.ed.SC_ELEMENT_LIST) + back = self.ed.GetElementBaseColour(self.ed.SC_ELEMENT_LIST_BACK) + self.assertEquals(text & opaque, opaque) + self.assertEquals(back & opaque, opaque) + self.assertNotEquals(text & dropAlpha, back & dropAlpha) + selText = self.ed.GetElementBaseColour(self.ed.SC_ELEMENT_LIST_SELECTED) + selBack = self.ed.GetElementBaseColour(self.ed.SC_ELEMENT_LIST_SELECTED_BACK) + self.assertEquals(selText & opaque, opaque) + self.assertEquals(selBack & opaque, opaque) + self.assertNotEquals(selText & dropAlpha, selBack & dropAlpha) class TestIndices(unittest.TestCase): def setUp(self): -- cgit v1.2.3