diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-09 06:16:04 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-09 06:16:04 +0000 |
commit | fca9326807d7ae597339b2408731b7e82770d8c5 (patch) | |
tree | eb8599229fa4760275fe10fee50ba817d01df64f /ext/tk/lib/tk | |
parent | 3757005cec2e512c35c4be383be76091048d08cc (diff) |
* ext/tcltklib/tcltklib.c: remove dangerous 'rb_jump_tag's.
* ext/tk/lib/tk.rb: add __val2ruby_optkeys and __ruby2val_optkeys to
help to convert option values between ruby and tcl.
* ext/tk/lib/tk/itemconfig.rb: add __item_val2ruby_optkeys and
__item_ruby2val_optkeys to help to convert option values between
ruby and tcl.
* ext/tk/lib/tk/radiobutton.rb: use __ruby2val_optkeys for 'variable'
option (for the reason of backward compatibility).
* ext/tk/lib/tk/composite.rb: clarify the arguments of super().
* ext/tk/lib/tk/spinbox.rb: ditto.
* ext/tk/lib/tk/text.rb: ditto.
* ext/tk/lib/tk/validation.rb: ditto.
* ext/tk/lib/tkextlib/*: support to treat tkvariable-type
configure options.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk')
-rw-r--r-- | ext/tk/lib/tk/composite.rb | 12 | ||||
-rw-r--r-- | ext/tk/lib/tk/itemconfig.rb | 144 | ||||
-rw-r--r-- | ext/tk/lib/tk/radiobutton.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/tk/spinbox.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/text.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/tk/validation.rb | 2 |
6 files changed, 160 insertions, 16 deletions
diff --git a/ext/tk/lib/tk/composite.rb b/ext/tk/lib/tk/composite.rb index d85b815dd7..58cca736db 100644 --- a/ext/tk/lib/tk/composite.rb +++ b/ext/tk/lib/tk/composite.rb @@ -97,7 +97,7 @@ module TkComposite rescue end - super + super(slot) end def configure(slot, value=None) @@ -134,7 +134,7 @@ module TkComposite rescue end - super + super(slot, value) end def configinfo(slot = nil) @@ -171,10 +171,10 @@ module TkComposite rescue end - super + super(slot) else # slot == nil - info_list = super + info_list = super(slot) tbl = @delegates['DEFAULT'] if tbl @@ -250,10 +250,10 @@ module TkComposite rescue end - super + super(slot) else # slot == nil - info_list = super + info_list = super(slot) tbl = @delegates['DEFAULT'] if tbl diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb index f6cfc0b524..d52f959d95 100644 --- a/ext/tk/lib/tk/itemconfig.rb +++ b/ext/tk/lib/tk/itemconfig.rb @@ -40,12 +40,30 @@ module TkItemConfigOptkeys end private :__item_numlistval_optkeys - def __item_tkvariable_optkeys - ['variable'] + def __item_tkvariable_optkeys(id) + ['variable', 'textvariable'] end private :__item_tkvariable_optkeys + def __item_val2ruby_optkeys(id) # { key=>method, ... } + # The method is used to convert a opt-value to a ruby's object. + # When get the value of the option "key", "method.call(id, val)" is called. + {} + end + private :__item_val2ruby_optkeys + + def __item_ruby2val_optkeys(id) # { key=>method, ... } + # The method is used to convert a ruby's object to a opt-value. + # When set the value of the option "key", "method.call(id, val)" is called. + # That is, "-#{key} #{method.call(id, value)}". + {} + end + private :__item_ruby2val_optkeys + def __item_methodcall_optkeys(id) # { key=>method, ... } + # Use the method for both of get and set. + # Usually, the 'key' will not be a widget option. + # # maybe need to override # {'coords'=>'coords'} {} @@ -133,6 +151,16 @@ module TkItemConfigMethod fail ArgumentError, "Invalid option `#{orig_opt.inspect}'" end + if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] ) + optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}")) + begin + return method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + return optval + end + end + if ( method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[option] ) return self.__send__(method, tagOrId) end @@ -200,6 +228,12 @@ module TkItemConfigMethod self.__send__(method, tagOrId, value) if value } + __item_ruby2val_optkeys(tagid(tagOrId)).each{|key, method| + key = key.to_s + value = slot[key] + slot[key] = method.call(tagOrId, value) if value + } + __item_keyonly_optkeys(tagid(tagOrId)).each{|defkey, undefkey| conf = slot.find{|kk, vv| kk == defkey.to_s} if conf @@ -233,6 +267,8 @@ module TkItemConfigMethod elsif undefkey tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{undefkey}")) end + elsif ( method = _symbolkey2str(__item_ruby2val_optkeys(tagid(tagOrId)))[slot] ) + method.call(tagOrId, value) elsif ( method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot] ) self.__send__(method, tagOrId, value) elsif (slot =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/) @@ -270,6 +306,31 @@ module TkItemConfigMethod if slot slot = slot.to_s case slot + when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ + method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] + conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true) + if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \ + && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val + end + if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}lcall(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val + end + when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/ method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot] return [slot, '', '', '', self.__send__(method, tagOrId)] @@ -411,7 +472,32 @@ module TkItemConfigMethod conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1] - case conf[__item_configinfo_struct(tagid(tagOrId))[:key]] + optkey = conf[__item_configinfo_struct(tagid(tagOrId))[:key]] + case optkey + when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ + method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[optkey] + if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \ + && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] + begin + val = method(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val + end + if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val + end + when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/ # do nothing @@ -583,6 +669,31 @@ module TkItemConfigMethod if slot slot = slot.to_s case slot + when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ + method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot] + conf = tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")), false, true) + if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \ + && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val + end + if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val + end + when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/ method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot] return {slot => ['', '', '', self.__send__(method, tagOrId)]} @@ -727,7 +838,32 @@ module TkItemConfigMethod conf[__item_configinfo_struct(tagid(tagOrId))[:key]] = conf[__item_configinfo_struct(tagid(tagOrId))[:key]][1..-1] - case conf[__item_configinfo_struct(tagid(tagOrId))[:key]] + optkey = conf[__item_configinfo_struct(tagid(tagOrId))[:key]] + case optkey + when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/ + method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[optkey] + if ( __item_configinfo_struct(tagid(tagOrId))[:default_value] \ + && conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:default_value]] = val + end + if ( conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] ) + optval = conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] + begin + val = method.call(tagOrId, optval) + rescue => e + warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG + val = optval + end + conf[__item_configinfo_struct(tagid(tagOrId))[:current_value]] = val + end + when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/ # do nothing diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb index 6f7a5f60a0..d82aa5d07d 100644 --- a/ext/tk/lib/tk/radiobutton.rb +++ b/ext/tk/lib/tk/radiobutton.rb @@ -17,6 +17,14 @@ class TkRadioButton<TkButton #end #private :create_self + def __ruby2val_optkeys # { key=>proc, ... } + { + 'variable'=>proc{|v| tk_trace_variable(v)} # for backward compatibility + } + end + private :__ruby2val_optkeys + + def deselect tk_send_without_enc('deselect') self diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb index ac84e06cb3..8941510fed 100644 --- a/ext/tk/lib/tk/spinbox.rb +++ b/ext/tk/lib/tk/spinbox.rb @@ -51,7 +51,7 @@ class TkSpinbox<TkEntry end def __validation_class_list - super << SpinCommand + super() << SpinCommand end Tk::ValidateConfigure.__def_validcmd(binding, SpinCommand) diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index 39f5622886..f2bad37b01 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -460,13 +460,13 @@ class TkText<TkTextWin args << tags.shift.collect{|x|_get_eval_string(x)}.join(' ') # taglist args << tags.shift if tags.size > 0 # chars end - super index, *args + super(index, *args) else # single chars-taglist argument :: str, tag, tag, ... if tags.size == 0 - super index, chars + super(index, chars) else - super index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ') + super(index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ')) end end end @@ -476,7 +476,7 @@ class TkText<TkTextWin @tags.each_value do |t| t.destroy end - super + super() end def backspace diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index 6755eef05f..0c5b5c61b9 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -337,7 +337,7 @@ module TkValidation ##################################### def __validation_class_list - super << ValidateCmd + super() << ValidateCmd end Tk::ValidateConfigure.__def_validcmd(binding, ValidateCmd) |