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
@@ -24,10 +24,12 @@ extern "C" { | ||
24 | 24 | #include "../MolLib.h" |
25 | 25 | |
26 | 26 | /* This definition is to work around 'VALUE' type in sources without "ruby.h" */ |
27 | +#ifndef RubyValue_is_Defined | |
28 | +#define RubyValue_is_Defined | |
27 | 29 | typedef void *RubyValue; |
28 | - | |
29 | 30 | #define RubyNil ((RubyValue)4) |
30 | - | |
31 | +#endif | |
32 | + | |
31 | 33 | extern char *gRubyVersion; |
32 | 34 | extern char *gRubyCopyright; |
33 | 35 |
@@ -11753,6 +11753,14 @@ Init_Molby(void) | ||
11753 | 11753 | s_EllipsoidSym = ID2SYM(rb_intern("ellipsoid")); |
11754 | 11754 | } |
11755 | 11755 | |
11756 | +#pragma mark ====== Interface with RubyDialog class ====== | |
11757 | + | |
11758 | +RubyValue | |
11759 | +RubyDialogCallback_parentModule(void) | |
11760 | +{ | |
11761 | + return (RubyValue)rb_mMolby; | |
11762 | +} | |
11763 | + | |
11756 | 11764 | #pragma mark ====== External functions ====== |
11757 | 11765 | |
11758 | 11766 | static VALUE s_ruby_top_self = Qfalse; |
@@ -51,6 +51,7 @@ VALUE rb_cDialog = Qfalse; | ||
51 | 51 | VALUE rb_cDialogItem = Qfalse; |
52 | 52 | VALUE rb_mDeviceContext = Qfalse; |
53 | 53 | VALUE rb_cBitmap = Qfalse; |
54 | +VALUE rb_eDialogError = Qfalse; | |
54 | 55 | VALUE gRubyDialogList = Qnil; |
55 | 56 | |
56 | 57 | const RDPoint gZeroPoint = {0, 0}; |
@@ -2710,10 +2711,14 @@ s_Bitmap_SaveToFile(VALUE self, VALUE fnval) | ||
2710 | 2711 | void |
2711 | 2712 | RubyDialogInitClass(void) |
2712 | 2713 | { |
2714 | + VALUE parent; | |
2713 | 2715 | if (rb_cDialog != Qfalse) |
2714 | 2716 | 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); | |
2717 | 2722 | rb_define_alloc_func(rb_cDialog, s_RubyDialog_Alloc); |
2718 | 2723 | rb_define_private_method(rb_cDialog, "initialize", s_RubyDialog_Initialize, -1); |
2719 | 2724 | rb_define_method(rb_cDialog, "run", s_RubyDialog_Run, 0); |
@@ -2744,7 +2749,11 @@ RubyDialogInitClass(void) | ||
2744 | 2749 | rb_define_singleton_method(rb_cDialog, "save_panel", s_RubyDialog_SavePanel, -1); |
2745 | 2750 | rb_define_singleton_method(rb_cDialog, "open_panel", s_RubyDialog_OpenPanel, -1); |
2746 | 2751 | |
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 | + | |
2748 | 2757 | rb_define_method(rb_cDialogItem, "[]=", s_RubyDialogItem_SetAttr, 2); |
2749 | 2758 | rb_define_method(rb_cDialogItem, "[]", s_RubyDialogItem_Attr, 1); |
2750 | 2759 | rb_define_alias(rb_cDialogItem, "set_attr", "[]="); |
@@ -2752,7 +2761,11 @@ RubyDialogInitClass(void) | ||
2752 | 2761 | rb_define_method(rb_cDialogItem, "append_string", s_RubyDialogItem_AppendString, 1); |
2753 | 2762 | rb_define_method(rb_cDialogItem, "refresh_rect", s_RubyDialogItem_RefreshRect, -1); |
2754 | 2763 | |
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 | + | |
2756 | 2769 | rb_define_method(rb_mDeviceContext, "clear", s_RubyDialog_Clear, 0); |
2757 | 2770 | rb_define_method(rb_mDeviceContext, "draw_ellipse", s_RubyDialog_DrawEllipse, -1); |
2758 | 2771 | rb_define_method(rb_mDeviceContext, "draw_line", s_RubyDialog_DrawLine, -1); |
@@ -2765,12 +2778,22 @@ RubyDialogInitClass(void) | ||
2765 | 2778 | |
2766 | 2779 | rb_include_module(rb_cDialog, rb_mDeviceContext); |
2767 | 2780 | |
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 | + | |
2769 | 2786 | rb_include_module(rb_cBitmap, rb_mDeviceContext); |
2770 | 2787 | rb_define_alloc_func(rb_cBitmap, s_Bitmap_Alloc); |
2771 | 2788 | rb_define_private_method(rb_cBitmap, "initialize", s_Bitmap_Initialize, -1); |
2772 | 2789 | rb_define_method(rb_cBitmap, "focus_exec", s_Bitmap_FocusExec, -1); |
2773 | 2790 | 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 | + | |
2774 | 2797 | { |
2775 | 2798 | static VALUE *sTable1[] = { |
2776 | 2799 | &sTextSymbol, &sTextFieldSymbol, &sRadioSymbol, &sButtonSymbol, |
@@ -18,21 +18,28 @@ | ||
18 | 18 | #ifndef __ruby_dialog_h__ |
19 | 19 | #define __ruby_dialog_h__ |
20 | 20 | |
21 | -#include "Molby_extern.h" | |
21 | +//#include "Molby_extern.h" | |
22 | 22 | |
23 | 23 | #ifdef __cplusplus |
24 | 24 | extern "C" { |
25 | 25 | #endif |
26 | 26 | |
27 | -/* RubyDialog class */ | |
28 | -/* extern VALUE rb_cDialog; */ | |
29 | - | |
30 | 27 | /* Style of the dialog frame */ |
31 | 28 | enum { |
32 | 29 | rd_Resizable = 1, |
33 | 30 | rd_HasCloseBox = 2, |
34 | 31 | }; |
35 | 32 | |
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 | + | |
36 | 43 | /* True if y-coordinate grows from bottom to top (like Cocoa) */ |
37 | 44 | extern int gRubyDialogIsFlipped; |
38 | 45 |
@@ -53,7 +60,7 @@ extern const RDRect gZeroRect; | ||
53 | 60 | |
54 | 61 | /* Utility function */ |
55 | 62 | 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); | |
57 | 64 | extern void RubyDialog_doTimerAction(RubyValue self); |
58 | 65 | extern void RubyDialog_doKeyAction(RubyValue self, int keyCode); |
59 | 66 | extern int RubyDialog_getFlexFlags(RubyValue self, RDItem *ip); |
@@ -73,7 +80,8 @@ extern void RubyDialog_OnPopUpMenuSelected(RubyValue self, RDItem *ip, int row, | ||
73 | 80 | |
74 | 81 | extern void RubyDialogInitClass(void); |
75 | 82 | |
76 | -/* Stub routines */ | |
83 | +/* Stub entries */ | |
84 | +STUB RubyValue RubyDialogCallback_parentModule(void); | |
77 | 85 | STUB RubyDialog *RubyDialogCallback_new(int style); |
78 | 86 | STUB void RubyDialogCallback_release(RubyDialog *dref); |
79 | 87 | STUB void RubyDialogCallback_setRubyObject(RubyDialog *dref, RubyValue val); |
@@ -97,6 +105,9 @@ STUB void RubyDialogCallback_setWindowSize(RubyDialog *dref, RDSize size); | ||
97 | 105 | |
98 | 106 | STUB void RubyDialogCallback_setAutoResizeEnabled(RubyDialog *dref, int flag); |
99 | 107 | 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); | |
100 | 111 | STUB int RubyDialogCallback_Listen(RubyDialog *dref, void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval); |
101 | 112 | |
102 | 113 | STUB void RubyDialogCallback_createStandardButtons(RubyDialog *dref, const char *oktitle, const char *canceltitle); |
@@ -42,9 +42,11 @@ typedef doublereal __CLPK_doublereal; | ||
42 | 42 | #ifdef __cplusplus |
43 | 43 | extern "C" { |
44 | 44 | #endif |
45 | - | |
46 | -#define STUB extern | |
47 | 45 | |
46 | +#ifndef STUB | |
47 | +#define STUB extern | |
48 | +#endif | |
49 | + | |
48 | 50 | #ifndef kRad2Deg |
49 | 51 | #define kRad2Deg (180./3.14159265358979) |
50 | 52 | #endif |
@@ -737,9 +737,14 @@ class Molecule | ||
737 | 737 | if block |
738 | 738 | d.instance_eval(&block) |
739 | 739 | 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 | |
743 | 748 | } |
744 | 749 | end |
745 | 750 | @aux_windows[title] = d |
@@ -756,16 +761,37 @@ class Molecule | ||
756 | 761 | end |
757 | 762 | end |
758 | 763 | |
759 | - def close_active_auxiliary_window | |
764 | + def close_all_auxiliary_windows | |
760 | 765 | 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) | |
766 | 768 | } |
769 | + return true | |
770 | + else | |
771 | + return false | |
767 | 772 | end |
768 | - return false; | |
769 | 773 | end |
770 | 774 | |
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 | + | |
771 | 797 | end |
@@ -549,8 +549,13 @@ MoleculeView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)) | ||
549 | 549 | bool |
550 | 550 | MoleculeView::OnClose(bool deleteWindow) |
551 | 551 | { |
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. | |
552 | 556 | if (!GetDocument()->Close()) |
553 | 557 | return false; |
558 | +#endif | |
554 | 559 | |
555 | 560 | // Dispose relationship between this and Molecule (MainView) |
556 | 561 | MainView_setViewObject(mview, NULL); |
@@ -366,7 +366,6 @@ MyDocument::OnExportGraphic(wxCommandEvent& event) | ||
366 | 366 | wxFileName fname(GetFilename()); |
367 | 367 | wxString fnstr; |
368 | 368 | Int scale, bg_color, n, i; |
369 | - char *p; | |
370 | 369 | i = MolActionCreateAndPerform(mol, SCRIPT_ACTION(";i"), "ask_graphic_export_scale", &n); |
371 | 370 | if (i != 0 || n < 0) |
372 | 371 | return; |
@@ -486,9 +485,9 @@ MyDocument::CleanUndoStack(bool shouldRegister) | ||
486 | 485 | void |
487 | 486 | MyDocument::OnCustomClose(wxCommandEvent &event) |
488 | 487 | { |
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) | |
492 | 491 | event.Skip(); |
493 | 492 | } |
494 | 493 |
@@ -504,6 +503,8 @@ MyDocument::Close() | ||
504 | 503 | return false; |
505 | 504 | } |
506 | 505 | if (wxDocument::Close()) { |
506 | + /* Close all auxiliary windows */ | |
507 | + MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "close_all_auxiliary_windows"); | |
507 | 508 | /* Send a message that this document will close */ |
508 | 509 | wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_documentWillClose); |
509 | 510 | myEvent.SetEventObject(this); |
@@ -529,7 +530,10 @@ MyDocument::OnDocumentModified(wxCommandEvent& event) | ||
529 | 530 | { |
530 | 531 | isModifyNotificationSent = false; |
531 | 532 | 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 | + | |
533 | 537 | event.Skip(); // Also pass to other notification handlers |
534 | 538 | UpdateModifyFlag(); |
535 | 539 | } |
@@ -31,6 +31,8 @@ | ||
31 | 31 | #include "wx/dcmemory.h" |
32 | 32 | |
33 | 33 | #include "RubyDialogFrame.h" |
34 | + | |
35 | +#include "../MolLib/Ruby_bind/Molby_extern.h" | |
34 | 36 | #include "MyApp.h" |
35 | 37 | #include "MyMBConv.h" |
36 | 38 | #include "MyDocument.h" |
@@ -73,7 +73,7 @@ public: | ||
73 | 73 | |
74 | 74 | /* Message bridge (with Ruby world); obj, event_type, event_id, proc val */ |
75 | 75 | void **messageData; |
76 | - Int countMessageData; | |
76 | + int countMessageData; | |
77 | 77 | |
78 | 78 | /* On key handler (the handler is in the Ruby world) */ |
79 | 79 | bool onKeyHandlerEnabled; |