]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/misc.i
Added missing header files
[wxWidgets.git] / wxPython / src / misc.i
index 1298d96f1cccef18852a0a4624ba9266d5771ec1..97e7ffb2cff13fa4474db4b5f68b6204f048fd20 100644 (file)
@@ -14,9 +14,9 @@
 
 %{
 #include "helpers.h"
 
 %{
 #include "helpers.h"
-#include <wx/resource.h>
 #include <wx/tooltip.h>
 #include <wx/busyinfo.h>
 #include <wx/tooltip.h>
 #include <wx/busyinfo.h>
+#include <wx/geometry.h>
 %}
 
 //----------------------------------------------------------------------
 %}
 
 //----------------------------------------------------------------------
@@ -79,22 +79,38 @@ public:
             return tup;
         }
 
             return tup;
         }
 
-        int __cmp__(const wxSize* sz) {
-            if (! sz) return 1;
-            if (*self == *sz) return 0;
-            return -1;
+        bool __eq__(PyObject* obj) {
+            wxSize  tmp;
+            wxSize* ptr = &tmp;
+            if (obj == Py_None)    return FALSE;
+            wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return FALSE;
+            return *self == *ptr;
         }
         }
+        bool __ne__(PyObject* obj) {
+            wxSize  tmp;
+            wxSize* ptr = &tmp;
+            if (obj == Py_None)    return TRUE;
+            wxPyBLOCK_THREADS(bool success = wxSize_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return TRUE;
+            return *self != *ptr;
+        }
+
     }
 
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
     }
 
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
-    def __repr__(self):                  return str(self.asTuple())
+    def __repr__(self):                  return 'wxSize'+str(self.asTuple())
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.width = val
         elif index == 1: self.height = val
         else: raise IndexError
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.width = val
         elif index == 1: self.height = val
         else: raise IndexError
+    def __nonzero__(self):               return self.asTuple() != (0,0)
+    def __getinitargs__(self):           return ()
+    def __getstate__(self):              return self.asTuple()
+    def __setstate__(self, state):       self.Set(*state)
 "
 
 };
 "
 
 };
@@ -122,31 +138,46 @@ public:
             return tup;
         }
 
             return tup;
         }
 
-        wxRealPoint __add__(const wxRealPoint* p) {
-            if (! p) return *self;
-            return *self + *p;
+        wxRealPoint __add__(const wxRealPoint& p) {
+            return *self + p;
         }
 
         }
 
-        wxRealPoint __sub__(const wxRealPoint* p) {
-            if (! p) return *self;
-            return *self - *p;
+        wxRealPoint __sub__(const wxRealPoint& p) {
+            return *self - p;
         }
 
         }
 
-        int __cmp__(const wxRealPoint* p) {
-            if (! p) return 1;
-            if (*self == *p) return 0;
-            return -1;
+        bool __eq__(PyObject* obj) {
+            wxRealPoint  tmp;
+            wxRealPoint* ptr = &tmp;
+            if (obj == Py_None)    return FALSE;
+            wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return FALSE;
+            return *self == *ptr;
         }
         }
+        bool __ne__(PyObject* obj) {
+            wxRealPoint  tmp;
+            wxRealPoint* ptr = &tmp;
+            if (obj == Py_None)    return TRUE;
+            wxPyBLOCK_THREADS(bool success = wxRealPoint_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return TRUE;
+            return *self != *ptr;
+        }
+
     }
     }
+
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
-    def __repr__(self):                  return str(self.asTuple())
+    def __repr__(self):                  return 'wxRealPoint'+str(self.asTuple())
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.width = val
         elif index == 1: self.height = val
         else: raise IndexError
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.width = val
         elif index == 1: self.height = val
         else: raise IndexError
+    def __nonzero__(self):      return self.asTuple() != (0.0, 0.0)
+    def __getinitargs__(self):           return ()
+    def __getstate__(self):              return self.asTuple()
+    def __setstate__(self, state):       self.Set(*state)
 "
 };
 
 "
 };
 
@@ -172,31 +203,46 @@ public:
             return tup;
         }
 
             return tup;
         }
 
-        wxPoint __add__(const wxPoint* p) {
-            if (! p) return *self;
-            return *self + *p;
+        wxPoint __add__(const wxPoint& p) {
+            return *self + p;
         }
 
         }
 
