]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.cpp
use "..." instead of <...> for wx includes
[wxWidgets.git] / wxPython / src / helpers.cpp
index e4c6354b20035cb3741b7c88652ca90145e4e8c6..7b29004df3ce850d28b21a801c75dbde8e12e383 100644 (file)
@@ -101,7 +101,6 @@ void WXDLLEXPORT wxEntryCleanup();
 
 
 #ifdef WXP_WITH_THREAD
-//PyThreadState*  wxPyEventThreadState = NULL;
 PyInterpreterState* wxPyInterpreter = NULL;
 #endif
 
@@ -118,7 +117,6 @@ void __wxPreStart()
 
 #ifdef WXP_WITH_THREAD
     PyEval_InitThreads();
-//    wxPyEventThreadState = PyThreadState_Get(); // PyThreadState_New(PyThreadState_Get()->interp);
     wxPyInterpreter = PyThreadState_Get()->interp;
 #endif
 
@@ -289,12 +287,16 @@ PyObject* wxPyClassExists(const char* className) {
 }
 
 
-PyObject*  wxPyMake_wxObject(wxObject* source) {
+PyObject*  wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) {
     PyObject* target = NULL;
     bool      isEvtHandler = FALSE;
 
     if (source) {
-        if (wxIsKindOf(source, wxEvtHandler)) {
+        // If it's derived from wxEvtHandler then there may
+        // already be a pointer to a Python object that we can use
+        // in the OOR data.
+        if (checkEvtHandler && wxIsKindOf(source, wxEvtHandler)) {
+            isEvtHandler = TRUE;
             wxEvtHandler* eh = (wxEvtHandler*)source;
             wxPyClientData* data = (wxPyClientData*)eh->GetClientObject();
             if (data) {
@@ -304,6 +306,8 @@ PyObject*  wxPyMake_wxObject(wxObject* source) {
         }
 
         if (! target) {
+            // Otherwise make it the old fashioned way by making a
+            // new shadow object and putting this pointer in it.
             wxClassInfo* info = source->GetClassInfo();
             wxChar*      name = (wxChar*)info->GetClassName();
             PyObject*    klass = wxPyClassExists(name);
@@ -330,6 +334,30 @@ PyObject*  wxPyMake_wxObject(wxObject* source) {
 }
 
 
+PyObject*  wxPyMake_wxSizer(wxSizer* source) {
+    PyObject* target = NULL;
+
+    if (source && wxIsKindOf(source, wxSizer)) {
+        // If it's derived from wxSizer then there may
+        // already be a pointer to a Python object that we can use
+        // in the OOR data.
+        wxSizer* sz = (wxSizer*)source;
+        wxPyClientData* data = (wxPyClientData*)sz->GetClientObject();
+        if (data) {
+            target = data->m_obj;
+            Py_INCREF(target);
+        }
+    }
+    if (! target) {
+        target = wxPyMake_wxObject(source, FALSE);
+        if (target != Py_None)
+            ((wxSizer*)source)->SetClientObject(new wxPyClientData(target));
+    }
+    return target;
+}
+
+
+
 //---------------------------------------------------------------------------
 
 PyObject* wxPyConstructObject(void* ptr,
@@ -374,8 +402,10 @@ PyObject* wxPyConstructObject(void* ptr,
     }
 
     char    buff[64];               // should always be big enough...
-
     sprintf(buff, "%sPtr", className);
+
+       wxASSERT_MSG(wxPython_dict, "wxPython_dict is not set yet!!");
+
     PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff);
     if (! classobj) {
         char temp[128];
@@ -391,42 +421,6 @@ PyObject* wxPyConstructObject(void* ptr,
 
 //---------------------------------------------------------------------------
 
-//  static PyThreadState* myPyThreadState_Get() {
-//      PyThreadState* current;
-//      current = PyThreadState_Swap(NULL);
-//      PyThreadState_Swap(current);
-//      return current;
-//  }
-
-
-//  bool wxPyRestoreThread() {
-//      // NOTE: The Python API docs state that if a thread already has the
-//      // interpreter lock and calls PyEval_RestoreThread again a deadlock
-//      // occurs, so I put in this code as a guard condition since there are
-//      // many possibilites for nested events and callbacks in wxPython.  If
-//      // The current thread is our thread, then we can assume that we
-//      // already have the lock.  (I hope!)
-//      //
-//  #ifdef WXP_WITH_THREAD
-//      if (wxPyEventThreadState != myPyThreadState_Get()) {
-//          PyEval_AcquireThread(wxPyEventThreadState);
-//          return TRUE;
-//      }
-//      else
-//  #endif
-//          return FALSE;
-//  }
-
-
-//  void wxPySaveThread(bool doSave) {
-//  #ifdef WXP_WITH_THREAD
-//      if (doSave) {
-//          PyEval_ReleaseThread(wxPyEventThreadState);
-//      }
-//  #endif
-//  }
-
-
 
 wxPyTState* wxPyBeginBlockThreads() {
     wxPyTState* state = NULL;
@@ -619,7 +613,7 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh) {
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-// These classes can be derived from in Python and passed through the event
+// These event classes can be derived from in Python and passed through the event
 // system without losing anything.  They do this by keeping a reference to
 // themselves and some special case handling in wxPyCallback::EventThunker.
 
@@ -655,37 +649,41 @@ PyObject* wxPyEvtSelfRef::GetSelf() const {
 }
 
 
+IMPLEMENT_ABSTRACT_CLASS(wxPyEvent, wxEvent);
+IMPLEMENT_ABSTRACT_CLASS(wxPyCommandEvent, wxCommandEvent);
+
+
 wxPyEvent::wxPyEvent(int id)
     : wxEvent(id) {
 }
 
-wxPyEvent::~wxPyEvent() {
-}
 
-// This one is so the event object can be Cloned...
-void wxPyEvent::CopyObject(wxObject& dest) const {
-    wxEvent::CopyObject(dest);
-    ((wxPyEvent*)&dest)->SetSelf(m_self, TRUE);
+wxPyEvent::wxPyEvent(const wxPyEvent& evt)
+    : wxEvent(evt)
+{
+    SetSelf(evt.m_self, TRUE);
 }
 
 
-IMPLEMENT_DYNAMIC_CLASS(wxPyEvent, wxEvent);
+wxPyEvent::~wxPyEvent() {
+}
 
 
 wxPyCommandEvent::wxPyCommandEvent(wxEventType commandType, int id)
     : wxCommandEvent(commandType, id) {
 }
 
-wxPyCommandEvent::~wxPyCommandEvent() {
-}
 
-void wxPyCommandEvent::CopyObject(wxObject& dest) const {
-    wxCommandEvent::CopyObject(dest);
-    ((wxPyCommandEvent*)&dest)->SetSelf(m_self, TRUE);
+wxPyCommandEvent::wxPyCommandEvent(const wxPyCommandEvent& evt)
+    : wxCommandEvent(evt)
+{
+    SetSelf(evt.m_self, TRUE);
 }
 
 
-IMPLEMENT_DYNAMIC_CLASS(wxPyCommandEvent, wxCommandEvent);
+wxPyCommandEvent::~wxPyCommandEvent() {
+}
+
 
 
 
@@ -1320,6 +1318,19 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
 
 
 //----------------------------------------------------------------------
+
+PyObject* wxArrayString2PyList_helper(const wxArrayString& arr) {
+
+    PyObject* list = PyList_New(0);
+    for (size_t i=0; i < arr.GetCount(); i++) {
+        PyObject* str = PyString_FromString(arr[i].c_str());
+        PyList_Append(list, str);
+        Py_DECREF(str);
+    }
+    return list;
+}
+
+
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------