X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1b62f00d8e3ec5437ab780cb3d73d299cc61e20c..faec5a4383bb54f846c1eae142353804eb88d956:/wxPython/src/gdi.i diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index e66a31dd73..286c696f20 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -105,18 +105,60 @@ public: }; +// Declarations of some alternate "constructors" %new wxBitmap* wxEmptyBitmap(int width, int height, int depth=-1); +%new wxBitmap* wxBitmapFromXPMData(PyObject* listOfStrings); +%new wxBitmap* wxBitmapFromIcon(const wxIcon& icon); #ifdef __WXMSW__ %new wxBitmap* wxBitmapFromData(PyObject* data, long type, int width, int height, int depth = 1); #endif -%{ // Alternate 'constructor' + + +%{ // Implementations of some alternate "constructors" + wxBitmap* wxEmptyBitmap(int width, int height, int depth=-1) { return new wxBitmap(width, height, depth); } + static char** ConvertListOfStrings(PyObject* listOfStrings) { + char** cArray = NULL; + int count; + + if (!PyList_Check(listOfStrings)) { + PyErr_SetString(PyExc_TypeError, "Expected a list of strings."); + return NULL; + } + count = PyList_Size(listOfStrings); + cArray = new char*[count]; + + for(int x=0; x<count; x++) { + // TODO: Need some validation and error checking here + cArray[x] = PyString_AsString(PyList_GET_ITEM(listOfStrings, x)); + } + return cArray; + } + + wxBitmap* wxBitmapFromXPMData(PyObject* listOfStrings) { + char** cArray = NULL; + wxBitmap* bmp; + + cArray = ConvertListOfStrings(listOfStrings); + if (! cArray) + return NULL; + bmp = new wxBitmap(cArray); + delete [] cArray; + return bmp; + } + + + wxBitmap* wxBitmapFromIcon(const wxIcon& icon) { + return new wxBitmap(icon); + } + + #ifdef __WXMSW__ wxBitmap* wxBitmapFromData(PyObject* data, long type, int width, int height, int depth = 1) { @@ -136,6 +178,8 @@ class wxMask { public: wxMask(const wxBitmap& bitmap); //~wxMask(); + + %addmethods { void Destroy() { delete self; } } }; %new wxMask* wxMaskColour(const wxBitmap& bitmap, const wxColour& colour); @@ -174,6 +218,8 @@ public: #ifdef __WXMSW__ void SetSize(const wxSize& size); #endif + void CopyFromBitmap(const wxBitmap& bmp); + %pragma(python) addtoclass = " def __del__(self,gdic=gdic): try: @@ -182,10 +228,31 @@ public: except: pass " - }; +// Declarations of some alternate "constructors" +%new wxIcon* wxEmptyIcon(); +%new wxIcon* wxIconFromXPMData(PyObject* listOfStrings); + +%{ // Implementations of some alternate "constructors" + wxIcon* wxEmptyIcon() { + return new wxIcon(); + } + + wxIcon* wxIconFromXPMData(PyObject* listOfStrings) { + char** cArray = NULL; + wxIcon* icon; + + cArray = ConvertListOfStrings(listOfStrings); + if (! cArray) + return NULL; + icon = new wxIcon(cArray); + delete [] cArray; + return icon; + } +%} + //--------------------------------------------------------------------------- class wxCursor @@ -268,23 +335,15 @@ enum wxFontEncoding wxFONTENCODING_MAX }; + class wxFont { public: - // I'll do it this way to use long-lived objects and not have to - // worry about when python may delete the object. - %addmethods { - wxFont( int pointSize, int family, int style, int weight, - int underline=FALSE, char* faceName = "", - wxFontEncoding encoding=wxFONTENCODING_DEFAULT) { - - return wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, - underline, faceName, encoding); - } - // NO Destructor. - } + wxFont( int pointSize, int family, int style, int weight, + int underline=FALSE, char* faceName = "", + wxFontEncoding encoding=wxFONTENCODING_DEFAULT); + ~wxFont(); bool Ok(); - wxString GetFaceName(); int GetFamily(); #ifdef __WXMSW__ @@ -317,6 +376,18 @@ public: } %} + +class wxFontList { +public: + + void AddFont(wxFont* font); + wxFont * FindOrCreateFont(int point_size, int family, int style, int weight, + bool underline = FALSE, const char* facename = NULL, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + void RemoveFont(wxFont *font); +}; + + //---------------------------------------------------------------------- class wxColour { @@ -352,19 +423,28 @@ public: %} -//---------------------------------------------------------------------- - -class wxPen { +class wxColourDatabase { public: - // I'll do it this way to use long-lived objects and not have to - // worry about when python may delete the object. + + wxColour *FindColour(const wxString& colour); + wxString FindName(const wxColour& colour) const; + %addmethods { - wxPen(wxColour* colour, int width=1, int style=wxSOLID) { - return wxThePenList->FindOrCreatePen(*colour, width, style); + void Append(const wxString& name, int red, int green, int blue) { + self->Append(name.c_str(), new wxColour(red, green, blue)); } - // NO Destructor. } +}; + + +//---------------------------------------------------------------------- + + +class wxPen { +public: + wxPen(wxColour& colour, int width=1, int style=wxSOLID); + ~wxPen(); int GetCap(); wxColour& GetColour(); @@ -389,20 +469,23 @@ public: #endif }; + +class wxPenList { +public: + + void AddPen(wxPen* pen); + wxPen* FindOrCreatePen(const wxColour& colour, int width, int style); + void RemovePen(wxPen* pen); +}; + + + //---------------------------------------------------------------------- class wxBrush { public: - // I'll do it this way to use long-lived objects and not have to - // worry about when python may delete the object. - %addmethods { - wxBrush(const wxColour* colour, int style=wxSOLID) { - return wxTheBrushList->FindOrCreateBrush(*colour, style); - } - // NO Destructor. - } - -// wxBrush(const wxColour& colour, int style=wxSOLID); + wxBrush(const wxColour& colour, int style=wxSOLID); + ~wxBrush(); wxColour& GetColour(); wxBitmap * GetStipple(); @@ -413,6 +496,15 @@ public: void SetStyle(int style); }; + +class wxBrushList { +public: + + void AddBrush(wxBrush *brush); + wxBrush * FindOrCreateBrush(const wxColour& colour, int style); + void RemoveBrush(wxBrush *brush); +}; + //---------------------------------------------------------------------- @@ -659,6 +751,13 @@ extern wxPalette wxNullPalette; extern wxFont wxNullFont; extern wxColour wxNullColour; + +extern wxFontList* wxTheFontList; +extern wxPenList* wxThePenList; +extern wxBrushlist* wxTheBrushList; +extern wxColourDatabase* wxTheColourDatabase; + + %readwrite %{ #endif