]>
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 #define ColourID scColourID
68 #define FontID scFontID
69 #define SurfaceID scSurfaceID
70 #define WindowID scWindowID
71 #define MenuID scMenuID
73 #define PRectangle scPRectangle
74 #define Colour scColour
75 #define ColourPair scColourPair
76 #define Window scWindow
77 #define Palette scPalette
79 #define Surface scSurface
80 #define Window scWindow
81 #define ListBox scListBox
83 #define Platform scPlatform
84 #define TextRange scTextRange
85 #define KeyMap scKeyMap
89 // Underlying the implementation of the platform classes are platform specific types.
90 // Sometimes these need to be passed around by client code so they are defined here
93 typedef GdkColor ColourID
;
94 typedef GdkFont
* FontID
;
95 typedef GdkDrawable
* SurfaceID
;
96 typedef GtkWidget
* WindowID
;
97 typedef GtkItemFactory
* MenuID
;
101 typedef COLORREF ColourID
;
102 typedef HFONT FontID
;
103 typedef HDC SurfaceID
;
104 typedef HWND WindowID
;
105 typedef HMENU MenuID
;
109 typedef wxColour ColourID
;
110 typedef wxFont
* FontID
;
111 typedef wxDC
* SurfaceID
;
112 typedef wxWindow
* WindowID
;
113 typedef wxMenu
* MenuID
;
117 * A geometric point class.
118 * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.
125 Point(int x_
=0, int y_
=0) : x(x_
), y(y_
) {
128 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
130 static Point
FromLong(long lpoint
);
134 * A geometric rectangle class.
135 * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably.
136 * PRectangles contain their top and left sides, but not their right and bottom sides.
145 PRectangle(int left_
=0, int top_
=0, int right_
=0, int bottom_
= 0) :
146 left(left_
), top(top_
), right(right_
), bottom(bottom_
) {
149 // Other automatically defined methods (assignment, copy constructor, destructor) are fine
151 bool operator==(PRectangle
&rc
) {
152 return (rc
.left
== left
) && (rc
.right
== right
) &&
153 (rc
.top
== top
) && (rc
.bottom
== bottom
);
155 bool Contains(Point pt
) {
156 return (pt
.x
>= left
) && (pt
.x
<= right
) &&
157 (pt
.y
>= top
) && (pt
.y
<= bottom
);
159 bool Contains(PRectangle rc
) {
160 return (rc
.left
>= left
) && (rc
.right
<= right
) &&
161 (rc
.top
>= top
) && (rc
.bottom
<= bottom
);
163 bool Intersects(PRectangle other
) {
164 return (right
>= other
.left
) && (left
<= other
.right
) &&
165 (bottom
>= other
.top
) && (top
<= other
.bottom
);
167 int Width() { return right
- left
; }
168 int Height() { return bottom
- top
; }
172 wxRect
wxRectFromPRectangle(PRectangle prc
);
173 PRectangle
PRectangleFromwxRect(wxRect rc
);
183 Colour(unsigned int red
, unsigned int green
, unsigned int blue
);
184 bool operator==(const Colour
&other
) const;
186 unsigned int GetRed();
187 unsigned int GetGreen();
188 unsigned int GetBlue();
190 friend class Surface
;
191 friend class Palette
;
195 * Colour pairs hold a desired colour and the colour that the graphics engine
196 * allocates to approximate the desired colour.
197 * To make palette management more automatic, ColourPairs could register at
198 * construction time with a palette management object.
204 ColourPair(Colour desired_
=Colour(0,0,0)) {
210 class Window
; // Forward declaration for Palette
213 * Colour palette management.
217 enum {numEntries
= 100};
218 ColourPair entries
[numEntries
];
220 GdkColor
*allocatedPalette
;
225 // wxPalette* pal; // **** Is this needed?
228 bool allowRealization
;
236 * This method either adds a colour to the list of wanted colours (want==true)
237 * or retrieves the allocated colour back to the ColourPair.
238 * This is one method to make it easier to keep the code for wanting and retrieving in sync.
240 void WantFind(ColourPair
&cp
, bool want
);
242 void Allocate(Window
&w
);
244 friend class Surface
;
256 // Private so Font objects can not be copied
257 Font(const Font
&) {}
258 Font
&operator=(const Font
&) { id
=0; return *this; }
263 virtual void Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
);
264 virtual void Release();
266 FontID
GetID() { return id
; }
267 // Alias another font - caller guarantees not to Release
268 void SetID(FontID id_
) { id
= id_
; }
269 friend class Surface
;
273 * A surface abstracts a place to draw.
279 GdkDrawable
*drawable
;
306 // Private so Surface objects can not be copied
307 Surface(const Surface
&) {}
308 Surface
&operator=(const Surface
&) { return *this; }
309 #if PLAT_WIN || PLAT_WX
310 void BrushColor(Colour back
);
311 void SetFont(Font
&font_
);
318 void Init(SurfaceID hdc_
);
319 void InitPixMap(int width
, int height
, Surface
*surface_
);
323 void PenColour(Colour fore
);
325 int DeviceHeightFont(int points
);
326 void MoveTo(int x_
, int y_
);
327 void LineTo(int x_
, int y_
);
328 void Polygon(Point
*pts
, int npts
, Colour fore
, Colour back
);
329 void RectangleDraw(PRectangle rc
, Colour fore
, Colour back
);
330 void FillRectangle(PRectangle rc
, Colour back
);
331 void FillRectangle(PRectangle rc
, Surface
&surfacePattern
);
332 void RoundedRectangle(PRectangle rc
, Colour fore
, Colour back
);
333 void Ellipse(PRectangle rc
, Colour fore
, Colour back
);
334 void Copy(PRectangle rc
, Point from
, Surface
&surfaceSource
);
336 void DrawText(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
);
337 void DrawTextClipped(PRectangle rc
, Font
&font_
, int ybase
, const char *s
, int len
, Colour fore
, Colour back
);
338 void MeasureWidths(Font
&font_
, const char *s
, int len
, int *positions
);
339 int WidthText(Font
&font_
, const char *s
, int len
);
340 int WidthChar(Font
&font_
, char ch
);
341 int Ascent(Font
&font_
);
342 int Descent(Font
&font_
);
343 int InternalLeading(Font
&font_
);
344 int ExternalLeading(Font
&font_
);
345 int Height(Font
&font_
);
346 int AverageCharWidth(Font
&font_
);
348 int SetPalette(Palette
*pal
, bool inBackGround
);
349 void SetClip(PRectangle rc
);
350 void FlushCachedState();
352 void SetUnicodeMode(bool unicodeMode_
) {
353 unicodeMode
=unicodeMode_
;
358 * Class to hide the details of window manipulation.
359 * Does not own the window which will normally have a longer life than this object.
362 friend class ListBox
;
367 Window(const Window
&source
) : id(source
.id
) {}
369 Window
&operator=(WindowID id_
) {
373 WindowID
GetID() { return id
; }
374 bool Created() { return id
!= 0; }
377 PRectangle
GetPosition();
378 void SetPosition(PRectangle rc
);
379 void SetPositionRelative(PRectangle rc
, Window relativeTo
);
380 PRectangle
GetClientPosition();
381 void Show(bool show
=true);
382 void InvalidateAll();
383 void InvalidateRectangle(PRectangle rc
);
384 virtual void SetFont(Font
&font
);
385 enum Cursor
{ cursorText
, cursorArrow
, cursorUp
, cursorWait
, cursorHoriz
, cursorVert
, cursorReverseArrow
};
386 void SetCursor(Cursor curs
);
387 void SetTitle(const char *s
);
389 LRESULT
SendMessage(UINT msg
, WPARAM wParam
=0, LPARAM lParam
=0);
391 HINSTANCE
GetInstance();
396 * Listbox management.
398 class ListBox
: public Window
{
404 int desiredVisibleRows
;
405 unsigned int maxItemCharacters
;
406 unsigned int aveCharWidth
;
410 void Create(Window
&parent
, int ctrlID
);
411 virtual void SetFont(Font
&font
);
412 void SetAverageCharWidth(int width
);
413 void SetVisibleRows(int rows
);
414 PRectangle
GetDesiredRect();
416 void Append(char *s
);
420 int Find(const char *prefix
);
421 void GetValue(int n
, char *value
, int len
);
432 MenuID
GetID() { return id
; }
435 void Show(Point pt
, Window
&w
);
439 * Platform class used to retrieve system wide parameters such as double click speed
440 * and chrome colour. Not a creatable object, more of a module with several functions.
443 // Private so Platform objects can not be copied
444 Platform(const Platform
&) {}
445 Platform
&operator=(const Platform
&) { return *this; }
447 // Should be private because no new Platforms are ever created
448 // but gcc warns about this
451 static Colour
Chrome();
452 static Colour
ChromeHighlight();
453 static const char *DefaultFont();
454 static int DefaultFontSize();
455 static unsigned int DoubleClickTime();
456 static void DebugDisplay(const char *s
);
457 static bool IsKeyDown(int key
);
458 static long SendScintilla(
459 WindowID w
, unsigned int msg
, unsigned long wParam
=0, long lParam
=0);
461 // These are utility functions not really tied to a platform
462 static int Minimum(int a
, int b
);
463 static int Maximum(int a
, int b
);
464 // Next three assume 16 bit shorts and 32 bit longs
465 static long LongFromTwoShorts(short a
,short b
) {
466 return (a
) | ((b
) << 16);
468 static short HighShortFromLong(long x
) {
469 return static_cast<short>(x
>> 16);
471 static short LowShortFromLong(long x
) {
472 return static_cast<short>(x
& 0xffff);
474 static void DebugPrintf(const char *format
, ...);
475 static bool ShowAssertionPopUps(bool assertionPopUps_
);
476 static void Assert(const char *c
, const char *file
, int line
);
477 static int Clamp(int val
, int minVal
, int maxVal
);
481 #define PLATFORM_ASSERT(c) ((void)0)
483 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))