diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-08 18:14:15 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-08 18:14:15 +0000 |
commit | 341f60d389acdb125fc7741e56cf66d84639e607 (patch) | |
tree | e4586165010be9bac4462f8c53f267c126cdd041 /ext/tk | |
parent | 686e28fcadf1e1674232579c01664165d8ecb062 (diff) | |
download | ruby-341f60d389acdb125fc7741e56cf66d84639e607.tar.gz ruby-341f60d389acdb125fc7741e56cf66d84639e607.tar.xz ruby-341f60d389acdb125fc7741e56cf66d84639e607.zip |
* ext/tcltklib/tcltklib.c (ip_init): set root-win title to "ruby" when
the running script is '-e one-liner' or '-' (stdin).
* ext/tcltklib/extconf.rb: add find_library("#{lib}#{ver}",..) for stub libs
* ext/tk/lib/tk/textmark.rb: TkTextMarkCurrent and TkTextMarkAnchor
have a wrong parent class.
* ext/tk/lib/tk/dialog.rb: rename TkDialog2 --> TkDialogObj and
TkWarning2 --> TkWarningObj (old names are changed to alias names)
* ext/tk/lib/tk/dialog.rb: bug fix of treatment of 'prev_command'
option and hashes for configuration
* ext/tk/lib/tk/dialog.rb: add TkDialogObj#name to return the button name
* ext/tk/lib/tk/radiobutton.rb: rename enbugged method value() ==> get_value()
and value=(val) ==> set_value(val).
* ext/tk/lib/tk/menu.rb: add TkMenu.new_menuspec
* ext/tk/lib/tk/menu.rb: add alias (TkMenuButton = TkMenubutton,
TkOptionMenuButton = TkOptionMenubutton)
* ext/tk/lib/tk/event.rb: new method aliases (same as option keys of
event_generate) for Event object
* ext/tk/lib/tk/font.rb: configinfo returns proper types of values
* ext/tk/lib/tk.rb: bind methods accept subst_args + block
* ext/tk/lib/tk/canvas.rb: ditto
* ext/tk/lib/tk/canvastag.rb: ditto
* ext/tk/lib/tk/frame.rb: ditto
* ext/tk/lib/tk/text.rb: ditto
* ext/tk/lib/tk/texttag.rb: ditto
* ext/tk/lib/tk/toplevel.rb: ditto
* ext/tk/lib/tkextlib/*: ditto and bug fix
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/lib/tk.rb | 64 | ||||
-rw-r--r-- | ext/tk/lib/tk/canvas.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/canvastag.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/dialog.rb | 49 | ||||
-rw-r--r-- | ext/tk/lib/tk/event.rb | 9 | ||||
-rw-r--r-- | ext/tk/lib/tk/font.rb | 143 | ||||
-rw-r--r-- | ext/tk/lib/tk/frame.rb | 12 | ||||
-rw-r--r-- | ext/tk/lib/tk/menu.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/radiobutton.rb | 4 | ||||
-rw-r--r-- | ext/tk/lib/tk/text.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/textmark.rb | 4 | ||||
-rw-r--r-- | ext/tk/lib/tk/texttag.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tk/toplevel.rb | 12 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/bwidget/labelentry.rb | 26 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/bwidget/listbox.rb | 56 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/bwidget/notebook.rb | 38 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/bwidget/spinbox.rb | 26 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/bwidget/tree.rb | 56 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/itk/incr_tk.rb | 44 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tkDND/tkdnd.rb | 39 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 27 |
22 files changed, 626 insertions, 115 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 9081eb993..3a8690305 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -901,12 +901,30 @@ module TkComm :_bind_append_for_event_class, :_bind_remove_for_event_class, :_bindinfo_for_event_class - def bind(tagOrClass, context, cmd=Proc.new, *args) + #def bind(tagOrClass, context, cmd=Proc.new, *args) + # _bind(["bind", tagOrClass], context, cmd, *args) + # tagOrClass + #end + def bind(tagOrClass, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind(["bind", tagOrClass], context, cmd, *args) tagOrClass end - def bind_append(tagOrClass, context, cmd=Proc.new, *args) + #def bind_append(tagOrClass, context, cmd=Proc.new, *args) + # _bind_append(["bind", tagOrClass], context, cmd, *args) + # tagOrClass + #end + def bind_append(tagOrClass, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append(["bind", tagOrClass], context, cmd, *args) tagOrClass end @@ -920,12 +938,30 @@ module TkComm _bindinfo(['bind', tagOrClass], context) end - def bind_all(context, cmd=Proc.new, *args) + #def bind_all(context, cmd=Proc.new, *args) + # _bind(['bind', 'all'], context, cmd, *args) + # TkBindTag::ALL + #end + def bind_all(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind(['bind', 'all'], context, cmd, *args) TkBindTag::ALL end - def bind_append_all(context, cmd=Proc.new, *args) + #def bind_append_all(context, cmd=Proc.new, *args) + # _bind_append(['bind', 'all'], context, cmd, *args) + # TkBindTag::ALL + #end + def bind_append_all(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append(['bind', 'all'], context, cmd, *args) TkBindTag::ALL end @@ -2067,11 +2103,27 @@ end module TkBindCore - def bind(context, cmd=Proc.new, *args) + #def bind(context, cmd=Proc.new, *args) + # Tk.bind(self, context, cmd, *args) + #end + def bind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end Tk.bind(self, context, cmd, *args) end - def bind_append(context, cmd=Proc.new, *args) + #def bind_append(context, cmd=Proc.new, *args) + # Tk.bind_append(self, context, cmd, *args) + #end + def bind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end Tk.bind_append(self, context, cmd, *args) end diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index 9a042155e..3bc08e94f 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -94,12 +94,30 @@ class TkCanvas<TkWindow *tags.collect{|t| tagid(t)})) end - def itembind(tag, context, cmd=Proc.new, *args) + #def itembind(tag, context, cmd=Proc.new, *args) + # _bind([path, "bind", tagid(tag)], context, cmd, *args) + # self + #end + def itembind(tag, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([path, "bind", tagid(tag)], context, cmd, *args) self end - def itembind_append(tag, context, cmd=Proc.new, *args) + #def itembind_append(tag, context, cmd=Proc.new, *args) + # _bind_append([path, "bind", tagid(tag)], context, cmd, *args) + # self + #end + def itembind_append(tag, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append([path, "bind", tagid(tag)], context, cmd, *args) self end diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb index 3d5c6703d..5d1d5e92a 100644 --- a/ext/tk/lib/tk/canvastag.rb +++ b/ext/tk/lib/tk/canvastag.rb @@ -21,12 +21,30 @@ module TkcTagAccess @c.bbox(@id) end - def bind(seq, cmd=Proc.new, *args) + #def bind(seq, cmd=Proc.new, *args) + # @c.itembind(@id, seq, cmd, *args) + # self + #end + def bind(seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end @c.itembind(@id, seq, cmd, *args) self end - def bind_append(seq, cmd=Proc.new, *args) + #def bind_append(seq, cmd=Proc.new, *args) + # @c.itembind_append(@id, seq, cmd, *args) + # self + #end + def bind_append(seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end @c.itembind_append(@id, seq, cmd, *args) self end diff --git a/ext/tk/lib/tk/dialog.rb b/ext/tk/lib/tk/dialog.rb index 2ced26b19..f7d17b5a9 100644 --- a/ext/tk/lib/tk/dialog.rb +++ b/ext/tk/lib/tk/dialog.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkDialog2 < TkWindow +class TkDialogObj < TkWindow extend Tk TkCommandNames = ['tk_dialog'.freeze].freeze @@ -23,7 +23,9 @@ class TkDialog2 < TkWindow c.delete('command'); c.delete(:command) # @config << Kernel.format("%s.button%s configure %s; ", # @path, i, hash_kv(c).join(' ')) - @config << @path+'.button'+i.to_s+'configure '+hash_kv(c).join(' ')+'; ' + # @config << @path+'.button'+i.to_s+' configure '+hash_kv(c).join(' ')+'; ' + @config << @path+'.button'+i.to_s+' configure '+ + array2tk_list(hash_kv(c))+'; ' } case configs when Proc @@ -74,7 +76,7 @@ class TkDialog2 < TkWindow #@config = "puts [winfo children .w0000];" @config = "" - @command = nil + @command = prev_command if keys.kind_of? Hash @title = keys['title'] if keys.key? 'title' @@ -84,7 +86,7 @@ class TkDialog2 < TkWindow @default_button = keys['default'] if keys.key? 'default' @buttons = keys['buttons'] if keys.key? 'buttons' - @command = keys['prev_command'] + @command = keys['prev_command'] if keys.key? 'prev_command' @message_config = keys['message_config'] if keys.key? 'message_config' @msgframe_config = keys['msgframe_config'] if keys.key? 'msgframe_config' @@ -121,36 +123,44 @@ class TkDialog2 < TkWindow if @message_config.kind_of? Hash # @config << Kernel.format("%s.msg configure %s;", # @path, hash_kv(@message_config).join(' ')) - @config << @path+'.msg configure '+hash_kv(@message_config).join(' ')+';' + # @config << @path+'.msg configure '+hash_kv(@message_config).join(' ')+';' + @config << @path+'.msg configure '+ + array2tk_list(hash_kv(@message_config))+';' end if @msgframe_config.kind_of? Hash # @config << Kernel.format("%s.top configure %s;", # @path, hash_kv(@msgframe_config).join(' ')) - @config << @path+'.top configure '+hash_kv(@msgframe_config).join(' ')+';' + # @config << @path+'.top configure '+hash_kv(@msgframe_config).join(' ')+';' + @config << @path+'.top configure '+ + array2tk_list(hash_kv(@msgframe_config))+';' end if @btnframe_config.kind_of? Hash # @config << Kernel.format("%s.bot configure %s;", # @path, hash_kv(@btnframe_config).join(' ')) - @config << @path+'.bot configure '+hash_kv(@btnframe_config).join(' ')+';' + # @config << @path+'.bot configure '+hash_kv(@btnframe_config).join(' ')+';' + @config << @path+'.bot configure '+ + array2tk_list(hash_kv(@btnframe_config))+';' end if @bitmap_config.kind_of? Hash # @config << Kernel.format("%s.bitmap configure %s;", # @path, hash_kv(@bitmap_config).join(' ')) - @config << @path+'.bitmap configure '+hash_kv(@bitmap_config).join(' ')+';' + # @config << @path+'.bitmap configure '+hash_kv(@bitmap_config).join(' ')+';' + @config << @path+'.bitmap configure '+ + array2tk_list(hash_kv(@bitmap_config))+';' end _set_button_config(@button_configs) if @button_configs + end + private :create_self + def show if @command.kind_of? Proc @command.call(self) end - end - private :create_self - def show if @default_button.kind_of? String default_button = @buttons.index(@default_button) else @@ -174,6 +184,10 @@ class TkDialog2 < TkWindow # @var.value.to_i @val end + + def name + @buttons[@val] + end ###################################################### # # # these methods must be overridden for each dialog # @@ -223,13 +237,17 @@ class TkDialog2 < TkWindow # returns nil or a Hash {option=>value, ...} for the button frame return nil end + def prev_command + # returns nil or a Proc + return nil + end end - +TkDialog2 = TkDialogObj # # TkDialog : with showing at initialize # -class TkDialog < TkDialog2 +class TkDialog < TkDialogObj def self.show(*args) self.new(*args) end @@ -244,7 +262,7 @@ end # # dialog for warning # -class TkWarning2 < TkDialog2 +class TkWarningObj < TkDialogObj def initialize(parent = nil, mes = nil) if !mes if parent.kind_of? TkWindow @@ -281,8 +299,9 @@ class TkWarning2 < TkDialog2 return "OK"; end end +TkWarning2 = TkWarningObj -class TkWarning < TkWarning2 +class TkWarning < TkWarningObj def self.show(*args) self.new(*args) end diff --git a/ext/tk/lib/tk/event.rb b/ext/tk/lib/tk/event.rb index 81d3e1c4c..5af0fcd44 100644 --- a/ext/tk/lib/tk/event.rb +++ b/ext/tk/lib/tk/event.rb @@ -130,6 +130,15 @@ module TkEvent # [] #end + alias button num + alias delta wheel_delta + alias root rootwin_id + alias rootx x_root + alias root_x x_root + alias rooty y_root + alias root_y y_root + alias sendevent send_event + end ############################################### diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb index 2ebe6612b..1e314e5bb 100644 --- a/ext/tk/lib/tk/font.rb +++ b/ext/tk/lib/tk/font.rb @@ -20,6 +20,17 @@ class TkFont Tk_FontUseTBL.clear } + # option_type : default => string + OptionType = Hash.new(?s) + OptionType['size'] = ?n + OptionType['pointadjust'] = ?n + OptionType['underline'] = ?b + OptionType['overstrike'] = ?b + + # metric_type : default => num_or_str + MetricType = Hash.new(?n) + MetricType['fixed'] = ?b + # set default font case Tk::TK_VERSION when /^4\.*/ @@ -112,6 +123,8 @@ class TkFont case type when 'kanji', 'latin', 'ascii' @type = type + when :kanji, :latin, :ascii + @type = type.to_s else fail ArgumentError, "unknown type '#{type}'" end @@ -637,7 +650,7 @@ class TkFont begin actual_core(@latinfont).each{|key,val| latinkeys[key] = val} rescue - latinkeys {} + latinkeys = {} end if latinkeys != {} tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) @@ -648,7 +661,7 @@ class TkFont begin actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val} rescue - kanjikeys {} + kanjikeys = {} end if kanjikeys != {} tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys)) @@ -662,23 +675,41 @@ class TkFont def actual_core_tk4x(font, window=nil, option=nil) # dummy - if option - "" + if option == 'pointadjust' || option == :pointadjust + 1.0 + elsif option + case OptionType[option.to_s] + when ?n + 0 + when ?b + false + else + '' + end else - [['family',[]], ['size',[]], ['weight',[]], ['slant',[]], - ['underline',[]], ['overstrike',[]], ['charset',[]], - ['pointadjust',[]]] + [['family',''], ['size',0], ['weight',''], ['slant',''], + ['underline',false], ['overstrike',false], ['charset',''], + ['pointadjust',0]] end end def actual_core_tk8x(font, window=nil, option=nil) - if option == 'compound' + if option == 'compound' || option == :compound "" elsif option if window - tk_call('font', 'actual', font, "-displayof", window, "-#{option}") + val = tk_call('font', 'actual', font, + "-displayof", window, "-#{option}") + else + val = tk_call('font', 'actual', font, "-#{option}") + end + case OptionType[option.to_s] + when ?n + num_or_str(val) + when ?b + bool(val) else - tk_call('font', 'actual', font, "-#{option}") + val end else l = tk_split_simplelist(if window @@ -692,7 +723,16 @@ class TkFont if key == '-compound' l.shift else - r.push [key[1..-1], l.shift] + key = key[1..-1] + val = l.shift + case OptionType[key] + when ?n + r.push [key, num_or_str(val)] + when ?b + r.push [key, bool(val)] + else + r.push [key, val] + end end end r @@ -707,12 +747,21 @@ class TkFont def configinfo_core_tk4x(font, option=nil) # dummy if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY - if option - "" + if option == 'pointadjust' || option == :pointadjust + 1.0 + elsif option + case OptionType[option.to_s] + when ?n + 0 + when ?b + false + else + '' + end else - [['family',[]], ['size',[]], ['weight',[]], ['slant',[]], - ['underline',[]], ['overstrike',[]], ['charset',[]], - ['pointadjust',[]]] + [['family',''], ['size',0], ['weight',''], ['slant',''], + ['underline',false], ['overstrike',false], ['charset',''], + ['pointadjust',1.0]] end else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY current_configinfo_core_tk4x(font, option) @@ -721,10 +770,18 @@ class TkFont def current_configinfo_core_tk4x(font, option=nil) if option - "" + case OptionType[option.to_s] + when ?n + 0 + when ?b + false + else + '' + end else - {'family'=>'', 'size'=>'', 'weight'=>'', 'slant'=>'', - 'underline'=>'', 'overstrike'=>'', 'charset'=>'', 'pointadjust'=>''} + {'family'=>'', 'size'=>0, 'weight'=>'', 'slant'=>'', + 'underline'=>false, 'overstrike'=>false, + 'charset'=>false, 'pointadjust'=>1.0} end end @@ -797,10 +854,18 @@ class TkFont def configinfo_core_tk8x(font, option=nil) if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY - if option == 'compound' + if option == 'compound' || option == :compound "" elsif option - tk_call('font', 'configure', font, "-#{option}") + val = tk_call('font', 'configure', font, "-#{option}") + case OptionType[option.to_s] + when ?n + num_or_str(val) + when ?b + bool(val) + else + val + end else l = tk_split_simplelist(tk_call('font', 'configure', font)) r = [] @@ -808,7 +873,16 @@ class TkFont if key == '-compound' l.shift else - r.push [key[1..-1], l.shift] + key = key[1..-1] + val = l.shift + case OptionType[key] + when ?n + r.push [key, num_or_str(val)] + when ?b + r.push [key, bool(val)] + else + r.push [key, val] + end end end r @@ -822,7 +896,15 @@ class TkFont if option == 'compound' "" elsif option - tk_call('font', 'configure', font, "-#{option}") + val = tk_call('font', 'configure', font, "-#{option}") + case OptionType[option.to_s] + when ?n + num_or_str(val) + when ?b + bool(val) + else + val + end else l = tk_split_simplelist(tk_call('font', 'configure', font)) r = {} @@ -830,7 +912,16 @@ class TkFont if key == '-compound' l.shift else - r[key[1..-1]] = l.shift + key = key[1..-1] + val = l.shift + case OptionType[key] + when ?n + r.push [key, num_or_str(val)] + when ?b + r.push [key, bool(val)] + else + r.push [key, val] + end end end r @@ -958,7 +1049,7 @@ class TkFont begin actual_core(@latinfont).each{|key,val| latinkeys[key] = val} rescue - latinkeys {} + latinkeys = {} end if latinkeys != {} tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) @@ -981,7 +1072,7 @@ class TkFont begin actual_core(@latinfont).each{|key,val| latinkeys[key] = val} rescue - latinkeys {} + latinkeys = {} end if latinkeys != {} tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) diff --git a/ext/tk/lib/tk/frame.rb b/ext/tk/lib/tk/frame.rb index 4f01825da..519b9ae8a 100644 --- a/ext/tk/lib/tk/frame.rb +++ b/ext/tk/lib/tk/frame.rb @@ -92,18 +92,18 @@ class TkFrame<TkWindow self.database_class.name end - def self.bind(*args) + def self.bind(*args, &b) if self == WidgetClassNames[WidgetClassName] || self.name == '' - super(*args) + super(*args, &b) else - TkDatabaseClass.new(self.name).bind(*args) + TkDatabaseClass.new(self.name).bind(*args, &b) end end - def self.bind_append(*args) + def self.bind_append(*args, &b) if self == WidgetClassNames[WidgetClassName] || self.name == '' - super(*args) + super(*args, &b) else - TkDatabaseClass.new(self.name).bind_append(*args) + TkDatabaseClass.new(self.name).bind_append(*args, &b) end end def self.bind_remove(*args) diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index 1972193e5..8a33b482c 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -3,6 +3,7 @@ # require 'tk' require 'tk/itemconfig' +require 'tk/menuspec' module TkMenuEntryConfig include TkItemConfigMethod @@ -33,6 +34,7 @@ end class TkMenu<TkWindow include TkMenuEntryConfig + extend TkMenuSpec TkCommandNames = ['menu'.freeze].freeze WidgetClassName = 'Menu'.freeze @@ -47,6 +49,24 @@ class TkMenu<TkWindow #end #private :create_self + def self.new_menuspec(menu_spec, parent = nil, tearoff = false, keys = nil) + if parent.kind_of?(Hash) + keys = _symbolkey2str(parent) + parent = keys.delete('parent') + tearoff = keys.delete('tearoff') + elsif tearoff.kind_of?(Hash) + keys = _symbolkey2str(tearoff) + tearoff = keys.delete('tearoff') + elsif keys + keys = _symbolkey2str(keys) + else + keys = {} + end + + widgetname = keys.delete('widgetname') + _create_menu(parent, menu_spec, widgetname, tearoff, keys) + end + def tagid(id) #id.to_s _get_eval_string(id) @@ -389,6 +409,7 @@ class TkMenubutton<TkLabel end private :create_self end +TkMenuButton = TkMenubutton class TkOptionMenubutton<TkMenubutton @@ -509,3 +530,4 @@ class TkOptionMenubutton<TkMenubutton @menu.current_entryconfiginfo(index, key) end end +TkOptionMenuButton = TkOptionMenubutton diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb index 8ee67bde6..5649a5c44 100644 --- a/ext/tk/lib/tk/radiobutton.rb +++ b/ext/tk/lib/tk/radiobutton.rb @@ -29,7 +29,7 @@ class TkRadioButton<TkButton configure 'variable', tk_trace_variable(v) end - def value + def get_value var = tk_send_without_enc('cget', '-variable') if TkVariable::USE_TCLs_SET_VARIABLE_FUNCTIONS _fromUTF8(INTERP._get_global_var(var)) @@ -38,7 +38,7 @@ class TkRadioButton<TkButton end end - def value=(val) + def set_value(val) var = tk_send_without_enc('cget', '-variable') if TkVariable::USE_TCLs_SET_VARIABLE_FUNCTIONS _fromUTF8(INTERP._set_global_var(var, _get_eval_string(val, true))) diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index fbe1c08c7..49b769403 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -519,12 +519,30 @@ class TkText<TkTextWin alias deltag tag_delete alias delete_tag tag_delete - def tag_bind(tag, seq, cmd=Proc.new, *args) + #def tag_bind(tag, seq, cmd=Proc.new, *args) + # _bind([@path, 'tag', 'bind', tag], seq, cmd, *args) + # self + #end + def tag_bind(tag, seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([@path, 'tag', 'bind', tag], seq, cmd, *args) self end - def tag_bind_append(tag, seq, cmd=Proc.new, *args) + #def tag_bind_append(tag, seq, cmd=Proc.new, *args) + # _bind_append([@path, 'tag', 'bind', tag], seq, cmd, *args) + # self + #end + def tag_bind_append(tag, seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append([@path, 'tag', 'bind', tag], seq, cmd, *args) self end diff --git a/ext/tk/lib/tk/textmark.rb b/ext/tk/lib/tk/textmark.rb index 6004b8602..fbe57a4cc 100644 --- a/ext/tk/lib/tk/textmark.rb +++ b/ext/tk/lib/tk/textmark.rb @@ -122,13 +122,13 @@ class TkTextMarkInsert<TkTextNamedMark end end -class TkTextMarkCurrent<TkTextMark +class TkTextMarkCurrent<TkTextNamedMark def self.new(parent,*args) super(parent, 'current', *args) end end -class TkTextMarkAnchor<TkTextMark +class TkTextMarkAnchor<TkTextNamedMark def self.new(parent,*args) super(parent, 'anchor', *args) end diff --git a/ext/tk/lib/tk/texttag.rb b/ext/tk/lib/tk/texttag.rb index 78f746986..37b83cc4a 100644 --- a/ext/tk/lib/tk/texttag.rb +++ b/ext/tk/lib/tk/texttag.rb @@ -162,12 +162,30 @@ class TkTextTag<TkObject @t.current_tag_configinfo @id, key end - def bind(seq, cmd=Proc.new, *args) + #def bind(seq, cmd=Proc.new, *args) + # _bind([@t.path, 'tag', 'bind', @id], seq, cmd, *args) + # self + #end + def bind(seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([@t.path, 'tag', 'bind', @id], seq, cmd, *args) self end - def bind_append(seq, cmd=Proc.new, *args) + #def bind_append(seq, cmd=Proc.new, *args) + # _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, *args) + # self + #end + def bind_append(seq, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, *args) self end diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index b96e184aa..95d6366ea 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -201,18 +201,18 @@ class TkToplevel<TkWindow self.database_class.name end - def self.bind(*args) + def self.bind(*args, &b) if self == WidgetClassNames[WidgetClassName] || self.name == '' - super(*args) + super(*args, &b) else - TkDatabaseClass.new(self.name).bind(*args) + TkDatabaseClass.new(self.name).bind(*args, &b) end end - def self.bind_append(*args) + def self.bind_append(*args, &b) if self == WidgetClassNames[WidgetClassName] || self.name == '' - super(*args) + super(*args, &b) else - TkDatabaseClass.new(self.name).bind_append(*args) + TkDatabaseClass.new(self.name).bind_append(*args, &b) end end def self.bind_remove(*args) diff --git a/ext/tk/lib/tkextlib/bwidget/labelentry.rb b/ext/tk/lib/tkextlib/bwidget/labelentry.rb index 7a6a7f01d..1425ef773 100644 --- a/ext/tk/lib/tkextlib/bwidget/labelentry.rb +++ b/ext/tk/lib/tkextlib/bwidget/labelentry.rb @@ -23,13 +23,31 @@ class Tk::BWidget::LabelEntry WidgetClassName = 'LabelEntry'.freeze WidgetClassNames[WidgetClassName] = self - def entrybind(*args) - _bind([path, 'bind'], *args) + #def entrybind(*args) + # _bind([path, 'bind'], *args) + # self + #end + def entrybind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'bind'], context, cmd, *args) self end - def entrybind_append(*args) - _bind_append([path, 'bind'], *args) + #def entrybind_append(*args) + # _bind_append([path, 'bind'], *args) + # self + #end + def entrybind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'bind'], context, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb index 9f505703f..7f218c923 100644 --- a/ext/tk/lib/tkextlib/bwidget/listbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb @@ -44,13 +44,33 @@ class Tk::BWidget::ListBox end end - def imagebind(*args) - _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + #def imagebind(*args) + # _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + # self + #end + def imagebind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_for_event_class(Event_for_Items, [path, 'bindImage'], + context, cmd, *args) self end - def imagebind_append(*args) - _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + #def imagebind_append(*args) + # _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + # self + #end + def imagebind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], + context, cmd, *args) self end @@ -63,13 +83,33 @@ class Tk::BWidget::ListBox _bindinfo_for_event_class(Event_for_Items, [path, 'bindImage'], *args) end - def textbind(*args) - _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + #def textbind(*args) + # _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + # self + #end + def textbind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_for_event_class(Event_for_Items, [path, 'bindText'], + context, cmd, *args) self end - def textbind_append(*args) - _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + #def textbind_append(*args) + # _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + # self + #end + def textbind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], + context, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/bwidget/notebook.rb b/ext/tk/lib/tkextlib/bwidget/notebook.rb index aba222ff8..8888ab224 100644 --- a/ext/tk/lib/tkextlib/bwidget/notebook.rb +++ b/ext/tk/lib/tkextlib/bwidget/notebook.rb @@ -41,13 +41,33 @@ class Tk::BWidget::NoteBook end end - def tabbind(*args) - _bind_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + #def tabbind(*args) + # _bind_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + # self + #end + def tabbind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_for_event_class(Event_for_Tabs, [path, 'bindtabs'], + context, cmd, *args) self end - def tabbind_append(*args) - _bind_append_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + #def tabbind_append(*args) + # _bind_append_for_event_class(Event_for_Tabs, [path, 'bindtabs'], *args) + # self + #end + def tabbind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append_for_event_class(Event_for_Tabs, [path, 'bindtabs'], + context, cmd, *args) self end @@ -105,9 +125,13 @@ class Tk::BWidget::NoteBook list(tk_send('pages', first, last)) end - def raise(page=None) - tk_send('raise', page) - self + def raise(page=nil) + if page + tk_send('raise', page) + self + else + tk_send('raise') + end end def see(page) diff --git a/ext/tk/lib/tkextlib/bwidget/spinbox.rb b/ext/tk/lib/tkextlib/bwidget/spinbox.rb index 4380e3835..66501ed70 100644 --- a/ext/tk/lib/tkextlib/bwidget/spinbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/spinbox.rb @@ -22,13 +22,31 @@ class Tk::BWidget::SpinBox WidgetClassName = 'SpinBox'.freeze WidgetClassNames[WidgetClassName] = self - def entrybind(*args) - _bind([path, 'bind'], *args) + #def entrybind(*args) + # _bind([path, 'bind'], *args) + # self + #end + def entrybind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind([path, 'bind'], context, cmd, *args) self end - def entrybind_append(*args) - _bind_append([path, 'bind'], *args) + #def entrybind_append(*args) + # _bind_append([path, 'bind'], *args) + # self + #end + def entrybind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append([path, 'bind'], context, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb index 9a49a96bb..16ca8e892 100644 --- a/ext/tk/lib/tkextlib/bwidget/tree.rb +++ b/ext/tk/lib/tkextlib/bwidget/tree.rb @@ -41,13 +41,33 @@ class Tk::BWidget::Tree end end - def imagebind(*args) - _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + #def imagebind(*args) + # _bind_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + # self + #end + def imagebind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_for_event_class(Event_for_Items, [path, 'bindImage'], + context, cmd, *args) self end - def imagebind_append(*args) - _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + #def imagebind_append(*args) + # _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], *args) + # self + #end + def imagebind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append_for_event_class(Event_for_Items, [path, 'bindImage'], + context, cmd, *args) self end @@ -60,13 +80,33 @@ class Tk::BWidget::Tree _bindinfo_for_event_class(Event_for_Items, [path, 'bindImage'], *args) end - def textbind(*args) - _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + #def textbind(*args) + # _bind_for_event_class(Event_for_Items, [path, 'bindText'], *args) + # self + #end + def textbind(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_for_event_class(Event_for_Items, [path, 'bindText'], + context, cmd, *args) self end - def textbind_append(*args) - _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + #def textbind_append(*args) + # _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], *args) + # self + #end + def textbind_append(context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + _bind_append_for_event_class(Event_for_Items, [path, 'bindText'], + context, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb index f11d9d791..106ffa351 100644 --- a/ext/tk/lib/tkextlib/itk/incr_tk.rb +++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb @@ -330,7 +330,18 @@ module Tk end end - def bind(*args) + #def bind(*args) + # unless @widget + # begin + # @widget = window(tk_call(@master, 'component', @component)) + # @path = @widget.path + # rescue + # fail RuntimeError, 'component is not assigned to a widget' + # end + # end + # @widget.bind(*args) + #end + def bind(context, *args) unless @widget begin @widget = window(tk_call(@master, 'component', @component)) @@ -339,10 +350,26 @@ module Tk fail RuntimeError, 'component is not assigned to a widget' end end - @widget.bind(*args) - end - - def bind_append(*args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + @widget.bind(context, cmd, *args) + end + + #def bind_append(*args) + # unless @widget + # begin + # @widget = window(tk_call(@master, 'component', @component)) + # @path = @widget.path + # rescue + # fail RuntimeError, 'component is not assigned to a widget' + # end + # end + # @widget.bind_append(*args) + #end + def bind_append(context, *args) unless @widget begin @widget = window(tk_call(@master, 'component', @component)) @@ -351,7 +378,12 @@ module Tk fail RuntimeError, 'component is not assigned to a widget' end end - @widget.bind_append(*args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + @widget.bind_append(context, cmd, *args) end def bind_remove(*args) diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb index f3c426048..ba563ba58 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb @@ -97,12 +97,30 @@ class Tk::Iwidgets::Scrolledcanvas *tags.collect{|t| tagid(t)})) end - def itembind(tag, context, cmd=Proc.new, *args) + #def itembind(tag, context, cmd=Proc.new, *args) + # _bind([path, "bind", tagid(tag)], context, cmd, *args) + # self + #end + def itembind(tag, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([path, "bind", tagid(tag)], context, cmd, *args) self end - def itembind_append(tag, context, cmd=Proc.new, *args) + #def itembind_append(tag, context, cmd=Proc.new, *args) + # _bind_append([path, "bind", tagid(tag)], context, cmd, *args) + # self + #end + def itembind_append(tag, context, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind_append([path, "bind", tagid(tag)], context, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb index 78381f8df..d40d60217 100644 --- a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb +++ b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb @@ -75,7 +75,28 @@ module Tk end end - def dnd_bindtarget(type, event, cmd=Proc.new, prior=50, *args) + #def dnd_bindtarget(type, event, cmd=Proc.new, prior=50, *args) + # event = tk_event_sequence(event) + # if prior.kind_of?(Numeric) + # tk_call('dnd', 'bindtarget', @path, type, event, + # install_bind_for_event_class(DND_Subst, cmd, *args), + # prior) + # else + # tk_call('dnd', 'bindtarget', @path, type, event, + # install_bind_for_event_class(DND_Subst, cmd, prior, *args)) + # end + # self + #end + def dnd_bindtarget(type, event, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + + prior = 50 + prior = args.shift unless args.empty? + event = tk_event_sequence(event) if prior.kind_of?(Numeric) tk_call('dnd', 'bindtarget', @path, type, event, @@ -101,8 +122,20 @@ module Tk end end - def dnd_bindsource(type, cmd=Proc.new, prior=None) - tk_call('dnd', 'bindsource', @path, type, cmd, prior) + #def dnd_bindsource(type, cmd=Proc.new, prior=None) + # tk_call('dnd', 'bindsource', @path, type, cmd, prior) + # self + #end + def dnd_bindsource(type, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end + + args = [None] if args.empty + + tk_call('dnd', 'bindsource', @path, type, cmd, *args) self end diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb index 729007edf..11f723a8f 100644 --- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb @@ -743,16 +743,39 @@ class Tk::TreeCtrl marquee_visible() end - def notify_bind(obj, event, cmd=Proc.new, *args) + #def notify_bind(obj, event, cmd=Proc.new, *args) + # _bind([@path, 'notify', 'bind', obj], event, cmd, *args) + # self + #end + def notify_bind(obj, event, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([@path, 'notify', 'bind', obj], event, cmd, *args) self end - def notify_bind_append(obj, event, cmd=Proc.new, *args) + #def notify_bind_append(obj, event, cmd=Proc.new, *args) + # _bind([@path, 'notify', 'bind', obj], event, cmd, *args) + # self + #end + def notify_bind_append(obj, event, *args) + if args[0].kind_of?(Proc) || args[0].kind_of?(Method) + cmd = args.shift + else + cmd = Proc.new + end _bind([@path, 'notify', 'bind', obj], event, cmd, *args) self end + def notify_bindremove(obj, event) + _bind_remove([@path, 'notify', 'bind', obj], event) + self + end + def notify_bindinfo(obj, event=nil) _bindinfo([@path, 'notify', 'bind', obj], event) end |