Molecular Modeling Software
リビジョン | 8c15a036a640d4cb7985fc5e389fb08bca0b9b10 (tree) |
---|---|
日時 | 2014-09-27 00:32:32 |
作者 | toshinagata1964 <toshinagata1964@a2be...> |
コミッター | toshinagata1964 |
Ruby#listen is now obsolete, and the message mechanism of Ruby dialog is reworked.
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@574 a2be9bc6-48de-4e38-9406-05402d4bc13c
@@ -548,7 +548,7 @@ s_MolActionPerformRubyScript(Molecule *mol, MolAction *action) | ||
548 | 548 | MyAppCallback_endUndoGrouping(); |
549 | 549 | } |
550 | 550 | if (result != 0) { |
551 | - Molby_showError(result); | |
551 | + Ruby_showError(result); | |
552 | 552 | } |
553 | 553 | MyAppCallback_hideProgressPanel(); /* In case when the progress panel is still onscreen */ |
554 | 554 | return (result == 0 ? 0 : -1); |
@@ -33,14 +33,15 @@ typedef void *RubyValue; | ||
33 | 33 | extern char *gRubyVersion; |
34 | 34 | extern char *gRubyCopyright; |
35 | 35 | |
36 | +extern void Ruby_showError(int status); | |
37 | +extern int Ruby_showValue(RubyValue value, char **outValueString); | |
38 | +extern int Ruby_UpdateUI(int index, Molecule *mol, int *outChecked, char **outTitle); | |
39 | + | |
36 | 40 | extern void Molby_startup(const char *script_path, const char *dir); |
37 | 41 | extern char *Molby_getDescription(void); |
38 | -extern void Molby_showError(int status); | |
39 | 42 | extern RubyValue Molby_evalRubyScriptOnMolecule(const char *script, Molecule *mol, const char *fname, int *status); |
40 | 43 | /* extern RubyValue Molby_evalRubyScript(const char *script, int *status); |
41 | 44 | extern RubyValue Molby_evalRubyScriptOnActiveMoleculeWithInterrupt(const char *script, int *status); */ |
42 | -extern int Molby_showRubyValue(RubyValue value, char **outValueString); | |
43 | -extern int Ruby_UpdateUI(int index, Molecule *mol, int *outChecked, char **outTitle); | |
44 | 45 | /*extern int Ruby_methodType(const char *className, const char *methodName);*/ |
45 | 46 | extern void Molby_buildARGV(int argc, const char **argv); |
46 | 47 |
@@ -11878,7 +11878,7 @@ Molby_evalRubyScriptOnMolecule(const char *script, Molecule *mol, const char *fn | ||
11878 | 11878 | } |
11879 | 11879 | |
11880 | 11880 | int |
11881 | -Molby_showRubyValue(RubyValue value, char **outValueString) | |
11881 | +Ruby_showValue(RubyValue value, char **outValueString) | |
11882 | 11882 | { |
11883 | 11883 | VALUE val = (VALUE)value; |
11884 | 11884 | if (gMolbyIsCheckingInterrupt) { |
@@ -11905,7 +11905,7 @@ Molby_showRubyValue(RubyValue value, char **outValueString) | ||
11905 | 11905 | } |
11906 | 11906 | |
11907 | 11907 | void |
11908 | -Molby_showError(int status) | |
11908 | +Ruby_showError(int status) | |
11909 | 11909 | { |
11910 | 11910 | static const int tag_raise = 6; |
11911 | 11911 | char *msg = NULL, *msg2; |
@@ -12163,7 +12163,7 @@ Molby_startup(const char *script, const char *dir) | ||
12163 | 12163 | rb_load_protect(rb_str_new2(script), 0, &status); |
12164 | 12164 | gMolbyRunLevel--; |
12165 | 12165 | if (status != 0) |
12166 | - Molby_showError(status); | |
12166 | + Ruby_showError(status); | |
12167 | 12167 | else |
12168 | 12168 | MyAppCallback_showScriptMessage("Done.\n"); |
12169 | 12169 | } |
@@ -15,8 +15,9 @@ | ||
15 | 15 | |
16 | 16 | */ |
17 | 17 | |
18 | +#include <ruby.h> | |
18 | 19 | #include "ruby_dialog.h" |
19 | -#include "Molby.h" | |
20 | +#include "IntGroup.h" | |
20 | 21 | |
21 | 22 | static VALUE |
22 | 23 | sTextSymbol, sTextFieldSymbol, sRadioSymbol, sButtonSymbol, |
@@ -61,6 +62,21 @@ const RDRect gZeroRect = {{0, 0}, {0, 0}}; | ||
61 | 62 | /* True if y-coordinate grows from bottom to top (like Cocoa) */ |
62 | 63 | int gRubyDialogIsFlipped = 0; |
63 | 64 | |
65 | +#pragma mark ====== External utility functions and macros ====== | |
66 | + | |
67 | +#define FileStringValuePtr(val) Ruby_FileStringValuePtr(&val) | |
68 | +extern char *Ruby_FileStringValuePtr(VALUE *valp); | |
69 | +extern VALUE Ruby_NewFileStringValue(const char *fstr); | |
70 | + | |
71 | +#define EncodedStringValuePtr(val) Ruby_EncodedStringValuePtr(&val) | |
72 | +extern char *Ruby_EncodedStringValuePtr(VALUE *valp); | |
73 | +extern VALUE Ruby_NewEncodedStringValue(const char *str, int len); | |
74 | + | |
75 | +extern VALUE Ruby_SetInterruptFlag(VALUE val); | |
76 | +extern VALUE Ruby_ObjectAtIndex(VALUE ary, int idx); | |
77 | +extern VALUE ValueFromIntGroup(IntGroup *ig); | |
78 | +extern IntGroup *IntGroupFromValue(VALUE val); | |
79 | + | |
64 | 80 | #pragma mark ====== Dialog alloc/init/release ====== |
65 | 81 | |
66 | 82 | typedef struct RubyDialogInfo { |
@@ -102,7 +118,7 @@ s_RubyDialog_Forget(VALUE self) | ||
102 | 118 | if (di != NULL) { |
103 | 119 | if (di->dref != NULL) { |
104 | 120 | /* Unregister all messages */ |
105 | - RubyDialogCallback_Listen(di->dref, NULL, NULL, NULL, NULL, NULL); | |
121 | + /* RubyDialogCallback_Listen(di->dref, NULL, NULL, NULL, NULL, NULL); */ | |
106 | 122 | } |
107 | 123 | di->dref = NULL; |
108 | 124 | } |
@@ -142,7 +158,7 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val) | ||
142 | 158 | itag = NUM2INT(rb_ivar_get(self, SYM2ID(sIndexSymbol))); |
143 | 159 | type = rb_ivar_get(self, SYM2ID(sTypeSymbol)); |
144 | 160 | if (dialog_val == Qnil || (dref = s_RubyDialog_GetController(dialog_val)) == NULL) |
145 | - rb_raise(rb_eStandardError, "The dialog item does not belong to any dialog (internal error?)"); | |
161 | + rb_raise(rb_eDialogError, "The dialog item does not belong to any dialog (internal error?)"); | |
146 | 162 | view = RubyDialogCallback_dialogItemAtIndex(dref, itag); |
147 | 163 | key_id = SYM2ID(key); |
148 | 164 | if (key == sRangeSymbol) { |
@@ -260,7 +276,7 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val) | ||
260 | 276 | } else if (rb_obj_is_kind_of(val, rb_cNumeric)) { |
261 | 277 | flex = NUM2INT(rb_Integer(val)); |
262 | 278 | } else { |
263 | - rb_raise(rb_eMolbyError, "the 'flex' attribute should be either an integer or an array of 4 boolean/integers"); | |
279 | + rb_raise(rb_eDialogError, "the 'flex' attribute should be either an integer or an array of 4 boolean/integers"); | |
264 | 280 | } |
265 | 281 | rb_ivar_set(self, key_id, INT2NUM(flex)); |
266 | 282 | } |
@@ -304,7 +320,7 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val) | ||
304 | 320 | weight = 3; |
305 | 321 | } else if (vali != Qnil) { |
306 | 322 | vali = rb_inspect(vali); |
307 | - rb_raise(rb_eMolbyError, "unknown font specification (%s)", EncodedStringValuePtr(vali)); | |
323 | + rb_raise(rb_eDialogError, "unknown font specification (%s)", EncodedStringValuePtr(vali)); | |
308 | 324 | } |
309 | 325 | } |
310 | 326 | RubyDialogCallback_setFontForItem(view, size, family, style, weight); |
@@ -355,7 +371,7 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val) | ||
355 | 371 | } |
356 | 372 | } else { |
357 | 373 | if (key == sTagSymbol && rb_obj_is_kind_of(val, rb_cInteger)) |
358 | - rb_raise(rb_eMolbyError, "the dialog item tag must not be integers"); | |
374 | + rb_raise(rb_eDialogError, "the dialog item tag must not be integers"); | |
359 | 375 | rb_ivar_set(self, key_id, val); |
360 | 376 | } |
361 | 377 | RubyDialogCallback_setNeedsDisplay(view, 1); |
@@ -389,7 +405,7 @@ s_RubyDialogItem_Attr(VALUE self, VALUE key) | ||
389 | 405 | if (key == sTypeSymbol) |
390 | 406 | return type; |
391 | 407 | if (dialog_val == Qnil || (dref = s_RubyDialog_GetController(dialog_val)) == NULL) |
392 | - rb_raise(rb_eStandardError, "The dialog item does not belong to any dialog (internal error?)"); | |
408 | + rb_raise(rb_eDialogError, "The dialog item does not belong to any dialog (internal error?)"); | |
393 | 409 | view = RubyDialogCallback_dialogItemAtIndex(dref, itag); |
394 | 410 | key_id = SYM2ID(key); |
395 | 411 |
@@ -502,7 +518,7 @@ s_RubyDialogItem_Attr(VALUE self, VALUE key) | ||
502 | 518 | int size, family, style, weight; |
503 | 519 | VALUE fval, sval, wval; |
504 | 520 | if (RubyDialogCallback_getFontForItem(view, &size, &family, &style, &weight) == 0) |
505 | - rb_raise(rb_eMolbyError, "Cannot get font for dialog item"); | |
521 | + rb_raise(rb_eDialogError, "Cannot get font for dialog item"); | |
506 | 522 | fval = (family == 1 ? sDefaultSymbol : |
507 | 523 | (family == 2 ? sRomanSymbol : |
508 | 524 | (family == 3 ? sSwissSymbol : |
@@ -555,11 +571,11 @@ s_RubyDialogItem_AppendString(VALUE self, VALUE val) | ||
555 | 571 | index_val = rb_ivar_get(self, SYM2ID(sIndexSymbol)); |
556 | 572 | itag = NUM2INT(index_val); |
557 | 573 | if (dialog_val == Qnil || (dref = s_RubyDialog_GetController(dialog_val)) == NULL) |
558 | - rb_raise(rb_eStandardError, "The dialog item does not belong to any dialog (internal error?)"); | |
574 | + rb_raise(rb_eDialogError, "The dialog item does not belong to any dialog (internal error?)"); | |
559 | 575 | view = RubyDialogCallback_dialogItemAtIndex(dref, itag); |
560 | 576 | val = rb_str_to_str(val); |
561 | 577 | if (RubyDialogCallback_appendString(view, EncodedStringValuePtr(val)) == 0) |
562 | - rb_raise(rb_eMolbyError, "Cannot append string to the dialog item"); | |
578 | + rb_raise(rb_eDialogError, "Cannot append string to the dialog item"); | |
563 | 579 | return self; |
564 | 580 | } |
565 | 581 |
@@ -584,7 +600,7 @@ s_RubyDialogItem_RefreshRect(int argc, VALUE *argv, VALUE self) | ||
584 | 600 | index_val = rb_ivar_get(self, SYM2ID(sIndexSymbol)); |
585 | 601 | itag = NUM2INT(index_val); |
586 | 602 | if (dialog_val == Qnil || (dref = s_RubyDialog_GetController(dialog_val)) == NULL) |
587 | - rb_raise(rb_eStandardError, "The dialog item does not belong to any dialog (internal error?)"); | |
603 | + rb_raise(rb_eDialogError, "The dialog item does not belong to any dialog (internal error?)"); | |
588 | 604 | view = RubyDialogCallback_dialogItemAtIndex(dref, itag); |
589 | 605 | rb_scan_args(argc, argv, "11", &rval, &fval); |
590 | 606 | if (argc == 1) |
@@ -699,9 +715,9 @@ s_RubyDialog_ItemIndexForTag(VALUE self, VALUE tag) | ||
699 | 715 | { |
700 | 716 | int i = s_RubyDialog_ItemIndexForTagNoRaise(self, tag); |
701 | 717 | if (i == -1) |
702 | - rb_raise(rb_eStandardError, "item number (%d) out of range", i); | |
718 | + rb_raise(rb_eDialogError, "item number (%d) out of range", i); | |
703 | 719 | else if (i == -2) |
704 | - rb_raise(rb_eStandardError, "Dialog has no item with tag %s", EncodedStringValuePtr(tag)); | |
720 | + rb_raise(rb_eDialogError, "Dialog has no item with tag %s", EncodedStringValuePtr(tag)); | |
705 | 721 | return i; |
706 | 722 | } |
707 | 723 |
@@ -1160,7 +1176,7 @@ s_RubyDialog_Item(int argc, VALUE *argv, VALUE self) | ||
1160 | 1176 | if (NIL_P(hash)) |
1161 | 1177 | hash = rb_hash_new(); |
1162 | 1178 | else if (TYPE(hash) != T_HASH) |
1163 | - rb_raise(rb_eMolbyError, "The second argument of Dialog#item must be a hash"); | |
1179 | + rb_raise(rb_eDialogError, "The second argument of Dialog#item must be a hash"); | |
1164 | 1180 | rect.size.width = rect.size.height = 1.0; |
1165 | 1181 | rect.origin.x = rect.origin.y = 0.0; |
1166 | 1182 |
@@ -1218,7 +1234,7 @@ s_RubyDialog_Item(int argc, VALUE *argv, VALUE self) | ||
1218 | 1234 | } |
1219 | 1235 | |
1220 | 1236 | if (RubyDialogCallback_createItem(dref, rb_id2name(SYM2ID(type)), title, rect) == NULL) |
1221 | - rb_raise(rb_eStandardError, "item type :%s is not implemented", rb_id2name(SYM2ID(type))); | |
1237 | + rb_raise(rb_eDialogError, "item type :%s is not implemented", rb_id2name(SYM2ID(type))); | |
1222 | 1238 | |
1223 | 1239 | /* Push to _items */ |
1224 | 1240 | items = rb_iv_get(self, "_items"); |
@@ -1335,7 +1351,7 @@ s_RubyDialog_RadioGroup(VALUE self, VALUE aval) | ||
1335 | 1351 | rb_ary_push(gval, INT2NUM(j)); |
1336 | 1352 | } |
1337 | 1353 | if (i < n) |
1338 | - rb_raise(rb_eStandardError, "the item %d (at index %d) does not represent a radio button", j, i); | |
1354 | + rb_raise(rb_eDialogError, "the item %d (at index %d) does not represent a radio button", j, i); | |
1339 | 1355 | |
1340 | 1356 | /* Set the radio group array to the specified items. If the item already belongs to a radio group, |
1341 | 1357 | then it is removed from that group. */ |
@@ -1473,7 +1489,7 @@ s_RubyDialog_StartTimer(int argc, VALUE *argv, VALUE self) | ||
1473 | 1489 | rb_iv_set(self, "_timer_action", actval); |
1474 | 1490 | dval = NUM2DBL(rb_Float(itval)); |
1475 | 1491 | if (RubyDialogCallback_startIntervalTimer(dref, dval) == 0) |
1476 | - rb_raise(rb_eStandardError, "Cannot start timer for dialog"); | |
1492 | + rb_raise(rb_eDialogError, "Cannot start timer for dialog"); | |
1477 | 1493 | return self; |
1478 | 1494 | } |
1479 | 1495 |
@@ -1587,6 +1603,7 @@ s_RubyDialog_SetMinSize(int argc, VALUE *argv, VALUE self) | ||
1587 | 1603 | return self; |
1588 | 1604 | } |
1589 | 1605 | |
1606 | +#if 0 | |
1590 | 1607 | /* |
1591 | 1608 | * call-seq: |
1592 | 1609 | * listen(obj, str, pr) |
@@ -1609,8 +1626,8 @@ s_RubyDialog_Listen(VALUE self, VALUE oval, VALUE sval, VALUE pval) | ||
1609 | 1626 | i = RubyDialogCallback_Listen(s_RubyDialog_GetController(self), mol, "Molecule", sptr, (RubyValue)oval, (RubyValue)pval); |
1610 | 1627 | if (i < 0) { |
1611 | 1628 | switch (i) { |
1612 | - case -1: rb_raise(rb_eMolbyError, "This dialog cannot be listened to."); break; | |
1613 | - case -2: rb_raise(rb_eMolbyError, "This message is not supported"); break; | |
1629 | + case -1: rb_raise(rb_eDialogError, "This dialog cannot be listened to."); break; | |
1630 | + case -2: rb_raise(rb_eDialogError, "This message is not supported"); break; | |
1614 | 1631 | } |
1615 | 1632 | } else { |
1616 | 1633 | /* Keep the objects in the internal array, to protect from GC */ |
@@ -1627,10 +1644,11 @@ s_RubyDialog_Listen(VALUE self, VALUE oval, VALUE sval, VALUE pval) | ||
1627 | 1644 | } |
1628 | 1645 | } |
1629 | 1646 | } else { |
1630 | - rb_raise(rb_eMolbyError, "Dialog#listen is presently only available for Molecule object"); | |
1647 | + rb_raise(rb_eDialogError, "Dialog#listen is presently only available for Molecule object"); | |
1631 | 1648 | } |
1632 | 1649 | return self; |
1633 | 1650 | } |
1651 | +#endif | |
1634 | 1652 | |
1635 | 1653 | /* |
1636 | 1654 | * call-seq: |
@@ -1698,7 +1716,7 @@ s_RubyDialog_OpenPanel(int argc, VALUE *argv, VALUE klass) | ||
1698 | 1716 | if (mulval != Qnil && mulval != Qfalse) { |
1699 | 1717 | multiple_selection = 1; |
1700 | 1718 | if (for_directories && multiple_selection) |
1701 | - rb_raise(rb_eStandardError, "open_panel for directories allows only single selection"); | |
1719 | + rb_raise(rb_eDialogError, "open_panel for directories allows only single selection"); | |
1702 | 1720 | } |
1703 | 1721 | iflag = Ruby_SetInterruptFlag(Qfalse); |
1704 | 1722 | n = RubyDialogCallback_openPanel(mp, dp, wp, &ary, for_directories, multiple_selection); |
@@ -1844,7 +1862,7 @@ RubyDialog_GetTableItemCount(RubyValue self, RDItem *ip) | ||
1844 | 1862 | void *vp[4] = { (void *)self, (void *)ip, (void *)sOnCountSymbol, NULL }; |
1845 | 1863 | VALUE val = rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status); |
1846 | 1864 | if (status != 0) { |
1847 | - Molby_showError(status); | |
1865 | + Ruby_showError(status); | |
1848 | 1866 | return 0; |
1849 | 1867 | } else if (val == Qnil) |
1850 | 1868 | return 0; |
@@ -1884,7 +1902,7 @@ RubyDialog_DragTableSelectionToRow(RubyValue self, RDItem *ip, int row) | ||
1884 | 1902 | void *vp[5] = { (void *)self, (void *)ip, (void *)sOnDragSelectionToRowSymbol, (void *)row, NULL }; |
1885 | 1903 | rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status); |
1886 | 1904 | if (status != 0) |
1887 | - Molby_showError(status); | |
1905 | + Ruby_showError(status); | |
1888 | 1906 | } |
1889 | 1907 | |
1890 | 1908 | int |
@@ -1916,7 +1934,7 @@ RubyDialog_OnTableSelectionChanged(RubyValue self, RDItem *ip) | ||
1916 | 1934 | void *vp[4] = { (void *)self, (void *)ip, (void *)sOnSelectionChangedSymbol, NULL }; |
1917 | 1935 | rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status); |
1918 | 1936 | if (status != 0) |
1919 | - Molby_showError(status); | |
1937 | + Ruby_showError(status); | |
1920 | 1938 | } |
1921 | 1939 | |
1922 | 1940 | int |
@@ -1948,7 +1966,7 @@ RubyDialog_OnPopUpMenuSelected(RubyValue self, RDItem *ip, int row, int column, | ||
1948 | 1966 | void *vp[7] = { (void *)self, (void *)ip, (void *)sOnPopUpMenuSelectedSymbol, (void *)row, (void *)column, (void *)selected_index, NULL }; |
1949 | 1967 | rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status); |
1950 | 1968 | if (status != 0) |
1951 | - Molby_showError(status); | |
1969 | + Ruby_showError(status); | |
1952 | 1970 | } |
1953 | 1971 | |
1954 | 1972 | #pragma mark ====== Utility function ====== |
@@ -2001,7 +2019,7 @@ s_RubyDialog_doItemAction(VALUE val) | ||
2001 | 2019 | VALUE flag; |
2002 | 2020 | RDItem *ip = (RDItem *)vp[1]; |
2003 | 2021 | RDItem *ip2; |
2004 | - Int options = (Int)vp[2]; | |
2022 | + int options = (int)vp[2]; | |
2005 | 2023 | VALUE ival, itval, actval, tval, aval; |
2006 | 2024 | RubyDialog *dref = s_RubyDialog_GetController(self); |
2007 | 2025 | VALUE items = rb_iv_get(self, "_items"); |
@@ -2100,7 +2118,7 @@ s_RubyDialog_doItemAction(VALUE val) | ||
2100 | 2118 | the item number (integer) as the argument. The default "action" method is |
2101 | 2119 | defined as s_RubyDialog_action. */ |
2102 | 2120 | void |
2103 | -RubyDialog_doItemAction(RubyValue self, RDItem *ip, Int options) | |
2121 | +RubyDialog_doItemAction(RubyValue self, RDItem *ip, int options) | |
2104 | 2122 | { |
2105 | 2123 | int status; |
2106 | 2124 | void *vp[3]; |
@@ -2109,7 +2127,7 @@ RubyDialog_doItemAction(RubyValue self, RDItem *ip, Int options) | ||
2109 | 2127 | vp[2] = (void *)options; |
2110 | 2128 | rb_protect(s_RubyDialog_doItemAction, (VALUE)vp, &status); |
2111 | 2129 | if (status != 0) |
2112 | - Molby_showError(status); | |
2130 | + Ruby_showError(status); | |
2113 | 2131 | } |
2114 | 2132 | |
2115 | 2133 | static VALUE |
@@ -2145,7 +2163,7 @@ RubyDialog_doPaintAction(RubyValue self, RDItem *ip) | ||
2145 | 2163 | vp[1] = ip; |
2146 | 2164 | rb_protect(s_RubyDialog_doPaintAction, (VALUE)vp, &status); |
2147 | 2165 | if (status != 0) |
2148 | - Molby_showError(status); | |
2166 | + Ruby_showError(status); | |
2149 | 2167 | } |
2150 | 2168 | |
2151 | 2169 | static VALUE |
@@ -2169,7 +2187,7 @@ RubyDialog_doTimerAction(RubyValue self) | ||
2169 | 2187 | if (status != 0) { |
2170 | 2188 | /* Stop timer before showing error dialog */ |
2171 | 2189 | RubyDialogCallback_stopIntervalTimer(s_RubyDialog_GetController((VALUE)self)); |
2172 | - Molby_showError(status); | |
2190 | + Ruby_showError(status); | |
2173 | 2191 | } |
2174 | 2192 | } |
2175 | 2193 |
@@ -2198,7 +2216,7 @@ RubyDialog_doKeyAction(RubyValue self, int keyCode) | ||
2198 | 2216 | values[1] = (void *)keyCode; |
2199 | 2217 | rb_protect(s_RubyDialog_doKeyAction, (VALUE)values, &status); |
2200 | 2218 | if (status != 0) { |
2201 | - Molby_showError(status); | |
2219 | + Ruby_showError(status); | |
2202 | 2220 | } |
2203 | 2221 | } |
2204 | 2222 |
@@ -2274,7 +2292,7 @@ RubyDialog_doCloseWindow(RubyValue self, int isModal) | ||
2274 | 2292 | void *args[2] = { (void *)self, (void *)isModal }; |
2275 | 2293 | rval = rb_protect(s_RubyDialog_doCloseWindow, (VALUE)args, &status); |
2276 | 2294 | if (status != 0) { |
2277 | - Molby_showError(status); | |
2295 | + Ruby_showError(status); | |
2278 | 2296 | } |
2279 | 2297 | } |
2280 | 2298 |
@@ -2291,7 +2309,7 @@ s_RubyDialog_GetDeviceContext(VALUE self) | ||
2291 | 2309 | Data_Get_Struct(self, RDBitmap, bitmap); |
2292 | 2310 | return RubyDialogCallback_getDeviceContextForBitmap(bitmap); |
2293 | 2311 | } else { |
2294 | - rb_raise(rb_eMolbyError, "No graphic device context is available"); | |
2312 | + rb_raise(rb_eDialogError, "No graphic device context is available"); | |
2295 | 2313 | return NULL; /* Not reached */ |
2296 | 2314 | } |
2297 | 2315 | } |
@@ -2350,24 +2368,24 @@ s_RubyDialog_DrawLine(int argc, VALUE *argv, VALUE self) | ||
2350 | 2368 | /* The second form */ |
2351 | 2369 | ncoords = argc; |
2352 | 2370 | if (ncoords < 2) |
2353 | - rb_raise(rb_eMolbyError, "Too few coordinates are given (requires at least two points)"); | |
2371 | + rb_raise(rb_eDialogError, "Too few coordinates are given (requires at least two points)"); | |
2354 | 2372 | coords = (float *)calloc(sizeof(float), ncoords * 2); |
2355 | 2373 | coords[0] = NUM2DBL(rb_Float(RARRAY_PTR(aval)[0])); |
2356 | 2374 | coords[1] = NUM2DBL(rb_Float(RARRAY_PTR(aval)[1])); |
2357 | 2375 | for (i = 1; i < ncoords; i++) { |
2358 | 2376 | aval = rb_ary_to_ary(argv[i]); |
2359 | 2377 | if (RARRAY_LEN(aval) < 2) |
2360 | - rb_raise(rb_eMolbyError, "The coordinate should be an array of two numerics"); | |
2378 | + rb_raise(rb_eDialogError, "The coordinate should be an array of two numerics"); | |
2361 | 2379 | coords[i * 2] = NUM2DBL(rb_Float(RARRAY_PTR(aval)[0])); |
2362 | 2380 | coords[i * 2 + 1] = NUM2DBL(rb_Float(RARRAY_PTR(aval)[1])); |
2363 | 2381 | } |
2364 | 2382 | } else { |
2365 | 2383 | /* The third form */ |
2366 | 2384 | if (RARRAY_LEN(aval) % 2 == 1) |
2367 | - rb_raise(rb_eMolbyError, "An odd number of numerics are given; the coordinate values should be given in pairs"); | |
2385 | + rb_raise(rb_eDialogError, "An odd number of numerics are given; the coordinate values should be given in pairs"); | |
2368 | 2386 | ncoords = RARRAY_LEN(aval) / 2; |
2369 | 2387 | if (ncoords < 2) |
2370 | - rb_raise(rb_eMolbyError, "Too few coordinates are given (requires at least two points)"); | |
2388 | + rb_raise(rb_eDialogError, "Too few coordinates are given (requires at least two points)"); | |
2371 | 2389 | coords = (float *)calloc(sizeof(float), ncoords * 2); |
2372 | 2390 | for (i = 0; i < ncoords * 2; i++) { |
2373 | 2391 | coords[i] = NUM2DBL(rb_Float(RARRAY_PTR(aval)[i])); |
@@ -2377,9 +2395,9 @@ s_RubyDialog_DrawLine(int argc, VALUE *argv, VALUE self) | ||
2377 | 2395 | /* The first form */ |
2378 | 2396 | ncoords = argc / 2; |
2379 | 2397 | if (ncoords < 2) |
2380 | - rb_raise(rb_eMolbyError, "Too few coordinates are given (requires at least two points)"); | |
2398 | + rb_raise(rb_eDialogError, "Too few coordinates are given (requires at least two points)"); | |
2381 | 2399 | if (argc % 2 == 1) |
2382 | - rb_raise(rb_eMolbyError, "An odd number of numerics are given; the coordinate values should be given in pairs"); | |
2400 | + rb_raise(rb_eDialogError, "An odd number of numerics are given; the coordinate values should be given in pairs"); | |
2383 | 2401 | coords = (float *)calloc(sizeof(float), ncoords * 2); |
2384 | 2402 | for (i = 0; i < ncoords * 2; i++) { |
2385 | 2403 | coords[i] = NUM2DBL(rb_Float(argv[i])); |
@@ -2410,7 +2428,7 @@ s_RubyDialog_DrawRectangle(int argc, VALUE *argv, VALUE self) | ||
2410 | 2428 | rb_scan_args(argc, argv, "11", &xval, &rval); |
2411 | 2429 | xval = rb_ary_to_ary(xval); |
2412 | 2430 | if (RARRAY_LEN(xval) < 4) |
2413 | - rb_raise(rb_eMolbyError, "The dimension of rectangle should be given as four numerics (x, y, width, height) or an array of four numerics."); | |
2431 | + rb_raise(rb_eDialogError, "The dimension of rectangle should be given as four numerics (x, y, width, height) or an array of four numerics."); | |
2414 | 2432 | hval = RARRAY_PTR(xval)[3]; |
2415 | 2433 | wval = RARRAY_PTR(xval)[2]; |
2416 | 2434 | yval = RARRAY_PTR(xval)[1]; |
@@ -2656,11 +2674,11 @@ s_Bitmap_Initialize(int argc, VALUE *argv, VALUE self) | ||
2656 | 2674 | width = NUM2INT(rb_Integer(wval)); |
2657 | 2675 | height = NUM2INT(rb_Integer(hval)); |
2658 | 2676 | if (width <= 0 || width >= 32768) |
2659 | - rb_raise(rb_eMolbyError, "Bitmap width (%d) is out of range (1..32767)", width); | |
2677 | + rb_raise(rb_eDialogError, "Bitmap width (%d) is out of range (1..32767)", width); | |
2660 | 2678 | if (height <= 0 || height >= 32768) |
2661 | - rb_raise(rb_eMolbyError, "Bitmap height (%d) is out of range (1..32767)", height); | |
2679 | + rb_raise(rb_eDialogError, "Bitmap height (%d) is out of range (1..32767)", height); | |
2662 | 2680 | if (depth != 32) |
2663 | - rb_raise(rb_eMolbyError, "Only depth = 32 is supported currently"); | |
2681 | + rb_raise(rb_eDialogError, "Only depth = 32 is supported currently"); | |
2664 | 2682 | bitmap = RubyDialogCallback_createBitmap(width, height, depth); |
2665 | 2683 | DATA_PTR(self) = bitmap; |
2666 | 2684 | return self; |
@@ -2714,7 +2732,7 @@ RubyDialogInitClass(void) | ||
2714 | 2732 | VALUE parent; |
2715 | 2733 | if (rb_cDialog != Qfalse) |
2716 | 2734 | return; |
2717 | - parent = RubyDialogCallback_parentModule(); | |
2735 | + parent = (VALUE)RubyDialogCallback_parentModule(); | |
2718 | 2736 | if (parent != Qfalse) |
2719 | 2737 | rb_cDialog = rb_define_class_under(parent, "Dialog", rb_cObject); |
2720 | 2738 | else |
@@ -2745,7 +2763,7 @@ RubyDialogInitClass(void) | ||
2745 | 2763 | rb_define_method(rb_cDialog, "size", s_RubyDialog_Size, 0); |
2746 | 2764 | rb_define_method(rb_cDialog, "set_min_size", s_RubyDialog_SetMinSize, -1); |
2747 | 2765 | rb_define_method(rb_cDialog, "min_size", s_RubyDialog_MinSize, 0); |
2748 | - rb_define_method(rb_cDialog, "listen", s_RubyDialog_Listen, 3); | |
2766 | +/* rb_define_method(rb_cDialog, "listen", s_RubyDialog_Listen, 3); */ | |
2749 | 2767 | rb_define_singleton_method(rb_cDialog, "save_panel", s_RubyDialog_SavePanel, -1); |
2750 | 2768 | rb_define_singleton_method(rb_cDialog, "open_panel", s_RubyDialog_OpenPanel, -1); |
2751 | 2769 |
@@ -39,7 +39,9 @@ typedef void *RubyValue; | ||
39 | 39 | #ifndef STUB |
40 | 40 | #define STUB extern |
41 | 41 | #endif |
42 | - | |
42 | + | |
43 | +extern void Ruby_showError(int status); | |
44 | + | |
43 | 45 | /* True if y-coordinate grows from bottom to top (like Cocoa) */ |
44 | 46 | extern int gRubyDialogIsFlipped; |
45 | 47 |
@@ -106,9 +108,7 @@ STUB void RubyDialogCallback_setWindowSize(RubyDialog *dref, RDSize size); | ||
106 | 108 | STUB void RubyDialogCallback_setAutoResizeEnabled(RubyDialog *dref, int flag); |
107 | 109 | STUB int RubyDialogCallback_isAutoResizeEnabled(RubyDialog *dref); |
108 | 110 | |
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); | |
111 | -STUB int RubyDialogCallback_Listen(RubyDialog *dref, void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval); | |
111 | +//STUB int RubyDialogCallback_Listen(RubyDialog *dref, void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval); | |
112 | 112 | |
113 | 113 | STUB void RubyDialogCallback_createStandardButtons(RubyDialog *dref, const char *oktitle, const char *canceltitle); |
114 | 114 | STUB RDItem *RubyDialogCallback_createItem(RubyDialog *dref, const char *type, const char *title, RDRect frame); |
@@ -761,23 +761,36 @@ class Molecule | ||
761 | 761 | end |
762 | 762 | end |
763 | 763 | |
764 | - def close_all_auxiliary_windows | |
765 | - if @aux_windows | |
764 | +# def close_all_auxiliary_windows | |
765 | +# if @aux_windows | |
766 | +# @aux_windows.values.each { |d| | |
767 | +# close_auxiliary_window(d) | |
768 | +# } | |
769 | +# return true | |
770 | +# else | |
771 | +# return false | |
772 | +# end | |
773 | +# end | |
774 | + | |
775 | + def on_close | |
776 | + mol = self | |
777 | + @on_close.call(mol) if @on_close | |
778 | + if @aux_windows | |
766 | 779 | @aux_windows.values.each { |d| |
767 | 780 | close_auxiliary_window(d) |
768 | - } | |
769 | - return true | |
770 | - else | |
771 | - return false | |
781 | + } | |
772 | 782 | end |
773 | 783 | end |
774 | 784 | |
775 | - def call_modification_handler_in_all_auxiliary_windows | |
785 | + def on_modified | |
776 | 786 | mol = self |
777 | - if @aux_windows | |
778 | - @aux_windows.values.each { |d| | |
787 | + # Call a handler if defined | |
788 | + @on_document_modified.call(mol) if @on_document_modified | |
789 | + if @aux_windows | |
790 | + @aux_windows.each_value { |d| | |
791 | + # For each auxiliary window, call a handler if defined | |
779 | 792 | d.instance_eval { @on_document_modified.call(mol) if @on_document_modified } |
780 | - } | |
793 | + } | |
781 | 794 | end |
782 | 795 | end |
783 | 796 |
@@ -361,12 +361,12 @@ ConsoleFrame::OnEnterPressed() | ||
361 | 361 | char *valueString; |
362 | 362 | MyAppCallback_setConsoleColor(1); |
363 | 363 | if (status != 0) { |
364 | - Molby_showError(status); | |
364 | + Ruby_showError(status); | |
365 | 365 | } else { |
366 | 366 | textCtrl->AppendText(wxT("-->")); |
367 | - status = Molby_showRubyValue(val, &valueString); | |
367 | + status = Ruby_showValue(val, &valueString); | |
368 | 368 | if (status != 0) { |
369 | - Molby_showError(status); | |
369 | + Ruby_showError(status); | |
370 | 370 | } else { |
371 | 371 | AssignArray(&valueHistory, &nValueHistory, sizeof(char *), nValueHistory, &valueString); |
372 | 372 | if (nValueHistory >= MAX_HISTORY_LINES) |
@@ -1139,7 +1139,7 @@ MyApp::OnExecuteScript(wxCommandEvent &event) | ||
1139 | 1139 | if (retval == (RubyValue)6 && status == -1) |
1140 | 1140 | MyAppCallback_errorMessageBox("Cannot open Ruby script %s", (const char *)path.mb_str(wxConvFile)); |
1141 | 1141 | else if (status != 0) |
1142 | - Molby_showError(status); | |
1142 | + Ruby_showError(status); | |
1143 | 1143 | } |
1144 | 1144 | dialog->Destroy(); |
1145 | 1145 | } |
@@ -1196,7 +1196,7 @@ MyApp::OnOpenFiles(const wxString &files) | ||
1196 | 1196 | if (retval == (RubyValue)6 && status == -1) |
1197 | 1197 | MyAppCallback_errorMessageBox("Cannot open Ruby script: %s", (const char *)file.mb_str(wxConvFile)); |
1198 | 1198 | else |
1199 | - Molby_showError(status); | |
1199 | + Ruby_showError(status); | |
1200 | 1200 | return false; |
1201 | 1201 | } |
1202 | 1202 | } else { |
@@ -75,7 +75,7 @@ BEGIN_EVENT_TABLE(MyDocument, wxDocument) | ||
75 | 75 | EVT_MENU(wxID_PASTE, MyDocument::OnPaste) |
76 | 76 | EVT_MENU(wxID_CUT, MyDocument::OnCut) |
77 | 77 | EVT_MENU(wxID_DELETE, MyDocument::OnDelete) |
78 | - EVT_MENU(wxID_CLOSE, MyDocument::OnCustomClose) | |
78 | +// EVT_MENU(wxID_CLOSE, MyDocument::OnCustomClose) | |
79 | 79 | EVT_MENU(myMenuID_CreateNewAtom, MyDocument::OnCreateNewAtom) |
80 | 80 | EVT_MENU_RANGE(myMenuID_CreateNewVdwParameter, myMenuID_CreateNewVdwCutoffParameter, MyDocument::OnCreateNewParameter) |
81 | 81 | EVT_MENU(myMenuID_CreatePiAnchor, MyDocument::OnCreatePiAnchor) |
@@ -488,7 +488,7 @@ MyDocument::OnCustomClose(wxCommandEvent &event) | ||
488 | 488 | // RubyValue val; |
489 | 489 | // MolActionCreateAndPerform(mol, SCRIPT_ACTION(";r"), "close_all_auxiliary_windows", &val); |
490 | 490 | // if (val == NULL || val == RubyNil) |
491 | - event.Skip(); | |
491 | +// event.Skip(); | |
492 | 492 | } |
493 | 493 | |
494 | 494 | bool |
@@ -503,8 +503,8 @@ MyDocument::Close() | ||
503 | 503 | return false; |
504 | 504 | } |
505 | 505 | if (wxDocument::Close()) { |
506 | - /* Close all auxiliary windows */ | |
507 | - MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "close_all_auxiliary_windows"); | |
506 | + /* Call close hander in the Ruby world */ | |
507 | + MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "on_close"); | |
508 | 508 | /* Send a message that this document will close */ |
509 | 509 | wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_documentWillClose); |
510 | 510 | myEvent.SetEventObject(this); |
@@ -531,8 +531,8 @@ MyDocument::OnDocumentModified(wxCommandEvent& event) | ||
531 | 531 | isModifyNotificationSent = false; |
532 | 532 | MoleculeClearModifyCount(GetMainView()->mol); |
533 | 533 | |
534 | - /* Send message to all auxiliary windows */ | |
535 | - MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "call_modification_handler_in_all_auxiliary_windows"); | |
534 | + /* Call modified handler in the Ruby world */ | |
535 | + MolActionCreateAndPerform(mol, SCRIPT_ACTION(""), "on_modified"); | |
536 | 536 | |
537 | 537 | event.Skip(); // Also pass to other notification handlers |
538 | 538 | UpdateModifyFlag(); |
@@ -66,8 +66,8 @@ RubyDialogFrame::RubyDialogFrame(wxWindow* parent, wxWindowID wid, const wxStrin | ||
66 | 66 | dval = NULL; |
67 | 67 | mySize = gZeroSize; |
68 | 68 | autoResizeEnabled = true; |
69 | - messageData = NULL; | |
70 | - countMessageData = 0; | |
69 | +// messageData = NULL; | |
70 | +// countMessageData = 0; | |
71 | 71 | onKeyHandlerEnabled = false; |
72 | 72 | currentContext = NULL; |
73 | 73 | currentDrawingItem = NULL; |
@@ -92,9 +92,10 @@ RubyDialogFrame::~RubyDialogFrame() | ||
92 | 92 | delete myTimer; |
93 | 93 | if (ditems != NULL) |
94 | 94 | free(ditems); |
95 | - DiscardMessageData(); | |
95 | +// DiscardMessageData(); | |
96 | 96 | } |
97 | 97 | |
98 | +#if 0 | |
98 | 99 | void |
99 | 100 | RubyDialogFrame::DiscardMessageData() |
100 | 101 | { |
@@ -114,6 +115,7 @@ RubyDialogFrame::DiscardMessageData() | ||
114 | 115 | messageData = NULL; |
115 | 116 | countMessageData = 0; |
116 | 117 | } |
118 | +#endif | |
117 | 119 | |
118 | 120 | int |
119 | 121 | RubyDialogFrame::AddDialogItem(RDItem *item) |
@@ -164,7 +166,7 @@ RubyDialogFrame::SetRubyObject(RubyValue val) | ||
164 | 166 | dval = val; |
165 | 167 | if (dval == NULL) { |
166 | 168 | /* Stop message mechanism (because this object is already disconnected from the Ruby world) */ |
167 | - DiscardMessageData(); | |
169 | + /* DiscardMessageData(); */ | |
168 | 170 | } |
169 | 171 | } |
170 | 172 |
@@ -479,6 +481,7 @@ sGetEventHandlerFromObjectAndType(void *obj, wxEventType eventType) | ||
479 | 481 | else return NULL; |
480 | 482 | } |
481 | 483 | |
484 | +#if 0 | |
482 | 485 | int |
483 | 486 | RubyDialogFrame::ListenToObject(void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval) |
484 | 487 | { |
@@ -584,6 +587,7 @@ RubyDialogFrame::HandleDocumentEvent(wxCommandEvent &event) | ||
584 | 587 | } |
585 | 588 | event.Skip(); |
586 | 589 | } |
590 | +#endif | |
587 | 591 | |
588 | 592 | void |
589 | 593 | RubyDialogFrame::HandlePaintEvent(wxPaintEvent &event) |
@@ -905,11 +909,13 @@ RubyDialogCallback_isAutoResizeEnabled(RubyDialog *dref) | ||
905 | 909 | return ((RubyDialogFrame *)dref)->IsAutoResizeEnabled(); |
906 | 910 | } |
907 | 911 | |
912 | +/* | |
908 | 913 | int |
909 | 914 | RubyDialogCallback_Listen(RubyDialog *dref, void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval) |
910 | 915 | { |
911 | 916 | return ((RubyDialogFrame *)dref)->ListenToObject(obj, objtype, msg, oval, pval); |
912 | 917 | } |
918 | +*/ | |
913 | 919 | |
914 | 920 | void |
915 | 921 | RubyDialogCallback_createStandardButtons(RubyDialog *dref, const char *oktitle, const char *canceltitle) |
@@ -72,8 +72,8 @@ public: | ||
72 | 72 | bool autoResizeEnabled; /* true if auto resizing is enabled */ |
73 | 73 | |
74 | 74 | /* Message bridge (with Ruby world); obj, event_type, event_id, proc val */ |
75 | - void **messageData; | |
76 | - int countMessageData; | |
75 | +// void **messageData; | |
76 | +// int countMessageData; | |
77 | 77 | |
78 | 78 | /* On key handler (the handler is in the Ruby world) */ |
79 | 79 | bool onKeyHandlerEnabled; |
@@ -86,13 +86,14 @@ public: | ||
86 | 86 | virtual ~RubyDialogFrame(); |
87 | 87 | |
88 | 88 | /* For internal use (discard data in messageData[]) */ |
89 | - void DiscardMessageData(); | |
89 | +// void DiscardMessageData(); | |
90 | 90 | |
91 | 91 | void SetAutoResizeEnabled(int flag) { autoResizeEnabled = (flag != 0); } |
92 | 92 | bool IsAutoResizeEnabled() { return autoResizeEnabled; } |
93 | 93 | |
94 | - int ListenToObject(void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval); | |
95 | - void HandleDocumentEvent(wxCommandEvent &event); | |
94 | +// int ListenToObject(void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval); | |
95 | +// void HandleDocumentEvent(wxCommandEvent &event); | |
96 | + | |
96 | 97 | void HandlePaintEvent(wxPaintEvent &event); |
97 | 98 | |
98 | 99 | int AddDialogItem(RDItem *item); |