1 // Scintilla source code edit control
3 ** Interface to platform facilities. Also includes some basic utilities.
4 ** Implemented in PlatGTK.cxx for GTK+/Linux, PlatWin.cxx for Windows, and PlatWX.cxx for wxWindows.
6 // Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
12 // PLAT_GTK = GTK+ on Linux or Win32
13 // PLAT_GTK_WIN32 is defined additionally when running PLAT_GTK under Win32
14 // PLAT_WIN = Win32 API on Win32 OS
15 // PLAT_WX is wxWindows on any supported platform
16 // PLAT_TK = Tcl/TK on Linux or Win32
19 #define PLAT_GTK_WIN32 0
20 #define PLAT_GTK_MACOSX 0
43 #elif defined(__HAIKU__)
47 #elif defined(SCINTILLA_QT)
51 #elif defined(SCINTILLA_QT_QML)
63 #if defined(__WIN32__) || defined(_MSC_VER)
65 #define PLAT_GTK_WIN32 1
68 #if defined(__APPLE__)
69 #undef PLAT_GTK_MACOSX
70 #define PLAT_GTK_MACOSX 1
73 #elif defined(__APPLE__)
84 namespace Scintilla::Internal
{
86 // Underlying the implementation of the platform classes are platform specific types.
87 // Sometimes these need to be passed around by client code so they are defined here
89 typedef void *SurfaceID
;
90 typedef void *WindowID
;
92 typedef void *TickerID
;
93 typedef void *Function
;
94 typedef void *IdlerID
;
100 constexpr const char *localeNameDefault
= "en-us";
102 struct FontParameters
{
103 const char *faceName
;
105 Scintilla::FontWeight weight
;
107 Scintilla::FontQuality extraFontFlag
;
108 Scintilla::Technology technology
;
109 Scintilla::CharacterSet characterSet
;
110 const char *localeName
;
112 constexpr FontParameters(
113 const char *faceName_
,
115 Scintilla::FontWeight weight_
= Scintilla::FontWeight::Normal
,
117 Scintilla::FontQuality extraFontFlag_
= Scintilla::FontQuality::QualityDefault
,
118 Scintilla::Technology technology_
= Scintilla::Technology::Default
,
119 Scintilla::CharacterSet characterSet_
= Scintilla::CharacterSet::Ansi
,
120 const char *localeName_
=localeNameDefault
) noexcept
:
126 extraFontFlag(extraFontFlag_
),
127 technology(technology_
),
128 characterSet(characterSet_
),
129 localeName(localeName_
)
137 Font() noexcept
= default;
138 // Deleted so Font objects can not be copied
139 Font(const Font
&) = delete;
140 Font(Font
&&) = delete;
141 Font
&operator=(const Font
&) = delete;
142 Font
&operator=(Font
&&) = delete;
143 virtual ~Font() noexcept
= default;
145 static std::shared_ptr
<Font
> Allocate(const FontParameters
&fp
);
150 virtual std::string_view
Text() const = 0;
151 virtual size_t Length() const = 0;
152 virtual size_t RepresentationCount() const = 0;
153 virtual XYPOSITION
Width() const = 0;
154 virtual XYPOSITION
Height() const = 0;
155 virtual XYPOSITION
TabWidth() const = 0;
156 virtual XYPOSITION
TabWidthMinimumPixels() const = 0;
157 virtual const Font
*FontOfPosition(size_t position
) const = 0;
158 virtual XYPOSITION
RepresentationWidth(size_t position
) const = 0;
159 virtual XYPOSITION
TabPositionAfter(XYPOSITION xPosition
) const = 0;
162 class IScreenLineLayout
{
164 virtual ~IScreenLineLayout() noexcept
= default;
165 virtual size_t PositionFromX(XYPOSITION xDistance
, bool charPosition
) = 0;
166 virtual XYPOSITION
XFromPosition(size_t caretPosition
) = 0;
167 virtual std::vector
<Interval
> FindRangeIntervals(size_t start
, size_t end
) = 0;
171 * Parameters for surfaces.
175 bool bidiR2L
= false;
176 SurfaceMode() = default;
177 explicit SurfaceMode(int codePage_
, bool bidiR2L_
) noexcept
: codePage(codePage_
), bidiR2L(bidiR2L_
) {
182 * A surface abstracts a place to draw.
186 Surface() noexcept
= default;
187 Surface(const Surface
&) = delete;
188 Surface(Surface
&&) = delete;
189 Surface
&operator=(const Surface
&) = delete;
190 Surface
&operator=(Surface
&&) = delete;
191 virtual ~Surface() noexcept
= default;
192 static std::unique_ptr
<Surface
> Allocate(Scintilla::Technology technology
);
194 virtual void Init(WindowID wid
)=0;
195 virtual void Init(SurfaceID sid
, WindowID wid
)=0;
196 virtual std::unique_ptr
<Surface
> AllocatePixMap(int width
, int height
)=0;
198 virtual void SetMode(SurfaceMode mode
)=0;
208 virtual void Release() noexcept
=0;
209 virtual int SupportsFeature(Scintilla::Supports feature
) noexcept
=0;
210 virtual bool Initialised()=0;
211 virtual int LogPixelsY()=0;
212 virtual int PixelDivisions()=0;
213 virtual int DeviceHeightFont(int points
)=0;
214 virtual void LineDraw(Point start
, Point end
, Stroke stroke
)=0;
215 virtual void PolyLine(const Point
*pts
, size_t npts
, Stroke stroke
)=0;
216 virtual void Polygon(const Point
*pts
, size_t npts
, FillStroke fillStroke
)=0;
217 virtual void RectangleDraw(PRectangle rc
, FillStroke fillStroke
)=0;
218 virtual void RectangleFrame(PRectangle rc
, Stroke stroke
)=0;
219 virtual void FillRectangle(PRectangle rc
, Fill fill
)=0;
220 virtual void FillRectangleAligned(PRectangle rc
, Fill fill
)=0;
221 virtual void FillRectangle(PRectangle rc
, Surface
&surfacePattern
)=0;
222 virtual void RoundedRectangle(PRectangle rc
, FillStroke fillStroke
)=0;
223 virtual void AlphaRectangle(PRectangle rc
, XYPOSITION cornerSize
, FillStroke fillStroke
)=0;
224 enum class GradientOptions
{ leftToRight
, topToBottom
};
225 virtual void GradientRectangle(PRectangle rc
, const std::vector
<ColourStop
> &stops
, GradientOptions options
)=0;
226 virtual void DrawRGBAImage(PRectangle rc
, int width
, int height
, const unsigned char *pixelsImage
) = 0;
227 virtual void Ellipse(PRectangle rc
, FillStroke fillStroke
)=0;
228 virtual void Stadium(PRectangle rc
, FillStroke fillStroke
, Ends ends
)=0;
229 virtual void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
)=0;
231 virtual std::unique_ptr
<IScreenLineLayout
> Layout(const IScreenLine
*screenLine
) = 0;
233 virtual void DrawTextNoClip(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
, ColourRGBA back
) = 0;
234 virtual void DrawTextClipped(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
, ColourRGBA back
) = 0;
235 virtual void DrawTextTransparent(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
) = 0;
236 virtual void MeasureWidths(const Font
*font_
, std::string_view text
, XYPOSITION
*positions
) = 0;
237 virtual XYPOSITION
WidthText(const Font
*font_
, std::string_view text
) = 0;
239 virtual void DrawTextNoClipUTF8(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
, ColourRGBA back
) = 0;
240 virtual void DrawTextClippedUTF8(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
, ColourRGBA back
) = 0;
241 virtual void DrawTextTransparentUTF8(PRectangle rc
, const Font
*font_
, XYPOSITION ybase
, std::string_view text
, ColourRGBA fore
) = 0;
242 virtual void MeasureWidthsUTF8(const Font
*font_
, std::string_view text
, XYPOSITION
*positions
) = 0;
243 virtual XYPOSITION
WidthTextUTF8(const Font
*font_
, std::string_view text
) = 0;
245 virtual XYPOSITION
Ascent(const Font
*font_
)=0;
246 virtual XYPOSITION
Descent(const Font
*font_
)=0;
247 virtual XYPOSITION
InternalLeading(const Font
*font_
)=0;
248 virtual XYPOSITION
Height(const Font
*font_
)=0;
249 virtual XYPOSITION
AverageCharWidth(const Font
*font_
)=0;
251 virtual void SetClip(PRectangle rc
)=0;
252 virtual void PopClip()=0;
253 virtual void FlushCachedState()=0;
254 virtual void FlushDrawing()=0;
258 * Class to hide the details of window manipulation.
259 * Does not own the window which will normally have a longer life than this object.
265 Window() noexcept
: wid(nullptr), cursorLast(Cursor::invalid
) {
267 Window(const Window
&source
) = delete;
268 Window(Window
&&) = delete;
269 Window
&operator=(WindowID wid_
) noexcept
{
271 cursorLast
= Cursor::invalid
;
274 Window
&operator=(const Window
&) = delete;
275 Window
&operator=(Window
&&) = delete;
276 virtual ~Window() noexcept
;
277 WindowID
GetID() const noexcept
{ return wid
; }
278 bool Created() const noexcept
{ return wid
!= nullptr; }
279 void Destroy() noexcept
;
280 PRectangle
GetPosition() const;
281 void SetPosition(PRectangle rc
);
282 void SetPositionRelative(PRectangle rc
, const Window
*relativeTo
);
283 PRectangle
GetClientPosition() const;
284 void Show(bool show
=true);
285 void InvalidateAll();
286 void InvalidateRectangle(PRectangle rc
);
287 enum class Cursor
{ invalid
, text
, arrow
, up
, wait
, horizontal
, vertical
, reverseArrow
, hand
};
288 void SetCursor(Cursor curs
);
289 PRectangle
GetMonitorRect(Point pt
);
295 * Listbox management.
298 // ScintillaBase implements IListBoxDelegate to receive ListBoxEvents from a ListBox
300 struct ListBoxEvent
{
301 enum class EventType
{ selectionChange
, doubleClick
} event
;
302 ListBoxEvent(EventType event_
) noexcept
: event(event_
) {
306 class IListBoxDelegate
{
308 virtual void ListNotify(ListBoxEvent
*plbe
)=0;
312 std::optional
<ColourRGBA
> fore
;
313 std::optional
<ColourRGBA
> back
;
314 std::optional
<ColourRGBA
> foreSelected
;
315 std::optional
<ColourRGBA
> backSelected
;
316 AutoCompleteOption options
=AutoCompleteOption::Normal
;
319 class ListBox
: public Window
{
322 ~ListBox() noexcept override
;
323 static std::unique_ptr
<ListBox
> Allocate();
325 virtual void SetFont(const Font
*font
)=0;
326 virtual void Create(Window
&parent
, int ctrlID
, Point location
, int lineHeight_
, bool unicodeMode_
, Scintilla::Technology technology_
)=0;
327 virtual void SetAverageCharWidth(int width
)=0;
328 virtual void SetVisibleRows(int rows
)=0;
329 virtual int GetVisibleRows() const=0;
330 virtual PRectangle
GetDesiredRect()=0;
331 virtual int CaretFromEdge()=0;
332 virtual void Clear() noexcept
=0;
333 virtual void Append(char *s
, int type
= -1)=0;
334 virtual int Length()=0;
335 virtual void Select(int n
)=0;
336 virtual int GetSelection()=0;
337 virtual int Find(const char *prefix
)=0;
338 virtual std::string
GetValue(int n
)=0;
339 virtual void RegisterImage(int type
, const char *xpm_data
)=0;
340 virtual void RegisterRGBAImage(int type
, int width
, int height
, const unsigned char *pixelsImage
) = 0;
341 virtual void ClearRegisteredImages()=0;
342 virtual void SetDelegate(IListBoxDelegate
*lbDelegate
)=0;
343 virtual void SetList(const char* list
, char separator
, char typesep
)=0;
344 virtual void SetOptions(ListOptions options_
)=0;
354 MenuID
GetID() const noexcept
{ return mid
; }
356 void Destroy() noexcept
;
357 void Show(Point pt
, const Window
&w
);
361 * Platform namespace used to retrieve system wide parameters such as double click speed
367 ColourRGBA
ChromeHighlight();
368 const char *DefaultFont();
369 int DefaultFontSize();
370 unsigned int DoubleClickTime();
371 constexpr long LongFromTwoShorts(short a
,short b
) noexcept
{
372 return (a
) | ((b
) << 16);