• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

Molecular Modeling Software


コミットメタ情報

リビジョンb96c758d4e26bf6e23946f69f202dc0fa7f6f06e (tree)
日時2014-09-25 01:22:17
作者toshinagata1964 <toshinagata1964@a2be...>
コミッターtoshinagata1964

ログメッセージ

Ruby dialog class is being restructured. The source does compile, but something may be broken at present.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@573 a2be9bc6-48de-4e38-9406-05402d4bc13c

変更サマリ

差分

--- a/MolLib/Ruby_bind/Molby_extern.h
+++ b/MolLib/Ruby_bind/Molby_extern.h
@@ -24,10 +24,12 @@ extern "C" {
2424 #include "../MolLib.h"
2525
2626 /* This definition is to work around 'VALUE' type in sources without "ruby.h" */
27+#ifndef RubyValue_is_Defined
28+#define RubyValue_is_Defined
2729 typedef void *RubyValue;
28-
2930 #define RubyNil ((RubyValue)4)
30-
31+#endif
32+
3133 extern char *gRubyVersion;
3234 extern char *gRubyCopyright;
3335
--- a/MolLib/Ruby_bind/ruby_bind.c
+++ b/MolLib/Ruby_bind/ruby_bind.c
@@ -11753,6 +11753,14 @@ Init_Molby(void)
1175311753 s_EllipsoidSym = ID2SYM(rb_intern("ellipsoid"));
1175411754 }
1175511755
11756+#pragma mark ====== Interface with RubyDialog class ======
11757+
11758+RubyValue
11759+RubyDialogCallback_parentModule(void)
11760+{
11761+ return (RubyValue)rb_mMolby;
11762+}
11763+
1175611764 #pragma mark ====== External functions ======
1175711765
1175811766 static VALUE s_ruby_top_self = Qfalse;
--- a/MolLib/Ruby_bind/ruby_dialog.c
+++ b/MolLib/Ruby_bind/ruby_dialog.c
@@ -51,6 +51,7 @@ VALUE rb_cDialog = Qfalse;
5151 VALUE rb_cDialogItem = Qfalse;
5252 VALUE rb_mDeviceContext = Qfalse;
5353 VALUE rb_cBitmap = Qfalse;
54+VALUE rb_eDialogError = Qfalse;
5455 VALUE gRubyDialogList = Qnil;
5556
5657 const RDPoint gZeroPoint = {0, 0};
@@ -2710,10 +2711,14 @@ s_Bitmap_SaveToFile(VALUE self, VALUE fnval)
27102711 void
27112712 RubyDialogInitClass(void)
27122713 {
2714+ VALUE parent;
27132715 if (rb_cDialog != Qfalse)
27142716 return;
2715-
2716- rb_cDialog = rb_define_class_under(rb_mMolby, "Dialog", rb_cObject);
2717+ parent = RubyDialogCallback_parentModule();
2718+ if (parent != Qfalse)
2719+ rb_cDialog = rb_define_class_under(parent, "Dialog", rb_cObject);
2720+ else
2721+ rb_cDialog = rb_define_class("Dialog", rb_cObject);
27172722 rb_define_alloc_func(rb_cDialog, s_RubyDialog_Alloc);
27182723 rb_define_private_method(rb_cDialog, "initialize", s_RubyDialog_Initialize, -1);
27192724 rb_define_method(rb_cDialog, "run", s_RubyDialog_Run, 0);
@@ -2744,7 +2749,11 @@ RubyDialogInitClass(void)
27442749 rb_define_singleton_method(rb_cDialog, "save_panel", s_RubyDialog_SavePanel, -1);
27452750 rb_define_singleton_method(rb_cDialog, "open_panel", s_RubyDialog_OpenPanel, -1);
27462751
2747- rb_cDialogItem = rb_define_class_under(rb_mMolby, "DialogItem", rb_cObject);
2752+ if (parent != Qfalse)
2753+ rb_cDialogItem = rb_define_class_under(parent, "DialogItem", rb_cObject);
2754+ else
2755+ rb_cDialogItem = rb_define_class("DialogItem", rb_cObject);
2756+
27482757 rb_define_method(rb_cDialogItem, "[]=", s_RubyDialogItem_SetAttr, 2);
27492758 rb_define_method(rb_cDialogItem, "[]", s_RubyDialogItem_Attr, 1);
27502759 rb_define_alias(rb_cDialogItem, "set_attr", "[]=");
@@ -2752,7 +2761,11 @@ RubyDialogInitClass(void)
27522761 rb_define_method(rb_cDialogItem, "append_string", s_RubyDialogItem_AppendString, 1);
27532762 rb_define_method(rb_cDialogItem, "refresh_rect", s_RubyDialogItem_RefreshRect, -1);
27542763
2755- rb_mDeviceContext = rb_define_module_under(rb_mMolby, "DeviceContext");
2764+ if (parent != Qfalse)
2765+ rb_mDeviceContext = rb_define_module_under(parent, "DeviceContext");
2766+ else
2767+ rb_mDeviceContext = rb_define_module("DeviceContext");
2768+
27562769 rb_define_method(rb_mDeviceContext, "clear", s_RubyDialog_Clear, 0);
27572770 rb_define_method(rb_mDeviceContext, "draw_ellipse", s_RubyDialog_DrawEllipse, -1);
27582771 rb_define_method(rb_mDeviceContext, "draw_line", s_RubyDialog_DrawLine, -1);
@@ -2765,12 +2778,22 @@ RubyDialogInitClass(void)
27652778
27662779 rb_include_module(rb_cDialog, rb_mDeviceContext);
27672780
2768- rb_cBitmap = rb_define_class_under(rb_mMolby, "Bitmap", rb_cObject);
2781+ if (parent != Qfalse)
2782+ rb_cBitmap = rb_define_class_under(parent, "Bitmap", rb_cObject);
2783+ else
2784+ rb_cBitmap = rb_define_class("Bitmap", rb_cObject);
2785+
27692786 rb_include_module(rb_cBitmap, rb_mDeviceContext);
27702787 rb_define_alloc_func(rb_cBitmap, s_Bitmap_Alloc);
27712788 rb_define_private_method(rb_cBitmap, "initialize", s_Bitmap_Initialize, -1);
27722789 rb_define_method(rb_cBitmap, "focus_exec", s_Bitmap_FocusExec, -1);
27732790 rb_define_method(rb_cBitmap, "save_to_file", s_Bitmap_SaveToFile, 1);
2791+
2792+ if (parent != Qfalse)
2793+ rb_eDialogError = rb_define_class_under(parent, "DialogError", rb_eStandardError);
2794+ else
2795+ rb_eDialogError = rb_define_class("DialogError", rb_eStandardError);
2796+
27742797 {
27752798 static VALUE *sTable1[] = {
27762799 &sTextSymbol, &sTextFieldSymbol, &sRadioSymbol, &sButtonSymbol,
--- a/MolLib/Ruby_bind/ruby_dialog.h
+++ b/MolLib/Ruby_bind/ruby_dialog.h
@@ -18,21 +18,28 @@
1818 #ifndef __ruby_dialog_h__
1919 #define __ruby_dialog_h__
2020
21-#include "Molby_extern.h"
21+//#include "Molby_extern.h"
2222
2323 #ifdef __cplusplus
2424 extern "C" {
2525 #endif
2626
27-/* RubyDialog class */
28-/* extern VALUE rb_cDialog; */
29-
3027 /* Style of the dialog frame */
3128 enum {
3229 rd_Resizable = 1,
3330 rd_HasCloseBox = 2,
3431 };
3532
33+#ifndef RubyValue_is_Defined
34+#define RubyValue_is_Defined
35+typedef void *RubyValue;
36+#define RubyNil (RubyValue)4
37+#endif
38+
39+#ifndef STUB
40+#define STUB extern
41+#endif
42+
3643 /* True if y-coordinate grows from bottom to top (like Cocoa) */
3744 extern int gRubyDialogIsFlipped;
3845
@@ -53,7 +60,7 @@ extern const RDRect gZeroRect;
5360
5461 /* Utility function */
5562 extern int RubyDialog_validateItemContent(RubyValue self, RDItem *ip, const char *s);
56-extern void RubyDialog_doItemAction(RubyValue self, RDItem *ip, Int options);
63+extern void RubyDialog_doItemAction(RubyValue self, RDItem *ip, int options);
5764 extern void RubyDialog_doTimerAction(RubyValue self);
5865 extern void RubyDialog_doKeyAction(RubyValue self, int keyCode);
5966 extern int RubyDialog_getFlexFlags(RubyValue self, RDItem *ip);
@@ -73,7 +80,8 @@ extern void RubyDialog_OnPopUpMenuSelected(RubyValue self, RDItem *ip, int row,
7380
7481 extern void RubyDialogInitClass(void);
7582
76-/* Stub routines */
83+/* Stub entries */
84+STUB RubyValue RubyDialogCallback_parentModule(void);
7785 STUB RubyDialog *RubyDialogCallback_new(int style);
7886 STUB void RubyDialogCallback_release(RubyDialog *dref);
7987 STUB void RubyDialogCallback_setRubyObject(RubyDialog *dref, RubyValue val);
@@ -97,6 +105,9 @@ STUB void RubyDialogCallback_setWindowSize(RubyDialog *dref, RDSize size);
97105
98106 STUB void RubyDialogCallback_setAutoResizeEnabled(RubyDialog *dref, int flag);
99107 STUB int RubyDialogCallback_isAutoResizeEnabled(RubyDialog *dref);
108+
109+//STUB int RubyDialogCallback_GetEventHandlerFromValueAndMessage(RubyValue val, const char *msg, RDEventHandlerRecord **recp);
110+//STUB int RubyDialogCallback_Listen(RubyDialog *dref, RDEventHandlerRecord *rec, RubyValue oval, RubyValue pval);
100111 STUB int RubyDialogCallback_Listen(RubyDialog *dref, void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval);
101112
102113 STUB void RubyDialogCallback_createStandardButtons(RubyDialog *dref, const char *oktitle, const char *canceltitle);
--- a/MolLib/Types.h
+++ b/MolLib/Types.h
@@ -42,9 +42,11 @@ typedef doublereal __CLPK_doublereal;
4242 #ifdef __cplusplus
4343 extern "C" {
4444 #endif
45-
46-#define STUB extern
4745
46+#ifndef STUB
47+#define STUB extern
48+#endif
49+
4850 #ifndef kRad2Deg
4951 #define kRad2Deg (180./3.14159265358979)
5052 #endif
--- a/Scripts/molecule.rb
+++ b/Scripts/molecule.rb
@@ -737,9 +737,14 @@ class Molecule
737737 if block
738738 d.instance_eval(&block)
739739 d.instance_eval { |_d|
740- listen(mol, "documentModified", lambda { |m| @on_document_modified.call(m) if @on_document_modified } )
741- listen(mol, "documentWillClose", lambda { |m| m.close_auxiliary_window(_d) } )
742- @on_close = lambda { mol.close_auxiliary_window(_d, true); true}
740+# listen(mol, "documentModified", lambda { |m| @on_document_modified.call(m) if @on_document_modified } )
741+# listen(mol, "documentWillClose", lambda { |m| m.close_auxiliary_window(_d) } )
742+ if @on_close != nil
743+ save_on_close = @on_close
744+ @on_close = lambda { save_on_close.call; mol.close_auxiliary_window(_d, true); true}
745+ else
746+ @on_close = lambda { mol.close_auxiliary_window(_d, true); true }
747+ end
743748 }
744749 end
745750 @aux_windows[title] = d
@@ -756,16 +761,37 @@ class Molecule
756761 end
757762 end
758763
759- def close_active_auxiliary_window
764+ def close_all_auxiliary_windows
760765 if @aux_windows
761- @aux_windows.each_value { |d|
762- if d.active?
763- close_auxiliary_window(d)
764- return true
765- end
766+ @aux_windows.values.each { |d|
767+ close_auxiliary_window(d)
766768 }
769+ return true
770+ else
771+ return false
767772 end
768- return false;
769773 end
770774
775+ def call_modification_handler_in_all_auxiliary_windows
776+ mol = self
777+ if @aux_windows
778+ @aux_windows.values.each { |d|
779+ d.instance_eval { @on_document_modified.call(mol) if @on_document_modified }
780+ }
781+ end
782+ end
783+
784+# def close_active_auxiliary_window
785+# puts "close_active_auxiliary_windows"
786+# if @aux_windows
787+# @aux_windows.each_value { |d|
788+# if d.active?
789+# close_auxiliary_window(d)
790+# return true
791+# end
792+# }
793+# end
794+# return false;
795+# end
796+
771797 end
--- a/wxSources/MoleculeView.cpp
+++ b/wxSources/MoleculeView.cpp
@@ -549,8 +549,13 @@ MoleculeView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
549549 bool
550550 MoleculeView::OnClose(bool deleteWindow)
551551 {
552+#if !defined(__WXMAC__)
553+ // On wxOSX, this causes invocation of MyDocument::Close() twice, which
554+ // apprently is not very good. However, on wxMSW this is not the case.
555+ // So we need to keep this code for wxMSW but not for wxOSX.
552556 if (!GetDocument()->Close())
553557 return false;
558+#endif
554559
555560 // Dispose relationship between this and Molecule (MainView)
556561 MainView_setViewObject(mview, NULL);
--- a/wxSources/MyDocument.cpp
+++ b/wxSources/MyDocument.cpp
@@ -366,7 +366,6 @@ MyDocument::OnExportGraphic(wxCommandEvent& event)
366366 wxFileName fname(GetFilename());
367367 wxString fnstr;
368368 Int scale, bg_color, n, i;
369- char *p;
370369 i = MolActionCreateAndPerform(mol, SCRIPT_ACTION(";i"), "ask_graphic_export_scale", &n);
371370 if (i != 0 || n < 0)
372371 return;
@@ -486,9 +485,9 @@ MyDocument::CleanUndoStack(bool shouldRegister)
486485 void
487486 MyDocument::OnCustomClose(wxCommandEvent &event)
488487 {
489- RubyValue val;
490- MolActionCreateAndPerform(mol, SCRIPT_ACTION(";r"), "close_active_auxiliary_window", &val);
491- if (val == NULL || val == RubyNil)
488+// RubyValue val;
489+// MolActionCreateAndPerform(mol, SCRIPT_ACTION(";r"), "close_all_auxiliary_windows", &val);
490+// if (val == NULL || val == RubyNil)
492491 event.Skip();
493492 }
494493
@@ -504,6 +503,8 @@ MyDocument::Close()
504503 return false;
505504 }
506505 if (wxDocument::Close()) {
506+ /* Close all auxiliary windows */
507+ MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "close_all_auxiliary_windows");
507508 /* Send a message that this document will close */
508509 wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_documentWillClose);
509510 myEvent.SetEventObject(this);
@@ -529,7 +530,10 @@ MyDocument::OnDocumentModified(wxCommandEvent& event)
529530 {
530531 isModifyNotificationSent = false;
531532 MoleculeClearModifyCount(GetMainView()->mol);
532-
533+
534+ /* Send message to all auxiliary windows */
535+ MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "call_modification_handler_in_all_auxiliary_windows");
536+
533537 event.Skip(); // Also pass to other notification handlers
534538 UpdateModifyFlag();
535539 }
--- a/wxSources/RubyDialogFrame.cpp
+++ b/wxSources/RubyDialogFrame.cpp
@@ -31,6 +31,8 @@
3131 #include "wx/dcmemory.h"
3232
3333 #include "RubyDialogFrame.h"
34+
35+#include "../MolLib/Ruby_bind/Molby_extern.h"
3436 #include "MyApp.h"
3537 #include "MyMBConv.h"
3638 #include "MyDocument.h"
--- a/wxSources/RubyDialogFrame.h
+++ b/wxSources/RubyDialogFrame.h
@@ -73,7 +73,7 @@ public:
7373
7474 /* Message bridge (with Ruby world); obj, event_type, event_id, proc val */
7575 void **messageData;
76- Int countMessageData;
76+ int countMessageData;
7777
7878 /* On key handler (the handler is in the Ruby world) */
7979 bool onKeyHandlerEnabled;
旧リポジトリブラウザで表示