OSDN Git Service

Ruby dialog capabilities are added: the items can now have foreground and background...
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Fri, 27 Sep 2013 15:34:31 +0000 (15:34 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Fri, 27 Sep 2013 15:34:31 +0000 (15:34 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@393 a2be9bc6-48de-4e38-9406-05402d4bc13c

MolLib/Ruby_bind/Molby_extern.h
MolLib/Ruby_bind/ruby_bind.c
MolLib/Ruby_bind/ruby_dialog.c
MolLib/Ruby_bind/ruby_dialog.h
wxSources/MyApp.cpp
wxSources/RubyDialogFrame.cpp
wxSources/RubyDialogFrame.h

index acead96..04a68ab 100755 (executable)
@@ -74,6 +74,9 @@ STUB void MyAppCallback_endUndoGrouping(void);
 STUB int MyAppCallback_switchToFilterMode(void);
 STUB void MyAppCallback_showConsoleWindow(void);
 STUB void MyAppCallback_hideConsoleWindow(void);
+STUB void MyAppCallback_bell(void);
+STUB int MyAppCallback_playSound(const char *filename, int flag);
+STUB void MyAppCallback_stopSound(void);
 
 #define DUMMY_CALLBACK ((int (*)(void *))1)
 
index 244bd3b..5afa6ab 100644 (file)
@@ -258,6 +258,55 @@ s_Kernel_HideConsoleWindow(VALUE self)
 
 /*
  *  call-seq:
+ *     bell
+ *
+ *  Ring the system bell.
+ */
+static VALUE
+s_Kernel_Bell(VALUE self)
+{
+       MyAppCallback_bell();
+       return Qnil;
+}
+
+/*
+ *  call-seq:
+ *     play_sound(filename, flag = 0)
+ *
+ *  Play the sound (a WAV file) in the file. Flag: 0, pause until sound ends;
+ *  1, play the sound asynchronously; 3, play the sound with loop asynchronously
+ */
+static VALUE
+s_Kernel_PlaySound(int argc, VALUE *argv, VALUE self)
+{
+       VALUE fnval, flval;
+       int flag, retval;
+       char *fname;
+       rb_scan_args(argc, argv, "11", &fnval, &flval);
+       if (flval == Qnil)
+               flag = 0;
+       else flag = NUM2INT(rb_Integer(flval));
+       fnval = rb_funcall(rb_cFile, rb_intern("expand_path"), 1, fnval);
+       fname = StringValuePtr(fnval);
+       retval = MyAppCallback_playSound(fname, flag);
+       return (retval ? Qtrue : Qnil);
+}
+
+/*
+ *  call-seq:
+ *     stop_sound
+ *
+ *  Stop the sound if playing.
+ */
+static VALUE
+s_Kernel_StopSound(VALUE self)
+{
+       MyAppCallback_stopSound();
+       return Qnil;
+}
+
+/*
+ *  call-seq:
  *     stdout.write(str)
  *
  *  Put the message in the main text view in black color.
@@ -10540,7 +10589,10 @@ Init_Molby(void)
        rb_define_method(rb_mKernel, "error_message_box", s_Kernel_ErrorMessageBox, 1);
        rb_define_method(rb_mKernel, "show_console_window", s_Kernel_ShowConsoleWindow, 0);
        rb_define_method(rb_mKernel, "hide_console_window", s_Kernel_HideConsoleWindow, 0);
-       
+       rb_define_method(rb_mKernel, "bell", s_Kernel_Bell, 0);
+       rb_define_method(rb_mKernel, "play_sound", s_Kernel_PlaySound, -1);
+       rb_define_method(rb_mKernel, "stop_sound", s_Kernel_StopSound, 0);
+
        s_ID_equal = rb_intern("==");
        g_RubyID_call = rb_intern("call");
 }
index bea542e..def4105 100644 (file)
@@ -23,7 +23,8 @@ static VALUE
        sCheckBoxSymbol, sToggleButtonSymbol, sPopUpSymbol, sTextViewSymbol,
     sViewSymbol, sLineSymbol, sTagSymbol, sTypeSymbol, sTitleSymbol, 
        sRadioGroupSymbol, sTableSymbol,
-       sResizableSymbol, sDialogSymbol, sIndexSymbol,
+       sResizableSymbol, sHasCloseBoxSymbol,
+       sDialogSymbol, sIndexSymbol,
        sXSymbol, sYSymbol, sWidthSymbol, sHeightSymbol, 
        sOriginSymbol, sSizeSymbol, sFrameSymbol,
        sEnabledSymbol, sEditableSymbol, sHiddenSymbol, sValueSymbol,
@@ -33,6 +34,7 @@ static VALUE
        sMarginSymbol, sPaddingSymbol, sSubItemsSymbol,
        sHFillSymbol, sVFillSymbol, sFlexSymbol,
        sIsProcessingActionSymbol,
+       sForeColorSymbol, sBackColorSymbol,
        sFontSymbol,
        sDefaultSymbol, sRomanSymbol, sSwissSymbol, sFixedSymbol,
        sNormalSymbol, sSlantSymbol, sItalicSymbol,
@@ -40,7 +42,7 @@ static VALUE
        /*  Data source for Table (= MyListCtrl)  */
        sOnCountSymbol, sOnGetValueSymbol, sOnSetValueSymbol, sOnSelectionChangedSymbol,
        sOnSetColorSymbol, sIsItemEditableSymbol, sIsDragAndDropEnabledSymbol, sOnDragSelectionToRowSymbol,
-       sSelectionSymbol, sColumnsSymbol, sRefreshSymbol, sHasPopUpMenu, sOnPopUpMenuSelected;
+       sSelectionSymbol, sColumnsSymbol, sRefreshSymbol, sHasPopUpMenuSymbol, sOnPopUpMenuSelectedSymbol;
 
 VALUE rb_cDialog = Qfalse;
 VALUE rb_cDialogItem = Qfalse;
@@ -107,7 +109,7 @@ s_RubyDialog_Alloc(VALUE klass)
 static VALUE
 s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val)
 {
-       int flag, itag;
+       int flag, itag, i;
        VALUE dialog_val, type;
        RubyDialog *dref;
        RDItem *view;
@@ -227,7 +229,6 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val)
                        rb_ivar_set(self, key_id, val);
                } else {
                        if (rb_obj_is_kind_of(val, rb_mEnumerable)) {
-                               int i;
                                for (i = 0; i < 6; i++) {
                                        VALUE gval = Ruby_ObjectAtIndex(val, i);
                                        if (RTEST(gval) && NUM2INT(rb_Integer(gval)) != 0)
@@ -240,8 +241,18 @@ s_RubyDialogItem_SetAttr(VALUE self, VALUE key, VALUE val)
                        }
                        rb_ivar_set(self, key_id, INT2NUM(flex));
                }
+       } else if (key == sForeColorSymbol || key == sBackColorSymbol) {
+               double col[4];
+               val = rb_ary_to_ary(val);
+               col[0] = col[1] = col[2] = col[3] = 1.0;
+               for (i = 0; i < 4 && i < RARRAY_LEN(val); i++)
+                       col[i] = NUM2DBL(rb_Float(RARRAY_PTR(val)[i]));
+               if (key == sForeColorSymbol)
+                       RubyDialogCallback_setForegroundColorForItem(view, col);
+               else
+                       RubyDialogCallback_setBackgroundColorForItem(view, col);
        } else if (key == sFontSymbol) {
-               int size, family, style, weight, i;
+               int size, family, style, weight;
                size = family = style = weight = 0;
                val = rb_ary_to_ary(val);
                for (i = 0; i < RARRAY_LEN(val); i++) {
@@ -457,6 +468,13 @@ s_RubyDialogItem_Attr(VALUE self, VALUE key)
                                rb_ary_push(val, ((flex & (1 << i)) ? INT2FIX(1) : INT2FIX(0)));
                        }
                }
+       } else if (key == sForeColorSymbol || key == sBackColorSymbol) {
+               double col[4];
+               if (key == sForeColorSymbol)
+                       RubyDialogCallback_getForegroundColorForItem(view, col);
+               else
+                       RubyDialogCallback_getBackgroundColorForItem(view, col);
+               val = rb_ary_new3(4, rb_float_new(col[0]), rb_float_new(col[1]), rb_float_new(col[2]), rb_float_new(col[3]));
        } else if (key == sFontSymbol) {
                int size, family, style, weight;
                VALUE fval, sval, wval;
@@ -544,6 +562,9 @@ s_RubyDialog_Initialize(int argc, VALUE *argv, VALUE self)
                optval = rb_hash_aref(val4, sResizableSymbol);
                if (RTEST(optval))
                        style |= rd_Resizable;
+               optval = rb_hash_aref(val4, sHasCloseBoxSymbol);
+               if (RTEST(optval))
+                       style |= rd_HasCloseBox;
        }
        
        di->dref = dref = RubyDialogCallback_new(style);
@@ -1379,6 +1400,26 @@ s_RubyDialog_StopTimer(VALUE self)
 
 /*
  *  call-seq:
+ *     on_key(action = nil)
+ *
+ *  Set keydown action method. When a keydown event occurs and no other controls
+ *  in this dialog accept the event, the action method (if non-nil) is invoked
+ *  with the keycode integer as the single argument. 
+ *  The action is either a symbol (method name) or a Proc object.
+ */
+static VALUE
+s_RubyDialog_OnKey(int argc, VALUE *argv, VALUE self)
+{
+       VALUE actval;
+       RubyDialog *dref = s_RubyDialog_GetController(self);
+       rb_scan_args(argc, argv, "01", &actval);
+       rb_iv_set(self, "_key_action", actval);
+       RubyDialogCallback_enableOnKeyHandler(dref, (actval != Qnil));
+       return self;
+}
+
+/*
+ *  call-seq:
  *     size -> [width, height]
  *
  *  Get the size for this dialog.
@@ -1675,7 +1716,7 @@ s_RubyDialog_doTableAction(VALUE val)
                }
                vp[7] = (void *)n;
                return retval;
-       } else if (sym == sHasPopUpMenu) {
+       } else if (sym == sHasPopUpMenuSymbol) {
                args[1] = INT2NUM((int)vp[3]);
                args[2] = INT2NUM((int)vp[4]);
                retval = s_RubyDialog_CallActionProc(self, pval, 3, args);
@@ -1695,7 +1736,7 @@ s_RubyDialog_doTableAction(VALUE val)
                        }
                }
                return retval;
-       } else if (sym == sOnPopUpMenuSelected) {
+       } else if (sym == sOnPopUpMenuSelectedSymbol) {
                args[1] = INT2NUM((int)vp[3]);
                args[2] = INT2NUM((int)vp[4]);
                args[3] = INT2NUM((int)vp[5]);
@@ -1801,7 +1842,7 @@ int
 RubyDialog_HasPopUpMenu(RubyValue self, RDItem *ip, int row, int column, char ***menu_titles)
 {
        int status;
-       void *vp[7] = { (void *)self, (void *)ip, (void *)sHasPopUpMenu, (void *)row, (void *)column, (void *)menu_titles, NULL };
+       void *vp[7] = { (void *)self, (void *)ip, (void *)sHasPopUpMenuSymbol, (void *)row, (void *)column, (void *)menu_titles, NULL };
        VALUE val = rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status);
        if (status != 0 || val == Qnil)
                return 0;
@@ -1812,7 +1853,7 @@ void
 RubyDialog_OnPopUpMenuSelected(RubyValue self, RDItem *ip, int row, int column, int selected_index)
 {
        int status;
-       void *vp[7] = { (void *)self, (void *)ip, (void *)sOnPopUpMenuSelected, (void *)row, (void *)column, (void *)selected_index, NULL };
+       void *vp[7] = { (void *)self, (void *)ip, (void *)sOnPopUpMenuSelectedSymbol, (void *)row, (void *)column, (void *)selected_index, NULL };
        rb_protect(s_RubyDialog_doTableAction, (VALUE)vp, &status);
        if (status != 0)
                Molby_showError(status);
@@ -1976,6 +2017,35 @@ RubyDialog_doTimerAction(RubyValue self)
 }
 
 static VALUE
+s_RubyDialog_doKeyAction(VALUE val)
+{
+       void **values = (void **)val;
+       VALUE self = (VALUE)values[0];
+       int keyCode = (int)values[1];
+       VALUE actval = rb_iv_get(self, "_key_action");
+       if (actval != Qnil) {
+               if (TYPE(actval) == T_SYMBOL)
+                       rb_funcall(self, SYM2ID(actval), 1, INT2NUM(keyCode));
+               else
+                       rb_funcall(actval, rb_intern("call"), 1, INT2NUM(keyCode));
+       }
+       return Qnil;
+}
+
+void
+RubyDialog_doKeyAction(RubyValue self, int keyCode)
+{
+       int status;
+       void *values[2];
+       values[0] = (void *)self;
+       values[1] = (void *)keyCode;
+       rb_protect(s_RubyDialog_doKeyAction, (VALUE)values, &status);
+       if (status != 0) {
+               Molby_showError(status);
+       }
+}
+
+static VALUE
 s_RubyDialog_getFlexFlags(VALUE val)
 {
        VALUE self = (VALUE)(((void **)val)[0]);
@@ -2010,6 +2080,23 @@ RubyDialog_getFlexFlags(RubyValue self, RDItem *ip)
        else return (int)args[2];
 }
 
+/*  Handle close box.  Invokes Dialog.end_modal or Dialog.hide in Ruby world  */
+void
+RubyDialog_doCloseWindow(RubyValue self, int isModal)
+{
+       int status;
+       VALUE val;
+       if (isModal) {
+               val = INT2NUM(1);
+               Ruby_funcall2_protect((VALUE)self, rb_intern("end_modal"), 1, &val, &status);
+       } else {
+               Ruby_funcall2_protect((VALUE)self, rb_intern("hide"), 0, NULL, &status);
+       }
+       if (status != 0) {
+               Molby_showError(status);
+       }
+}
+
 #pragma mark ====== Initialize class ======
 
 void
@@ -2038,6 +2125,7 @@ RubyDialogInitClass(void)
        rb_define_method(rb_cDialog, "hide", s_RubyDialog_Hide, 0);
        rb_define_method(rb_cDialog, "start_timer", s_RubyDialog_StartTimer, -1);
        rb_define_method(rb_cDialog, "stop_timer", s_RubyDialog_StopTimer, 0);
+       rb_define_method(rb_cDialog, "on_key", s_RubyDialog_OnKey, -1);
        rb_define_method(rb_cDialog, "set_size", s_RubyDialog_SetSize, -1);
        rb_define_method(rb_cDialog, "size", s_RubyDialog_Size, 0);
        rb_define_method(rb_cDialog, "set_min_size", s_RubyDialog_SetMinSize, -1);
@@ -2058,7 +2146,8 @@ RubyDialogInitClass(void)
                        &sTextSymbol, &sTextFieldSymbol, &sRadioSymbol, &sButtonSymbol,
                        &sCheckBoxSymbol, &sToggleButtonSymbol, &sPopUpSymbol, &sTextViewSymbol,
                        &sViewSymbol, &sTableSymbol,
-                       &sResizableSymbol, &sDialogSymbol, &sIndexSymbol, &sLineSymbol, &sTagSymbol,
+                       &sResizableSymbol, &sHasCloseBoxSymbol,
+                       &sDialogSymbol, &sIndexSymbol, &sLineSymbol, &sTagSymbol,
                        &sTypeSymbol, &sTitleSymbol, &sXSymbol, &sYSymbol,
                        &sWidthSymbol, &sHeightSymbol, &sOriginSymbol, &sSizeSymbol,
                        &sFrameSymbol, &sEnabledSymbol, &sEditableSymbol, &sHiddenSymbol,
@@ -2067,18 +2156,20 @@ RubyDialogInitClass(void)
                        &sVerticalAlignSymbol, &sBottomSymbol, &sMarginSymbol, &sPaddingSymbol,
                        &sSubItemsSymbol, &sHFillSymbol, &sVFillSymbol, &sFlexSymbol,
                        &sIsProcessingActionSymbol,
+                       &sForeColorSymbol, &sBackColorSymbol,
                        &sFontSymbol, &sDefaultSymbol, &sRomanSymbol, &sSwissSymbol,
                        &sFixedSymbol, &sNormalSymbol, &sSlantSymbol, &sItalicSymbol,
                        &sMediumSymbol, &sBoldSymbol, &sLightSymbol,
                        &sOnCountSymbol, &sOnGetValueSymbol, &sOnSetValueSymbol, &sOnSelectionChangedSymbol,
                        &sOnSetColorSymbol, &sIsItemEditableSymbol, &sIsDragAndDropEnabledSymbol, &sOnDragSelectionToRowSymbol,
-                       &sSelectionSymbol, &sColumnsSymbol, &sRefreshSymbol, &sHasPopUpMenu, &sOnPopUpMenuSelected
+                       &sSelectionSymbol, &sColumnsSymbol, &sRefreshSymbol, &sHasPopUpMenuSymbol, &sOnPopUpMenuSelectedSymbol
                };
                static const char *sTable2[] = {
                        "text", "textfield", "radio", "button",
                        "checkbox", "togglebutton", "popup", "textview",
                        "view", "table",
-                       "resizable", "dialog", "index", "line", "tag",
+                       "resizable", "has_close_box",
+                       "dialog", "index", "line", "tag",
                        "type", "title", "x", "y",
                        "width", "height", "origin", "size",
                        "frame", "enabled", "editable", "hidden",
@@ -2087,6 +2178,7 @@ RubyDialogInitClass(void)
                        "vertical_align", "bottom", "margin", "padding",
                        "subitems", "hfill", "vfill", "flex",
                        "is_processing_action",
+                       "foreground_color", "background_color",
                        "font", "default", "roman", "swiss",
                        "fixed", "normal", "slant", "italic",
                        "medium", "bold", "light",
index 3acd0ca..4fc9ee8 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
 /*  Style of the dialog frame  */
 enum {
        rd_Resizable = 1,
+       rd_HasCloseBox = 2,
 };
 
 /*  True if y-coordinate grows from bottom to top (like Cocoa)  */
@@ -52,7 +53,9 @@ extern const RDRect gZeroRect;
 extern int RubyDialog_validateItemContent(RubyValue self, RDItem *ip, const char *s);
 extern void RubyDialog_doItemAction(RubyValue self, RDItem *ip);
 extern void RubyDialog_doTimerAction(RubyValue self);
+extern void RubyDialog_doKeyAction(RubyValue self, int keyCode);
 extern int RubyDialog_getFlexFlags(RubyValue self, RDItem *ip);
+extern void RubyDialog_doCloseWindow(RubyValue self, int isModal);
 
 extern int RubyDialog_GetTableItemCount(RubyValue self, RDItem *ip);
 extern void RubyDialog_GetTableItemText(RubyValue self, RDItem *ip, int row, int column, char *buf, int blen);
@@ -79,6 +82,8 @@ STUB void RubyDialogCallback_show(RubyDialog *dref);
 STUB void RubyDialogCallback_hide(RubyDialog *dref);
 STUB int RubyDialogCallback_startIntervalTimer(RubyDialog *dref, float interval);
 STUB void RubyDialogCallback_stopIntervalTimer(RubyDialog *dref);
+STUB void RubyDialogCallback_enableOnKeyHandler(RubyDialog *dref, int flag);
+
 STUB RDSize RubyDialogCallback_windowMinSize(RubyDialog *dref);
 STUB void RubyDialogCallback_setWindowMinSize(RubyDialog *dref, RDSize size);
 STUB RDSize RubyDialogCallback_windowSize(RubyDialog *dref);
@@ -115,6 +120,10 @@ STUB int RubyDialogCallback_isItemHidden(RDItem *item);
 STUB void RubyDialogCallback_setNeedsDisplay(RDItem *item, int flag);
 STUB void RubyDialogCallback_setFontForItem(RDItem *item, int size, int family, int style, int weight);
 STUB int RubyDialogCallback_getFontForItem(RDItem *item, int *size, int *family, int *style, int *weight);
+STUB void RubyDialogCallback_setForegroundColorForItem(RDItem *item, const double *col);
+STUB void RubyDialogCallback_setBackgroundColorForItem(RDItem *item, const double *col);
+STUB void RubyDialogCallback_getForegroundColorForItem(RDItem *item, double *col);
+STUB void RubyDialogCallback_getBackgroundColorForItem(RDItem *item, double *col);
 STUB int RubyDialogCallback_appendString(RDItem *item, const char *str);
 
 STUB int RubyDialogCallback_countSubItems(RDItem *item);
index 617b661..e0a4e49 100755 (executable)
@@ -41,6 +41,8 @@
 #include "wx/stdpaths.h"
 #include "wx/textfile.h"
 #include "wx/process.h"
+#include "wx/utils.h"
+#include "wx/sound.h"
 
 #include "MyApp.h"
 #include "MyDocument.h"
@@ -1667,12 +1669,13 @@ MyAppCallback_getTextWithPrompt(const char *prompt, char *buf, int bufsize)
        wxTextCtrl *tctrl;
        int retval;
        wxString pstr(prompt, WX_DEFAULT_CONV);
+       wxString defstr(buf, WX_DEFAULT_CONV);
        {       //  Vertical sizer containing [prompt, textbox, buttons]
                wxBoxSizer *sizer1;
                sizer1 = new wxBoxSizer(wxVERTICAL);
                stext = new wxStaticText(dialog, -1, pstr, wxDefaultPosition, wxSize(200, 22));
                sizer1->Add(stext, 0, wxEXPAND | wxALL, 6);
-               tctrl = new wxTextCtrl(dialog, -1, _T(""), wxDefaultPosition, wxSize(200, 22));
+               tctrl = new wxTextCtrl(dialog, -1, defstr, wxDefaultPosition, wxSize(200, 22));
                sizer1->Add(tctrl, 0, wxEXPAND | wxALL, 6);
                wxSizer *bsizer = dialog->CreateButtonSizer(wxOK | wxCANCEL);
                sizer1->Add(bsizer, 0, wxEXPAND | wxALL, 6);
@@ -1894,3 +1897,25 @@ void MyAppCallback_hideConsoleWindow(void)
        ConsoleFrame *frame = wxGetApp().GetConsoleFrame();
        frame->Hide();
 }
+
+void MyAppCallback_bell(void)
+{
+       wxBell();
+}
+
+int MyAppCallback_playSound(const char *filename, int flag)
+{
+       unsigned uflag = wxSOUND_SYNC;
+       if (flag == 1)
+               uflag = wxSOUND_ASYNC;
+       else if (flag == 3)
+               uflag = wxSOUND_ASYNC | wxSOUND_LOOP;
+       wxString fnamestr(filename, wxConvFile);
+       bool retval = wxSound::Play(fnamestr, uflag);
+       return retval;
+}
+
+void MyAppCallback_stopSound(void)
+{
+       wxSound::Stop();
+}
index 3073761..c7f65a4 100644 (file)
@@ -39,6 +39,8 @@ BEGIN_EVENT_TABLE(RubyDialogFrame, wxDialog)
   EVT_BUTTON(wxID_OK, RubyDialogFrame::OnDefaultButtonPressed)
   EVT_BUTTON(wxID_CANCEL, RubyDialogFrame::OnDefaultButtonPressed)
   EVT_SIZE(RubyDialogFrame::OnSize)
+  EVT_CHAR(RubyDialogFrame::OnChar)
+  EVT_CLOSE(RubyDialogFrame::OnCloseWindow)
 END_EVENT_TABLE()
 
 RubyDialogFrame::RubyDialogFrame(wxWindow* parent, wxWindowID wid, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
@@ -51,6 +53,7 @@ RubyDialogFrame::RubyDialogFrame(wxWindow* parent, wxWindowID wid, const wxStrin
        autoResizeEnabled = true;
        messageData = NULL;
        countMessageData = 0;
+       onKeyHandlerEnabled = false;
        
        //  Create a vertical box sizer that contains a panel containing all controls and a sizer containing
        //  OK/Cancel buttons
@@ -316,6 +319,23 @@ RubyDialogFrame::OnSize(wxSizeEvent &event)
        event.Skip();
 }
 
+void
+RubyDialogFrame::OnChar(wxKeyEvent &event)
+{
+
+       int code = event.GetKeyCode();
+       if (onKeyHandlerEnabled) {
+               RubyDialog_doKeyAction((RubyValue)dval, code);
+       } else
+               event.Skip();
+}
+
+void
+RubyDialogFrame::OnCloseWindow(wxCloseEvent &event)
+{
+       RubyDialog_doCloseWindow((RubyValue)dval, IsModal());
+}
+
 int
 RubyDialogFrame::ListenToObject(void *obj, const char *objtype, const char *msg, RubyValue oval, RubyValue pval)
 {
@@ -486,11 +506,12 @@ RubyDialogFrame::OnPopUpMenuSelected(MyListCtrl *ctrl, long row, long column, in
 RubyDialog *
 RubyDialogCallback_new(int style)
 {
-       /*  RubyDialogFrame should not have a close box  */
        RubyDialogFrame *dref;
        int fstyle = wxCAPTION | wxSYSTEM_MENU;
        if (style & rd_Resizable)
                fstyle |= wxRESIZE_BOX | wxRESIZE_BORDER;
+       if (style & rd_HasCloseBox)
+               fstyle |= wxCLOSE_BOX;
        dref = new RubyDialogFrame(GetMainFrame(), -1, _T("Ruby Dialog"), wxDefaultPosition, wxDefaultSize, fstyle);
        return (RubyDialog *)dref;
 }
@@ -567,6 +588,13 @@ RubyDialogCallback_stopIntervalTimer(RubyDialog *dref)
        ((RubyDialogFrame *)dref)->StopIntervalTimer();
 }
 
+void
+RubyDialogCallback_enableOnKeyHandler(RubyDialog *dref, int flag)
+{
+       ((RubyDialogFrame *)dref)->onKeyHandlerEnabled = (flag != 0);
+}
+
+
 static inline RDRect
 RDRectFromwxRect(const wxRect &frame)
 {
@@ -840,6 +868,8 @@ RubyDialogCallback_setStringToItem(RDItem *item, const char *s)
        wxString str(s, WX_DEFAULT_CONV);
        if (wxDynamicCast((wxWindow *)item, wxTextCtrl) != NULL) {
                ((wxTextCtrl *)item)->SetValue(str);
+       } else if (wxDynamicCast((wxWindow *)item, wxStaticText) != NULL) {
+               ((wxStaticText *)item)->SetLabel(str);
        }
 }
 
@@ -849,6 +879,8 @@ RubyDialogCallback_getStringFromItem(RDItem *item, char *buf, int bufsize)
        wxString str;
        if (wxDynamicCast((wxWindow *)item, wxTextCtrl) != NULL) {
                str = ((wxTextCtrl *)item)->GetValue();
+       } else if (wxDynamicCast((wxWindow *)item, wxStaticText) != NULL) {
+                       str = ((wxStaticText *)item)->GetLabel();
        } else {
                buf[0] = 0;
                return;
@@ -1042,6 +1074,40 @@ RubyDialogCallback_getFontForItem(RDItem *item, int *size, int *family, int *sty
        } else return 0;
 }
 
+void
+RubyDialogCallback_setForegroundColorForItem(RDItem *item, const double *col)
+{
+       wxColour wcol(col[0] * 255, col[1] * 255, col[2] * 255, col[3] * 255);
+       ((wxWindow *)item)->SetForegroundColour(wcol);
+}
+
+void
+RubyDialogCallback_setBackgroundColorForItem(RDItem *item, const double *col)
+{
+       wxColour wcol(col[0] * 255, col[1] * 255, col[2] * 255, col[3] * 255);
+       ((wxWindow *)item)->SetBackgroundColour(wcol);
+}
+
+void
+RubyDialogCallback_getForegroundColorForItem(RDItem *item, double *col)
+{
+       wxColour wcol = ((wxWindow *)item)->GetForegroundColour();
+       col[0] = wcol.Red() / 255.0;
+       col[1] = wcol.Green() / 255.0;
+       col[2] = wcol.Blue() / 255.0;
+       col[3] = wcol.Alpha() / 255.0;
+}
+
+void
+RubyDialogCallback_getBackgroundColorForItem(RDItem *item, double *col)
+{
+       wxColour wcol = ((wxWindow *)item)->GetBackgroundColour();
+       col[0] = wcol.Red() / 255.0;
+       col[1] = wcol.Green() / 255.0;
+       col[2] = wcol.Blue() / 255.0;
+       col[3] = wcol.Alpha() / 255.0;
+}
+
 int
 RubyDialogCallback_appendString(RDItem *item, const char *str)
 {
index d0a632e..5353e15 100644 (file)
@@ -45,6 +45,9 @@ public:
        void **messageData;
        Int countMessageData;
        
+       /*  On key handler (the handler is in the Ruby world)  */
+       bool onKeyHandlerEnabled;
+
        RubyDialogFrame(wxWindow* parent, wxWindowID wid, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE);
        virtual ~RubyDialogFrame();
 
@@ -68,6 +71,8 @@ public:
        void OnTimerEvent(wxTimerEvent &event);
        void OnDefaultButtonPressed(wxCommandEvent &event);
        void OnSize(wxSizeEvent &event);
+       void OnChar(wxKeyEvent &event);
+       void OnCloseWindow(wxCloseEvent &event);
 
        //  MyListCtrlDataSource methods
        virtual int GetItemCount(MyListCtrl *ctrl);