]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/include/Platform.h
1 // Scintilla source code edit control
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.
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.
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
18 #define PLAT_GTK_WIN32 0
32 #define PLAT_GTK_WIN32 1
42 // Include the main header for each platform
46 #pragma warning(disable: 4505 4514 4710 4800)
49 #include <gdk/gdkkeysyms.h>
53 #define _WIN32_WINNT 0x0400 // Otherwise some required stuff gets ifdef'd out
54 // Vassili Bourdo: shut up annoying Visual C++ warnings:
56 #pragma warning(disable: 4244 4309 4710 4800)
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
71 typedef GdkColor ColourID
;
72 typedef GdkFont
* FontID
;
73 typedef GdkDrawable
* SurfaceID
;
74 typedef GtkWidget
* WindowID
;
75 typedef GtkItemFactory
* MenuID
;
79 typedef COLORREF ColourID
;
81 typedef HDC SurfaceID
;
82 typedef HWND WindowID
;
87 typedef wxColour ColourID
;
88 typedef wxFont
* FontID
;
89 typedef wxDC
* SurfaceID
;
90 typedef wxWindow
* WindowID
;
91 typedef wxMenu
* MenuID
;
95 * A geometric point class.
96 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
103 Point(int x_
=0, int y_
=0) : x(x_
), y(y_
) {
106 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
108 static Point
FromLong(long lpoint
);
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.
123 PRectangle(int left_
=0, int top_
=0, int right_
=0, int bottom_
= 0) :
124 left(left_
), top(top_
), right(right_
), bottom(bottom_
) {
127 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
129 bool operator==(PRectangle
&rc
) {
130 return (rc
.left
== left
) && (rc
.right
== right
) &&
131 (rc
.top
== top
) && (rc
.bottom
== bottom
);
133 bool Contains(Point pt
) {
134 return (pt
.x
>= left
) && (pt
.x
<= right
) &&
135 (pt
.y
>= top
) && (pt
.y
<= bottom
);
137 bool Contains(PRectangle rc
) {
138 return (rc
.left
>= left
) && (rc
.right
<= right
) &&
139 (rc
.top
>= top
) && (rc
.bottom
<= bottom
);
141 bool Intersects(PRectangle other
) {
142 return (right
>= other
.left
) && (left
<= other
.right
) &&
143 (bottom
>= other
.top
) && (top
<= other
.bottom
);
145 int Width() { return right
- left
; }
146 int Height() { return bottom
- top
; }
150 wxRect
wxRectFromPRectangle(PRectangle prc
);
151 PRectangle
PRectangleFromwxRect(wxRect rc
);
161 Colour(unsigned int red
, unsigned int green
, unsigned int blue
);
162 bool operator==(const Colour
&other
) const;
164 unsigned int GetRed();
165 unsigned int GetGreen();
166 unsigned int GetBlue();
168 friend class Surface
;
169 friend class Palette
;
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.
182 ColourPair(Colour desired_
=Colour(0,0,0)) {
188 class Window
; // Forward declaration for Palette
191 * Colour palette management.
195 enum {numEntries
= 100};
196 ColourPair entries
[numEntries
];
198 GdkColor
*allocatedPalette
;
203 // wxPalette* pal; // **** Is this needed?
206 bool allowRealization
;
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.
218 void WantFind(ColourPair
&cp
, bool want
);
220 void Allocate(Window
&w
);
222 friend class Surface
;
234 // Private so Font objects can not be copied
235 Font(const Font
&) {}
236 Font
&operator=(const Font
&) { id
=0; return *this; }
241 virtual void Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
);
242 virtual void Release();
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
;
251 * A surface abstracts a place to draw.
257 GdkDrawable
*drawable
;
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_
);
296 void Init(SurfaceID hdc_
);
297 void InitPixMap(int width
, int height
, Surface
*surface_
);
301 void PenColour(Colour fore
);
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
);
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_
);
326 int SetPalette(Palette
*pal
, bool inBackGround
);
327 void SetClip(PRectangle rc
);
328 void FlushCachedState();
330 void SetUnicodeMode(bool unicodeMode_
) {
331 unicodeMode
=unicodeMode_
;
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.
340 friend class ListBox
;
345 Window(const Window
&source
) : id(source
.id
) {}
347 Window
&operator=(WindowID id_
) {
351 WindowID
GetID() { return id
; }
352 bool Created() { return id
!= 0; }
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
);
367 LRESULT
SendMessage(UINT msg
, WPARAM wParam
=0, LPARAM lParam
=0);
369 HINSTANCE
GetInstance();
374 * Listbox management.
376 class ListBox
: public Window
{
382 int desiredVisibleRows
;
383 unsigned int maxItemCharacters
;
384 unsigned int aveCharWidth
;
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();
394 void Append(char *s
);
398 int Find(const char *prefix
);
399 void GetValue(int n
, char *value
, int len
);
410 MenuID
GetID() { return id
; }
413 void Show(Point pt
, Window
&w
);
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.
421 // Private so Platform objects can not be copied
422 Platform(const Platform
&) {}
423 Platform
&operator=(const Platform
&) { return *this; }
425 // Should be private because no new Platforms are ever created
426 // but gcc warns about this
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);
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);
446 static short HighShortFromLong(long x
) {
447 return static_cast<short>(x
>> 16);
449 static short LowShortFromLong(long x
) {
450 return static_cast<short>(x
& 0xffff);
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
);
459 #define PLATFORM_ASSERT(c) ((void)0)
461 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))