📄 platform.h
字号:
// 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-2003 by Neil Hodgson <neilh@scintilla.org>// 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#define PLAT_GTK 0#define PLAT_GTK_WIN32 0#define PLAT_WIN 0#define PLAT_WX 1#define PLAT_FOX 0#if defined(FOX)#undef PLAT_FOX#define PLAT_FOX 1#elif defined(__WX__)#undef PLAT_WX#define PLAT_WX 1#undef PLAT_WIN#elif defined(GTK)#undef PLAT_GTK#define PLAT_GTK 1#undef PLAT_WX#define PLAT_WX 1#ifdef _MSC_VER#undef PLAT_GTK_WIN32#define PLAT_GTK_WIN32 1#endif#else#undef PLAT_WIN#define PLAT_WIN 1#endif// 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 heretypedef 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 exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably. */class Point {public: int x; int y; explicit Point(int x_=0, int y_=0) : x(x_), y(y_) { } // Other automatically defined methods (assignment, copy constructor, destructor) are fine static Point FromLong(long lpoint);};/** * A geometric rectangle class. * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably. * PRectangles contain their top and left sides, but not their right and bottom sides. */class PRectangle {public: int left; int top; int right; int bottom; PRectangle(int left_=0, int top_=0, int right_=0, int bottom_ = 0) : left(left_), top(top_), right(right_), bottom(bottom_) { } // Other automatically defined methods (assignment, copy constructor, destructor) are fine bool operator==(PRectangle &rc) { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } bool Contains(Point pt) { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } bool Contains(PRectangle rc) { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } bool Intersects(PRectangle other) { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } void Move(int xDelta, int yDelta) { left += xDelta; top += yDelta; right += xDelta; bottom += yDelta; } int Width() { return right - left; } int Height() { return bottom - top; }};/** * In some circumstances, including Win32 in paletted mode and GTK+, each colour * must be allocated before use. The desired colours are held in the ColourDesired class, * and after allocation the allocation entry is stored in the ColourAllocated class. In other * circumstances, such as Win32 in true colour mode, the allocation process just copies * the RGB values from the desired to the allocated class. * As each desired colour requires allocation before it can be used, the ColourPair class * holds both a ColourDesired and a ColourAllocated * The Palette class is responsible for managing the palette of colours which contains a * list of ColourPair objects and performs the allocation. *//** * Holds a desired RGB colour. */class ColourDesired { long co;public: ColourDesired(long lcol=0) { co = lcol; } ColourDesired(unsigned int red, unsigned int green, unsigned int blue) { Set(red, green, blue); } bool operator==(const ColourDesired &other) const { return co == other.co; } void Set(long lcol) { co = lcol; } void Set(unsigned int red, unsigned int green, unsigned int blue) { co = red | (green << 8) | (blue << 16); } static inline unsigned int ValueOfHex(const char ch) { if (ch >= '0' && ch <= '9') return ch - '0'; else if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10; else if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10; else return 0; } void Set(const char *val) { if (*val == '#') { val++; } unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); Set(r, g, b); } long AsLong() const { return co; } unsigned int GetRed() { return co & 0xff; } unsigned int GetGreen() { return (co >> 8) & 0xff; } unsigned int GetBlue() { return (co >> 16) & 0xff; }};/** * Holds an allocated RGB colour which may be an approximation to the desired colour. */class ColourAllocated { long coAllocated;public: ColourAllocated(long lcol=0) { coAllocated = lcol; } void Set(long lcol) { coAllocated = lcol; } long AsLong() const { return coAllocated; }};/** * Colour pairs hold a desired colour and an allocated colour. */struct ColourPair { ColourDesired desired; ColourAllocated allocated; ColourPair(ColourDesired desired_=ColourDesired(0,0,0)) { desired = desired_; allocated.Set(desired.AsLong()); } void Copy() { allocated.Set(desired.AsLong()); }};class Window; // Forward declaration for Palette/** * Colour palette management. */class Palette { int used; int size; ColourPair *entries;#if PLAT_GTK void *allocatedPalette; // GdkColor * int allocatedLen;#endif // Private so Palette objects can not be copied Palette(const Palette &) {} Palette &operator=(const Palette &) { return *this; }public:#if PLAT_WIN void *hpal;#endif bool allowRealization; Palette(); ~Palette(); void Release();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -