OSDN Git Service

Commit DialogBox compile Okay
[tortoisegit/TortoiseGitJp.git] / ext / scintilla / include / Platform.h
1 // Scintilla source code edit control\r
2 /** @file Platform.h\r
3  ** Interface to platform facilities. Also includes some basic utilities.\r
4  ** Implemented in PlatGTK.cxx for GTK+/Linux, PlatWin.cxx for Windows, and PlatWX.cxx for wxWindows.\r
5  **/\r
6 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>\r
7 // The License.txt file describes the conditions under which this software may be distributed.\r
8 \r
9 #ifndef PLATFORM_H\r
10 #define PLATFORM_H\r
11 \r
12 // PLAT_GTK = GTK+ on Linux or Win32\r
13 // PLAT_GTK_WIN32 is defined additionally when running PLAT_GTK under Win32\r
14 // PLAT_WIN = Win32 API on Win32 OS\r
15 // PLAT_WX is wxWindows on any supported platform\r
16 \r
17 #define PLAT_GTK 0\r
18 #define PLAT_GTK_WIN32 0\r
19 #define PLAT_MACOSX 0\r
20 #define PLAT_WIN 0\r
21 #define PLAT_WX  0\r
22 #define PLAT_FOX 0\r
23 \r
24 #if defined(FOX)\r
25 #undef PLAT_FOX\r
26 #define PLAT_FOX 1\r
27 \r
28 #elif defined(__WX__)\r
29 #undef PLAT_WX\r
30 #define PLAT_WX  1\r
31 \r
32 #elif defined(GTK)\r
33 #undef PLAT_GTK\r
34 #define PLAT_GTK 1\r
35 \r
36 #if defined(__WIN32__) || defined(_MSC_VER)\r
37 #undef PLAT_GTK_WIN32\r
38 #define PLAT_GTK_WIN32 1\r
39 #endif\r
40 \r
41 #elif defined(MACOSX)\r
42 #undef PLAT_MACOSX\r
43 #define PLAT_MACOSX 1\r
44 \r
45 #else\r
46 #undef PLAT_WIN\r
47 #define PLAT_WIN 1\r
48 \r
49 #endif\r
50 \r
51 #ifdef SCI_NAMESPACE\r
52 namespace Scintilla {\r
53 #endif\r
54 \r
55 // Underlying the implementation of the platform classes are platform specific types.\r
56 // Sometimes these need to be passed around by client code so they are defined here\r
57 \r
58 typedef void *FontID;\r
59 typedef void *SurfaceID;\r
60 typedef void *WindowID;\r
61 typedef void *MenuID;\r
62 typedef void *TickerID;\r
63 typedef void *Function;\r
64 typedef void *IdlerID;\r
65 \r
66 /**\r
67  * A geometric point class.\r
68  * Point is exactly the same as the Win32 POINT and GTK+ GdkPoint so can be used interchangeably.\r
69  */\r
70 class Point {\r
71 public:\r
72         int x;\r
73         int y;\r
74 \r
75         explicit Point(int x_=0, int y_=0) : x(x_), y(y_) {\r
76         }\r
77 \r
78         // Other automatically defined methods (assignment, copy constructor, destructor) are fine\r
79 \r
80         static Point FromLong(long lpoint);\r
81 };\r
82 \r
83 /**\r
84  * A geometric rectangle class.\r
85  * PRectangle is exactly the same as the Win32 RECT so can be used interchangeably.\r
86  * PRectangles contain their top and left sides, but not their right and bottom sides.\r
87  */\r
88 class PRectangle {\r
89 public:\r
90         int left;\r
91         int top;\r
92         int right;\r
93         int bottom;\r
94 \r
95         PRectangle(int left_=0, int top_=0, int right_=0, int bottom_ = 0) :\r
96                 left(left_), top(top_), right(right_), bottom(bottom_) {\r
97         }\r
98 \r
99         // Other automatically defined methods (assignment, copy constructor, destructor) are fine\r
100 \r
101         bool operator==(PRectangle &rc) {\r
102                 return (rc.left == left) && (rc.right == right) &&\r
103                         (rc.top == top) && (rc.bottom == bottom);\r
104         }\r
105         bool Contains(Point pt) {\r
106                 return (pt.x >= left) && (pt.x <= right) &&\r
107                         (pt.y >= top) && (pt.y <= bottom);\r
108         }\r
109         bool Contains(PRectangle rc) {\r
110                 return (rc.left >= left) && (rc.right <= right) &&\r
111                         (rc.top >= top) && (rc.bottom <= bottom);\r
112         }\r
113         bool Intersects(PRectangle other) {\r
114                 return (right > other.left) && (left < other.right) &&\r
115                         (bottom > other.top) && (top < other.bottom);\r
116         }\r
117         void Move(int xDelta, int yDelta) {\r
118                 left += xDelta;\r
119                 top += yDelta;\r
120                 right += xDelta;\r
121                 bottom += yDelta;\r
122         }\r
123         int Width() { return right - left; }\r
124         int Height() { return bottom - top; }\r
125         bool Empty() {\r
126                 return (Height() <= 0) || (Width() <= 0);\r
127         }\r
128 };\r
129 \r
130 /**\r
131  * In some circumstances, including Win32 in paletted mode and GTK+, each colour\r
132  * must be allocated before use. The desired colours are held in the ColourDesired class,\r
133  * and after allocation the allocation entry is stored in the ColourAllocated class. In other\r
134  * circumstances, such as Win32 in true colour mode, the allocation process just copies\r
135  * the RGB values from the desired to the allocated class.\r
136  * As each desired colour requires allocation before it can be used, the ColourPair class\r
137  * holds both a ColourDesired and a ColourAllocated\r
138  * The Palette class is responsible for managing the palette of colours which contains a\r
139  * list of ColourPair objects and performs the allocation.\r
140  */\r
141 \r
142 /**\r
143  * Holds a desired RGB colour.\r
144  */\r
145 class ColourDesired {\r
146         long co;\r
147 public:\r
148         ColourDesired(long lcol=0) {\r
149                 co = lcol;\r
150         }\r
151 \r
152         ColourDesired(unsigned int red, unsigned int green, unsigned int blue) {\r
153                 Set(red, green, blue);\r
154         }\r
155 \r
156         bool operator==(const ColourDesired &other) const {\r
157                 return co == other.co;\r
158         }\r
159 \r
160         void Set(long lcol) {\r
161                 co = lcol;\r
162         }\r
163 \r
164         void Set(unsigned int red, unsigned int green, unsigned int blue) {\r
165                 co = red | (green << 8) | (blue << 16);\r
166         }\r
167 \r
168         static inline unsigned int ValueOfHex(const char ch) {\r
169                 if (ch >= '0' && ch <= '9')\r
170                         return ch - '0';\r
171                 else if (ch >= 'A' && ch <= 'F')\r
172                         return ch - 'A' + 10;\r
173                 else if (ch >= 'a' && ch <= 'f')\r
174                         return ch - 'a' + 10;\r
175                 else\r
176                         return 0;\r
177         }\r
178 \r
179         void Set(const char *val) {\r
180                 if (*val == '#') {\r
181                         val++;\r
182                 }\r
183                 unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]);\r
184                 unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]);\r
185                 unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]);\r
186                 Set(r, g, b);\r
187         }\r
188 \r
189         long AsLong() const {\r
190                 return co;\r
191         }\r
192 \r
193         unsigned int GetRed() {\r
194                 return co & 0xff;\r
195         }\r
196 \r
197         unsigned int GetGreen() {\r
198                 return (co >> 8) & 0xff;\r
199         }\r
200 \r
201         unsigned int GetBlue() {\r
202                 return (co >> 16) & 0xff;\r
203         }\r
204 };\r
205 \r
206 /**\r
207  * Holds an allocated RGB colour which may be an approximation to the desired colour.\r
208  */\r
209 class ColourAllocated {\r
210         long coAllocated;\r
211 \r
212 public:\r
213 \r
214         ColourAllocated(long lcol=0) {\r
215                 coAllocated = lcol;\r
216         }\r
217 \r
218         void Set(long lcol) {\r
219                 coAllocated = lcol;\r
220         }\r
221 \r
222         long AsLong() const {\r
223                 return coAllocated;\r
224         }\r
225 };\r
226 \r
227 /**\r
228  * Colour pairs hold a desired colour and an allocated colour.\r
229  */\r
230 struct ColourPair {\r
231         ColourDesired desired;\r
232         ColourAllocated allocated;\r
233 \r
234         ColourPair(ColourDesired desired_=ColourDesired(0,0,0)) {\r
235                 desired = desired_;\r
236                 allocated.Set(desired.AsLong());\r
237         }\r
238         void Copy() {\r
239                 allocated.Set(desired.AsLong());\r
240         }\r
241 };\r
242 \r
243 class Window;   // Forward declaration for Palette\r
244 \r
245 /**\r
246  * Colour palette management.\r
247  */\r
248 class Palette {\r
249         int used;\r
250         int size;\r
251         ColourPair *entries;\r
252 #if PLAT_GTK\r
253         void *allocatedPalette; // GdkColor *\r
254         int allocatedLen;\r
255 #endif\r
256         // Private so Palette objects can not be copied\r
257         Palette(const Palette &) {}\r
258         Palette &operator=(const Palette &) { return *this; }\r
259 public:\r
260 #if PLAT_WIN\r
261         void *hpal;\r
262 #endif\r
263         bool allowRealization;\r
264 \r
265         Palette();\r
266         ~Palette();\r
267 \r
268         void Release();\r
269 \r
270         /**\r
271          * This method either adds a colour to the list of wanted colours (want==true)\r
272          * or retrieves the allocated colour back to the ColourPair.\r
273          * This is one method to make it easier to keep the code for wanting and retrieving in sync.\r
274          */\r
275         void WantFind(ColourPair &cp, bool want);\r
276 \r
277         void Allocate(Window &w);\r
278 };\r
279 \r
280 /**\r
281  * Font management.\r
282  */\r
283 class Font {\r
284 protected:\r
285         FontID id;\r
286 #if PLAT_WX\r
287         int ascent;\r
288 #endif\r
289         // Private so Font objects can not be copied\r
290         Font(const Font &) {}\r
291         Font &operator=(const Font &) { id=0; return *this; }\r
292 public:\r
293         Font();\r
294         virtual ~Font();\r
295 \r
296         virtual void Create(const char *faceName, int characterSet, int size,\r
297                 bool bold, bool italic, bool extraFontFlag=false);\r
298         virtual void Release();\r
299 \r
300         FontID GetID() { return id; }\r
301         // Alias another font - caller guarantees not to Release\r
302         void SetID(FontID id_) { id = id_; }\r
303         friend class Surface;\r
304         friend class SurfaceImpl;\r
305 };\r
306 \r
307 /**\r
308  * A surface abstracts a place to draw.\r
309  */\r
310 class Surface {\r
311 private:\r
312         // Private so Surface objects can not be copied\r
313         Surface(const Surface &) {}\r
314         Surface &operator=(const Surface &) { return *this; }\r
315 public:\r
316         Surface() {};\r
317         virtual ~Surface() {};\r
318         static Surface *Allocate();\r
319 \r
320         virtual void Init(WindowID wid)=0;\r
321         virtual void Init(SurfaceID sid, WindowID wid)=0;\r
322         virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid)=0;\r
323 \r
324         virtual void Release()=0;\r
325         virtual bool Initialised()=0;\r
326         virtual void PenColour(ColourAllocated fore)=0;\r
327         virtual int LogPixelsY()=0;\r
328         virtual int DeviceHeightFont(int points)=0;\r
329         virtual void MoveTo(int x_, int y_)=0;\r
330         virtual void LineTo(int x_, int y_)=0;\r
331         virtual void Polygon(Point *pts, int npts, ColourAllocated fore, ColourAllocated back)=0;\r
332         virtual void RectangleDraw(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;\r
333         virtual void FillRectangle(PRectangle rc, ColourAllocated back)=0;\r
334         virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0;\r
335         virtual void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;\r
336         virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,\r
337                 ColourAllocated outline, int alphaOutline, int flags)=0;\r
338         virtual void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;\r
339         virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0;\r
340 \r
341         virtual void DrawTextNoClip(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back)=0;\r
342         virtual void DrawTextClipped(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back)=0;\r
343         virtual void DrawTextTransparent(PRectangle rc, Font &font_, int ybase, const char *s, int len, ColourAllocated fore)=0;\r
344         virtual void MeasureWidths(Font &font_, const char *s, int len, int *positions)=0;\r
345         virtual int WidthText(Font &font_, const char *s, int len)=0;\r
346         virtual int WidthChar(Font &font_, char ch)=0;\r
347         virtual int Ascent(Font &font_)=0;\r
348         virtual int Descent(Font &font_)=0;\r
349         virtual int InternalLeading(Font &font_)=0;\r
350         virtual int ExternalLeading(Font &font_)=0;\r
351         virtual int Height(Font &font_)=0;\r
352         virtual int AverageCharWidth(Font &font_)=0;\r
353 \r
354         virtual int SetPalette(Palette *pal, bool inBackGround)=0;\r
355         virtual void SetClip(PRectangle rc)=0;\r
356         virtual void FlushCachedState()=0;\r
357 \r
358         virtual void SetUnicodeMode(bool unicodeMode_)=0;\r
359         virtual void SetDBCSMode(int codePage)=0;\r
360 };\r
361 \r
362 /**\r
363  * A simple callback action passing one piece of untyped user data.\r
364  */\r
365 typedef void (*CallBackAction)(void*);\r
366 \r
367 /**\r
368  * Class to hide the details of window manipulation.\r
369  * Does not own the window which will normally have a longer life than this object.\r
370  */\r
371 class Window {\r
372 protected:\r
373         WindowID id;\r
374 #if PLAT_MACOSX\r
375         void *windowRef;\r
376         void *control;\r
377 #endif\r
378 public:\r
379         Window() : id(0), cursorLast(cursorInvalid) {\r
380 #if PLAT_MACOSX\r
381           windowRef = 0;\r
382           control = 0;\r
383 #endif\r
384         }\r
385         Window(const Window &source) : id(source.id), cursorLast(cursorInvalid) {\r
386 #if PLAT_MACOSX\r
387           windowRef = 0;\r
388           control = 0;\r
389 #endif\r
390         }\r
391         virtual ~Window();\r
392         Window &operator=(WindowID id_) {\r
393                 id = id_;\r
394                 return *this;\r
395         }\r
396         WindowID GetID() const { return id; }\r
397         bool Created() const { return id != 0; }\r
398         void Destroy();\r
399         bool HasFocus();\r
400         PRectangle GetPosition();\r
401         void SetPosition(PRectangle rc);\r
402         void SetPositionRelative(PRectangle rc, Window relativeTo);\r
403         PRectangle GetClientPosition();\r
404         void Show(bool show=true);\r
405         void InvalidateAll();\r
406         void InvalidateRectangle(PRectangle rc);\r
407         virtual void SetFont(Font &font);\r
408         enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow, cursorHand };\r
409         void SetCursor(Cursor curs);\r
410         void SetTitle(const char *s);\r
411         PRectangle GetMonitorRect(Point pt);\r
412 #if PLAT_MACOSX\r
413         void SetWindow(void *ref) { windowRef = ref; };\r
414         void SetControl(void *_control) { control = _control; };\r
415 #endif\r
416 private:\r
417         Cursor cursorLast;\r
418 };\r
419 \r
420 /**\r
421  * Listbox management.\r
422  */\r
423 \r
424 class ListBox : public Window {\r
425 public:\r
426         ListBox();\r
427         virtual ~ListBox();\r
428         static ListBox *Allocate();\r
429 \r
430         virtual void SetFont(Font &font)=0;\r
431         virtual void Create(Window &parent, int ctrlID, Point location, int lineHeight_, bool unicodeMode_)=0;\r
432         virtual void SetAverageCharWidth(int width)=0;\r
433         virtual void SetVisibleRows(int rows)=0;\r
434         virtual int GetVisibleRows() const=0;\r
435         virtual PRectangle GetDesiredRect()=0;\r
436         virtual int CaretFromEdge()=0;\r
437         virtual void Clear()=0;\r
438         virtual void Append(char *s, int type = -1)=0;\r
439         virtual int Length()=0;\r
440         virtual void Select(int n)=0;\r
441         virtual int GetSelection()=0;\r
442         virtual int Find(const char *prefix)=0;\r
443         virtual void GetValue(int n, char *value, int len)=0;\r
444         virtual void RegisterImage(int type, const char *xpm_data)=0;\r
445         virtual void ClearRegisteredImages()=0;\r
446         virtual void SetDoubleClickAction(CallBackAction, void *)=0;\r
447         virtual void SetList(const char* list, char separator, char typesep)=0;\r
448 };\r
449 \r
450 /**\r
451  * Menu management.\r
452  */\r
453 class Menu {\r
454         MenuID id;\r
455 public:\r
456         Menu();\r
457         MenuID GetID() { return id; }\r
458         void CreatePopUp();\r
459         void Destroy();\r
460         void Show(Point pt, Window &w);\r
461 };\r
462 \r
463 class ElapsedTime {\r
464         long bigBit;\r
465         long littleBit;\r
466 public:\r
467         ElapsedTime();\r
468         double Duration(bool reset=false);\r
469 };\r
470 \r
471 /**\r
472  * Dynamic Library (DLL/SO/...) loading\r
473  */\r
474 class DynamicLibrary {\r
475 public:\r
476         virtual ~DynamicLibrary() {};\r
477 \r
478         /// @return Pointer to function "name", or NULL on failure.\r
479         virtual Function FindFunction(const char *name) = 0;\r
480 \r
481         /// @return true if the library was loaded successfully.\r
482         virtual bool IsValid() = 0;\r
483 \r
484         /// @return An instance of a DynamicLibrary subclass with "modulePath" loaded.\r
485         static DynamicLibrary *Load(const char *modulePath);\r
486 };\r
487 \r
488 /**\r
489  * Platform class used to retrieve system wide parameters such as double click speed\r
490  * and chrome colour. Not a creatable object, more of a module with several functions.\r
491  */\r
492 class Platform {\r
493         // Private so Platform objects can not be copied\r
494         Platform(const Platform &) {}\r
495         Platform &operator=(const Platform &) { return *this; }\r
496 public:\r
497         // Should be private because no new Platforms are ever created\r
498         // but gcc warns about this\r
499         Platform() {}\r
500         ~Platform() {}\r
501         static ColourDesired Chrome();\r
502         static ColourDesired ChromeHighlight();\r
503         static const char *DefaultFont();\r
504         static int DefaultFontSize();\r
505         static unsigned int DoubleClickTime();\r
506         static bool MouseButtonBounce();\r
507         static void DebugDisplay(const char *s);\r
508         static bool IsKeyDown(int key);\r
509         static long SendScintilla(\r
510                 WindowID w, unsigned int msg, unsigned long wParam=0, long lParam=0);\r
511         static long SendScintillaPointer(\r
512                 WindowID w, unsigned int msg, unsigned long wParam=0, void *lParam=0);\r
513         static bool IsDBCSLeadByte(int codePage, char ch);\r
514         static int DBCSCharLength(int codePage, const char *s);\r
515         static int DBCSCharMaxLength();\r
516 \r
517         // These are utility functions not really tied to a platform\r
518         static int Minimum(int a, int b);\r
519         static int Maximum(int a, int b);\r
520         // Next three assume 16 bit shorts and 32 bit longs\r
521         static long LongFromTwoShorts(short a,short b) {\r
522                 return (a) | ((b) << 16);\r
523         }\r
524         static short HighShortFromLong(long x) {\r
525                 return static_cast<short>(x >> 16);\r
526         }\r
527         static short LowShortFromLong(long x) {\r
528                 return static_cast<short>(x & 0xffff);\r
529         }\r
530         static void DebugPrintf(const char *format, ...);\r
531         static bool ShowAssertionPopUps(bool assertionPopUps_);\r
532         static void Assert(const char *c, const char *file, int line);\r
533         static int Clamp(int val, int minVal, int maxVal);\r
534 };\r
535 \r
536 #ifdef  NDEBUG\r
537 #define PLATFORM_ASSERT(c) ((void)0)\r
538 #else\r
539 #ifdef SCI_NAMESPACE\r
540 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__))\r
541 #else\r
542 #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__))\r
543 #endif\r
544 #endif\r
545 \r
546 #ifdef SCI_NAMESPACE\r
547 }\r
548 #endif\r
549 \r
550 // Shut up annoying Visual C++ warnings:\r
551 #ifdef _MSC_VER\r
552 #pragma warning(disable: 4244 4309 4514 4710)\r
553 #endif\r
554 \r
555 #endif\r