]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/Platform.h
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
18 #define PLAT_GTK_WIN32 0
19 #define PLAT_GTK_MACOSX 0
34 #elif defined(SCINTILLA_QT)
42 #if defined(__WIN32__) || defined(_MSC_VER)
44 #define PLAT_GTK_WIN32 1
47 #if defined(__APPLE__)
48 #undef PLAT_GTK_MACOSX
49 #define PLAT_GTK_MACOSX 1
52 #elif defined(__APPLE__)
67 typedef float XYPOSITION
;
68 typedef double XYACCUMULATOR
;
69 //#define XYPOSITION int
71 // Underlying the implementation of the platform classes are platform specific types.
72 // Sometimes these need to be passed around by client code so they are defined here
75 typedef void *SurfaceID
;
76 typedef void *WindowID
;
78 typedef void *TickerID
;
79 typedef void *Function
;
80 typedef void *IdlerID
;
83 * A geometric point class.
84 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
91 explicit Point(XYPOSITION x_
=0, XYPOSITION y_
=0) : x(x_
), y(y_
) {
94 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
96 static Point
FromLong(long lpoint
);
100 * A geometric rectangle class.
101 * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably.
102 * PRectangles contain their top and left sides, but not their right and bottom sides.
111 PRectangle(XYPOSITION left_
=0, XYPOSITION top_
=0, XYPOSITION right_
=0, XYPOSITION bottom_
= 0) :
112 left(left_
), top(top_
), right(right_
), bottom(bottom_
) {
115 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
117 bool operator==(PRectangle
&rc
) {
118 return (rc
.left
== left
) && (rc
.right
== right
) &&
119 (rc
.top
== top
) && (rc
.bottom
== bottom
);
121 bool Contains(Point pt
) {
122 return (pt
.x
>= left
) && (pt
.x
<= right
) &&
123 (pt
.y
>= top
) && (pt
.y
<= bottom
);
125 bool Contains(PRectangle rc
) {
126 return (rc
.left
>= left
) && (rc
.right
<= right
) &&
127 (rc
.top
>= top
) && (rc
.bottom
<= bottom
);
129 bool Intersects(PRectangle other
) {
130 return (right
> other
.left
) && (left
< other
.right
) &&
131 (bottom
> other
.top
) && (top
< other
.bottom
);
133 void Move(XYPOSITION xDelta
, XYPOSITION yDelta
) {
139 XYPOSITION
Width() { return right
- left
; }
140 XYPOSITION
Height() { return bottom
- top
; }
142 return (Height() <= 0) || (Width() <= 0);
147 * Holds a desired RGB colour.
149 class ColourDesired
{
152 ColourDesired(long lcol
=0) {
156 ColourDesired(unsigned int red
, unsigned int green
, unsigned int blue
) {
157 Set(red
, green
, blue
);
160 bool operator==(const ColourDesired
&other
) const {
161 return co
== other
.co
;
164 void Set(long lcol
) {
168 void Set(unsigned int red
, unsigned int green
, unsigned int blue
) {
169 co
= red
| (green
<< 8) | (blue
<< 16);
172 static inline unsigned int ValueOfHex(const char ch
) {
173 if (ch
>= '0' && ch
<= '9')
175 else if (ch
>= 'A' && ch
<= 'F')
176 return ch
- 'A' + 10;
177 else if (ch
>= 'a' && ch
<= 'f')
178 return ch
- 'a' + 10;
183 void Set(const char *val
) {
187 unsigned int r
= ValueOfHex(val
[0]) * 16 + ValueOfHex(val
[1]);
188 unsigned int g
= ValueOfHex(val
[2]) * 16 + ValueOfHex(val
[3]);
189 unsigned int b
= ValueOfHex(val
[4]) * 16 + ValueOfHex(val
[5]);
193 long AsLong() const {
197 unsigned int GetRed() {
201 unsigned int GetGreen() {
202 return (co
>> 8) & 0xff;
205 unsigned int GetBlue() {
206 return (co
>> 16) & 0xff;
214 struct FontParameters
{
215 const char *faceName
;
224 const char *faceName_
,
228 int extraFontFlag_
=0,
230 int characterSet_
=0) :
236 extraFontFlag(extraFontFlag_
),
237 technology(technology_
),
238 characterSet(characterSet_
)
250 // Private so Font objects can not be copied
252 Font
&operator=(const Font
&);
257 virtual void Create(const FontParameters
&fp
);
258 virtual void Release();
260 FontID
GetID() { return fid
; }
261 // Alias another font - caller guarantees not to Release
262 void SetID(FontID fid_
) { fid
= fid_
; }
264 void SetAscent(int ascent_
) { ascent
= ascent_
; }
266 friend class Surface
;
267 friend class SurfaceImpl
;
271 * A surface abstracts a place to draw.
275 // Private so Surface objects can not be copied
276 Surface(const Surface
&) {}
277 Surface
&operator=(const Surface
&) { return *this; }
280 virtual ~Surface() {}
281 static Surface
*Allocate(int technology
);
283 virtual void Init(WindowID wid
)=0;
284 virtual void Init(SurfaceID sid
, WindowID wid
)=0;
285 virtual void InitPixMap(int width
, int height
, Surface
*surface_
, WindowID wid
)=0;
287 virtual void Release()=0;
288 virtual bool Initialised()=0;
289 virtual void PenColour(ColourDesired fore
)=0;
290 virtual int LogPixelsY()=0;
291 virtual int DeviceHeightFont(int points
)=0;
292 virtual void MoveTo(int x_
, int y_
)=0;
293 virtual void LineTo(int x_
, int y_
)=0;
294 virtual void Polygon(Point
*pts
, int npts
, ColourDesired fore
, ColourDesired back
)=0;
295 virtual void RectangleDraw(PRectangle rc
, ColourDesired fore
, ColourDesired back
)=0;
296 virtual void FillRectangle(PRectangle rc
, ColourDesired back
)=0;
297 virtual void FillRectangle(PRectangle rc
, Surface
&surfacePattern
)=0;
298 virtual void RoundedRectangle(PRectangle rc
, ColourDesired fore
, ColourDesired back
)=0;
299 virtual void AlphaRectangle(PRectangle rc
, int cornerSize
, ColourDesired fill
, int alphaFill
,
300 ColourDesired outline
, int alphaOutline
, int flags
)=0;
301 virtual void DrawRGBAImage(PRectangle rc
, int width
, int height
, const unsigned char *pixelsImage
) = 0;
302 virtual void Ellipse(PRectangle rc
, ColourDesired fore
, ColourDesired back
)=0;
303 virtual void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
)=0;
305 virtual void DrawTextNoClip(PRectangle rc
, Font
&font_
, XYPOSITION ybase
, const char *s
, int len
, ColourDesired fore
, ColourDesired back
)=0;
306 virtual void DrawTextClipped(PRectangle rc
, Font
&font_
, XYPOSITION ybase
, const char *s
, int len
, ColourDesired fore
, ColourDesired back
)=0;
307 virtual void DrawTextTransparent(PRectangle rc
, Font
&font_
, XYPOSITION ybase
, const char *s
, int len
, ColourDesired fore
)=0;
308 virtual void MeasureWidths(Font
&font_
, const char *s
, int len
, XYPOSITION
*positions
)=0;
309 virtual XYPOSITION
WidthText(Font
&font_
, const char *s
, int len
)=0;
310 virtual XYPOSITION
WidthChar(Font
&font_
, char ch
)=0;
311 virtual XYPOSITION
Ascent(Font
&font_
)=0;
312 virtual XYPOSITION
Descent(Font
&font_
)=0;
313 virtual XYPOSITION
InternalLeading(Font
&font_
)=0;
314 virtual XYPOSITION
ExternalLeading(Font
&font_
)=0;
315 virtual XYPOSITION
Height(Font
&font_
)=0;
316 virtual XYPOSITION
AverageCharWidth(Font
&font_
)=0;
318 virtual void SetClip(PRectangle rc
)=0;
319 virtual void FlushCachedState()=0;
321 virtual void SetUnicodeMode(bool unicodeMode_
)=0;
322 virtual void SetDBCSMode(int codePage
)=0;
326 * A simple callback action passing one piece of untyped user data.
328 typedef void (*CallBackAction
)(void*);
331 * Class to hide the details of window manipulation.
332 * Does not own the window which will normally have a longer life than this object.
342 Window() : wid(0), cursorLast(cursorInvalid
) {
348 Window(const Window
&source
) : wid(source
.wid
), cursorLast(cursorInvalid
) {
355 Window
&operator=(WindowID wid_
) {
359 WindowID
GetID() const { return wid
; }
360 bool Created() const { return wid
!= 0; }
363 PRectangle
GetPosition();
364 void SetPosition(PRectangle rc
);
365 void SetPositionRelative(PRectangle rc
, Window relativeTo
);
366 PRectangle
GetClientPosition();
367 void Show(bool show
=true);
368 void InvalidateAll();
369 void InvalidateRectangle(PRectangle rc
);
370 virtual void SetFont(Font
&font
);
371 enum Cursor
{ cursorInvalid
, cursorText
, cursorArrow
, cursorUp
, cursorWait
, cursorHoriz
, cursorVert
, cursorReverseArrow
, cursorHand
};
372 void SetCursor(Cursor curs
);
373 void SetTitle(const char *s
);
374 PRectangle
GetMonitorRect(Point pt
);
376 void SetWindow(void *ref
) { windowRef
= ref
; }
377 void SetControl(void *_control
) { control
= _control
; }
384 * Listbox management.
387 class ListBox
: public Window
{
391 static ListBox
*Allocate();
393 virtual void SetFont(Font
&font
)=0;
394 virtual void Create(Window
&parent
, int ctrlID
, Point location
, int lineHeight_
, bool unicodeMode_
, int technology_
)=0;
395 virtual void SetAverageCharWidth(int width
)=0;
396 virtual void SetVisibleRows(int rows
)=0;
397 virtual int GetVisibleRows() const=0;
398 virtual PRectangle
GetDesiredRect()=0;
399 virtual int CaretFromEdge()=0;
400 virtual void Clear()=0;
401 virtual void Append(char *s
, int type
= -1)=0;
402 virtual int Length()=0;
403 virtual void Select(int n
)=0;
404 virtual int GetSelection()=0;
405 virtual int Find(const char *prefix
)=0;
406 virtual void GetValue(int n
, char *value
, int len
)=0;
407 virtual void RegisterImage(int type
, const char *xpm_data
)=0;
408 virtual void RegisterRGBAImage(int type
, int width
, int height
, const unsigned char *pixelsImage
) = 0;
409 virtual void ClearRegisteredImages()=0;
410 virtual void SetDoubleClickAction(CallBackAction
, void *)=0;
411 virtual void SetList(const char* list
, char separator
, char typesep
)=0;
421 MenuID
GetID() { return mid
; }
424 void Show(Point pt
, Window
&w
);
432 double Duration(bool reset
=false);
436 * Dynamic Library (DLL/SO/...) loading
438 class DynamicLibrary
{
440 virtual ~DynamicLibrary() {}
442 /// @return Pointer to function "name", or NULL on failure.
443 virtual Function
FindFunction(const char *name
) = 0;
445 /// @return true if the library was loaded successfully.
446 virtual bool IsValid() = 0;
448 /// @return An instance of a DynamicLibrary subclass with "modulePath" loaded.
449 static DynamicLibrary
*Load(const char *modulePath
);
453 * Platform class used to retrieve system wide parameters such as double click speed
454 * and chrome colour. Not a creatable object, more of a module with several functions.
457 // Private so Platform objects can not be copied
458 Platform(const Platform
&) {}
459 Platform
&operator=(const Platform
&) { return *this; }
461 // Should be private because no new Platforms are ever created
462 // but gcc warns about this
465 static ColourDesired
Chrome();
466 static ColourDesired
ChromeHighlight();
467 static const char *DefaultFont();
468 static int DefaultFontSize();
469 static unsigned int DoubleClickTime();
470 static bool MouseButtonBounce();
471 static void DebugDisplay(const char *s
);
472 static bool IsKeyDown(int key
);
473 static long SendScintilla(
474 WindowID w
, unsigned int msg
, unsigned long wParam
=0, long lParam
=0);
475 static long SendScintillaPointer(
476 WindowID w
, unsigned int msg
, unsigned long wParam
=0, void *lParam
=0);
477 static bool IsDBCSLeadByte(int codePage
, char ch
);
478 static int DBCSCharLength(int codePage
, const char *s
);
479 static int DBCSCharMaxLength();
481 // These are utility functions not really tied to a platform
482 static int Minimum(int a
, int b
);
483 static int Maximum(int a
, int b
);
484 // Next three assume 16 bit shorts and 32 bit longs
485 static long LongFromTwoShorts(short a
,short b
) {
486 return (a
) | ((b
) << 16);
488 static short HighShortFromLong(long x
) {
489 return static_cast<short>(x
>> 16);
491 static short LowShortFromLong(long x
) {
492 return static_cast<short>(x
& 0xffff);
494 static void DebugPrintf(const char *format
, ...);
495 static bool ShowAssertionPopUps(bool assertionPopUps_
);
496 static void Assert(const char *c
, const char *file
, int line
);
497 static int Clamp(int val
, int minVal
, int maxVal
);
501 #define PLATFORM_ASSERT(c) ((void)0)
504 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__))
506 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))
514 // Shut up annoying Visual C++ warnings:
516 #pragma warning(disable: 4244 4309 4514 4710)
519 #if defined(__GNUC__) && defined(SCINTILLA_QT)
520 #pragma GCC diagnostic ignored "-Wmissing-braces"
521 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
522 #pragma GCC diagnostic ignored "-Wchar-subscripts"