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