OSDN Git Service

Event handling of the Ruby dialog is improved.
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 5 Aug 2013 14:22:01 +0000 (14:22 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 5 Aug 2013 14:22:01 +0000 (14:22 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@380 a2be9bc6-48de-4e38-9406-05402d4bc13c

MolLib/Ruby_bind/ruby_dialog.c
wxSources/RubyDialogFrame.cpp
wxSources/RubyDialogFrame.h

index 4a5b445..c60df26 100644 (file)
@@ -279,7 +279,7 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val)
                if (type == sTableSymbol) {
                        IntGroup *ig = IntGroupFromValue(val);
                        int row, count;
-                       count = RubyDialog_GetTableItemCount((RubyValue)self, (RDItem *)view);
+                       count = RubyDialog_GetTableItemCount((RubyValue)dialog_val, (RDItem *)view);
                        for (row = 0; row < count; row++) {
                                int flag = (IntGroupLookup(ig, row, NULL) != 0);
                                RubyDialogCallback_setTableRowSelected((RDItem *)view, row, flag);
@@ -482,7 +482,7 @@ s_RubyDialogItem_Attr(VALUE self, VALUE key)
                if (type == sTableSymbol) {
                        IntGroup *ig = IntGroupNew();
                        int row, count;
-                       count = RubyDialog_GetTableItemCount((RubyValue)self, (RDItem *)view);
+                       count = RubyDialog_GetTableItemCount((RubyValue)dialog_val, (RDItem *)view);
                        for (row = 0; row < count; row++) {
                                if (RubyDialogCallback_isTableRowSelected((RDItem *)view, row))
                                        IntGroupAdd(ig, row, 1);
@@ -764,7 +764,7 @@ s_RubyDialog_Show(VALUE self)
  *
  *  Hide the modeless dialog. This is to be used with Dialog#show in pairs.
  *  If the dialog is registered in the ruby_dialog_list global variable, it becomes unregistered.
- *  Mixing Dialog#hide and Dialog#run will lead to unpredictable results, including crash. The 
+ *  Mixing Dialog#hide and Dialog#run will lead to unpredictable results, including crash.
  */
 static VALUE
 s_RubyDialog_Hide(VALUE self)
index 2446633..bca1d52 100644 (file)
@@ -74,9 +74,15 @@ RubyDialogFrame::~RubyDialogFrame()
                free(ditems);
        for (i = 0; i < countMessageData; i++) {
                if (messageData[i * 5] != NULL) {
-                       ((wxEvtHandler *)messageData[i * 5])->Disconnect((int)messageData[i * 5 + 1], (wxEventType)messageData[i * 5 + 2], wxCommandEventHandler(RubyDialogFrame::HandleDocumentEvent));
+                       wxEventType eventType = (wxEventType)messageData[i * 5 + 2];
+                       wxEvtHandler *handler = NULL;
+                       if (eventType == MyDocumentEvent)
+                               handler = MyDocumentFromMolecule((Molecule *)messageData[i * 5]);
+                       if (handler != NULL) {
+                               handler->Disconnect((int)messageData[i * 5 + 1], eventType, wxCommandEventHandler(RubyDialogFrame::HandleDocumentEvent), NULL, this);
+                       }
                }
-       }       
+       }
 }
 
 int
@@ -320,10 +326,12 @@ RubyDialogFrame::ListenToObject(void *obj, const char *objtype, const char *msg,
        if (pval == NULL || pval == RubyNil) {
                /*  Remove the registration  */
                for (i = 0; i < countMessageData; i++) {
-                       if (messageData[i * 5] == (void *)handler && 
+                       if (messageData[i * 5] == obj && 
                                messageData[i * 5 + 1] == (void *)eventId &&
                                messageData[i * 5 + 2] == (void *)eventType) {
-                               handler->Disconnect(eventId, eventType, wxCommandEventHandler(RubyDialogFrame::HandleDocumentEvent));
+                               handler->Disconnect(eventId, eventType, wxCommandEventHandler(RubyDialogFrame::HandleDocumentEvent), NULL, this);
+                               if (eventType == MyDocumentEvent)
+                                       MoleculeRelease((Molecule *)obj);
                                break;
                        }
                }
@@ -335,7 +343,7 @@ RubyDialogFrame::ListenToObject(void *obj, const char *objtype, const char *msg,
                /*  Check the duplicate  */
                j = countMessageData;  /*  The position to store info if it is new  */
                for (i = 0; i < countMessageData; i++) {
-                       if (messageData[i * 5] == (void *)handler && 
+                       if (messageData[i * 5] == obj && 
                                messageData[i * 5 + 1] == (void *)eventId &&
                                messageData[i * 5 + 2] == (void *)eventType) {
                                /*  Just replace the arguments  */
@@ -352,12 +360,14 @@ RubyDialogFrame::ListenToObject(void *obj, const char *objtype, const char *msg,
                                /*  Create a new entry  */
                                InsertArray(&messageData, &countMessageData, sizeof(void *) * 5, i, 1, NULL);
                        }
-                       messageData[j * 5] = (void *)handler;
+                       messageData[j * 5] = obj;
                        messageData[j * 5 + 1] = (void *)eventId;
                        messageData[j * 5 + 2] = (void *)eventType;
                        messageData[j * 5 + 3] = (void *)oval;
                        messageData[j * 5 + 4] = (void *)pval;
                        handler->Connect(eventId, eventType, wxCommandEventHandler(RubyDialogFrame::HandleDocumentEvent), NULL, this);
+                       if (eventType == MyDocumentEvent)
+                               MoleculeRetain((Molecule *)obj);
                        i = j;
                }
                return i;
@@ -371,19 +381,23 @@ RubyDialogFrame::HandleDocumentEvent(wxCommandEvent &event)
        int eventId = event.GetId();
        int eventType = event.GetEventType();
        wxObject *eventObject = event.GetEventObject();
-               
+       void *obj;
+
+       if (eventType == MyDocumentEvent) {
+               if (wxDynamicCast(eventObject, MyDocument) != NULL) {
+                       obj = ((MyDocument *)eventObject)->GetMolecule();
+               } else return;
+       } else return;
+       
        /*  Look up the message table  */
        for (i = 0; i < countMessageData; i++) {
-               if (messageData[i * 5] == (void *)eventObject && 
+               if (messageData[i * 5] == obj && 
                        messageData[i * 5 + 1] == (void *)eventId &&
                        messageData[i * 5 + 2] == (void *)eventType) {
                        int status;
                        RubyValue oval = (RubyValue)messageData[i * 5 + 3];
                        RubyValue pval = (RubyValue)messageData[i * 5 + 4];
                        Ruby_funcall2_protect_extern(pval, g_RubyID_call, 1, &oval, &status);
-/*                     if (status != 0) {
-                               Molby_showError(status);
-                       } */
                }
        }
        event.Skip();
@@ -515,6 +529,8 @@ RubyDialogCallback_close(RubyDialog *dref)
 void
 RubyDialogCallback_show(RubyDialog *dref)
 {
+       if (((RubyDialogFrame *)dref)->myTimer != NULL)
+               ((RubyDialogFrame *)dref)->StartIntervalTimer(-1);
        ((RubyDialogFrame *)dref)->Show(true);
        ((RubyDialogFrame *)dref)->Raise();
 }
index 5487f24..eb24c93 100644 (file)
@@ -41,7 +41,7 @@ public:
        RDSize mySize;  /*  Previous size  */
        bool autoResizeEnabled;  /*  true if auto resizing is enabled  */
        
-       /*  Message bridge (with Ruby world); obj, objtype, msg, pval  */
+       /*  Message bridge (with Ruby world); obj, event_type, event_id, proc val  */
        void **messageData;
        Int countMessageData;