-        wxPoint __sub__(const wxPoint* p) {
-            if (! p) return *self;
-            return *self - *p;
+        wxPoint __sub__(const wxPoint& p) {
+            return *self - p;
         }
 
         }
 
-        int __cmp__(const wxPoint* p) {
-            if (! p) return 1;
-            if (*self == *p) return 0;
-            return -1;
+        bool __eq__(PyObject* obj) {
+            wxPoint  tmp;
+            wxPoint* ptr = &tmp;
+            if (obj == Py_None)    return FALSE;
+            wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return FALSE;
+            return *self == *ptr;
+        }
+        bool __ne__(PyObject* obj) {
+            wxPoint  tmp;
+            wxPoint* ptr = &tmp;
+            if (obj == Py_None)    return TRUE;
+            wxPyBLOCK_THREADS(bool success = wxPoint_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return TRUE;
+            return *self != *ptr;
         }
         }
+
     }
     }
+
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
-    def __repr__(self):                  return str(self.asTuple())
+    def __repr__(self):                  return 'wxPoint'+str(self.asTuple())
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.x = val
         elif index == 1: self.y = val
         else: raise IndexError
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
         if index == 0: self.x = val
         elif index == 1: self.y = val
         else: raise IndexError
+    def __nonzero__(self):      return self.asTuple() != (0,0)
+    def __getinitargs__(self):           return ()
+    def __getstate__(self):              return self.asTuple()
+    def __setstate__(self, state):       self.Set(*state)
 "
 };
 
 "
 };
 
