X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6ee2116be1a8abc2cf8734bf407767c04a617990..dc0bedff0c90235ee845936035db5218a0b68a3e:/wxPython/src/gdi.i diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index ffcb6744b3..ba26ef7556 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -15,15 +15,12 @@ %{ #include "helpers.h" -#include #include -#ifndef __WXMSW__ -#include -#endif #include #include #include #include +#include %} //---------------------------------------------------------------------- @@ -35,9 +32,6 @@ %import _defs.i %import misc.i -%{ - static wxString wxPyEmptyStr(""); -%} //--------------------------------------------------------------------------- @@ -58,13 +52,13 @@ public: class wxBitmap : public wxGDIObject { public: - wxBitmap(const wxString& name, wxBitmapType type); + wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY); ~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_ANY); + bool SaveFile(const wxString& name, wxBitmapType type, wxPalette* palette = NULL); void SetMask(wxMask* mask); #ifdef __WXMSW__ void SetPalette(wxPalette& palette); @@ -87,8 +81,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); @@ -206,7 +200,9 @@ public: int desiredWidth = -1, int desiredHeight = -1); ~wxIcon(); +#ifndef __WXMAC__ bool LoadFile(const wxString& name, long flags); +#endif // wxGDIImage methods #ifdef __WXMSW__ @@ -239,6 +235,7 @@ public: // Declarations of some alternate "constructors" %new wxIcon* wxEmptyIcon(); %new wxIcon* wxIconFromXPMData(PyObject* listOfStrings); +%new wxIcon* wxIconFromBitmap(const wxBitmap& bmp); %{ // Implementations of some alternate "constructors" wxIcon* wxEmptyIcon() { @@ -256,6 +253,12 @@ public: delete [] cArray; return icon; } + + wxIcon* wxIconFromBitmap(const wxBitmap& bmp) { + wxIcon* icon = new wxIcon(); + icon->CopyFromBitmap(bmp); + return icon; + } %} //--------------------------------------------------------------------------- @@ -304,7 +307,8 @@ enum wxFontFamily wxFONTFAMILY_SWISS = wxSWISS, wxFONTFAMILY_MODERN = wxMODERN, wxFONTFAMILY_TELETYPE = wxTELETYPE, - wxFONTFAMILY_MAX + wxFONTFAMILY_MAX, + wxFONTFAMILY_UNKNOWN }; // font styles @@ -366,6 +370,10 @@ enum wxFontEncoding wxFONTENCODING_CP866, // and another one // and for Windows wxFONTENCODING_CP874, // WinThai + wxFONTENCODING_CP932, // Japanese (shift-JIS) + wxFONTENCODING_CP936, // Chiniese simplified (GB) + wxFONTENCODING_CP949, // Korean (Hangul charset) + wxFONTENCODING_CP950, // Chinese (traditional - Big5) wxFONTENCODING_CP1250, // WinLatin2 wxFONTENCODING_CP1251, // WinCyrillic wxFONTENCODING_CP1252, // WinLatin1 @@ -394,6 +402,44 @@ enum wxFontEncoding // ToString() and restore them using FromString()) struct wxNativeFontInfo { +#ifdef __WXGTK__ + // init the elements from an XLFD, return TRUE if ok + bool FromXFontName(const wxString& xFontName); + + // return false if we were never initialized with a valid XLFD + bool IsDefault() const; + + // generate an XLFD using the fontElements + wxString GetXFontName() const; + + // set the XFLD + void SetXFontName(const wxString& xFontName); +#endif + + wxNativeFontInfo() { Init(); } + + // reset to the default state + void Init(); + +#ifndef __WXGTK__ + // accessors and modifiers for the font elements + int GetPointSize() const; + wxFontStyle GetStyle() const; + wxFontWeight GetWeight() const; + bool GetUnderlined() const; + wxString GetFaceName() const; + wxFontFamily GetFamily() const; + wxFontEncoding GetEncoding() const; + + void SetPointSize(int pointsize); + void SetStyle(wxFontStyle style); + void SetWeight(wxFontWeight weight); + void SetUnderlined(bool underlined); + void SetFaceName(wxString facename); + void SetFamily(wxFontFamily family); + void SetEncoding(wxFontEncoding encoding); +#endif + // it is important to be able to serialize wxNativeFontInfo objects to be // able to store them (in config file, for example) bool FromString(const wxString& s); @@ -404,6 +450,12 @@ struct wxNativeFontInfo return self->ToString(); } } + + // we also want to present the native font descriptions to the user in some + // human-readable form (it is not platform independent neither, but can + // hopefully be understood by the user) + bool FromUserString(const wxString& s); + wxString ToUserString() const; }; @@ -514,7 +566,12 @@ public: bool GetUnderlined() const; wxString GetFaceName() const; wxFontEncoding GetEncoding() const; + + bool IsFixedWidth(); + wxNativeFontInfo* GetNativeFontInfo() const; + wxString GetNativeFontInfoDesc() const; + wxString GetNativeFontInfoUserDesc() const; void SetPointSize(int pointSize); void SetFamily(int family); @@ -524,6 +581,8 @@ public: void SetUnderlined(bool underlined); void SetEncoding(wxFontEncoding encoding); void SetNativeFontInfo(const wxNativeFontInfo& info); + // void SetNativeFontInfo(const wxString& info); + void SetNativeFontInfoUserDesc(const wxString& info); wxString GetFamilyString() const; wxString GetStyleString() const; @@ -543,6 +602,8 @@ public: bool underline = FALSE, const char* facename = NULL, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); void RemoveFont(wxFont *font); + + int GetCount(); }; @@ -590,6 +651,25 @@ public: %addmethods { void Append(const wxString& name, int red, int green, int blue) { + // first see if the name is already there + wxString cName = name; + cName.MakeUpper(); + wxString cName2 = cName; + if ( !cName2.Replace(wxT("GRAY"), wxT("GREY")) ) + cName2.clear(); + + wxNode *node = self->First(); + while ( node ) { + const wxChar *key = node->GetKeyString(); + if ( cName == key || cName2 == key ) { + wxColour* c = (wxColour *)node->Data(); + c->Set(red, green, blue); + return; + } + node = node->Next(); + } + + // otherwise append the new colour self->Append(name.c_str(), new wxColour(red, green, blue)); } } @@ -598,7 +678,6 @@ public: //---------------------------------------------------------------------- - class wxPen : public wxGDIObject { public: wxPen(wxColour& colour, int width=1, int style=wxSOLID); @@ -618,7 +697,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__ @@ -628,12 +707,58 @@ public: }; + + +// 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: + 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; iDrawLabel(text, image, rect, alignment, indexAccel, &rv); + return rv; + } + } + void DrawLine(long x1, long y1, long x2, long y2); void DrawLines(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0); void DrawPolygon(int PCOUNT, wxPoint* points, long xoffset=0, long yoffset=0, @@ -708,18 +852,18 @@ public: void EndDrawing(); void EndPage(); void FloodFill(long x, long y, const wxColour& colour, int style=wxFLOOD_SURFACE); - wxBrush& GetBackground(); - wxBrush& GetBrush(); + wxBrush GetBackground(); + wxBrush GetBrush(); long GetCharHeight(); long GetCharWidth(); void GetClippingBox(long *OUTPUT, long *OUTPUT, long *OUTPUT, long *OUTPUT); - wxFont& GetFont(); + wxFont GetFont(); int GetLogicalFunction(); void GetLogicalScale(double *OUTPUT, double *OUTPUT); int GetMapMode(); bool GetOptimization(); - wxPen& GetPen(); + wxPen GetPen(); %addmethods { %new wxColour* GetPixel(long x, long y) { wxColour* wc = new wxColour(); @@ -783,12 +927,202 @@ public: void CalcBoundingBox(int x, int y); void ResetBoundingBox(); + %addmethods { + void GetBoundingBox(int* OUTPUT, int* OUTPUT, int* OUTPUT, int* OUTPUT); + // See below for implementation + } + #ifdef __WXMSW__ long GetHDC(); #endif + + + %addmethods { + // NOTE: These methods are VERY SIMILAR in implentation. It would be + // nice to factor out common code and or turn them into a set of + // template-like macros. + + // Draw a point for every set of coordinants in pyPoints, optionally + // setting a new pen for each + PyObject* _DrawPointList(PyObject* pyPoints, PyObject* pyPens) { + bool isFastSeq = PyList_Check(pyPoints) || PyTuple_Check(pyPoints); + bool isFastPens = PyList_Check(pyPens) || PyTuple_Check(pyPens); + int numObjs = 0; + int numPens = 0; + wxPen* pen; + PyObject* obj; + int x1, y1; + int i = 0; + + if (!PySequence_Check(pyPoints)) { + goto err0; + } + if (!PySequence_Check(pyPens)) { + goto err1; + } + numObjs = PySequence_Length(pyPoints); + 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 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 { @@ -806,6 +1140,26 @@ public: %} +//--------------------------------------------------------------------------- + +class wxBufferedDC : public wxMemoryDC { +public: + // Construct a wxBufferedDC using a user supplied buffer. + wxBufferedDC( wxDC *dc, const wxBitmap &buffer ); + + // Construct a wxBufferedDC with an internal buffer of 'area' + // (where area is usually something like the size of the window + // being buffered) + %name(wxBufferedDCInternalBuffer)wxBufferedDC( wxDC *dc, const wxSize &area ); +}; + + +class wxBufferedPaintDC : public wxBufferedDC +{ +public: + wxBufferedPaintDC( wxWindow *window, const wxBitmap &buffer = wxNullBitmap ); +}; + //--------------------------------------------------------------------------- class wxScreenDC : public wxDC { @@ -840,91 +1194,42 @@ public: //--------------------------------------------------------------------------- -#ifndef __WXMSW__ -class wxPostScriptDC : public wxDC { -public: - wxPostScriptDC(const wxString& output, bool interactive = TRUE, wxWindow* win = NULL); -}; -#endif - -//--------------------------------------------------------------------------- - #ifdef __WXMSW__ -class wxMetaFileDC : public wxDC { -public: - wxMetaFileDC(const wxString& filename = wxPyEmptyStr); - wxMetaFile* Close(); -}; -#endif - -//--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- - -%readonly %{ -#if 0 +#include %} -extern wxFont *wxNORMAL_FONT; -extern wxFont *wxSMALL_FONT; -extern wxFont *wxITALIC_FONT; -extern wxFont *wxSWISS_FONT; -extern wxPen *wxRED_PEN; -extern wxPen *wxCYAN_PEN; -extern wxPen *wxGREEN_PEN; -extern wxPen *wxBLACK_PEN; -extern wxPen *wxWHITE_PEN; -extern wxPen *wxTRANSPARENT_PEN; -extern wxPen *wxBLACK_DASHED_PEN; -extern wxPen *wxGREY_PEN; -extern wxPen *wxMEDIUM_GREY_PEN; -extern wxPen *wxLIGHT_GREY_PEN; +class wxMetaFile : public wxObject { +public: + wxMetaFile(const wxString& filename = wxEmptyString); + ~wxMetaFile(); -extern wxBrush *wxBLUE_BRUSH; -extern wxBrush *wxGREEN_BRUSH; -extern wxBrush *wxWHITE_BRUSH; -extern wxBrush *wxBLACK_BRUSH; -extern wxBrush *wxTRANSPARENT_BRUSH; -extern wxBrush *wxCYAN_BRUSH; -extern wxBrush *wxRED_BRUSH; -extern wxBrush *wxGREY_BRUSH; -extern wxBrush *wxMEDIUM_GREY_BRUSH; -extern wxBrush *wxLIGHT_GREY_BRUSH; + bool Ok(); + bool SetClipboard(int width = 0, int height = 0); -extern wxColour *wxBLACK; -extern wxColour *wxWHITE; -extern wxColour *wxRED; -extern wxColour *wxBLUE; -extern wxColour *wxGREEN; -extern wxColour *wxCYAN; -extern wxColour *wxLIGHT_GREY; + wxSize GetSize(); + int GetWidth(); + int GetHeight(); -extern wxCursor *wxSTANDARD_CURSOR; -extern wxCursor *wxHOURGLASS_CURSOR; -extern wxCursor *wxCROSS_CURSOR; + const wxString& GetFileName() const { return m_filename; } -extern wxBitmap wxNullBitmap; -extern wxIcon wxNullIcon; -extern wxCursor wxNullCursor; -extern wxPen wxNullPen; -extern wxBrush wxNullBrush; -extern wxPalette wxNullPalette; -extern wxFont wxNullFont; -extern wxColour wxNullColour; +}; +// bool wxMakeMetaFilePlaceable(const wxString& filename, +// int minX, int minY, int maxX, int maxY, float scale=1.0); -extern wxFontList* wxTheFontList; -extern wxPenList* wxThePenList; -extern wxBrushList* wxTheBrushList; -extern wxColourDatabase* wxTheColourDatabase; +class wxMetaFileDC : public wxDC { +public: + wxMetaFileDC(const wxString& filename = wxEmptyString, + int width = 0, int height = 0, + const wxString& description = wxEmptyString); + wxMetaFile* Close(); +}; -%readwrite -%{ #endif -%} //--------------------------------------------------------------------------- @@ -990,6 +1295,10 @@ public: ~wxRegion(); void Clear(); +#ifndef __WXMAC__ + bool Offset(wxCoord x, wxCoord y); +#endif + wxRegionContain Contains(long x, long y); %name(ContainsPoint)wxRegionContain Contains(const wxPoint& pt); %name(ContainsRect)wxRegionContain Contains(const wxRect& rect); @@ -1043,3 +1352,72 @@ public: //--------------------------------------------------------------------------- +%readonly +%{ +#if 0 +%} + +extern wxFont *wxNORMAL_FONT; +extern wxFont *wxSMALL_FONT; +extern wxFont *wxITALIC_FONT; +extern wxFont *wxSWISS_FONT; + +extern wxPen *wxRED_PEN; +extern wxPen *wxCYAN_PEN; +extern wxPen *wxGREEN_PEN; +extern wxPen *wxBLACK_PEN; +extern wxPen *wxWHITE_PEN; +extern wxPen *wxTRANSPARENT_PEN; +extern wxPen *wxBLACK_DASHED_PEN; +extern wxPen *wxGREY_PEN; +extern wxPen *wxMEDIUM_GREY_PEN; +extern wxPen *wxLIGHT_GREY_PEN; + +extern wxBrush *wxBLUE_BRUSH; +extern wxBrush *wxGREEN_BRUSH; +extern wxBrush *wxWHITE_BRUSH; +extern wxBrush *wxBLACK_BRUSH; +extern wxBrush *wxTRANSPARENT_BRUSH; +extern wxBrush *wxCYAN_BRUSH; +extern wxBrush *wxRED_BRUSH; +extern wxBrush *wxGREY_BRUSH; +extern wxBrush *wxMEDIUM_GREY_BRUSH; +extern wxBrush *wxLIGHT_GREY_BRUSH; + +extern wxColour *wxBLACK; +extern wxColour *wxWHITE; +extern wxColour *wxRED; +extern wxColour *wxBLUE; +extern wxColour *wxGREEN; +extern wxColour *wxCYAN; +extern wxColour *wxLIGHT_GREY; + +extern wxCursor *wxSTANDARD_CURSOR; +extern wxCursor *wxHOURGLASS_CURSOR; +extern wxCursor *wxCROSS_CURSOR; + + +extern wxBitmap wxNullBitmap; +extern wxIcon wxNullIcon; +extern wxCursor wxNullCursor; +extern wxPen wxNullPen; +extern wxBrush wxNullBrush; +extern wxPalette wxNullPalette; +extern wxFont wxNullFont; +extern wxColour wxNullColour; + + +extern wxFontList* wxTheFontList; +extern wxPenList* wxThePenList; +extern wxBrushList* wxTheBrushList; +extern wxColourDatabase* wxTheColourDatabase; + + +%readwrite +%{ +#endif +%} + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +