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