]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/Platform.h
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.
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
34 // Include the main header for each platform
38 #include <gdk/gdkkeysyms.h>
42 #define _WIN32_WINNT 0x0400 // Otherwise some required stuff gets ifdef'd out
43 // Vassili Bourdo: shut up annoying Visual C++ warnings:
45 #pragma warning(disable: 4800 4244 4309)
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
60 typedef GdkColor ColourID
;
61 typedef GdkFont
* FontID
;
62 typedef GdkDrawable
* SurfaceID
;
63 typedef GtkWidget
* WindowID
;
64 typedef GtkItemFactory
* MenuID
;
68 typedef COLORREF ColourID
;
70 typedef HDC SurfaceID
;
71 typedef HWND WindowID
;
76 typedef wxColour ColourID
;
77 typedef wxFont
* FontID
;
78 typedef wxDC
* SurfaceID
;
79 typedef wxWindow
* WindowID
;
80 typedef wxMenu
* MenuID
;
83 #if PLAT_GTK || PLAT_WX
84 #define SHIFT_PRESSED 1
85 #define LEFT_CTRL_PRESSED 2
86 #define LEFT_ALT_PRESSED 4
89 // Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably
96 Point(int x_
=0, int y_
=0) : x(x_
), y(y_
) {
99 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
101 static Point
FromLong(long lpoint
);
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
113 PRectangle(int left_
=0, int top_
=0, int right_
=0, int bottom_
= 0) :
114 left(left_
), top(top_
), right(right_
), bottom(bottom_
) {
117 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
119 bool Contains(Point pt
) {
120 return (pt
.x
>= left
) && (pt
.x
<= right
) &&
121 (pt
.y
>= top
) && (pt
.y
<= bottom
);
123 bool Contains(PRectangle rc
) {
124 return (rc
.left
>= left
) && (rc
.right
<= right
) &&
125 (rc
.top
>= top
) && (rc
.bottom
<= bottom
);
127 bool Intersects(PRectangle other
) {
128 return (right
>= other
.left
) && (left
<= other
.right
) &&
129 (bottom
>= other
.top
) && (top
<= other
.bottom
);
131 int Width() { return right
- left
; }
132 int Height() { return bottom
- top
; }
136 wxRect
wxRectFromPRectangle(PRectangle prc
);
137 PRectangle
PRectangleFromwxRect(wxRect rc
);
144 Colour(unsigned int red
, unsigned int green
, unsigned int blue
);
145 bool operator==(const Colour
&other
) const;
147 unsigned int GetRed();
148 unsigned int GetGreen();
149 unsigned int GetBlue();
151 friend class Surface
;
152 friend class Palette
;
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.
163 ColourPair(Colour desired_
=Colour(0,0,0)) {
169 class Window
; // Forward declaration for Palette
173 enum {numEntries
= 100};
174 ColourPair entries
[numEntries
];
176 GdkColor
*allocatedPalette
;
181 // wxPalette* pal; // **** Is this needed?
184 bool allowRealization
;
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
);
196 void Allocate(Window
&w
);
198 friend class Surface
;
206 // Private so Font objects can not be copied
207 Font(const Font
&) {}
208 Font
&operator=(const Font
&) { id
=0; return *this; }
213 void Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
);
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
;
222 // A surface abstracts a place to draw
227 GdkDrawable
*drawable
;
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_
);
266 void Init(SurfaceID hdc_
);
267 void InitPixMap(int width
, int height
, Surface
*surface_
);
271 void PenColour(Colour fore
);
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
);
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_
);
296 int SetPalette(Palette
*pal
, bool inBackGround
);
297 void SetClip(PRectangle rc
);
298 void FlushCachedState();
300 void SetUnicodeMode(bool unicodeMode_
) {
301 unicodeMode
=unicodeMode_
;
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
308 friend class ListBox
;
313 Window(const Window
&source
) : id(source
.id
) {}
315 Window
&operator=(WindowID id_
) {
319 WindowID
GetID() { return id
; }
320 bool Created() { return id
!= 0; }
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
);
335 LRESULT
SendMessage(UINT msg
, WPARAM wParam
=0, LPARAM lParam
=0);
337 HINSTANCE
GetInstance();
341 class ListBox
: public Window
{
350 ListBox
&operator=(WindowID id_
) {
354 void Create(Window
&parent
, int ctrlID
);
356 void Append(char *s
);
360 int Find(const char *prefix
);
361 void GetValue(int n
, char *value
, int len
);
369 MenuID
GetID() { return id
; }
372 void Show(Point pt
, Window
&w
);
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.
378 // Private so Platform objects can not be copied
379 Platform(const Platform
&) {}
380 Platform
&operator=(const Platform
&) { return *this; }
382 // Should be private because no new Platforms are ever created
383 // but gcc warns about this
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);
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
);