]>
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 // Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably 
  90         Point(int x_
=0, int y_
=0) : x(x_
), y(y_
) { 
  93         // Other automatically defined methods (assignment, copy constructor, destructor) are fine 
  95         static Point 
FromLong(long lpoint
); 
  98 // PRectangle is exactly the same as the Win32 RECT so can be used interchangeably 
  99 // PRectangles contain their top and left sides, but not their right and bottom sides 
 107         PRectangle(int left_
=0, int top_
=0, int right_
=0, int bottom_ 
= 0) : 
 108                 left(left_
), top(top_
), right(right_
), bottom(bottom_
) { 
 111         // Other automatically defined methods (assignment, copy constructor, destructor) are fine 
 113         bool Contains(Point pt
) { 
 114                 return (pt
.x 
>= left
) && (pt
.x 
<= right
) && 
 115                         (pt
.y 
>= top
) && (pt
.y 
<= bottom
); 
 117         bool Contains(PRectangle rc
) { 
 118                 return (rc
.left 
>= left
) && (rc
.right 
<= right
) && 
 119                         (rc
.top 
>= top
) && (rc
.bottom 
<= bottom
); 
 121         bool Intersects(PRectangle other
) { 
 122                 return (right 
>= other
.left
) && (left 
<= other
.right
) && 
 123                         (bottom 
>= other
.top
) && (top 
<= other
.bottom
); 
 125         int Width() { return right 
- left
; } 
 126         int Height() { return bottom 
- top
; } 
 130 wxRect 
wxRectFromPRectangle(PRectangle prc
); 
 131 PRectangle 
PRectangleFromwxRect(wxRect rc
); 
 138         Colour(unsigned int red
, unsigned int green
, unsigned int blue
); 
 139         bool operator==(const Colour 
&other
) const; 
 141         unsigned int GetRed(); 
 142         unsigned int GetGreen(); 
 143         unsigned int GetBlue(); 
 145         friend class Surface
; 
 146         friend class Palette
; 
 149 // Colour pairs hold a desired colour and the colour that the graphics engine 
 150 // allocates to approximate the desired colour. 
 151 // To make palette management more automatic, ColourPairs could register at  
 152 // construction time with a palette management object. 
 157         ColourPair(Colour desired_
=Colour(0,0,0)) { 
 163 class Window
;   // Forward declaration for Palette 
 167         enum {numEntries 
= 100}; 
 168         ColourPair entries
[numEntries
]; 
 170         GdkColor 
*allocatedPalette
; 
 175         // wxPalette* pal;  // **** Is this needed? 
 178         bool allowRealization
; 
 185         // This method either adds a colour to the list of wanted colours (want==true) 
 186         // or retrieves the allocated colour back to the ColourPair. 
 187         // This is one method to make it easier to keep the code for wanting and retrieving in sync. 
 188         void WantFind(ColourPair 
&cp
, bool want
); 
 190         void Allocate(Window 
&w
); 
 192         friend class Surface
; 
 201         // Private so Font objects can not be copied 
 202         Font(const Font 
&) {} 
 203         Font 
&operator=(const Font 
&) { id
=0; return *this; } 
 208         virtual void Create(const char *faceName
, int characterSet
, int size
, bool bold
, bool italic
); 
 209         virtual void Release(); 
 211         FontID 
GetID() { return id
; } 
 212         // Alias another font - caller guarantees not to Release 
 213         void SetID(FontID id_
) { id 
= id_
; } 
 214         friend class Surface
; 
 217 // A surface abstracts a place to draw 
 222         GdkDrawable 
*drawable
; 
 249         // Private so Surface objects can not be copied 
 250         Surface(const Surface 
&) {} 
 251         Surface 
&operator=(const Surface 
&) { return *this; } 
 252 #if PLAT_WIN || PLAT_WX 
 253         void BrushColor(Colour back
); 
 254         void SetFont(Font 
&font_
); 
 261         void Init(SurfaceID hdc_
); 
 262         void InitPixMap(int width
, int height
, Surface 
*surface_
); 
 266         void PenColour(Colour fore
); 
 268         int DeviceHeightFont(int points
); 
 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
); 
 293         void FlushCachedState(); 
 295         void SetUnicodeMode(bool unicodeMode_
) { 
 296                 unicodeMode
=unicodeMode_
; 
 300 // Class to hide the details of window manipulation 
 301 // Does not own the window which will normally have a longer life than this object 
 303         friend class ListBox
; 
 308         Window(const Window 
&source
) : id(source
.id
) {} 
 310         Window 
&operator=(WindowID id_
) { 
 314         WindowID 
GetID() { return id
; } 
 315         bool Created() { return id 
!= 0; } 
 318         PRectangle 
GetPosition(); 
 319         void SetPosition(PRectangle rc
); 
 320         void SetPositionRelative(PRectangle rc
, Window relativeTo
); 
 321         PRectangle 
GetClientPosition(); 
 322         void Show(bool show
=true); 
 323         void InvalidateAll(); 
 324         void InvalidateRectangle(PRectangle rc
); 
 325         virtual void SetFont(Font 
&font
); 
 326         enum Cursor 
{ cursorText
, cursorArrow
, cursorUp
, cursorWait
, cursorHoriz
, cursorVert
, cursorReverseArrow 
}; 
 327         void SetCursor(Cursor curs
); 
 328         void SetTitle(const char *s
); 
 330         LRESULT 
SendMessage(UINT msg
, WPARAM wParam
=0, LPARAM lParam
=0); 
 332         HINSTANCE 
GetInstance(); 
 336 class ListBox 
: public Window 
{ 
 342         int desiredVisibleRows
; 
 343         unsigned int maxItemCharacters
; 
 344         unsigned int aveCharWidth
; 
 348         void Create(Window 
&parent
, int ctrlID
); 
 349         virtual void SetFont(Font 
&font
); 
 350         void SetAverageCharWidth(int width
); 
 351         void SetVisibleRows(int rows
); 
 352         PRectangle 
GetDesiredRect(); 
 354         void Append(char *s
); 
 358         int Find(const char *prefix
); 
 359         void GetValue(int n
, char *value
, int len
); 
 367         MenuID 
GetID() { return id
; } 
 370         void Show(Point pt
, Window 
&w
); 
 373 // Platform class used to retrieve system wide parameters such as double click speed 
 374 // and chrome colour. Not a creatable object, more of a module with several functions. 
 376         // Private so Platform objects can not be copied 
 377         Platform(const Platform 
&) {} 
 378         Platform 
&operator=(const Platform 
&) { return *this; } 
 380         // Should be private because no new Platforms are ever created 
 381         // but gcc warns about this 
 384         static Colour 
Chrome(); 
 385         static Colour 
ChromeHighlight(); 
 386         static const char *DefaultFont(); 
 387         static int DefaultFontSize(); 
 388         static unsigned int DoubleClickTime(); 
 389         static void DebugDisplay(const char *s
); 
 390         static bool IsKeyDown(int key
); 
 391         static long SendScintilla( 
 392                 WindowID w
, unsigned int msg
, unsigned long wParam
=0, long lParam
=0); 
 394         // These are utility functions not really tied to a platform 
 395         static int Minimum(int a
, int b
); 
 396         static int Maximum(int a
, int b
); 
 397         // Next three assume 16 bit shorts and 32 bit longs 
 398         static long LongFromTwoShorts(short a
,short b
) { 
 399                 return (a
) | ((b
) << 16); 
 401         static short HighShortFromLong(long x
) { 
 402                 return static_cast<short>(x 
>> 16); 
 404         static short LowShortFromLong(long x
) { 
 405                 return static_cast<short>(x 
& 0xffff); 
 407         static void DebugPrintf(const char *format
, ...); 
 408         static int Clamp(int val
, int minVal
, int maxVal
);