scintilla: Update to include scintilla 3.0.3
[anjuta-extras.git] / plugins / scintilla / scintilla / include / Platform.h
blob654c4870acbf868000379ad0cbf3fc37b43717e3
1 // Scintilla source code edit control
2 /** @file Platform.h
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.
5 **/
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.
9 #ifndef PLATFORM_H
10 #define PLATFORM_H
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
17 #define PLAT_GTK 0
18 #define PLAT_GTK_WIN32 0
19 #define PLAT_GTK_MACOSX 0
20 #define PLAT_MACOSX 0
21 #define PLAT_WIN 0
22 #define PLAT_WX 0
23 #define PLAT_FOX 0
25 #if defined(FOX)
26 #undef PLAT_FOX
27 #define PLAT_FOX 1
29 #elif defined(__WX__)
30 #undef PLAT_WX
31 #define PLAT_WX 1
33 #elif defined(GTK)
34 #undef PLAT_GTK
35 #define PLAT_GTK 1
37 #if defined(__WIN32__) || defined(_MSC_VER)
38 #undef PLAT_GTK_WIN32
39 #define PLAT_GTK_WIN32 1
40 #endif
42 #if defined(__APPLE__)
43 #undef PLAT_GTK_MACOSX
44 #define PLAT_GTK_MACOSX 1
45 #endif
47 #elif defined(__APPLE__)
49 #undef PLAT_MACOSX
50 #define PLAT_MACOSX 1
52 #else
53 #undef PLAT_WIN
54 #define PLAT_WIN 1
56 #endif
58 #ifdef SCI_NAMESPACE
59 namespace Scintilla {
60 #endif
62 typedef float XYPOSITION;
63 typedef double XYACCUMULATOR;
64 //#define XYPOSITION int
66 // Underlying the implementation of the platform classes are platform specific types.
67 // Sometimes these need to be passed around by client code so they are defined here
69 typedef void *FontID;
70 typedef void *SurfaceID;
71 typedef void *WindowID;
72 typedef void *MenuID;
73 typedef void *TickerID;
74 typedef void *Function;
75 typedef void *IdlerID;
77 /**
78 * A geometric point class.
79 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
81 class Point {
82 public:
83 XYPOSITION x;
84 XYPOSITION y;
86 explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) : x(x_), y(y_) {
89 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
91 static Point FromLong(long lpoint);
94 /**
95 * A geometric rectangle class.
96 * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably.
97 * PRectangles contain their top and left sides, but not their right and bottom sides.
99 class PRectangle {
100 public:
101 XYPOSITION left;
102 XYPOSITION top;
103 XYPOSITION right;
104 XYPOSITION bottom;
106 PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) :
107 left(left_), top(top_), right(right_), bottom(bottom_) {
110 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
112 bool operator==(PRectangle &rc) {
113 return (rc.left == left) && (rc.right == right) &&
114 (rc.top == top) && (rc.bottom == bottom);
116 bool Contains(Point pt) {
117 return (pt.x >= left) && (pt.x <= right) &&
118 (pt.y >= top) && (pt.y <= bottom);
120 bool Contains(PRectangle rc) {
121 return (rc.left >= left) && (rc.right <= right) &&
122 (rc.top >= top) && (rc.bottom <= bottom);
124 bool Intersects(PRectangle other) {
125 return (right > other.left) && (left < other.right) &&
126 (bottom > other.top) && (top < other.bottom);
128 void Move(XYPOSITION xDelta, XYPOSITION yDelta) {
129 left += xDelta;
130 top += yDelta;
131 right += xDelta;
132 bottom += yDelta;
134 XYPOSITION Width() { return right - left; }
135 XYPOSITION Height() { return bottom - top; }
136 bool Empty() {
137 return (Height() <= 0) || (Width() <= 0);
142 * Holds a desired RGB colour.
144 class ColourDesired {
145 long co;
146 public:
147 ColourDesired(long lcol=0) {
148 co = lcol;
151 ColourDesired(unsigned int red, unsigned int green, unsigned int blue) {
152 Set(red, green, blue);
155 bool operator==(const ColourDesired &other) const {
156 return co == other.co;
159 void Set(long lcol) {
160 co = lcol;
163 void Set(unsigned int red, unsigned int green, unsigned int blue) {
164 co = red | (green << 8) | (blue << 16);
167 static inline unsigned int ValueOfHex(const char ch) {
168 if (ch >= '0' && ch <= '9')
169 return ch - '0';
170 else if (ch >= 'A' && ch <= 'F')
171 return ch - 'A' + 10;
172 else if (ch >= 'a' && ch <= 'f')
173 return ch - 'a' + 10;
174 else
175 return 0;
178 void Set(const char *val) {
179 if (*val == '#') {
180 val++;
182 unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]);
183 unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]);
184 unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]);
185 Set(r, g, b);
188 long AsLong() const {
189 return co;
192 unsigned int GetRed() {
193 return co & 0xff;
196 unsigned int GetGreen() {
197 return (co >> 8) & 0xff;
200 unsigned int GetBlue() {
201 return (co >> 16) & 0xff;
206 * Font management.
209 struct FontParameters {
210 const char *faceName;
211 float size;
212 int weight;
213 bool italic;
214 int extraFontFlag;
215 int technology;
216 int characterSet;
218 FontParameters(
219 const char *faceName_,
220 float size_=10,
221 int weight_=400,
222 bool italic_=false,
223 int extraFontFlag_=0,
224 int technology_=0,
225 int characterSet_=0) :
227 faceName(faceName_),
228 size(size_),
229 weight(weight_),
230 italic(italic_),
231 extraFontFlag(extraFontFlag_),
232 technology(technology_),
233 characterSet(characterSet_)
239 class Font {
240 protected:
241 FontID fid;
242 #if PLAT_WX
243 int ascent;
244 #endif
245 // Private so Font objects can not be copied
246 Font(const Font &);
247 Font &operator=(const Font &);
248 public:
249 Font();
250 virtual ~Font();
252 virtual void Create(const FontParameters &fp);
253 virtual void Release();
255 FontID GetID() { return fid; }
256 // Alias another font - caller guarantees not to Release
257 void SetID(FontID fid_) { fid = fid_; }
258 #if PLAT_WX
259 void SetAscent(int ascent_) { ascent = ascent_; }
260 #endif
261 friend class Surface;
262 friend class SurfaceImpl;
266 * A surface abstracts a place to draw.
268 class Surface {
269 private:
270 // Private so Surface objects can not be copied
271 Surface(const Surface &) {}
272 Surface &operator=(const Surface &) { return *this; }
273 public:
274 Surface() {}
275 virtual ~Surface() {}
276 static Surface *Allocate(int technology);
278 virtual void Init(WindowID wid)=0;
279 virtual void Init(SurfaceID sid, WindowID wid)=0;
280 virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid)=0;
282 virtual void Release()=0;
283 virtual bool Initialised()=0;
284 virtual void PenColour(ColourDesired fore)=0;
285 virtual int LogPixelsY()=0;
286 virtual int DeviceHeightFont(int points)=0;
287 virtual void MoveTo(int x_, int y_)=0;
288 virtual void LineTo(int x_, int y_)=0;
289 virtual void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back)=0;
290 virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0;
291 virtual void FillRectangle(PRectangle rc, ColourDesired back)=0;
292 virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0;
293 virtual void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back)=0;
294 virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill,
295 ColourDesired outline, int alphaOutline, int flags)=0;
296 virtual void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) = 0;
297 virtual void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)=0;
298 virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0;
300 virtual void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back)=0;
301 virtual void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back)=0;
302 virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore)=0;
303 virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions)=0;
304 virtual XYPOSITION WidthText(Font &font_, const char *s, int len)=0;
305 virtual XYPOSITION WidthChar(Font &font_, char ch)=0;
306 virtual XYPOSITION Ascent(Font &font_)=0;
307 virtual XYPOSITION Descent(Font &font_)=0;
308 virtual XYPOSITION InternalLeading(Font &font_)=0;
309 virtual XYPOSITION ExternalLeading(Font &font_)=0;
310 virtual XYPOSITION Height(Font &font_)=0;
311 virtual XYPOSITION AverageCharWidth(Font &font_)=0;
313 virtual void SetClip(PRectangle rc)=0;
314 virtual void FlushCachedState()=0;
316 virtual void SetUnicodeMode(bool unicodeMode_)=0;
317 virtual void SetDBCSMode(int codePage)=0;
321 * A simple callback action passing one piece of untyped user data.
323 typedef void (*CallBackAction)(void*);
326 * Class to hide the details of window manipulation.
327 * Does not own the window which will normally have a longer life than this object.
329 class Window {
330 protected:
331 WindowID wid;
332 #if PLAT_MACOSX
333 void *windowRef;
334 void *control;
335 #endif
336 public:
337 Window() : wid(0), cursorLast(cursorInvalid) {
338 #if PLAT_MACOSX
339 windowRef = 0;
340 control = 0;
341 #endif
343 Window(const Window &source) : wid(source.wid), cursorLast(cursorInvalid) {
344 #if PLAT_MACOSX
345 windowRef = 0;
346 control = 0;
347 #endif
349 virtual ~Window();
350 Window &operator=(WindowID wid_) {
351 wid = wid_;
352 return *this;
354 WindowID GetID() const { return wid; }
355 bool Created() const { return wid != 0; }
356 void Destroy();
357 bool HasFocus();
358 PRectangle GetPosition();
359 void SetPosition(PRectangle rc);
360 void SetPositionRelative(PRectangle rc, Window relativeTo);
361 PRectangle GetClientPosition();
362 void Show(bool show=true);
363 void InvalidateAll();
364 void InvalidateRectangle(PRectangle rc);
365 virtual void SetFont(Font &font);
366 enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow, cursorHand };
367 void SetCursor(Cursor curs);
368 void SetTitle(const char *s);
369 PRectangle GetMonitorRect(Point pt);
370 #if PLAT_MACOSX
371 void SetWindow(void *ref) { windowRef = ref; }
372 void SetControl(void *_control) { control = _control; }
373 #endif
374 private:
375 Cursor cursorLast;
379 * Listbox management.
382 class ListBox : public Window {
383 public:
384 ListBox();
385 virtual ~ListBox();
386 static ListBox *Allocate();
388 virtual void SetFont(Font &font)=0;
389 virtual void Create(Window &parent, int ctrlID, Point location, int lineHeight_, bool unicodeMode_, int technology_)=0;
390 virtual void SetAverageCharWidth(int width)=0;
391 virtual void SetVisibleRows(int rows)=0;
392 virtual int GetVisibleRows() const=0;
393 virtual PRectangle GetDesiredRect()=0;
394 virtual int CaretFromEdge()=0;
395 virtual void Clear()=0;
396 virtual void Append(char *s, int type = -1)=0;
397 virtual int Length()=0;
398 virtual void Select(int n)=0;
399 virtual int GetSelection()=0;
400 virtual int Find(const char *prefix)=0;
401 virtual void GetValue(int n, char *value, int len)=0;
402 virtual void RegisterImage(int type, const char *xpm_data)=0;
403 virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) = 0;
404 virtual void ClearRegisteredImages()=0;
405 virtual void SetDoubleClickAction(CallBackAction, void *)=0;
406 virtual void SetList(const char* list, char separator, char typesep)=0;
410 * Menu management.
412 class Menu {
413 MenuID mid;
414 public:
415 Menu();
416 MenuID GetID() { return mid; }
417 void CreatePopUp();
418 void Destroy();
419 void Show(Point pt, Window &w);
422 class ElapsedTime {
423 long bigBit;
424 long littleBit;
425 public:
426 ElapsedTime();
427 double Duration(bool reset=false);
431 * Dynamic Library (DLL/SO/...) loading
433 class DynamicLibrary {
434 public:
435 virtual ~DynamicLibrary() {}
437 /// @return Pointer to function "name", or NULL on failure.
438 virtual Function FindFunction(const char *name) = 0;
440 /// @return true if the library was loaded successfully.
441 virtual bool IsValid() = 0;
443 /// @return An instance of a DynamicLibrary subclass with "modulePath" loaded.
444 static DynamicLibrary *Load(const char *modulePath);
448 * Platform class used to retrieve system wide parameters such as double click speed
449 * and chrome colour. Not a creatable object, more of a module with several functions.
451 class Platform {
452 // Private so Platform objects can not be copied
453 Platform(const Platform &) {}
454 Platform &operator=(const Platform &) { return *this; }
455 public:
456 // Should be private because no new Platforms are ever created
457 // but gcc warns about this
458 Platform() {}
459 ~Platform() {}
460 static ColourDesired Chrome();
461 static ColourDesired ChromeHighlight();
462 static const char *DefaultFont();
463 static int DefaultFontSize();
464 static unsigned int DoubleClickTime();
465 static bool MouseButtonBounce();
466 static void DebugDisplay(const char *s);
467 static bool IsKeyDown(int key);
468 static long SendScintilla(
469 WindowID w, unsigned int msg, unsigned long wParam=0, long lParam=0);
470 static long SendScintillaPointer(
471 WindowID w, unsigned int msg, unsigned long wParam=0, void *lParam=0);
472 static bool IsDBCSLeadByte(int codePage, char ch);
473 static int DBCSCharLength(int codePage, const char *s);
474 static int DBCSCharMaxLength();
476 // These are utility functions not really tied to a platform
477 static int Minimum(int a, int b);
478 static int Maximum(int a, int b);
479 // Next three assume 16 bit shorts and 32 bit longs
480 static long LongFromTwoShorts(short a,short b) {
481 return (a) | ((b) << 16);
483 static short HighShortFromLong(long x) {
484 return static_cast<short>(x >> 16);
486 static short LowShortFromLong(long x) {
487 return static_cast<short>(x & 0xffff);
489 static void DebugPrintf(const char *format, ...);
490 static bool ShowAssertionPopUps(bool assertionPopUps_);
491 static void Assert(const char *c, const char *file, int line);
492 static int Clamp(int val, int minVal, int maxVal);
495 #ifdef NDEBUG
496 #define PLATFORM_ASSERT(c) ((void)0)
497 #else
498 #ifdef SCI_NAMESPACE
499 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__))
500 #else
501 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))
502 #endif
503 #endif
505 #ifdef SCI_NAMESPACE
507 #endif
509 // Shut up annoying Visual C++ warnings:
510 #ifdef _MSC_VER
511 #pragma warning(disable: 4244 4309 4514 4710)
512 #endif
514 #endif