]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/gdi.i
Added a set of sophisticated Error Dialogs from Chris Fama.
[wxWidgets.git] / wxPython / src / gdi.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gdi.i
3 // Purpose: SWIG interface file for wxDC, wxBrush, wxPen, wxFont, etc.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7/7/97
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module gdi
15
16 %{
17 #include "helpers.h"
18 #include <wx/metafile.h>
19 #include <wx/imaglist.h>
20 #ifndef __WXMSW__
21 #include <wx/dcps.h>
22 #endif
23 #include <wx/fontmap.h>
24 #include <wx/fontenc.h>
25 #include <wx/fontmap.h>
26 #include <wx/fontutil.h>
27 %}
28
29 //----------------------------------------------------------------------
30
31 %include typemaps.i
32 %include my_typemaps.i
33
34 // Import some definitions of other classes, etc.
35 %import _defs.i
36 %import misc.i
37
38 %{
39 static wxString wxPyEmptyStr("");
40 %}
41
42 //---------------------------------------------------------------------------
43
44 class wxGDIObject : public wxObject {
45 public:
46 wxGDIObject();
47 ~wxGDIObject();
48
49 bool GetVisible();
50 void SetVisible( bool visible );
51
52 bool IsNull();
53
54 };
55
56 //---------------------------------------------------------------------------
57
58 class wxBitmap : public wxGDIObject
59 {
60 public:
61 wxBitmap(const wxString& name, wxBitmapType type);
62 ~wxBitmap();
63
64 wxPalette* GetPalette();
65 wxMask* GetMask();
66 bool LoadFile(const wxString& name, long flags);
67 bool SaveFile(const wxString& name, int type, wxPalette* palette = NULL);
68 void SetMask(wxMask* mask);
69 #ifdef __WXMSW__
70 void SetPalette(wxPalette& palette);
71 #endif
72
73 // wxGDIImage methods
74 #ifdef __WXMSW__
75 long GetHandle();
76 void SetHandle(long handle);
77 #endif
78 bool Ok();
79 int GetWidth();
80 int GetHeight();
81 int GetDepth();
82 void SetWidth(int w);
83 void SetHeight(int h);
84 void SetDepth(int d);
85 #ifdef __WXMSW__
86 void SetSize(const wxSize& size);
87 #endif
88
89 wxBitmap GetSubBitmap( const wxRect& rect );
90 bool CopyFromIcon(const wxIcon& icon);
91 #ifdef __WXMSW__
92 bool CopyFromCursor(const wxCursor& cursor);
93 int GetQuality();
94 void SetQuality(int q);
95 #endif
96
97 %pragma(python) addtoclass = "
98 def __del__(self,gdic=gdic):
99 try:
100 if self.thisown == 1 :
101 gdic.delete_wxBitmap(self)
102 except:
103 pass
104 "
105 };
106
107
108 // Declarations of some alternate "constructors"
109 %new wxBitmap* wxEmptyBitmap(int width, int height, int depth=-1);
110 %new wxBitmap* wxBitmapFromXPMData(PyObject* listOfStrings);
111 %new wxBitmap* wxBitmapFromIcon(const wxIcon& icon);
112 %new wxBitmap* wxBitmapFromBits(char* bits, int width, int height, int depth = 1 );
113
114 // #ifdef __WXMSW__
115 // %new wxBitmap* wxBitmapFromData(PyObject* data, long type,
116 // int width, int height, int depth = 1);
117 // #endif
118
119
120
121 %{ // Implementations of some alternate "constructors"
122
123 wxBitmap* wxEmptyBitmap(int width, int height, int depth=-1) {
124 return new wxBitmap(width, height, depth);
125 }
126
127 static char** ConvertListOfStrings(PyObject* listOfStrings) {
128 char** cArray = NULL;
129 int count;
130
131 if (!PyList_Check(listOfStrings)) {
132 PyErr_SetString(PyExc_TypeError, "Expected a list of strings.");
133 return NULL;
134 }
135 count = PyList_Size(listOfStrings);
136 cArray = new char*[count];
137
138 for(int x=0; x<count; x++) {
139 // TODO: Need some validation and error checking here
140 cArray[x] = PyString_AsString(PyList_GET_ITEM(listOfStrings, x));
141 }
142 return cArray;
143 }
144
145
146 wxBitmap* wxBitmapFromXPMData(PyObject* listOfStrings) {
147 char** cArray = NULL;
148 wxBitmap* bmp;
149
150 cArray = ConvertListOfStrings(listOfStrings);
151 if (! cArray)
152 return NULL;
153 bmp = new wxBitmap(cArray);
154 delete [] cArray;
155 return bmp;
156 }
157
158
159 wxBitmap* wxBitmapFromIcon(const wxIcon& icon) {
160 return new wxBitmap(icon);
161 }
162
163
164 wxBitmap* wxBitmapFromBits(char* bits, int width, int height, int depth = 1 ) {
165 return new wxBitmap(bits, width, height, depth);
166 }
167
168
169 // #ifdef __WXMSW__
170 // wxBitmap* wxBitmapFromData(PyObject* data, long type,
171 // int width, int height, int depth = 1) {
172 // if (! PyString_Check(data)) {
173 // PyErr_SetString(PyExc_TypeError, "Expected string object");
174 // return NULL;
175 // }
176 // return new wxBitmap((void*)PyString_AsString(data), type, width, height, depth);
177 // }
178 // #endif
179 %}
180
181 //---------------------------------------------------------------------------
182
183 class wxMask : public wxObject {
184 public:
185 wxMask(const wxBitmap& bitmap);
186 //~wxMask();
187
188 %addmethods { void Destroy() { delete self; } }
189 };
190
191 %new wxMask* wxMaskColour(const wxBitmap& bitmap, const wxColour& colour);
192 %{
193 wxMask* wxMaskColour(const wxBitmap& bitmap, const wxColour& colour) {
194 return new wxMask(bitmap, colour);
195 }
196 %}
197
198
199 //---------------------------------------------------------------------------
200
201
202 class wxIcon : public wxGDIObject
203 {
204 public:
205 wxIcon(const wxString& name, long flags,
206 int desiredWidth = -1, int desiredHeight = -1);
207 ~wxIcon();
208
209 bool LoadFile(const wxString& name, long flags);
210
211 // wxGDIImage methods
212 #ifdef __WXMSW__
213 long GetHandle();
214 void SetHandle(long handle);
215 #endif
216 bool Ok();
217 int GetWidth();
218 int GetHeight();
219 int GetDepth();
220 void SetWidth(int w);
221 void SetHeight(int h);
222 void SetDepth(int d);
223 #ifdef __WXMSW__
224 void SetSize(const wxSize& size);
225 #endif
226 void CopyFromBitmap(const wxBitmap& bmp);
227
228 %pragma(python) addtoclass = "
229 def __del__(self,gdic=gdic):
230 try:
231 if self.thisown == 1 :
232 gdic.delete_wxIcon(self)
233 except:
234 pass
235 "
236 };
237
238
239 // Declarations of some alternate "constructors"
240 %new wxIcon* wxEmptyIcon();
241 %new wxIcon* wxIconFromXPMData(PyObject* listOfStrings);
242
243 %{ // Implementations of some alternate "constructors"
244 wxIcon* wxEmptyIcon() {
245 return new wxIcon();
246 }
247
248 wxIcon* wxIconFromXPMData(PyObject* listOfStrings) {
249 char** cArray = NULL;
250 wxIcon* icon;
251
252 cArray = ConvertListOfStrings(listOfStrings);
253 if (! cArray)
254 return NULL;
255 icon = new wxIcon(cArray);
256 delete [] cArray;
257 return icon;
258 }
259 %}
260
261 //---------------------------------------------------------------------------
262
263 class wxCursor : public wxGDIObject
264 {
265 public:
266 #ifdef __WXMSW__
267 wxCursor(const wxString& cursorName, long flags, int hotSpotX=0, int hotSpotY=0);
268 #endif
269 ~wxCursor();
270
271 // wxGDIImage methods
272 #ifdef __WXMSW__
273 long GetHandle();
274 void SetHandle(long handle);
275 #endif
276 bool Ok();
277 #ifdef __WXMSW__
278 int GetWidth();
279 int GetHeight();
280 int GetDepth();
281 void SetWidth(int w);
282 void SetHeight(int h);
283 void SetDepth(int d);
284 void SetSize(const wxSize& size);
285 #endif
286 };
287
288 %name(wxStockCursor) %new wxCursor* wxPyStockCursor(int id);
289 %{ // Alternate 'constructor'
290 wxCursor* wxPyStockCursor(int id) {
291 return new wxCursor(id);
292 }
293 %}
294
295 //----------------------------------------------------------------------
296
297
298 enum wxFontFamily
299 {
300 wxFONTFAMILY_DEFAULT = wxDEFAULT,
301 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
302 wxFONTFAMILY_ROMAN = wxROMAN,
303 wxFONTFAMILY_SCRIPT = wxSCRIPT,
304 wxFONTFAMILY_SWISS = wxSWISS,
305 wxFONTFAMILY_MODERN = wxMODERN,
306 wxFONTFAMILY_TELETYPE = wxTELETYPE,
307 wxFONTFAMILY_MAX
308 };
309
310 // font styles
311 enum wxFontStyle
312 {
313 wxFONTSTYLE_NORMAL = wxNORMAL,
314 wxFONTSTYLE_ITALIC = wxITALIC,
315 wxFONTSTYLE_SLANT = wxSLANT,
316 wxFONTSTYLE_MAX
317 };
318
319 // font weights
320 enum wxFontWeight
321 {
322 wxFONTWEIGHT_NORMAL = wxNORMAL,
323 wxFONTWEIGHT_LIGHT = wxLIGHT,
324 wxFONTWEIGHT_BOLD = wxBOLD,
325 wxFONTWEIGHT_MAX
326 };
327
328
329 // font encodings
330 enum wxFontEncoding
331 {
332 wxFONTENCODING_SYSTEM = -1, // system default
333 wxFONTENCODING_DEFAULT, // current default encoding
334
335 // ISO8859 standard defines a number of single-byte charsets
336 wxFONTENCODING_ISO8859_1, // West European (Latin1)
337 wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
338 wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
339 wxFONTENCODING_ISO8859_4, // Baltic (old) (Latin4)
340 wxFONTENCODING_ISO8859_5, // Cyrillic
341 wxFONTENCODING_ISO8859_6, // Arabic
342 wxFONTENCODING_ISO8859_7, // Greek
343 wxFONTENCODING_ISO8859_8, // Hebrew
344 wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
345 wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
346 wxFONTENCODING_ISO8859_11, // Thai
347 wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
348 // here anyhow to make all ISO8859
349 // consecutive numbers
350 wxFONTENCODING_ISO8859_13, // Baltic (Latin7)
351 wxFONTENCODING_ISO8859_14, // Latin8
352 wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
353 wxFONTENCODING_ISO8859_MAX,
354
355 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
356 wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
357 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
358 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
359
360 // what would we do without Microsoft? They have their own encodings
361 // for DOS
362 wxFONTENCODING_CP437, // original MS-DOS codepage
363 wxFONTENCODING_CP850, // CP437 merged with Latin1
364 wxFONTENCODING_CP852, // CP437 merged with Latin2
365 wxFONTENCODING_CP855, // another cyrillic encoding
366 wxFONTENCODING_CP866, // and another one
367 // and for Windows
368 wxFONTENCODING_CP874, // WinThai
369 wxFONTENCODING_CP1250, // WinLatin2
370 wxFONTENCODING_CP1251, // WinCyrillic
371 wxFONTENCODING_CP1252, // WinLatin1
372 wxFONTENCODING_CP1253, // WinGreek (8859-7)
373 wxFONTENCODING_CP1254, // WinTurkish
374 wxFONTENCODING_CP1255, // WinHebrew
375 wxFONTENCODING_CP1256, // WinArabic
376 wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
377 wxFONTENCODING_CP12_MAX,
378
379 wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
380 wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
381
382 wxFONTENCODING_UNICODE, // Unicode - currently used only by
383 // wxEncodingConverter class
384
385 wxFONTENCODING_MAX
386 };
387
388
389
390 // wxNativeFontInfo is platform-specific font representation: this struct
391 // should be considered as opaque font description only used by the native
392 // functions, the user code can only get the objects of this type from
393 // somewhere and pass it somewhere else (possibly save them somewhere using
394 // ToString() and restore them using FromString())
395 struct wxNativeFontInfo
396 {
397 // it is important to be able to serialize wxNativeFontInfo objects to be
398 // able to store them (in config file, for example)
399 bool FromString(const wxString& s);
400 wxString ToString() const;
401
402 %addmethods {
403 wxString __str__() {
404 return self->ToString();
405 }
406 }
407 };
408
409
410 // wxFontMapper manages user-definable correspondence between logical font
411 // names and the fonts present on the machine.
412 //
413 // The default implementations of all functions will ask the user if they are
414 // not capable of finding the answer themselves and store the answer in a
415 // config file (configurable via SetConfigXXX functions). This behaviour may
416 // be disabled by giving the value of FALSE to "interactive" parameter.
417 // However, the functions will always consult the config file to allow the
418 // user-defined values override the default logic and there is no way to
419 // disable this - which shouldn't be ever needed because if "interactive" was
420 // never TRUE, the config file is never created anyhow.
421 class wxFontMapper
422 {
423 public:
424 wxFontMapper();
425 ~wxFontMapper();
426
427
428 // find an alternative for the given encoding (which is supposed to not be
429 // available on this system). If successful, return TRUE and rwxFontEcoding
430 // that can be used it wxFont ctor otherwise return FALSE
431 //bool GetAltForEncoding(wxFontEncoding encoding,
432 // wxFontEncoding *alt_encoding,
433 // const wxString& facename = wxEmptyString,
434 // bool interactive = TRUE);
435
436
437 // Find an alternative for the given encoding (which is supposed to not be
438 // available on this system). If successful, returns the encoding otherwise
439 // returns None.
440 %addmethods {
441 PyObject* GetAltForEncoding(wxFontEncoding encoding,
442 const wxString& facename = wxEmptyString,
443 bool interactive = TRUE) {
444 wxFontEncoding alt_enc;
445 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
446 return PyInt_FromLong(alt_enc);
447 else {
448 Py_INCREF(Py_None);
449 return Py_None;
450 }
451 }
452 }
453
454
455 // checks whether given encoding is available in given face or not.
456 // If no facename is given,
457 bool IsEncodingAvailable(wxFontEncoding encoding,
458 const wxString& facename = wxEmptyString);
459
460 // returns the encoding for the given charset (in the form of RFC 2046) or
461 // wxFONTENCODING_SYSTEM if couldn't decode it
462 wxFontEncoding CharsetToEncoding(const wxString& charset,
463 bool interactive = TRUE);
464
465 // return internal string identifier for the encoding (see also
466 // GetEncodingDescription())
467 static wxString GetEncodingName(wxFontEncoding encoding);
468
469 // return user-readable string describing the given encoding
470 //
471 // NB: hard-coded now, but might change later (read it from config?)
472 static wxString GetEncodingDescription(wxFontEncoding encoding);
473
474 // the parent window for modal dialogs
475 void SetDialogParent(wxWindow *parent);
476
477 // the title for the dialogs (note that default is quite reasonable)
478 void SetDialogTitle(const wxString& title);
479
480 // functions which allow to configure the config object used: by default,
481 // the global one (from wxConfigBase::Get() will be used) and the default
482 // root path for the config settings is the string returned by
483 // GetDefaultConfigPath()
484
485
486 // set the config object to use (may be NULL to use default)
487 void SetConfig(wxConfigBase *config);
488
489 // set the root config path to use (should be an absolute path)
490 void SetConfigPath(const wxString& prefix);
491
492 // return default config path
493 static const wxChar *GetDefaultConfigPath();
494 };
495
496
497
498
499 class wxFont : public wxGDIObject {
500 public:
501 wxFont( int pointSize, int family, int style, int weight,
502 int underline=FALSE, char* faceName = "",
503 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
504
505 %name(wxFontFromNativeInfo)wxFont(const wxNativeFontInfo& info);
506
507 ~wxFont();
508
509 bool Ok() const;
510 int GetPointSize() const;
511 int GetFamily() const;
512 int GetStyle() const;
513 int GetWeight() const;
514 bool GetUnderlined() const;
515 wxString GetFaceName() const;
516 wxFontEncoding GetEncoding() const;
517 wxNativeFontInfo* GetNativeFontInfo() const;
518
519 void SetPointSize(int pointSize);
520 void SetFamily(int family);
521 void SetStyle(int style);
522 void SetWeight(int weight);
523 void SetFaceName(const wxString& faceName);
524 void SetUnderlined(bool underlined);
525 void SetEncoding(wxFontEncoding encoding);
526 void SetNativeFontInfo(const wxNativeFontInfo& info);
527
528 wxString GetFamilyString() const;
529 wxString GetStyleString() const;
530 wxString GetWeightString() const;
531
532 static wxFontEncoding GetDefaultEncoding();
533 static void SetDefaultEncoding(wxFontEncoding encoding);
534
535 };
536
537
538 class wxFontList : public wxObject {
539 public:
540
541 void AddFont(wxFont* font);
542 wxFont * FindOrCreateFont(int point_size, int family, int style, int weight,
543 bool underline = FALSE, const char* facename = NULL,
544 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
545 void RemoveFont(wxFont *font);
546 };
547
548
549 //----------------------------------------------------------------------
550
551 class wxColour : public wxObject {
552 public:
553 wxColour(unsigned char red=0, unsigned char green=0, unsigned char blue=0);
554 ~wxColour();
555 unsigned char Red();
556 unsigned char Green();
557 unsigned char Blue();
558 bool Ok();
559 void Set(unsigned char red, unsigned char green, unsigned char blue);
560 %addmethods {
561 PyObject* Get() {
562 PyObject* rv = PyTuple_New(3);
563 PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red()));
564 PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green()));
565 PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue()));
566 return rv;
567 }
568 }
569 %pragma(python) addtoclass = "asTuple = Get"
570 %pragma(python) addtoclass = "def __str__(self): return str(self.asTuple())"
571 %pragma(python) addtoclass = "def __repr__(self): return str(self.asTuple())"
572
573 };
574
575 %new wxColour* wxNamedColour(const wxString& colorName);
576
577 %{ // Alternate 'constructor'
578 wxColour* wxNamedColour(const wxString& colorName) {
579 return new wxColour(colorName);
580 }
581 %}
582
583
584
585 class wxColourDatabase : public wxObject {
586 public:
587
588 wxColour *FindColour(const wxString& colour);
589 wxString FindName(const wxColour& colour) const;
590
591 %addmethods {
592 void Append(const wxString& name, int red, int green, int blue) {
593 self->Append(name.c_str(), new wxColour(red, green, blue));
594 }
595 }
596 };
597
598
599 //----------------------------------------------------------------------
600
601 class wxPen : public wxGDIObject {
602 public:
603 wxPen(wxColour& colour, int width=1, int style=wxSOLID);
604 ~wxPen();
605
606 int GetCap();
607 wxColour GetColour();
608
609 int GetJoin();
610 int GetStyle();
611 int GetWidth();
612 bool Ok();
613 void SetCap(int cap_style);
614 void SetColour(wxColour& colour);
615 void SetJoin(int join_style);
616 void SetStyle(int style);
617 void SetWidth(int width);
618
619 // **** This one needs to return a list of ints (wxDash)
620 //int GetDashes(wxDash **dashes);
621 void SetDashes(int LCOUNT, wxDash* choices);
622
623 #ifdef __WXMSW__
624 wxBitmap* GetStipple();
625 void SetStipple(wxBitmap& stipple);
626 #endif
627 };
628
629
630
631 %{
632 class wxPyPen : public wxPen {
633 public:
634 wxPyPen(wxColour& colour, int width=1, int style=wxSOLID)
635 : wxPen(colour, width, style)
636 { m_dash = NULL; }
637 ~wxPyPen() {
638 if (m_dash)
639 delete m_dash;
640 }
641
642 void SetDashes(int nb_dashes, const wxDash *dash) {
643 m_dash = new wxDash[nb_dashes];
644 for (int i=0; i<nb_dashes; i++)
645 m_dash[i] = dash[i];
646 wxPen::SetDashes(nb_dashes, m_dash);
647 }
648
649 private:
650 wxDash* m_dash;
651 };
652 %}
653
654
655
656 class wxPyPen : public wxPen {
657 public:
658 wxPyPen(wxColour& colour, int width=1, int style=wxSOLID);
659 ~wxPyPen();
660
661 void SetDashes(int LCOUNT, wxDash* choices);
662 };
663
664
665
666 class wxPenList : public wxObject {
667 public:
668
669 void AddPen(wxPen* pen);
670 wxPen* FindOrCreatePen(const wxColour& colour, int width, int style);
671 void RemovePen(wxPen* pen);
672 };
673
674
675
676 //----------------------------------------------------------------------
677
678 class wxBrush : public wxGDIObject {
679 public:
680 wxBrush(const wxColour& colour, int style=wxSOLID);
681 ~wxBrush();
682
683 wxColour GetColour();
684 wxBitmap * GetStipple();
685 int GetStyle();
686 bool Ok();
687 void SetColour(wxColour &colour);
688 void SetStipple(wxBitmap& bitmap);
689 void SetStyle(int style);
690 };
691
692
693 class wxBrushList : public wxObject {
694 public:
695
696 void AddBrush(wxBrush *brush);
697 wxBrush * FindOrCreateBrush(const wxColour& colour, int style);
698 void RemoveBrush(wxBrush *brush);
699 };
700
701 //----------------------------------------------------------------------
702
703
704
705 class wxDC : public wxObject {
706 public:
707 // wxDC(); **** abstract base class, can't instantiate.
708 ~wxDC();
709
710 void BeginDrawing();
711 // %name(BlitXY)
712 bool Blit(long xdest, long ydest,
713 long width, long height,
714 wxDC *source, long xsrc, long ysrc,
715 int logicalFunc = wxCOPY, int useMask = FALSE);
716 // bool Blit(const wxPoint& destPt, const wxSize& sz,
717 // wxDC *source, const wxPoint& srcPt,
718 // int logicalFunc = wxCOPY, int useMask = FALSE);
719
720 void Clear();
721 void CrossHair(long x, long y);
722 void DestroyClippingRegion();
723 long DeviceToLogicalX(long x);
724 long DeviceToLogicalXRel(long x);
725 long DeviceToLogicalY(long y);
726 long DeviceToLogicalYRel(long y);
727 void DrawArc(long x1, long y1, long x2, long y2, long xc, long yc);
728 void DrawCircle(long x, long y, long radius);
729 void DrawEllipse(long x, long y, long width, long height);
730 void DrawEllipticArc(long x, long y, long width, long height, long start, long end);
731 void DrawIcon(const wxIcon& icon, long x, long y);
732 void DrawLine(long x1, long y1, long x2, long y2);
733 void DrawLines(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0);
734 void DrawPolygon(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0,
735 int fill_style=wxODDEVEN_RULE);
736 void DrawPoint(long x, long y);
737 void DrawRectangle(long x, long y, long width, long height);
738 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle);
739 void DrawRoundedRectangle(long x, long y, long width, long height, long radius=20);
740 void DrawSpline(int PCOUNT, wxPoint* points);
741 void DrawText(const wxString& text, long x, long y);
742 void EndDoc();
743 void EndDrawing();
744 void EndPage();
745 void FloodFill(long x, long y, const wxColour& colour, int style=wxFLOOD_SURFACE);
746 wxBrush& GetBackground();
747 wxBrush& GetBrush();
748 long GetCharHeight();
749 long GetCharWidth();
750 void GetClippingBox(long *OUTPUT, long *OUTPUT,
751 long *OUTPUT, long *OUTPUT);
752 wxFont& GetFont();
753 int GetLogicalFunction();
754 void GetLogicalScale(double *OUTPUT, double *OUTPUT);
755 int GetMapMode();
756 bool GetOptimization();
757 wxPen& GetPen();
758 %addmethods {
759 %new wxColour* GetPixel(long x, long y) {
760 wxColour* wc = new wxColour();
761 self->GetPixel(x, y, wc);
762 return wc;
763 }
764 }
765 %name(GetSizeTuple)void GetSize(int* OUTPUT, int* OUTPUT);
766 wxSize GetSize();
767 wxSize GetSizeMM();
768 wxColour GetTextBackground();
769 void GetTextExtent(const wxString& string, long *OUTPUT, long *OUTPUT);
770 %name(GetFullTextExtent)void GetTextExtent(const wxString& string,
771 long *OUTPUT, long *OUTPUT, long *OUTPUT, long* OUTPUT,
772 const wxFont* font = NULL);
773 wxColour GetTextForeground();
774 void GetUserScale(double *OUTPUT, double *OUTPUT);
775 long LogicalToDeviceX(long x);
776 long LogicalToDeviceXRel(long x);
777 long LogicalToDeviceY(long y);
778 long LogicalToDeviceYRel(long y);
779 long MaxX();
780 long MaxY();
781 long MinX();
782 long MinY();
783 bool Ok();
784 void SetDeviceOrigin(long x, long y);
785 void SetBackground(const wxBrush& brush);
786 void SetBackgroundMode(int mode);
787 void SetClippingRegion(long x, long y, long width, long height);
788 %name(SetClippingRegionAsRegion) void SetClippingRegion(const wxRegion& region);
789 void SetPalette(const wxPalette& colourMap);
790 void SetBrush(const wxBrush& brush);
791 void SetFont(const wxFont& font);
792 void SetLogicalFunction(int function);
793 void SetLogicalScale(double x, double y);
794 void SetMapMode(int mode);
795 void SetOptimization(bool optimize);
796 void SetPen(const wxPen& pen);
797 void SetTextBackground(const wxColour& colour);
798 void SetTextForeground(const wxColour& colour);
799 void SetUserScale(double x_scale, double y_scale);
800 bool StartDoc(const wxString& message);
801 void StartPage();
802
803
804
805 void DrawBitmap(const wxBitmap& bitmap, long x, long y,
806 int useMask = FALSE);
807
808 bool CanDrawBitmap();
809 bool CanGetTextExtent();
810 int GetDepth();
811 wxSize GetPPI();
812
813 void GetLogicalOrigin(int *OUTPUT, int *OUTPUT);
814 void SetLogicalOrigin(int x, int y);
815 void GetDeviceOrigin(int *OUTPUT, int *OUTPUT);
816 void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
817
818 void CalcBoundingBox(int x, int y);
819 void ResetBoundingBox();
820
821 %addmethods {
822 void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT);
823 // See below for implementation
824 }
825
826 #ifdef __WXMSW__
827 long GetHDC();
828 #endif
829
830
831 %addmethods {
832 // NOTE: These methods are VERY SIMILAR in implentation. It would be
833 // nice to factor out code and or turn them into a set of
834 // template-like macros.
835
836 // Draw a point for every set of coordinants in pyPoints, optionally
837 // setting a new pen for each
838 PyObject* _DrawPointList(PyObject* pyPoints, PyObject* pyPens) {
839 bool isFastSeq = PyList_Check(pyPoints) || PyTuple_Check(pyPoints);
840 bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
841 int numObjs = 0;
842 int numPens = 0;
843 wxPen* pen;
844 PyObject* obj;
845 int x1, y1;
846 int i = 0;
847
848 if (!PySequence_Check(pyPoints)) {
849 goto err0;
850 }
851 if (!PySequence_Check(pyPens)) {
852 goto err1;
853 }
854 numObjs = PySequence_Length(pyPoints);
855 numPens = PySequence_Length(pyPens);
856
857 for (i = 0; i < numObjs; i++) {
858 // Use a new pen?
859 if (i < numPens) {
860 if (isFastPens) {
861 obj = PySequence_Fast_GET_ITEM(pyPens, i);
862 }
863 else {
864 obj = PySequence_GetItem(pyPens, i);
865 }
866 if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
867 if (!isFastPens)
868 Py_DECREF(obj);
869 goto err1;
870 }
871
872 self->SetPen(*pen);
873 if (!isFastPens)
874 Py_DECREF(obj);
875 }
876
877 // Get the point coordinants
878 if (isFastSeq) {
879 obj = PySequence_Fast_GET_ITEM(pyPoints, i);
880 }
881 else {
882 obj = PySequence_GetItem(pyPoints, i);
883 }
884 if (! _2int_seq_helper(obj, &x1, &y1)) {
885 if (!isFastPens)
886 Py_DECREF(obj);
887 goto err0;
888 }
889
890 // Now draw the point
891 self->DrawPoint(x1, y1);
892
893 if (!isFastSeq)
894 Py_DECREF(obj);
895 }
896
897 Py_INCREF(Py_None);
898 return Py_None;
899
900 err1:
901 PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
902 return NULL;
903 err0:
904 PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences.");
905 return NULL;
906 }
907
908
909 // Draw a line for every set of coordinants in pyLines, optionally
910 // setting a new pen for each
911 PyObject* _DrawLineList(PyObject* pyLines, PyObject* pyPens) {
912 bool isFastSeq = PyList_Check(pyLines) || PyTuple_Check(pyLines);
913 bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens);
914 int numObjs = 0;
915 int numPens = 0;
916 wxPen* pen;
917 PyObject* obj;
918 int x1, y1, x2, y2;
919 int i = 0;
920
921 if (!PySequence_Check(pyLines)) {
922 goto err0;
923 }
924 if (!PySequence_Check(pyPens)) {
925 goto err1;
926 }
927 numObjs = PySequence_Length(pyLines);
928 numPens = PySequence_Length(pyPens);
929
930 for (i = 0; i < numObjs; i++) {
931 // Use a new pen?
932 if (i < numPens) {
933 if (isFastPens) {
934 obj = PySequence_Fast_GET_ITEM(pyPens, i);
935 }
936 else {
937 obj = PySequence_GetItem(pyPens, i);
938 }
939 if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) {
940 if (!isFastPens)
941 Py_DECREF(obj);
942 goto err1;
943 }
944
945 self->SetPen(*pen);
946 if (!isFastPens)
947 Py_DECREF(obj);
948 }
949
950 // Get the line coordinants
951 if (isFastSeq) {
952 obj = PySequence_Fast_GET_ITEM(pyLines, i);
953 }
954 else {
955 obj = PySequence_GetItem(pyLines, i);
956 }
957 if (! _4int_seq_helper(obj, &x1, &y1, &x2, &y2)) {
958 if (!isFastPens)
959 Py_DECREF(obj);
960 goto err0;
961 }
962
963 // Now draw the line
964 self->DrawLine(x1, y1, x2, y2);
965
966 if (!isFastSeq)
967 Py_DECREF(obj);
968 }
969
970 Py_INCREF(Py_None);
971 return Py_None;
972
973 err1:
974 PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens");
975 return NULL;
976 err0:
977 PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x2,y2) sequences.");
978 return NULL;
979 }
980 }
981
982
983 %pragma(python) addtoclass = "
984 def DrawPointList(self, points, pens=None):
985 if pens is None:
986 pens = []
987 elif isinstance(pens, wxPenPtr):
988 pens = [pens]
989 elif len(pens) != len(points):
990 raise ValueError('points and pens must have same length')
991 return self._DrawPointList(points, pens)
992
993 def DrawLineList(self, lines, pens=None):
994 if pens is None:
995 pens = []
996 elif isinstance(pens, wxPenPtr):
997 pens = [pens]
998 elif len(pens) != len(lines):
999 raise ValueError('lines and pens must have same length')
1000 return self._DrawLineList(lines, pens)
1001 "
1002
1003
1004 };
1005
1006
1007
1008 %{
1009 static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) {
1010 *x1 = dc->MinX();
1011 *y1 = dc->MinY();
1012 *x2 = dc->MaxX();
1013 *y2 = dc->MaxY();
1014 }
1015 %}
1016
1017 //----------------------------------------------------------------------
1018
1019 class wxMemoryDC : public wxDC {
1020 public:
1021 wxMemoryDC();
1022
1023 void SelectObject(const wxBitmap& bitmap);
1024 }
1025
1026 %new wxMemoryDC* wxMemoryDCFromDC(wxDC* oldDC);
1027 %{ // Alternate 'constructor'
1028 wxMemoryDC* wxMemoryDCFromDC(wxDC* oldDC) {
1029 return new wxMemoryDC(oldDC);
1030 }
1031 %}
1032
1033
1034 //---------------------------------------------------------------------------
1035
1036 class wxScreenDC : public wxDC {
1037 public:
1038 wxScreenDC();
1039
1040 %name(StartDrawingOnTopWin) bool StartDrawingOnTop(wxWindow* window);
1041 bool StartDrawingOnTop(wxRect* rect = NULL);
1042 bool EndDrawingOnTop();
1043 };
1044
1045 //---------------------------------------------------------------------------
1046
1047 class wxClientDC : public wxDC {
1048 public:
1049 wxClientDC(wxWindow* win);
1050 };
1051
1052 //---------------------------------------------------------------------------
1053
1054 class wxPaintDC : public wxDC {
1055 public:
1056 wxPaintDC(wxWindow* win);
1057 };
1058
1059 //---------------------------------------------------------------------------
1060
1061 class wxWindowDC : public wxDC {
1062 public:
1063 wxWindowDC(wxWindow* win);
1064 };
1065
1066 //---------------------------------------------------------------------------
1067
1068 #ifndef __WXMSW__
1069 class wxPostScriptDC : public wxDC {
1070 public:
1071 wxPostScriptDC(const wxString& output, bool interactive = TRUE, wxWindow* win = NULL);
1072 };
1073 #endif
1074
1075 //---------------------------------------------------------------------------
1076
1077
1078 #ifdef __WXMSW__
1079 class wxMetaFileDC : public wxDC {
1080 public:
1081 wxMetaFileDC(const wxString& filename = wxPyEmptyStr);
1082 wxMetaFile* Close();
1083 };
1084 #endif
1085
1086 //---------------------------------------------------------------------------
1087 //---------------------------------------------------------------------------
1088
1089
1090 %readonly
1091 %{
1092 #if 0
1093 %}
1094 extern wxFont *wxNORMAL_FONT;
1095 extern wxFont *wxSMALL_FONT;
1096 extern wxFont *wxITALIC_FONT;
1097 extern wxFont *wxSWISS_FONT;
1098
1099 extern wxPen *wxRED_PEN;
1100 extern wxPen *wxCYAN_PEN;
1101 extern wxPen *wxGREEN_PEN;
1102 extern wxPen *wxBLACK_PEN;
1103 extern wxPen *wxWHITE_PEN;
1104 extern wxPen *wxTRANSPARENT_PEN;
1105 extern wxPen *wxBLACK_DASHED_PEN;
1106 extern wxPen *wxGREY_PEN;
1107 extern wxPen *wxMEDIUM_GREY_PEN;
1108 extern wxPen *wxLIGHT_GREY_PEN;
1109
1110 extern wxBrush *wxBLUE_BRUSH;
1111 extern wxBrush *wxGREEN_BRUSH;
1112 extern wxBrush *wxWHITE_BRUSH;
1113 extern wxBrush *wxBLACK_BRUSH;
1114 extern wxBrush *wxTRANSPARENT_BRUSH;
1115 extern wxBrush *wxCYAN_BRUSH;
1116 extern wxBrush *wxRED_BRUSH;
1117 extern wxBrush *wxGREY_BRUSH;
1118 extern wxBrush *wxMEDIUM_GREY_BRUSH;
1119 extern wxBrush *wxLIGHT_GREY_BRUSH;
1120
1121 extern wxColour *wxBLACK;
1122 extern wxColour *wxWHITE;
1123 extern wxColour *wxRED;
1124 extern wxColour *wxBLUE;
1125 extern wxColour *wxGREEN;
1126 extern wxColour *wxCYAN;
1127 extern wxColour *wxLIGHT_GREY;
1128
1129 extern wxCursor *wxSTANDARD_CURSOR;
1130 extern wxCursor *wxHOURGLASS_CURSOR;
1131 extern wxCursor *wxCROSS_CURSOR;
1132
1133 extern wxBitmap wxNullBitmap;
1134 extern wxIcon wxNullIcon;
1135 extern wxCursor wxNullCursor;
1136 extern wxPen wxNullPen;
1137 extern wxBrush wxNullBrush;
1138 extern wxPalette wxNullPalette;
1139 extern wxFont wxNullFont;
1140 extern wxColour wxNullColour;
1141
1142
1143 extern wxFontList* wxTheFontList;
1144 extern wxPenList* wxThePenList;
1145 extern wxBrushList* wxTheBrushList;
1146 extern wxColourDatabase* wxTheColourDatabase;
1147
1148
1149 %readwrite
1150 %{
1151 #endif
1152 %}
1153
1154 //---------------------------------------------------------------------------
1155
1156 class wxPalette : public wxGDIObject {
1157 public:
1158 wxPalette(int LCOUNT, byte* choices, byte* choices, byte* choices);
1159 ~wxPalette();
1160
1161 int GetPixel(byte red, byte green, byte blue);
1162 bool GetRGB(int pixel, byte* OUTPUT, byte* OUTPUT, byte* OUTPUT);
1163 bool Ok();
1164 };
1165
1166 //---------------------------------------------------------------------------
1167
1168 enum {
1169 wxIMAGELIST_DRAW_NORMAL ,
1170 wxIMAGELIST_DRAW_TRANSPARENT,
1171 wxIMAGELIST_DRAW_SELECTED,
1172 wxIMAGELIST_DRAW_FOCUSED,
1173 wxIMAGE_LIST_NORMAL,
1174 wxIMAGE_LIST_SMALL,
1175 wxIMAGE_LIST_STATE
1176 };
1177
1178 class wxImageList : public wxObject {
1179 public:
1180 wxImageList(int width, int height, int mask=TRUE, int initialCount=1);
1181 ~wxImageList();
1182
1183 int Add(const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap);
1184 %name(AddWithColourMask)int Add(const wxBitmap& bitmap, const wxColour& maskColour);
1185 %name(AddIcon)int Add(const wxIcon& icon);
1186 #ifdef __WXMSW__
1187 bool Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap);
1188 #else
1189 // %name(ReplaceIcon)bool Replace(int index, const wxIcon& icon);
1190 // int Add(const wxBitmap& bitmap);
1191 bool Replace(int index, const wxBitmap& bitmap);
1192 #endif
1193
1194 bool Draw(int index, wxDC& dc, int x, int x, int flags = wxIMAGELIST_DRAW_NORMAL,
1195 const bool solidBackground = FALSE);
1196
1197 int GetImageCount();
1198 bool Remove(int index);
1199 bool RemoveAll();
1200 void GetSize(int index, int& OUTPUT, int& OUTPUT);
1201 };
1202
1203
1204 //---------------------------------------------------------------------------
1205 // Regions, etc.
1206
1207 enum wxRegionContain {
1208 wxOutRegion, wxPartRegion, wxInRegion
1209 };
1210
1211
1212 class wxRegion : public wxGDIObject {
1213 public:
1214 wxRegion(long x=0, long y=0, long width=0, long height=0);
1215 ~wxRegion();
1216
1217 void Clear();
1218 wxRegionContain Contains(long x, long y);
1219 %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt);
1220 %name(ContainsRect)wxRegionContain Contains(const wxRect& rect);
1221 %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h);
1222
1223 wxRect GetBox();
1224
1225 bool Intersect(long x, long y, long width, long height);
1226 %name(IntersectRect)bool Intersect(const wxRect& rect);
1227 %name(IntersectRegion)bool Intersect(const wxRegion& region);
1228
1229 bool IsEmpty();
1230
1231 bool Union(long x, long y, long width, long height);
1232 %name(UnionRect)bool Union(const wxRect& rect);
1233 %name(UnionRegion)bool Union(const wxRegion& region);
1234
1235 bool Subtract(long x, long y, long width, long height);
1236 %name(SubtractRect)bool Subtract(const wxRect& rect);
1237 %name(SubtractRegion)bool Subtract(const wxRegion& region);
1238
1239 bool Xor(long x, long y, long width, long height);
1240 %name(XorRect)bool Xor(const wxRect& rect);
1241 %name(XorRegion)bool Xor(const wxRegion& region);
1242 };
1243
1244
1245
1246 class wxRegionIterator : public wxObject {
1247 public:
1248 wxRegionIterator(const wxRegion& region);
1249 ~wxRegionIterator();
1250
1251 long GetX();
1252 long GetY();
1253 long GetW();
1254 long GetWidth();
1255 long GetH();
1256 long GetHeight();
1257 wxRect GetRect();
1258 bool HaveRects();
1259 void Reset();
1260
1261 %addmethods {
1262 void Next() {
1263 (*self) ++;
1264 }
1265 };
1266 };
1267
1268
1269 //---------------------------------------------------------------------------
1270