From ce1b23b7a5a496f4b6d3ad4627a161b1dc6945fe Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 15 Jul 2004 01:18:57 +0000 Subject: * ext/tk/, ext/tcltklib/: bug fix * ext/tk/lib/tk.rb: better operation for SIGINT when processing callbacks. * ext/tk/lib/tk/msgcat.rb: ditto. * ext/tk/lib/tk/variable.rb: ditto. * ext/tk/lib/tk/timer.rb: ditto. * ext/tk/lib/tk/validation.rb: add Tk::ValidateConfigure.__def_validcmd() to define validatecommand methods easier * ext/tk/lib/tk.rb (_genobj_for_tkwidget): support autoload Tk ext classes * ext/tk/lib/tk/canvas.rb and so on: remove the parent widget type check for items (e.g. canvas items; depends on the class) to avoid some troubles on Tk extension widget class definition. * ext/tk/lib/tkextlib/: add Iwidget and TkTable extension support * ext/tk/sample/tkextlib/: add samples of Iwidget and TkTable git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 78 ++- ext/tk/lib/tk/canvas.rb | 6 +- ext/tk/lib/tk/canvastag.rb | 30 +- ext/tk/lib/tk/event.rb | 4 + ext/tk/lib/tk/menu.rb | 12 +- ext/tk/lib/tk/menuspec.rb | 32 +- ext/tk/lib/tk/text.rb | 4 +- ext/tk/lib/tk/textimage.rb | 6 +- ext/tk/lib/tk/textmark.rb | 12 +- ext/tk/lib/tk/texttag.rb | 14 +- ext/tk/lib/tk/textwindow.rb | 6 +- ext/tk/lib/tk/validation.rb | 18 +- ext/tk/lib/tk/variable.rb | 61 +- ext/tk/lib/tkextlib/SUPPORT_STATUS | 11 +- ext/tk/lib/tkextlib/bwidget.rb | 2 + ext/tk/lib/tkextlib/bwidget/listbox.rb | 2 +- ext/tk/lib/tkextlib/bwidget/tree.rb | 2 +- ext/tk/lib/tkextlib/itk/incr_tk.rb | 6 +- ext/tk/lib/tkextlib/iwidgets.rb | 21 + ext/tk/lib/tkextlib/iwidgets/buttonbox.rb | 8 +- ext/tk/lib/tkextlib/iwidgets/checkbox.rb | 8 +- ext/tk/lib/tkextlib/iwidgets/dialogshell.rb | 8 +- ext/tk/lib/tkextlib/iwidgets/entryfield.rb | 6 + ext/tk/lib/tkextlib/iwidgets/menubar.rb | 190 ++++++ ext/tk/lib/tkextlib/iwidgets/messagebox.rb | 8 +- ext/tk/lib/tkextlib/iwidgets/notebook.rb | 163 +++++ ext/tk/lib/tkextlib/iwidgets/optionmenu.rb | 87 +++ ext/tk/lib/tkextlib/iwidgets/panedwindow.rb | 127 ++++ ext/tk/lib/tkextlib/iwidgets/promptdialog.rb | 131 ++++ ext/tk/lib/tkextlib/iwidgets/pushbutton.rb | 30 + ext/tk/lib/tkextlib/iwidgets/radiobox.rb | 8 +- ext/tk/lib/tkextlib/iwidgets/scopedobject.rb | 24 + ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb | 315 ++++++++++ ext/tk/lib/tkextlib/iwidgets/scrolledframe.rb | 59 ++ ext/tk/lib/tkextlib/iwidgets/scrolledhtml.rb | 43 ++ ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb | 190 ++++++ ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb | 518 +++++++++++++++ ext/tk/lib/tkextlib/iwidgets/selectionbox.rb | 92 +++ ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb | 92 +++ ext/tk/lib/tkextlib/iwidgets/spindate.rb | 38 ++ ext/tk/lib/tkextlib/iwidgets/spinint.rb | 20 + ext/tk/lib/tkextlib/iwidgets/spinner.rb | 150 +++++ ext/tk/lib/tkextlib/iwidgets/spintime.rb | 38 ++ ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb | 154 +++++ ext/tk/lib/tkextlib/iwidgets/tabset.rb | 89 +++ ext/tk/lib/tkextlib/iwidgets/toolbar.rb | 37 +- ext/tk/lib/tkextlib/tcllib.rb | 8 +- ext/tk/lib/tkextlib/tcllib/autoscroll.rb | 59 +- ext/tk/lib/tkextlib/tcllib/cursor.rb | 55 +- ext/tk/lib/tkextlib/tcllib/ip_entry.rb | 1 + ext/tk/lib/tkextlib/tcllib/plotchart.rb | 87 ++- ext/tk/lib/tkextlib/tcllib/style.rb | 28 +- ext/tk/lib/tkextlib/tile.rb | 2 + ext/tk/lib/tkextlib/tktable.rb | 14 + ext/tk/lib/tkextlib/tktable/setup.rb | 8 + ext/tk/lib/tkextlib/tktable/tktable.rb | 796 ++++++++++++++++++++++++ ext/tk/lib/tkextlib/vu.rb | 2 + ext/tk/lib/tkextlib/vu/pie.rb | 6 +- 58 files changed, 3866 insertions(+), 160 deletions(-) create mode 100644 ext/tk/lib/tkextlib/iwidgets/menubar.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/notebook.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/optionmenu.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/panedwindow.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/promptdialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/pushbutton.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scopedobject.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledframe.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledhtml.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/selectionbox.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/spindate.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/spinint.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/spinner.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/spintime.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb create mode 100644 ext/tk/lib/tkextlib/iwidgets/tabset.rb create mode 100644 ext/tk/lib/tkextlib/tktable.rb create mode 100644 ext/tk/lib/tkextlib/tktable/setup.rb create mode 100644 ext/tk/lib/tkextlib/tktable/tktable.rb (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index bb2335f107..312452df1d 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -26,6 +26,7 @@ module TkComm extend TkUtil WidgetClassNames = {}.taint + TkExtlibAutoloadModule = [].taint # None = Object.new ### --> definition is moved to TkUtil module # def None.to_s @@ -92,17 +93,64 @@ module TkComm # gen_class_name = ruby_class_name + 'GeneratedOnTk' gen_class_name = ruby_class_name classname_def = '' - elsif Object.const_defined?('Tk' + tk_class) - ruby_class_name = 'Tk' + tk_class + else # ruby_class == nil + mods = TkExtlibAutoloadModule.find_all{|m| m.const_defined?(tk_class)} + mods.each{|mod| + begin + mod.const_get(tk_class) # auto_load + break if (ruby_class = WidgetClassNames[tk_class]) + rescue LoadError + # ignore load error + end + } + + unless ruby_class + std_class = 'Tk' << tk_class + if Object.const_defined?(std_class) + Object.const_get(std_class) # auto_load + ruby_class = WidgetClassNames[tk_class] + end + end + + if ruby_class + # found + ruby_class_name = ruby_class.name + gen_class_name = ruby_class_name + classname_def = '' + else + # unknown + ruby_class_name = 'TkWindow' + gen_class_name = 'TkWidget_' + tk_class + classname_def = "WidgetClassName = '#{tk_class}'.freeze" + end + end + +################################### +=begin + if ruby_class = WidgetClassNames[tk_class] + ruby_class_name = ruby_class.name # gen_class_name = ruby_class_name + 'GeneratedOnTk' gen_class_name = ruby_class_name classname_def = '' else - ruby_class_name = 'TkWindow' - # gen_class_name = ruby_class_name + tk_class + 'GeneratedOnTk' - gen_class_name = 'TkWidget_' + tk_class - classname_def = "WidgetClassName = '#{tk_class}'.freeze" + mod = TkExtlibAutoloadModule.find{|m| m.const_defined?(tk_class)} + if mod + ruby_class_name = mod.name + '::' + tk_class + gen_class_name = ruby_class_name + classname_def = '' + elsif Object.const_defined?('Tk' + tk_class) + ruby_class_name = 'Tk' + tk_class + # gen_class_name = ruby_class_name + 'GeneratedOnTk' + gen_class_name = ruby_class_name + classname_def = '' + else + ruby_class_name = 'TkWindow' + # gen_class_name = ruby_class_name + tk_class + 'GeneratedOnTk' + gen_class_name = 'TkWidget_' + tk_class + classname_def = "WidgetClassName = '#{tk_class}'.freeze" + end end +=end =begin unless Object.const_defined? gen_class_name @@ -131,7 +179,12 @@ module TkComm private :_genobj_for_tkwidget module_function :_genobj_for_tkwidget - def tk_tcl2ruby(val, enc_mode = nil, listobj = true) + def _at(x,y) + "@#{Integer(x)},#{Integer(y)}" + end + module_function :_at + + def tk_tcl2ruby(val, enc_mode = false, listobj = true) if val =~ /^rb_out\S* (c(_\d+_)?\d+)/ #return Tk_CMDTBL[$1] return TkCore::INTERP.tk_cmd_tbl[$1] @@ -181,7 +234,7 @@ module TkComm private :tk_tcl2ruby module_function :tk_tcl2ruby - private_class_method :tk_tcl2ruby + #private_class_method :tk_tcl2ruby unless const_defined?(:USE_TCLs_LIST_FUNCTIONS) USE_TCLs_LIST_FUNCTIONS = true @@ -238,7 +291,8 @@ if USE_TCLs_LIST_FUNCTIONS array2tk_list(e) elsif e.kind_of? Hash tmp_ary = [] - e.each{|k,v| tmp_ary << k << v } + #e.each{|k,v| tmp_ary << k << v } + e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v } array2tk_list(tmp_ary) else _get_eval_string(e) @@ -369,7 +423,9 @@ else if e.kind_of? Array "{#{array2tk_list(e)}}" elsif e.kind_of? Hash - "{#{e.to_a.collect{|ee| array2tk_list(ee)}.join(' ')}}" + # "{#{e.to_a.collect{|ee| array2tk_list(ee)}.join(' ')}}" + e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v } + array2tk_list(tmp_ary) else s = _get_eval_string(e) (s.index(/\s/) || s.size == 0)? "{#{s}}": s @@ -3108,7 +3164,6 @@ class TkObject, , ... , , , ... + # # If you need support extra arguments given by Tcl/Tk, # please override _get_extra_args_tbl diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index fdb4ec201b..f0f5dcd2e8 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -320,9 +320,9 @@ class TkMenuClonefalse) + parent.menu(mbar) + end + mbar + end + private :_create_menu_for_menubar + def _create_menubutton(parent, menu_info, tearoff=false, default_opts = nil) btn_info = menu_info[0] @@ -160,12 +184,10 @@ module TkMenuSpec tearoff = keys.delete('tearoff') if keys.key?('tearoff') - if parent.kind_of?(TkRoot) || parent.kind_of?(TkToplevel) + if _use_menubar?(parent) # menubar by menu entries - unless (mbar = parent.menu).kind_of?(TkMenu) - mbar = TkMenu.new(parent, :tearoff=>false) - parent.menu(mbar) - end + + mbar = _create_menu_for_menubar(parent) menu_name = nil diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index d2fdfd9401..bd4586e4e2 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -502,9 +502,9 @@ class TkText, , ... , , , ... + # #def self._get_extra_args_tbl # # return an array of convert procs # [] #end + + def self.ret_val(val) + (val)? '1': '0' + end end ############################################### @@ -257,7 +263,7 @@ class TkValidateCommand else @id = install_cmd(proc{|*arg| ex_args = [] - extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} klass.ret_val(cmd.call( *(ex_args.concat(klass.scan_args(keys, arg))) )) @@ -272,9 +278,9 @@ class TkValidateCommand else @id = install_cmd(proc{|*arg| ex_args = [] - extra_args_tbl.reverse_each{|conv| ex_args << conv.call(args.pop)} + extra_args_tbl.reverse_each{|conv| ex_args << conv.call(arg.pop)} klass.ret_val(cmd.call( - *(ex_args << klass.new(*klass.scan_args(keys,arg))) + *(ex_args << klass.new(*klass.scan_args(keys, arg))) )) }) + ' ' + args end diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index 6398537bfa..22b17eb0e1 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -96,12 +96,45 @@ TkCore::INTERP.add_tk_procs('rb_var', 'args', <<-'EOL') end end + # + # default_value is available only when the variable is an assoc array. + # + def default_value(val=nil, &b) + if b + @def_default = :proc + @default_val = proc(&b) + else + @def_default = :val + @default_val = val + end + self + end + def default_value=(val) + @def_default = :val + @default_val = val + self + end + def default_proc(cmd = Proc.new) + @def_default = :proc + @default_val = cmd + self + end + + def undef_default + @default_val = nil + @def_default = false + self + end + def initialize(val="") # @id = Tk_VARIABLE_ID.join('') @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_) Tk_VARIABLE_ID[1].succ! TkVar_ID_TBL[@id] = self + @def_default = false + @default_val = nil + @trace_var = nil @trace_elem = nil @trace_opts = nil @@ -290,7 +323,19 @@ if USE_TCLs_SET_VARIABLE_FUNCTIONS def [](*idxs) index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',') - _fromUTF8(INTERP._get_global_var2(@id, index)) + begin + _fromUTF8(INTERP._get_global_var2(@id, index)) + rescue => e + case @def_default + when :proc + @default_val.call(self, *idxs) + when :val + @default_val + else + fail e + end + end + #_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))) end @@ -389,7 +434,19 @@ else def [](*idxs) index = idxs.collect{|idx| _get_eval_string(idx)}.join(',') - INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) + begin + INTERP._eval(Kernel.format('global %s; set %s(%s)', @id, @id, index)) + rescue => e + case @def_default + when :proc + @default_val.call(self, *idxs) + when :val + @default_val + else + fail e + end + end + #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))) diff --git a/ext/tk/lib/tkextlib/SUPPORT_STATUS b/ext/tk/lib/tkextlib/SUPPORT_STATUS index 4fd652a8a2..81e92a1acf 100644 --- a/ext/tk/lib/tkextlib/SUPPORT_STATUS +++ b/ext/tk/lib/tkextlib/SUPPORT_STATUS @@ -49,8 +49,14 @@ script may give you some hints about that. Tcllib http://sf.net/projects/tcllib ==> tcllib (partial support; Tklib part only) +IWidgets http://sf.net/projects/incrTcl ==> iwidgets + BWidgets http://sf.net/projects/tcllib ==> bwidget +TkTable http://sf.net/projects/tktable ==> tktable + [ * see also + written by Ferenc Engard (ferenc@engard.hu) ] + vu http://tktable.sourceforge.net ==> vu TkHTML http://www.hwaci.com/sw/tkhtml/index.html ==> tkHTML @@ -84,11 +90,6 @@ TkDND http://sourceforge.net/projects/tkdnd ==> tkDND TclX http://sf.net/projects/tclx * may support Tk part only -IWidgets http://sf.net/projects/incrTcl - -TkTable http://sf.net/projects/tktable - * see http://www.korus.hu/~fery/ruby/tktable.rb - winico http://tktable.sourceforge.net diff --git a/ext/tk/lib/tkextlib/bwidget.rb b/ext/tk/lib/tkextlib/bwidget.rb index 78d7d5230f..411a6ac99a 100644 --- a/ext/tk/lib/tkextlib/bwidget.rb +++ b/ext/tk/lib/tkextlib/bwidget.rb @@ -17,6 +17,8 @@ TkPackage.require('BWidget') module Tk module BWidget + TkComm::TkExtlibAutoloadModule.unshift(self) + extend TkCore LIBRARY = tk_call('set', '::BWIDGET::LIBRARY') diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb index 28173fb7f9..102be9a5fa 100644 --- a/ext/tk/lib/tkextlib/bwidget/listbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb @@ -162,7 +162,7 @@ class Tk::BWidget::ListBox::Item include TkTreatTagFont ListItem_TBL = TkCore::INTERP.create_table - ListItem_ID = ['item:'.freeze, '00000'.taint].freeze + ListItem_ID = ['bw:item'.freeze, '00000'.taint].freeze TkCore::INTERP.init_ip_env{ ListItem_TBL.clear } diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb index 888ce9409f..f657e7148e 100644 --- a/ext/tk/lib/tkextlib/bwidget/tree.rb +++ b/ext/tk/lib/tkextlib/bwidget/tree.rb @@ -203,7 +203,7 @@ class Tk::BWidget::Tree::Node include TkTreatTagFont TreeNode_TBL = TkCore::INTERP.create_table - TreeNode_ID = ['node:'.freeze, '00000'.taint].freeze + TreeNode_ID = ['bw:node'.freeze, '00000'.taint].freeze TkCore::INTERP.init_ip_env{ TreeNode_TBL.clear } diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb index db01bfe85e..84143a3ea3 100644 --- a/ext/tk/lib/tkextlib/itk/incr_tk.rb +++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb @@ -47,6 +47,10 @@ module Tk '::itk::' << self::WidgetClassName end + def __destroy_hook__ + Tk::Itk::Component::ComponentID_TBL.delete(self.path) + end + #### [incr Tk] public methods def component simplelist(tk_send('component')) @@ -129,7 +133,7 @@ module Tk end ComponentID_TBL = TkCore::INTERP.create_table - Itk_Component_ID = ['itk_component'.freeze, '00000'.taint].freeze + Itk_Component_ID = ['itk:component'.freeze, '00000'.taint].freeze TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear } diff --git a/ext/tk/lib/tkextlib/iwidgets.rb b/ext/tk/lib/tkextlib/iwidgets.rb index 0370ad5d23..b76fb79cc1 100644 --- a/ext/tk/lib/tkextlib/iwidgets.rb +++ b/ext/tk/lib/tkextlib/iwidgets.rb @@ -19,6 +19,8 @@ TkPackage.require('Iwidgets') module Tk module Iwidgets + TkComm::TkExtlibAutoloadModule.unshift(self) + extend TkCore def self.package_version @@ -55,11 +57,30 @@ module Tk autoload :Labeledframe, 'tkextlib/iwidgets/labeledframe' autoload :Labeledwidget, 'tkextlib/iwidgets/labeledwidget' autoload :Mainwindow, 'tkextlib/iwidgets/mainwindow' + autoload :Menubar, 'tkextlib/iwidgets/menubar' autoload :Messagebox, 'tkextlib/iwidgets/messagebox' autoload :Messagedialog, 'tkextlib/iwidgets/messagedialog' + autoload :Notebook, 'tkextlib/iwidgets/notebook' + autoload :Optionmenu, 'tkextlib/iwidgets/optionmenu' + autoload :Panedwindow, 'tkextlib/iwidgets/panedwindow' + autoload :Pushbutton, 'tkextlib/iwidgets/pushbutton' + autoload :Promptdialog, 'tkextlib/iwidgets/promptdialog' autoload :Radiobox, 'tkextlib/iwidgets/radiobox' + autoload :Scrolledcanvas, 'tkextlib/iwidgets/scrolledcanvas' + autoload :Scrolledframe, 'tkextlib/iwidgets/scrolledframe' + autoload :Scrolledhtml, 'tkextlib/iwidgets/scrolledhtml' + autoload :Scrolledlistbox, 'tkextlib/iwidgets/scrolledlistbox' + autoload :Scrolledtext, 'tkextlib/iwidgets/scrolledtext' autoload :Scrolledwidget, 'tkextlib/iwidgets/scrolledwidget' + autoload :Selectionbox, 'tkextlib/iwidgets/selectionbox' + autoload :Selectiondialog, 'tkextlib/iwidgets/selectiondialog' autoload :Shell, 'tkextlib/iwidgets/shell' + autoload :Spindate, 'tkextlib/iwidgets/spindate' + autoload :Spinint, 'tkextlib/iwidgets/spinint' + autoload :Spinner, 'tkextlib/iwidgets/spinner' + autoload :Spintime, 'tkextlib/iwidgets/spintime' + autoload :Tabnotebook, 'tkextlib/iwidgets/tabnotebook' + autoload :Tabset, 'tkextlib/iwidgets/tabset' autoload :Timeentry, 'tkextlib/iwidgets/timeentry' autoload :Timefield, 'tkextlib/iwidgets/timefield' autoload :Toolbar, 'tkextlib/iwidgets/toolbar' diff --git a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb index 5ca48ed229..1ff190b9ff 100644 --- a/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/buttonbox.rb @@ -56,7 +56,9 @@ class Tk::Iwidgets::Buttonbox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'add', tagid(tag), *hash_kv(keys)) @@ -87,7 +89,9 @@ class Tk::Iwidgets::Buttonbox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys)) diff --git a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb index 5e0fb5e7b6..05d0e1d813 100644 --- a/ext/tk/lib/tkextlib/iwidgets/checkbox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/checkbox.rb @@ -56,7 +56,9 @@ class Tk::Iwidgets::Checkbox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'add', tagid(tag), *hash_kv(keys)) @@ -93,7 +95,9 @@ class Tk::Iwidgets::Checkbox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys)) diff --git a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb index 4736ebab77..88b9a97094 100644 --- a/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb +++ b/ext/tk/lib/tkextlib/iwidgets/dialogshell.rb @@ -56,7 +56,9 @@ class Tk::Iwidgets::Dialogshell keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'add', tagid(tag), *hash_kv(keys)) @@ -87,7 +89,9 @@ class Tk::Iwidgets::Dialogshell keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys)) diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb index 6299259b9b..300573bcec 100644 --- a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb +++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb @@ -87,7 +87,13 @@ class Tk::Iwidgets::Entryfield def value _fromUTF8(tk_send_without_enc('get')) end + def value= (val) + tk_send_without_enc('delete', 0, 'end') + tk_send_without_enc('insert', 0, _get_eval_enc_str(val)) + val + end alias get value + alias set value= def cursor=(index) tk_send_without_enc('icursor', index) diff --git a/ext/tk/lib/tkextlib/iwidgets/menubar.rb b/ext/tk/lib/tkextlib/iwidgets/menubar.rb new file mode 100644 index 0000000000..b4c94ff564 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/menubar.rb @@ -0,0 +1,190 @@ +# +# tkextlib/iwidgets/menubar.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Menubar < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Menubar + TkCommandNames = ['::iwidgets::menubar'.freeze].freeze + WidgetClassName = 'Menubar'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'menucget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'menuconfigure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias menucget itemcget + alias menuconfigure itemconfigure + alias menuconfiginfo itemconfiginfo + alias current_menuconfiginfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def __methodcall_optkeys + {'menubuttons'=>'menubuttons'} + end + + def menubuttons(val = nil) + unless val + return tk_call(@path, 'cget', '-menubuttons') + end + + tk_call(@path, 'configure', '-menubuttons', _parse_menu_spec(val)) + self + end + + def _parse_menu_spec(menu_spec) + ret = '' + menu_spec.each{|spec| + next unless spec + + if spec.kind_of?(Hash) + args = [spec] + type = 'options' + else + type, *args = spec + end + + type = type.to_s + case type + when 'options' + keys = args[0] + ary = [type] + ary.concat(hash_kv(keys)) + ret << array2tk_list(ary) << "\n" + + when 'menubutton', 'cascade' + name, keys = args + if keys + ary = [type, name] + keys = _symbolkey2str(keys) + keys['menu'] = _parse_menu_spec(keys['menu']) if keys.key?('menu') + ary.concat(hash_kv(keys)) + ret << array2tk_list(ary) << "\n" + else + ret << array2tk_list([type, name]) << "\n" + end + + else + name, keys = args + if keys + ary = [type, name] + ary.concat(hash_kv(keys)) + ret << array2tk_list(ary) << "\n" + else + ret << array2tk_list([type, name]) << "\n" + end + end + } + ret + end + + #################################### + + def add(type, tag=nil, keys={}) + if tag.kind_of?(Hash) + keys = tag + tag = nil + end + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else + tag = Tk::Itk::Component.new(self) + end + keys = _symbolkey2str(keys) + keys['menu'] = _parse_menu_spec(keys['menu']) if keys.key?('menu') + tk_call(@path, 'add', type, tagid(tag), *hash_kv(keys)) + tag + end + + def delete(path1, path2=nil) + if path2 + else + tk_call(@path, 'delete', index(idx)) + end + self + end + + def index(idx) + number(tk_call(@path, 'index', tagid(idx))) + end + + def insert(idx, type, tag=nil, keys={}) + if tag.kind_of?(Hash) + keys = tag + tag = nil + end + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else + tag = Tk::Itk::Component.new(self) + end + keys = _symbolkey2str(keys) + keys['menu'] = _parse_menu_spec(keys['menu']) if keys.key?('menu') + tk_call(@path, 'insert', index(idx), type, tagid(tag), *hash_kv(keys)) + tag + end + + def invoke(idx) + tk_call(@path, 'invoke', index(idx)) + self + end + + def menupath(pat) + if (win = tk_call(@path, 'path', pat)) == '-1' + return nil + end + window(win) + end + def menupath_glob(pat) + if (win = tk_call(@path, 'path', '-glob', pat)) == '-1' + return nil + end + window(win) + end + def menupath_tclregexp(pat) + if (win = tk_call(@path, 'path', '-regexp', pat)) == '-1' + return nil + end + window(win) + end + + def type(path) + tk_call(@path, 'type', path) + end + + def yposition(path) + number(tk_call(@path, 'yposition', path)) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb index a9d9775c75..608f6f7adb 100644 --- a/ext/tk/lib/tkextlib/iwidgets/messagebox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/messagebox.rb @@ -41,10 +41,10 @@ class Tk::Iwidgets::Messagebox end end - alias type_cget itemcget - alias type_configure itemconfigure - alias type_configinfo itemconfiginfo - alias current_type_configinfo current_itemconfiginfo + alias typecget itemcget + alias typeconfigure itemconfigure + alias typeconfiginfo itemconfiginfo + alias current_typeconfiginfo current_itemconfiginfo private :itemcget, :itemconfigure private :itemconfiginfo, :current_itemconfiginfo diff --git a/ext/tk/lib/tkextlib/iwidgets/notebook.rb b/ext/tk/lib/tkextlib/iwidgets/notebook.rb new file mode 100644 index 0000000000..511ee3dff3 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/notebook.rb @@ -0,0 +1,163 @@ +# +# tkextlib/iwidgets/notebook.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Notebook < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Notebook + TkCommandNames = ['::iwidgets::notebook'.freeze].freeze + WidgetClassName = 'Notebook'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'tabcget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'tabconfigure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias pagecget itemcget + alias pageconfigure itemconfigure + alias pageconfiginfo itemconfiginfo + alias current_pageconfiginfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def add(keys={}) + window(tk_call(@path, 'add', *hash_kv(keys))) + end + + def child_site_list + list(tk_call(@path, 'childsite')) + end + + def child_site(idx) + if (new_idx = self.index(idx)) < 0 + new_idx = tagid(idx) + end + window(tk_call(@path, 'childsite', new_idx)) + end + + def delete(idx1, idx2=nil) + if (new_idx1 = self.index(idx1)) < 0 + new_idx1 = tagid(idx1) + end + if idx2 + if (new_idx2 = self.index(idx2)) < 0 + new_idx2 = tagid(idx2) + end + tk_call(@path, 'delete', new_idx1, new_idx2) + else + tk_call(@path, 'delete', new_idx1) + end + self + end + + def index(idx) + number(tk_call(@path, 'index', tagid(idx))) + end + + def insert(idx, keys={}) + if (new_idx = self.index(idx)) < 0 + new_idx = tagid(idx) + end + window(tk_call(@path, 'insert', new_idx, *hash_kv(keys))) + end + + def next + tk_call(@path, 'next') + self + end + + def prev + tk_call(@path, 'prev') + self + end + + def select(idx) + if (new_idx = self.index(idx)) < 0 + new_idx = tagid(idx) + end + tk_call(@path, 'select', new_idx) + self + end + + def scrollcommand(cmd=Proc.new) + configure_cmd 'scrollcommand', cmd + self + end + alias xscrollcommand scrollcommand + alias yscrollcommand scrollcommand + + def xscrollbar(bar=nil) + if bar + @scrollbar = bar + @scrollbar.orient 'horizontal' + self.scrollcommand {|*arg| @scrollbar.set(*arg)} + @scrollbar.command {|*arg| self.xview(*arg)} + Tk.update # avoid scrollbar trouble + end + @scrollbar + end + def yscrollbar(bar=nil) + if bar + @scrollbar = bar + @scrollbar.orient 'vertical' + self.scrollcommand {|*arg| @scrollbar.set(*arg)} + @scrollbar.command {|*arg| self.yview(*arg)} + Tk.update # avoid scrollbar trouble + end + @scrollbar + end + alias scrollbar yscrollbar + + def view(*index) + if index.size == 0 + window(tk_send_without_enc('view')) + else + tk_send_without_enc('view', *index) + self + end + end + alias xview view + alias yview view + + def view_moveto(*index) + view('moveto', *index) + end + alias xview_moveto view_moveto + alias yview_moveto view_moveto + def view_scroll(*index) + view('scroll', *index) + end + alias xview_scroll view_scroll + alias yview_scroll view_scroll +end diff --git a/ext/tk/lib/tkextlib/iwidgets/optionmenu.rb b/ext/tk/lib/tkextlib/iwidgets/optionmenu.rb new file mode 100644 index 0000000000..226163a150 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/optionmenu.rb @@ -0,0 +1,87 @@ +# +# tkextlib/iwidgets/optionmenu.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Optionmenu < Tk::Iwidgets::Labeledwidget + end + end +end + +class Tk::Iwidgets::Optionmenu + TkCommandNames = ['::iwidgets::optionmenu'.freeze].freeze + WidgetClassName = 'Optionmenu'.freeze + WidgetClassNames[WidgetClassName] = self + + def delete(first, last=nil) + if last + tk_call(@path, 'delete', first, last) + else + tk_call(@path, 'delete', first) + end + self + end + + def disable(idx) + tk_call(@path, 'disable', idx) + self + end + + def enable(idx) + tk_call(@path, 'enable', idx) + self + end + + def get(first=nil, last=nil) + if last + simplelist(tk_call(@path, 'get', first, last)) + elsif first + tk_call(@path, 'get', first) + else + tk_call(@path, 'get') + end + end + def get_range(first, last) + get(first, last) + end + def get_selected + get() + end + + def index(idx) + number(tk_call(@path, 'index', idx)) + end + + def insert(idx, *args) + tk_call(@path, 'insert', idx, *args) + self + end + + def select(idx) + tk_call(@path, 'select', idx) + self + end + + def sort(*params, &b) + # see 'lsort' man page about params + if b + tk_call(@path, 'sort', '-command', proc(&b), *params) + else + tk_call(@path, 'sort', *params) + end + self + end + def sort_ascending + tk_call(@path, 'sort', 'ascending') + self + end + def sort_descending + tk_call(@path, 'sort', 'descending') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb new file mode 100644 index 0000000000..a205036239 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/panedwindow.rb @@ -0,0 +1,127 @@ +# +# tkextlib/iwidgets/panedwindow.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Panedwindow < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Panedwindow + TkCommandNames = ['::iwidgets::panedwindow'.freeze].freeze + WidgetClassName = 'Panedwindow'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'panecget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'paneconfigure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias panecget itemcget + alias paneconfigure itemconfigure + alias paneconfiginfo itemconfiginfo + alias current_paneconfiginfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def add(tag=nil, keys={}) + if tag.kind_of?(Hash) + keys = tag + tag = nil + end + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else + tag = Tk::Itk::Component.new(self) + end + window(tk_call(@path, 'add', tagid(tag), *hash_kv(keys))) + tag + end + + def child_site_list + list(tk_call(@path, 'childsite')) + end + + def child_site(idx) + window(tk_call(@path, 'childsite', index(idx))) + end + + def delete(idx) + tk_call(@path, 'delete', index(idx)) + self + end + + def fraction(*percentages) + tk_call(@path, 'fraction', *percentages) + self + end + + def hide(idx) + tk_call(@path, 'hide', index(idx)) + self + end + + def index(idx) + number(tk_call(@path, 'index', tagid(idx))) + end + + def insert(idx, tag=nil, keys={}) + if tag.kind_of?(Hash) + keys = tag + tag = nil + end + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else + tag = Tk::Itk::Component.new(self) + end + window(tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))) + tag + end + + def invoke(idx=nil) + if idx + tk_call(@path, 'invoke', index(idx)) + else + tk_call(@path, 'invoke') + end + self + end + + def reset + tk_call(@path, 'reset') + self + end + + def show(idx) + tk_call(@path, 'show', index(idx)) + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/promptdialog.rb b/ext/tk/lib/tkextlib/iwidgets/promptdialog.rb new file mode 100644 index 0000000000..ec18647511 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/promptdialog.rb @@ -0,0 +1,131 @@ +# +# tkextlib/iwidgets/promptdialog.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Promptdialog < Tk::Iwidgets::Dialog + end + end +end + +class Tk::Iwidgets::Promptdialog + TkCommandNames = ['::iwidgets::promptdialog'.freeze].freeze + WidgetClassName = 'Promptdialog'.freeze + WidgetClassNames[WidgetClassName] = self + + # index method is not available, because it shows index of the entry field + def default(name) + tk_call(@path, 'default', tagid(name)) + self + end + + def hide(name) + tk_call(@path, 'hide', tagid(name)) + self + end + + def invoke(name=nil) + if name + tk_call(@path, 'invoke', tagid(name)) + else + tk_call(@path, 'invoke') + end + self + end + + def show(name) + tk_call(@path, 'show', tagid(name)) + self + end + + + # based on Tk::Iwidgets::Entryfield + def clear + tk_call(@path, 'clear') + self + end + + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + + def value + _fromUTF8(tk_send_without_enc('get')) + end + def value= (val) + tk_send_without_enc('delete', 0, 'end') + tk_send_without_enc('insert', 0, _get_eval_enc_str(val)) + val + end + alias get value + alias set value= + + def cursor=(index) + tk_send_without_enc('icursor', index) + #self + index + end + alias icursor cursor= + + def index(index) + number(tk_send_without_enc('index', index)) + end + + def insert(pos,text) + tk_send_without_enc('insert', pos, _get_eval_enc_str(text)) + self + end + + def mark(pos) + tk_send_without_enc('scan', 'mark', pos) + self + end + def dragto(pos) + tk_send_without_enc('scan', 'dragto', pos) + self + end + def selection_adjust(index) + tk_send_without_enc('selection', 'adjust', index) + self + end + def selection_clear + tk_send_without_enc('selection', 'clear') + self + end + def selection_from(index) + tk_send_without_enc('selection', 'from', index) + self + end + def selection_present() + bool(tk_send_without_enc('selection', 'present')) + end + def selection_range(s, e) + tk_send_without_enc('selection', 'range', s, e) + self + end + def selection_to(index) + tk_send_without_enc('selection', 'to', index) + self + end + + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/pushbutton.rb b/ext/tk/lib/tkextlib/iwidgets/pushbutton.rb new file mode 100644 index 0000000000..25d3633507 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/pushbutton.rb @@ -0,0 +1,30 @@ +# +# tkextlib/iwidgets/pushbutton.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Pushbutton < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Pushbutton + TkCommandNames = ['::iwidgets::pushbutton'.freeze].freeze + WidgetClassName = 'Pushbutton'.freeze + WidgetClassNames[WidgetClassName] = self + + def invoke + tk_call_without_enc(@path, 'invoke') + self + end + + def flash + tk_call_without_enc(@path, 'flash') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb index dd96089ffa..84c15082d6 100644 --- a/ext/tk/lib/tkextlib/iwidgets/radiobox.rb +++ b/ext/tk/lib/tkextlib/iwidgets/radiobox.rb @@ -56,7 +56,9 @@ class Tk::Iwidgets::Radiobox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'add', tagid(tag), *hash_kv(keys)) @@ -93,7 +95,9 @@ class Tk::Iwidgets::Radiobox keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys)) diff --git a/ext/tk/lib/tkextlib/iwidgets/scopedobject.rb b/ext/tk/lib/tkextlib/iwidgets/scopedobject.rb new file mode 100644 index 0000000000..bddef50841 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scopedobject.rb @@ -0,0 +1,24 @@ +# +# tkextlib/iwidgets/buttonbox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scopedobject < TkObject + end + end +end + +class Tk::Iwidgets::Scopedobject + TkCommandNames = ['::iwidgets::scopedobject'.freeze].freeze + WidgetClassName = 'Scopedobject'.freeze + WidgetClassNames[WidgetClassName] = self + + def initialize(obj_name, keys={}) + @path = tk_call(self.class::TkCommandNames[0], obj_name, *hash_kv(keys)) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb new file mode 100644 index 0000000000..c5ed19c1f1 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb @@ -0,0 +1,315 @@ +# +# tkextlib/iwidgets/scrolledcanvas.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/canvas' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledcanvas < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Scrolledcanvas + TkCommandNames = ['::iwidgets::scrolledcanvas'.freeze].freeze + WidgetClassName = 'Scrolledcanvas'.freeze + WidgetClassNames[WidgetClassName] = self + + ################################ + + def initialize(*args) + super(*args) + @canvas = component_widget('canvas') + end + + def method_missing(id, *args) + if @canvas.methods.include?(id.id2name) + @canvas.__send__(id, *args) + else + super(id, *args) + end + end + + ################################ + + def child_site + window(tk_call(@path, 'childsite')) + end + + def justify(dir) + tk_call(@path, 'justify', dir) + self + end + + ########################## + include TkCanvasItemConfig + + def tagid(tag) + if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag) + tag.id + elsif tag.kind_of?(Tk::Itk::Component) + tag.name + else + tag # maybe an Array of configure paramters + end + end + private :tagid + + # create a canvas item without creating a TkcItem object + def create(type, *args) + type.create(self, *args) + end + + ####################### + + def addtag(tag, mode, *args) + tk_send_without_enc('addtag', tagid(tag), mode, *args) + self + end + def addtag_above(tagOrId, target) + addtag(tagOrId, 'above', tagid(target)) + end + def addtag_all(tagOrId) + addtag(tagOrId, 'all') + end + def addtag_below(tagOrId, target) + addtag(tagOrId, 'below', tagid(target)) + end + def addtag_closest(tagOrId, x, y, halo=None, start=None) + addtag(tagOrId, 'closest', x, y, halo, start) + end + def addtag_enclosed(tagOrId, x1, y1, x2, y2) + addtag(tagOrId, 'enclosed', x1, y1, x2, y2) + end + def addtag_overlapping(tagOrId, x1, y1, x2, y2) + addtag(tagOrId, 'overlapping', x1, y1, x2, y2) + end + def addtag_withtag(tagOrId, tag) + addtag(tagOrId, 'withtag', tagid(tag)) + end + + def bbox(tagOrId, *tags) + list(tk_send_without_enc('bbox', tagid(tagOrId), + *tags.collect{|t| tagid(t)})) + end + + def itembind(tag, context, cmd=Proc.new, args=nil) + _bind([path, "bind", tagid(tag)], context, cmd, args) + self + end + + def itembind_append(tag, context, cmd=Proc.new, args=nil) + _bind_append([path, "bind", tagid(tag)], context, cmd, args) + self + end + + def itembind_remove(tag, context) + _bind_remove([path, "bind", tagid(tag)], context) + self + end + + def itembindinfo(tag, context=nil) + _bindinfo([path, "bind", tagid(tag)], context) + end + + def canvasx(screen_x, *args) + #tk_tcl2ruby(tk_send_without_enc('canvasx', screen_x, *args)) + number(tk_send_without_enc('canvasx', screen_x, *args)) + end + def canvasy(screen_y, *args) + #tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args)) + number(tk_send_without_enc('canvasy', screen_y, *args)) + end + + def coords(tag, *args) + if args == [] + tk_split_list(tk_send_without_enc('coords', tagid(tag))) + else + tk_send_without_enc('coords', tagid(tag), *(args.flatten)) + self + end + end + + def dchars(tag, first, last=None) + tk_send_without_enc('dchars', tagid(tag), + _get_eval_enc_str(first), _get_eval_enc_str(last)) + self + end + + def delete(*args) + if TkcItem::CItemID_TBL[self.path] + find('withtag', *args).each{|item| + TkcItem::CItemID_TBL[self.path].delete(item.id) + } + end + tk_send_without_enc('delete', *args.collect{|t| tagid(t)}) + self + end + alias remove delete + + def dtag(tag, tag_to_del=None) + tk_send_without_enc('dtag', tagid(tag), tag_to_del) + self + end + + def find(mode, *args) + list(tk_send_without_enc('find', mode, *args)).collect!{|id| + TkcItem.id2obj(self, id) + } + end + def find_above(target) + find('above', tagid(target)) + end + def find_all + find('all') + end + def find_below(target) + find('below', tagid(target)) + end + def find_closest(x, y, halo=None, start=None) + find('closest', x, y, halo, start) + end + def find_enclosed(x1, y1, x2, y2) + find('enclosed', x1, y1, x2, y2) + end + def find_overlapping(x1, y1, x2, y2) + find('overlapping', x1, y1, x2, y2) + end + def find_withtag(tag) + find('withtag', tag) + end + + def itemfocus(tagOrId=nil) + if tagOrId + tk_send_without_enc('focus', tagid(tagOrId)) + self + else + ret = tk_send_without_enc('focus') + if ret == "" + nil + else + TkcItem.id2obj(self, ret) + end + end + end + + def gettags(tagOrId) + list(tk_send_without_enc('gettags', tagid(tagOrId))).collect{|tag| + TkcTag.id2obj(self, tag) + } + end + + def icursor(tagOrId, index) + tk_send_without_enc('icursor', tagid(tagOrId), index) + self + end + + def index(tagOrId, index) + number(tk_send_without_enc('index', tagid(tagOrId), index)) + end + + def insert(tagOrId, index, string) + tk_send_without_enc('insert', tagid(tagOrId), index, + _get_eval_enc_str(string)) + self + end + + def lower(tag, below=nil) + if below + tk_send_without_enc('lower', tagid(tag), tagid(below)) + else + tk_send_without_enc('lower', tagid(tag)) + end + self + end + + def move(tag, x, y) + tk_send_without_enc('move', tagid(tag), x, y) + self + end + + def postscript(keys) + tk_send("postscript", *hash_kv(keys)) + end + + def raise(tag, above=nil) + if above + tk_send_without_enc('raise', tagid(tag), tagid(above)) + else + tk_send_without_enc('raise', tagid(tag)) + end + self + end + + def scale(tag, x, y, xs, ys) + tk_send_without_enc('scale', tagid(tag), x, y, xs, ys) + self + end + + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + + def select(mode, *args) + r = tk_send_without_enc('select', mode, *args) + (mode == 'item')? TkcItem.id2obj(self, r): self + end + def select_adjust(tagOrId, index) + select('adjust', tagid(tagOrId), index) + end + def select_clear + select('clear') + end + def select_from(tagOrId, index) + select('from', tagid(tagOrId), index) + end + def select_item + select('item') + end + def select_to(tagOrId, index) + select('to', tagid(tagOrId), index) + end + + def itemtype(tag) + TkcItem.type2class(tk_send('type', tagid(tag))) + end + + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end + + def yview(*index) + if index.size == 0 + list(tk_send_without_enc('yview')) + else + tk_send_without_enc('yview', *index) + self + end + end + def yview_moveto(*index) + yview('moveto', *index) + end + def yview_scroll(*index) + yview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledframe.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledframe.rb new file mode 100644 index 0000000000..8b47460357 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledframe.rb @@ -0,0 +1,59 @@ +# +# tkextlib/iwidgets/scrolledframe.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledframe < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Scrolledframe + TkCommandNames = ['::iwidgets::scrolledframe'.freeze].freeze + WidgetClassName = 'Scrolledframe'.freeze + WidgetClassNames[WidgetClassName] = self + + def child_site + window(tk_call(@path, 'childsite')) + end + + def justify(dir) + tk_call(@path, 'justify', dir) + self + end + + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end + + def yview(*index) + if index.size == 0 + list(tk_send_without_enc('yview')) + else + tk_send_without_enc('yview', *index) + self + end + end + def yview_moveto(*index) + yview('moveto', *index) + end + def yview_scroll(*index) + yview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledhtml.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledhtml.rb new file mode 100644 index 0000000000..7023d889d1 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledhtml.rb @@ -0,0 +1,43 @@ +# +# tkextlib/iwidgets/scrolledhtml.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledhtml < Tk::Iwidgets::Scrolledtext + end + end +end + +class Tk::Iwidgets::Scrolledhtml + TkCommandNames = ['::iwidgets::scrolledhtml'.freeze].freeze + WidgetClassName = 'Scrolledhtml'.freeze + WidgetClassNames[WidgetClassName] = self + + def import(href) + tk_call(@path, 'import', href) + self + end + + def import_link(href) + tk_call(@path, 'import', '-link', href) + self + end + + def pwd + tk_call(@path, 'pwd') + end + + def render(htmltext, workdir=None) + tk_call(@path, 'render', htmltext, workdir) + self + end + + def title + tk_call(@path, 'title') + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb new file mode 100644 index 0000000000..9fe23b4edc --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb @@ -0,0 +1,190 @@ +# +# tkextlib/iwidgets/scrolledlistbox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/listbox' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledlistbox < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Scrolledlistbox + TkCommandNames = ['::iwidgets::scrolledlistbox'.freeze].freeze + WidgetClassName = 'Scrolledlistbox'.freeze + WidgetClassNames[WidgetClassName] = self + + ################################ + + def initialize(*args) + super(*args) + @listbox = component_widget('listbox') + end + + def method_missing(id, *args) + if @listbox.methods.include?(id.id2name) + @listbox.__send__(id, *args) + else + super(id, *args) + end + end + + ################################ + + def clear + tk_call(@path, 'clear') + self + end + + def get_curselection + tk_call(@path, 'getcurselection') + end + + def justify(dir) + tk_call(@path, 'justify', dir) + self + end + + def selected_item_count + number(tk_call(@path, 'selecteditemcount')) + end + + def sort(*params, &b) + # see 'lsort' man page about params + if b + tk_call(@path, 'sort', '-command', proc(&b), *params) + else + tk_call(@path, 'sort', *params) + end + self + end + def sort_ascending + tk_call(@path, 'sort', 'ascending') + self + end + def sort_descending + tk_call(@path, 'sort', 'descending') + self + end + + ##################################### + + def bbox(index) + list(tk_send_without_enc('bbox', index)) + end + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + def get(*index) + _fromUTF8(tk_send_without_enc('get', *index)) + end + def insert(index, *args) + tk_send('insert', index, *args) + self + end + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + def see(index) + tk_send_without_enc('see', index) + self + end + + ##################################### + + include TkListItemConfig + + def tagid(tag) + if tag.kind_of?(Tk::Itk::Component) + tag.name + else + super(tag) + end + end + private :tagid + + ##################################### + + def activate(y) + tk_send_without_enc('activate', y) + self + end + def curselection + list(tk_send_without_enc('curselection')) + end + def get(first, last=nil) + if last + tk_split_simplelist(_fromUTF8(tk_send_without_enc('get', first, last))) + else + _fromUTF8(tk_send_without_enc('get', first)) + end + end + def nearest(y) + tk_send_without_enc('nearest', y).to_i + end + def size + tk_send_without_enc('size').to_i + end + def selection_anchor(index) + tk_send_without_enc('selection', 'anchor', index) + self + end + def selection_clear(first, last=None) + tk_send_without_enc('selection', 'clear', first, last) + self + end + def selection_includes(index) + bool(tk_send_without_enc('selection', 'includes', index)) + end + def selection_set(first, last=None) + tk_send_without_enc('selection', 'set', first, last) + self + end + + def index(index) + tk_send_without_enc('index', index).to_i + end + + ##################################### + + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end + + def yview(*index) + if index.size == 0 + list(tk_send_without_enc('yview')) + else + tk_send_without_enc('yview', *index) + self + end + end + def yview_moveto(*index) + yview('moveto', *index) + end + def yview_scroll(*index) + yview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb new file mode 100644 index 0000000000..95d1034f16 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb @@ -0,0 +1,518 @@ +# +# tkextlib/iwidgets/scrolledtext.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/text' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Scrolledtext < Tk::Iwidgets::Scrolledwidget + end + end +end + +class Tk::Iwidgets::Scrolledtext + TkCommandNames = ['::iwidgets::scrolledtext'.freeze].freeze + WidgetClassName = 'Scrolledtext'.freeze + WidgetClassNames[WidgetClassName] = self + + ################################ + + def initialize(*args) + super(*args) + @text = component_widget('text') + end + + def method_missing(id, *args) + if @text.methods.include?(id.id2name) + @text.__send__(id, *args) + else + super(id, *args) + end + end + + ################################ + + def child_site + window(tk_call(@path, 'childsite')) + end + + def clear + tk_call(@path, 'clear') + self + end + + def import(file, idx=nil) + if idx + tk_call(@path, 'import', file, index(idx)) + else + tk_call(@path, 'import', file) + end + self + end + + def export(file) + tk_call(@path, 'export', file) + self + end + + ##################################### + + include TkTextTagConfig + + def tagid(tag) + if tag.kind_of?(Tk::Itk::Component) + tag.name + else + super(tag) + end + end + private :tagid + + def bbox(index) + list(tk_send('bbox', index)) + end + def compare(idx1, op, idx2) + bool(tk_send_without_enc('compare', _get_eval_enc_str(idx1), + op, _get_eval_enc_str(idx2))) + end + + def debug + bool(tk_send_without_enc('debug')) + end + def debug=(boolean) + tk_send_without_enc('debug', boolean) + #self + boolean + end + + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + + def dlineinfo(index) + list(tk_send_without_enc('dlineinfo', _get_eval_enc_str(index))) + end + + def get(*index) + _fromUTF8(tk_send_without_enc('get', *index)) + end + def get_displaychars(*index) + # Tk8.5 feature + get('-displaychars', *index) + end + + def image_cget(index, slot) + case slot.to_s + when 'text', 'label', 'show', 'data', 'file' + _fromUTF8(tk_send_without_enc('image', 'cget', + _get_eval_enc_str(index), "-#{slot}")) + else + tk_tcl2ruby(_fromUTF8(tk_send_without_enc('image', 'cget', + _get_eval_enc_str(index), + "-#{slot}"))) + end + end + + def image_configure(index, slot, value=None) + if slot.kind_of? Hash + _fromUTF8(tk_send_without_enc('image', 'configure', + _get_eval_enc_str(index), + *hash_kv(slot, true))) + else + _fromUTF8(tk_send_without_enc('image', 'configure', + _get_eval_enc_str(index), + "-#{slot}", + _get_eval_enc_str(value))) + end + self + end + + def image_configinfo(index, slot = nil) + if TkComm::GET_CONFIGINFO_AS_ARRAY + if slot + case slot.to_s + when 'text', 'label', 'show', 'data', 'file' + conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index), "-#{slot}"))) + else + conf = tk_split_list(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index), "-#{slot}"))) + end + conf[0] = conf[0][1..-1] + conf + else + tk_split_simplelist(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index)))).collect{|conflist| + conf = tk_split_simplelist(conflist) + conf[0] = conf[0][1..-1] + case conf[0] + when 'text', 'label', 'show', 'data', 'file' + else + if conf[3] + if conf[3].index('{') + conf[3] = tk_split_list(conf[3]) + else + conf[3] = tk_tcl2ruby(conf[3]) + end + end + if conf[4] + if conf[4].index('{') + conf[4] = tk_split_list(conf[4]) + else + conf[4] = tk_tcl2ruby(conf[4]) + end + end + end + conf[1] = conf[1][1..-1] if conf.size == 2 # alias info + conf + } + end + else # ! TkComm::GET_CONFIGINFO_AS_ARRAY + if slot + case slot.to_s + when 'text', 'label', 'show', 'data', 'file' + conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index), "-#{slot}"))) + else + conf = tk_split_list(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index), "-#{slot}"))) + end + key = conf.shift[1..-1] + { key => conf } + else + ret = {} + tk_split_simplelist(_fromUTF8(tk_send_without_enc('image', 'configure', _get_eval_enc_str(index)))).each{|conflist| + conf = tk_split_simplelist(conflist) + key = conf.shift[1..-1] + case key + when 'text', 'label', 'show', 'data', 'file' + else + if conf[2] + if conf[2].index('{') + conf[2] = tk_split_list(conf[2]) + else + conf[2] = tk_tcl2ruby(conf[2]) + end + end + if conf[3] + if conf[3].index('{') + conf[3] = tk_split_list(conf[3]) + else + conf[3] = tk_tcl2ruby(conf[3]) + end + end + end + if conf.size == 1 + ret[key] = conf[0][1..-1] # alias info + else + ret[key] = conf + end + } + ret + end + end + end + + def current_image_configinfo(index, slot = nil) + if TkComm::GET_CONFIGINFO_AS_ARRAY + if slot + conf = image_configinfo(index, slot) + {conf[0] => conf[4]} + else + ret = {} + image_configinfo(index).each{|conf| + ret[conf[0]] = conf[4] if conf.size > 2 + } + ret + end + else # ! TkComm::GET_CONFIGINFO_AS_ARRAY + ret = {} + image_configinfo(index, slot).each{|k, conf| + ret[k] = conf[-1] if conf.kind_of?(Array) + } + ret + end + end + + def image_names + tk_split_simplelist(_fromUTF8(tk_send_without_enc('image', 'names'))).collect{|elt| + tagid2obj(elt) + } + end + + def index(index) + tk_send_without_enc('index', _get_eval_enc_str(index)) + end + + def insert(index, *args) + tk_send('insert', index, *args) + self + end + + def mark_names + tk_split_simplelist(_fromUTF8(tk_send_without_enc('mark', 'names'))).collect{|elt| + tagid2obj(elt) + } + end + + def mark_gravity(mark, direction=nil) + if direction + tk_send_without_enc('mark', 'gravity', + _get_eval_enc_str(mark), direction) + self + else + tk_send_without_enc('mark', 'gravity', _get_eval_enc_str(mark)) + end + end + + def mark_set(mark, index) + tk_send_without_enc('mark', 'set', _get_eval_enc_str(mark), + _get_eval_enc_str(index)) + self + end + alias set_mark mark_set + + def mark_unset(*marks) + tk_send_without_enc('mark', 'unset', + *(marks.collect{|mark| _get_eval_enc_str(mark)})) + self + end + alias unset_mark mark_unset + + def mark_next(index) + tagid2obj(_fromUTF8(tk_send_without_enc('mark', 'next', + _get_eval_enc_str(index)))) + end + alias next_mark mark_next + + def mark_previous(index) + tagid2obj(_fromUTF8(tk_send_without_enc('mark', 'previous', + _get_eval_enc_str(index)))) + end + alias previous_mark mark_previous + + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + + + def _ktext_length(txt) + if $KCODE !~ /n/i + return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length + end + + # $KCODE == 'NONE' + if JAPANIZED_TK + tk_call_without_enc('kstring', 'length', + _get_eval_enc_str(txt)).to_i + else + begin + tk_call_without_enc('encoding', 'convertto', 'ascii', + _get_eval_enc_str(txt)).length + rescue StandardError, NameError + # sorry, I have no plan + txt.length + end + end + end + private :_ktext_length + + def tksearch(*args) + # call 'search' subcommand of text widget + # args ::= [] [] + # If is regexp, then it must be a regular expression of Tcl + if args[0].kind_of?(Array) + opts = args.shift.collect{|opt| '-' + opt.to_s } + else + opts = [] + end + + opts << '--' + + ret = tk_send('search', *(opts + args)) + if ret == "" + nil + else + ret + end + end + + def tksearch_with_count(*args) + # call 'search' subcommand of text widget + # args ::= [] [] + # If is regexp, then it must be a regular expression of Tcl + if args[0].kind_of?(Array) + opts = args.shift.collect{|opt| '-' + opt.to_s } + else + opts = [] + end + + opts << '-count' << args.shift << '--' + + ret = tk_send('search', *(opts + args)) + if ret == "" + nil + else + ret + end + end + + def search_with_length(pat,start,stop=None) + pat = pat.chr if pat.kind_of? Integer + if stop != None + return ["", 0] if compare(start,'>=',stop) + txt = get(start,stop) + if (pos = txt.index(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index(start + " + #{pos} chars"), pat.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(pat), pat.dup] + else + #return [index(start + " + #{pos} chars"), $&.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(match), match] + end + else + return ["", 0] + end + else + txt = get(start,'end - 1 char') + if (pos = txt.index(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index(start + " + #{pos} chars"), pat.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(pat), pat.dup] + else + #return [index(start + " + #{pos} chars"), $&.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(match), match] + end + else + txt = get('1.0','end - 1 char') + if (pos = txt.index(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), + _ktext_length(pat), pat.dup] + else + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] + end + else + return ["", 0] + end + end + end + end + + def search(pat,start,stop=None) + search_with_length(pat,start,stop)[0] + end + + def rsearch_with_length(pat,start,stop=None) + pat = pat.chr if pat.kind_of? Integer + if stop != None + return ["", 0] if compare(start,'<=',stop) + txt = get(stop,start) + if (pos = txt.rindex(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index(stop + " + #{pos} chars"), pat.split('').length] + return [index(stop + " + #{pos} chars"), _ktext_length(pat), pat.dup] + else + #return [index(stop + " + #{pos} chars"), $&.split('').length] + return [index(stop + " + #{pos} chars"), _ktext_length(match), match] + end + else + return ["", 0] + end + else + txt = get('1.0',start) + if (pos = txt.rindex(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup] + else + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] + end + else + txt = get('1.0','end - 1 char') + if (pos = txt.rindex(pat)) + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 + if pat.kind_of? String + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup] + else + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] + end + else + return ["", 0] + end + end + end + end + + def rsearch(pat,start,stop=None) + rsearch_with_length(pat,start,stop)[0] + end + + def see(index) + tk_send_without_enc('see', index) + self + end + + ############################### + + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end + + def yview(*index) + if index.size == 0 + list(tk_send_without_enc('yview')) + else + tk_send_without_enc('yview', *index) + self + end + end + def yview_moveto(*index) + yview('moveto', *index) + end + def yview_scroll(*index) + yview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb b/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb new file mode 100644 index 0000000000..91ba9248e1 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/selectionbox.rb @@ -0,0 +1,92 @@ +# +# tkextlib/iwidgets/selectionbox.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Selectionbox < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Selectionbox + TkCommandNames = ['::iwidgets::selectionbox'.freeze].freeze + WidgetClassName = 'Selectionbox'.freeze + WidgetClassNames[WidgetClassName] = self + + def child_site + window(tk_call(@path, 'childsite')) + end + + def clear_items + tk_call(@path, 'clear', 'items') + self + end + + def clear_selection + tk_call(@path, 'clear', 'selection') + self + end + + def get + tk_call(@path, 'get') + end + + def insert_items(idx, *args) + tk_call(@path, 'insert', 'items', idx, *args) + end + + def insert_selection(pos, text) + tk_call(@path, 'insert', 'selection', pos, text) + end + + def select_item + tk_call(@path, 'selectitem') + self + end + + # based on TkListbox ( and TkTextWin ) + def curselection + list(tk_send_without_enc('curselection')) + end + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + def index(index) + tk_send_without_enc('index', index).to_i + end + def nearest(y) + tk_send_without_enc('nearest', y).to_i + end + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + def selection_anchor(index) + tk_send_without_enc('selection', 'anchor', index) + self + end + def selection_clear(first, last=None) + tk_send_without_enc('selection', 'clear', first, last) + self + end + def selection_includes(index) + bool(tk_send_without_enc('selection', 'includes', index)) + end + def selection_set(first, last=None) + tk_send_without_enc('selection', 'set', first, last) + self + end + def size + tk_send_without_enc('size').to_i + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb b/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb new file mode 100644 index 0000000000..794da5d61c --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/selectiondialog.rb @@ -0,0 +1,92 @@ +# +# tkextlib/iwidgets/selectiondialog.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Selectiondialog < Tk::Iwidgets::Dialog + end + end +end + +class Tk::Iwidgets::Selectiondialog + TkCommandNames = ['::iwidgets::selectiondialog'.freeze].freeze + WidgetClassName = 'Selectiondialog'.freeze + WidgetClassNames[WidgetClassName] = self + + def child_site + window(tk_call(@path, 'childsite')) + end + + def clear_items + tk_call(@path, 'clear', 'items') + self + end + + def clear_selection + tk_call(@path, 'clear', 'selection') + self + end + + def get + tk_call(@path, 'get') + end + + def insert_items(idx, *args) + tk_call(@path, 'insert', 'items', idx, *args) + end + + def insert_selection(pos, text) + tk_call(@path, 'insert', 'selection', pos, text) + end + + def select_item + tk_call(@path, 'selectitem') + self + end + + # based on TkListbox ( and TkTextWin ) + def curselection + list(tk_send_without_enc('curselection')) + end + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + def index(index) + tk_send_without_enc('index', index).to_i + end + def nearest(y) + tk_send_without_enc('nearest', y).to_i + end + def scan_mark(x, y) + tk_send_without_enc('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send_without_enc('scan', 'dragto', x, y) + self + end + def selection_anchor(index) + tk_send_without_enc('selection', 'anchor', index) + self + end + def selection_clear(first, last=None) + tk_send_without_enc('selection', 'clear', first, last) + self + end + def selection_includes(index) + bool(tk_send_without_enc('selection', 'includes', index)) + end + def selection_set(first, last=None) + tk_send_without_enc('selection', 'set', first, last) + self + end + def size + tk_send_without_enc('size').to_i + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/spindate.rb b/ext/tk/lib/tkextlib/iwidgets/spindate.rb new file mode 100644 index 0000000000..6099ba77b9 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/spindate.rb @@ -0,0 +1,38 @@ +# +# tkextlib/iwidgets/spindate.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Spindate < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Spindate + TkCommandNames = ['::iwidgets::spindate'.freeze].freeze + WidgetClassName = 'Spindate'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_string + tk_call(@path, 'get', '-string') + end + alias get get_string + + def get_clicks + number(tk_call(@path, 'get', '-clicks')) + end + + def show(date=None) + tk_call(@path, 'show', date) + self + end + def show_now + tk_call(@path, 'show', 'now') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/spinint.rb b/ext/tk/lib/tkextlib/iwidgets/spinint.rb new file mode 100644 index 0000000000..071b6ab8f7 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/spinint.rb @@ -0,0 +1,20 @@ +# +# tkextlib/iwidgets/spinint.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Spinint < Tk::Iwidgets::Spinner + end + end +end + +class Tk::Iwidgets::Spinint + TkCommandNames = ['::iwidgets::spinint'.freeze].freeze + WidgetClassName = 'Spinint'.freeze + WidgetClassNames[WidgetClassName] = self +end diff --git a/ext/tk/lib/tkextlib/iwidgets/spinner.rb b/ext/tk/lib/tkextlib/iwidgets/spinner.rb new file mode 100644 index 0000000000..f4f0eb46c8 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/spinner.rb @@ -0,0 +1,150 @@ +# +# tkextlib/iwidgets/spinner.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Spinner < Tk::Iwidgets::Labeledwidget + end + end +end + +class Tk::Iwidgets::Spinner + TkCommandNames = ['::iwidgets::spinner'.freeze].freeze + WidgetClassName = 'Spinner'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include Tk::ValidateConfigure + + class EntryfieldValidate < TkValidateCommand + #class CalCmdArgs < TkUtil::CallbackSubst + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?c, ?s, :char ], + [ ?P, ?s, :post ], + [ ?S, ?s, :current ], + [ ?W, ?w, :widget ], + nil + ] + PROC_TBL = [ + [ ?s, TkComm.method(:string) ], + [ ?w, TkComm.method(:window) ], + nil + ] + _setup_subst_table(KEY_TBL, PROC_TBL); + end + + def self._config_keys + ['validate', 'invalid'] + end + end + + def __validation_class_list + super << EntryfieldValidate + end + + Tk::ValidateConfigure.__def_validcmd(binding, EntryfieldValidate) + + #################################### + + def up + tk_call_without_enc(@path, 'up') + self + end + + def down + tk_call_without_enc(@path, 'down') + self + end + + def clear + tk_call_without_enc(@path, 'clear') + self + end + + def delete(first, last=None) + tk_send_without_enc('delete', first, last) + self + end + + def value + _fromUTF8(tk_send_without_enc('get')) + end + def value= (val) + tk_send_without_enc('delete', 0, 'end') + tk_send_without_enc('insert', 0, _get_eval_enc_str(val)) + val + end + alias get value + alias set value= + + def cursor=(index) + tk_send_without_enc('icursor', index) + #self + index + end + alias icursor cursor= + + def index(index) + number(tk_send_without_enc('index', index)) + end + + def insert(pos,text) + tk_send_without_enc('insert', pos, _get_eval_enc_str(text)) + self + end + + def mark(pos) + tk_send_without_enc('scan', 'mark', pos) + self + end + def dragto(pos) + tk_send_without_enc('scan', 'dragto', pos) + self + end + def selection_adjust(index) + tk_send_without_enc('selection', 'adjust', index) + self + end + def selection_clear + tk_send_without_enc('selection', 'clear') + self + end + def selection_from(index) + tk_send_without_enc('selection', 'from', index) + self + end + def selection_present() + bool(tk_send_without_enc('selection', 'present')) + end + def selection_range(s, e) + tk_send_without_enc('selection', 'range', s, e) + self + end + def selection_to(index) + tk_send_without_enc('selection', 'to', index) + self + end + + # based on tk/scrollable.rb + def xview(*index) + if index.size == 0 + list(tk_send_without_enc('xview')) + else + tk_send_without_enc('xview', *index) + self + end + end + def xview_moveto(*index) + xview('moveto', *index) + end + def xview_scroll(*index) + xview('scroll', *index) + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/spintime.rb b/ext/tk/lib/tkextlib/iwidgets/spintime.rb new file mode 100644 index 0000000000..c1e1f5e5f1 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/spintime.rb @@ -0,0 +1,38 @@ +# +# tkextlib/iwidgets/spintime.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Spintime < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Spintime + TkCommandNames = ['::iwidgets::spintime'.freeze].freeze + WidgetClassName = 'Spintime'.freeze + WidgetClassNames[WidgetClassName] = self + + def get_string + tk_call(@path, 'get', '-string') + end + alias get get_string + + def get_clicks + number(tk_call(@path, 'get', '-clicks')) + end + + def show(date=None) + tk_call(@path, 'show', date) + self + end + def show_now + tk_call(@path, 'show', 'now') + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb new file mode 100644 index 0000000000..5321331551 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/tabnotebook.rb @@ -0,0 +1,154 @@ +# +# tkextlib/iwidgets/tabnotebook.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Tabnotebook < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Tabnotebook + TkCommandNames = ['::iwidgets::tabnotebook'.freeze].freeze + WidgetClassName = 'Tabnotebook'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'tabcget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'tabconfigure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias pagecget itemcget + alias pageconfigure itemconfigure + alias pageconfiginfo itemconfiginfo + alias current_pageconfiginfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def initialize(*args) + super(*args) + @tabset = self.component_widget('tabset') + end + + def add(keys={}) + window(tk_call(@path, 'add', *hash_kv(keys))) + end + + def child_site_list + list(tk_call(@path, 'childsite')) + end + + def child_site(idx) + window(tk_call(@path, 'childsite', index(idx))) + end + + def delete(idx1, idx2=nil) + if idx2 + tk_call(@path, 'delete', index(idx1), index(idx2)) + else + tk_call(@path, 'delete', index(idx1)) + end + self + end + + def index(idx) + #number(tk_call(@path, 'index', tagid(idx))) + @tabset.index(tagid(idx)) + end + + def insert(idx, keys={}) + window(tk_call(@path, 'insert', index(idx), *hash_kv(keys))) + end + + def next + tk_call(@path, 'next') + self + end + + def prev + tk_call(@path, 'prev') + self + end + + def select(idx) + tk_call(@path, 'select', index(idx)) + self + end + + def scrollcommand(cmd=Proc.new) + configure_cmd 'scrollcommand', cmd + self + end + alias xscrollcommand scrollcommand + alias yscrollcommand scrollcommand + + def xscrollbar(bar=nil) + if bar + @scrollbar = bar + @scrollbar.orient 'horizontal' + self.scrollcommand {|*arg| @scrollbar.set(*arg)} + @scrollbar.command {|*arg| self.xview(*arg)} + Tk.update # avoid scrollbar trouble + end + @scrollbar + end + def yscrollbar(bar=nil) + if bar + @scrollbar = bar + @scrollbar.orient 'vertical' + self.scrollcommand {|*arg| @scrollbar.set(*arg)} + @scrollbar.command {|*arg| self.yview(*arg)} + Tk.update # avoid scrollbar trouble + end + @scrollbar + end + alias scrollbar yscrollbar + + def view(*index) + if index.size == 0 + window(tk_send_without_enc('view')) + else + tk_send_without_enc('view', *index) + self + end + end + alias xview view + alias yview view + + def view_moveto(*index) + view('moveto', *index) + end + alias xview_moveto view_moveto + alias yview_moveto view_moveto + def view_scroll(*index) + view('scroll', *index) + end + alias xview_scroll view_scroll + alias yview_scroll view_scroll +end diff --git a/ext/tk/lib/tkextlib/iwidgets/tabset.rb b/ext/tk/lib/tkextlib/iwidgets/tabset.rb new file mode 100644 index 0000000000..1b76916ab7 --- /dev/null +++ b/ext/tk/lib/tkextlib/iwidgets/tabset.rb @@ -0,0 +1,89 @@ +# +# tkextlib/iwidgets/tabset.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tkextlib/iwidgets.rb' + +module Tk + module Iwidgets + class Tabset < Tk::Itk::Widget + end + end +end + +class Tk::Iwidgets::Tabset + TkCommandNames = ['::iwidgets::tabset'.freeze].freeze + WidgetClassName = 'Tabset'.freeze + WidgetClassNames[WidgetClassName] = self + + #################################### + + include TkItemConfigMethod + + def __item_cget_cmd(id) + [self.path, 'tabcget', id] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'tabconfigure', id] + end + private :__item_config_cmd + + def tagid(tagOrId) + if tagOrId.kind_of?(Tk::Itk::Component) + tagOrId.name + else + #_get_eval_string(tagOrId) + tagOrId + end + end + + alias tabcget itemcget + alias tabconfigure itemconfigure + alias tabconfiginfo itemconfiginfo + alias current_tabconfiginfo current_itemconfiginfo + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo + + #################################### + + def add(keys={}) + window(tk_call(@path, 'add', *hash_kv(keys))) + end + + def delete(idx1, idx2=nil) + if idx2 + tk_call(@path, 'delete', index(idx1), index(idx2)) + else + tk_call(@path, 'delete', index(idx1)) + end + self + end + + def index(idx) + number(tk_call(@path, 'index', tagid(idx))) + end + + def insert(idx, keys={}) + window(tk_call(@path, 'insert', index(idx), *hash_kv(keys))) + end + + def next + tk_call(@path, 'next') + self + end + + def prev + tk_call(@path, 'prev') + self + end + + def select(idx) + tk_call(@path, 'select', index(idx)) + self + end +end diff --git a/ext/tk/lib/tkextlib/iwidgets/toolbar.rb b/ext/tk/lib/tkextlib/iwidgets/toolbar.rb index 81239f9b97..fffd5b388c 100644 --- a/ext/tk/lib/tkextlib/iwidgets/toolbar.rb +++ b/ext/tk/lib/tkextlib/iwidgets/toolbar.rb @@ -22,6 +22,16 @@ class Tk::Iwidgets::Toolbar include TkItemConfigMethod + def __item_cget_cmd(id) + [self.path, 'itemcget', self.index(id)] + end + private :__item_cget_cmd + + def __item_config_cmd(id) + [self.path, 'itemconfigure', self.index(id)] + end + private :__item_config_cmd + def tagid(tagOrId) if tagOrId.kind_of?(Tk::Itk::Component) tagOrId.name @@ -38,10 +48,12 @@ class Tk::Iwidgets::Toolbar keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end - tk_call(@path, 'add', type, tagid(tag), *hash_kv(keys)) + window(tk_call(@path, 'add', type, tagid(tag), *hash_kv(keys))) tag end @@ -63,24 +75,13 @@ class Tk::Iwidgets::Toolbar keys = tag tag = nil end - unless tag + if tag + tag = Tk::Itk::Component.new(self, tagid(tag)) + else tag = Tk::Itk::Component.new(self) end - tk_call(@path, 'insert', index(idx), type, tagid(tag), *hash_kv(keys)) + window(tk_call(@path, 'insert', index(idx), type, + tagid(tag), *hash_kv(keys))) tag end - - def invoke(idx=nil) - if idx - tk_call(@path, 'invoke', index(idx)) - else - tk_call(@path, 'invoke') - end - self - end - - def show(idx) - tk_call(@path, 'show', index(idx)) - self - end end diff --git a/ext/tk/lib/tkextlib/tcllib.rb b/ext/tk/lib/tkextlib/tcllib.rb index 831cc5a327..8810943b5b 100644 --- a/ext/tk/lib/tkextlib/tcllib.rb +++ b/ext/tk/lib/tkextlib/tcllib.rb @@ -29,7 +29,7 @@ rescue => e err << "\n ['" << target << "'] " << e.class.name << ' : ' << e.message end -# package:: style +# package:: cursor target = 'tkextlib/tcllib/style' begin require target @@ -40,6 +40,8 @@ end # autoload module Tk module Tcllib + TkComm::TkExtlibAutoloadModule.unshift(self) + # package:: ctext autoload :CText, 'tkextlib/tcllib/ctext' @@ -49,6 +51,7 @@ module Tk # package:: ipentry autoload :IP_Entry, 'tkextlib/tcllib/ip_entry' + autoload :IPEntry, 'tkextlib/tcllib/ip_entry' # package:: Plotchart autoload :Plotchart, 'tkextlib/tcllib/plotchart' @@ -58,7 +61,6 @@ module Tk end end -unless err.empty? +if $VERBOSE && !err.empty? warn("Warning: some sub-packages are failed to require : " + err) end - diff --git a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb index 117ed8d98a..d0cb2812cb 100644 --- a/ext/tk/lib/tkextlib/tcllib/autoscroll.rb +++ b/ext/tk/lib/tkextlib/tcllib/autoscroll.rb @@ -38,31 +38,40 @@ module Tk '' end end + + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/autoscroll' extension is not available on your current environment." + end + + def self.autoscroll(win) + Tk::Tcllib::Autoscroll.not_available + end + + def self.unautoscroll(win) + Tk::Tcllib::Autoscroll.not_available + end end end end -# TkPackage.require('autoscroll', '1.0') -TkPackage.require('autoscroll') - module Tk module Scrollable def autoscroll(mode = nil) case mode when :x, 'x' if @xscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar) end when :y, 'y' if @yscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar) end when nil, :both, 'both' if @xscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@xscrollbar) end if @yscrollbar - tk_send_without_enc('::autoscroll::autoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.autoscroll(@yscrollbar) end else fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected" @@ -73,18 +82,18 @@ module Tk case mode when :x, 'x' if @xscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar) end when :y, 'y' if @yscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar) end when nil, :both, 'both' if @xscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @xscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@xscrollbar) end if @yscrollbar - tk_send_without_enc('::autoscroll::unautoscroll', @yscrollbar) + Tk::Tcllib::Autoscroll.unautoscroll(@yscrollbar) end else fail ArgumentError, "'x', 'y' or 'both' (String or Symbol) is expected" @@ -98,12 +107,36 @@ class TkScrollbar def autoscroll # Arranges for the already existing scrollbar to be mapped # and unmapped as needed. - tk_send_without_enc('::autoscroll::autoscroll', @path) + #tk_call_without_enc('::autoscroll::autoscroll', @path) + Tk::Tcllib::Autoscroll.autoscroll(self) self end def unautoscroll # Returns the scrollbar to its original static state. - tk_send_without_enc('::autoscroll::unautoscroll', @path) + #tk_call_without_enc('::autoscroll::unautoscroll', @path) + Tk::Tcllib::Autoscroll.unautoscroll(self) self end end + +# TkPackage.require('autoscroll', '1.0') +TkPackage.require('autoscroll') + +module Tk + module Tcllib + class << Autoscroll + undef not_available + end + + module Autoscroll + def self.autoscroll(win) + tk_call_without_enc('::autoscroll::autoscroll', win.path) + end + + def self.unautoscroll(win) + tk_call_without_enc('::autoscroll::unautoscroll', win.path) + end + end + end +end + diff --git a/ext/tk/lib/tkextlib/tcllib/cursor.rb b/ext/tk/lib/tkextlib/tcllib/cursor.rb index 119b8a143f..8813aa05dd 100644 --- a/ext/tk/lib/tkextlib/tcllib/cursor.rb +++ b/ext/tk/lib/tkextlib/tcllib/cursor.rb @@ -9,19 +9,32 @@ require 'tk' require 'tkextlib/tcllib.rb' -# TkPackage.require('cursor', '0.1') -TkPackage.require('cursor') - module Tk module Tcllib module Cursor def self.package_version begin - TkPackage.require('ipentry') + TkPackage.require('cursor') rescue '' end end + + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/cursor' extension is not available on your current environment." + end + + def self.cursor_display(win=None) + Tk::Tcllib::Cursor.not_available + end + + def self.cursor_propagate(win, cursor) + Tk::Tcllib::Cursor.not_available + end + + def self.cursor_restore(win, cursor = None) + Tk::Tcllib::Cursor.not_available + end end end @@ -29,20 +42,48 @@ module Tk # Pops up a dialog with a listbox containing all the cursor names. # Selecting a cursor name will display it in that dialog. # This is simply for viewing any available cursors on the platform . - tk_call_without_enc('::cursor::display', parent) + #tk_call_without_enc('::cursor::display', parent) + Tk::Tcllib::Cursor.cursor_display(parent) end end class TkWindow def cursor_propagate(cursor) # Sets the cursor for self and all its descendants to cursor. - tk_send_without_enc('::cursor::propagate', @path, cursor) + #tk_call_without_enc('::cursor::propagate', @path, cursor) + Tk::Tcllib::Cursor.cursor_propagate(cursor) end def cursor_restore(cursor = None) # Restore the original or previously set cursor for self and all its # descendants. If cursor is specified, that will be used if on any # widget that did not have a preset cursor (set by a previous call # to TkWindow#cursor_propagate). - tk_send_without_enc('::cursor::restore', @path, cursor) + #tk_call_without_enc('::cursor::restore', @path, cursor) + Tk::Tcllib::Cursor.cursor_restore(cursor) + end +end + +# TkPackage.require('cursor', '0.1') +TkPackage.require('cursor') + +module Tk + module Tcllib + class << Cursor + undef not_available + end + + module Cursor + def self.cursor_display(win=None) + tk_call_without_enc('::cursor::display', win) + end + + def self.cursor_propagate(win, cursor) + tk_call_without_enc('::cursor::propagate', win.path, cursor) + end + + def self.cursor_restore(win, cursor = None) + tk_call_without_enc('::cursor::restore', win.path, cursor) + end + end end end diff --git a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb index 748478a322..977ef4e5c8 100644 --- a/ext/tk/lib/tkextlib/tcllib/ip_entry.rb +++ b/ext/tk/lib/tkextlib/tcllib/ip_entry.rb @@ -27,6 +27,7 @@ module Tk end end end + IPEntry = IP_Entry end end diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb index b22a4ebbdf..65451a27a9 100644 --- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb +++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb @@ -221,7 +221,10 @@ module Tk::Tcllib::Plotchart class XYPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createXYPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createXYPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis [, keys]) # xaxis := Array of [minimum, maximum, stepsize] @@ -248,12 +251,16 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis)) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, x, y) tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series), x, y) self @@ -271,14 +278,20 @@ module Tk::Tcllib::Plotchart ############################ class Stripchart < XYPlot - TkCommandNames = ['::Plotchart::createStripchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createStripchart'.freeze + ].freeze end ############################ class PolarPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createPolarplot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createPolarplot'.freeze + ].freeze def initialize(*args) # args := ([parent,] radius_data [, keys]) # radius_data := Array of [maximum_radius, stepsize] @@ -302,12 +315,16 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@radius_data)) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, radius, angle) tk_call_without_enc(@chart, 'plot', _get_eval_enc_str(series), radius, angle) @@ -329,7 +346,10 @@ module Tk::Tcllib::Plotchart class IsometricPlot < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createIsometricPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createIsometricPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis, [, step] [, keys]) # xaxis := Array of [minimum, maximum] @@ -369,8 +389,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis), @stepsize) end @@ -406,7 +426,10 @@ module Tk::Tcllib::Plotchart class Plot3D < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::create3DPlot'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::create3DPlot'.freeze + ].freeze def initialize(*args) # args := ([parent,] xaxis, yaxis, zaxis [, keys]) # xaxis := Array of [minimum, maximum, stepsize] @@ -436,8 +459,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xaxis), array2tk_list(@yaxis), array2tk_list(@zaxis)) @@ -478,7 +501,10 @@ module Tk::Tcllib::Plotchart class Piechart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createPiechart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createPiechart'.freeze + ].freeze def initialize(*args) # args := ([parent] [, keys]) if args[0].kind_of?(TkCanvas) @@ -491,8 +517,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path) + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path) end private :_create_chart @@ -506,7 +532,10 @@ module Tk::Tcllib::Plotchart class Barchart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createBarchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createBarchart'.freeze + ].freeze def initialize(*args) # args := ([parent,] xlabels, ylabels [, series] [, keys]) @@ -549,13 +578,17 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, array2tk_list(@xlabels), array2tk_list(@ylabels), @series_size) end private :_create_chart + def __destroy_hook__ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + end + def plot(series, dat, col=None) tk_call_without_enc(@chart, 'plot', series, dat, col) self @@ -573,14 +606,20 @@ module Tk::Tcllib::Plotchart ############################ class HorizontalBarchart < Barchart - TkCommandNames = ['::Plotchart::createHorizontalBarchart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createHorizontalBarchart'.freeze + ].freeze end ############################ class Timechart < TkCanvas include ChartMethod - TkCommandNames = ['::Plotchart::createTimechart'.freeze].freeze + TkCommandNames = [ + 'canvas'.freeze, + '::Plotchart::createTimechart'.freeze + ].freeze def initialize(*args) # args := ([parent,] time_begin, time_end, items [, keys]) @@ -612,8 +651,8 @@ module Tk::Tcllib::Plotchart end def _create_chart - p self.class::TkCommandNames[0] if $DEBUG - tk_call_without_enc(self.class::TkCommandNames[0], @path, + p self.class::TkCommandNames[1] if $DEBUG + tk_call_without_enc(self.class::TkCommandNames[1], @path, @time_begin, @time_end, @items) end private :_create_chart @@ -650,7 +689,7 @@ module Tk::Tcllib::Plotchart @parent = @chart_obj = chart @ppath = @chart_obj.path @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_) - SeriesID_TBL[@id] = self + # SeriesID_TBL[@id] = self SeriesID_TBL[@ppath] = {} unless SeriesID_TBL[@ppath] SeriesID_TBL[@ppath][@id] = self Series_ID[1].succ! diff --git a/ext/tk/lib/tkextlib/tcllib/style.rb b/ext/tk/lib/tkextlib/tcllib/style.rb index dea2962b7f..17fc834ccb 100644 --- a/ext/tk/lib/tkextlib/tcllib/style.rb +++ b/ext/tk/lib/tkextlib/tcllib/style.rb @@ -9,10 +9,7 @@ require 'tk' require 'tkextlib/tcllib.rb' -# TkPackage.require('style', '0.1') -TkPackage.require('style') - -module Tk +module Tk::Tcllib module Style def self.package_version begin @@ -22,6 +19,29 @@ module Tk end end + def self.not_available + fail RuntimeError, "'tkextlib/tcllib/style' extension is not available on your current environment." + end + + def self.names + Tk::Tcllib::Style.not_available + end + + def self.use(style) + Tk::Tcllib::Style.not_available + end + end +end + +# TkPackage.require('style', '0.1') +TkPackage.require('style') + +module Tk::Tcllib + class << Style + undef not_available + end + + module Style def self.names tk_split_simplelist(tk_call('style::names')) end diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb index 7633981559..91c01ca736 100644 --- a/ext/tk/lib/tkextlib/tile.rb +++ b/ext/tk/lib/tkextlib/tile.rb @@ -18,6 +18,8 @@ TkPackage.require('tile') # autoload module Tk module Tile + TkComm::TkExtlibAutoloadModule.unshift(self) + def self.package_version begin TkPackage.require('tile') diff --git a/ext/tk/lib/tkextlib/tktable.rb b/ext/tk/lib/tkextlib/tktable.rb new file mode 100644 index 0000000000..385eb13497 --- /dev/null +++ b/ext/tk/lib/tkextlib/tktable.rb @@ -0,0 +1,14 @@ +# +# TkTable support +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tktable/setup.rb' + +# load library +require 'tkextlib/tktable/tktable' diff --git a/ext/tk/lib/tkextlib/tktable/setup.rb b/ext/tk/lib/tkextlib/tktable/setup.rb new file mode 100644 index 0000000000..ce0f0bd4d4 --- /dev/null +++ b/ext/tk/lib/tkextlib/tktable/setup.rb @@ -0,0 +1,8 @@ +# +# setup.rb -- setup script before calling TkPackage.require() +# +# If you need some setup operations (for example, add a library path +# to the library search path) before using Tcl/Tk library packages +# wrapped by Ruby scripts in this directory, please write the setup +# operations in this file. +# diff --git a/ext/tk/lib/tkextlib/tktable/tktable.rb b/ext/tk/lib/tkextlib/tktable/tktable.rb new file mode 100644 index 0000000000..18751fca6c --- /dev/null +++ b/ext/tk/lib/tkextlib/tktable/tktable.rb @@ -0,0 +1,796 @@ +# +# tkextlib/tktable/tktable.rb +# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) +# + +require 'tk' +require 'tk/validation' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tktable/setup.rb' + +# TkPackage.require('Tktable', '2.8') +TkPackage.require('Tktable') + +module Tk + class TkTable < TkWindow + def self.package_version + begin + TkPackage.require('Tktable') + rescue + '' + end + end + + class CellTag < TkObject + end + + module ConfigMethod + end + end +end + +module Tk::TkTable::ConfigMethod + include TkItemConfigMethod + + def __item_cget_cmd(id) # id := [ type, tagOrId ] + [self.path, id[0], 'cget', id[1]] + end + private :__item_cget_cmd + + def __item_config_cmd(id) # id := [ type, tagOrId ] + [self.path, id[0], 'configure', id[1]] + end + private :__item_config_cmd + + def __item_pathname(id) + if id.kind_of?(Array) + id = tagid(id[1]) + end + [self.path, id].join(';') + end + private :__item_pathname + + def tag_cget(tagOrId, option) + itemcget(['tag', tagid(tagOrId)], option) + end + def tag_configure(tagOrId, slot, value=None) + itemconfigure(['tag', tagid(tagOrId)], slot, value) + end + def tag_configinfo(tagOrId, slot=nil) + itemconfigure(['tag', tagid(tagOrId)], slot) + end + def current_tag_configinfo(tagOrId, slot=nil) + itemconfigure(['tag', tagid(tagOrId)], slot) + end + + def window_cget(tagOrId, option) + itemcget(['window', tagid(tagOrId)], option) + end + def window_configure(tagOrId, slot, value=None) + itemconfigure(['window', tagid(tagOrId)], slot, value) + end + def window_configinfo(tagOrId, slot=nil) + itemconfigure(['window', tagid(tagOrId)], slot) + end + def current_window_configinfo(tagOrId, slot=nil) + itemconfigure(['window', tagid(tagOrId)], slot) + end + + private :itemcget, :itemconfigure + private :itemconfiginfo, :current_itemconfiginfo +end + +##################################################### + +class Tk::TkTable::CellTag + include TkTreatTagFont + + CellTagID_TBL = TkCore::INTERP.create_table + CellTag_ID = ['tktbl:celltag'.freeze, '00000'.taint].freeze + + TkCore::INTERP.init_ip_env{ CellTagID_TBL.clear } + + def self.id2obj(table, id) + tpath = table.path + return id unless CellTagID_TBL[tpath] + CellTagID_TBL[tpath][id]? CellTagID_TBL[tpath][id] : id + end + + def initialize(parent, keys=nil) + @parent = @t = parent + @tpath - parent.path + @path = @id = CellTag_ID.join(TkCore::INTERP._ip_id_) + CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] + CellTagID_TBL[@tpath][@id] = self + CellTag_ID[1].succ! + configure(keys) if keys + end + + def id + @id + end + + def destroy + tk_call(@tpath, 'tag', 'delete', @id) + CellTagID_TBL[@tpath].delete(@id) if CellTagID_TBL[@tpath] + self + end + alias delete destroy + + def exist? + @t.tag_exist?(@id) + end + def include?(idx) + @t.tag_include?(@id, idx) + end + + def add_cell(*args) + @t.tag_cell(@id, *args) + end + def add_col(*args) + @t.tag_col(@id, *args) + end + def add_row(*args) + @t.tag_row(@id, *args) + end + + def raise(target=None) + @t.tag_raise(@id, target) + end + def lower(target=None) + @t.tag_lower(@id, target) + end + + def cget(key) + @t.tag_cget(@id, key) + end + def configure(key, val=None) + @t.tag_configure(@id, key, val) + end + def configinfo(key=nil) + @t.tag_configinfo(@id, key) + end + def current_configinfo(key=nil) + @t.current_tag_configinfo(@id, key) + end +end + +class Tk::TkTable::NamedCellTag < Tk::TkTable::CellTag + def self.new(parent, name, keys=nil) + if CellTagID_TBL[parent.path] && CellTagID_TBL[parent.path][name] + cell = CellTagID_TBL[parent.path][name] + cell.configure(keys) if keys + return cell + else + super(parent, name, keys) + end + end + + def initialize(parent, name, keys=nil) + @parent = @t = parent + @tpath - parent.path + @path = @id = name + CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] + CellTagID_TBL[@tpath][@id] = self + configure(keys) if keys + end +end + +##################################################### + +class Tk::TkTable + TkCommandNames = ['table'.freeze].freeze + WidgetClassName = 'Table'.freeze + WidgetClassNames[WidgetClassName] = self + + include Scrollable + include Tk::TkTable::ConfigMethod + include Tk::ValidateConfigure + + def __destroy_hook__ + Tk::TkTable::CelTag::CellTagID_TBL.delete(@path) + end + + ################################# + + class BrowseCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?c, ?n, :column ], + [ ?C, ?s, :index ], + [ ?i, ?x, :cursor ], + [ ?r, ?n, :row ], + [ ?s, ?s, :last_index ], + [ ?S, ?s, :new_index ], + [ ?W, ?w, :widget ], + nil + ] + + PROC_TBL = [ + [ ?n, TkComm.method(:number) ], + [ ?x, TkComm.method(:num_or_str) ], + [ ?s, TkComm.method(:string) ], + [ ?w, TkComm.method(:window) ], + nil + ] + + _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + val + end + end + + def self._config_keys + ['browsecommand', 'browsecmd'] + end + end + #-------------------------------- + class CellCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?c, ?n, :column ], + [ ?C, ?s, :index ], + [ ?i, ?m, :rw_mode ], + [ ?r, ?n, :row ], + [ ?s, ?v, :value ], + [ ?W, ?w, :widget ], + nil + ] + + PROC_TBL = [ + [ ?n, TkComm.method(:number) ], + [ ?s, TkComm.method(:string) ], + [ ?w, TkComm.method(:window) ], + [ ?m, proc{|val| (val == '0')? (:r) : (:w)} ], + [ ?v, proc{|val| TkComm.tk_tcl2ruby(val, true, false)} ], + nil + ] + + _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + TkComm._get_eval_string(val) + end + end + + def self._config_keys + ['command'] + end + end + #-------------------------------- + class SelectionCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?c, ?n, :sel_columns ], + [ ?C, ?s, :sel_area ], + [ ?i, ?n, :total ], + [ ?r, ?n, :sel_rows ], + [ ?s, ?s, :value ], + [ ?W, ?w, :widget ], + nil + ] + + PROC_TBL = [ + [ ?n, TkComm.method(:number) ], + [ ?s, TkComm.method(:string) ], + [ ?w, TkComm.method(:window) ], + nil + ] + + _setup_subst_table(KEY_TBL, PROC_TBL); + + def self.ret_val(val) + val.to_s + end + end + + def self._config_keys + ['selectioncommand', 'selcmd'] + end + end + #-------------------------------- + class ValidateCommand < TkValidateCommand + class ValidateArgs < TkUtil::CallbackSubst + KEY_TBL = [ + [ ?c, ?n, :column ], + [ ?C, ?s, :index ], + [ ?i, ?x, :cursor ], + [ ?r, ?n, :row ], + [ ?s, ?v, :current_value ], + [ ?S, ?v, :new_value ], + [ ?W, ?w, :widget ], + nil + ] + + PROC_TBL = [ + [ ?n, TkComm.method(:number) ], + [ ?x, TkComm.method(:num_or_str) ], + [ ?s, TkComm.method(:string) ], + [ ?w, TkComm.method(:window) ], + [ ?v, proc{|val| TkComm.tk_tcl2ruby(val, true, false)} ], + nil + ] + + _setup_subst_table(KEY_TBL, PROC_TBL); + end + + def self._config_keys + ['vcmd', 'validatecommand'] + end + end + + ################################# + + def __validation_class_list + super << + BrowseCommand << CellCommand << SelectionCommand << ValidateCommand + end + + Tk::ValidateConfigure.__def_validcmd(binding, BrowseCommand) + Tk::ValidateConfigure.__def_validcmd(binding, CellCommand) + Tk::ValidateConfigure.__def_validcmd(binding, SelectionCommand) + Tk::ValidateConfigure.__def_validcmd(binding, ValidateCommand) + + ################################# + + def activate(idx) + tk_send('activate', tagid(idx)) + end + + def bbox(idx) + list(tk_send('bbox', tagid(idx))) + end + + def border_mark(x, y) + simplelist(tk_send('scan', 'mark', x, y)) + end + def border_mark_row(x, y) + tk_send('scan', 'mark', x, y, 'row') + end + def border_mark_col(x, y) + tk_send('scan', 'mark', x, y, 'col') + end + def border_dragto(x, y) + tk_send('scan', 'dragto', x, y) + end + + def clear_cache(first=None, last=None) + tk_send('clear', 'cache', tagid(first), tagid(last)) + self + end + def clear_sizes(first=None, last=None) + tk_send('clear', 'sizes', tagid(first), tagid(last)) + self + end + def clear_tags(first=None, last=None) + tk_send('clear', 'tags', tagid(first), tagid(last)) + self + end + def clear_all(first=None, last=None) + tk_send('clear', 'all', tagid(first), tagid(last)) + self + end + + def curselection + simplelist(tk_send('curselection')) + end + def curselection=(val) + tk_send('curselection', val) + val + end + + def curvalue + tk_tcl2ruby(tk_send('curvalue'), true, false) + end + def curvalue=(val) + tk_send('curvalue', val) + val + end + + def delete_active(idx1, idx2=None) + tk_send('delete', 'active', tagid(idx1), tagid(idx2)) + self + end + def delete_cols(*args) # ?switches_array?, index, ?count? + params = [] + if args[0].kind_of?(Array) + switches = args.shift + switches.each{|k| params << "-#{k}"} + end + params << '--' + params << tagid(args.shift) + params.concat(args) + tk_send('delete', 'cols', *params) + self + end + def delete_rows(*args) # ?switches_array?, index, ?count? + params = [] + if args[0].kind_of?(Array) + switches = args.shift + switches.each{|k| params << "-#{k}"} + end + params << '--' + params << tagid(args.shift) + params.concat(args) + tk_send('delete', 'rows', *params) + self + end + + def get(idx) + tk_tcl2ruby(tk_send('get', tagid(idx)), true, false) + end + def get_area(idx1, idx2) + simplelist(tk_send('get', tagid(idx1), tagid(idx2))).collect{|v| + tk_tcl2ruby(v, true, false) + } + end + + def height_list + list(tk_send('height')) + end + def height(row) + number(tk_send('height', row)) + end + def set_height(*pairs) + tk_send('height', *(pairs.flatten)) + self + end + + def hidden_list + simplelist(tk_send('hidden')) + end + def hidden?(idx, *args) + if args.empty? + if (ret = tk_send('hidden', tagid(idx))) == '' + false + else + ret + end + else + bool(tk_send('hidden', tagid(idx), *(args.collect{|i| tagid(i)}))) + end + end + + def icursor + number(tk_send('icursor')) + end + def icursor_set(idx) + number(tk_send('icursor', tagid(idx))) + end + + def index(idx) + tk_send('index', tagid(idx)) + end + def row_index(idx) + number(tk_send('index', tagid(idx), 'row')) + end + def col_index(idx) + number(tk_send('index', tagid(idx), 'col')) + end + + def insert_active(idx, val) + tk_send('insert', 'active', tagid(idx), val) + self + end + def insert_cols(*args) # ?switches_array?, index, ?count? + params = [] + if args[0].kind_of?(Array) + switches = args.shift + switches.each{|k| params << "-#{k}"} + end + params << '--' + params.concat(args) + params << tagid(args.shift) + tk_send('insert', 'cols', *params) + self + end + def insert_rows(*args) # ?switches_array?, index, ?count? + params = [] + if args[0].kind_of?(Array) + switches = args.shift + switches.each{|k| params << "-#{k}"} + end + params << '--' + params << tagid(args.shift) + params.concat(args) + tk_send('insert', 'rows', *params) + self + end + + # def postscript(*args) + # tk_send('postscript', *args) + # end + + def reread + tk_send('reread') + self + end + + def scan_mark(x, y) + tk_send('scan', 'mark', x, y) + self + end + def scan_dragto(x, y) + tk_send('scan', 'dragto', x, y) + self + end + + def see(idx) + tk_send('see', tagid(idx)) + self + end + + def selection_anchor(idx) + tk_send('selection', 'anchor', tagid(idx)) + self + end + def selection_clear(first, last=None) + tk_send('selection', 'clear', tagid(first), tagid(last)) + self + end + def selection_clear_all + selection_clear('all') + end + def selection_include?(idx) + bool(tk_send('selection', 'includes', tagid(idx))) + end + def selection_set(first, last=None) + tk_send('selection', 'set', tagid(first), tagid(last)) + self + end + + def set(*pairs) # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', *args) + self + end + def set_row(*pairs) # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', 'row', *args) + self + end + def set_col(*pairs) # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', 'col', *args) + self + end +=begin + def set(*pairs) # idx, val, idx, val, ... OR [idx, val], [idx, val], ... + if pairs[0].kind_of?(Array) + # [idx, val], [idx, val], ... + args = [] + pairs.each{|idx, val| args << tagid(idx) << val } + tk_send('set', *args) + else + # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', *args) + end + self + end + def set_row(*pairs) + if pairs[0].kind_of?(Array) + # [idx, val], [idx, val], ... + args = [] + pairs.each{|idx, val| args << tagid(idx) << val } + tk_send('set', 'row', *args) + else + # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', 'row', *args) + end + self + end + def set_col(*pairs) + if pairs[0].kind_of?(Array) + # [idx, val], [idx, val], ... + args = [] + pairs.each{|idx, val| args << idx << val } + tk_send('set', 'col', *args) + else + # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + args << pairs[i+1] + } + tk_send('set', 'col', *args) + end + self + end +=end + + def spans + simplelist(tk_send('spans')).collect{|inf| + lst = simplelist(inf) + idx = lst[0] + rows, cols = lst[1].split(',').map!{|n| Integer(n)} + [idx [rows, cols]] + } + end + alias span_list spans + def span(idx) + lst = simplelist(tk_send('spans', tagid(idx))) + idx = lst[0] + rows, cols = lst[1].split(',').map!{|n| Integer(n)} + [idx [rows, cols]] + end + def set_spans(*pairs) + # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + val = pairs[i+1] + if val.kind_of?(Array) + args << val.join(',') + else + args << val + end + } + tk_send('spans', *args) + self + end +=begin + def set_spans(*pairs) + if pairs[0].kind_of?(Array) + # [idx, val], [idx, val], ... + args = [] + pairs.each{|idx, val| + args << tagid(idx) + if val.kind_of?(Array) + args << val.join(',') + else + args << val + end + } + tk_send('spans', *args) + else + # idx, val, idx, val, ... + args = [] + 0.step(pairs.size-1, 2){|i| + args << tagid(pairs[i]) + val = pairs[i+1] + if val.kind_of?(Array) + args << val.join(',') + else + args << val + end + } + tk_send('spans', *args) + end + self + end +=end + + def tagid(tag) + if tag.kind_of?(Tk::TkTable::CellTag) + tag.id + elsif tag.kind_of?(Array) + if tag[0].kind_of?(Integer) && tag[1].kind_of?(Integer) + # [row, col] + tag.join(',') + else + tag + end + else + tag + end + end + + def tagid2obj(tagid) + if Tk::TkTable::CellTag::CellTagID_TBL.key?(@path) + if Tk::TkTable::CellTag::CellTagID_TBL[@path].key?(tagid) + Tk::TkTable::CellTag::CellTagID_TBL[@path][tagid] + else + tagid + end + else + tagid + end + end + + def tag_cell(tag, *cells) + tk_send('tag', 'cell', tagid(tag), *(cells.collect{|idx| tagid(idx)})) + self + end + def tag_reset(*cells) + tk_send('tag', 'cell', '', *(cells.collect{|idx| tagid(idx)})) + self + end + def tag_col(tag, *cols) + tk_send('tag', 'col', tagid(tag), *cols) + self + end + def tag_col_reset(*cols) + tk_send('tag', 'col', '', *cols) + self + end + def tag_delete(tag) + tk_send('tag', 'delete', tagid(tag)) + if Tk::TkTable::CellTag::CellTagID_TBL[@path] + if tag.kind_of? Tk::TkTable::CellTag + Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag.id) + else + Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag) + end + end + self + end + def tag_exist?(tag) + bool(tk_send('tag', 'exists', tagid(tag))) + end + def tag_include?(tag, idx) + bool(tk_send('tag', 'includes', tagid(tag), tagid(idx))) + end + def tag_lower(tag, target=None) + tk_send('tag', 'lower', tagid(tag), tagid(target)) + self + end + def tag_names(pat=None) + simplelist(tk_send('tag', 'names', pat)).collect{|tag| tagid2obj(tag)} + end + def tag_raise(tag, target=None) + tk_send('tag', 'raise', tagid(tag), tagid(target)) + self + end + def tag_row(tag, *rows) + tk_send('tag', 'row', tagid(tag), *rows) + self + end + def tag_row_reset(*rows) + tk_send('tag', 'row', '', *rows) + self + end + + def validate(idx) + bool(tk_send('validate', tagid(idx))) + end + + def width_list + list(tk_send('width')) + end + def width(row) + number(tk_send('width', row)) + end + def set_width(*pairs) + tk_send('width', *(pairs.flatten)) + self + end + + def window_delete(*args) + tk_send('window', 'delete', *(args.collect{|idx| tagid(idx)})) + self + end + def window_move(from_idx, to_idx) + tk_send('window', 'move', tagid(from_idx), tagid(to_idx)) + self + end + def window_names(pat=None) + simplelist(tk_send('window', 'names', pat)) + end +end diff --git a/ext/tk/lib/tkextlib/vu.rb b/ext/tk/lib/tkextlib/vu.rb index 4d61243340..d3809f05b7 100644 --- a/ext/tk/lib/tkextlib/vu.rb +++ b/ext/tk/lib/tkextlib/vu.rb @@ -18,6 +18,8 @@ TkPackage.require('vu') # autoload module Tk module Vu + TkComm::TkExtlibAutoloadModule.unshift(self) + def self.package_version begin TkPackage.require('vu') diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb index b4506e10b5..dc676ad765 100644 --- a/ext/tk/lib/tkextlib/vu/pie.rb +++ b/ext/tk/lib/tkextlib/vu/pie.rb @@ -39,6 +39,10 @@ class Tk::Vu::Pie < TkWindow WidgetClassName = 'Pie'.freeze WidgetClassNames[WidgetClassName] = self + def __destroy_hook__ + Tk::Vu::PieSlice::SliceID_TBL.delete(@path) + end + ############################### include Tk::Vu::PieSliceConfigMethod @@ -112,7 +116,7 @@ end class Tk::Vu::PieSlice SliceID_TBL = TkCore::INTERP.create_table - Pie_Slice_ID = ['vu_pie'.freeze, '00000'.taint].freeze + Pie_Slice_ID = ['vu:pie'.freeze, '00000'.taint].freeze TkCore::INTERP.init_ip_env{ SliceID_TBL.clear } def self.id2obj(pie, id) -- cgit v1.2.3