// Scintilla source code edit control /** @file Platform.h ** Interface to platform facilities. Also includes some basic utilities. ** Implemented in PlatGTK.cxx for GTK+/Linux, PlatWin.cxx for Windows, and PlatWX.cxx for wxWindows. **/ // Copyright 1998-2009 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #ifndef PLATFORM_H #define PLATFORM_H // PLAT_GTK = GTK+ on Linux or Win32 // PLAT_GTK_WIN32 is defined additionally when running PLAT_GTK under Win32 // PLAT_WIN = Win32 API on Win32 OS // PLAT_WX is wxWindows on any supported platform // PLAT_TK = Tcl/TK on Linux or Win32 #define PLAT_GTK 0 #define PLAT_GTK_WIN32 0 #define PLAT_GTK_MACOSX 0 #define PLAT_MACOSX 0 #define PLAT_WIN 0 #define PLAT_WX 0 #define PLAT_QT 0 #define PLAT_FOX 0 #define PLAT_CURSES 0 #define PLAT_TK 0 #define PLAT_HAIKU 0 #if defined(FOX) #undef PLAT_FOX #define PLAT_FOX 1 #elif defined(__WX__) #undef PLAT_WX #define PLAT_WX 1 #elif defined(CURSES) #undef PLAT_CURSES #define PLAT_CURSES 1 #elif defined(__HAIKU__) #undef PLAT_HAIKU #define PLAT_HAIKU 1 #elif defined(SCINTILLA_QT) #undef PLAT_QT #define PLAT_QT 1 #elif defined(TK) #undef PLAT_TK #define PLAT_TK 1 #elif defined(GTK) #undef PLAT_GTK #define PLAT_GTK 1 #if defined(__WIN32__) || defined(_MSC_VER) #undef PLAT_GTK_WIN32 #define PLAT_GTK_WIN32 1 #endif #if defined(__APPLE__) #undef PLAT_GTK_MACOSX #define PLAT_GTK_MACOSX 1 #endif #elif defined(__APPLE__) #undef PLAT_MACOSX #define PLAT_MACOSX 1 #else #undef PLAT_WIN #define PLAT_WIN 1 #endif namespace Scintilla { typedef float XYPOSITION; typedef double XYACCUMULATOR; // Underlying the implementation of the platform classes are platform specific types. // Sometimes these need to be passed around by client code so they are defined here typedef void *FontID; typedef void *SurfaceID; typedef void *WindowID; typedef void *MenuID; typedef void *TickerID; typedef void *Function; typedef void *IdlerID; /** * A geometric point class. * Point is similar to the Win32 POINT and GTK+ GdkPoint types. */ class Point { public: XYPOSITION x; XYPOSITION y; constexpr explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) noexcept : x(x_), y(y_) { } static Point FromInts(int x_, int y_) noexcept { return Point(static_cast(x_), static_cast(y_)); } bool operator!=(Point other) const noexcept { return (x != other.x) || (y != other.y); } Point operator+(Point other) const noexcept { return Point(x + other.x, y + other.y); } Point operator-(Point other) const noexcept { return Point(x - other.x, y - other.y); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine }; /** * A geometric rectangle class. * PRectangle is similar to Win32 RECT. * PRectangles contain their top and left sides, but not their right and bottom sides. */ class PRectangle { public: XYPOSITION left; XYPOSITION top; XYPOSITION right; XYPOSITION bottom; constexpr explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) noexcept : left(left_), top(top_), right(right_), bottom(bottom_) { } static PRectangle FromInts(int left_, int top_, int right_, int bottom_) noexcept { return PRectangle(static_cast(left_), static_cast(top_), static_cast(right_), static_cast(bottom_)); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine bool operator==(const PRectangle &rc) const noexcept { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } bool Contains(Point pt) const noexcept { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } bool ContainsWholePixel(Point pt) const noexcept { // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } bool Contains(PRectangle rc) const noexcept { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } bool Intersects(PRectangle other) const noexcept { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } void Move(XYPOSITION xDelta, XYPOSITION yDelta) noexcept { left += xDelta; top += yDelta; right += xDelta; bottom += yDelta; } XYPOSITION Width() const noexcept { return right - left; } XYPOSITION Height() const noexcept { return bottom - top; } bool Empty() const noexcept { return (Height() <= 0) || (Width() <= 0); } }; /** * Holds an RGB colour with 8 bits for each component. */ constexpr const float componentMaximum = 255.0f; class ColourDesired { int co; public: explicit ColourDesired(int co_=0) noexcept : co(co_) { } ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : co(red | (green << 8) | (blue << 16)) { } bool operator==(const ColourDesired &other) const noexcept { return co == other.co; } int AsInteger() const noexcept { return co; } // Red, green and blue values as bytes 0..255 unsigned char GetRed() const noexcept { return co & 0xff; } unsigned char GetGreen() const noexcept { return (co >> 8) & 0xff; } unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } // Red, green and blue values as float 0..1.0 float GetRedComponent() const noexcept { return GetRed() / componentMaximum; } float GetGreenComponent() const noexcept { return GetGreen() / componentMaximum; } float GetBlueComponent() const noexcept { return GetBlue() / componentMaximum; } }; /** * Holds an RGBA colour. */ class ColourAlpha : public ColourDesired { public: explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { } ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : ColourDesired(red | (green << 8) | (blue << 16)) { } ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { } ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : ColourDesired(cd.AsInteger() | (alpha << 24)) { } ColourDesired GetColour() const noexcept { return ColourDesired(AsInteger() & 0xffffff); } unsigned char GetAlpha() const noexcept { return (AsInteger() >> 24) & 0xff; } float GetAlphaComponent() const noexcept { return GetAlpha() / componentMaximum; } ColourAlpha MixedWith(ColourAlpha other) const noexcept { const unsigned int red = (GetRed() + other.GetRed()) / 2; const unsigned int green = (GetGreen() + other.GetGreen()) / 2; const unsigned int blue = (GetBlue() + other.GetBlue()) / 2; const unsigned int alpha = (GetAlpha() + other.GetAlpha()) / 2; return ColourAlpha(red, green, blue, alpha); } }; /** * Holds an element of a gradient with an RGBA colour and a relative position. */ class ColourStop { public: float position; ColourAlpha colour; ColourStop(float position_, ColourAlpha colour_) noexcept : position(position_), colour(colour_) { } }; /** * Font management. */ struct FontParameters { const char *faceName; float size; int weight; bool italic; int extraFontFlag; int technology; int characterSet; FontParameters( const char *faceName_, float size_=10, int weight_=400, bool italic_=false, int extraFontFlag_=0, int technology_=0, int characterSet_=0) noexcept : faceName(faceName_), size(size_), weight(weight_), italic(italic_), extraFontFlag(extraFontFlag_), technology(technology_), characterSet(characterSet_) { } }; class Font { protected: FontID fid; public: Font() noexcept; // Deleted so Font objects can not be copied Font(const Font &) = delete; Font(Font &&) = delete; Font &operator=(const Font &) = delete; Font &operator=(Font &&) = delete; virtual ~Font(); virtual void Create(const FontParameters &fp); virtual void Release(); FontID GetID() const noexcept { return fid; } // Alias another font - caller guaranHTTP/1.1 200 OK Connection: keep-alive Connection: keep-alive Content-Disposition: inline; filename="Platform.h" Content-Disposition: inline; filename="Platform.h" Content-Length: 15694 Content-Length: 15694 Content-Security-Policy: default-src 'none' Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset=UTF-8 Date: Sun, 04 Jan 2026 05:42:34 UTC ETag: "bb453e20b4a9a75aafb0e0f4687a10825185fb7a" ETag: "bb453e20b4a9a75aafb0e0f4687a10825185fb7a" Expires: Wed, 02 Jan 2036 05:42:34 GMT Expires: Wed, 02 Jan 2036 05:42:35 GMT Last-Modified: Sun, 04 Jan 2026 05:42:34 GMT Last-Modified: Sun, 04 Jan 2026 05:42:35 GMT Server: OpenBSD httpd Server: OpenBSD httpd X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff // Scintilla source code edit control /** @file Platform.h ** Interface to platform facilities. Also includes some basic utilities. ** Implemented in PlatGTK.cxx for GTK+/Linux, PlatWin.cxx for Windows, and PlatWX.cxx for wxWindows. **/ // Copyright 1998-2009 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #ifndef PLATFORM_H #define PLATFORM_H // PLAT_GTK = GTK+ on Linux or Win32 // PLAT_GTK_WIN32 is defined additionally when running PLAT_GTK under Win32 // PLAT_WIN = Win32 API on Win32 OS // PLAT_WX is wxWindows on any supported platform // PLAT_TK = Tcl/TK on Linux or Win32 #define PLAT_GTK 0 #define PLAT_GTK_WIN32 0 #define PLAT_GTK_MACOSX 0 #define PLAT_MACOSX 0 #define PLAT_WIN 0 #define PLAT_WX 0 #define PLAT_QT 0 #define PLAT_FOX 0 #define PLAT_CURSES 0 #define PLAT_TK 0 #define PLAT_HAIKU 0 #if defined(FOX) #undef PLAT_FOX #define PLAT_FOX 1 #elif defined(__WX__) #undef PLAT_WX #define PLAT_WX 1 #elif defined(CURSES) #undef PLAT_CURSES #define PLAT_CURSES 1 #elif defined(__HAIKU__) #undef PLAT_HAIKU #define PLAT_HAIKU 1 #elif defined(SCINTILLA_QT) #undef PLAT_QT #define PLAT_QT 1 #elif defined(TK) #undef PLAT_TK #define PLAT_TK 1 #elif defined(GTK) #undef PLAT_GTK #define PLAT_GTK 1 #if defined(__WIN32__) || defined(_MSC_VER) #undef PLAT_GTK_WIN32 #define PLAT_GTK_WIN32 1 #endif #if defined(__APPLE__) #undef PLAT_GTK_MACOSX #define PLAT_GTK_MACOSX 1 #endif #elif defined(__APPLE__) #undef PLAT_MACOSX #define PLAT_MACOSX 1 #else #undef PLAT_WIN #define PLAT_WIN 1 #endif namespace Scintilla { typedef float XYPOSITION; typedef double XYACCUMULATOR; // Underlying the implementation of the platform classes are platform specific types. // Sometimes these need to be passed around by client code so they are defined here typedef void *FontID; typedef void *SurfaceID; typedef void *WindowID; typedef void *MenuID; typedef void *TickerID; typedef void *Function; typedef void *IdlerID; /** * A geometric point class. * Point is similar to the Win32 POINT and GTK+ GdkPoint types. */ class Point { public: XYPOSITION x; XYPOSITION y; constexpr explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) noexcept : x(x_), y(y_) { } static Point FromInts(int x_, int y_) noexcept { return Point(static_cast(x_), static_cast(y_)); } bool operator!=(Point other) const noexcept { return (x != other.x) || (y != other.y); } Point operator+(Point other) const noexcept { return Point(x + other.x, y + other.y); } Point operator-(Point other) const noexcept { return Point(x - other.x, y - other.y); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine }; /** * A geometric rectangle class. * PRectangle is similar to Win32 RECT. * PRectangles contain their top and left sides, but not their right and bottom sides. */ class PRectangle { public: XYPOSITION left; XYPOSITION top; XYPOSITION right; XYPOSITION bottom; constexpr explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) noexcept : left(left_), top(top_), right(right_), bottom(bottom_) { } static PRectangle FromInts(int left_, int top_, int right_, int bottom_) noexcept { return PRectangle(static_cast(left_), static_cast(top_), static_cast(right_), static_cast(bottom_)); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine bool operator==(const PRectangle &rc) const noexcept { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } bool Contains(Point pt) const noexcept { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } bool ContainsWholePixel(Point pt) const noexcept { // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } bool Contains(PRectangle rc) const noexcept { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } bool Intersects(PRectangle other) const noexcept { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } void Move(XYPOSITION xDelta, XYPOSITION yDelta) noexcept { left += xDelta; top += yDelta; right += xDelta; bottom += yDelta; } XYPOSITION Width() const noexcept { return right - left; } XYPOSITION Height() const noexcept { return bottom - top; } bool Empty() const noexcept { return (Height() <= 0) || (Width() <= 0); } }; /** * Holds an RGB colour with 8 bits for each component. */ constexpr const float componentMaximum = 255.0f; class ColourDesired { int co; public: explicit ColourDesired(int co_=0) noexcept : co(co_) { } ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : co(red | (green << 8) | (blue << 16)) { } bool operator==(const ColourDesired &other) const noexcept { return co == other.co; } int AsInteger() const noexcept { return co; } // Red, green and blue values as bytes 0..255 unsigned char GetRed() const noexcept { return co & 0xff; } unsigned char GetGreen() const noexcept { return (co >> 8) & 0xff; } unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } // Red, green and blue values as float 0..1.0 float GetRedComponent() const noexcept { return GetRed() / componentMaximum; } float GetGreenComponent() const noexcept { return GetGreen() / componentMaximum; } float GetBlueComponent() const noexcept { return GetBlue() / componentMaximum; } }; /** * Holds an RGBA colour. */ class ColourAlpha : public ColourDesired { public: explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { } ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : ColourDesired(red | (green << 8) | (blue << 16)) { } ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { } ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : ColourDesired(cd.AsInteger() | (alpha << 24)) { } ColourDesired GetColour() const noexcept { return ColourDesired(AsInteger() & 0xffffff); } unsigned char GetAlpha() const noexcept { return (AsInteger() >> 24) & 0xff; } float GetAlphaComponent() const noexcept { return GetAlpha() / componentMaximum; } ColourAlpha MixedWith(ColourAlpha other) const noexcept { const unsigned i