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