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