X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de20db997ddf7ee903076e72e9918caa2e269c19..4161723f46249f316c0d4932364d413eefc7460c:/wxPython/src/gdi.i?ds=inline diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index 63e628e81e..90b7415191 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -15,11 +15,11 @@ %{ #include "helpers.h" -#include #include -#ifndef __WXMSW__ -#include -#endif +#include +#include +#include +#include %} //---------------------------------------------------------------------- @@ -31,35 +31,36 @@ %import _defs.i %import misc.i +%{ + static wxString wxPyEmptyStr(""); +%} + //--------------------------------------------------------------------------- -// class wxGDIImage { -// public: -// long GetHandle(); -// void SetHandle(long handle); -// bool Ok(); -// int GetWidth(); -// int GetHeight(); -// int GetDepth(); -// void SetWidth(int w); -// void SetHeight(int h); -// void SetDepth(int d); -// void SetSize(const wxSize& size); -// }; +class wxGDIObject : public wxObject { +public: + wxGDIObject(); + ~wxGDIObject(); + + bool GetVisible(); + void SetVisible( bool visible ); + + bool IsNull(); + +}; //--------------------------------------------------------------------------- -class wxBitmap -//: public wxGDIImage +class wxBitmap : public wxGDIObject { public: - wxBitmap(const wxString& name, long type); + wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_BMP); ~wxBitmap(); wxPalette* GetPalette(); wxMask* GetMask(); - bool LoadFile(const wxString& name, long flags); - bool SaveFile(const wxString& name, int type, wxPalette* palette = NULL); + bool LoadFile(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_BMP); + bool SaveFile(const wxString& name, wxBitmapType type, wxPalette* palette = NULL); void SetMask(wxMask* mask); #ifdef __WXMSW__ void SetPalette(wxPalette& palette); @@ -82,8 +83,8 @@ public: #endif wxBitmap GetSubBitmap( const wxRect& rect ); -#ifdef __WXMSW__ bool CopyFromIcon(const wxIcon& icon); +#ifdef __WXMSW__ bool CopyFromCursor(const wxCursor& cursor); int GetQuality(); void SetQuality(int q); @@ -100,37 +101,87 @@ 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); +%new wxBitmap* wxBitmapFromBits(char* bits, int width, int height, int depth = 1 ); -#ifdef __WXMSW__ -%new wxBitmap* wxBitmapFromData(PyObject* data, long type, - int width, int height, int depth = 1); -#endif +// #ifdef __WXMSW__ +// %new wxBitmap* wxBitmapFromData(PyObject* data, long type, +// int width, int height, int depth = 1); +// #endif + + + +%{ // Implementations of some alternate "constructors" -%{ // Alternate 'constructor' wxBitmap* wxEmptyBitmap(int width, int height, int depth=-1) { return new wxBitmap(width, height, depth); } -#ifdef __WXMSW__ - wxBitmap* wxBitmapFromData(PyObject* data, long type, - int width, int height, int depth = 1) { - if (! PyString_Check(data)) { - PyErr_SetString(PyExc_TypeError, "Expected string object"); + 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]; - return new wxBitmap((void*)PyString_AsString(data), type, width, height, depth); + for(int x=0; xToString(); + } + } +}; + + +// wxFontMapper manages user-definable correspondence between logical font +// names and the fonts present on the machine. +// +// The default implementations of all functions will ask the user if they are +// not capable of finding the answer themselves and store the answer in a +// config file (configurable via SetConfigXXX functions). This behaviour may +// be disabled by giving the value of FALSE to "interactive" parameter. +// However, the functions will always consult the config file to allow the +// user-defined values override the default logic and there is no way to +// disable this - which shouldn't be ever needed because if "interactive" was +// never TRUE, the config file is never created anyhow. +class wxFontMapper +{ +public: + wxFontMapper(); + ~wxFontMapper(); + + + // find an alternative for the given encoding (which is supposed to not be + // available on this system). If successful, return TRUE and rwxFontEcoding + // that can be used it wxFont ctor otherwise return FALSE + //bool GetAltForEncoding(wxFontEncoding encoding, + // wxFontEncoding *alt_encoding, + // const wxString& facename = wxEmptyString, + // bool interactive = TRUE); - return wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, - underline, faceName, encoding); + + // Find an alternative for the given encoding (which is supposed to not be + // available on this system). If successful, returns the encoding otherwise + // returns None. + %addmethods { + PyObject* GetAltForEncoding(wxFontEncoding encoding, + const wxString& facename = wxEmptyString, + bool interactive = TRUE) { + wxFontEncoding alt_enc; + if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive)) + return PyInt_FromLong(alt_enc); + else { + Py_INCREF(Py_None); + return Py_None; + } } - // NO Destructor. } - bool Ok(); - wxString GetFaceName(); - int GetFamily(); -#ifdef __WXMSW__ - int GetFontId(); -#endif - int GetPointSize(); - int GetStyle(); - bool GetUnderlined(); - int GetWeight(); - wxFontEncoding GetEncoding(); - void SetFaceName(const wxString& faceName); - void SetFamily(int family); + // checks whether given encoding is available in given face or not. + // If no facename is given, + bool IsEncodingAvailable(wxFontEncoding encoding, + const wxString& facename = wxEmptyString); + + // returns the encoding for the given charset (in the form of RFC 2046) or + // wxFONTENCODING_SYSTEM if couldn't decode it + wxFontEncoding CharsetToEncoding(const wxString& charset, + bool interactive = TRUE); + + // return internal string identifier for the encoding (see also + // GetEncodingDescription()) + static wxString GetEncodingName(wxFontEncoding encoding); + + // return user-readable string describing the given encoding + // + // NB: hard-coded now, but might change later (read it from config?) + static wxString GetEncodingDescription(wxFontEncoding encoding); + + // the parent window for modal dialogs + void SetDialogParent(wxWindow *parent); + + // the title for the dialogs (note that default is quite reasonable) + void SetDialogTitle(const wxString& title); + + // functions which allow to configure the config object used: by default, + // the global one (from wxConfigBase::Get() will be used) and the default + // root path for the config settings is the string returned by + // GetDefaultConfigPath() + + + // set the config object to use (may be NULL to use default) + void SetConfig(wxConfigBase *config); + + // set the root config path to use (should be an absolute path) + void SetConfigPath(const wxString& prefix); + + // return default config path + static const wxChar *GetDefaultConfigPath(); +}; + + + + +class wxFont : public wxGDIObject { +public: + wxFont( int pointSize, int family, int style, int weight, + int underline=FALSE, char* faceName = "", + wxFontEncoding encoding=wxFONTENCODING_DEFAULT); + + %name(wxFontFromNativeInfo)wxFont(const wxNativeFontInfo& info); + + ~wxFont(); + + bool Ok() const; + int GetPointSize() const; + int GetFamily() const; + int GetStyle() const; + int GetWeight() const; + bool GetUnderlined() const; + wxString GetFaceName() const; + wxFontEncoding GetEncoding() const; + wxNativeFontInfo* GetNativeFontInfo() const; + void SetPointSize(int pointSize); + void SetFamily(int family); void SetStyle(int style); - void SetUnderlined(bool underlined); void SetWeight(int weight); + void SetFaceName(const wxString& faceName); + void SetUnderlined(bool underlined); void SetEncoding(wxFontEncoding encoding); - wxString GetFamilyString(); - wxString GetStyleString(); - wxString GetWeightString(); + void SetNativeFontInfo(const wxNativeFontInfo& info); + + wxString GetFamilyString() const; + wxString GetStyleString() const; + wxString GetWeightString() const; + + static wxFontEncoding GetDefaultEncoding(); + static void SetDefaultEncoding(wxFontEncoding encoding); + }; -%inline %{ - wxFontEncoding wxFont_GetDefaultEncoding() { - return wxFont::GetDefaultEncoding(); - } - void wxFont_SetDefaultEncoding(wxFontEncoding encoding) { - wxFont::SetDefaultEncoding(encoding); - } -%} +class wxFontList : public wxObject { +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); + + int GetCount(); +}; + //---------------------------------------------------------------------- -class wxColour { +class wxColour : public wxObject { public: wxColour(unsigned char red=0, unsigned char green=0, unsigned char blue=0); ~wxColour(); @@ -347,22 +583,30 @@ public: %} -//---------------------------------------------------------------------- - -class wxPen { +class wxColourDatabase : public wxObject { 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 wxGDIObject { +public: + wxPen(wxColour& colour, int width=1, int style=wxSOLID); + ~wxPen(); int GetCap(); - wxColour& GetColour(); + wxColour GetColour(); int GetJoin(); int GetStyle(); @@ -375,7 +619,7 @@ public: void SetWidth(int width); // **** This one needs to return a list of ints (wxDash) - int GetDashes(wxDash **dashes); + //int GetDashes(wxDash **dashes); void SetDashes(int LCOUNT, wxDash* choices); #ifdef __WXMSW__ @@ -384,22 +628,71 @@ public: #endif }; -//---------------------------------------------------------------------- -class wxBrush { + + +// The list of ints for the dashes needs to exist for the life of the pen +// so we make it part of the class to save it. wxPyPen is aliased to wxPen +// in _extras.py + +%{ +class wxPyPen : public wxPen { 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); + wxPyPen(wxColour& colour, int width=1, int style=wxSOLID) + : wxPen(colour, width, style) + { m_dash = NULL; } + ~wxPyPen() { + if (m_dash) + delete [] m_dash; + } + + void SetDashes(int nb_dashes, const wxDash *dash) { + if (m_dash) + delete [] m_dash; + m_dash = new wxDash[nb_dashes]; + for (int i=0; iSetPen(*pen); + if (!isFastPens) + Py_DECREF(obj); + } + + // Get the point coordinants + if (isFastSeq) { + obj = PySequence_Fast_GET_ITEM(pyPoints, i); + } + else { + obj = PySequence_GetItem(pyPoints, i); + } + if (! _2int_seq_helper(obj, &x1, &y1)) { + if (!isFastPens) + Py_DECREF(obj); + goto err0; + } + + // Now draw the point + self->DrawPoint(x1, y1); + + if (!isFastSeq) + Py_DECREF(obj); + } + + Py_INCREF(Py_None); + return Py_None; + + err1: + PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens"); + return NULL; + err0: + PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x,y) sequences."); + return NULL; + } + + + // Draw a line for every set of coordinants in pyLines, optionally + // setting a new pen for each + PyObject* _DrawLineList(PyObject* pyLines, PyObject* pyPens) { + bool isFastSeq = PyList_Check(pyLines) || PyTuple_Check(pyLines); + bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens); + int numObjs = 0; + int numPens = 0; + wxPen* pen; + PyObject* obj; + int x1, y1, x2, y2; + int i = 0; + + if (!PySequence_Check(pyLines)) { + goto err0; + } + if (!PySequence_Check(pyPens)) { + goto err1; + } + numObjs = PySequence_Length(pyLines); + numPens = PySequence_Length(pyPens); + + for (i = 0; i < numObjs; i++) { + // Use a new pen? + if (i < numPens) { + if (isFastPens) { + obj = PySequence_Fast_GET_ITEM(pyPens, i); + } + else { + obj = PySequence_GetItem(pyPens, i); + } + if (SWIG_GetPtrObj(obj, (void **) &pen, "_wxPen_p")) { + if (!isFastPens) + Py_DECREF(obj); + goto err1; + } + + self->SetPen(*pen); + if (!isFastPens) + Py_DECREF(obj); + } + + // Get the line coordinants + if (isFastSeq) { + obj = PySequence_Fast_GET_ITEM(pyLines, i); + } + else { + obj = PySequence_GetItem(pyLines, i); + } + if (! _4int_seq_helper(obj, &x1, &y1, &x2, &y2)) { + if (!isFastPens) + Py_DECREF(obj); + goto err0; + } + + // Now draw the line + self->DrawLine(x1, y1, x2, y2); + + if (!isFastSeq) + Py_DECREF(obj); + } + + Py_INCREF(Py_None); + return Py_None; + + err1: + PyErr_SetString(PyExc_TypeError, "Expected a sequence of wxPens"); + return NULL; + err0: + PyErr_SetString(PyExc_TypeError, "Expected a sequence of (x1,y1, x2,y2) sequences."); + return NULL; + } + } + + + %pragma(python) addtoclass = " + def DrawPointList(self, points, pens=None): + if pens is None: + pens = [] + elif isinstance(pens, wxPenPtr): + pens = [pens] + elif len(pens) != len(points): + raise ValueError('points and pens must have same length') + return self._DrawPointList(points, pens) + + def DrawLineList(self, lines, pens=None): + if pens is None: + pens = [] + elif isinstance(pens, wxPenPtr): + pens = [pens] + elif len(pens) != len(lines): + raise ValueError('lines and pens must have same length') + return self._DrawLineList(lines, pens) +" + + }; + +%{ +static void wxDC_GetBoundingBox(wxDC* dc, int* x1, int* y1, int* x2, int* y2) { + *x1 = dc->MinX(); + *y1 = dc->MinY(); + *x2 = dc->MaxX(); + *y2 = dc->MaxY(); +} +%} + //---------------------------------------------------------------------- class wxMemoryDC : public wxDC { @@ -580,41 +1079,165 @@ public: //--------------------------------------------------------------------------- -#ifndef __WXMSW__ -class wxPostScriptDC : public wxDC { + +#ifdef __WXMSW__ + +%{ +#include +%} + +class wxMetaFile : public wxObject { public: - wxPostScriptDC(const wxString& output, bool interactive = TRUE, wxWindow* win = NULL); + wxMetaFile(const wxString& filename = wxPyEmptyStr); + ~wxMetaFile(); + + bool Ok(); + bool SetClipboard(int width = 0, int height = 0); + + wxSize GetSize(); + int GetWidth(); + int GetHeight(); + + const wxString& GetFileName() const { return m_filename; } + }; -#endif -//--------------------------------------------------------------------------- +// bool wxMakeMetaFilePlaceable(const wxString& filename, +// int minX, int minY, int maxX, int maxY, float scale=1.0); -#ifdef __WXMSW__ -class wxPrinterDC : public wxDC { + +class wxMetaFileDC : public wxDC { public: - wxPrinterDC(const wxString& driver, const wxString& device, const wxString& output, - bool interactive = TRUE, int orientation = wxPORTRAIT); + wxMetaFileDC(const wxString& filename = wxPyEmptyStr, + int width = 0, int height = 0, + const wxString& description = wxPyEmptyStr); + wxMetaFile* Close(); }; + #endif //--------------------------------------------------------------------------- -#ifdef __WXMSW__ -class wxMetaFileDC : public wxDC { +class wxPalette : public wxGDIObject { public: - wxMetaFileDC(const wxString& filename = wxPyEmptyStr); - wxMetaFile* Close(); + wxPalette(int LCOUNT, byte* choices, byte* choices, byte* choices); + ~wxPalette(); + + int GetPixel(byte red, byte green, byte blue); + bool GetRGB(int pixel, byte* OUTPUT, byte* OUTPUT, byte* OUTPUT); + bool Ok(); }; -#endif //--------------------------------------------------------------------------- + +enum { + wxIMAGELIST_DRAW_NORMAL , + wxIMAGELIST_DRAW_TRANSPARENT, + wxIMAGELIST_DRAW_SELECTED, + wxIMAGELIST_DRAW_FOCUSED, + wxIMAGE_LIST_NORMAL, + wxIMAGE_LIST_SMALL, + wxIMAGE_LIST_STATE +}; + +class wxImageList : public wxObject { +public: + wxImageList(int width, int height, int mask=TRUE, int initialCount=1); + ~wxImageList(); + + int Add(const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap); + %name(AddWithColourMask)int Add(const wxBitmap& bitmap, const wxColour& maskColour); + %name(AddIcon)int Add(const wxIcon& icon); +#ifdef __WXMSW__ + bool Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap); +#else +// %name(ReplaceIcon)bool Replace(int index, const wxIcon& icon); +// int Add(const wxBitmap& bitmap); + bool Replace(int index, const wxBitmap& bitmap); +#endif + + bool Draw(int index, wxDC& dc, int x, int x, int flags = wxIMAGELIST_DRAW_NORMAL, + const bool solidBackground = FALSE); + + int GetImageCount(); + bool Remove(int index); + bool RemoveAll(); + void GetSize(int index, int& OUTPUT, int& OUTPUT); +}; + + //--------------------------------------------------------------------------- +// Regions, etc. + +enum wxRegionContain { + wxOutRegion, wxPartRegion, wxInRegion +}; + + +class wxRegion : public wxGDIObject { +public: + wxRegion(long x=0, long y=0, long width=0, long height=0); + ~wxRegion(); + + void Clear(); + wxRegionContain Contains(long x, long y); + %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt); + %name(ContainsRect)wxRegionContain Contains(const wxRect& rect); + %name(ContainsRectDim)wxRegionContain Contains(long x, long y, long w, long h); + + wxRect GetBox(); + + bool Intersect(long x, long y, long width, long height); + %name(IntersectRect)bool Intersect(const wxRect& rect); + %name(IntersectRegion)bool Intersect(const wxRegion& region); + + bool IsEmpty(); + + bool Union(long x, long y, long width, long height); + %name(UnionRect)bool Union(const wxRect& rect); + %name(UnionRegion)bool Union(const wxRegion& region); + + bool Subtract(long x, long y, long width, long height); + %name(SubtractRect)bool Subtract(const wxRect& rect); + %name(SubtractRegion)bool Subtract(const wxRegion& region); + + bool Xor(long x, long y, long width, long height); + %name(XorRect)bool Xor(const wxRect& rect); + %name(XorRegion)bool Xor(const wxRegion& region); +}; + + +class wxRegionIterator : public wxObject { +public: + wxRegionIterator(const wxRegion& region); + ~wxRegionIterator(); + + long GetX(); + long GetY(); + long GetW(); + long GetWidth(); + long GetH(); + long GetHeight(); + wxRect GetRect(); + bool HaveRects(); + void Reset(); + + %addmethods { + void Next() { + (*self) ++; + } + }; +}; + + +//--------------------------------------------------------------------------- %readonly %{ #if 0 %} + extern wxFont *wxNORMAL_FONT; extern wxFont *wxSMALL_FONT; extern wxFont *wxITALIC_FONT; @@ -654,6 +1277,7 @@ extern wxCursor *wxSTANDARD_CURSOR; extern wxCursor *wxHOURGLASS_CURSOR; extern wxCursor *wxCROSS_CURSOR; + extern wxBitmap wxNullBitmap; extern wxIcon wxNullIcon; extern wxCursor wxNullCursor; @@ -663,60 +1287,18 @@ extern wxPalette wxNullPalette; extern wxFont wxNullFont; extern wxColour wxNullColour; + +extern wxFontList* wxTheFontList; +extern wxPenList* wxThePenList; +extern wxBrushList* wxTheBrushList; +extern wxColourDatabase* wxTheColourDatabase; + + %readwrite %{ #endif %} //--------------------------------------------------------------------------- - -class wxPalette { -public: - wxPalette(int LCOUNT, byte* choices, byte* choices, byte* choices); - ~wxPalette(); - - int GetPixel(byte red, byte green, byte blue); - bool GetRGB(int pixel, byte* OUTPUT, byte* OUTPUT, byte* OUTPUT); - bool Ok(); -}; - -//--------------------------------------------------------------------------- - -enum { - wxIMAGELIST_DRAW_NORMAL , - wxIMAGELIST_DRAW_TRANSPARENT, - wxIMAGELIST_DRAW_SELECTED, - wxIMAGELIST_DRAW_FOCUSED, - wxIMAGE_LIST_NORMAL, - wxIMAGE_LIST_SMALL, - wxIMAGE_LIST_STATE -}; - -class wxImageList { -public: - wxImageList(int width, int height, int mask=TRUE, int initialCount=1); - ~wxImageList(); - - int Add(const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap); - %name(AddWithColourMask)int Add(const wxBitmap& bitmap, const wxColour& maskColour); - %name(AddIcon)int Add(const wxIcon& icon); -#ifdef __WXMSW__ - bool Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap); -#else -// %name(ReplaceIcon)bool Replace(int index, const wxIcon& icon); -// int Add(const wxBitmap& bitmap); - bool Replace(int index, const wxBitmap& bitmap); -#endif - - bool Draw(int index, wxDC& dc, int x, int x, int flags = wxIMAGELIST_DRAW_NORMAL, - const bool solidBackground = FALSE); - - int GetImageCount(); - bool Remove(int index); - bool RemoveAll(); - void GetSize(int index, int& OUTPUT, int& OUTPUT); -}; - - //---------------------------------------------------------------------------