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