diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 09:42:12 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-06 09:42:12 +0000 |
commit | eb6571a860ff8c37c3583145be57287e8af97533 (patch) | |
tree | cd0a8b46f0b92608ec8997ca542d99029f28b1c5 /ext/tk/lib/tk | |
parent | d9034d23ce8dcb88f310a9e33b79379123c1f7fd (diff) |
* ext/tk/lib : improve framework of developping Tcl/Tk extension wrappers
* BWidget extension support on Ruby/Tk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk')
29 files changed, 241 insertions, 159 deletions
diff --git a/ext/tk/lib/tk/button.rb b/ext/tk/lib/tk/button.rb index 15e87c300d..407a47c400 100644 --- a/ext/tk/lib/tk/button.rb +++ b/ext/tk/lib/tk/button.rb @@ -8,14 +8,14 @@ class TkButton<TkLabel TkCommandNames = ['button'.freeze].freeze WidgetClassName = 'Button'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('button', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('button', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('button', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('button', @path) + # end + #end + #private :create_self def invoke _fromUTF8(tk_send_without_enc('invoke')) diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index 17a05c0ce1..0f3a4fc482 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -40,20 +40,21 @@ class TkCanvas<TkWindow TkcItem::CItemID_TBL.delete(@path) end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('canvas', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('canvas', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('canvas', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('canvas', @path) + # end + #end + #private :create_self def tagid(tag) if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag) tag.id else - tag + # tag + _get_eval_string(tag) end end private :tagid diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb index 056bf74c05..1db7b7b768 100644 --- a/ext/tk/lib/tk/canvastag.rb +++ b/ext/tk/lib/tk/canvastag.rb @@ -316,7 +316,8 @@ end class TkcGroup<TkcTag Tk_cGroup_ID = ['tkcg'.freeze, '00000'.taint].freeze - def create_self(parent, *args) + #def create_self(parent, *args) + def initialize(parent, *args) unless parent.kind_of?(TkCanvas) fail ArguemntError, "expect TkCanvas for 1st argument" end @@ -329,7 +330,7 @@ class TkcGroup<TkcTag Tk_cGroup_ID[1].succ! add(*args) if args != [] end - private :create_self + #private :create_self def include(*tags) for i in tags diff --git a/ext/tk/lib/tk/checkbutton.rb b/ext/tk/lib/tk/checkbutton.rb index a1ee5e8764..d76d99c0f2 100644 --- a/ext/tk/lib/tk/checkbutton.rb +++ b/ext/tk/lib/tk/checkbutton.rb @@ -8,14 +8,14 @@ class TkCheckButton<TkRadioButton TkCommandNames = ['checkbutton'.freeze].freeze WidgetClassName = 'Checkbutton'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('checkbutton', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('checkbutton', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('checkbutton', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('checkbutton', @path) + # end + #end + #private :create_self def toggle tk_send_without_enc('toggle') diff --git a/ext/tk/lib/tk/dialog.rb b/ext/tk/lib/tk/dialog.rb index 30521e126a..d6355f21c1 100644 --- a/ext/tk/lib/tk/dialog.rb +++ b/ext/tk/lib/tk/dialog.rb @@ -162,8 +162,11 @@ class TkDialog2 < TkWindow # @path+" "+@title+" {#{@message}} "+@bitmap+" "+ # String(default_button)+" "+@buttons.join(' ')+']}') Tk.ip_eval(@config) - @val = Tk.ip_eval('tk_dialog ' + @path + ' ' + @title + - ' {' + @message + '} ' + @bitmap + ' ' + + # @val = Tk.ip_eval('tk_dialog ' + @path + ' ' + @title + + # ' {' + @message + '} ' + @bitmap + ' ' + + # String(default_button) + ' ' + @buttons.join(' ')).to_i + @val = Tk.ip_eval(self.class::TkCommandNames[0] + ' ' + @path + ' ' + + @title + ' {' + @message + '} ' + @bitmap + ' ' + String(default_button) + ' ' + @buttons.join(' ')).to_i end diff --git a/ext/tk/lib/tk/entry.rb b/ext/tk/lib/tk/entry.rb index 2077c1e9e4..f125739417 100644 --- a/ext/tk/lib/tk/entry.rb +++ b/ext/tk/lib/tk/entry.rb @@ -16,14 +16,13 @@ class TkEntry<TkLabel WidgetClassName = 'Entry'.freeze WidgetClassNames[WidgetClassName] = self - - def create_self(keys) - tk_call_without_enc('entry', @path) - if keys and keys != None - configure(keys) - end - end - private :create_self + #def create_self(keys) + # tk_call_without_enc('entry', @path) + # if keys and keys != None + # configure(keys) + # end + #end + #private :create_self def bbox(index) list(tk_send_without_enc('bbox', index)) diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb index 4c6c0844b2..19fd9dbf00 100644 --- a/ext/tk/lib/tk/event.rb +++ b/ext/tk/lib/tk/event.rb @@ -117,9 +117,21 @@ module TkEvent # that is generated by _get_subst_key() or _get_all_subst_keys(). # _setup_subst_table(KEY_TBL, PROC_TBL); + + + # If you need support extra arguments given by Tcl/Tk, + # please override _get_extra_args_tbl + # + #def self._get_extra_args_tbl + # # return an array of convert procs + # [] + #end + end def install_bind_for_event_class(klass, cmd, *args) + extra_args_tbl = klass._get_extra_args_tbl + if args.compact.size > 0 args = args.join(' ') keys = klass._get_subst_key(args) @@ -130,7 +142,9 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, *klass.scan_args(keys, arg)) + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} + TkUtil.eval_cmd(cmd, *(ex_args.concat(klass.scan_args(keys, arg)))) }) end id + ' ' + args @@ -143,7 +157,10 @@ module TkEvent id = install_cmd(cmd) else id = install_cmd(proc{|*arg| - TkUtil.eval_cmd(cmd, klass.new(*klass.scan_args(keys, arg))) + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} + TkUtil.eval_cmd(cmd, + *(ex_args << klass.new(*klass.scan_args(keys, arg)))) }) end id + ' ' + args @@ -151,7 +168,7 @@ module TkEvent end def install_bind(cmd, *args) - install_bind_for_event_class(Event, cmd, *args) + install_bind_for_event_class(TkEvent::Event, cmd, *args) end end diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb index b4c5c79213..527584f1ed 100644 --- a/ext/tk/lib/tk/font.rb +++ b/ext/tk/lib/tk/font.rb @@ -197,7 +197,7 @@ class TkFont def TkFont.init_widget_font(pathname, *args) win, tag, key = pathname.split(';') - key = 'font' unless key + key = 'font' if key == nil || key == '' path = [win, tag, key].join(';') case (Tk::TK_VERSION) @@ -868,7 +868,7 @@ class TkFont begin if w.include?(';') win, tag, optkey = w.split(';') - optkey = 'font' unless optkey + optkey = 'font' if optkey == nil || optkey == '' winobj = tk_tcl2ruby(win) # winobj.tagfont_configure(tag, {'font'=>@latinfont}) if winobj.kind_of? TkText diff --git a/ext/tk/lib/tk/frame.rb b/ext/tk/lib/tk/frame.rb index 6598ceb55c..4f01825da9 100644 --- a/ext/tk/lib/tk/frame.rb +++ b/ext/tk/lib/tk/frame.rb @@ -32,7 +32,7 @@ class TkFrame<TkWindow def initialize(parent=nil, keys=nil) my_class_name = nil - if self.class < WidgetClassNames[WidgetClassName] + if self.class < WidgetClassNames[self.class::WidgetClassName] my_class_name = self.class.name my_class_name = nil if my_class_name == '' end @@ -68,14 +68,14 @@ class TkFrame<TkWindow super(keys) end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('frame', @path, *hash_kv(keys)) - else - tk_call_without_enc( 'frame', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('frame', @path, *hash_kv(keys)) + # else + # tk_call_without_enc( 'frame', @path) + # end + #end + #private :create_self def database_classname @classname diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb index b1cc776748..2714500419 100644 --- a/ext/tk/lib/tk/itemconfig.rb +++ b/ext/tk/lib/tk/itemconfig.rb @@ -105,6 +105,13 @@ module TkItemConfigMethod ################################################ + def tagid(tagOrId) + # maybe need to override + tagOrId + end + + ################################################ + def itemcget(tagOrId, option) option = option.to_s diff --git a/ext/tk/lib/tk/itemfont.rb b/ext/tk/lib/tk/itemfont.rb index f653755b06..f194595d57 100644 --- a/ext/tk/lib/tk/itemfont.rb +++ b/ext/tk/lib/tk/itemfont.rb @@ -28,7 +28,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') if key pathname = [win, tag, key].join(';') @@ -130,7 +130,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') optkeys = [key] if key @@ -181,7 +181,7 @@ module TkTreatItemFont fail ArgumentError, "unknown font option name `#{key}'" end - win, tag = __item_pathname(tagid(tagOrId)).split(':') + win, tag = __item_pathname(tagid(tagOrId)).split(';') optkeys = [key] if key diff --git a/ext/tk/lib/tk/label.rb b/ext/tk/lib/tk/label.rb index fe2640958d..ea669d576e 100644 --- a/ext/tk/lib/tk/label.rb +++ b/ext/tk/lib/tk/label.rb @@ -7,14 +7,14 @@ class TkLabel<TkWindow TkCommandNames = ['label'.freeze].freeze WidgetClassName = 'Label'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('label', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('label', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('label', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('label', @path) + # end + #end + #private :create_self def textvariable(v) configure 'textvariable', tk_trace_variable(v) diff --git a/ext/tk/lib/tk/labelframe.rb b/ext/tk/lib/tk/labelframe.rb index fa658848c8..fd16d3419d 100644 --- a/ext/tk/lib/tk/labelframe.rb +++ b/ext/tk/lib/tk/labelframe.rb @@ -8,13 +8,13 @@ class TkLabelFrame<TkFrame TkCommandNames = ['labelframe'.freeze].freeze WidgetClassName = 'Labelframe'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('labelframe', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('labelframe', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('labelframe', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('labelframe', @path) + # end + #end + #private :create_self end TkLabelframe = TkLabelFrame diff --git a/ext/tk/lib/tk/listbox.rb b/ext/tk/lib/tk/listbox.rb index 799d573b1d..70df0ad685 100644 --- a/ext/tk/lib/tk/listbox.rb +++ b/ext/tk/lib/tk/listbox.rb @@ -23,17 +23,18 @@ class TkListbox<TkTextWin WidgetClassName = 'Listbox'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('listbox', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('listbox', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('listbox', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('listbox', @path) + # end + #end + #private :create_self def tagid(id) - id.to_s + #id.to_s + _get_eval_string(id) end def activate(y) diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index f5a16cf3cf..fdb4ec201b 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -38,17 +38,18 @@ class TkMenu<TkWindow WidgetClassName = 'Menu'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('menu', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('menu', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('menu', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('menu', @path) + # end + #end + #private :create_self def tagid(id) - id.to_s + #id.to_s + _get_eval_string(id) end def activate(index) diff --git a/ext/tk/lib/tk/message.rb b/ext/tk/lib/tk/message.rb index b359800142..79121bebb3 100644 --- a/ext/tk/lib/tk/message.rb +++ b/ext/tk/lib/tk/message.rb @@ -8,12 +8,12 @@ class TkMessage<TkLabel TkCommandNames = ['message'.freeze].freeze WidgetClassName = 'Message'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('message', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('message', @path) - end - end + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('message', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('message', @path) + # end + #end private :create_self end diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb index 46d17a2020..db735d929a 100644 --- a/ext/tk/lib/tk/optiondb.rb +++ b/ext/tk/lib/tk/optiondb.rb @@ -34,7 +34,8 @@ module TkOptionDB def readfile(file, pri=None) tk_call('option', 'readfile', file, pri) end - module_function :add, :clear, :get, :readfile + alias read_file readfile + module_function :add, :clear, :get, :readfile, :read_file def read_entries(file, f_enc=nil) if TkCore::INTERP.safe? diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb index 1cfc7bad7a..1e0430b606 100644 --- a/ext/tk/lib/tk/panedwindow.rb +++ b/ext/tk/lib/tk/panedwindow.rb @@ -7,14 +7,14 @@ class TkPanedWindow<TkWindow TkCommandNames = ['panedwindow'.freeze].freeze WidgetClassName = 'Panedwindow'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('panedwindow', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('panedwindow', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('panedwindow', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('panedwindow', @path) + # end + #end + #private :create_self def add(*args) keys = args.pop diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb index e00f0a03eb..697c021283 100644 --- a/ext/tk/lib/tk/radiobutton.rb +++ b/ext/tk/lib/tk/radiobutton.rb @@ -8,14 +8,14 @@ class TkRadioButton<TkButton TkCommandNames = ['radiobutton'.freeze].freeze WidgetClassName = 'Radiobutton'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - if keys and keys != None - tk_call_without_enc('radiobutton', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('radiobutton', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('radiobutton', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('radiobutton', @path) + # end + #end + #private :create_self def deselect tk_send_without_enc('deselect') diff --git a/ext/tk/lib/tk/scale.rb b/ext/tk/lib/tk/scale.rb index 9398a6cd52..135a0cf62d 100644 --- a/ext/tk/lib/tk/scale.rb +++ b/ext/tk/lib/tk/scale.rb @@ -10,13 +10,16 @@ class TkScale<TkWindow def create_self(keys) if keys and keys != None - if keys.key?('command') + if keys.key?('command') && ! keys['command'].kind_of?(String) cmd = keys.delete('command') keys['command'] = proc{|val| cmd.call(val.to_f)} end - tk_call_without_enc('scale', @path, *hash_kv(keys, true)) + #tk_call_without_enc('scale', @path, *hash_kv(keys, true)) + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) else - tk_call_without_enc('scale', @path) + #tk_call_without_enc('scale', @path) + tk_call_without_enc(self.class::TkCommandNames[0], @path) end end private :create_self diff --git a/ext/tk/lib/tk/scrollable.rb b/ext/tk/lib/tk/scrollable.rb index c5f4fdb70c..6e10ef51a2 100644 --- a/ext/tk/lib/tk/scrollable.rb +++ b/ext/tk/lib/tk/scrollable.rb @@ -52,8 +52,8 @@ module Tk @xscrollbar.orient 'horizontal' self.xscrollcommand {|*arg| @xscrollbar.set(*arg)} @xscrollbar.command {|*arg| self.xview(*arg)} + Tk.update # avoid scrollbar trouble end - Tk.update # avoid scrollbar trouble @xscrollbar end def yscrollbar(bar=nil) @@ -62,8 +62,8 @@ module Tk @yscrollbar.orient 'vertical' self.yscrollcommand {|*arg| @yscrollbar.set(*arg)} @yscrollbar.command {|*arg| self.yview(*arg)} + Tk.update # avoid scrollbar trouble end - Tk.update # avoid scrollbar trouble @yscrollbar end end diff --git a/ext/tk/lib/tk/scrollbar.rb b/ext/tk/lib/tk/scrollbar.rb index 8d4d40322d..98b0247207 100644 --- a/ext/tk/lib/tk/scrollbar.rb +++ b/ext/tk/lib/tk/scrollbar.rb @@ -19,9 +19,12 @@ class TkScrollbar<TkWindow } if keys and keys != None - tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true)) + #tk_call_without_enc('scrollbar', @path, *hash_kv(keys, true)) + tk_call_without_enc(self.class::TkCommandNames[0], @path, + *hash_kv(keys, true)) else - tk_call_without_enc('scrollbar', @path) + #tk_call_without_enc('scrollbar', @path) + tk_call_without_enc(self.class::TkCommandNames[0], @path) end end private :create_self diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb index 1c58f9199b..664df61755 100644 --- a/ext/tk/lib/tk/spinbox.rb +++ b/ext/tk/lib/tk/spinbox.rb @@ -11,13 +11,13 @@ class TkSpinbox<TkEntry WidgetClassName = 'Spinbox'.freeze WidgetClassNames[WidgetClassName] = self - def create_self(keys) - tk_call_without_enc('spinbox', @path) - if keys and keys != None - configure(keys) - end - end - private :create_self + #def create_self(keys) + # tk_call_without_enc('spinbox', @path) + # if keys and keys != None + # configure(keys) + # end + #end + #private :create_self def identify(x, y) tk_send_without_enc('identify', x, y) diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index 7593b59368..b992db5ff0 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -88,11 +88,15 @@ class TkText<TkTextWin end def create_self(keys) - if keys and keys != None - tk_call_without_enc('text', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('text', @path) - end + #if keys and keys != None + # #tk_call_without_enc('text', @path, *hash_kv(keys, true)) + # tk_call_without_enc(self.class::TkCommandNames[0], @path, + # *hash_kv(keys, true)) + #else + # #tk_call_without_enc('text', @path) + # tk_call_without_enc(self.class::TkCommandNames[0], @path) + #end + super(keys) init_instance_variable end private :create_self @@ -131,7 +135,8 @@ class TkText<TkTextWin || tag.kind_of?(TkTextWindow) tag.id else - tag + # tag + _get_eval_string(tag) end end private :tagid diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index c95002dbeb..1984952248 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -158,14 +158,14 @@ class TkToplevel<TkWindow } end - def create_self(keys) - if keys and keys != None - tk_call_without_enc('toplevel', @path, *hash_kv(keys, true)) - else - tk_call_without_enc('toplevel', @path) - end - end - private :create_self + #def create_self(keys) + # if keys and keys != None + # tk_call_without_enc('toplevel', @path, *hash_kv(keys, true)) + # else + # tk_call_without_enc('toplevel', @path) + # end + #end + #private :create_self def specific_class @classname diff --git a/ext/tk/lib/tk/txtwin_abst.rb b/ext/tk/lib/tk/txtwin_abst.rb index 63da9da11d..5520360eab 100644 --- a/ext/tk/lib/tk/txtwin_abst.rb +++ b/ext/tk/lib/tk/txtwin_abst.rb @@ -4,10 +4,11 @@ require 'tk' class TkTextWin<TkWindow - def create_self - fail RuntimeError, "TkTextWin is an abstract class" - end - private :create_self + TkCommnadNames = [].freeze + #def create_self + # fail RuntimeError, "TkTextWin is an abstract class" + #end + #private :create_self def bbox(index) list(tk_send_without_enc('bbox', index)) diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index 0524a43757..30111f20cc 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -158,6 +158,15 @@ module TkValidation ] _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + (val)? '1': '0' + end + + #def self._get_extra_args_tbl + # # return an array of convert procs + # [] + #end end ############################## @@ -168,6 +177,8 @@ module TkValidation end def _initialize_for_cb_class(klass, cmd = Proc.new, *args) + extra_args_tbl = klass._get_extra_args_tbl + if args.compact.size > 0 args = args.join(' ') keys = klass._get_subst_key(args) @@ -177,7 +188,11 @@ module TkValidation @id = install_cmd(cmd) else @id = install_cmd(proc{|*arg| - (cmd.call(*klass.scan_args(keys, arg)))? '1':'0' + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + klass.ret_val(cmd.call( + *(ex_args.concat(klass.scan_args(keys, arg))) + )) }) + ' ' + args end else @@ -188,9 +203,11 @@ module TkValidation @id = install_cmd(cmd) else @id = install_cmd(proc{|*arg| - (cmd.call( - klass.new(*klass.scan_args(keys,arg))) - )? '1': '0' + ex_args = [] + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + klass.ret_val(cmd.call( + *(ex_args << klass.new(*klass.scan_args(keys,arg))) + )) }) + ' ' + args end end diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index 61d6e8a410..bfa19fc18d 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -197,8 +197,13 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') @id end + def ref(*idxs) + "#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})" + end + def is_hash? #ITNERP._eval("global #{@id}; array exist #{@id}") == '1' + INTERP._invoke_without_enc('global', @id) INTERP._invoke_without_enc('array', 'exist', @id) == '1' end @@ -211,6 +216,7 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') fail RuntimeError, 'cannot get keys from a scalar variable' end #tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}")) + INTERP._invoke_without_enc('global', @id) tk_split_simplelist(INTERP._fromUTF8(INTERP._invoke_without_enc('array', 'names', @id))) end @@ -242,6 +248,7 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS def value #if INTERP._eval("global #{@id}; array exist #{@id}") == '1' + INTERP._invoke_without_enc('global', @id) if INTERP._invoke('array', 'exist', @id) == '1' #Hash[*tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}"))] Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', @id))] @@ -277,16 +284,21 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS end end - def [](index) + def [](*idxs) + index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') + _fromUTF8(INTERP._get_global_var2(@id, index)) #_fromUTF8(INTERP._get_global_var2(@id, _toUTF8(_get_eval_string(index)))) - _fromUTF8(INTERP._get_global_var2(@id, _get_eval_string(index, true))) + #_fromUTF8(INTERP._get_global_var2(@id, _get_eval_string(index, true))) end - def []=(index,val) + def []=(*args) + val = args.pop + index = args.collect{|idx| _get_eval_string(idx, true)}.join(',') + _fromUTF8(INTERP._set_global_var2(@id, index, _get_eval_string(val, true))) #_fromUTF8(INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(index)), # _toUTF8(_get_eval_string(val)))) - _fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true), - _get_eval_string(val, true))) + #_fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true), + # _get_eval_string(val, true))) end def unset(elem=nil) @@ -371,16 +383,22 @@ else end end - def [](index) - INTERP._eval(Kernel.format('global %s; set %s(%s)', - @id, @id, _get_eval_string(index))) + def [](*idxs) + index = idxs.collect{|idx| _get_eval_string(idx)}.join(',') + INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) + #INTERP._eval(Kernel.format('global %s; set %s(%s)', + # @id, @id, _get_eval_string(index))) #INTERP._eval(Kernel.format('set %s(%s)', @id, _get_eval_string(index))) #INTERP._eval('set ' + @id + '(' + _get_eval_string(index) + ')') end - def []=(index,val) + def []=(*args) + val = args.pop + index = args.collect{|idx| _get_eval_string(idx)}.join(',') INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id, - _get_eval_string(index), _get_eval_string(val))) + index, _get_eval_string(val))) + #INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id, + # _get_eval_string(index), _get_eval_string(val))) #INTERP._eval(Kernel.format('set %s(%s) %s', @id, # _get_eval_string(index), _get_eval_string(val))) #INTERP._eval('set ' + @id + '(' + _get_eval_string(index) + ') ' + @@ -869,6 +887,7 @@ class TkVarAccess<TkVariable def self.new_hash(name, *args) return TkVar_ID_TBL[name] if TkVar_ID_TBL[name] + INTERP._invoke_without_enc('global', name) if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0' self.new(name, {}) # force creating else diff --git a/ext/tk/lib/tk/wm.rb b/ext/tk/lib/tk/wm.rb index 2467656837..b5106adade 100644 --- a/ext/tk/lib/tk/wm.rb +++ b/ext/tk/lib/tk/wm.rb @@ -178,10 +178,13 @@ module Tk self end end - def protocol(name=nil, cmd=nil) + def protocol(name=nil, cmd=nil, &b) if cmd tk_call_without_enc('wm', 'protocol', path, name, cmd) self + elsif b + tk_call_without_enc('wm', 'protocol', path, name, proc(&b)) + self elsif name result = tk_call_without_enc('wm', 'protocol', path, name) (result == "")? nil : tk_tcl2ruby(result) |