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