]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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)
55 // Underlying the implementation of the platform classes are platform specific types.
56 // Sometimes these need to be passed around by client code so they are defined here
59 typedef GdkColor ColourID
;
60 typedef GdkFont
* FontID
;
61 typedef GdkDrawable
* SurfaceID
;
62 typedef GtkWidget
* WindowID
;
63 typedef GtkItemFactory
* MenuID
;
67 typedef COLORREF ColourID
;
69 typedef HDC SurfaceID
;
70 typedef HWND WindowID
;
75 typedef wxColour ColourID
;
76 typedef wxFont
* FontID
;
77 typedef wxDC
* SurfaceID
;
78 typedef wxWindow
* WindowID
;
79 typedef wxMenu
* MenuID
;
82 #if PLAT_GTK || PLAT_WX
83 #define SHIFT_PRESSED 1
84 #define LEFT_CTRL_PRESSED 2
85 #define LEFT_ALT_PRESSED 4
88 // Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably
95 Point(int x_
=0, int y_
=0) : x(x_
), y(y_
) {
98 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
100 static Point
FromLong(long lpoint
);
103 // PRectangle is exactly the same as the Win32 RECT so can be used interchangeably
104 // PRectangles contain their top and left sides, but not their right and bottom sides
112 PRectangle(int left_
=0, int top_
=0, int right_
=0, int bottom_
= 0) :
113 left(left_
), top(top_
), right(right_
), bottom(bottom_
) {
116 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
118 bool Contains(Point pt
) {
119 return (pt
.x
>= left
) && (pt
.x
<= right
) &&
120 (pt
.y
>= top
) && (pt
.y
<= bottom
);
122 bool Contains(PRectangle rc
) {
123 return (rc
.left
>= left
) && (rc
.right
<= right
) &&
124 (rc
.top
>= top
) && (rc
.bottom
<= bottom
);
126 bool Intersects(PRectangle other
) {
127 return (right
>= other
.left
) && (left
<= other
.right
) &&
128 (bottom
>= other
.top
) && (top
<= other
.bottom
);
130 int Width() { return right
- left
; }
131 int Height() { return bottom
- top
; }
135 wxRect
wxRectFromPRectangle(PRectangle prc
);
136 PRectangle
PRectangleFromwxRect(wxRect rc
);
143 Colour(unsigned int red
, unsigned int green
, unsigned int blue
);
144 bool operator==(const Colour
&other
) const;
146 unsigned int GetRed();
147 unsigned int GetGreen();
148 unsigned int GetBlue();
150 friend class Surface
;
151 friend class Palette
;
154 // Colour pairs hold a desired colour and the colour that the graphics engine
155 // allocates to approximate the desired colour.
156 // To make palette management more automatic, ColourPairs could register at
157 // construction time with a palette management object.
162 ColourPair(Colour desired_
=Colour(0,0,0)) {
168 class Window
; // Forward declaration for Palette
172 enum {numEntries
= 100};
173 ColourPair entries
[numEntries
];
175 GdkColor
*allocatedPalette
;
180 // wxPalette* pal; // **** Is this needed?
183 bool allowRealization
;
190 // This method either adds a colour to the list of wanted colours (want==true)
191 // or retrieves the allocated colour back to the ColourPair.
192 // This is one method to make it easier to keep the code for wanting and retrieving in sync.
193 void WantFind(ColourPair
&cp
, bool want
);
195 void Allocate(Window
&w
);
197 friend class Surface
;
205 // Private so Font objects can not be copied
206 Font(const Font
&) {}
207 Font
&operator=(const Font
&) { id
=0; return *this; }
212 void Create(const char *faceName
, int size
, bool bold
=false, bool italic
=false);
215 FontID
GetID() { return id
; }
216 friend class Surface
;
219 // A surface abstracts a place to draw
223 GdkDrawable
*drawable
;
250 // Private so Surface objects can not be copied
251 Surface(const Surface
&) {}
252 Surface
&operator=(const Surface
&) { return *this; }
253 #if PLAT_WIN || PLAT_WX
254 void BrushColor(Colour back
);
255 void SetFont(Font
&font_
);
262 void Init(SurfaceID hdc_
);
263 void InitPixMap(int width
, int height
, Surface
*surface_
);
267 void PenColour(Colour fore
);
269 void MoveTo(int x_
, int y_
);
270 void LineTo(int x_
, int y_
);
271 void Polygon(Point
*pts
, int npts
, Colour fore
, Colour back
);
272 void RectangleDraw(PRectangle rc
, Colour fore
, Colour back
);
273 void FillRectangle(PRectangle rc
, Colour back
);
274 void FillRectangle(PRectangle rc
, Surface
&surfacePattern
);
275 void RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
);
276 void Ellipse(PRectangle rc
, Colour fore
, Colour back
);
277 void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
);
279 void DrawText(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
);
280 void DrawTextClipped(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
);
281 void MeasureWidths(Font
&font_
, const char *s
, int len
, int *positions
);
282 int WidthText(Font
&font_
, const char *s
, int len
);
283 int WidthChar(Font
&font_
, char ch
);
284 int Ascent(Font
&font_
);
285 int Descent(Font
&font_
);
286 int InternalLeading(Font
&font_
);
287 int ExternalLeading(Font
&font_
);
288 int Height(Font
&font_
);
289 int AverageCharWidth(Font
&font_
);
291 int SetPalette(Palette
*pal
, bool inBackGround
);
292 void SetClip(PRectangle rc
);
295 // Class to hide the details of window manipulation
296 // Does not own the window which will normally have a longer life than this object
298 friend class ListBox
;
304 Window
&operator=(WindowID id_
) {
308 WindowID
GetID() { return id
; }
309 bool Created() { return id
!= 0; }
312 PRectangle
GetPosition();
313 void SetPosition(PRectangle rc
);
314 void SetPositionRelative(PRectangle rc
, Window relativeTo
);
315 PRectangle
GetClientPosition();
316 void Show(bool show
=true);
317 void InvalidateAll();
318 void InvalidateRectangle(PRectangle rc
);
319 void SetFont(Font
&font
);
320 enum Cursor
{ cursorText
, cursorArrow
, cursorUp
, cursorWait
, cursorHoriz
, cursorVert
, cursorReverseArrow
};
321 void SetCursor(Cursor curs
);
322 void SetTitle(const char *s
);
324 LRESULT
SendMessage(UINT msg
, WPARAM wParam
=0, LPARAM lParam
=0);
326 HINSTANCE
GetInstance();
330 class ListBox
: public Window
{
339 ListBox
&operator=(WindowID id_
) {
343 void Create(Window
&parent
, int ctrlID
);
345 void Append(char *s
);
349 int Find(const char *prefix
);
350 void GetValue(int n
, char *value
, int len
);
358 MenuID
GetID() { return id
; }
361 void Show(Point pt
, Window
&w
);
364 // Platform class used to retrieve system wide parameters such as double click speed
365 // and chrome colour. Not a creatable object, more of a module with several functions.
367 // Private so Platform objects can not be copied
368 Platform(const Platform
&) {}
369 Platform
&operator=(const Platform
&) { return *this; }
371 // Should be private because no new Platforms are ever created
372 // but gcc warns about this
375 static Colour
Chrome();
376 static Colour
ChromeHighlight();
377 static const char *DefaultFont();
378 static int DefaultFontSize();
379 static unsigned int DoubleClickTime();
380 static void DebugDisplay(const char *s
);
381 static bool IsKeyDown(int key
);
382 static long SendScintilla(
383 WindowID w
, unsigned int msg
, unsigned long wParam
=0, long lParam
=0);
385 // These are utility functions not really tied to a platform
386 static int Minimum(int a
, int b
);
387 static int Maximum(int a
, int b
);
388 static void DebugPrintf(const char *format
, ...);
389 static int Clamp(int val
, int minVal
, int maxVal
);