]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/Platform.h
overwrote with src\wxBase.dsp
[wxWidgets.git] / src / stc / scintilla / include / Platform.h
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-2001 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
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
30 #ifdef _MSC_VER
31 #undef PLAT_GTK_WIN32
32 #define PLAT_GTK_WIN32 1
33 #endif
34
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
45 #ifdef _MSC_VER
46 #pragma warning(disable: 4505 4514 4710 4800)
47 #endif
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
56 #pragma warning(disable: 4244 4309 4710 4800)
57 #endif
58 #include <windows.h>
59 #include <commctrl.h>
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
71 typedef GdkColor ColourID;
72 typedef GdkFont* FontID;
73 typedef GdkDrawable* SurfaceID;
74 typedef GtkWidget* WindowID;
75 typedef GtkItemFactory* MenuID;
76 #endif
77
78 #if PLAT_WIN
79 typedef COLORREF ColourID;
80 typedef HFONT FontID;
81 typedef HDC SurfaceID;
82 typedef HWND WindowID;
83 typedef HMENU MenuID;
84 #endif
85
86 #if PLAT_WX
87 typedef wxColour ColourID;
88 typedef wxFont* FontID;
89 typedef wxDC* SurfaceID;
90 typedef wxWindow* WindowID;
91 typedef wxMenu* MenuID;
92 #endif
93
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 */
98 class Point {
99 public:
100 int x;
101 int y;
102
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
107
108 static Point FromLong(long lpoint);
109 };
110
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 */
116 class PRectangle {
117 public:
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
129 bool operator==(PRectangle &rc) {
130 return (rc.left == left) && (rc.right == right) &&
131 (rc.top == top) && (rc.bottom == bottom);
132 }
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
150 wxRect wxRectFromPRectangle(PRectangle prc);
151 PRectangle PRectangleFromwxRect(wxRect rc);
152 #endif
153
154 /**
155 * A colour class.
156 */
157 class Colour {
158 ColourID co;
159 public:
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();
167
168 friend class Surface;
169 friend class Palette;
170 };
171
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 */
178 struct 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
188 class Window; // Forward declaration for Palette
189
190 /**
191 * Colour palette management.
192 */
193 class 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
205 public:
206 bool allowRealization;
207
208 Palette();
209 ~Palette();
210
211 void Release();
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 */
218 void WantFind(ColourPair &cp, bool want);
219
220 void Allocate(Window &w);
221
222 friend class Surface;
223 };
224
225 /**
226 * Font management.
227 */
228 class Font {
229 protected:
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; }
237 public:
238 Font();
239 virtual ~Font();
240
241 virtual void Create(const char *faceName, int characterSet, int size, bool bold, bool italic);
242 virtual void Release();
243
244 FontID GetID() { return id; }
245 // Alias another font - caller guarantees not to Release
246 void SetID(FontID id_) { id = id_; }
247 friend class Surface;
248 };
249
250 /**
251 * A surface abstracts a place to draw.
252 */
253 class Surface {
254 private:
255 bool unicodeMode;
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
291 public:
292 Surface();
293 ~Surface();
294
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();
303 int DeviceHeightFont(int points);
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_);
325
326 int SetPalette(Palette *pal, bool inBackGround);
327 void SetClip(PRectangle rc);
328 void FlushCachedState();
329
330 void SetUnicodeMode(bool unicodeMode_) {
331 unicodeMode=unicodeMode_;
332 }
333 };
334
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 */
339 class Window {
340 friend class ListBox;
341 protected:
342 WindowID id;
343 public:
344 Window() : id(0) {}
345 Window(const Window &source) : id(source.id) {}
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);
362 virtual void SetFont(Font &font);
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
373 /**
374 * Listbox management.
375 */
376 class ListBox : public Window {
377 #if PLAT_GTK
378 WindowID list;
379 WindowID scroller;
380 int current;
381 #endif
382 int desiredVisibleRows;
383 unsigned int maxItemCharacters;
384 unsigned int aveCharWidth;
385 public:
386 ListBox();
387 virtual ~ListBox();
388 void Create(Window &parent, int ctrlID);
389 virtual void SetFont(Font &font);
390 void SetAverageCharWidth(int width);
391 void SetVisibleRows(int rows);
392 PRectangle GetDesiredRect();
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
403 /**
404 * Menu management.
405 */
406 class Menu {
407 MenuID id;
408 public:
409 Menu();
410 MenuID GetID() { return id; }
411 void CreatePopUp();
412 void Destroy();
413 void Show(Point pt, Window &w);
414 };
415
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 */
420 class Platform {
421 // Private so Platform objects can not be copied
422 Platform(const Platform &) {}
423 Platform &operator=(const Platform &) { return *this; }
424 public:
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);
438
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);
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 }
452 static void DebugPrintf(const char *format, ...);
453 static bool ShowAssertionPopUps(bool assertionPopUps_);
454 static void Assert(const char *c, const char *file, int line);
455 static int Clamp(int val, int minVal, int maxVal);
456 };
457
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
464 #endif