]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/stc/scintilla/include/Platform.h
compilation fix for FALSE -> wxItemKind conversion
[wxWidgets.git] / src / stc / scintilla / include / Platform.h
... / ...
CommitLineData
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-2002 by Neil Hodgson <neilh@scintilla.org>
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
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
16
17#define PLAT_GTK 0
18#define PLAT_GTK_WIN32 0
19#define PLAT_WIN 0
20#define PLAT_WX 0
21#define PLAT_FOX 0
22
23#if defined(FOX)
24#undef PLAT_FOX
25#define PLAT_FOX 1
26
27#elif defined(__WX__)
28#undef PLAT_WX
29#define PLAT_WX 1
30
31#elif defined(GTK)
32#undef PLAT_GTK
33#define PLAT_GTK 1
34
35#ifdef _MSC_VER
36#undef PLAT_GTK_WIN32
37#define PLAT_GTK_WIN32 1
38#endif
39
40#else
41#undef PLAT_WIN
42#define PLAT_WIN 1
43
44#endif
45
46
47// Underlying the implementation of the platform classes are platform specific types.
48// Sometimes these need to be passed around by client code so they are defined here
49
50typedef void *FontID;
51typedef void *SurfaceID;
52typedef void *WindowID;
53typedef void *MenuID;
54typedef void *TickerID;
55
56/**
57 * A geometric point class.
58 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
59 */
60class Point {
61public:
62 int x;
63 int y;
64
65 Point(int x_=0, int y_=0) : x(x_), y(y_) {
66 }
67
68 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
69
70 static Point FromLong(long lpoint);
71};
72
73/**
74 * A geometric rectangle class.
75 * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably.
76 * PRectangles contain their top and left sides, but not their right and bottom sides.
77 */
78class PRectangle {
79public:
80 int left;
81 int top;
82 int right;
83 int bottom;
84
85 PRectangle(int left_=0, int top_=0, int right_=0, int bottom_ = 0) :
86 left(left_), top(top_), right(right_), bottom(bottom_) {
87 }
88
89 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
90
91 bool operator==(PRectangle &rc) {
92 return (rc.left == left) && (rc.right == right) &&
93 (rc.top == top) && (rc.bottom == bottom);
94 }
95 bool Contains(Point pt) {
96 return (pt.x >= left) && (pt.x <= right) &&
97 (pt.y >= top) && (pt.y <= bottom);
98 }
99 bool Contains(PRectangle rc) {
100 return (rc.left >= left) && (rc.right <= right) &&
101 (rc.top >= top) && (rc.bottom <= bottom);
102 }
103 bool Intersects(PRectangle other) {
104 return (right >= other.left) && (left <= other.right) &&
105 (bottom >= other.top) && (top <= other.bottom);
106 }
107 int Width() { return right - left; }
108 int Height() { return bottom - top; }
109};
110
111/**
112 * In some circumstances, including Win32 in paletted mode and GTK+, each colour
113 * must be allocated before use. The desired colours are held in the ColourDesired class,
114 * and after allocation the allocation entry is stored in the ColourAllocated class. In other
115 * circumstances, such as Win32 in true colour mode, the allocation process just copies
116 * the RGB values from the desired to the allocated class.
117 * As each desired colour requires allocation before it can be used, the ColourPair class
118 * holds both a ColourDesired and a ColourAllocated
119 * The Palette class is responsible for managing the palette of colours which contains a
120 * list of ColourPair objects and performs the allocation.
121 */
122
123/**
124 * Holds a desired RGB colour.
125 */
126class ColourDesired {
127 long co;
128public:
129 ColourDesired(long lcol=0) {
130 co = lcol;
131 }
132
133 ColourDesired(unsigned int red, unsigned int green, unsigned int blue) {
134 co = red | (green << 8) | (blue << 16);
135 }
136
137 bool operator==(const ColourDesired &other) const {
138 return co == other.co;
139 }
140
141 void Set(long lcol) {
142 co = lcol;
143 }
144
145 long AsLong() const {
146 return co;
147 }
148
149 unsigned int GetRed() {
150 return co & 0xff;
151 }
152
153 unsigned int GetGreen() {
154 return (co >> 8) & 0xff;
155 }
156
157 unsigned int GetBlue() {
158 return (co >> 16) & 0xff;
159 }
160};
161
162/**
163 * Holds an allocated RGB colour which may be an approximation to the desired colour.
164 */
165class ColourAllocated {
166 long coAllocated;
167
168public:
169
170 ColourAllocated(long lcol=0) {
171 coAllocated = lcol;
172 }
173
174 void Set(long lcol) {
175 coAllocated = lcol;
176 }
177
178 long AsLong() const {
179 return coAllocated;
180 }
181};
182
183/**
184 * Colour pairs hold a desired colour and an allocated colour.
185 */
186struct ColourPair {
187 ColourDesired desired;
188 ColourAllocated allocated;
189
190 ColourPair(ColourDesired desired_=ColourDesired(0,0,0)) {
191 desired = desired_;
192 allocated.Set(desired.AsLong());
193 }
194};
195
196class Window; // Forward declaration for Palette
197
198/**
199 * Colour palette management.
200 */
201class Palette {
202 int used;
203 enum {numEntries = 100};
204 ColourPair entries[numEntries];
205#if PLAT_GTK
206 void *allocatedPalette; // GdkColor *
207 int allocatedLen;
208#endif
209public:
210#if PLAT_WIN
211 void *hpal;
212#endif
213 bool allowRealization;
214
215 Palette();
216 ~Palette();
217
218 void Release();
219
220 /**
221 * This method either adds a colour to the list of wanted colours (want==true)
222 * or retrieves the allocated colour back to the ColourPair.
223 * This is one method to make it easier to keep the code for wanting and retrieving in sync.
224 */
225 void WantFind(ColourPair &cp, bool want);
226
227 void Allocate(Window &w);
228};
229
230/**
231 * Font management.
232 */
233class Font {
234protected:
235 FontID id;
236#if PLAT_WX
237 int ascent;
238#endif
239 // Private so Font objects can not be copied
240 Font(const Font &) {}
241 Font &operator=(const Font &) { id=0; return *this; }
242public:
243 Font();
244 virtual ~Font();
245
246 virtual void Create(const char *faceName, int characterSet, int size, bool bold, bool italic);
247 virtual void Release();
248
249 FontID GetID() { return id; }
250 // Alias another font - caller guarantees not to Release
251 void SetID(FontID id_) { id = id_; }
252 friend class Surface;
253 friend class SurfaceImpl;
254};
255
256/**
257 * A surface abstracts a place to draw.
258 */
259class Surface {
260private:
261 // Private so Surface objects can not be copied
262 Surface(const Surface &) {}
263 Surface &operator=(const Surface &) { return *this; }
264public:
265 Surface() {};
266 virtual ~Surface() {};
267 static Surface *Allocate();
268
269 virtual void Init()=0;
270 virtual void Init(SurfaceID sid)=0;
271 virtual void InitPixMap(int width, int height, Surface *surface_)=0;
272
273 virtual void Release()=0;
274 virtual bool Initialised()=0;
275 virtual void PenColour(ColourAllocated fore)=0;
276 virtual int LogPixelsY()=0;
277 virtual int DeviceHeightFont(int points)=0;
278 virtual void MoveTo(int x_, int y_)=0;
279 virtual void LineTo(int x_, int y_)=0;
280 virtual void Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back)=0;
281 virtual void RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;
282 virtual void FillRectangle(PRectangle rc, ColourAllocated back)=0;
283 virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0;
284 virtual void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;
285 virtual void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;
286 virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0;
287
288 virtual void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back)=0;
289 virtual void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back)=0;
290 virtual void MeasureWidths(Font &font_, const char *s, int len, int *positions)=0;
291 virtual int WidthText(Font &font_, const char *s, int len)=0;
292 virtual int WidthChar(Font &font_, char ch)=0;
293 virtual int Ascent(Font &font_)=0;
294 virtual int Descent(Font &font_)=0;
295 virtual int InternalLeading(Font &font_)=0;
296 virtual int ExternalLeading(Font &font_)=0;
297 virtual int Height(Font &font_)=0;
298 virtual int AverageCharWidth(Font &font_)=0;
299
300 virtual int SetPalette(Palette *pal, bool inBackGround)=0;
301 virtual void SetClip(PRectangle rc)=0;
302 virtual void FlushCachedState()=0;
303
304 virtual void SetUnicodeMode(bool unicodeMode_)=0;
305};
306
307/**
308 * A simple callback action passing one piece of untyped user data.
309 */
310typedef void (*CallBackAction)(void*);
311
312/**
313 * Class to hide the details of window manipulation.
314 * Does not own the window which will normally have a longer life than this object.
315 */
316class Window {
317protected:
318 WindowID id;
319public:
320 Window() : id(0), cursorLast(cursorInvalid) {}
321 Window(const Window &source) : id(source.id), cursorLast(cursorInvalid) {}
322 virtual ~Window();
323 Window &operator=(WindowID id_) {
324 id = id_;
325 return *this;
326 }
327 WindowID GetID() { return id; }
328 bool Created() { return id != 0; }
329 void Destroy();
330 bool HasFocus();
331 PRectangle GetPosition();
332 void SetPosition(PRectangle rc);
333 void SetPositionRelative(PRectangle rc, Window relativeTo);
334 PRectangle GetClientPosition();
335 void Show(bool show=true);
336 void InvalidateAll();
337 void InvalidateRectangle(PRectangle rc);
338 virtual void SetFont(Font &font);
339 enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow };
340 void SetCursor(Cursor curs);
341 void SetTitle(const char *s);
342private:
343 Cursor cursorLast;
344};
345
346/**
347 * Listbox management.
348 */
349
350class ListBox : public Window {
351private:
352#if PLAT_GTK
353 WindowID list;
354 WindowID scroller;
355 int current;
356#endif
357 int desiredVisibleRows;
358 unsigned int maxItemCharacters;
359 unsigned int aveCharWidth;
360public:
361 CallBackAction doubleClickAction;
362 void *doubleClickActionData;
363public:
364 ListBox();
365 virtual ~ListBox();
366 void Create(Window &parent, int ctrlID);
367 virtual void SetFont(Font &font);
368 void SetAverageCharWidth(int width);
369 void SetVisibleRows(int rows);
370 PRectangle GetDesiredRect();
371 void Clear();
372 void Append(char *s);
373 int Length();
374 void Select(int n);
375 int GetSelection();
376 int Find(const char *prefix);
377 void GetValue(int n, char *value, int len);
378 void Sort();
379 void SetDoubleClickAction(CallBackAction action, void *data) {
380 doubleClickAction = action;
381 doubleClickActionData = data;
382 }
383};
384
385/**
386 * Menu management.
387 */
388class Menu {
389 MenuID id;
390public:
391 Menu();
392 MenuID GetID() { return id; }
393 void CreatePopUp();
394 void Destroy();
395 void Show(Point pt, Window &w);
396};
397
398class ElapsedTime {
399 long bigBit;
400 long littleBit;
401public:
402 ElapsedTime();
403 double Duration(bool reset=false);
404};
405
406/**
407 * Platform class used to retrieve system wide parameters such as double click speed
408 * and chrome colour. Not a creatable object, more of a module with several functions.
409 */
410class Platform {
411 // Private so Platform objects can not be copied
412 Platform(const Platform &) {}
413 Platform &operator=(const Platform &) { return *this; }
414public:
415 // Should be private because no new Platforms are ever created
416 // but gcc warns about this
417 Platform() {}
418 ~Platform() {}
419 static ColourDesired Chrome();
420 static ColourDesired ChromeHighlight();
421 static const char *DefaultFont();
422 static int DefaultFontSize();
423 static unsigned int DoubleClickTime();
424 static void DebugDisplay(const char *s);
425 static bool IsKeyDown(int key);
426 static long SendScintilla(
427 WindowID w, unsigned int msg, unsigned long wParam=0, long lParam=0);
428 static bool IsDBCSLeadByte(int codePage, char ch);
429
430 // These are utility functions not really tied to a platform
431 static int Minimum(int a, int b);
432 static int Maximum(int a, int b);
433 // Next three assume 16 bit shorts and 32 bit longs
434 static long LongFromTwoShorts(short a,short b) {
435 return (a) | ((b) << 16);
436 }
437 static short HighShortFromLong(long x) {
438 return static_cast<short>(x >> 16);
439 }
440 static short LowShortFromLong(long x) {
441 return static_cast<short>(x & 0xffff);
442 }
443 static void DebugPrintf(const char *format, ...);
444 static bool ShowAssertionPopUps(bool assertionPopUps_);
445 static void Assert(const char *c, const char *file, int line);
446 static int Clamp(int val, int minVal, int maxVal);
447};
448
449#ifdef NDEBUG
450#define PLATFORM_ASSERT(c) ((void)0)
451#else
452#define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))
453#endif
454
455// Shut up annoying Visual C++ warnings:
456#ifdef _MSC_VER
457#pragma warning(disable: 4244 4309 4514 4710)
458#endif
459
460#endif