@@ -204,7 +250,7 @@ public:
 
 class wxRect {
 public:
 
 class wxRect {
 public:
-    wxRect(int x=0, int y=0, int w=0, int h=0);
+    wxRect(int x=0, int y=0, int width=0, int height=0);
     // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
     ~wxRect();
 
     // TODO: do this one too... wxRect(const wxPoint& pos, const wxSize& size);
     ~wxRect();
 
@@ -220,6 +266,8 @@ public:
 
     wxPoint GetPosition();
     wxSize GetSize();
 
     wxPoint GetPosition();
     wxSize GetSize();
+    void SetPosition( const wxPoint &p );
+    void SetSize( const wxSize &s );
 
     int  GetLeft();
     int  GetTop();
 
     int  GetLeft();
     int  GetTop();
@@ -231,12 +279,24 @@ public:
     void SetTop(int top);
     void SetBottom(int bottom);
 
     void SetTop(int top);
     void SetBottom(int bottom);
 
+    void Deflate(int dx, int dy);
     void Inflate(int dx, int dy);
     void Inflate(int dx, int dy);
-    bool Inside(int cx, int cy);
+    %name(InsideXY)bool Inside(int cx, int cy);
+    bool Inside(const wxPoint& pt);
+    bool Intersects(const wxRect& rect);
+    %name(OffsetXY) void Offset(int dx, int dy);
+    void Offset(const wxPoint& pt);
 
     int x, y, width, height;
 
     %addmethods {
 
     int x, y, width, height;
 
     %addmethods {
+        void Set(int x=0, int y=0, int width=0, int height=0) {
+            self->x = x;
+            self->y = y;
+            self->width = width;
+            self->height = height;
+        }
+
         PyObject* asTuple() {
             wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(4);
         PyObject* asTuple() {
             wxPyBeginBlockThreads();
             PyObject* tup = PyTuple_New(4);
@@ -248,21 +308,32 @@ public:
             return tup;
         }
 
             return tup;
         }
 
-        wxRect __add__(const wxRect* rect) {
-            if (! rect) return *self;
-            return *self + *rect;
+        wxRect __add__(const wxRect& rect) {
+            return *self + rect;
         }
 
         }
 
-        int __cmp__(const wxRect* rect) {
-            if (! rect) return 1;
-            if (*self == *rect) return 0;
-            return -1;
+        bool __eq__(PyObject* obj) {
+            wxRect  tmp;
+            wxRect* ptr = &tmp;
+            if (obj == Py_None)    return FALSE;
+            wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return FALSE;
+            return *self == *ptr;
+        }
+        bool __ne__(PyObject* obj) {
+            wxRect  tmp;
+            wxRect* ptr = &tmp;
+            if (obj == Py_None)    return TRUE;
+            wxPyBLOCK_THREADS(bool success = wxRect_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return TRUE;
+            return *self != *ptr;
         }
         }
+
     }
 
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
     }
 
     %pragma(python) addtoclass = "
     def __str__(self):                   return str(self.asTuple())
-    def __repr__(self):                  return str(self.asTuple())
+    def __repr__(self):                  return 'wxRect'+str(self.asTuple())
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
     def __len__(self):                   return len(self.asTuple())
     def __getitem__(self, index):        return self.asTuple()[index]
     def __setitem__(self, index, val):
@@ -271,6 +342,10 @@ public:
         elif index == 2: self.width = val
         elif index == 3: self.height = val
         else: raise IndexError
         elif index == 2: self.width = val
         elif index == 3: self.height = val
         else: raise IndexError
+    def __nonzero__(self):               return self.asTuple() != (0,0,0,0)
+    def __getinitargs__(self):           return ()
+    def __getstate__(self):              return self.asTuple()
+    def __setstate__(self, state):       self.Set(*state)
 
     # override the __getattr__ made by SWIG
     def __getattr__(self, name):
 
     # override the __getattr__ made by SWIG
     def __getattr__(self, name):
@@ -326,7 +401,7 @@ public:
         if (dest != wxRect(0,0,0,0)) {
             wxPyBeginBlockThreads();
             wxRect* newRect = new wxRect(dest);
         if (dest != wxRect(0,0,0,0)) {
             wxPyBeginBlockThreads();
             wxRect* newRect = new wxRect(dest);
-            obj = wxPyConstructObject((void*)newRect, "wxRect");
+            obj = wxPyConstructObject((void*)newRect, wxT("wxRect"));
             PyObject* one = PyInt_FromLong(1);
             PyObject_SetAttrString(obj, "thisown", one);
             Py_DECREF(one);
             PyObject* one = PyInt_FromLong(1);
             PyObject_SetAttrString(obj, "thisown", one);
             Py_DECREF(one);
@@ -339,13 +414,116 @@ public:
 %}
 
 
 %}
 
 
+
+//---------------------------------------------------------------------------
+// wxPoint2Ds represent a point or a vector in a 2d coordinate system
+
+class wxPoint2DDouble
+{
+public:
+    double m_x;
+    double m_y;
+
+    %name(x)double m_x;
+    %name(y)double m_y;
+
+    wxPoint2DDouble( double x=0 , double y=0 );
+    %name(wxPoint2DDoubleCopy)wxPoint2DDouble( const wxPoint2DDouble &pt );
+    %name(wxPoint2DDoubleFromPoint)wxPoint2DDouble( const wxPoint &pt );
+
+    // two different conversions to integers, floor and rounding
+    void GetFloor( int* OUTPUT , int* OUTPUT ) const;
+    void GetRounded( int* OUTPUT , int* OUTPUT ) const;
+
+    double GetVectorLength() const;
+    double GetVectorAngle() const ;
+    void SetVectorLength( double length );
+    void SetVectorAngle( double degrees );
+    // LinkError: void SetPolarCoordinates( double angle , double length );
+    // LinkError: void Normalize();
+    %pragma(python) addtoclass = "
+    def SetPolarCoordinates(self, angle, length):
+        self.SetVectorLength(length)
+        self.SetVectorAngle(angle)
+    def Normalize(self):
+        self.SetVectorLength(1.0)
+    "
+
+    double GetDistance( const wxPoint2DDouble &pt ) const;
+    double GetDistanceSquare( const wxPoint2DDouble &pt ) const;
+    double GetDotProduct( const wxPoint2DDouble &vec ) const;
+    double GetCrossProduct( const wxPoint2DDouble &vec ) const;
+
+    %addmethods {
+        void Set( double x=0 , double y=0 ) {
+            self->m_x = x;
+            self->m_y = y;
+        }
+
+        // the reflection of this point
+        wxPoint2DDouble __neg__() { return -(*self); }
+
+        wxPoint2DDouble& __iadd__(const wxPoint2DDouble& pt) { return (*self) += pt; }
+        wxPoint2DDouble& __isub__(const wxPoint2DDouble& pt) { return (*self) -= pt; }
+        wxPoint2DDouble& __imul__(const wxPoint2DDouble& pt) { return (*self) *= pt; }
+        wxPoint2DDouble& __idiv__(const wxPoint2DDouble& pt) { return (*self) /= pt; }
+
+        // TODO:
+        //wxPoint2DDouble& operator*=(double n);
+        //wxPoint2DDouble& operator*=(int n);
+        //wxPoint2DDouble& operator/=(double n);
+        //wxPoint2DDouble& operator/=(int n);
+
+        bool __eq__(PyObject* obj) {
+            wxPoint2DDouble  tmp;
+            wxPoint2DDouble* ptr = &tmp;
+            if (obj == Py_None)    return FALSE;
+            wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return FALSE;
+            return *self == *ptr;
+        }
+        bool __ne__(PyObject* obj) {
+            wxPoint2DDouble  tmp;
+            wxPoint2DDouble* ptr = &tmp;
+            if (obj == Py_None)    return TRUE;
+            wxPyBLOCK_THREADS(bool success = wxPoint2DDouble_helper(obj, &ptr); PyErr_Clear());
+            if (! success)         return TRUE;
+            return *self != *ptr;
+        }
+
+
+        PyObject* asTuple() {
+            wxPyBeginBlockThreads();
+            PyObject* tup = PyTuple_New(2);
+            PyTuple_SET_ITEM(tup, 0, PyFloat_FromDouble(self->m_x));
+            PyTuple_SET_ITEM(tup, 1, PyFloat_FromDouble(self->m_y));
+            wxPyEndBlockThreads();
+            return tup;
+        }
+    }
+
+    %pragma(python) addtoclass = "
+    def __str__(self):                   return str(self.asTuple())
+    def __repr__(self):                  return 'wxPoint2DDouble'+str(self.asTuple())
+    def __len__(self):                   return len(self.asTuple())
+    def __getitem__(self, index):        return self.asTuple()[index]
+    def __setitem__(self, index, val):
+        if index == 0: self.m_x = val
+        elif index == 1: self.m_yt = val
+        else: raise IndexError
+    def __nonzero__(self):               return self.asTuple() != (0.0, 0.0)
+    def __getinitargs__(self):           return ()
+    def __getstate__(self):              return self.asTuple()
+    def __setstate__(self, state):       self.Set(*state)
+"
+};
+
+
 //---------------------------------------------------------------------------
 // Miscellaneous functions
 
 long wxNewId();
 void wxRegisterId(long id);
 //---------------------------------------------------------------------------
 // Miscellaneous functions
 
 long wxNewId();
 void wxRegisterId(long id);
-%name(NewId) long wxNewId();
-%name(RegisterId) void wxRegisterId(long id);
 long wxGetCurrentId();
 
 void wxBell();
 long wxGetCurrentId();
 
 void wxBell();
@@ -379,14 +557,16 @@ bool wxYield();
 bool wxYieldIfNeeded();
 void wxEnableTopLevelWindows(bool enable);
 
 bool wxYieldIfNeeded();
 void wxEnableTopLevelWindows(bool enable);
 
-%inline %{
+#ifdef wxUSE_RESOURCES
+inline %{
     wxString wxGetResource(const wxString& section, const wxString& entry,
                            const wxString& file = wxPyEmptyString) {
     wxString wxGetResource(const wxString& section, const wxString& entry,
                            const wxString& file = wxPyEmptyString) {
-        wxChar * retval;
+        wxChar* retval;
         wxGetResource(section, entry, &retval, file);
         return retval;
     }
 %}
         wxGetResource(section, entry, &retval, file);
         return retval;
     }
 %}
+#endif
 
 wxString wxStripMenuCodes(const wxString& in);
 
 
 wxString wxStripMenuCodes(const wxString& in);
 
@@ -485,6 +665,7 @@ wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
 #if 0  // we want to use the definition from the header, not the
        // one SWIG will generate.
 %}
 #if 0  // we want to use the definition from the header, not the
        // one SWIG will generate.
 %}
+// See also wxPy_ReinitStockObjects in helpers.cpp
 extern wxAcceleratorTable wxNullAcceleratorTable;
 %{
 #endif
 extern wxAcceleratorTable wxNullAcceleratorTable;
 %{
 #endif