]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/include/Platform.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / stc / scintilla / include / Platform.h
CommitLineData
9ce192d4 1// Scintilla source code edit control
65ec6247
RD
2/** @file Platform.h
3 ** Interface to platform facilities. Also includes some basic utilities.
7e0c58e9 4 ** Implemented in PlatGTK.cxx for GTK+/Linux, PlatWin.cxx for Windows, and PlatWX.cxx for wxWindows.
65ec6247 5 **/
9e96e16f 6// Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
9ce192d4
RD
7// The License.txt file describes the conditions under which this software may be distributed.
8
9#ifndef PLATFORM_H
10#define PLATFORM_H
11
65ec6247
RD
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
7e0c58e9 15// PLAT_WX is wxWindows on any supported platform
9ce192d4
RD
16
17#define PLAT_GTK 0
65ec6247 18#define PLAT_GTK_WIN32 0
1dcf666d 19#define PLAT_GTK_MACOSX 0
7e0c58e9 20#define PLAT_MACOSX 0
9ce192d4
RD
21#define PLAT_WIN 0
22#define PLAT_WX 0
1dcf666d 23#define PLAT_QT 0
1a2fb4cd 24#define PLAT_FOX 0
9ce192d4 25
1a2fb4cd
RD
26#if defined(FOX)
27#undef PLAT_FOX
28#define PLAT_FOX 1
29
30#elif defined(__WX__)
9ce192d4
RD
31#undef PLAT_WX
32#define PLAT_WX 1
33
1dcf666d
RD
34#elif defined(SCINTILLA_QT)
35#undef PLAT_QT
36#define PLAT_QT 1
37
9ce192d4
RD
38#elif defined(GTK)
39#undef PLAT_GTK
40#define PLAT_GTK 1
41
9e96e16f 42#if defined(__WIN32__) || defined(_MSC_VER)
65ec6247
RD
43#undef PLAT_GTK_WIN32
44#define PLAT_GTK_WIN32 1
45#endif
46
1dcf666d
RD
47#if defined(__APPLE__)
48#undef PLAT_GTK_MACOSX
49#define PLAT_GTK_MACOSX 1
50#endif
51
9e96e16f
RD
52#elif defined(__APPLE__)
53
7e0c58e9
RD
54#undef PLAT_MACOSX
55#define PLAT_MACOSX 1
56
9ce192d4
RD
57#else
58#undef PLAT_WIN
59#define PLAT_WIN 1
60
61#endif
62
7e0c58e9
RD
63#ifdef SCI_NAMESPACE
64namespace Scintilla {
65#endif
9ce192d4 66
1dcf666d
RD
67typedef float XYPOSITION;
68typedef double XYACCUMULATOR;
69//#define XYPOSITION int
70
9ce192d4
RD
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
73
1a2fb4cd
RD
74typedef void *FontID;
75typedef void *SurfaceID;
76typedef void *WindowID;
77typedef void *MenuID;
78typedef void *TickerID;
e14d10b0 79typedef void *Function;
8e54aaed 80typedef void *IdlerID;
9ce192d4 81
65ec6247
RD
82/**
83 * A geometric point class.
84 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
85 */
9ce192d4
RD
86class Point {
87public:
1dcf666d
RD
88 XYPOSITION x;
89 XYPOSITION y;
65ec6247 90
1dcf666d 91 explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) : x(x_), y(y_) {
9ce192d4
RD
92 }
93
94 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
65ec6247 95
9ce192d4
RD
96 static Point FromLong(long lpoint);
97};
98
65ec6247
RD
99/**
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.
103 */
9ce192d4
RD
104class PRectangle {
105public:
1dcf666d
RD
106 XYPOSITION left;
107 XYPOSITION top;
108 XYPOSITION right;
109 XYPOSITION bottom;
9ce192d4 110
1dcf666d 111 PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) :
9ce192d4
RD
112 left(left_), top(top_), right(right_), bottom(bottom_) {
113 }
114
115 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
116
65ec6247
RD
117 bool operator==(PRectangle &rc) {
118 return (rc.left == left) && (rc.right == right) &&
119 (rc.top == top) && (rc.bottom == bottom);
120 }
9ce192d4
RD
121 bool Contains(Point pt) {
122 return (pt.x >= left) && (pt.x <= right) &&
123 (pt.y >= top) && (pt.y <= bottom);
124 }
125 bool Contains(PRectangle rc) {
126 return (rc.left >= left) && (rc.right <= right) &&
127 (rc.top >= top) && (rc.bottom <= bottom);
128 }
129 bool Intersects(PRectangle other) {
a834585d
RD
130 return (right > other.left) && (left < other.right) &&
131 (bottom > other.top) && (top < other.bottom);
9ce192d4 132 }
1dcf666d 133 void Move(XYPOSITION xDelta, XYPOSITION yDelta) {
9e730a78
RD
134 left += xDelta;
135 top += yDelta;
136 right += xDelta;
137 bottom += yDelta;
138 }
1dcf666d
RD
139 XYPOSITION Width() { return right - left; }
140 XYPOSITION Height() { return bottom - top; }
9e96e16f 141 bool Empty() {
7e0c58e9
RD
142 return (Height() <= 0) || (Width() <= 0);
143 }
9ce192d4
RD
144};
145
65ec6247 146/**
1a2fb4cd 147 * Holds a desired RGB colour.
65ec6247 148 */
1a2fb4cd
RD
149class ColourDesired {
150 long co;
9ce192d4 151public:
1a2fb4cd
RD
152 ColourDesired(long lcol=0) {
153 co = lcol;
154 }
65ec6247 155
1a2fb4cd 156 ColourDesired(unsigned int red, unsigned int green, unsigned int blue) {
9e730a78 157 Set(red, green, blue);
1a2fb4cd
RD
158 }
159
160 bool operator==(const ColourDesired &other) const {
161 return co == other.co;
162 }
163
164 void Set(long lcol) {
165 co = lcol;
166 }
167
9e730a78
RD
168 void Set(unsigned int red, unsigned int green, unsigned int blue) {
169 co = red | (green << 8) | (blue << 16);
170 }
171
172 static inline unsigned int ValueOfHex(const char ch) {
173 if (ch >= '0' && ch <= '9')
174 return ch - '0';
175 else if (ch >= 'A' && ch <= 'F')
176 return ch - 'A' + 10;
177 else if (ch >= 'a' && ch <= 'f')
178 return ch - 'a' + 10;
179 else
180 return 0;
181 }
182
183 void Set(const char *val) {
184 if (*val == '#') {
185 val++;
186 }
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]);
190 Set(r, g, b);
191 }
192
1a2fb4cd
RD
193 long AsLong() const {
194 return co;
195 }
196
197 unsigned int GetRed() {
198 return co & 0xff;
199 }
200
201 unsigned int GetGreen() {
202 return (co >> 8) & 0xff;
203 }
204
205 unsigned int GetBlue() {
206 return (co >> 16) & 0xff;
207 }
9ce192d4
RD
208};
209
65ec6247 210/**
1dcf666d 211 * Font management.
65ec6247 212 */
9ce192d4 213
1dcf666d
RD
214struct FontParameters {
215 const char *faceName;
216 float size;
217 int weight;
218 bool italic;
219 int extraFontFlag;
220 int technology;
221 int characterSet;
222
223 FontParameters(
224 const char *faceName_,
225 float size_=10,
226 int weight_=400,
227 bool italic_=false,
228 int extraFontFlag_=0,
229 int technology_=0,
230 int characterSet_=0) :
231
232 faceName(faceName_),
233 size(size_),
234 weight(weight_),
235 italic(italic_),
236 extraFontFlag(extraFontFlag_),
237 technology(technology_),
238 characterSet(characterSet_)
239 {
9e730a78 240 }
9ce192d4 241
9ce192d4
RD
242};
243
244class Font {
d134f170 245protected:
9e96e16f 246 FontID fid;
9ce192d4
RD
247#if PLAT_WX
248 int ascent;
249#endif
250 // Private so Font objects can not be copied
1dcf666d
RD
251 Font(const Font &);
252 Font &operator=(const Font &);
9ce192d4
RD
253public:
254 Font();
d134f170 255 virtual ~Font();
9ce192d4 256
1dcf666d 257 virtual void Create(const FontParameters &fp);
d134f170 258 virtual void Release();
9ce192d4 259
9e96e16f 260 FontID GetID() { return fid; }
f6bcfd97 261 // Alias another font - caller guarantees not to Release
9e96e16f 262 void SetID(FontID fid_) { fid = fid_; }
1dcf666d
RD
263#if PLAT_WX
264 void SetAscent(int ascent_) { ascent = ascent_; }
265#endif
9ce192d4 266 friend class Surface;
1dcf666d 267 friend class SurfaceImpl;
9ce192d4
RD
268};
269
65ec6247
RD
270/**
271 * A surface abstracts a place to draw.
272 */
9ce192d4
RD
273class Surface {
274private:
9ce192d4
RD
275 // Private so Surface objects can not be copied
276 Surface(const Surface &) {}
277 Surface &operator=(const Surface &) { return *this; }
9ce192d4 278public:
1dcf666d
RD
279 Surface() {}
280 virtual ~Surface() {}
281 static Surface *Allocate(int technology);
1a2fb4cd 282
9e730a78
RD
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;
1a2fb4cd
RD
286
287 virtual void Release()=0;
288 virtual bool Initialised()=0;
1dcf666d 289 virtual void PenColour(ColourDesired fore)=0;
1a2fb4cd
RD
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;
1dcf666d
RD
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;
1a2fb4cd 297 virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0;
1dcf666d
RD
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;
1a2fb4cd
RD
303 virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0;
304
1dcf666d
RD
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;
317
1a2fb4cd
RD
318 virtual void SetClip(PRectangle rc)=0;
319 virtual void FlushCachedState()=0;
320
321 virtual void SetUnicodeMode(bool unicodeMode_)=0;
9e730a78 322 virtual void SetDBCSMode(int codePage)=0;
9ce192d4
RD
323};
324
1a2fb4cd
RD
325/**
326 * A simple callback action passing one piece of untyped user data.
327 */
328typedef void (*CallBackAction)(void*);
329
65ec6247
RD
330/**
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.
333 */
9ce192d4 334class Window {
9ce192d4 335protected:
9e96e16f 336 WindowID wid;
7e0c58e9
RD
337#if PLAT_MACOSX
338 void *windowRef;
339 void *control;
340#endif
9ce192d4 341public:
9e96e16f 342 Window() : wid(0), cursorLast(cursorInvalid) {
7e0c58e9
RD
343#if PLAT_MACOSX
344 windowRef = 0;
345 control = 0;
346#endif
347 }
9e96e16f 348 Window(const Window &source) : wid(source.wid), cursorLast(cursorInvalid) {
7e0c58e9
RD
349#if PLAT_MACOSX
350 windowRef = 0;
351 control = 0;
352#endif
353 }
9ce192d4 354 virtual ~Window();
9e96e16f
RD
355 Window &operator=(WindowID wid_) {
356 wid = wid_;
9ce192d4
RD
357 return *this;
358 }
9e96e16f
RD
359 WindowID GetID() const { return wid; }
360 bool Created() const { return wid != 0; }
9ce192d4
RD
361 void Destroy();
362 bool HasFocus();
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);
d134f170 370 virtual void SetFont(Font &font);
9e730a78 371 enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow, cursorHand };
9ce192d4
RD
372 void SetCursor(Cursor curs);
373 void SetTitle(const char *s);
7e0c58e9
RD
374 PRectangle GetMonitorRect(Point pt);
375#if PLAT_MACOSX
1dcf666d
RD
376 void SetWindow(void *ref) { windowRef = ref; }
377 void SetControl(void *_control) { control = _control; }
7e0c58e9 378#endif
1a2fb4cd
RD
379private:
380 Cursor cursorLast;
9ce192d4
RD
381};
382
65ec6247
RD
383/**
384 * Listbox management.
385 */
1a2fb4cd 386
9ce192d4 387class ListBox : public Window {
9ce192d4
RD
388public:
389 ListBox();
390 virtual ~ListBox();
9e730a78
RD
391 static ListBox *Allocate();
392
393 virtual void SetFont(Font &font)=0;
1dcf666d 394 virtual void Create(Window &parent, int ctrlID, Point location, int lineHeight_, bool unicodeMode_, int technology_)=0;
9e730a78
RD
395 virtual void SetAverageCharWidth(int width)=0;
396 virtual void SetVisibleRows(int rows)=0;
1e9bafca 397 virtual int GetVisibleRows() const=0;
9e730a78
RD
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;
9e730a78 407 virtual void RegisterImage(int type, const char *xpm_data)=0;
1dcf666d 408 virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) = 0;
9e730a78
RD
409 virtual void ClearRegisteredImages()=0;
410 virtual void SetDoubleClickAction(CallBackAction, void *)=0;
1e9bafca 411 virtual void SetList(const char* list, char separator, char typesep)=0;
9ce192d4
RD
412};
413
65ec6247
RD
414/**
415 * Menu management.
416 */
9ce192d4 417class Menu {
9e96e16f 418 MenuID mid;
9ce192d4
RD
419public:
420 Menu();
9e96e16f 421 MenuID GetID() { return mid; }
9ce192d4
RD
422 void CreatePopUp();
423 void Destroy();
424 void Show(Point pt, Window &w);
425};
426
1a2fb4cd
RD
427class ElapsedTime {
428 long bigBit;
429 long littleBit;
430public:
431 ElapsedTime();
432 double Duration(bool reset=false);
433};
434
e14d10b0
RD
435/**
436 * Dynamic Library (DLL/SO/...) loading
437 */
438class DynamicLibrary {
439public:
1dcf666d 440 virtual ~DynamicLibrary() {}
e14d10b0
RD
441
442 /// @return Pointer to function "name", or NULL on failure.
443 virtual Function FindFunction(const char *name) = 0;
444
445 /// @return true if the library was loaded successfully.
446 virtual bool IsValid() = 0;
447
448 /// @return An instance of a DynamicLibrary subclass with "modulePath" loaded.
449 static DynamicLibrary *Load(const char *modulePath);
450};
451
65ec6247
RD
452/**
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.
455 */
9ce192d4
RD
456class Platform {
457 // Private so Platform objects can not be copied
458 Platform(const Platform &) {}
459 Platform &operator=(const Platform &) { return *this; }
460public:
461 // Should be private because no new Platforms are ever created
462 // but gcc warns about this
463 Platform() {}
464 ~Platform() {}
1a2fb4cd
RD
465 static ColourDesired Chrome();
466 static ColourDesired ChromeHighlight();
9ce192d4
RD
467 static const char *DefaultFont();
468 static int DefaultFontSize();
469 static unsigned int DoubleClickTime();
9e730a78 470 static bool MouseButtonBounce();
9ce192d4
RD
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);
a834585d
RD
475 static long SendScintillaPointer(
476 WindowID w, unsigned int msg, unsigned long wParam=0, void *lParam=0);
1a2fb4cd 477 static bool IsDBCSLeadByte(int codePage, char ch);
9e730a78
RD
478 static int DBCSCharLength(int codePage, const char *s);
479 static int DBCSCharMaxLength();
65ec6247 480
9ce192d4
RD
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);
d134f170
RD
484 // Next three assume 16 bit shorts and 32 bit longs
485 static long LongFromTwoShorts(short a,short b) {
486 return (a) | ((b) << 16);
487 }
488 static short HighShortFromLong(long x) {
489 return static_cast<short>(x >> 16);
490 }
491 static short LowShortFromLong(long x) {
492 return static_cast<short>(x & 0xffff);
493 }
9ce192d4 494 static void DebugPrintf(const char *format, ...);
65ec6247
RD
495 static bool ShowAssertionPopUps(bool assertionPopUps_);
496 static void Assert(const char *c, const char *file, int line);
9ce192d4
RD
497 static int Clamp(int val, int minVal, int maxVal);
498};
499
65ec6247
RD
500#ifdef NDEBUG
501#define PLATFORM_ASSERT(c) ((void)0)
502#else
7e0c58e9
RD
503#ifdef SCI_NAMESPACE
504#define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__))
505#else
65ec6247
RD
506#define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))
507#endif
7e0c58e9
RD
508#endif
509
510#ifdef SCI_NAMESPACE
511}
512#endif
65ec6247 513
1a2fb4cd
RD
514// Shut up annoying Visual C++ warnings:
515#ifdef _MSC_VER
516#pragma warning(disable: 4244 4309 4514 4710)
517#endif
518
1dcf666d
RD
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"
523#endif
524
9ce192d4 525#endif