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