diff options
Diffstat (limited to 'ext/tk')
| -rw-r--r-- | ext/tk/.cvsignore | 3 | ||||
| -rw-r--r-- | ext/tk/MANIFEST | 26 | ||||
| -rw-r--r-- | ext/tk/depend | 1 | ||||
| -rw-r--r-- | ext/tk/extconf.rb | 2 | ||||
| -rw-r--r-- | ext/tk/lib/README | 15 | ||||
| -rw-r--r-- | ext/tk/lib/tk.rb | 3790 | ||||
| -rw-r--r-- | ext/tk/lib/tkafter.rb | 312 | ||||
| -rw-r--r-- | ext/tk/lib/tkbgerror.rb | 17 | ||||
| -rw-r--r-- | ext/tk/lib/tkcanvas.rb | 874 | ||||
| -rw-r--r-- | ext/tk/lib/tkclass.rb | 47 | ||||
| -rw-r--r-- | ext/tk/lib/tkdialog.rb | 142 | ||||
| -rw-r--r-- | ext/tk/lib/tkentry.rb | 224 | ||||
| -rw-r--r-- | ext/tk/lib/tkfont.rb | 1045 | ||||
| -rw-r--r-- | ext/tk/lib/tkmenubar.rb | 143 | ||||
| -rw-r--r-- | ext/tk/lib/tkmngfocus.rb | 27 | ||||
| -rw-r--r-- | ext/tk/lib/tkpalette.rb | 48 | ||||
| -rw-r--r-- | ext/tk/lib/tkscrollbox.rb | 29 | ||||
| -rw-r--r-- | ext/tk/lib/tktext.rb | 1041 | ||||
| -rw-r--r-- | ext/tk/lib/tkvirtevent.rb | 81 | ||||
| -rw-r--r-- | ext/tk/sample/tkbiff.rb | 149 | ||||
| -rw-r--r-- | ext/tk/sample/tkbrowse.rb | 79 | ||||
| -rw-r--r-- | ext/tk/sample/tkdialog.rb | 62 | ||||
| -rw-r--r-- | ext/tk/sample/tkfrom.rb | 132 | ||||
| -rw-r--r-- | ext/tk/sample/tkhello.rb | 10 | ||||
| -rw-r--r-- | ext/tk/sample/tkline.rb | 45 | ||||
| -rw-r--r-- | ext/tk/sample/tktimer.rb | 50 | ||||
| -rw-r--r-- | ext/tk/tkutil.c | 45 |
27 files changed, 0 insertions, 8439 deletions
diff --git a/ext/tk/.cvsignore b/ext/tk/.cvsignore deleted file mode 100644 index 44e7f262dc..0000000000 --- a/ext/tk/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -mkmf.log -*.log diff --git a/ext/tk/MANIFEST b/ext/tk/MANIFEST deleted file mode 100644 index bf03ac3841..0000000000 --- a/ext/tk/MANIFEST +++ /dev/null @@ -1,26 +0,0 @@ -MANIFEST -extconf.rb -depend -tkutil.c -lib/README -lib/tk.rb -lib/tkafter.rb -lib/tkbgerror.rb -lib/tkcanvas.rb -lib/tkclass.rb -lib/tkdialog.rb -lib/tkentry.rb -lib/tkfont.rb -lib/tkmenubar.rb -lib/tkmngfocus.rb -lib/tkpalette.rb -lib/tkscrollbox.rb -lib/tktext.rb -lib/tkvirtevent.rb -sample/tkbiff.rb -sample/tkbrowse.rb -sample/tkdialog.rb -sample/tkfrom.rb -sample/tkhello.rb -sample/tkline.rb -sample/tktimer.rb diff --git a/ext/tk/depend b/ext/tk/depend deleted file mode 100644 index fd63e230f0..0000000000 --- a/ext/tk/depend +++ /dev/null @@ -1 +0,0 @@ -tkutil.o: tkutil.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb deleted file mode 100644 index f769b06e30..0000000000 --- a/ext/tk/extconf.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'mkmf' -create_makefile("tkutil") diff --git a/ext/tk/lib/README b/ext/tk/lib/README deleted file mode 100644 index 87b59f4972..0000000000 --- a/ext/tk/lib/README +++ /dev/null @@ -1,15 +0,0 @@ -README this file -tk.rb Tk interface -tkafter.rb handles Tcl after -tkbgerror.rb Tk error module -tkcanvas.rb Tk canvas interface -tkclass.rb provides generic names for Tk classes -tkdialog.rb Tk dialog class -tkentry.rb Tk entry class -tkfont.rb Tk font support -tkmenubar.rb TK menubar utility -tkmngfocus.rb focus manager -tkpalette.rb pallete support -tkscrollbox.rb scroll box, also example of compound widget -tktext.rb text classes -tkvirtevent.rb virtual event support diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb deleted file mode 100644 index 701392c875..0000000000 --- a/ext/tk/lib/tk.rb +++ /dev/null @@ -1,3790 +0,0 @@ -# -# tk.rb - Tk interface module using tcltklib -# $Date$ -# by Yukihiro Matsumoto <matz@netlab.jp> - -# use Shigehiro's tcltklib -require "tcltklib" -require "tkutil" - -module TkComm - WidgetClassNames = {} - - None = Object.new - def None.to_s - 'None' - end - - Tk_CMDTBL = {} - Tk_WINDOWS = {} - - def error_at - frames = caller() - frames.delete_if do |c| - c =~ %r!/tk(|core|thcore|canvas|text|entry|scrollbox)\.rb:\d+! - end - frames - end - private :error_at - - def _genobj_for_tkwidget(path) - return TkRoot.new if path == '.' - - begin - tk_class = TkCore::INTERP._invoke('winfo', 'class', path) - rescue - return path - end - - ruby_class = WidgetClassNames[tk_class] - gen_class_name = ruby_class.name + 'GeneratedOnTk' - unless Object.const_defined? gen_class_name - eval "class #{gen_class_name}<#{ruby_class.name} - def initialize(path) - @path=path - Tk_WINDOWS[@path] = self - end - end" - end - eval "#{gen_class_name}.new('#{path}')" - end - - def tk_tcl2ruby(val) - if val =~ /^rb_out (c\d+)/ - return Tk_CMDTBL[$1] - end - if val.include? ?\s - return val.split.collect{|v| tk_tcl2ruby(v)} - end - case val - when /^@font/ - TkFont.get_obj(val) - when /^-?\d+$/ - val.to_i - when /^\./ - Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) - when / / - val.split.collect{|elt| - tk_tcl2ruby(elt) - } - when /^-?\d+\.\d*$/ - val.to_f - else - val - end - end - - def tk_split_list(str) - return [] if str == "" - idx = str.index('{') - while idx and idx > 0 and str[idx-1] == ?\\ - idx = str.index('{', idx+1) - end - unless idx - list = tk_tcl2ruby(str) - unless Array === list - list = [list] - end - return list - end - - list = tk_tcl2ruby(str[0,idx]) - list = [] if list == "" - str = str[idx+1..-1] - i = -1 - brace = 1 - str.each_byte {|c| - i += 1 - brace += 1 if c == ?{ - brace -= 1 if c == ?} - break if brace == 0 - } - if str.size == i + 1 - return tk_split_list(str[0, i]) - end - if str[0, i] == ' ' - list.push ' ' - else - list.push tk_split_list(str[0, i]) - end - list += tk_split_list(str[i+1..-1]) - list - end - - def tk_split_simplelist(str) - return [] if str == "" - idx = str.index('{') - while idx and idx > 0 and str[idx-1] == ?\\ - idx = str.index('{', idx+1) - end - return str.split unless idx - - list = str[0,idx].split - str = str[idx+1..-1] - i = -1 - brace = 1 - str.each_byte {|c| - i += 1 - brace += 1 if c == ?{ - brace -= 1 if c == ?} - break if brace == 0 - } - if i == 0 - list.push '' - elsif str[0, i] == ' ' - list.push ' ' - else - list.push str[0..i-1] - end - list += tk_split_simplelist(str[i+1..-1]) - list - end - private :tk_tcl2ruby, :tk_split_list, :tk_split_simplelist - - def _symbolkey2str(keys) - h = {} - keys.each{|key,value| h[key.to_s] = value} - h - end - private :_symbolkey2str - - def hash_kv(keys) - conf = [] - if keys and keys != None - for k, v in keys - conf.push("-#{k}") - conf.push(v) - end - end - conf - end - private :hash_kv - - def array2tk_list(ary) - ary.collect{|e| - if e.kind_of? Array - "{#{array2tk_list(e)}}" - elsif e.kind_of? Hash - "{#{e.to_a.collect{|ee| array2tk_list(ee)}.join(' ')}}" - else - s = _get_eval_string(e) - (s.index(/\s/))? "{#{s}}": s - end - }.join(" ") - end - private :array2tk_list - - def bool(val) - case val - when "1", 1, 'yes', 'true' - TRUE - else - FALSE - end - end - def number(val) - case val - when /^-?\d+$/ - val.to_i - when /^-?\d+\.\d*$/ - val.to_f - else - val - end - end - def string(val) - if val == "{}" - '' - elsif val[0] == ?{ - val[1..-2] - else - val - end - end - def list(val) - tk_split_list(val) - end - def window(val) - Tk_WINDOWS[val] - end - def procedure(val) - if val =~ /^rb_out (c\d+)/ - Tk_CMDTBL[$1] - else - nil - end - end - private :bool, :number, :string, :list, :window, :procedure - - def _get_eval_string(str) - return nil if str == None - if str.kind_of?(String) - # do nothing - elsif str.kind_of?(Symbol) - str = str.id2name - elsif str.kind_of?(Hash) - str = hash_kv(str).join(" ") - elsif str.kind_of?(Array) - str = array2tk_list(str) - elsif str.kind_of?(Proc) - str = install_cmd(str) - elsif str == nil - str = "" - elsif str == false - str = "0" - elsif str == true - str = "1" - elsif (str.respond_to?(:to_eval)) - str = str.to_eval() - else - str = str.to_s() - end - return str - end - private :_get_eval_string - - def ruby2tcl(v) - if v.kind_of?(Hash) - v = hash_kv(v) - v.flatten! - v.collect{|e|ruby2tcl(e)} - else - _get_eval_string(v) - end - end - private :ruby2tcl - - Tk_IDs = [0, 0] # [0]-cmdid, [1]-winid - def _curr_cmd_id - id = format("c%.4d", Tk_IDs[0]) - end - def _next_cmd_id - id = _curr_cmd_id - Tk_IDs[0] += 1 - id - end - def install_cmd(cmd) - return '' if cmd == '' - id = _next_cmd_id - Tk_CMDTBL[id] = cmd - @cmdtbl = [] unless @cmdtbl - @cmdtbl.push id - return format("rb_out %s", id); - end - def uninstall_cmd(id) - id = $1 if /rb_out (c\d+)/ =~ id - Tk_CMDTBL.delete(id) - end - private :install_cmd, :uninstall_cmd - - def install_win(ppath,name=nil) - if !name or name == '' - name = format("w%.4d", Tk_IDs[1]) - Tk_IDs[1] += 1 - end - if !ppath or ppath == "." - @path = format(".%s", name); - else - @path = format("%s.%s", ppath, name) - end - Tk_WINDOWS[@path] = self - end - - def uninstall_win() - Tk_WINDOWS.delete(@path) - end - - class Event - def initialize(seq,a,b,c,d,f,h,k,m,o,p,s,t,w,x,y, - aa,bb,dd,ee,kk,nn,rr,ss,tt,ww,xx,yy) - @serial = seq - @above = a - @num = b - @count = c - @detail = d - @focus = (f == 1) - @height = h - @keycode = k - @mode = m - @override = (o == 1) - @place = p - @state = s - @time = t - @width = w - @x = x - @y = y - @char = aa - @borderwidth = bb - @wheel_delta = dd - @send_event = (ee == 1) - @keysym = kk - @keysym_num = nn - @rootwin_id = rr - @subwindow = ss - @type = tt - @widget = ww - @x_root = xx - @y_root = yy - end - attr :serial - attr :above - attr :num - attr :count - attr :detail - attr :focus - attr :height - attr :keycode - attr :mode - attr :override - attr :place - attr :state - attr :time - attr :width - attr :x - attr :y - attr :char - attr :borderwidth - attr :wheel_delta - attr :send_event - attr :keysym - attr :keysym_num - attr :rootwin_id - attr :subwindow - attr :type - attr :widget - attr :x_root - attr :y_root - end - - def install_bind(cmd, args=nil) - if args - id = install_cmd(proc{|*arg| - TkUtil.eval_cmd cmd, *arg - }) - id + " " + args - else - id = install_cmd(proc{|*arg| - TkUtil.eval_cmd cmd, Event.new(*arg) - }) - id + ' %# %a %b %c %d %f %h %k %m %o %p %s %t %w %x %y' + - ' %A %B %D %E %K %N %R %S %T %W %X %Y' - end - end - - def tk_event_sequence(context) - if context.kind_of? TkVirtualEvent - context = context.path - end - if context.kind_of? Array - context = context.collect{|ev| - if ev.kind_of? TkVirtualEvent - ev.path - else - ev - end - }.join("><") - end - if /,/ =~ context - context = context.split(/\s*,\s*/).join("><") - else - context - end - end - - def _bind_core(mode, what, context, cmd, args=nil) - id = install_bind(cmd, args) if cmd - begin - tk_call(*(what + ["<#{tk_event_sequence(context)}>", mode + id])) - rescue - uninstall_cmd(id) if cmd - fail - end - end - - def _bind(what, context, cmd, args=nil) - _bind_core('', what, context, cmd, args) - end - - def _bind_append(what, context, cmd, args=nil) - _bind_core('+', what, context, cmd, args) - end - - def _bind_remove(what, context) - tk_call(*(what + ["<#{tk_event_sequence(context)}>", ''])) - end - - def _bindinfo(what, context=nil) - if context - tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline| - if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ - [Tk_CMDTBL[$1], $2] - else - cmdline - end - } - else - tk_split_simplelist(tk_call(*what)).collect!{|seq| - l = seq.scan(/<*[^<>]+>*/).collect!{|subseq| - case (subseq) - when /^<<[^<>]+>>$/ - TkVirtualEvent.getobj(subseq[1..-2]) - when /^<[^<>]+>$/ - subseq[1..-2] - else - subseq.split('') - end - }.flatten - (l.size == 1) ? l[0] : l - } - end - end - private :install_bind, :tk_event_sequence, - :_bind_core, :_bind, :_bind_append, :_bind_remove, :_bindinfo - - def bind(tagOrClass, context, cmd=Block.new, args=nil) - _bind(["bind", tagOrClass], context, cmd, args) - end - - def bind_append(tagOrClass, context, cmd=Block.new, args=nil) - _bind_append(["bind", tagOrClass], context, cmd, args) - end - - def bind_remove(tagOrClass, context) - _bind_remove(['bind', tagOrClass], context) - end - - def bindinfo(tagOrClass, context=nil) - _bindinfo(['bind', tagOrClass], context) - end - - def bind_all(context, cmd=Block.new, args=nil) - _bind(['bind', 'all'], context, cmd, args) - end - - def bind_append_all(context, cmd=Block.new, args=nil) - _bind_append(['bind', 'all'], context, cmd, args) - end - - def bindinfo_all(context=nil) - _bindinfo(['bind', 'all'], context) - end - - def pack(*args) - TkPack.configure(*args) - end - - def grid(*args) - TkGrid.configure(*args) - end - - def update(idle=nil) - if idle - tk_call 'update', 'idletasks' - else - tk_call 'update' - end - end - -end - -module TkCore - include TkComm - extend TkComm - - INTERP = TclTkIp.new - - INTERP._invoke("proc", "rb_out", "args", <<-'EOL') - regsub -all {!} $args {\\!} args - regsub -all "{" $args "\\{" args - if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} { - return -code $st $ret - } { - return $ret - } - EOL - - EventFlag = TclTkLib::EventFlag - - def callback_break - fail TkCallbackBreak, "Tk callback returns 'break' status" - end - - def callback_continue - fail TkCallbackContinue, "Tk callback returns 'continue' status" - end - - def after(ms, cmd=Block.new) - myid = _curr_cmd_id - cmdid = install_cmd(cmd) - tk_call("after",ms,cmdid) -# return -# if false #defined? Thread -# Thread.start do -# ms = Float(ms)/1000 -# ms = 10 if ms == 0 -# sleep ms/1000 -# cmd.call -# end -# else -# cmdid = install_cmd(cmd) -# tk_call("after",ms,cmdid) -# end - end - - def after_idle(cmd=Block.new) - myid = _curr_cmd_id - cmdid = install_cmd(cmd) - tk_call('after','idle',cmdid) - end - - def clock_clicks(ms=nil) - if ms - tk_call('clock','clicks','-milliseconds').to_i - else - tk_call('clock','clicks').to_i - end - end - - def clock_format(clk, form=nil) - if form - tk_call('clock','format',clk,'-format',form).to_i - else - tk_call('clock','format',clk).to_i - end - end - - def clock_formatGMT(clk, form=nil) - if form - tk_call('clock','format',clk,'-format',form,'-gmt','1').to_i - else - tk_call('clock','format',clk,'-gmt','1').to_i - end - end - - def clock_scan(str, base=nil) - if base - tk_call('clock','scan',str,'-base',base).to_i - else - tk_call('clock','scan',str).to_i - end - end - - def clock_scanGMT(str, base=nil) - if base - tk_call('clock','scan',str,'-base',base,'-gmt','1').to_i - else - tk_call('clock','scan',str,'-gmt','1').to_i - end - end - - def clock_seconds - tk_call('clock','seconds').to_i - end - - def TkCore.callback(arg) - arg = tk_split_list(arg) - _get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg)) - end - - def scaling(scale=nil) - if scale - tk_call('tk', 'scaling', scale) - else - Float(number(tk_call('tk', 'scaling'))) - end - end - def scaling_displayof(win, scale=nil) - if scale - tk_call('tk', 'scaling', '-displayof', win, scale) - else - Float(number(tk_call('tk', '-displayof', win, 'scaling'))) - end - end - - def appname(name=None) - tk_call('tk', 'appname', name) - end - - def appsend(interp, async, *args) - if async - tk_call('send', '-async', '--', interp, *args) - else - tk_call('send', '--', interp, *args) - end - end - - def rb_appsend(interp, async, *args) - args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')} - args.push(').to_s"') - appsend(interp, async, 'ruby "(', *args) - end - - def appsend_displayof(interp, win, async, *args) - win = '.' if win == nil - if async - tk_call('send', '-async', '-displayof', win, '--', interp, *args) - else - tk_call('send', '-displayor', win, '--', interp, *args) - end - end - - def rb_appsend_displayof(interp, win, async, *args) - args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')} - args.push(').to_s"') - appsend_displayof(interp, win, async, 'ruby "(', *args) - end - - def info(*args) - tk_call('info', *args) - end - - def mainloop(check_root = true) - TclTkLib.mainloop(check_root) - end - - def mainloop_watchdog(check_root = true) - TclTkLib.mainloop_watchdog(check_root) - end - - def do_one_event(flag = 0) - TclTkLib.do_one_event(flag) - end - - def set_eventloop_tick(timer_tick) - TclTkLib.set_eventloop_tick(timer_tick) - end - - def get_eventloop_tick() - TclTkLib.get_eventloop_tick - end - - def set_eventloop_weight(loop_max, no_event_tick) - TclTkLib.set_eventloop_weight(loop_max, no_event_tick) - end - - def get_eventloop_weight() - TclTkLib.get_eventloop_weight - end - - def restart(app_name = nil, use = nil) - tk_call('set', 'argv0', app_name) if app_name - if use - tk_call('set', 'argc', 2) - tk_call('set', 'argv', "-use #{use}") - end - TkCore::INTERP.restart - TkComm::Tk_CMDTBL.clear - TkComm::Tk_WINDOWS.clear - nil - end - - def event_generate(window, context, keys=nil) - window = window.path if window.kind_of? TkObject - if keys - tk_call('event', 'generate', window, - "<#{tk_event_sequence(context)}>", *hash_kv(keys)) - else - tk_call('event', 'generate', window, "<#{tk_event_sequence(context)}>") - end - end - - def messageBox(keys) - tk_call 'tk_messageBox', *hash_kv(keys) - end - - def getOpenFile(keys = nil) - tk_call 'tk_getOpenFile', *hash_kv(keys) - end - - def getSaveFile(keys = nil) - tk_call 'tk_getSaveFile', *hash_kv(keys) - end - - def chooseColor(keys = nil) - tk_call 'tk_chooseColor', *hash_kv(keys) - end - - def chooseDirectory(keys = nil) - tk_call 'tk_chooseDirectory', *hash_kv(keys) - end - - def tk_call(*args) - puts args.inspect if $DEBUG - args.collect! {|x|ruby2tcl(x)} - args.compact! - args.flatten! - print "=> ", args.join(" ").inspect, "\n" if $DEBUG - begin - res = INTERP._invoke(*args) - rescue NameError - err = $! - begin - args.unshift "unknown" - res = INTERP._invoke(*args) - rescue - fail unless /^invalid command/ =~ $! - fail err - end - end - if INTERP._return_value() != 0 - fail RuntimeError, res, error_at - end - print "==> ", res.inspect, "\n" if $DEBUG - return res - end -end - -module TkPackage - include TkCore - extend TkPackage - - def add_path(path) - Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path - end - - def forget(package) - tk_call('package', 'forget', package) - nil - end - - def names - tk_split_simplelist(tk_call('package', 'names')) - end - - def provide(package, version=nil) - if version - tk_call('package', 'provide', package, version) - nil - else - tk_call('package', 'provide', package) - end - end - - def present(package, version=None) - tk_call('package', 'present', package, version) - end - - def present_exact(package, version) - tk_call('package', 'present', '-exact', package, version) - end - - def require(package, version=None) - tk_call('package', 'require', package, version) - end - - def require_exact(package, version) - tk_call('package', 'require', '-exact', package, version) - end - - def versions(package) - tk_split_simplelist(tk_call('package', 'versions', package)) - end - - def vcompare(version1, version2) - Integer(tk_call('package', 'vcompare', version1, version2)) - end - - def vsatisfies(version1, version2) - bool(tk_call('package', 'vsatisfies', version1, version2)) - end -end - -module Tk - include TkCore - extend Tk - - TCL_VERSION = INTERP._invoke("info", "tclversion") - TK_VERSION = INTERP._invoke("set", "tk_version") - - TCL_PATCHLEVEL = INTERP._invoke("info", "patchlevel") - TK_PATCHLEVEL = INTERP._invoke("set", "tk_patchLevel") - - TCL_LIBRARY = INTERP._invoke("set", "tcl_library") - TK_LIBRARY = INTERP._invoke("set", "tk_library") - LIBRARY = INTERP._invoke("info", "library") - - PLATFORM = Hash[*tk_split_simplelist(INTERP._eval('array get tcl_platform'))] - - JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "") - - def root - TkRoot.new - end - - def bell - tk_call 'bell' - end - - def Tk.focus(display=nil) - if display == nil - r = tk_call('focus') - else - r = tk_call('focus', '-displayof', display) - end - tk_tcl2ruby(r) - end - - def Tk.focus_lastfor(win) - tk_tcl2ruby(tk_call('focus', '-lastfor', win)) - end - - def Tk.strictMotif(bool=None) - bool(tk_call('set', 'tk_strictMotif', bool)) - end - - def Tk.show_kinsoku(mode='both') - begin - if /^8\.*/ === TK_VERSION && JAPANIZED_TK - tk_split_simplelist(tk_call('kinsoku', 'show', mode)) - end - rescue - end - end - def Tk.add_kinsoku(chars, mode='both') - begin - if /^8\.*/ === TK_VERSION && JAPANIZED_TK - tk_split_simplelist(tk_call('kinsoku', 'add', mode, - *(chars.split('')))) - else - [] - end - rescue - [] - end - end - def Tk.delete_kinsoku(chars, mode='both') - begin - if /^8\.*/ === TK_VERSION && JAPANIZED_TK - tk_split_simplelist(tk_call('kinsoku', 'delete', mode, - *(chars.split('')))) - end - rescue - end - end - - def Tk.toUTF8(str,encoding) - INTERP._toUTF8(str,encoding) - end - - def Tk.fromUTF8(str,encoding) - INTERP._fromUTF8(str,encoding) - end - - module Scrollable - def xscrollcommand(cmd=Block.new) - configure_cmd 'xscrollcommand', cmd - end - def yscrollcommand(cmd=Block.new) - configure_cmd 'yscrollcommand', cmd - end - def xview(*index) - v = tk_send('xview', *index) - list(v) if index.size == 0 - end - def yview(*index) - v = tk_send('yview', *index) - list(v) if index.size == 0 - end - def xscrollbar(bar=nil) - if bar - @xscrollbar = bar - @xscrollbar.orient 'horizontal' - self.xscrollcommand {|arg| @xscrollbar.set(*arg)} - @xscrollbar.command {|arg| self.xview(*arg)} - end - @xscrollbar - end - def yscrollbar(bar=nil) - if bar - @yscrollbar = bar - @yscrollbar.orient 'vertical' - self.yscrollcommand {|arg| @yscrollbar.set(*arg)} - @yscrollbar.command {|arg| self.yview(*arg)} - end - @yscrollbar - end - end - - module Wm - include TkComm - def aspect(*args) - w = tk_call('wm', 'aspect', path, *args) - list(w) if args.length == 0 - end - def client(name=None) - tk_call 'wm', 'client', path, name - end - def colormapwindows(*args) - list(tk_call('wm', 'colormapwindows', path, *args)) - end - def wm_command(value=None) - string(tk_call('wm', 'command', path, value)) - end - def deiconify - tk_call 'wm', 'deiconify', path - end - def focusmodel(*args) - tk_call 'wm', 'focusmodel', path, *args - end - def frame - tk_call('wm', 'frame', path) - end - def geometry(*args) - tk_call('wm', 'geometry', path, *args) - end - def grid(*args) - w = tk_call('wm', 'grid', path, *args) - list(w) if args.size == 0 - end - def group(*args) - w = tk_call 'wm', 'group', path, *args - window(w) if args.size == 0 - end - def iconbitmap(*args) - tk_call 'wm', 'iconbitmap', path, *args - end - def iconify - tk_call 'wm', 'iconify', path - end - def iconmask(*args) - tk_call 'wm', 'iconmask', path, *args - end - def iconname(*args) - tk_call 'wm', 'iconname', path, *args - end - def iconposition(*args) - w = tk_call('wm', 'iconposition', path, *args) - list(w) if args.size == 0 - end - def iconwindow(*args) - w = tk_call('wm', 'iconwindow', path, *args) - window(w) if args.size == 0 - end - def maxsize(*args) - w = tk_call('wm', 'maxsize', path, *args) - list(w) if args.size == 0 - end - def minsize(*args) - w = tk_call('wm', 'minsize', path, *args) - list(w) if args.size == 0 - end - def overrideredirect(bool=None) - if bool == None - bool(tk_call('wm', 'overrideredirect', path)) - else - tk_call 'wm', 'overrideredirect', path, bool - end - end - def positionfrom(*args) - tk_call 'wm', 'positionfrom', path, *args - end - def protocol(name=nil, cmd=nil) - if cmd - tk_call('wm', 'protocol', path, name, cmd) - elsif name - result = tk_call('wm', 'protocol', path, name) - (result == "")? nil : tk_tcl2ruby(result) - else - tk_split_simplelist(tk_call('wm', 'protocol', path)) - end - end - def resizable(*args) - w = tk_call('wm', 'resizable', path, *args) - if args.length == 0 - list(w).collect{|e| bool(e)} - end - end - def sizefrom(*args) - tk_call('wm', 'sizefrom', path, *args) - end - def state(state=None) - tk_call 'wm', 'state', path, state - end - def title(*args) - tk_call 'wm', 'title', path, *args - end - def transient(*args) - window(tk_call('wm', 'transient', path, *args)) - end - def withdraw - tk_call 'wm', 'withdraw', path - end - end -end - -########################################### -# convert kanji string to/from utf-8 -########################################### -if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK - class TclTkIp - # from tkencoding.rb by ttate@jaist.ac.jp - alias __eval _eval - alias __invoke _invoke - private :__eval - private :__invoke - - attr_accessor :encoding - - def _eval(cmd) - if @encoding - _fromUTF8(__eval(_toUTF8(cmd, @encoding)), @encoding) - else - __eval(cmd) - end - end - - def _invoke(*cmds) - if @encoding - cmds = cmds.collect{|cmd| _toUTF8(cmd, @encoding)} - _fromUTF8(__invoke(*cmds), @encoding) - else - __invoke(*cmds) - end - end - end - - module Tk - def encoding=(name) - INTERP.encoding = name - end - - def encoding - INTERP.encoding - end - - def encoding_names - tk_split_simplelist(tk_call('encoding', 'names')) - end - - def encoding_system - tk_call('encoding', 'system') - end - - def encoding_system=(enc) - tk_call('encoding', 'system', enc) - end - end - - # estimate encoding - case $KCODE - when /^e/i # EUC - Tk.encoding = 'euc-jp' - when /^s/i # SJIS - Tk.encoding = 'shiftjis' - when /^u/i # UTF8 - Tk.encoding = 'utf-8' - else # NONE - begin - Tk.encoding = Tk.encoding_system - rescue StandardError, NameError - Tk.encoding = 'utf-8' - end - end - -else - # dummy methods - module Tk - def encoding=(name) - nil - end - def encoding - nil - end - def encoding_names - nil - end - def encoding_system - nil - end - def encoding_system=(enc) - nil - end - end -end - -module TkBindCore - def bind(context, cmd=Block.new, args=nil) - Tk.bind(to_eval, context, cmd, args) - end - - def bind_append(context, cmd=Block.new, args=nil) - Tk.bind_append(to_eval, context, cmd, args) - end - - def bind_remove(context) - Tk.bind_remove(to_eval, context) - end - - def bindinfo(context=nil) - Tk.bindinfo(to_eval, context) - end -end - -class TkBindTag - include TkBindCore - - BTagID_TBL = {} - Tk_BINDTAG_ID = ["btag00000"] - - def TkBindTag.id2obj(id) - BTagID_TBL[id]? BTagID_TBL[id]: id - end - - ALL = self.new - ALL.instance_eval { - @id = 'all' - BTagID_TBL[@id] = self - } - - def initialize(*args) - @id = Tk_BINDTAG_ID[0] - Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ - BTagID_TBL[@id] = self - bind(*args) if args != [] - end - - def to_eval - @id - end - - def inspect - format "#<TkBindTag: %s>", @id - end -end - -class TkBindTagAll<TkBindTag - def TkBindTagAll.new(*args) - $stderr.puts "Warning: TkBindTagALL is obsolete. Use TkBindTag::ALL\n" - - TkBindTag::ALL.bind(*args) if args != [] - TkBindTag::ALL - end -end - -class TkVariable - include Tk - extend TkCore - - TkVar_CB_TBL = {} - Tk_VARIABLE_ID = ["v00000"] - - INTERP._invoke("proc", "rb_var", "args", "ruby [format \"TkVariable.callback %%Q!%s!\" $args]") - - def TkVariable.callback(args) - name1,name2,op = tk_split_list(args) - if TkVar_CB_TBL[name1] - _get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op)) - else - '' - end - end - - def initialize(val="") - @id = Tk_VARIABLE_ID[0] - Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ - if val == [] - INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)', - @id, @id, @id)) - elsif val.kind_of?(Array) - a = [] - val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))} - s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) - elsif val.kind_of?(Hash) - s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ - .gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; array set %s %s', @id, @id, s)) - else - s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; set %s %s', @id, @id, s)) - end - end - - def wait - INTERP._eval("tkwait variable #{@id}") - end - - def id - @id - end - - def value - begin - INTERP._eval(format('global %s; set %s', @id, @id)) - rescue - if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1" - fail - else - Hash[*tk_split_simplelist(INTERP._eval(format('global %s; array get %s', - @id, @id)))] - end - end - end - - def value=(val) - begin - s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; set %s %s', @id, @id, s)) - rescue - if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1" - fail - else - if val == [] - INTERP._eval(format('global %s; unset %s; set %s(0) 0; unset %s(0)', - @id, @id, @id, @id)) - elsif val.kind_of?(Array) - a = [] - val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e))} - s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; unset %s; array set %s %s', - @id, @id, @id, s)) - elsif val.kind_of?(Hash) - s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")\ - .gsub(/[\[\]$"]/, '\\\\\&') + '"' - INTERP._eval(format('global %s; unset %s; array set %s %s', - @id, @id, @id, s)) - else - fail - end - end - end - end - - def [](index) - INTERP._eval(format('global %s; set %s(%s)', - @id, @id, _get_eval_string(index))) - end - - def []=(index,val) - INTERP._eval(format('global %s; set %s(%s) %s', @id, @id, - _get_eval_string(index), _get_eval_string(val))) - end - - def to_i - number(value).to_i - end - - def to_f - number(value).to_f - end - - def to_s - string(value).to_s - end - - def inspect - format "#<TkVariable: %s>", @id - end - - def ==(other) - case other - when TkVariable - self.equal(other) - when String - self.to_s == other - when Integer - self.to_i == other - when Float - self.to_f == other - when Array - self.to_a == other - else - false - end - end - - def to_a - list(value) - end - - def to_eval - @id - end - - def unset(elem=nil) - if elem - INTERP._eval(format('global %s; unset %s(%s)', - @id, @id, tk_tcl2ruby(elem))) - else - INTERP._eval(format('global %s; unset %s', @id, @id)) - end - end - alias remove unset - - def trace_callback(elem, op) - if @trace_var.kind_of? Array - @trace_var.each{|m,e| e.call(self,elem,op) if m.index(op)} - end - if elem.kind_of? String - if @trace_elem[elem].kind_of? Array - @trace_elem[elem].each{|m,e| e.call(self,elem,op) if m.index(op)} - end - end - end - - def trace(opts, cmd) - @trace_var = [] if @trace_var == nil - opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - @trace_var.unshift([opts,cmd]) - if @trace_opts == nil - TkVar_CB_TBL[@id] = self - @trace_opts = opts - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - else - newopts = @trace_opts.dup - opts.each_byte{|c| newopts += c.chr unless newopts.index(c)} - if newopts != @trace_opts - Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var') - @trace_opts.replace(newopts) - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - end - end - end - - def trace_element(elem, opts, cmd) - @trace_elem = {} if @trace_elem == nil - @trace_elem[elem] = [] if @trace_elem[elem] == nil - opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - @trace_elem[elem].unshift([opts,cmd]) - if @trace_opts == nil - TkVar_CB_TBL[@id] = self - @trace_opts = opts - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - else - newopts = @trace_opts.dup - opts.each_byte{|c| newopts += c.chr unless newopts.index(c)} - if newopts != @trace_opts - Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var') - @trace_opts.replace(newopts) - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - end - end - end - - def trace_vinfo - return [] unless @trace_var - @trace_var.dup - end - def trace_vinfo_for_element(elem) - return [] unless @trace_elem - return [] unless @trace_elem[elem] - @trace_elem[elem].dup - end - - def trace_vdelete(opts,cmd) - return unless @trace_var.kind_of? Array - opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - idx = -1 - newopts = '' - @trace_var.each_with_index{|e,i| - if idx < 0 && e[0] == opts && e[1] == cmd - idx = i - next - end - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} - } - if idx >= 0 - @trace_var.delete_at(idx) - else - return - end - - @trace_elem.each{|elem| - @trace_elem[elem].each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} - } - } - - newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') - if newopts != @trace_opts - Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var') - @trace_opts.replace(newopts) - if @trace_opts != '' - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - end - end - end - - def trace_vdelete_for_element(elem,opts,cmd) - return unless @trace_elem.kind_of? Hash - return unless @trace_elem[elem].kind_of? Array - opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('') - idx = -1 - @trace_elem[elem].each_with_index{|e,i| - if idx < 0 && e[0] == opts && e[1] == cmd - idx = i - next - end - } - if idx >= 0 - @trace_elem[elem].delete_at(idx) - else - return - end - - newopts = '' - @trace_var.each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} - } - @trace_elem.each{|elem| - @trace_elem[elem].each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} - } - } - - newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('') - if newopts != @trace_opts - Tk.tk_call('trace', 'vdelete', @id, @trace_opts, 'rb_var') - @trace_opts.replace(newopts) - if @trace_opts != '' - Tk.tk_call('trace', 'variable', @id, @trace_opts, 'rb_var') - end - end - end -end - -class TkVarAccess<TkVariable - def initialize(varname, val=nil) - @id = varname - if val - s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' #" - INTERP._eval(format('global %s; set %s %s', @id, @id, s)) - end - end -end - -module Tk - begin - auto_path = INTERP._invoke('set', 'auto_path') - rescue - begin - auto_path = INTERP._invoke('set', 'env(TCLLIBPATH)') - rescue - auto_path = Tk::LIBRARY - end - end - AUTO_PATH = TkVarAccess.new('auto_path', auto_path) - - TCL_PACKAGE_PATH = TkVarAccess.new('tcl_pkgPath') -end - -module TkSelection - include Tk - extend Tk - def clear(win=Tk.root) - tk_call 'selection', 'clear', win.path - end - def get(type=None) - tk_call 'selection', 'get', type - end - def TkSelection.handle(win, func, type=None, format=None) - tk_call 'selection', 'handle', win.path, func, type, format - end - def handle(func, type=None, format=None) - TkSelection.handle self, func, type, format - end - def TkSelection.own(win=None, func=None) - window(tk_call('selection', 'own', win, func)) - end - def own(func=None) - TkSelection.own self, func - end - - module_function :clear, :get -end - -module TkKinput - include Tk - extend Tk - - def TkKinput.start(window, style=None) - tk_call 'kinput_start', window.path, style - end - def kinput_start(style=None) - TkKinput.start(self, style) - end - - def TkKinput.send_spot(window) - tk_call 'kinput_send_spot', window.path - end - def kinput_send_spot - TkKinput.send_spot(self) - end - - def TkKinput.input_start(window, keys=nil) - tk_call 'kanjiInput', 'start', window.path, *hash_kv(keys) - end - def kanji_input_start(keys=nil) - TkKinput.input_start(self, keys) - end - - def TkKinput.attribute_config(window, slot, value=None) - if slot.kind_of? Hash - tk_call 'kanjiInput', 'attribute', window.path, *hash_kv(slot) - else - tk_call 'kanjiInput', 'attribute', window.path, "-#{slot}", value - end - end - def kinput_attribute_config(slot, value=None) - TkKinput.attribute_config(self, slot, value) - end - - def TkKinput.attribute_info(window, slot=nil) - if slot - conf = tk_split_list(tk_call('kanjiInput', 'attribute', - window.path, "-#{slot}")) - conf[0] = conf[0][1..-1] - conf - else - tk_split_list(tk_call('kanjiInput', 'attribute', - window.path)).collect{|conf| - conf[0] = conf[0][1..-1] - conf - } - end - end - def kinput_attribute_info(slot=nil) - TkKinput.attribute_info(self, slot) - end - - def TkKinput.input_end(window) - tk_call 'kanjiInput', 'end', window.path - end - def kanji_input_end - TkKinput.input_end(self) - end -end - -module TkXIM - include Tk - extend Tk - - def TkXIM.useinputmethods(window=nil, value=nil) - if window - if value - tk_call 'tk', 'useinputmethods', '-displayof', window.path, value - else - tk_call 'tk', 'useinputmethods', '-displayof', window.path - end - else - if value - tk_call 'tk', 'useinputmethods', value - else - tk_call 'tk', 'useinputmethods' - end - end - end - - def TkXIM.configure(window, slot, value=None) - begin - if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK - if slot.kind_of? Hash - tk_call 'imconfigure', window.path, *hash_kv(slot) - else - tk_call 'imconfigure', window.path, "-#{slot}", value - end - end - rescue - end - end - - def TkXIM.configinfo(window, slot=nil) - begin - if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK - if slot - conf = tk_split_list(tk_call('imconfigure', window.path, "-#{slot}")) - conf[0] = conf[0][1..-1] - conf - else - tk_split_list(tk_call('imconfigure', window.path)).collect{|conf| - conf[0] = conf[0][1..-1] - conf - } - end - else - [] - end - rescue - [] - end - end - - def useinputmethods(value=nil) - TkXIM.useinputmethods(self, value) - end - - def imconfigure(window, slot, value=None) - TkXIM.configinfo(window, slot, value) - end - - def imconfiginfo(slot=nil) - TkXIM.configinfo(window, slot) - end -end - -module TkWinfo - include Tk - extend Tk - def TkWinfo.atom(name) - number(tk_call('winfo', 'atom', name)) - end - def winfo_atom(name) - TkWinfo.atom name - end - def TkWinfo.atomname(id) - tk_call 'winfo', 'atomname', id - end - def winfo_atomname(id) - TkWinfo.atomname id - end - def TkWinfo.cells(window) - number(tk_call('winfo', 'cells', window.path)) - end - def winfo_cells - TkWinfo.cells self - end - def TkWinfo.children(window) - c = tk_call('winfo', 'children', window.path) - list(c) - end - def winfo_children - TkWinfo.children self - end - def TkWinfo.classname(window) - tk_call 'winfo', 'class', window.path - end - def winfo_classname - TkWinfo.classname self - end - def TkWinfo.colormapfull(window) - bool(tk_call('winfo', 'colormapfull', window.path)) - end - def winfo_colormapfull - TkWinfo.colormapfull self - end - def TkWinfo.containing(rootX, rootY) - path = tk_call('winfo', 'containing', rootX, rootY) - window(path) - end - def winfo_containing(x, y) - TkWinfo.containing x, y - end - def TkWinfo.depth(window) - number(tk_call('winfo', 'depth', window.path)) - end - def winfo_depth - TkWinfo.depth self - end - def TkWinfo.exist?(window) - bool(tk_call('winfo', 'exists', window.path)) - end - def winfo_exist? - TkWinfo.exist? self - end - def TkWinfo.fpixels(window, number) - number(tk_call('winfo', 'fpixels', window.path, number)) - end - def winfo_fpixels(number) - TkWinfo.fpixels self, number - end - def TkWinfo.geometry(window) - tk_call('winfo', 'geometry', window.path) - end - def winfo_geometry - TkWinfo.geometry self - end - def TkWinfo.height(window) - number(tk_call('winfo', 'height', window.path)) - end - def winfo_height - TkWinfo.height self - end - def TkWinfo.id(window) - tk_call('winfo', 'id', window.path) - end - def winfo_id - TkWinfo.id self - end - def TkWinfo.interps(window=nil) - if window - tk_split_simplelist(tk_call('winfo', 'interps', - '-displayof', window.path)) - else - tk_split_simplelist(tk_call('winfo', 'interps')) - end - end - def winfo_interps - TkWinfo.interps self - end - def TkWinfo.mapped?(window) - bool(tk_call('winfo', 'ismapped', window.path)) - end - def winfo_mapped? - TkWinfo.mapped? self - end - def TkWinfo.manager(window) - tk_call('winfo', 'manager', window.path) - end - def winfo_manager - TkWinfo.manager self - end - def TkWinfo.appname(window) - tk_call('winfo', 'name', window.path) - end - def winfo_appname - TkWinfo.appname self - end - def TkWinfo.parent(window) - window(tk_call('winfo', 'parent', window.path)) - end - def winfo_parent - TkWinfo.parent self - end - def TkWinfo.widget(id) - window(tk_call('winfo', 'pathname', id)) - end - def winfo_widget(id) - TkWinfo.widget id - end - def TkWinfo.pixels(window, number) - number(tk_call('winfo', 'pixels', window.path, number)) - end - def winfo_pixels(number) - TkWinfo.pixels self, number - end - def TkWinfo.reqheight(window) - number(tk_call('winfo', 'reqheight', window.path)) - end - def winfo_reqheight - TkWinfo.reqheight self - end - def TkWinfo.reqwidth(window) - number(tk_call('winfo', 'reqwidth', window.path)) - end - def winfo_reqwidth - TkWinfo.reqwidth self - end - def TkWinfo.rgb(window, color) - list(tk_call('winfo', 'rgb', window.path, color)) - end - def winfo_rgb(color) - TkWinfo.rgb self, color - end - def TkWinfo.rootx(window) - number(tk_call('winfo', 'rootx', window.path)) - end - def winfo_rootx - TkWinfo.rootx self - end - def TkWinfo.rooty(window) - number(tk_call('winfo', 'rooty', window.path)) - end - def winfo_rooty - TkWinfo.rooty self - end - def TkWinfo.screen(window) - tk_call 'winfo', 'screen', window.path - end - def winfo_screen - TkWinfo.screen self - end - def TkWinfo.screencells(window) - number(tk_call('winfo', 'screencells', window.path)) - end - def winfo_screencells - TkWinfo.screencells self - end - def TkWinfo.screendepth(window) - number(tk_call('winfo', 'screendepth', window.path)) - end - def winfo_screendepth - TkWinfo.screendepth self - end - def TkWinfo.screenheight (window) - number(tk_call('winfo', 'screenheight', window.path)) - end - def winfo_screenheight - TkWinfo.screenheight self - end - def TkWinfo.screenmmheight(window) - number(tk_call('winfo', 'screenmmheight', window.path)) - end - def winfo_screenmmheight - TkWinfo.screenmmheight self - end - def TkWinfo.screenmmwidth(window) - number(tk_call('winfo', 'screenmmwidth', window.path)) - end - def winfo_screenmmwidth - TkWinfo.screenmmwidth self - end - def TkWinfo.screenvisual(window) - tk_call 'winfo', 'screenvisual', window.path - end - def winfo_screenvisual - TkWinfo.screenvisual self - end - def TkWinfo.screenwidth(window) - number(tk_call('winfo', 'screenwidth', window.path)) - end - def winfo_screenwidth - TkWinfo.screenwidth self - end - def TkWinfo.server(window) - tk_call 'winfo', 'server', window.path - end - def winfo_server - TkWinfo.server self - end - def TkWinfo.toplevel(window) - window(tk_call('winfo', 'toplevel', window.path)) - end - def winfo_toplevel - TkWinfo.toplevel self - end - def TkWinfo.visual(window) - tk_call 'winfo', 'visual', window.path - end - def winfo_visual - TkWinfo.visual self - end - def TkWinfo.visualid(window) - tk_call 'winfo', 'visualid', window.path - end - def winfo_visualid - TkWinfo.visualid self - end - def TkWinfo.visualsavailable(window, includeids=false) - if includeids - v = tk_call('winfo', 'visualsavailable', window.path, "includeids") - else - v = tk_call('winfo', 'visualsavailable', window.path) - end - list(v) - end - def winfo_visualsavailable(includeids=false) - TkWinfo.visualsavailable self, includeids - end - def TkWinfo.vrootheight(window) - number(tk_call('winfo', 'vrootheight', window.path)) - end - def winfo_vrootheight - TkWinfo.vrootheight self - end - def TkWinfo.vrootwidth(window) - number(tk_call('winfo', 'vrootwidth', window.path)) - end - def winfo_vrootwidth - TkWinfo.vrootwidth self - end - def TkWinfo.vrootx(window) - number(tk_call('winfo', 'vrootx', window.path)) - end - def winfo_vrootx - TkWinfo.vrootx self - end - def TkWinfo.vrooty(window) - number(tk_call('winfo', 'vrooty', window.path)) - end - def winfo_vrooty - TkWinfo.vrooty self - end - def TkWinfo.width(window) - number(tk_call('winfo', 'width', window.path)) - end - def winfo_width - TkWinfo.width self - end - def TkWinfo.x(window) - number(tk_call('winfo', 'x', window.path)) - end - def winfo_x - TkWinfo.x self - end - def TkWinfo.y(window) - number(tk_call('winfo', 'y', window.path)) - end - def winfo_y - TkWinfo.y self - end - def TkWinfo.viewable(window) - bool(tk_call('winfo', 'viewable', window.path)) - end - def winfo_viewable - TkWinfo.viewable self - end - def TkWinfo.pointerx(window) - number(tk_call('winfo', 'pointerx', window.path)) - end - def winfo_pointerx - TkWinfo.pointerx self - end - def TkWinfo.pointery(window) - number(tk_call('winfo', 'pointery', window.path)) - end - def winfo_pointery - TkWinfo.pointery self - end - def TkWinfo.pointerxy(window) - list(tk_call('winfo', 'pointerxy', window.path)) - end - def winfo_pointerxy - TkWinfo.pointerxy self - end -end - -module TkPack - include Tk - extend Tk - def configure(win, *args) - if args[-1].kind_of?(Hash) - keys = args.pop - end - wins = [win.epath] - for i in args - wins.push i.epath - end - tk_call "pack", 'configure', *(wins+hash_kv(keys)) - end - - def forget(*args) - tk_call 'pack', 'forget' *args - end - - def info(slave) - ilist = list(tk_call('pack', 'info', slave.epath)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - return info - end - - def propagate(master, bool=None) - if bool == None - bool(tk_call('pack', 'propagate', master.epath)) - else - tk_call('pack', 'propagate', master.epath, bool) - end - end - - def slaves(master) - list(tk_call('pack', 'slaves', master.epath)) - end - - module_function :configure, :forget, :info, :propagate, :slaves -end - -module TkGrid - include Tk - extend Tk - - def bbox(*args) - list(tk_call('grid', 'bbox', *args)) - end - - def configure(widget, *args) - if args[-1].kind_of?(Hash) - keys = args.pop - end - wins = [widget.epath] - for i in args - wins.push i.epath - end - tk_call "grid", 'configure', *(wins+hash_kv(keys)) - end - - def columnconfigure(master, index, args) - tk_call "grid", 'columnconfigure', master, index, *hash_kv(args) - end - - def rowconfigure(master, index, args) - tk_call "grid", 'rowconfigure', master, index, *hash_kv(args) - end - - def columnconfiginfo(master, index, slot=nil) - if slot - tk_call 'grid', 'columnconfigure', master, index, "-#{slot}" - else - ilist = list(tk_call('grid', 'columnconfigure', master, index)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - info - end - end - - def rowconfiginfo(master, index, slot=nil) - if slot - tk_call 'grid', 'rowconfigure', master, index, "-#{slot}" - else - ilist = list(tk_call('grid', 'rowconfigure', master, index)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - info - end - end - - def add(widget, *args) - configure(widget, *args) - end - - def forget(*args) - tk_call 'grid', 'forget', *args - end - - def info(slave) - list(tk_call('grid', 'info', slave)) - end - - def location(master, x, y) - list(tk_call('grid', 'location', master, x, y)) - end - - def propagate(master, bool=None) - if bool == None - bool(tk_call('grid', 'propagate', master.epath)) - else - tk_call('grid', 'propagate', master.epath, bool) - end - end - - def remove(*args) - tk_call 'grid', 'remove', *args - end - - def size(master) - tk_call 'grid', 'size', master - end - - def slaves(master, args) - list(tk_call('grid', 'slaves', master, *hash_kv(args))) - end - - module_function :bbox, :forget, :propagate, :info - module_function :remove, :size, :slaves, :location - module_function :configure, :columnconfigure, :rowconfigure - module_function :columnconfiginfo, :rowconfiginfo -end - -module TkPlace - include Tk - extend Tk - - def configure(win, slot, value=None) - if slot.kind_of? Hash - tk_call 'place', 'configure', win.epath, *hash_kv(slot) - else - tk_call 'place', 'configure', win.epath, "-#{slot}", value - end - end - - def configinfo(win, slot = nil) - # for >= Tk8.4a2 ? - if slot - conf = tk_split_list(tk_call('place', 'configure', - win.epath, "-#{slot}") ) - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_call('place', 'configure', - win.epath)).collect{|conflist| - conf = tk_split_simplelist(conflist) - conf[0] = conf[0][1..-1] - conf - } - end - end - - def forget(win) - tk_call 'place', 'forget', win - end - - def info(win) - ilist = list(tk_call('place', 'info', win.epath)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - return info - end - - def slaves(master) - list(tk_call('place', 'slaves', master.epath)) - end - - module_function :configure, :configinfo, :forget, :info, :slaves -end - -module TkOption - include Tk - extend Tk - def add pat, value, pri=None - tk_call 'option', 'add', pat, value, pri - end - def clear - tk_call 'option', 'clear' - end - def get win, name, klass - tk_call('option', 'get', win ,name, klass).taint - end - def readfile file, pri=None - tk_call 'option', 'readfile', file, pri - end - module_function :add, :clear, :get, :readfile - - # support procs on the resource database - @@resource_proc_class = Class.new - class << @@resource_proc_class - private :new - - CARRIER = '.'.freeze - METHOD_TBL = {} - ADD_METHOD = false - SAFE_MODE = 4 - - def __check_proc_string__(str) - # If you want to check the proc_string, do it in this method. - str - end - - def method_missing(id, *args) - res_proc = self::METHOD_TBL[id] - unless res_proc.kind_of? Proc - if id == :new || (!self::METHOD_TBL.has_key?(id) && !self::ADD_METHOD) - raise NoMethodError, - "not support resource-proc '#{id.id2name}' for #{self.name}" - end - proc_str = TkOption.get(self::CARRIER, id.id2name, '') - proc_str = '{' + proc_str + '}' unless /\A\{.*\}\Z/ =~ proc_str - proc_str = __check_proc_string__(proc_str) - res_proc = eval 'Block.new' + proc_str - self::METHOD_TBL[id] = res_proc - end - proc{ - $SAFE = self::SAFE_MODE - res_proc.call(*args) - }.call - end - - private :__check_proc_string__, :method_missing - end - - def new_proc_class(klass, func, safe = 4, add = false, parent = nil) - klass = klass.to_s if klass.kind_of? Symbol - unless (?A..?Z) === klass[0] - fail ArgumentError, "bad string '#{klass}' for class name" - end - unless func.kind_of? Array - fail ArgumentError, "method-list must be Array" - end - func_str = func.join(' ') - if parent == nil - install_win(parent) - elsif parent <= @@resource_proc_class - install_win(parent::CARRIER) - else - fail ArgumentError, "parent must be Resource-Proc class" - end - carrier = Tk.tk_call('frame', @path, '-class', klass) - - body = <<-"EOD" - class #{klass} < TkOption.module_eval('@@resource_proc_class') - CARRIER = '#{carrier}'.freeze - METHOD_TBL = {} - ADD_METHOD = #{add} - SAFE_MODE = #{safe} - %w(#{func_str}).each{|f| METHOD_TBL.delete(f.intern) } - end - EOD - - if parent.kind_of?(Class) && parent <= @@resource_proc_class - parent.class_eval body - eval parent.name + '::' + klass - else - eval body - eval 'TkOption::' + klass - end - end - module_function :new_proc_class -end - -module TkTreatFont - def font_configinfo - ret = TkFont.used_on(self.path) - if ret == nil - ret = TkFont.init_widget_font(self.path, self.path, 'configure') - end - ret - end - alias fontobj font_configinfo - - def font_configure(slot) - slot = _symbolkey2str(slot) - if (fnt = slot.delete('font')) - if fnt.kind_of? TkFont - return fnt.call_font_configure(self.path, self.path,'configure',slot) - else - latinfont_configure(fnt) if fnt - end - end - if (ltn = slot.delete('latinfont')) - latinfont_configure(ltn) if ltn - end - if (ltn = slot.delete('asciifont')) - latinfont_configure(ltn) if ltn - end - if (knj = slot.delete('kanjifont')) - kanjifont_configure(knj) if knj - end - - tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {} - self - end - - def latinfont_configure(ltn, keys=nil) - fobj = fontobj - if ltn.kind_of? TkFont - conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val} - if keys - fobj.latin_configure(conf.update(keys)) - else - fobj.latin_configure(conf) - end - else - fobj.latin_replace(ltn) - end - end - alias asciifont_configure latinfont_configure - - def kanjifont_configure(knj, keys=nil) - fobj = fontobj - if knj.kind_of? TkFont - conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val} - if keys - fobj.kanji_configure(conf.update(keys)) - else - fobj.kanji_configure(cond) - end - else - fobj.kanji_replace(knj) - end - end - - def font_copy(window, tag=nil) - if tag - window.tagfontobj(tag).configinfo.each{|key,value| - fontobj.configure(key,value) - } - fontobj.replace(window.tagfontobj(tag).latin_font, - window.tagfontobj(tag).kanji_font) - else - window.fontobj.configinfo.each{|key,value| - fontobj.configure(key,value) - } - fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font) - end - end - - def latinfont_copy(window, tag=nil) - if tag - fontobj.latin_replace(window.tagfontobj(tag).latin_font) - else - fontobj.latin_replace(window.fontobj.latin_font) - end - end - alias asciifont_copy latinfont_copy - - def kanjifont_copy(window, tag=nil) - if tag - fontobj.kanji_replace(window.tagfontobj(tag).kanji_font) - else - fontobj.kanji_replace(window.fontobj.kanji_font) - end - end -end - -module TkTreatItemFont - def __conf_cmd(idx) - raise NotImplementedError, "need to define `__conf_cmd'" - end - def __item_pathname(tagOrId) - raise NotImplementedError, "need to define `__item_pathname'" - end - private :__conf_cmd, :__item_pathname - - def tagfont_configinfo(tagOrId) - pathname = __item_pathname(tagOrId) - ret = TkFont.used_on(pathname) - if ret == nil - ret = TkFont.init_widget_font(pathname, self.path, - __conf_cmd(0), __conf_cmd(1), tagOrId) - end - ret - end - alias tagfontobj tagfont_configinfo - - def tagfont_configure(tagOrId, slot) - pathname = __item_pathname(tagOrId) - slot = _symbolkey2str(slot) - if (fnt = slot.delete('font')) - if fnt.kind_of? TkFont - return fnt.call_font_configure(pathname, self.path, - __conf_cmd(0), __conf_cmd(1), - tagOrId, slot) - else - latintagfont_configure(tagOrId, fnt) if fnt - end - end - if (ltn = slot.delete('latinfont')) - latintagfont_configure(tagOrId, ltn) if ltn - end - if (ltn = slot.delete('asciifont')) - latintagfont_configure(tagOrId, ltn) if ltn - end - if (knj = slot.delete('kanjifont')) - kanjitagfont_configure(tagOrId, knj) if knj - end - - tk_call(self.path, __conf_cmd(0), __conf_cmd(1), - tagOrId, *hash_kv(slot)) if slot != {} - self - end - - def latintagfont_configure(tagOrId, ltn, keys=nil) - fobj = tagfontobj(tagOrId) - if ltn.kind_of? TkFont - conf = {} - ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} - if conf == {} - fobj.latin_replace(ltn) - fobj.latin_configure(keys) if keys - elsif keys - fobj.latin_configure(conf.update(keys)) - else - fobj.latin_configure(conf) - end - else - fobj.latin_replace(ltn) - end - end - alias asciitagfont_configure latintagfont_configure - - def kanjitagfont_configure(tagOrId, knj, keys=nil) - fobj = tagfontobj(tagOrId) - if knj.kind_of? TkFont - conf = {} - knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} - if conf == {} - fobj.kanji_replace(knj) - fobj.kanji_configure(keys) if keys - elsif keys - fobj.kanji_configure(conf.update(keys)) - else - fobj.kanji_configure(conf) - end - else - fobj.kanji_replace(knj) - end - end - - def tagfont_copy(tagOrId, window, wintag=nil) - if wintag - window.tagfontobj(wintag).configinfo.each{|key,value| - tagfontobj(tagOrId).configure(key,value) - } - tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, - window.tagfontobj(wintag).kanji_font) - else - window.tagfont(wintag).configinfo.each{|key,value| - tagfontobj(tagOrId).configure(key,value) - } - tagfontobj(tagOrId).replace(window.fontobj.latin_font, - window.fontobj.kanji_font) - end - end - - def latintagfont_copy(tagOrId, window, wintag=nil) - if wintag - tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) - else - tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) - end - end - alias asciitagfont_copy latintagfont_copy - - def kanjitagfont_copy(tagOrId, window, wintag=nil) - if wintag - tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) - else - tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) - end - end -end - -class TkObject<TkKernel - include Tk - include TkTreatFont - include TkBindCore - - def path - return @path - end - - def epath - return @path - end - - def to_eval - @path - end - - def tk_send(cmd, *rest) - tk_call path, cmd, *rest - end - private :tk_send - - def method_missing(id, *args) - name = id.id2name - case args.length - when 1 - configure name, args[0] - when 0 - begin - cget name - rescue - fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at - end - else - fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at - end - end - - def [](id) - cget id - end - - def []=(id, val) - configure id, val - end - - def cget(slot) - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - tk_call path, 'cget', "-#{slot}" - else - tk_tcl2ruby tk_call(path, 'cget', "-#{slot}") - end - end - - def configure(slot, value=None) - if slot.kind_of? Hash - if (slot['font'] || slot[:font] || - slot['kanjifont'] || slot[:kanjifont] || - slot['latinfont'] || slot[:latinfont] || - slot['asciifont'] || slot[:asciifont] ) - font_configure(slot) - else - tk_call path, 'configure', *hash_kv(slot) - end - - else - if (slot == 'font' || slot == :font || - slot == 'kanjifont' || slot == :kanjifont || - slot == 'latinfont' || slot == :latinfont || - slot == 'asciifont' || slot == :asciifont ) - if value == None - fontobj - else - font_configure({slot=>value}) - end - else - tk_call path, 'configure', "-#{slot}", value - end - end - end - - def configure_cmd(slot, value) - configure slot, install_cmd(value) - end - - def configinfo(slot = nil) - if slot == 'font' || slot == :font || - slot == 'kanjifont' || slot == :kanjifont - fontobj - else - if slot - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - conf = tk_split_simplelist(tk_send('configure', "-#{slot}") ) - else - conf = tk_split_list(tk_send('configure', "-#{slot}") ) - end - conf[0] = conf[0][1..-1] - conf - else - ret = tk_split_simplelist(tk_send('configure') ).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 - } - fontconf = ret.assoc('font') - if fontconf - ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'} - fontconf[4] = fontobj - ret.push(fontconf) - else - ret - end - end - end - end - - def event_generate(context, keys=nil) - if keys - tk_call('event', 'generate', path, - "<#{tk_event_sequence(context)}>", *hash_kv(keys)) - else - tk_call('event', 'generate', path, "<#{tk_event_sequence(context)}>") - end - end - - def tk_trace_variable(v) - unless v.kind_of?(TkVariable) - fail ArgumentError, format("requires TkVariable given %s", v.type) - end - v - end - private :tk_trace_variable - - def destroy - tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id - end -end - -class TkWindow<TkObject - extend TkBindCore - - def initialize(parent=nil, keys=nil) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - keydup = true - parent = keys.delete('parent') - widgetname = keys.delete('widgetname') - install_win(if parent then parent.path end, widgetname) - elsif keys - keys = _symbolkey2str(keys) - widgetname = keys.delete('widgetname') - install_win(if parent then parent.path end, widgetname) - else - install_win(if parent then parent.path end) - end - if self.method(:create_self).arity == 0 - p 'create_self has no arg' if $DEBUG - create_self - if keys - # tk_call @path, 'configure', *hash_kv(keys) - configure(keys) - end - else - p 'create_self has args' if $DEBUG - fontkeys = {} - if keys - ['font', 'kanjifont', 'latinfont', 'asciifont'].each{|key| - fontkeys[key] = keys.delete(key) if keys.key?(key) - } - end - create_self(keys) - font_configure(fontkeys) unless fontkeys.empty? - end - end - - def create_self - end - private :create_self - - def pack(keys = nil) - tk_call 'pack', epath, *hash_kv(keys) - self - end - - def unpack - tk_call 'pack', 'forget', epath - self - end - alias pack_forget unpack - - def pack_config(slot, value=None) - if slot.kind_of? Hash - tk_call 'pack', 'configure', epath, *hash_kv(slot) - else - tk_call 'pack', 'configure', epath, "-#{slot}", value - end - end - - def pack_info() - ilist = list(tk_call('pack', 'info', epath)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - return info - end - - def pack_propagate(mode = nil) - if mode - tk_call('pack', 'propagate', epath, mode) - else - bool(tk_call('pack', 'propagate', epath)) - end - end - - def pack_slaves() - list(tk_call('pack', 'slaves', epath)) - end - - def grid(keys = nil) - tk_call 'grid', epath, *hash_kv(keys) - self - end - - def ungrid - tk_call 'grid', 'forget', epath - self - end - alias grid_forget ungrid - - def grid_bbox(*args) - list(tk_call('grid', 'bbox', epath, *args)) - end - - def grid_config(slot, value=None) - if slot.kind_of? Hash - tk_call 'grid', 'configure', epath, *hash_kv(slot) - else - tk_call 'grid', 'configure', epath, "-#{slot}", value - end - end - - def grid_columnconfig(index, keys) - tk_call('grid', 'columnconfigure', epath, index, *hash_kv(keys)) - end - - def grid_rowconfig(index, keys) - tk_call('grid', 'rowconfigure', epath, index, *hash_kv(keys)) - end - - def grid_columnconfiginfo(index, slot=nil) - if slot - tk_call('grid', 'columnconfigure', epath, index, "-#{slot}") - else - ilist = list(tk_call('grid', 'columnconfigure', epath, index)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - info - end - end - - def grid_rowconfiginfo(index, slot=nil) - if slot - tk_call('grid', 'rowconfigure', epath, index, "-#{slot}") - else - ilist = list(tk_call('grid', 'rowconfigure', epath, index)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - info - end - end - - def grid_info() - list(tk_call('grid', 'info', epath)) - end - - def grid_location(x, y) - list(tk_call('grid', 'location', epath, x, y)) - end - - def grid_propagate(mode=nil) - if mode - tk_call('grid', 'propagate', epath, mode) - else - bool(tk_call('grid', 'propagate', epath)) - end - end - - def grid_remove() - tk_call 'grid', 'remove', epath - end - - def grid_size() - tk_call 'grid', 'size', epath - end - - def grid_slaves(args) - list(tk_call('grid', 'slaves', epath, *hash_kv(args))) - end - - def place(keys = nil) - tk_call 'place', epath, *hash_kv(keys) - self - end - - def unplace - tk_call 'place', 'forget', epath - self - end - alias place_forget unplace - - def place_config(slot, value=None) - if slot.kind_of? Hash - tk_call 'place', 'configure', epath, *hash_kv(slot) - else - tk_call 'place', 'configure', epath, "-#{slot}", value - end - end - - def place_configinfo(slot = nil) - # for >= Tk8.4a2 ? - if slot - conf = tk_split_list(tk_call('place', 'configure', epath, "-#{slot}") ) - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_call('place', - 'configure', epath)).collect{|conflist| - conf = tk_split_simplelist(conflist) - conf[0] = conf[0][1..-1] - conf - } - end - end - - def place_info() - ilist = list(tk_call('place', 'info', epath)) - info = {} - while key = ilist.shift - info[key[1..-1]] = ilist.shift - end - return info - end - - def place_slaves() - list(tk_call('place', 'slaves', epath)) - end - - def focus(force=false) - if force - tk_call 'focus', '-force', path - else - tk_call 'focus', path - end - self - end - - def grab(*args) - if !args or args.length == 0 - tk_call 'grab', 'set', path - elsif args.length == 1 - case args[0] - when 'global', :global - return(tk_call('grab', 'set', '-global', path)) - when 'release', :release - return tk_call('grab', 'release', path) - else - val = tk_call('grab', args[0], path) - end - case args[0] - when 'current', :current - return window(val) - when 'status', :status - return val - end - else - fail ArgumentError, 'wrong # of args' - end - end - - def lower(below=None) - tk_call 'lower', epath, below - self - end - def raise(above=None) - tk_call 'raise', epath, above - self - end - - def command(cmd=Block.new) - configure_cmd 'command', cmd - end - - def colormodel model=None - tk_call 'tk', 'colormodel', path, model - self - end - - def destroy - super - tk_call 'destroy', epath - if @cmdtbl - for id in @cmdtbl - uninstall_cmd id - end - end - uninstall_win - end - - def wait_visibility - tk_call 'tkwait', 'visibility', path - end - alias wait wait_visibility - - def wait_destroy - tk_call 'tkwait', 'window', epath - end - - def bindtags(taglist=nil) - if taglist - fail ArgumentError unless taglist.kind_of? Array - tk_call('bindtags', path, taglist) - else - list(tk_call('bindtags', path)).collect{|tag| - if tag.kind_of?(String) - if cls = WidgetClassNames[tag] - cls - elsif btag = TkBindTag.id2obj(tag) - btag - else - tag - end - else - tag - end - } - end - end -end - -class TkRoot<TkWindow - include Wm - ROOT = [] - def TkRoot.new - return ROOT[0] if ROOT[0] - new = super - ROOT[0] = new - Tk_WINDOWS["."] = new - end - - WidgetClassName = 'Tk'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - def create_self - @path = '.' - end - def path - "." - end -end - -class TkToplevel<TkWindow - include Wm - - WidgetClassName = 'Toplevel'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - -################# old version -# def initialize(parent=nil, screen=nil, classname=nil, keys=nil) -# if screen.kind_of? Hash -# keys = screen.dup -# else -# @screen = screen -# end -# @classname = classname -# if keys.kind_of? Hash -# keys = keys.dup -# @classname = keys.delete('classname') if keys.key?('classname') -# @colormap = keys.delete('colormap') if keys.key?('colormap') -# @container = keys.delete('container') if keys.key?('container') -# @screen = keys.delete('screen') if keys.key?('screen') -# @use = keys.delete('use') if keys.key?('use') -# @visual = keys.delete('visual') if keys.key?('visual') -# end -# super(parent, keys) -# end -# -# def create_self -# s = [] -# s << "-class" << @classname if @classname -# s << "-colormap" << @colormap if @colormap -# s << "-container" << @container if @container -# s << "-screen" << @screen if @screen -# s << "-use" << @use if @use -# s << "-visual" << @visual if @visual -# tk_call 'toplevel', @path, *s -# end -################# - - def initialize(parent=nil, screen=nil, classname=nil, keys=nil) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - @screen = keys['screen'] - @classname = keys['class'] - @colormap = keys['colormap'] - @container = keys['container'] - @screen = keys['screen'] - @use = keys['use'] - @visual = keys['visual'] - super(keys) - return - end - if screen.kind_of? Hash - keys = _symbolkey2str(screen) - else - @screen = screen - end - @classname = classname - if keys.kind_of? Hash - keys = _symbolkey2str(keys) - if keys.key?(:classname) || keys.key?('classname') - keys['class'] = keys.delete('classname') - end - @classname = keys['class'] - @colormap = keys['colormap'] - @container = keys['container'] - @screen = keys['screen'] - @use = keys['use'] - @visual = keys['visual'] - end - super(parent, keys) - end - - def create_self(keys) - if keys and keys != None - tk_call 'toplevel', @path, *hash_kv(keys) - else - tk_call 'toplevel', @path - end - end - - def specific_class - @classname - end -end - -class TkFrame<TkWindow - WidgetClassName = 'Frame'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - -################# old version -# def initialize(parent=nil, keys=nil) -# if keys.kind_of? Hash -# keys = keys.dup -# @classname = keys.delete('classname') if keys.key?('classname') -# @colormap = keys.delete('colormap') if keys.key?('colormap') -# @container = keys.delete('container') if keys.key?('container') -# @visual = keys.delete('visual') if keys.key?('visual') -# end -# super(parent, keys) -# end -# -# def create_self -# s = [] -# s << "-class" << @classname if @classname -# s << "-colormap" << @colormap if @colormap -# s << "-container" << @container if @container -# s << "-visual" << @visual if @visual -# tk_call 'frame', @path, *s -# end -################# - - def initialize(parent=nil, keys=nil) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - else - if keys - keys = _symbolkey2str(keys) - keys['parent'] = parent - else - keys = {'parent'=>parent} - end - end - if keys.key?('classname') - keys['class'] = keys.delete('classname') - end - @classname = keys['class'] - @colormap = keys['colormap'] - @container = keys['container'] - @visual = keys['visual'] - super(keys) - end - - def create_self(keys) - if keys and keys != None - tk_call 'frame', @path, *hash_kv(keys) - else - tk_call 'frame', @path - end - end -end - -class TkLabel<TkWindow - WidgetClassName = 'Label'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - def create_self(keys) - if keys and keys != None - tk_call 'label', @path, *hash_kv(keys) - else - tk_call 'label', @path - end - end - def textvariable(v) - configure 'textvariable', tk_trace_variable(v) - end -end - -class TkButton<TkLabel - WidgetClassNames['Button'] = self - def TkButton.to_eval - 'Button' - end - def create_self(keys) - if keys and keys != None - tk_call 'button', @path, *hash_kv(keys) - else - tk_call 'button', @path - end - end - def invoke - tk_send 'invoke' - end - def flash - tk_send 'flash' - end -end - -class TkRadioButton<TkButton - WidgetClassNames['Radiobutton'] = self - def TkRadioButton.to_eval - 'Radiobutton' - end - def create_self(keys) - if keys and keys != None - tk_call 'radiobutton', @path, *hash_kv(keys) - else - tk_call 'radiobutton', @path - end - end - def deselect - tk_send 'deselect' - end - def select - tk_send 'select' - end - def variable(v) - configure 'variable', tk_trace_variable(v) - end -end -TkRadiobutton = TkRadioButton - -class TkCheckButton<TkRadioButton - WidgetClassNames['Checkbutton'] = self - def TkCheckButton.to_eval - 'Checkbutton' - end - def create_self(keys) - if keys and keys != None - tk_call 'checkbutton', @path, *hash_kv(keys) - else - tk_call 'checkbutton', @path - end - end - def toggle - tk_send 'toggle' - end -end -TkCheckbutton = TkCheckButton - -class TkMessage<TkLabel - WidgetClassNames['Message'] = self - def TkMessage.to_eval - 'Message' - end - def create_self(keys) - if keys and keys != None - tk_call 'message', @path, *hash_kv(keys) - else - tk_call 'message', @path - end - end -end - -class TkScale<TkWindow - WidgetClassName = 'Scale'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - def create_self(keys) - if keys and keys != None - tk_call 'scale', @path, *hash_kv(keys) - else - tk_call 'scale', @path - end - end - - def get(x=None, y=None) - number(tk_send('get', x, y)) - end - - def coords(val=None) - tk_split_list(tk_send('coords', val)) - end - - def identify(x, y) - tk_send('identify', x, y) - end - - def set(val) - tk_send "set", val - end - - def value - get - end - - def value= (val) - set val - end -end - -class TkScrollbar<TkWindow - WidgetClassName = 'Scrollbar'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - def create_self(keys) - if keys and keys != None - tk_call 'scrollbar', @path, *hash_kv(keys) - else - tk_call 'scrollbar', @path - end - end - - def delta(deltax=None, deltay=None) - number(tk_send('delta', deltax, deltay)) - end - - def fraction(x=None, y=None) - number(tk_send('fraction', x, y)) - end - - def identify(x, y) - tk_send('identify', x, y) - end - - def get - ary1 = tk_send('get').split - ary2 = [] - for i in ary1 - ary2.push number(i) - end - ary2 - end - - def set(first, last) - tk_send "set", first, last - end - - def activate(element=None) - tk_send('activate', element) - end -end - -class TkTextWin<TkWindow - def create_self - fail TypeError, "TkTextWin is abstract class" - end - - def bbox(index) - tk_send 'bbox', index - end - def delete(first, last=None) - tk_send 'delete', first, last - end - def get(*index) - tk_send 'get', *index - end - def index(index) - tk_send 'index', index - end - def insert(index, chars, *args) - tk_send 'insert', index, chars, *args - end - def scan_mark(x, y) - tk_send 'scan', 'mark', x, y - end - def scan_dragto(x, y) - tk_send 'scan', 'dragto', x, y - end - def see(index) - tk_send 'see', index - end -end - -module TkTreatListItemFont - include TkTreatItemFont - - ItemCMD = ['itemconfigure', TkComm::None] - def __conf_cmd(idx) - ItemCMD[idx] - end - - def __item_pathname(tagOrId) - self.path + ';' + tagOrId.to_s - end -end - -class TkListbox<TkTextWin - include TkTreatListItemFont - include Scrollable - - WidgetClassNames['Listbox'] = self - def TkListbox.to_eval - 'Listbox' - end - def create_self(keys) - if keys and keys != None - tk_call 'listbox', @path, *hash_kv(keys) - else - tk_call 'listbox', @path - end - end - - def activate(y) - tk_send 'activate', y - end - def curselection - list(tk_send('curselection')) - end - def get(*index) - v = tk_send('get', *index) - if index.size == 1 - v - else - tk_split_simplelist(v) - end - end - def nearest(y) - tk_send('nearest', y).to_i - end - def size - tk_send('size').to_i - end - def selection_anchor(index) - tk_send 'selection', 'anchor', index - end - def selection_clear(first, last=None) - tk_send 'selection', 'clear', first, last - end - def selection_includes(index) - bool(tk_send('selection', 'includes', index)) - end - def selection_set(first, last=None) - tk_send 'selection', 'set', first, last - end - - def itemcget(index, key) - case key.to_s - when 'text', 'label', 'show' - tk_send 'itemcget', index, "-#{key}" - else - tk_tcl2ruby tk_send('itemcget', index, "-#{key}") - end - end - def itemconfigure(index, key, val=None) - if key.kind_of? Hash - if (key['font'] || key[:font] || - key['kanjifont'] || key[:kanjifont] || - key['latinfont'] || key[:latinfont] || - key['asciifont'] || key[:asciifont] ) - tagfont_configure(index, _symbolkey2str(key)) - else - tk_send 'itemconfigure', index, *hash_kv(key) - end - - else - if (key == 'font' || key == :font || - key == 'kanjifont' || key == :kanjifont || - key == 'latinfont' || key == :latinfont || - key == 'asciifont' || key == :asciifont ) - tagfont_configure(index, {key=>val}) - else - tk_call 'itemconfigure', index, "-#{key}", val - end - end - end - - def itemconfiginfo(index, key=nil) - if key - case key.to_s - when 'text', 'label', 'show' - conf = tk_split_simplelist(tk_send('itemconfigure',index,"-#{key}")) - else - conf = tk_split_list(tk_send('itemconfigure',index,"-#{key}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_send('itemconfigure', index)).collect{|conflist| - conf = tk_split_simplelist(conflist) - conf[0] = conf[0][1..-1] - case conf[0] - when 'text', 'label', 'show' - 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 - } - end - end -end - -module TkTreatMenuEntryFont - include TkTreatItemFont - - ItemCMD = ['entryconfigure', TkComm::None] - def __conf_cmd(idx) - ItemCMD[idx] - end - - def __item_pathname(tagOrId) - self.path + ';' + tagOrId.to_s - end -end - -class TkMenu<TkWindow - include TkTreatMenuEntryFont - - WidgetClassName = 'Menu'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - def create_self(keys) - if keys and keys != None - tk_call 'menu', @path, *hash_kv(keys) - else - tk_call 'menu', @path - end - end - def activate(index) - tk_send 'activate', index - end - def add(type, keys=nil) - tk_send 'add', type, *hash_kv(keys) - end - def index(index) - tk_send 'index', index - end - def invoke(index) - tk_send 'invoke', index - end - def insert(index, type, keys=nil) - tk_send 'insert', index, type, *hash_kv(keys) - end - def delete(index, last=None) - tk_send 'delete', index, last - end - def popup(x, y, index=None) - tk_call 'tk_popup', path, x, y, index - end - def post(x, y) - tk_send 'post', x, y - end - def postcascade(index) - tk_send 'postcascade', index - end - def postcommand(cmd=Block.new) - configure_cmd 'postcommand', cmd - end - def tearoffcommand(cmd=Block.new) - configure_cmd 'tearoffcommand', cmd - end - def menutype(index) - tk_send 'type', index - end - def unpost - tk_send 'unpost' - end - def yposition(index) - number(tk_send('yposition', index)) - end - def entrycget(index, key) - case key.to_s - when 'text', 'label', 'show' - tk_send 'entrycget', index, "-#{key}" - else - tk_tcl2ruby tk_send('entrycget', index, "-#{key}") - end - end - def entryconfigure(index, key, val=None) - if key.kind_of? Hash - if (key['font'] || key[:font] || - key['kanjifont'] || key[:kanjifont] || - key['latinfont'] || key[:latinfont] || - key['asciifont'] || key[:asciifont]) - tagfont_configure(index, _symbolkey2str(key)) - else - tk_send 'entryconfigure', index, *hash_kv(key) - end - - else - if (key == 'font' || key == :font || - key == 'kanjifont' || key == :kanjifont || - key == 'latinfont' || key == :latinfont || - key == 'asciifont' || key == :asciifont ) - tagfont_configure({key=>val}) - else - tk_call 'entryconfigure', index, "-#{key}", val - end - end - end - - def entryconfiginfo(index, key=nil) - if key - case key.to_s - when 'text', 'label', 'show' - conf = tk_split_simplelist(tk_send('entryconfigure',index,"-#{key}")) - else - conf = tk_split_list(tk_send('entryconfigure',index,"-#{key}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_send('entryconfigure', index)).collect{|conflist| - conf = tk_split_simplelist(conflist) - conf[0] = conf[0][1..-1] - case conf[0] - when 'text', 'label', 'show' - 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 - } - end - end -end - -class TkMenuClone<TkMenu - def initialize(parent, type=None) - widgetname = nil - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - parent = keys.delete('parent') - widgetname = keys.delete('widgetname') - type = keys.delete('type'); type = None unless type - end - unless parent.kind_of?(TkMenu) - fail ArgumentError, "parent must be TkMenu" - end - @parent = parent - install_win(@parent.path, widgetname) - tk_call @parent.path, 'clone', @path, type - end -end - -module TkSystemMenu - def initialize(parent, keys=nil) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - parent = keys.delete('parent') - end - fail unless parent.kind_of? TkMenu - @path = format("%s.%s", parent.path, self.type::SYSMENU_NAME) - TkComm::Tk_WINDOWS[@path] = self - if self.method(:create_self).arity == 0 - p 'create_self has no arg' if $DEBUG - create_self - configure(keys) if keys - else - p 'create_self has an arg' if $DEBUG - create_self(keys) - end - end -end - -class TkSysMenu_Help<TkMenu - # for all platform - include TkSystemMenu - SYSMENU_NAME = 'help' -end - -class TkSysMenu_System<TkMenu - # for Windows - include TkSystemMenu - SYSMENU_NAME = 'system' -end - -class TkSysMenu_Apple<TkMenu - # for Machintosh - include TkSystemMenu - SYSMENU_NAME = 'apple' -end - -class TkMenubutton<TkLabel - WidgetClassNames['Menubutton'] = self - def TkMenubutton.to_eval - 'Menubutton' - end - def create_self(keys) - if keys and keys != None - tk_call 'menubutton', @path, *hash_kv(keys) - else - tk_call 'menubutton', @path - end - end -end - -class TkOptionMenubutton<TkMenubutton - class OptionMenu<TkMenu - def initialize(parent) - @path = parent.path + '.menu' - TkComm::Tk_WINDOWS[@path] = self - end - end - - def initialize(parent=nil, var=TkVariable.new, firstval=nil, *vals) - if parent.kind_of Hash - keys = _symbolkey2str(parent) - parent = keys['parent'] - var = keys['variable'] if keys['variable'] - firstval, *vals = keys['values'] - end - fail unless var.kind_of? TkVariable - @variable = var - firstval = @variable.value unless firstval - @variable.value = firstval - install_win(if parent then parent.path end) - @menu = OptionMenu.new(self) - tk_call 'tk_optionMenu', @path, @variable.id, firstval, *vals - end - - def value - @variable.value - end - - def activate(index) - @menu.activate(index) - end - def add(value) - @menu.add('radiobutton', 'variable'=>@variable, - 'label'=>value, 'value'=>value) - end - def index(index) - @menu.index(index) - end - def invoke(index) - @menu.invoke(index) - end - def insert(index, value) - @menu.add(index, 'radiobutton', 'variable'=>@variable, - 'label'=>value, 'value'=>value) - end - def delete(index, last=None) - @menu.delete(index, last) - end - def yposition(index) - @menu.yposition(index) - end - def menucget(index, key) - @menu.cget(index, key) - end - def menuconfigure(index, key, val=None) - @menu.configure(index, key, val) - end - def menuconfiginfo(index, key=nil) - @menu.configinfo(index, key) - end - def entrycget(index, key) - @menu.entrycget(index, key) - end - def entryconfigure(index, key, val=None) - @menu.entryconfigure(index, key, val) - end - def entryconfiginfo(index, key=nil) - @menu.entryconfiginfo(index, key) - end -end - -module TkComposite - include Tk - extend Tk - - def initialize(parent=nil, *args) - if parent.kind_of? Hash - keys = _symbolkey2str(parent) - parent = keys['parent'] - keys['parent'] = @frame = TkFrame.new(parent) - @path = @epath = @frame.path - initialize_composite(keys) - else - @frame = TkFrame.new(parent) - @path = @epath = @frame.path - initialize_composite(*args) - end - end - - def epath - @epath - end - - def initialize_composite(*args) end - private :initialize_composite - - def delegate(option, *wins) - unless @delegates - @delegates = {} - @delegates['DEFAULT'] = @frame - end - if @delegates[option].kind_of?(Array) - for i in wins - @delegates[option].push(i) - end - else - @delegates[option] = wins - end - end - - def configure(slot, value=None) - if slot.kind_of? Hash - slot.each{|slot,value| configure slot, value} - else - if @delegates and @delegates[slot] - for i in @delegates[slot] - if not i - i = @delegates['DEFALUT'] - redo - else - last = i.configure(slot, value) - end - end - last - else - super - end - end - end -end - -module TkClipboard - include Tk - extend Tk - - def clear - tk_call 'clipboard', 'clear' - end - def get - begin - tk_call 'selection', 'get', '-selection', 'CLIPBOARD' - rescue - '' - end - end - def set(data) - clear - append(data) - end - def append(data) - tk_call 'clipboard', 'append', data - end - - module_function :clear, :set, :get, :append -end - -autoload :TkCanvas, 'tkcanvas' -autoload :TkImage, 'tkcanvas' -autoload :TkBitmapImage, 'tkcanvas' -autoload :TkPhotoImage, 'tkcanvas' -autoload :TkEntry, 'tkentry' -autoload :TkSpinbox, 'tkentry' -autoload :TkText, 'tktext' -autoload :TkDialog, 'tkdialog' -autoload :TkWarning, 'tkdialog' -autoload :TkMenubar, 'tkmenubar' -autoload :TkAfter, 'tkafter' -autoload :TkPalette, 'tkpalette' -autoload :TkFont, 'tkfont' -autoload :TkVirtualEvent, 'tkvirtevent' -autoload :TkBgError, 'tkbgerror' -autoload :TkManageFocus, 'tkmngfocus' -autoload :TkPalette, 'tkpalette' -autoload :TkWinDDE, 'tkwinpkg' -autoload :TkWinRegistry, 'tkwinpkg' -autoload :TkMacResource, 'tkmacpkg' diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb deleted file mode 100644 index b7c21e7529..0000000000 --- a/ext/tk/lib/tkafter.rb +++ /dev/null @@ -1,312 +0,0 @@ -# -# tkafter.rb : methods for Tcl/Tk after command -# -# $Id$ -# -require 'tk' - -class TkAfter - include TkCore - extend TkCore - - Tk_CBID = [0] - Tk_CBTBL = {} - - INTERP._invoke("proc", "rb_after", "id", "ruby [format \"TkAfter.callback %%Q!%s!\" $id]") - - ############################### - # class methods - ############################### - def TkAfter.callback(obj_id) - @after_id = nil - ex_obj = Tk_CBTBL[obj_id] - return nil if ex_obj == nil; # canceled - _get_eval_string(ex_obj.do_callback) - end - - def TkAfter.info - tk_call('after', 'info').split(' ').collect!{|id| - ret = Tk_CBTBL.find{|key,val| val.after_id == id} - (ret == nil)? id: ret[1] - } - end - - ############################### - # instance methods - ############################### - def do_callback - @in_callback = true - begin - @return_value = @current_proc.call(self) - rescue StandardError, NameError - if @cancel_on_exception - cancel - return nil - else - fail $! - end - end - if @set_next - set_next_callback(@current_args) - else - @set_next = true - end - @in_callback = false - @return_value - end - - def set_callback(sleep, args=nil) - @after_script = "rb_after #{@id}" - @after_id = tk_call('after', sleep, @after_script) - @current_args = args - @current_script = [sleep, @after_script] - end - - def set_next_callback(args) - if @running == false || @proc_max == 0 || @do_loop == 0 - Tk_CBTBL.delete(@id) ;# for GC - @running = false - return - end - if @current_pos >= @proc_max - if @do_loop < 0 || (@do_loop -= 1) > 0 - @current_pos = 0 - else - Tk_CBTBL.delete(@id) ;# for GC - @running = false - return - end - end - - @current_args = args - - if @sleep_time.kind_of? Proc - sleep = @sleep_time.call(self) - else - sleep = @sleep_time - end - @current_sleep = sleep - - cmd, *cmd_args = @loop_proc[@current_pos] - @current_pos += 1 - @current_proc = cmd - - set_callback(sleep, cmd_args) - end - - def initialize(*args) - @id = format("a%.4d", Tk_CBID[0]) - Tk_CBID[0] += 1 - - @set_next = true - - @init_sleep = 0 - @init_proc = nil - @init_args = [] - - @current_script = [] - @current_proc = nil - @current_args = nil - @return_value = nil - - @sleep_time = 0 - @current_sleep = 0 - @loop_exec = 0 - @do_loop = 0 - @loop_proc = [] - @proc_max = 0 - @current_pos = 0 - - @after_id = nil - @after_script = nil - - @cancel_on_exception = true - - set_procs(*args) if args != [] - - @running = false - end - - attr :after_id - attr :after_script - attr :current_proc - attr :current_args - attr :current_sleep - alias :current_interval :current_sleep - attr :return_value - - attr_accessor :loop_exec - - def get_procs - [@init_sleep, @init_proc, @init_args, @sleep_time, @loop_exec, @loop_proc] - end - - def current_status - [@running, @current_sleep, @current_proc, @current_args, - @do_loop, @cancel_on_exception] - end - - def cancel_on_exception? - @cancel_on_exception - end - - def cancel_on_exception=(mode) - @cancel_on_exception = mode - end - - def running? - @running - end - - def loop_rest - @do_loop - end - - def loop_rest=(rest) - @do_loop = rest - end - - def set_procs(interval, loop_exec, *procs) - if !interval == 'idle' \ - && !interval.kind_of?(Integer) && !interval.kind_of?(Proc) - fail format("%s need to be Integer or Proc", interval.inspect) - end - @sleep_time = interval - - @loop_proc = [] - procs.each{|e| - if e.kind_of? Proc - @loop_proc.push([e]) - else - @loop_proc.push(e) - end - } - @proc_max = @loop_proc.size - @current_pos = 0 - - @do_loop = 0 - if loop_exec - if loop_exec.kind_of?(Integer) && loop_exec < 0 - @loop_exec = -1 - elsif loop_exec == nil || loop_exec == false || loop_exec == 0 - @loop_exec = 1 - else - if not loop_exec.kind_of?(Integer) - fail format("%s need to be Integer", loop_exec.inspect) - end - @loop_exec = loop_exec - end - @do_loop = @loop_exec - end - - self - end - - def add_procs(*procs) - procs.each{|e| - if e.kind_of? Proc - @loop_proc.push([e]) - else - @loop_proc.push(e) - end - } - @proc_max = @loop_proc.size - - self - end - - def set_start_proc(sleep, init_proc, *init_args) - if !sleep == 'idle' && !sleep.kind_of?(Integer) - fail format("%s need to be Integer", sleep.inspect) - end - @init_sleep = sleep - @init_proc = init_proc - @init_args = init_args - self - end - - def start(*init_args) - return nil if @running - - Tk_CBTBL[@id] = self - @do_loop = @loop_exec - @current_pos = 0 - - argc = init_args.size - if argc > 0 - sleep = init_args.shift - if !sleep == 'idle' && !sleep.kind_of?(Integer) - fail format("%s need to be Integer", sleep.inspect) - end - @init_sleep = sleep - end - @init_proc = init_args.shift if argc > 1 - @init_args = init_args if argc > 0 - - @current_sleep = @init_sleep - @running = true - if @init_proc - if not @init_proc.kind_of? Proc - fail format("%s need to be Proc", @init_proc.inspect) - end - @current_proc = @init_proc - set_callback(sleep, @init_args) - @set_next = false if @in_callback - else - set_next_callback(@init_args) - end - - self - end - - def restart(*restart_args) - cancel if @running - if restart_args == [] - start(@init_sleep, @init_proc, *@init_args) - else - start(*restart_args) - end - end - - def cancel - @running = false - tk_call 'after', 'cancel', @after_id if @after_id - @after_id = nil - Tk_CBTBL.delete(@id) ;# for GC - self - end - alias stop cancel - - def continue(wait=nil) - sleep, cmd = @current_script - return nil if cmd == nil || @running == true - if wait - if not wait.kind_of? Integer - fail format("%s need to be Integer", wait.inspect) - end - sleep = wait - end - Tk_CBTBL[@id] = self - @running = true - @after_id = tk_call('after', sleep, cmd) - self - end - - def skip - return nil if @running == false - cancel - Tk_CBTBL[@id] = self - @running = true - set_next_callback(@current_args) - self - end - - def info - if @after_id - inf = tk_split_list(tk_call('after', 'info', @after_id)) - [Tk_CBTBL[inf[0][1]], inf[1]] - else - nil - end - end -end diff --git a/ext/tk/lib/tkbgerror.rb b/ext/tk/lib/tkbgerror.rb deleted file mode 100644 index 8022077a3f..0000000000 --- a/ext/tk/lib/tkbgerror.rb +++ /dev/null @@ -1,17 +0,0 @@ -# -# tkbgerror -- bgerror ( tkerror ) module -# 1998/07/16 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> -# -require 'tk' - -module TkBgError - extend Tk - - def bgerror(message) - tk_call 'bgerror', message - end - alias tkerror bgerror - alias show bgerror - - module_function :bgerror, :tkerror, :show -end diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb deleted file mode 100644 index 7f0fba13ec..0000000000 --- a/ext/tk/lib/tkcanvas.rb +++ /dev/null @@ -1,874 +0,0 @@ -# -# tkcanvas.rb - Tk canvas classes -# $Date$ -# by Yukihiro Matsumoto <matz@caelum.co.jp> -# $Date$ -# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> - -require "tk" -require 'tkfont' - -module TkTreatCItemFont - include TkTreatItemFont - - ItemCMD = ['itemconfigure', TkComm::None] - def __conf_cmd(idx) - ItemCMD[idx] - end - - def __item_pathname(tagOrId) - if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) - self.path + ';' + tagOrId.id.to_s - else - self.path + ';' + tagOrId.to_s - end - end -end - -class TkCanvas<TkWindow - include TkTreatCItemFont - include Scrollable - - WidgetClassName = 'Canvas'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - def create_self(keys) - if keys and keys != None - tk_call 'canvas', @path, *hash_kv(keys) - else - tk_call 'canvas', @path - end - end - - def tagid(tag) - if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag) - tag.id - else - tag - end - end - private :tagid - - def addtag(tag, mode, *args) - tk_send 'addtag', tagid(tag), mode, *args - 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('bbox', tagid(tagOrId), *tags.collect{|t| tagid(t)})) - end - - def itembind(tag, context, cmd=Block.new, args=nil) - _bind([path, "bind", tagid(tag)], context, cmd, args) - end - - def itembind_append(tag, context, cmd=Block.new, args=nil) - _bind_append([path, "bind", tagid(tag)], context, cmd, args) - end - - def itembindinfo(tag, context=nil) - _bindinfo([path, "bind", tagid(tag)], context) - end - - def canvasx(x, *args) - tk_tcl2ruby(tk_send('canvasx', x, *args)) - end - def canvasy(y, *args) - tk_tcl2ruby(tk_send('canvasy', y, *args)) - end - - def coords(tag, *args) - if args == [] - tk_split_list(tk_send('coords', tagid(tag))) - else - tk_send('coords', tagid(tag), *args) - end - end - - def dchars(tag, first, last=None) - tk_send 'dchars', tagid(tag), first, last - end - - def delete(*args) - tk_send 'delete', *args.collect{|t| tagid(t)} - end - alias remove delete - - def dtag(tag, tag_to_del=None) - tk_send 'dtag', tagid(tag), tag_to_del - end - - def find(mode, *args) - list(tk_send('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 'focus', tagid(tagOrId) - else - ret = tk_send('focus') - if ret == "" - nil - else - TkcItem.id2obj(self, ret) - end - end - end - - def gettags(tagOrId) - list(tk_send('gettags', tagid(tagOrId))).collect{|tag| - TkcTag.id2obj(self, tag) - } - end - - def icursor(tagOrId, index) - tk_send 'icursor', tagid(tagOrId), index - end - - def index(tagOrId, index) - tk_send 'index', tagid(tagOrId), index - end - - def insert(tagOrId, index, string) - tk_send 'insert', tagid(tagOrId), index, string - end - - def itemcget(tagOrId, option) - case option.to_s - when 'dash', 'activedash', 'disableddash' - conf = tk_send('itemcget', tagid(tagOrId), "-#{option}") - if conf =~ /^[0-9]/ - list(conf) - else - conf - end - when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' - tk_send 'itemcget', tagid(tagOrId), "-#{option}" - else - tk_tcl2ruby tk_send('itemcget', tagid(tagOrId), "-#{option}") - end - end - - def itemconfigure(tagOrId, key, value=None) - if key.kind_of? Hash - key = _symbolkey2str(key) - if ( key['font'] || key['kanjifont'] \ - || key['latinfont'] || key['asciifont'] ) - tagfont_configure(tagOrId, key.dup) - else - tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) - end - - else - if ( key == 'font' || key == :font || - key == 'kanjifont' || key == :kanjifont || - key == 'latinfont' || key == :latinfont || - key == 'asciifont' || key == :asciifont ) - tagfont_configure(tagid(tagOrId), {key=>value}) - else - tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value - end - end - end -# def itemconfigure(tagOrId, key, value=None) -# if key.kind_of? Hash -# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) -# else -# tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value -# end -# end -# def itemconfigure(tagOrId, keys) -# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys) -# end - - def itemconfiginfo(tagOrId, key=nil) - if key - case key.to_s - when 'dash', 'activedash', 'disableddash' - conf = tk_split_simplelist(tk_send('itemconfigure', - tagid(tagOrId), "-#{key}")) - if conf[3] && conf[3] =~ /^[0-9]/ - conf[3] = list(conf[3]) - end - if conf[4] && conf[4] =~ /^[0-9]/ - conf[4] = list(conf[4]) - end - when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' - conf = tk_split_simplelist(tk_send('itemconfigure', - tagid(tagOrId), "-#{key}")) - else - conf = tk_split_list(tk_send('itemconfigure', - tagid(tagOrId), "-#{key}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_send('itemconfigure', - tagid(tagOrId))).collect{|conflist| - conf = tk_split_simplelist(conflist) - conf[0] = conf[0][1..-1] - case conf[0] - when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' - when 'dash', 'activedash', 'disableddash' - if conf[3] && conf[3] =~ /^[0-9]/ - conf[3] = list(conf[3]) - end - if conf[4] && conf[4] =~ /^[0-9]/ - conf[4] = list(conf[4]) - end - 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 - } - end - end - - def lower(tag, below=None) - tk_send 'lower', tagid(tag), tagid(below) - end - - def move(tag, x, y) - tk_send 'move', tagid(tag), x, y - end - - def postscript(keys) - tk_send "postscript", *hash_kv(keys) - end - - def raise(tag, above=None) - tk_send 'raise', tagid(tag), tagid(above) - end - - def scale(tag, x, y, xs, ys) - tk_send 'scale', tagid(tag), x, y, xs, ys - end - - def scan_mark(x, y) - tk_send 'scan', 'mark', x, y - end - def scan_dragto(x, y) - tk_send 'scan', 'dragto', x, y - end - - def select(mode, *args) - tk_send 'select', mode, *args - 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 -end - -module TkcTagAccess - include TkComm - include TkTreatTagFont - - def addtag(tag) - @c.addtag(tag, 'with', @id) - end - - def bbox - @c.bbox(@id) - end - - def bind(seq, cmd=Block.new, args=nil) - @c.itembind @id, seq, cmd, args - end - - def bindinfo(seq=nil) - @c.itembindinfo @id, seq - end - - def cget(option) - @c.itemcget @id, option - end - - def configure(key, value=None) - @c.itemconfigure @id, key, value - end -# def configure(keys) -# @c.itemconfigure @id, keys -# end - - def configinfo(key=nil) - @c.itemconfiginfo @id, key - end - - def coords(*args) - @c.coords @id, *args - end - - def dchars(first, last=None) - @c.dchars @id, first, last - end - - def dtag(tag_to_del=None) - @c.dtag @id, tag_to_del - end - - def find - @c.find 'withtag', @id - end - alias list find - - def focus - @c.itemfocus @id - end - - def gettags - @c.gettags @id - end - - def icursor(index) - @c.icursor @id, index - end - - def index(index) - @c.index @id, index - end - - def insert(beforethis, string) - @c.insert @id, beforethis, string - end - - def lower(belowthis=None) - @c.lower @id, belowthis - end - - def move(xamount, yamount) - @c.move @id, xamount, yamount - end - - def raise(abovethis=None) - @c.raise @id, abovethis - end - - def scale(xorigin, yorigin, xscale, yscale) - @c.scale @id, xorigin, yorigin, xscale, yscale - end - - def select_adjust(index) - @c.select('adjust', @id, index) - end - def select_from(index) - @c.select('from', @id, index) - end - def select_to(index) - @c.select('to', @id, index) - end - - def itemtype - @c.itemtype @id - end - - # Following operators support logical expressions of canvas tags - # (for Tk8.3+). - # If tag1.path is 't1' and tag2.path is 't2', then - # ltag = tag1 & tag2; ltag.path => "(t1)&&(t2)" - # ltag = tag1 | tag2; ltag.path => "(t1)||(t2)" - # ltag = tag1 ^ tag2; ltag.path => "(t1)^(t2)" - # ltag = - tag1; ltag.path => "!(t1)" - def & (tag) - if tag.kind_of? TkObject - TkcTagString.new(@c, '(' + @id + ')&&(' + tag.path + ')') - else - TkcTagString.new(@c, '(' + @id + ')&&(' + tag.to_s + ')') - end - end - - def | (tag) - if tag.kind_of? TkObject - TkcTagString.new(@c, '(' + @id + ')||(' + tag.path + ')') - else - TkcTagString.new(@c, '(' + @id + ')||(' + tag.to_s + ')') - end - end - - def ^ (tag) - if tag.kind_of? TkObject - TkcTagString.new(@c, '(' + @id + ')^(' + tag.path + ')') - else - TkcTagString.new(@c, '(' + @id + ')^(' + tag.to_s + ')') - end - end - - def -@ - TkcTagString.new(@c, '!(' + @id + ')') - end -end - -class TkcTag<TkObject - include TkcTagAccess - - CTagID_TBL = {} - Tk_CanvasTag_ID = ['ctag0000'] - - def TkcTag.id2obj(canvas, id) - cpath = canvas.path - return id unless CTagID_TBL[cpath] - CTagID_TBL[cpath][id]? CTagID_TBL[cpath][id]: id - end - - def initialize(parent, mode=nil, *args) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @c = parent - @cpath = parent.path - @path = @id = Tk_CanvasTag_ID[0] - CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] - CTagID_TBL[@cpath][@id] = self - Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ - if mode - tk_call @c.path, "addtag", @id, mode, *args - end - end - def id - return @id - end - - def delete - @c.delete @id - CTagID_TBL[@cpath].delete(@id) if CTagID_TBL[@cpath] - end - alias remove delete - alias destroy delete - - def set_to_above(target) - @c.addtag_above(@id, target) - end - alias above set_to_above - - def set_to_all - @c.addtag_all(@id) - end - alias all set_to_all - - def set_to_below(target) - @c.addtag_below(@id, target) - end - alias below set_to_below - - def set_to_closest(x, y, halo=None, start=None) - @c.addtag_closest(@id, x, y, halo, start) - end - alias closest set_to_closest - - def set_to_enclosed(x1, y1, x2, y2) - @c.addtag_enclosed(@id, x1, y1, x2, y2) - end - alias enclosed set_to_enclosed - - def set_to_overlapping(x1, y1, x2, y2) - @c.addtag_overlapping(@id, x1, y1, x2, y2) - end - alias overlapping set_to_overlapping - - def set_to_withtag(target) - @c.addtag_withtag(@id, target) - end - alias withtag set_to_withtag -end - -class TkcTagString<TkcTag - def self.new(parent, name, *args) - if CTagID_TBL[parent.path] && CTagID_TBL[parent.path][name] - return CTagID_TBL[parent.path][name] - else - super(parent, name, *args) - end - end - - def initialize(parent, name, mode=nil, *args) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @c = parent - @cpath = parent.path - @path = @id = name - CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] - CTagID_TBL[@cpath][@id] = self - if mode - tk_call @c.path, "addtag", @id, mode, *args - end - end -end -TkcNamedTag = TkcTagString - -class TkcTagAll<TkcTag - def initialize(parent) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @c = parent - @cpath = parent.path - @path = @id = 'all' - CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] - CTagID_TBL[@cpath][@id] = self - end -end - -class TkcTagCurrent<TkcTag - def initialize(parent) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @c = parent - @cpath = parent.path - @path = @id = 'current' - CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] - CTagID_TBL[@cpath][@id] = self - end -end - -class TkcGroup<TkcTag - Tk_cGroup_ID = ['tkcg00000'] - def create_self(parent, *args) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @c = parent - @cpath = parent.path - @path = @id = Tk_cGroup_ID[0] - CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] - CTagID_TBL[@cpath][@id] = self - Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ - add(*args) if args != [] - end - - def include(*tags) - for i in tags - i.addtag @id - end - end - - def exclude(*tags) - for i in tags - i.delete @id - end - end -end - -class TkcItem<TkObject - include TkcTagAccess - - CItemTypeToClass = {} - CItemID_TBL = {} - - def TkcItem.type2class(type) - CItemTypeToClass[type] - end - - def TkcItem.id2obj(canvas, id) - cpath = canvas.path - return id unless CItemID_TBL[cpath] - CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id - end - - def initialize(parent, *args) - if not parent.kind_of?(TkCanvas) - fail format("%s need to be TkCanvas", parent.inspect) - end - @parent = @c = parent - @path = parent.path - fontkeys = {} - if args.size == 1 && args[0].kind_of?(Hash) - args[0] = _symbolkey2str(args[0]) - coords = args[0].delete('coords') - if not coords.kind_of?(Array) - fail "coords parameter must be given by an Array" - end - args[0,0] = coords.flatten - end - if args[-1].kind_of? Hash - keys = _symbolkey2str(args.pop) - ['font', 'kanjifont', 'latinfont', 'asciifont'].each{|key| - fontkeys[key] = keys.delete(key) if keys.key?(key) - } - args += hash_kv(keys) - end - @id = create_self(*args).to_i ;# 'canvas item id' is integer number - CItemID_TBL[@path] = {} unless CItemID_TBL[@path] - CItemID_TBL[@path][@id] = self - font_configure(fontkeys) unless fontkeys.empty? - -######## old version -# if args[-1].kind_of? Hash -# keys = args.pop -# end -# @id = create_self(*args).to_i ;# 'canvas item id' is integer number -# CItemID_TBL[@path] = {} unless CItemID_TBL[@path] -# CItemID_TBL[@path][@id] = self -# if keys -# # tk_call @path, 'itemconfigure', @id, *hash_kv(keys) -# configure(keys) if keys -# end -######## - end - def create_self(*args); end - private :create_self - def id - return @id - end - - def delete - @c.delete @id - CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path] - end - alias remove delete - alias destroy delete -end - -class TkcArc<TkcItem - CItemTypeToClass['arc'] = self - def create_self(*args) - tk_call(@path, 'create', 'arc', *args) - end -end -class TkcBitmap<TkcItem - CItemTypeToClass['bitmap'] = self - def create_self(*args) - tk_call(@path, 'create', 'bitmap', *args) - end -end -class TkcImage<TkcItem - CItemTypeToClass['image'] = self - def create_self(*args) - tk_call(@path, 'create', 'image', *args) - end -end -class TkcLine<TkcItem - CItemTypeToClass['line'] = self - def create_self(*args) - tk_call(@path, 'create', 'line', *args) - end -end -class TkcOval<TkcItem - CItemTypeToClass['oval'] = self - def create_self(*args) - tk_call(@path, 'create', 'oval', *args) - end -end -class TkcPolygon<TkcItem - CItemTypeToClass['polygon'] = self - def create_self(*args) - tk_call(@path, 'create', 'polygon', *args) - end -end -class TkcRectangle<TkcItem - CItemTypeToClass['rectangle'] = self - def create_self(*args) - tk_call(@path, 'create', 'rectangle', *args) - end -end -class TkcText<TkcItem - CItemTypeToClass['text'] = self - def create_self(*args) - tk_call(@path, 'create', 'text', *args) - end -end -class TkcWindow<TkcItem - CItemTypeToClass['window'] = self - def create_self(*args) - tk_call(@path, 'create', 'window', *args) - end -end - -class TkImage<TkObject - include Tk - - Tk_IMGTBL = {} - - Tk_Image_ID = ['i00000'] - def initialize(keys=nil) - @path = Tk_Image_ID[0] - Tk_Image_ID[0] = Tk_Image_ID[0].succ - tk_call 'image', 'create', @type, @path, *hash_kv(keys) - Tk_IMGTBL[@path] = self - end - - def delete - Tk_IMGTBL.delete(@id) if @id - tk_call('image', 'delete', @path) - end - def height - number(tk_call('image', 'height', @path)) - end - def inuse - bool(tk_call('image', 'inuse', @path)) - end - def itemtype - tk_call('image', 'type', @path) - end - def width - number(tk_call('image', 'width', @path)) - end - - def TkImage.names - Tk.tk_call('image', 'names').split.collect!{|id| - (Tk_IMGTBL[id])? Tk_IMGTBL[id] : id - } - end - - def TkImage.types - Tk.tk_call('image', 'types').split - end -end - -class TkBitmapImage<TkImage - def initialize(*args) - @type = 'bitmap' - super - end -end - -class TkPhotoImage<TkImage - def initialize(*args) - @type = 'photo' - super - end - - def blank - tk_send 'blank' - end - - def cget(option) - case option.to_s - when 'data', 'file' - tk_send 'cget', option - else - tk_tcl2ruby tk_send('cget', option) - end - end - - def copy(source, *opts) - args = opts.collect{|term| - if term.kind_of?(String) && term.include?(?\s) - term.split - else - term - end - }.flatten - - tk_send 'copy', source, *args - end - - def data(keys=nil) - tk_send 'data', *hash_kv(keys) - end - - def get(x, y) - tk_send 'get', x, y - end - - def put(data, *to) - if to == [] - tk_send 'put', data - else - tk_send 'put', data, '-to', *to - end - end - - def read(file, *opts) - args = opts.collect{|term| - if term.kind_of?(String) && term.include?(?\s) - term.split - else - term - end - }.flatten - - tk_send 'read', file, *args - end - - def redither - tk_send 'redither' - end - - def write(file, *opts) - args = opts.collect{|term| - if term.kind_of?(String) && term.include?(?\s) - term.split - else - term - end - }.flatten - - tk_send 'write', file, *args - end -end diff --git a/ext/tk/lib/tkclass.rb b/ext/tk/lib/tkclass.rb deleted file mode 100644 index 9ea275e560..0000000000 --- a/ext/tk/lib/tkclass.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# tkclass.rb - Tk classes -# Date: 2000/11/27 09:23:36 -# by Yukihiro Matsumoto <matz@caelum.co.jp> -# -# $Id$ - -require "tk" - -TopLevel = TkToplevel -Frame = TkFrame -Label = TkLabel -Button = TkButton -Radiobutton = TkRadioButton -Checkbutton = TkCheckButton -Message = TkMessage -Entry = TkEntry -Spinbox = TkSpinbox -Text = TkText -Scale = TkScale -Scrollbar = TkScrollbar -Listbox = TkListbox -Menu = TkMenu -Menubutton = TkMenubutton -Canvas = TkCanvas -Arc = TkcArc -Bitmap = TkcBitmap -Line = TkcLine -Oval = TkcOval -Polygon = TkcPolygon -Rectangle = TkcRectangle -TextItem = TkcText -WindowItem = TkcWindow -BitmapImage = TkBitmapImage -PhotoImage = TkPhotoImage -Selection = TkSelection -Winfo = TkWinfo -Pack = TkPack -Grid = TkGrid -Place = TkPlace -Variable = TkVariable -Font = TkFont -VirtualEvent = TkVirtualEvent - -def Mainloop - Tk.mainloop -end diff --git a/ext/tk/lib/tkdialog.rb b/ext/tk/lib/tkdialog.rb deleted file mode 100644 index 8b8ee69128..0000000000 --- a/ext/tk/lib/tkdialog.rb +++ /dev/null @@ -1,142 +0,0 @@ -require "tk" - -class TkDialog < TkWindow - extend Tk - - # initialize tk_dialog - def initialize(keys = nil) - super() - @var = TkVariable.new - id = @var.id - - @title = title - - @message = message - @message_config = message_config - - @bitmap = bitmap - @bitmap_config = message_config - - @default_button = default_button - - @buttons = buttons - @button_configs = proc{|num| button_configs num} - - if keys.kind_of? Hash - keys = _symbolkey2str(keys) - @title = keys['title'] if keys['title'] - @message = keys['message'] if keys['message'] - @bitmap = keys['bitmap'] if keys['bitmap'] - @default_button = keys['default'] if keys['default'] - @buttons = keys['buttons'] if keys['buttons'] - - @command = keys['prev_command'] - - @message_config = keys['message_config'] if keys['message_config'] - @bitmap_config = keys['bitmap_config'] if keys['bitmap_config'] - @button_configs = keys['button_configs'] if keys['button_configs'] - end - - if @title.include? ?\s - @title = '{' + @title + '}' - end - - @buttons = tk_split_list(@buttons) if @buttons.kind_of? String - @buttons = @buttons.collect{|s| - if s.kind_of? Array - s = s.join(' ') - end - if s.include? ?\s - '{' + s + '}' - else - s - end - } - - config = "" - if @message_config.kind_of? Hash - config << format("%s.msg configure %s\n", - @path, hash_kv(@message_config).join(' ')) - end - if @bitmap_config.kind_of? Hash - config << format("%s.msg configure %s\n", - @path, hash_kv(@bitmap_config).join(' ')) - end - if @button_configs.kind_of? Proc - @buttons.each_index{|i| - if (c = @button_configs.call(i)).kind_of? Hash - config << format("%s.button%s configure %s\n", - @path, i, hash_kv(c).join(' ')) - end - } - end - config = 'after idle {' + config + '};' if config != "" - - if @command.kind_of? Proc - @command.call(self) - end - - INTERP._eval('eval {global '+id+';'+config+ - 'set '+id+' [tk_dialog '+ - @path+" "+@title+" {#{@message}} "+@bitmap+" "+ - String(@default_button)+" "+@buttons.join(' ')+']}') - end - def value - return @var.value.to_i - end - ###################################################### - # # - # these methods must be overridden for each dialog # - # # - ###################################################### - def title - return "DIALOG" - end - def message - return "MESSAGE" - end - def message_config - return nil - end - def bitmap - return "info" - end - def bitmap_config - return nil - end - def default_button - return 0 - end - def buttons - #return "BUTTON1 BUTTON2" - return ["BUTTON1", "BUTTON2"] - end - def button_configs(num) - return nil - end -end - -# -# dialog for warning -# -class TkWarning < TkDialog - def initialize(mes) - @mes = mes - super() - end - def message - return @mes - end - def title - return "WARNING"; - end - def bitmap - return "warning"; - end - def default_button - return 0; - end - def buttons - return "OK"; - end -end diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb deleted file mode 100644 index f95fdf340d..0000000000 --- a/ext/tk/lib/tkentry.rb +++ /dev/null @@ -1,224 +0,0 @@ -# -# tkentry.rb - Tk entry classes -# $Date$ -# by Yukihiro Matsumoto <matz@caelum.co.jp> - -require 'tk.rb' - -class TkEntry<TkLabel - include Scrollable - - WidgetClassName = 'Entry'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - class ValidateCmd - include TkComm - - class ValidateArgs - def initialize(d,i,s,v,pp,ss,vv,ww) - @action = d - @index = i - @current = s - @type = v - @value = pp - @string = ss - @triggered = vv - @widget = ww - end - attr :action - attr :index - attr :current - attr :type - attr :value - attr :string - attr :triggered - attr :widget - end - - def initialize(cmd = Block.new, args=nil) - if args - @id = install_cmd(proc{|*arg| - TkUtil.eval_cmd cmd, *arg - }) + " " + args - else - @id = install_cmd(proc{|arg| - TkUtil.eval_cmd cmd, ValidateArgs.new(*arg) - }) + ' %d %i %s %v %P %S %V %W' - end - end - - def to_eval - @id - end - end - - def create_self(keys) - if keys and keys != None - tk_call 'entry', @path, *hash_kv(keys) - else - tk_call 'entry', @path - end - end - - def bbox(index) - tk_send 'bbox', index - end - - def delete(s, e=None) - tk_send 'delete', s, e - end - - def configure(slot, value=None) - if slot.kind_of? Hash - slot = _symbolkey2str(slot) - if slot['vcmd'].kind_of? Array - cmd, *args = slot['vcmd'] - slot['vcmd'] = ValidateCmd.new(cmd, args.join(' ')) - elsif slot['vcmd'].kind_of? Proc - slot['vcmd'] = ValidateCmd.new(slot['vcmd']) - end - if slot['validatecommand'].kind_of? Array - cmd, *args = slot['validatecommand'] - slot['validatecommand'] = ValidateCmd.new(cmd, args.join(' ')) - elsif slot['validatecommand'].kind_of? Proc - slot['validatecommand'] = ValidateCmd.new(slot['validatecommand']) - end - if slot['invcmd'].kind_of? Array - cmd, *args = slot['invcmd'] - slot['invcmd'] = ValidateCmd.new(cmd, args.join(' ')) - elsif slot['invcmd'].kind_of? Proc - slot['invcmd'] = ValidateCmd.new(slot['invcmd']) - end - if slot['invalidcommand'].kind_of? Array - cmd, *args = slot['invalidcommand'] - slot['invalidcommand'] = ValidateCmd.new(cmd, args.join(' ')) - elsif slot['invalidcommand'].kind_of? Proc - slot['invalidcommand'] = ValidateCmd.new(slot['invalidcommand']) - end - super(slot) - else - if (slot == 'vcmd' || slot == :vcmd || - slot == 'validatecommand' || slot == :validatecommand || - slot == 'invcmd' || slot == :invcmd || - slot == 'invalidcommand' || slot == :invalidcommand) - if value.kind_of? Array - cmd, *args = value - value = ValidateCmd.new(cmd, args.join(' ')) - elsif value.kind_of? Proc - value = ValidateCmd.new(value) - end - end - super(slot, value) - end - end - - def cursor - tk_send 'index', 'insert' - end - def cursor=(index) - tk_send 'icursor', index - end - def index(index) - number(tk_send('index', index)) - end - def insert(pos,text) - tk_send 'insert', pos, text - end - def mark(pos) - tk_send 'scan', 'mark', pos - end - def dragto(pos) - tk_send 'scan', 'dragto', pos - end - def selection_adjust(index) - tk_send 'selection', 'adjust', index - end - def selection_clear - tk_send 'selection', 'clear' - end - def selection_from(index) - tk_send 'selection', 'from', index - end - def selection_present() - bool(tk_send('selection', 'present')) - end - def selection_range(s, e) - tk_send 'selection', 'range', s, e - end - def selection_to(index) - tk_send 'selection', 'to', index - end - - def validate(mode = nil) - if mode - configure 'validate', mode - else - if tk_send('validate') == '0' - false - else - true - end - end - end - - def validatecommand(cmd = ValidateCmd.new, args = nil) - if cmd.kind_of?(ValidateCmd) - configure('validatecommand', cmd) - else - configure('validatecommand', ValidateCmd.new(cmd, args)) - end - end - alias vcmd validatecommand - - def invalidcommand(cmd = ValidateCmd.new, args = nil) - if cmd.kind_of?(ValidateCmd) - configure('invalidcommand', cmd) - else - configure('invalidcommand', ValidateCmd.new(cmd, args)) - end - end - alias invcmd invalidcommand - - def value - tk_send 'get' - end - def value= (val) - tk_send 'delete', 0, 'end' - tk_send 'insert', 0, val - end -end - -class TkSpinbox<TkEntry - WidgetClassName = 'Spinbox'.freeze - WidgetClassNames[WidgetClassName] = self - def self.to_eval - WidgetClassName - end - - def create_self(keys) - if keys and keys != None - tk_call 'spinbox', @path, *hash_kv(keys) - else - tk_call 'spinbox', @path - end - end - - def identify(x, y) - tk_send 'identify', x, y - end - - def spinup - tk_send 'invoke', 'spinup' - end - - def spindown - tk_send 'invoke', 'spindown' - end - - def set(str) - tk_send 'set', str - end -end diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb deleted file mode 100644 index d9eb8ecbed..0000000000 --- a/ext/tk/lib/tkfont.rb +++ /dev/null @@ -1,1045 +0,0 @@ -# -# tkfont.rb - the class to treat fonts on Ruby/Tk -# -# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) -# -require 'tk' - -class TkFont - include Tk - extend TkCore - - Tk_FontID = [0] - Tk_FontNameTBL = {} - Tk_FontUseTBL = {} - - # set default font - case Tk::TK_VERSION - when /^4\.*/ - DEFAULT_LATIN_FONT_NAME = 'a14'.freeze - DEFAULT_KANJI_FONT_NAME = 'k14'.freeze - when /^8\.*/ - if JAPANIZED_TK - begin - fontnames = tk_call('font', 'names') - case fontnames - when /defaultgui/ - # Tcl/Tk-JP for Windows - ltn = 'defaultgui' - knj = 'defaultgui' - when /Mincho:Helvetica-12/ - # Tcl/Tk-JP for UNIX/X - ltn, knj = tk_split_simplelist(tk_call('font', 'configure', - 'Mincho:Helvetica-12', - '-compound')) - else - # unknown Tcl/Tk-JP - platform = tk_call('set', 'tcl_platform(platform)') - case platform - when 'unix' - ltn = {'family'=>'Helvetica'.freeze, 'size'=>-12} - knj = 'k14' - #knj = '-misc-fixed-medium-r-normal--14-*-*-*-c-*-jisx0208.1983-0' - when 'windows' - ltn = {'family'=>'MS Sans Serif'.freeze, 'size'=>8} - knj = 'mincho' - when 'macintosh' - ltn = 'system' - knj = 'mincho' - else # unknown - ltn = 'Helvetica' - knj = 'mincho' - end - end - rescue - ltn = 'Helvetica' - knj = 'mincho' - end - - else # not JAPANIZED_TK - begin - platform = tk_call('set', 'tcl_platform(platform)') - case platform - when 'unix' - ltn = {'family'=>'Helvetica'.freeze, 'size'=>-12} - knj = 'k14' - #knj = '-misc-fixed-medium-r-normal--14-*-*-*-c-*-jisx0208.1983-0' - when 'windows' - ltn = {'family'=>'MS Sans Serif'.freeze, 'size'=>8} - knj = 'mincho' - when 'macintosh' - ltn = 'system' - knj = 'mincho' - else # unknown - ltn = 'Helvetica' - knj = 'mincho' - end - rescue - ltn = 'Helvetica' - knj = 'mincho' - end - end - - DEFAULT_LATIN_FONT_NAME = ltn.freeze - DEFAULT_KANJI_FONT_NAME = knj.freeze - - else # unknown version - DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze - DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze - - end - - if $DEBUG - print "default latin font = "; p DEFAULT_LATIN_FONT_NAME - print "default kanji font = "; p DEFAULT_KANJI_FONT_NAME - end - - ################################### - # class methods - ################################### - def TkFont.families(window=nil) - case (Tk::TK_VERSION) - when /^4\.*/ - ['fixed'] - - when /^8\.*/ - if window - tk_split_simplelist(tk_call('font', 'families', '-displayof', window)) - else - tk_split_simplelist(tk_call('font', 'families')) - end - end - end - - def TkFont.names - case (Tk::TK_VERSION) - when /^4\.*/ - r = ['fixed'] - r += ['a14', 'k14'] if JAPANIZED_TK - Tk_FontNameTBL.each_value{|obj| r.push(obj)} - r | [] - - when /^8\.*/ - tk_split_simplelist(tk_call('font', 'names')) - - end - end - - def TkFont.create_copy(font) - fail 'source-font need to be TkFont' unless font.kind_of? TkFont - keys = {} - font.configinfo.each{|key,value| keys[key] = value } - TkFont.new(font.latin_font, font.kanji_font, keys) - end - - def TkFont.get_obj(name) - if name =~ /^(@font[0-9]+)(|c|l|k)$/ - Tk_FontNameTBL[$1] - else - nil - end - end - - def TkFont.init_widget_font(path, *args) - case (Tk::TK_VERSION) - when /^4\.*/ - conf = tk_split_simplelist(tk_call(*args)). - find_all{|prop| prop[0..5]=='-font ' || prop[0..10]=='-kanjifont '}. - collect{|prop| tk_split_simplelist(prop)} - if font_inf = conf.assoc('-font') - ltn = font_inf[4] - ltn = nil if ltn == [] - else - #ltn = nil - raise RuntimeError, "unknown option '-font'" - end - if font_inf = conf.assoc('-kanjifont') - knj = font_inf[4] - knj = nil if knj == [] - else - knj = nil - end - TkFont.new(ltn, knj).call_font_configure(path, *(args + [{}])) - - when /^8\.*/ - font_prop = tk_split_simplelist(tk_call(*args)).find{|prop| - prop[0..5] == '-font ' - } - unless font_prop - raise RuntimeError, "unknown option '-font'" - end - fnt = tk_split_simplelist(font_prop)[4] - if fnt == "" - TkFont.new(nil, nil).call_font_configure(path, *(args + [{}])) - else - begin - compound = tk_split_simplelist( - Hash[*tk_split_simplelist(tk_call('font', 'configure', - fnt))].collect{|key,value| - [key[1..-1], value] - }.assoc('compound')[1]) - rescue - compound = [] - end - if compound == [] - #TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \ - #.call_font_configure(path, *(args + [{}])) - TkFont.new(fnt).call_font_configure(path, *(args + [{}])) - else - TkFont.new(compound[0], compound[1]) \ - .call_font_configure(path, *(args + [{}])) - end - end - end - end - - def TkFont.used_on(path=nil) - if path - Tk_FontUseTBL[path] - else - Tk_FontUseTBL.values | [] - end - end - - def TkFont.failsafe(font) - begin - if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK - tk_call('font', 'failsafe', font) - end - rescue - end - end - - ################################### - private - ################################### - def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil) - @id = format("@font%.4d", Tk_FontID[0]) - Tk_FontID[0] += 1 - Tk_FontNameTBL[@id] = self - knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj - create_compoundfont(ltn, knj, keys) - end - - def _get_font_info_from_hash(font) - font = _symbolkey2str(font) - foundry = (info = font['foundry'] .to_s)? info: '*' - family = (info = font['family'] .to_s)? info: '*' - weight = (info = font['weight'] .to_s)? info: '*' - slant = (info = font['slant'] .to_s)? info: '*' - swidth = (info = font['swidth'] .to_s)? info: '*' - adstyle = (info = font['adstyle'] .to_s)? info: '*' - pixels = (info = font['pixels'] .to_s)? info: '*' - points = (info = font['points'] .to_s)? info: '*' - resx = (info = font['resx'] .to_s)? info: '*' - resy = (info = font['resy'] .to_s)? info: '*' - space = (info = font['space'] .to_s)? info: '*' - avgWidth = (info = font['avgWidth'].to_s)? info: '*' - charset = (info = font['charset'] .to_s)? info: '*' - encoding = (info = font['encoding'].to_s)? info: '*' - - [foundry, family, weight, slant, swidth, adstyle, - pixels, points, resx, resy, space, avgWidth, charset, encoding] - end - - def create_latinfont_tk4x(font) - if font.kind_of? Hash - @latinfont = '-' + _get_font_info_from_hash(font).join('-') + '-' - - elsif font.kind_of? Array - finfo = {} - finfo['family'] = font[0].to_s - if font[1] - fsize = font[1].to_s - if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/ - if $1 == '-' - finfo['pixels'] = $2 - else - finfo['points'] = $2 - end - else - finfo['points'] = '13' - end - end - font[2..-1].each{|style| - case (style) - when 'normal' - finfo['weight'] = style - when 'bold' - finfo['weight'] = style - when 'roman' - finfo['slant'] = 'r' - when 'italic' - finfo['slant'] = 'i' - end - } - - @latinfont = '-' + _get_font_info_from_hash(finfo).join('-') + '-' - - elsif font.kind_of? TkFont - @latinfont = font.latin_font - - else - if font - @latinfont = font - else - @latinfont = DEFAULT_LATIN_FONT_NAME - end - - end - end - - def create_kanjifont_tk4x(font) - unless JAPANIZED_TK - @kanjifont = "" - return - end - - if font.kind_of? Hash - @kanjifont = '-' + _get_font_info_from_hash(font).join('-') + '-' - - elsif font.kind_of? Array - finfo = {} - finfo['family'] = font[0].to_s - if font[1] - fsize = font[1].to_s - if fsize != '0' && fsize =~ /^(|\+|-)([0-9]+)$/ - if $1 == '-' - finfo['pixels'] = $2 - else - finfo['points'] = $2 - end - else - finfo['points'] = '13' - end - end - font[2..-1].each{|style| - case (style) - when 'normal' - finfo['weight'] = style - when 'bold' - finfo['weight'] = style - when 'roman' - finfo['slant'] = 'r' - when 'italic' - finfo['slant'] = 'i' - end - } - - @kanjifont = '-' + _get_font_info_from_hash(finfo).join('-') + '-' - elsif font.kind_of? TkFont - @kanjifont = font.kanji_font - else - if font - @kanjifont = font - else - @kanjifont = DEFAULT_KANJI_FONT_NAME - end - end - end - - def create_compoundfont_tk4x(ltn, knj, keys) - create_latinfont(ltn) - create_kanjifont(knj) - - if JAPANIZED_TK - @compoundfont = [[@latinfont], [@kanjifont]] - @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont} - else - @compoundfont = @latinfont - @fontslot = {'font'=>@latinfont} - end - end - - def create_latinfont_tk8x(font) - @latinfont = @id + 'l' - - if JAPANIZED_TK - if font.kind_of? Hash - if font[:charset] || font['charset'] - tk_call('font', 'create', @latinfont, *hash_kv(font)) - else - tk_call('font', 'create', @latinfont, - '-charset', 'iso8859', *hash_kv(font)) - end - elsif font.kind_of? Array - tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font)) - tk_call('font', 'configure', @latinfont, '-charset', 'iso8859') - elsif font.kind_of? TkFont - tk_call('font', 'create', @latinfont, '-copy', font.latin_font) - elsif font - tk_call('font', 'create', @latinfont, '-copy', font, - '-charset', 'iso8859') - else - tk_call('font', 'create', @latinfont, '-charset', 'iso8859') - end - else - if font.kind_of? Hash - tk_call('font', 'create', @latinfont, *hash_kv(font)) - else - keys = {} - if font.kind_of? Array - actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} - elsif font.kind_of? TkFont - actual_core(font.latin_font).each{|key,val| keys[key] = val} - elsif font - actual_core(font).each{|key,val| keys[key] = val} - end - tk_call('font', 'create', @latinfont, *hash_kv(keys)) - end - - if font && @compoundfont - keys = {} - actual_core(@latinfont).each{|key,val| keys[key] = val} - tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) - end - end - end - - def create_kanjifont_tk8x(font) - @kanjifont = @id + 'k' - - if JAPANIZED_TK - if font.kind_of? Hash - if font[:charset] || font['charset'] - tk_call('font', 'create', @kanjifont, *hash_kv(font)) - else - tk_call('font', 'create', @kanjifont, - '-charset', 'jisx0208.1983', *hash_kv(font)) - end - elsif font.kind_of? Array - tk_call('font', 'create', @kanjifont, '-copy', array2tk_list(font)) - tk_call('font', 'configure', @kanjifont, '-charset', 'jisx0208.1983') - elsif font.kind_of? TkFont - tk_call('font', 'create', @kanjifont, '-copy', font.kanji_font) - elsif font - tk_call('font', 'create', @kanjifont, '-copy', font, - '-charset', 'jisx0208.1983') - else - tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983') - end - # end of JAPANIZED_TK - - else - if font.kind_of? Hash - tk_call('font', 'create', @kanjifont, *hash_kv(font)) - else - keys = {} - if font.kind_of? Array - actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} - elsif font.kind_of? TkFont - actual_core(font.kanji_font).each{|key,val| keys[key] = val} - elsif font - actual_core(font).each{|key,val| keys[key] = val} - end - tk_call('font', 'create', @kanjifont, *hash_kv(keys)) - end - - if font && @compoundfont - keys = {} - actual_core(@kanjifont).each{|key,val| keys[key] = val} - tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) - end - end - end - - def create_compoundfont_tk8x(ltn, knj, keys) - create_latinfont(ltn) - create_kanjifont(knj) - - @compoundfont = @id + 'c' - if JAPANIZED_TK - @fontslot = {'font'=>@compoundfont} - tk_call('font', 'create', @compoundfont, - '-compound', [@latinfont, @kanjifont], *hash_kv(keys)) - else - tk_call('font', 'create', @compoundfont) - - latinkeys = {} - begin - actual_core(@latinfont).each{|key,val| latinkeys[key] = val} - rescue - latinkeys {} - end - if latinkeys != {} - tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) - end - - if knj - kanjikeys = {} - begin - actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val} - rescue - kanjikeys {} - end - if kanjikeys != {} - tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys)) - end - end - - @fontslot = {'font'=>@compoundfont} - tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) - end - end - - def actual_core_tk4x(font, window=nil, option=nil) - # dummy - if option - "" - else - [['family',[]], ['size',[]], ['weight',[]], ['slant',[]], - ['underline',[]], ['overstrike',[]], ['charset',[]], - ['pointadjust',[]]] - end - end - - def actual_core_tk8x(font, window=nil, option=nil) - if option == 'compound' - "" - elsif option - if window - tk_call('font', 'actual', font, "-displayof", window, "-#{option}") - else - tk_call('font', 'actual', font, "-#{option}") - end - else - l = tk_split_simplelist(if window - tk_call('font', 'actual', font, - "-displayof", window) - else - tk_call('font', 'actual', font) - end) - r = [] - while key=l.shift - if key == '-compound' - l.shift - else - r.push [key[1..-1], l.shift] - end - end - r - end - end - - def configure_core_tk4x(font, slot, value=None) - "" - end - - def configinfo_core_tk4x(font, option=nil) - # dummy - if option - "" - else - [['family',[]], ['size',[]], ['weight',[]], ['slant',[]], - ['underline',[]], ['overstrike',[]], ['charset',[]], - ['pointadjust',[]]] - end - end - - def configure_core_tk8x(font, slot, value=None) - if slot.kind_of? Hash - tk_call 'font', 'configure', font, *hash_kv(slot) - else - tk_call 'font', 'configure', font, "-#{slot}", value - end - end - - def configinfo_core_tk8x(font, option=nil) - if option == 'compound' - "" - elsif option - tk_call('font', 'configure', font, "-#{option}") - else - l = tk_split_simplelist(tk_call('font', 'configure', font)) - r = [] - while key=l.shift - if key == '-compound' - l.shift - else - r.push [key[1..-1], l.shift] - end - end - r - end - end - - def delete_core_tk4x - Tk_FontNameTBL.delete(@id) - Tk_FontUseTBL.delete_if{|key,value| value == self} - end - - def delete_core_tk8x - begin - tk_call('font', 'delete', @latinfont) - rescue - end - begin - tk_call('font', 'delete', @kanjifont) - rescue - end - begin - tk_call('font', 'delete', @compoundfont) - rescue - end - Tk_FontNameTBL.delete(@id) - Tk_FontUseTBL.delete_if{|key,value| value == self} - end - - def latin_replace_core_tk4x(ltn) - create_latinfont_tk4x(ltn) - @compoundfont[0] = [@latinfont] if JAPANIZED_TK - @fontslot['font'] = @latinfont - Tk_FontUseTBL.dup.each{|w, fobj| - if self == fobj - begin - if w.include?(';') - win, tag = w.split(';') - winobj = tk_tcl2ruby(win) -# winobj.tagfont_configure(tag, {'font'=>@latinfont}) - if winobj.kind_of? TkText - tk_call(win, 'tag', 'configure', tag, '-font', @latinfont) - elsif winobj.kind_of? TkCanvas - tk_call(win, 'itemconfigure', tag, '-font', @latinfont) - elsif winobj.kind_of? TkMenu - tk_call(win, 'entryconfigure', tag, '-font', @latinfont) - else - raise RuntimeError, "unknown widget type" - end - else -# tk_tcl2ruby(w).font_configure('font'=>@latinfont) - tk_call(w, 'configure', '-font', @latinfont) - end - rescue - Tk_FontUseTBL.delete(w) - end - end - } - self - end - - def kanji_replace_core_tk4x(knj) - return self unless JAPANIZED_TK - - create_kanjifont_tk4x(knj) - @compoundfont[1] = [@kanjifont] - @fontslot['kanjifont'] = @kanjifont - Tk_FontUseTBL.dup.each{|w, fobj| - if self == fobj - begin - if w.include?(';') - win, tag = w.split(';') - winobj = tk_tcl2ruby(win) -# winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont}) - if winobj.kind_of? TkText - tk_call(win, 'tag', 'configure', tag, '-kanjifont', @kanjifont) - elsif winobj.kind_of? TkCanvas - tk_call(win, 'itemconfigure', tag, '-kanjifont', @kanjifont) - elsif winobj.kind_of? TkMenu - tk_call(win, 'entryconfigure', tag, '-kanjifont', @latinfont) - else - raise RuntimeError, "unknown widget type" - end - else -# tk_tcl2ruby(w).font_configure('kanjifont'=>@kanjifont) - tk_call(w, 'configure', '-kanjifont', @kanjifont) - end - rescue - Tk_FontUseTBL.delete(w) - end - end - } - self - end - - def latin_replace_core_tk8x(ltn) - begin - tk_call('font', 'delete', @latinfont) - rescue - end - create_latinfont(ltn) - self - end - - def kanji_replace_core_tk8x(knj) - begin - tk_call('font', 'delete', @kanjifont) - rescue - end - create_kanjifont(knj) - self - end - - def measure_core_tk4x(window, text) - 0 - end - - def measure_core_tk8x(window, text) - if window - number(tk_call('font', 'measure', @compoundfont, - '-displayof', window, text)) - else - number(tk_call('font', 'measure', @compoundfont, text)) - end - end - - def metrics_core_tk4x(font, window, option=nil) - # dummy - if option - "" - else - [['ascent',[]], ['descent',[]], ['linespace',[]], ['fixed',[]]] - end - end - - def metrics_core_tk8x(font, window, option=nil) - if option - if window - number(tk_call('font', 'metrics', font, - "-displayof", window, "-#{option}")) - else - number(tk_call('font', 'metrics', font, "-#{option}")) - end - else - l = tk_split_list(if window - tk_call('font','metrics',font,"-displayof",window) - else - tk_call('font','metrics',font) - end) - r = [] - while key=l.shift - r.push [key[1..-1], l.shift.to_i] - end - r - end - end - - ################################### - # private alias - ################################### - case (Tk::TK_VERSION) - when /^4\.*/ - alias create_latinfont create_latinfont_tk4x - alias create_kanjifont create_kanjifont_tk4x - alias create_compoundfont create_compoundfont_tk4x - alias actual_core actual_core_tk4x - alias configure_core configure_core_tk4x - alias configinfo_core configinfo_core_tk4x - alias delete_core delete_core_tk4x - alias latin_replace_core latin_replace_core_tk4x - alias kanji_replace_core kanji_replace_core_tk4x - alias measure_core measure_core_tk4x - alias metrics_core metrics_core_tk4x - - when /^8\.[0123]/ - alias create_latinfont create_latinfont_tk8x - alias create_kanjifont create_kanjifont_tk8x - alias create_compoundfont create_compoundfont_tk8x - alias actual_core actual_core_tk8x - alias configure_core configure_core_tk8x - alias configinfo_core configinfo_core_tk8x - alias delete_core delete_core_tk8x - alias latin_replace_core latin_replace_core_tk8x - alias kanji_replace_core kanji_replace_core_tk8x - alias measure_core measure_core_tk8x - alias metrics_core metrics_core_tk8x - - when /^8\.*/ - alias create_latinfont create_latinfont_tk8x - alias create_kanjifont create_kanjifont_tk8x - alias create_compoundfont create_compoundfont_tk8x - alias actual_core actual_core_tk8x - alias configure_core configure_core_tk8x - alias configinfo_core configinfo_core_tk8x - alias delete_core delete_core_tk8x - alias latin_replace_core latin_replace_core_tk8x - alias kanji_replace_core kanji_replace_core_tk8x - alias measure_core measure_core_tk8x - alias metrics_core metrics_core_tk8x - - end - - ################################### - public - ################################### - def method_missing(id, *args) - name = id.id2name - case args.length - when 1 - configure name, args[0] - when 0 - begin - configinfo name - rescue - fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at - end - else - fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at - end - end - - def call_font_configure(path, *args) - args += hash_kv(args.pop.update(@fontslot)) - tk_call(*args) - Tk_FontUseTBL[path] = self - self - end - - def used - ret = [] - Tk_FontUseTBL.each{|key,value| - if key.include?(';') - win, tag = key.split(';') - winobj = tk_tcl2ruby(win) - if winobj.kind_of? TkText - ret.push([winobj, winobj.tagid2obj(tag)]) - elsif winobj.kind_of? TkCanvas - if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag - ret.push([winobj, tagobj]) - elsif (tagobj = TkcItem.id2obj(tag)).kind_of? TkcItem - ret.push([winobj, tagobj]) - else - ret.push([winobj, tag]) - end - elsif winobj.kind_of? TkMenu - ret.push([winobj, tag]) - else - ret.push([win, tag]) - end - else - ret.push(tk_tcl2ruby(key)) if value == self - end - } - ret - end - - def id - @id - end - - def to_eval - font - end - - def font - @compoundfont - end - - def latin_font - @latinfont - end - - def kanji_font - @kanjifont - end - - def actual(option=nil) - actual_core(@compoundfont, nil, option) - end - - def actual_displayof(window, option=nil) - window = '.' unless window - actual_core(@compoundfont, window, option) - end - - def latin_actual(option=nil) - actual_core(@latinfont, nil, option) - end - - def latin_actual_displayof(window, option=nil) - window = '.' unless window - actual_core(@latinfont, window, option) - end - - def kanji_actual(option=nil) - #if JAPANIZED_TK - if @kanjifont != "" - actual_core(@kanjifont, nil, option) - else - actual_core_tk4x(nil, nil, option) - end - end - - def kanji_actual_displayof(window, option=nil) - #if JAPANIZED_TK - if @kanjifont != "" - window = '.' unless window - actual_core(@kanjifont, window, option) - else - actual_core_tk4x(nil, window, option) - end - end - - def [](slot) - configinfo slot - end - - def []=(slot, val) - configure slot, val - end - - def configure(slot, value=None) - configure_core(@compoundfont, slot, value) - end - - def configinfo(slot=nil) - configinfo_core(@compoundfont, slot) - end - - def delete - delete_core - end - - def latin_configure(slot, value=None) - if JAPANIZED_TK - configure_core(@latinfont, slot, value) - else - configure(slot, value) - end - end - - def latin_configinfo(slot=nil) - if JAPANIZED_TK - configinfo_core(@latinfont, slot) - else - configinfo(slot) - end - end - - def kanji_configure(slot, value=None) - #if JAPANIZED_TK - if @kanjifont != "" - configure_core(@kanjifont, slot, value) - configure('size'=>configinfo('size')) # to reflect new configuration - else - #"" - configure(slot, value) - end - end - - def kanji_configinfo(slot=nil) - #if JAPANIZED_TK - if @kanjifont != "" - configinfo_core(@kanjifont, slot) - else - #[] - configinfo(slot) - end - end - - def replace(ltn, knj) - latin_replace(ltn) - kanji_replace(knj) - self - end - - def latin_replace(ltn) - latin_replace_core(ltn) - reset_pointadjust - end - - def kanji_replace(knj) - kanji_replace_core(knj) - reset_pointadjust - end - - def measure(text) - measure_core(nil, text) - end - - def measure_displayof(window, text) - window = '.' unless window - measure_core(window, text) - end - - def metrics(option=nil) - metrics_core(@compoundfont, nil, option) - end - - def metrics_displayof(window, option=nil) - window = '.' unless window - metrics_core(@compoundfont, window, option) - end - - def latin_metrics(option=nil) - metrics_core(@latinfont, nil, option) - end - - def latin_metrics_displayof(window, option=nil) - window = '.' unless window - metrics_core(@latinfont, window, option) - end - - def kanji_metrics(option=nil) - if JAPANIZED_TK - metrics_core(@kanjifont, nil, option) - else - metrics_core_tk4x(nil, nil, option) - end - end - - def kanji_metrics_displayof(window, option=nil) - if JAPANIZED_TK - window = '.' unless window - metrics_core(@kanjifont, window, option) - else - metrics_core_tk4x(nil, window, option) - end - end - - def reset_pointadjust - begin - if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK - configure('pointadjust' => latin_actual.assoc('size')[1].to_f / - kanji_actual.assoc('size')[1].to_f ) - end - rescue - end - self - end - - ################################### - # public alias - ################################### - alias ascii_font latin_font - alias create_asciifont create_latinfont - alias ascii_actual latin_actual - alias ascii_actual_displayof latin_actual_displayof - alias ascii_configure latin_configure - alias ascii_configinfo latin_configinfo - alias ascii_replace latin_replace - alias ascii_metrics latin_metrics - -end - -module TkTreatTagFont - def font_configinfo - @parent.tagfont_configinfo(@id) - end -# alias font font_configinfo - - def font_configure(slot) - @parent.tagfont_configure(@id, slot) - end - - def latinfont_configure(ltn, keys=nil) - @parent.latintagfont_configure(@id, ltn, keys) - end - alias asciifont_configure latinfont_configure - - def kanjifont_configure(knj, keys=nil) - @parent.kanjitagfont_configure(@id, ltn, keys) - end - - def font_copy(window, wintag=nil) - @parent.tagfont_copy(@id, window, wintag) - end - - def latinfont_copy(window, wintag=nil) - @parent.latintagfont_copy(@id, window, wintag) - end - alias asciifont_copy latinfont_copy - - def kanjifont_copy(window, wintag=nil) - @parent.kanjitagfont_copy(@id, window, wintag) - end -end diff --git a/ext/tk/lib/tkmenubar.rb b/ext/tk/lib/tkmenubar.rb deleted file mode 100644 index 0d29571eb7..0000000000 --- a/ext/tk/lib/tkmenubar.rb +++ /dev/null @@ -1,143 +0,0 @@ -# -# tkmenubar.rb -# -# Copyright (C) 1998 maeda shugo. All rights reserved. -# This file can be distributed under the terms of the Ruby. - -# Usage: -# -# menu_spec = [ -# [['File', 0], -# ['Open', proc{puts('Open clicked')}, 0], -# '---', -# ['Quit', proc{exit}, 0]], -# [['Edit', 0], -# ['Cut', proc{puts('Cut clicked')}, 2], -# ['Copy', proc{puts('Copy clicked')}, 0], -# ['Paste', proc{puts('Paste clicked')}, 0]] -# ] -# menubar = TkMenubar.new(nil, menu_spec, -# 'tearoff'=>false, -# 'foreground'=>'grey40', -# 'activeforeground'=>'red', -# 'font'=>'-adobe-helvetica-bold-r-*--12-*-iso8859-1') -# menubar.pack('side'=>'top', 'fill'=>'x') -# -# -# OR -# -# -# menubar = TkMenubar.new -# menubar.add_menu([['File', 0], -# ['Open', proc{puts('Open clicked')}, 0], -# '---', -# ['Quit', proc{exit}, 0]]) -# menubar.add_menu([['Edit', 0], -# ['Cut', proc{puts('Cut clicked')}, 2], -# ['Copy', proc{puts('Copy clicked')}, 0], -# ['Paste', proc{puts('Paste clicked')}, 0]]) -# menubar.configure('tearoff', false) -# menubar.configure('foreground', 'grey40') -# menubar.configure('activeforeground', 'red') -# menubar.configure('font', '-adobe-helvetica-bold-r-*--12-*-iso8859-1') -# menubar.pack('side'=>'top', 'fill'=>'x') - -# The format of the menu_spec is: -# [ -# [ -# [button text, underline, accelerator], -# [menu label, command, underline, accelerator], -# '---', # separator -# ... -# ], -# ... -# ] - -# underline and accelerator are optional parameters. -# Hashes are OK instead of Arrays. - -# To use add_menu, configuration must be done by calling configure after -# adding all menus by add_menu, not by the constructor arguments. - -require "tk" - -class TkMenubar<TkFrame - - include TkComposite - - def initialize(parent = nil, spec = nil, options = nil) - if parent.kind_of? Hash - options = _symbolkey2str(parent) - spec = options.delete('spec') - super(options) - else - super(parent, options) - end - - @menus = [] - - if spec - for menu_info in spec - add_menu(menu_info) - end - end - - if options - for key, value in options - configure(key, value) - end - end - end - - def add_menu(menu_info) - btn_info = menu_info.shift - mbtn = TkMenubutton.new(@frame) - - if btn_info.kind_of?(Hash) - for key, value in btn_info - mbtn.configure(key, value) - end - elsif btn_info.kind_of?(Array) - mbtn.configure('text', btn_info[0]) if btn_info[0] - mbtn.configure('underline', btn_info[1]) if btn_info[1] - mbtn.configure('accelerator', btn_info[2]) if btn_info[2] - else - mbtn.configure('text', btn_info) - end - - menu = TkMenu.new(mbtn) - - for item_info in menu_info - if item_info.kind_of?(Hash) - menu.add('command', item_info) - elsif item_info.kind_of?(Array) - options = {} - options['label'] = item_info[0] if item_info[0] - options['command'] = item_info[1] if item_info[1] - options['underline'] = item_info[2] if item_info[2] - options['accelerator'] = item_info[3] if item_info[3] - menu.add('command', options) - elsif /^-+$/ =~ item_info - menu.add('sep') - else - menu.add('command', 'label' => item_info) - end - end - - mbtn.menu(menu) - @menus.push([mbtn, menu]) - delegate('tearoff', menu) - delegate('foreground', mbtn, menu) - delegate('background', mbtn, menu) - delegate('disabledforeground', mbtn, menu) - delegate('activeforeground', mbtn, menu) - delegate('activebackground', mbtn, menu) - delegate('font', mbtn, menu) - delegate('kanjifont', mbtn, menu) - mbtn.pack('side' => 'left') - end - - def [](index) - return @menus[index] - end -end diff --git a/ext/tk/lib/tkmngfocus.rb b/ext/tk/lib/tkmngfocus.rb deleted file mode 100644 index 921fb646e7..0000000000 --- a/ext/tk/lib/tkmngfocus.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# tkmngfocus.rb : methods for Tcl/Tk standard library 'focus.tcl' -# 1998/07/16 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> -# -require 'tk' - -module TkManageFocus - extend Tk - - def TkManageFocus.followsMouse - tk_call 'tk_focusFollowsMouse' - end - - def TkManageFocus.next(window) - tk_call 'tk_focusNext', window - end - def focusNext - TkManageFocus.next(self) - end - - def TkManageFocus.prev(window) - tk_call 'tk_focusPrev', window - end - def focusPrev - TkManageFocus.prev(self) - end -end diff --git a/ext/tk/lib/tkpalette.rb b/ext/tk/lib/tkpalette.rb deleted file mode 100644 index a2dc7c87cb..0000000000 --- a/ext/tk/lib/tkpalette.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# tkpalette.rb : methods for Tcl/Tk standard library 'palette.tcl' -# 1998/06/21 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> -# -require 'tk' - -module TkPalette - include Tk - extend Tk - - def TkPalette.set(*args) - args = args.to_a.flatten if args.kind_of? Hash - tk_call 'tk_setPalette', *args - end - def TkPalette.setPalette(*args) - TkPalette.set(*args) - end - - def TkPalette.bisque - tk_call 'tk_bisque' - end - - def TkPalette.darken(color, percent) - tk_call 'tkDarken', color, percent - end - - def TkPalette.recolorTree(window, colors) - if not colors.kind_of?(Hash) - fail "2nd arg need to be Hash" - end - - colors.each{|key, value| - begin - if window.cget(key) == tk_call('set', "tkPalette(#{key})") - window[key] = colors[key] - end - rescue - # ignore - end - } - - TkWinfo.children(window).each{|w| TkPalette.recolorTree(w, colors)} - end - - def recolorTree(colors) - TkPalette.recolorTree(self, colors) - end -end diff --git a/ext/tk/lib/tkscrollbox.rb b/ext/tk/lib/tkscrollbox.rb deleted file mode 100644 index 6236430491..0000000000 --- a/ext/tk/lib/tkscrollbox.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# tkscrollbox.rb - Tk Listbox with Scrollbar -# as an example of Composite Widget -# $Date$ -# by Yukihiro Matsumoto <matz@netlab.co.jp> - -require 'tk.rb' - -class TkScrollbox<TkListbox - include TkComposite - def initialize_composite(keys=nil) - list = TkListbox.new(@frame) - scroll = TkScrollbar.new(@frame) - @path = list.path - - list.configure 'yscroll', scroll.path+" set" - list.pack 'side'=>'left','fill'=>'both','expand'=>'yes' - scroll.configure 'command', list.path+" yview" - scroll.pack 'side'=>'right','fill'=>'y' - - delegate('DEFAULT', list) - delegate('foreground', list) - delegate('background', list, scroll) - delegate('borderwidth', @frame) - delegate('relief', @frame) - - configure keys if keys - end -end diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb deleted file mode 100644 index 2db9a22bdf..0000000000 --- a/ext/tk/lib/tktext.rb +++ /dev/null @@ -1,1041 +0,0 @@ -# -# tktext.rb - Tk text classes -# $Date$ -# by Yukihiro Matsumoto <matz@caelum.co.jp> - -require 'tk.rb' -require 'tkfont' - -module TkTreatTextTagFont - include TkTreatItemFont - - ItemCMD = ['tag', 'configure'] - def __conf_cmd(idx) - ItemCMD[idx] - end - - def __item_pathname(tagOrId) - if tagOrId.kind_of?(TkTextTag) - self.path + ';' + tagOrId.id - else - self.path + ';' + tagOrId - end - end -end - -class TkText<TkTextWin - ItemConfCMD = ['tag', 'configure'] - include TkTreatTextTagFont - include Scrollable - - WidgetClassName = 'Text'.freeze - WidgetClassNames[WidgetClassName] = self - - def self.to_eval - WidgetClassName - end - - def self.new(*args, &block) - obj = super(*args){} - obj.init_instance_variable - obj.instance_eval(&block) if defined? yield - obj - end - - def init_instance_variable - @tags = {} - end - - def create_self(keys) - if keys and keys != None - tk_call 'text', @path, *hash_kv(keys) - else - tk_call 'text', @path - end - init_instance_variable - end - - def index(index) - tk_send 'index', index - end - - def value - tk_send 'get', "1.0", "end - 1 char" - end - - def value= (val) - tk_send 'delete', "1.0", 'end' - tk_send 'insert', "1.0", val - end - - def _addcmd(cmd) - @cmdtbl.push cmd - end - - def _addtag(name, obj) - @tags[name] = obj - end - - def tagid2obj(tagid) - if not @tags[tagid] - tagid - else - @tags[tagid] - end - end - - def tag_names(index=None) - tk_split_list(tk_send('tag', 'names', index)).collect{|elt| - tagid2obj(elt) - } - end - - def mark_names - tk_split_list(tk_send('mark', 'names')).collect{|elt| - tagid2obj(elt) - } - end - - def mark_next(index) - tagid2obj(tk_send('mark', 'next', index)) - end - - def mark_previous(index) - tagid2obj(tk_send('mark', 'previous', index)) - end - - def window_names - tk_send('window', 'names').collect{|elt| - tagid2obj(elt) - } - end - - def image_names - tk_send('image', 'names').collect{|elt| - tagid2obj(elt) - } - end - - def set_insert(index) - tk_send 'mark', 'set', 'insert', index - end - - def set_current(index) - tk_send 'mark', 'set', 'current', index - end - - def insert(index, chars, *tags) - super index, chars, tags.collect{|x|_get_eval_string(x)}.join(' ') - end - - def destroy - @tags = {} unless @tags - @tags.each_value do |t| - t.destroy - end - super - end - - def backspace - self.delete 'insert' - end - - def compare(idx1, op, idx2) - bool(tk_send('compare', idx1, op, idx2)) - end - - def debug - bool(tk_send('debug')) - end - def debug=(boolean) - tk_send 'debug', boolean - end - - def bbox(index) - inf = tk_send('bbox', index) - (inf == "")? [0,0,0,0]: inf - end - def dlineinfo(index) - inf = tk_send('dlineinfo', index) - (inf == "")? [0,0,0,0,0]: inf - end - - def yview_pickplace(*what) - tk_send 'yview', '-pickplace', *what - end - - def xview_pickplace(*what) - tk_send 'xview', '-pickplace', *what - end - - def tag_add(tag, index1, index2=None) - tk_send 'tag', 'add', tag, index1, index2 - end - - def tag_bind(tag, seq, cmd=Block.new, args=nil) - _bind(['tag', 'bind', tag], seq, cmd, args) - end - - def tag_bind_append(tag, seq, cmd=Block.new, args=nil) - _bind_append(['tag', 'bind', tag], seq, cmd, args) - end - - def tag_bindinfo(tag, context=nil) - _bindinfo(['tag', 'bind', tag], context) - end - - def tag_cget(tag, key) - case key.to_s - when 'text', 'label', 'show', 'data', 'file' - tk_call @path, 'tag', 'cget', tag, "-#{key}" - else - tk_tcl2ruby tk_call(@path, 'tag', 'cget', tag, "-#{key}") - end - end - - def tag_configure(tag, key, val=None) - if key.kind_of? Hash - key = _symbolkey2str(key) - if ( key['font'] || key['kanjifont'] \ - || key['latinfont'] || key['asciifont'] ) - tagfont_configure(tag, key) - else - tk_send 'tag', 'configure', tag, *hash_kv(key) - end - - else - if key == 'font' || key == :font || - key == 'kanjifont' || key == :kanjifont || - key == 'latinfont' || key == :latinfont || - key == 'asciifont' || key == :asciifont - tagfont_configure(tag, {key=>val}) - else - tk_send 'tag', 'configure', tag, "-#{key}", val - end - end - end - - def tag_configinfo(tag, key=nil) - if key - case key.to_s - when 'text', 'label', 'show', 'data', 'file' - conf = tk_split_simplelist(tk_send('tag','configure',tag,"-#{key}")) - else - conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_send('tag', 'configure', tag)).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 - } - end - end - - def tag_raise(tag, above=None) - tk_send 'tag', 'raise', tag, above - end - - def tag_lower(tag, below=None) - tk_send 'tag', 'lower', tag, below - end - - def tag_remove(tag, *index) - tk_send 'tag', 'remove', tag, *index - end - - def tag_ranges(tag) - l = tk_split_simplelist(tk_send('tag', 'ranges', tag)) - r = [] - while key=l.shift - r.push [key, l.shift] - end - r - end - - def tag_nextrange(tag, first, last=None) - tk_split_simplelist(tk_send('tag', 'nextrange', tag, first, last)) - end - - def tag_prevrange(tag, first, last=None) - tk_split_simplelist(tk_send('tag', 'prevrange', tag, first, last)) - 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('kstring', 'length', txt).to_i - else - begin - tk_call('encoding', 'convertto', 'ascii', txt).length - rescue StandardError, NameError - # sorry, I have no plan - txt.length - end - end - end - private :_ktext_length - - 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 dump(type_info, *index, &block) - args = type_info.collect{|inf| '-' + inf} - args << '-command' << block if block - str = tk_send('dump', *(args + index)) - result = [] - sel = nil - i = 0 - while i < str.size - # retrieve key - idx = str.index(/ /, i) - result.push str[i..(idx-1)] - i = idx + 1 - - # retrieve value - case result[-1] - when 'text' - if str[i] == ?{ - # text formed as {...} - val, i = _retrieve_braced_text(str, i) - result.push val - else - # text which may contain backslahes - val, i = _retrieve_backslashed_text(str, i) - result.push val - end - else - idx = str.index(/ /, i) - val = str[i..(idx-1)] - case result[-1] - when 'mark' - case val - when 'insert' - result.push TkTextMarkInsert.new(self) - when 'current' - result.push TkTextMarkCurrent.new(self) - when 'anchor' - result.push TkTextMarkAnchor.new(self) - else - result.push tk_tcl2ruby(val) - end - when 'tagon' - if val == 'sel' - if sel - result.push sel - else - result.push TkTextTagSel.new(self) - end - else - result.push tk_tcl2ruby(val) - end - when 'tagoff' - result.push tk_tcl2ruby(sel) - when 'window' - result.push tk_tcl2ruby(val) - end - i = idx + 1 - end - - # retrieve index - idx = str.index(/ /, i) - if idx - result.push str[i..(idx-1)] - i = idx + 1 - else - result.push str[i..-1] - break - end - end - - kvis = [] - until result.empty? - kvis.push [result.shift, result.shift, result.shift] - end - kvis # result is [[key1, value1, index1], [key2, value2, index2], ...] - end - - def _retrieve_braced_text(str, i) - cnt = 0 - idx = i - while idx < str.size - case str[idx] - when ?{ - cnt += 1 - when ?} - cnt -= 1 - if cnt == 0 - break - end - end - idx += 1 - end - return str[i+1..idx-1], idx + 2 - end - private :_retrieve_braced_text - - def _retrieve_backslashed_text(str, i) - j = i - idx = nil - loop { - idx = str.index(/ /, j) - if str[idx-1] == ?\\ - j += 1 - else - break - end - } - val = str[i..(idx-1)] - val.gsub!(/\\( |\{|\})/, '\1') - return val, idx + 1 - end - private :_retrieve_backslashed_text - - def dump_all(*index, &block) - dump(['all'], *index, &block) - end - def dump_mark(*index, &block) - dump(['mark'], *index, &block) - end - def dump_tag(*index, &block) - dump(['tag'], *index, &block) - end - def dump_text(*index, &block) - dump(['text'], *index, &block) - end - def dump_window(*index, &block) - dump(['window'], *index, &block) - end - def dump_image(*index, &block) - dump(['image'], *index, &block) - end -end - -class TkTextTag<TkObject - include TkTreatTagFont - - TTagID_TBL = {} - Tk_TextTag_ID = ['tag0000'] - - def TkTextTag.id2obj(text, id) - tpath = text.path - return id unless TTagID_TBL[tpath] - TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id - end - - def initialize(parent, *args) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @parent = @t = parent - @tpath = parent.path - @path = @id = Tk_TextTag_ID[0] - TTagID_TBL[@id] = self - TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath] - TTagID_TBL[@tpath][@id] = self - Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ - #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) - if args != [] then - keys = args.pop - if keys.kind_of? Hash then - add(*args) if args != [] - configure(keys) - else - args.push keys - add(*args) - end - end - @t._addtag id, self - end - - def id - return @id - end - - def first - @id + '.first' - end - - def last - @id + '.last' - end - - def add(*index) - tk_call @t.path, 'tag', 'add', @id, *index - end - - def remove(*index) - tk_call @t.path, 'tag', 'remove', @id, *index - end - - def ranges - l = tk_split_simplelist(tk_call(@t.path, 'tag', 'ranges', @id)) - r = [] - while key=l.shift - r.push [key, l.shift] - end - r - end - - def nextrange(first, last=None) - tk_split_simplelist(tk_call(@t.path, 'tag', 'nextrange', @id, first, last)) - end - - def prevrange(first, last=None) - tk_split_simplelist(tk_call(@t.path, 'tag', 'prevrange', @id, first, last)) - end - - def [](key) - cget key - end - - def []=(key,val) - configure key, val - end - - def cget(key) - case key.to_s - when 'text', 'label', 'show', 'data', 'file' - tk_call @t.path, 'tag', 'cget', @id, "-#{key}" - else - tk_tcl2ruby tk_call(@t.path, 'tag', 'cget', @id, "-#{key}") - end - end - - def configure(key, val=None) - @t.tag_configure @id, key, val - end -# def configure(key, val=None) -# if key.kind_of? Hash -# tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key) -# else -# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val -# end -# end -# def configure(key, value) -# if value == FALSE -# value = "0" -# elsif value.kind_of? Proc -# value = install_cmd(value) -# end -# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", value -# end - - def configinfo(key=nil) - @t.tag_configinfo @id, key - end - - def bind(seq, cmd=Block.new, args=nil) - _bind([@t.path, 'tag', 'bind', @id], seq, cmd, args) - end - - def bind_append(seq, cmd=Block.new, args=nil) - _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, args) - end - - def bindinfo(context=nil) - _bindinfo([@t.path, 'tag', 'bind', @id], context) - end - - def raise(above=None) - tk_call @t.path, 'tag', 'raise', @id, above - end - - def lower(below=None) - tk_call @t.path, 'tag', 'lower', @id, below - end - - def destroy - tk_call @t.path, 'tag', 'delete', @id - TTagID_TBL[@tpath].delete(@id) if CTagID_TBL[@tpath] - end -end - -class TkTextNamedTag<TkTextTag - def self.new(parent, name, *args) - if TTagID_TBL[parent.path] && TTagID_TBL[parent.path][name] - return TTagID_TBL[parent.path][name] - else - super(parent, name, *args) - end - end - - def initialize(parent, name, *args) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @tpath = parent.path - @path = @id = name - TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath] - TTagID_TBL[@tpath][@id] = self - if mode - tk_call @t.path, "addtag", @id, *args - end - end -end - -class TkTextTagSel<TkTextTag - def initialize(parent, keys=nil) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @path = @id = 'sel' - #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) - configure(keys) if keys - @t._addtag id, self - end -end - -class TkTextMark<TkObject - Tk_TextMark_ID = ['mark0000'] - def initialize(parent, index) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @path = @id = Tk_TextMark_ID[0] - Tk_TextMark_ID[0] = Tk_TextMark_ID[0].succ - tk_call @t.path, 'mark', 'set', @id, index - @t._addtag id, self - end - def id - return @id - end - - def set(where) - tk_call @t.path, 'mark', 'set', @id, where - end - - def unset - tk_call @t.path, 'mark', 'unset', @id - end - alias destroy unset - - def gravity - tk_call @t.path, 'mark', 'gravity', @id - end - - def gravity=(direction) - tk_call @t.path, 'mark', 'gravity', @id, direction - end - - def next(index = nil) - if index - @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index)) - else - @t.tagid2obj(tk_call(@t.path, 'mark', 'next', @id)) - end - end - - def previous(index = nil) - if index - @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index)) - else - @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', @id)) - end - end -end - -class TkTextMarkInsert<TkTextMark - def initialize(parent, index=nil) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @path = @id = 'insert' - tk_call @t.path, 'mark', 'set', @id, index if index - @t._addtag id, self - end -end - -class TkTextMarkCurrent<TkTextMark - def initialize(parent,index=nil) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @path = @id = 'current' - tk_call @t.path, 'mark', 'set', @id, index if index - @t._addtag id, self - end -end - -class TkTextMarkAnchor<TkTextMark - def initialize(parent,index=nil) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - @path = @id = 'anchor' - tk_call @t.path, 'mark', 'set', @id, index if index - @t._addtag id, self - end -end - -class TkTextWindow<TkObject - def initialize(parent, index, keys) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - if index == 'end' - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars')) - elsif index.kind_of? TkTextMark - if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end') - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars')) - else - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path)) - end - else - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index)) - end - @path.gravity = 'left' - @index = @path.path - keys = _symbolkey2str(keys) - @id = keys['window'] - if keys['create'] - @p_create = keys['create'] - if @p_create.kind_of? Proc - keys['create'] = install_cmd(proc{@id = @p_create.call; @id.path}) - end - end - tk_call @t.path, 'window', 'create', @index, *hash_kv(keys) - end - - def [](slot) - cget(slot) - end - def []=(slot, value) - configure(slot, value) - end - - def cget(slot) - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - tk_call @t.path, 'window', 'cget', @index, "-#{slot}" - else - tk_tcl2ruby tk_call(@t.path, 'window', 'cget', @index, "-#{slot}") - end - end - - def configure(slot, value=None) - if slot.kind_of? Hash - slot = _symbolkey2str(slot) - @id = slot['window'] if slot['window'] - if slot['create'] - self.create=value - slot['create']=nil - end - if slot.size > 0 - tk_call @t.path, 'window', 'configure', @index, *hash_kv(slot) - end - else - @id = value if slot == 'window' || slot == :window - if slot == 'create' || slot == :create - self.create=value - else - tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value - end - end - end - - def window - @id - end - - def window=(value) - tk_call @t.path, 'window', 'configure', @index, '-window', value - @id = value - end - - def create - @p_create - end - - def create=(value) - @p_create = value - if @p_create.kind_of? Proc - value = install_cmd(proc{@id = @p_create.call}) - end - tk_call @t.path, 'window', 'configure', @index, '-create', value - end - - def configinfo(slot = nil) - if slot - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - conf = tk_split_simplelist(tk_call(@t.path, 'window', 'configure', - @index, "-#{slot}")) - else - conf = tk_split_list(tk_call(@t.path, 'window', 'configure', - @index, "-#{slot}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_call(@t.path, 'window', 'configure', - @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 - } - end - end - -end - -class TkTextImage<TkObject - def initialize(parent, index, keys) - if not parent.kind_of?(TkText) - fail format("%s need to be TkText", parent.inspect) - end - @t = parent - if index == 'end' - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars')) - elsif index.kind_of? TkTextMark - if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end') - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars')) - else - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path)) - end - else - @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index)) - end - @path.gravity = 'left' - @index = @path.path - @id = tk_call(@t.path, 'image', 'create', @index, *hash_kv(keys)) - end - - def [](slot) - cget(slot) - end - def []=(slot, value) - configure(slot, value) - end - - def cget(slot) - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - tk_call @t.path, 'image', 'cget', @index, "-#{slot}" - else - tk_tcl2ruby tk_call(@t.path, 'image', 'cget', @index, "-#{slot}") - end - end - - def configure(slot, value=None) - if slot.kind_of? Hash - tk_call @t.path, 'image', 'configure', @index, *hash_kv(slot) - else - tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value - end - end -# def configure(slot, value) -# tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value -# end - - def image - tk_call @t.path, 'image', 'configure', @index, '-image' - end - - def image=(value) - tk_call @t.path, 'image', 'configure', @index, '-image', value - end - - def configinfo(slot = nil) - if slot - case slot.to_s - when 'text', 'label', 'show', 'data', 'file' - conf = tk_split_simplelist(tk_call(@t.path, 'image', 'configure', - @index, "-#{slot}")) - else - conf = tk_split_list(tk_call(@t.path, 'image', 'configure', - @index, "-#{slot}")) - end - conf[0] = conf[0][1..-1] - conf - else - tk_split_simplelist(tk_call(@t.path, 'image', 'configure', - @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 - } - end - end -end diff --git a/ext/tk/lib/tkvirtevent.rb b/ext/tk/lib/tkvirtevent.rb deleted file mode 100644 index f5dcdc9429..0000000000 --- a/ext/tk/lib/tkvirtevent.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -# tkvirtevent.rb : treats virtual events -# 1998/07/16 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> -# -require 'tk' - -class TkVirtualEvent<TkObject - extend Tk - - TkVirtualEventID = [0] - TkVirtualEventTBL = {} - - class PreDefVirtEvent<self - def initialize(event) - @path = @id = event - TkVirtualEvent::TkVirtualEventTBL[@id] = self - end - end - - def TkVirtualEvent.getobj(event) - obj = TkVirtualEventTBL[event] - if obj - obj - else - if tk_call('event', 'info').index("<#{event}>") - PreDefVirtEvent.new(event) - else - fail ArgumentError, "undefined virtual event '<#{event}>'" - end - end - end - - def TkVirtualEvent.info - tk_call('event', 'info').split(/\s+/).collect!{|seq| - TkVirtualEvent.getobj(seq[1..-2]) - } - end - - def initialize(*sequences) - @path = @id = format("<VirtEvent%.4d>", TkVirtualEventID[0]) - TkVirtualEventID[0] += 1 - add(*sequences) - end - - def add(*sequences) - if sequences != [] - tk_call('event', 'add', "<#{@id}>", - *(sequences.collect{|seq| "<#{tk_event_sequence(seq)}>"}) ) - TkVirtualEventTBL[@id] = self - end - self - end - - def delete(*sequences) - if sequences == [] - tk_call('event', 'delete', "<#{@id}>") - TkVirtualEventTBL.delete(@id) - else - tk_call('event', 'delete', "<#{@id}>", - *(sequences.collect{|seq| "<#{tk_event_sequence(seq)}>"}) ) - TkVirtualEventTBL.delete(@id) if info == [] - end - self - end - - def info - tk_call('event', 'info', "<#{@id}>").split(/\s+/).collect!{|seq| - l = seq.scan(/<*[^<>]+>*/).collect!{|subseq| - case (subseq) - when /^<<[^<>]+>>$/ - TkVirtualEvent.getobj(subseq[1..-2]) - when /^<[^<>]+>$/ - subseq[1..-2] - else - subseq.split('') - end - }.flatten - (l.size == 1) ? l[0] : l - } - end -end diff --git a/ext/tk/sample/tkbiff.rb b/ext/tk/sample/tkbiff.rb deleted file mode 100644 index ac27184437..0000000000 --- a/ext/tk/sample/tkbiff.rb +++ /dev/null @@ -1,149 +0,0 @@ -#! /usr/local/bin/ruby - -if ARGV[0] != '-d' - unless $DEBUG - exit if fork - end -else - ARGV.shift -end - -if ARGV.length == 0 - if ENV['MAIL'] - $spool = ENV['MAIL'] - else - $spool = '/usr/spool/mail/' + ENV['USER'] - end -else - $spool = ARGV[0] -end - -require "parsedate" -require "base64" - -include ParseDate - -class Mail - def Mail.new(f) - if !f.kind_of?(IO) - f = open(f, "r") - me = super - f.close - else - me = super - end - return me - end - - def initialize(f) - @header = {} - @body = [] - while line = f.gets() - line.chop! - next if /^From / =~ line # skip From-line - break if /^$/ =~ line # end of header - if /^(\S+):\s*(.*)/ =~ line - @header[attr = $1.capitalize] = $2 - elsif attr - sub(/^\s*/, '') - @header[attr] += "\n" + $_ - end - end - - return unless $_ - - while line = f.gets() - break if /^From / =~ line - @body.push($_) - end - end - - def header - return @header - end - - def body - return @body - end - -end - -require "tkscrollbox" - -$top = TkRoot.new -$top.withdraw -$list = TkScrollbox.new($top) { - relief 'raised' - width 80 - height 8 - setgrid 'yes' - pack -} -TkButton.new($top) { - text 'Dismiss' - command proc {$top.withdraw} - pack('fill'=>'both','expand'=>'yes') -} -$top.bind "Control-c", proc{exit} -$top.bind "Control-q", proc{exit} -$top.bind "space", proc{exit} - -$spool_size = 0 -$check_time = Time.now - -def check - $check_time = Time.now - size = File.size($spool) - if size and size != $spool_size - $spool_size = size - pop_up if size > 0 - end - Tk.after 5000, proc{check} -end - -if defined? Thread - Thread.start do - loop do - sleep 600 - if Time.now - $check_time > 200 - Tk.after 5000, proc{check} - end - end - end -end - -def pop_up - outcount = 0; - $list.delete 0, 'end' - f = open($spool, "r") - while !f.eof? - mail = Mail.new(f) - date, from, subj = mail.header['Date'], mail.header['From'], mail.header['Subject'] - next if !date - y = m = d = 0 - y, m, d = parsedate(date) if date - from = "sombody@somewhere" if ! from - subj = "(nil)" if ! subj - from = decode_b(from) - subj = decode_b(subj) - $list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) - outcount += 1 - end - f.close - if outcount == 0 - $list.insert 'end', "You have no mail." - else - $list.see 'end' - end - $top.deiconify - Tk.after 2000, proc{$top.withdraw} -end - -$list.insert 'end', "You have no mail." -check -Tk.after 2000, proc{$top.withdraw} -begin - Tk.mainloop -rescue - `echo #$! > /tmp/tkbiff` -end diff --git a/ext/tk/sample/tkbrowse.rb b/ext/tk/sample/tkbrowse.rb deleted file mode 100644 index 882f0a489b..0000000000 --- a/ext/tk/sample/tkbrowse.rb +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/local/bin/ruby -# -# This script generates a directory browser, which lists the working -# directory and allows you to open files or subdirectories by -# double-clicking. - -# Create a scrollbar on the right side of the main window and a listbox -# on the left side. - -require "tkscrollbox" - -# The procedure below is invoked to open a browser on a given file; if the -# file is a directory then another instance of this program is invoked; if -# the file is a regular file then the Mx editor is invoked to display -# the file. - -$dirlist = {} - -def browsedir (dir) - if $dirlist.key? dir - $dirlist[dir] - else - top = if $dirlist.size > 0 then TkToplevel.new else nil end - list = TkScrollbox.new(top) { - relief 'raised' - width 20 - height 20 - setgrid 'yes' - pack - } - list.insert 'end', *`ls #{dir}`.split - - # Set up bindings for the browser. - - list.focus - list.bind "Control-q", proc{exit} - list.bind "Control-c", proc{exit} - list.bind "Control-p", proc{ - print "selection <", TkSelection.get, ">\n" - } - - list.bind "Double-Button-1", proc{ - for i in TkSelection.get.split - print "clicked ", i, "\n" - browse dir, i - end - } - $dirlist[dir] = list - end -end - -def browse (dir, file) - file="#{dir}/#{file}" - if File.directory? file - browsedir(file) - else - if File.file? file - if ENV['EDITOR'] - system format("%s %s&", ENV['EDITOR'], file) - else - system "xedit #{file}&" - end - else - STDERR.print "\"#{file}\" isn't a directory or regular file" - end - end -end - -# Fill the listbox with a list of all the files in the directory (run -# the "ls" command to get that information). - -if ARGV.length>0 - dir = ARGV[0] -else - dir="." -end - -browsedir(dir) -Tk.mainloop diff --git a/ext/tk/sample/tkdialog.rb b/ext/tk/sample/tkdialog.rb deleted file mode 100644 index e83e16d0a8..0000000000 --- a/ext/tk/sample/tkdialog.rb +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/local/bin/ruby -require "tk" - -root = TkFrame.new -top = TkFrame.new(root) { - relief 'raised' - border 1 -} -msg = TkMessage.new(top) { - text "File main.c hasn't been saved to disk since \ -it was last modified. What should I do?" - justify 'center' - aspect 200 - font '-Adobe-helvetica-medium-r-normal--*-240*' - pack('padx'=>5, 'pady'=>5, 'expand'=>'yes') -} -top.pack('fill'=>'both') -root.pack - -bot = TkFrame.new(root) { - relief 'raised' - border 1 -} - -TkFrame.new(bot) { |left| - relief 'sunken' - border 1 - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10) - TkButton.new(left) { - text "Save File" - command "quit 'save'" - pack('expand'=>'yes','padx'=>6,'pady'=> 6) - top.bind "Enter", proc{state 'active'} - msg.bind "Enter", proc{state 'active'} - bot.bind "Enter", proc{state 'active'} - top.bind "Leave", proc{state 'normal'} - msg.bind "Leave", proc{state 'normal'} - bot.bind "Leave", proc{state 'normal'} - Tk.root.bind "ButtonRelease-1", proc{quit 'save'} - Tk.root.bind "Return", proc{quit 'save'} - } -} -TkButton.new(bot) { - text "Quit Anyway" - command "quit 'quit'" - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10) -} -TkButton.new(bot) { - text "Return To Editor" - command "quit 'return'" - pack('side'=>'left', 'expand'=>'yes', 'padx'=>10) -} -bot.pack -root.pack('side'=>'top', 'fill'=>'both', 'expand'=>'yes') - -def quit(button) - print "aaa\n" - print "You pressed the \"#{button}\" button; bye-bye!\n" - exit -end - -Tk.mainloop diff --git a/ext/tk/sample/tkfrom.rb b/ext/tk/sample/tkfrom.rb deleted file mode 100644 index 8c3efb8137..0000000000 --- a/ext/tk/sample/tkfrom.rb +++ /dev/null @@ -1,132 +0,0 @@ -#! /usr/local/bin/ruby - -require "parsedate" -require "base64" - -include ParseDate - -class Mail - def Mail.new(f) - if !f.kind_of?(IO) - f = open(f, "r") - me = super(f) - f.close - else - me = super - end - return me - end - - def initialize(f) - @header = {} - @body = [] - while line = f.gets() - $_.chop! - next if /^From / =~ line # skip From-line - break if /^$/ =~ line # end of header - if /^(\S+):\s*(.*)/ =~ line - @header[attr = $1.capitalize] = $2 - elsif attr - sub(/^\s*/, '') - @header[attr] += "\n" + $_ - end - end - - return unless $_ - - while line = f.gets() - break if /^From / =~ line - @body.push($_) - end - end - - def header - return @header - end - - def body - return @body - end - -end - -if ARGV.length == 0 - if ENV['MAIL'] - ARGV[0] = ENV['MAIL'] - elsif ENV['USER'] - ARGV[0] = '/usr/spool/mail/' + ENV['USER'] - elsif ENV['LOGNAME'] - ARGV[0] = '/usr/spool/mail/' + ENV['LOGNAME'] - end -end - -require "tk" -list = scroll = nil -TkFrame.new{|f| - list = TkListbox.new(f) { - yscroll proc{|idx| - scroll.set *idx - } - relief 'raised' -# geometry "80x5" - width 80 - height 5 - setgrid 'yes' - pack('side'=>'left','fill'=>'both','expand'=>'yes') - } - scroll = TkScrollbar.new(f) { - command proc{|idx| - list.yview *idx - } - pack('side'=>'right','fill'=>'y') - } - pack -} -root = Tk.root -TkButton.new(root) { - text 'Dismiss' - command proc {exit} - pack('fill'=>'both','expand'=>'yes') -} -root.bind "Control-c", proc{exit} -root.bind "Control-q", proc{exit} -root.bind "space", proc{exit} - -$outcount = 0; -for file in ARGV - next if File.exist?(file) - atime = File.atime(file) - mtime = File.mtime(file) - f = open(file, "r") - begin - until f.eof - mail = Mail.new(f) - date = mail.header['Date'] - next unless date - from = mail.header['From'] - subj = mail.header['Subject'] - y = m = d = 0 - y, m, d = parsedate(date) if date - from = "sombody@somewhere" unless from - subj = "(nil)" unless subj - from = decode_b(from) - subj = decode_b(subj) - list.insert 'end', format('%-02d/%02d/%02d [%-28.28s] %s',y,m,d,from,subj) - $outcount += 1 - end - ensure - f.close - File.utime(atime, mtime, file) - list.see 'end' - end -end - -limit = 10000 -if $outcount == 0 - list.insert 'end', "You have no mail." - limit = 2000 -end -Tk.after limit, proc{ - exit -} -Tk.mainloop diff --git a/ext/tk/sample/tkhello.rb b/ext/tk/sample/tkhello.rb deleted file mode 100644 index 5188fe1c8c..0000000000 --- a/ext/tk/sample/tkhello.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "tk" - -TkButton.new(nil, - 'text' => 'hello', - 'command' => proc{print "hello\n"}).pack('fill'=>'x') -TkButton.new(nil, - 'text' => 'quit', - 'command' => 'exit').pack('fill'=>'x') - -Tk.mainloop diff --git a/ext/tk/sample/tkline.rb b/ext/tk/sample/tkline.rb deleted file mode 100644 index 2406b0749f..0000000000 --- a/ext/tk/sample/tkline.rb +++ /dev/null @@ -1,45 +0,0 @@ - -require "tkclass" - -$tkline_init = FALSE -def start_random - return if $tkline_init - $tkline_init = TRUE - if defined? Thread - Thread.start do - loop do - sleep 2 - Line.new($c, rand(400), rand(200), rand(400), rand(200)) - end - end - end -end - -$c = Canvas.new -$c.pack -$start_x = start_y = 0 - -def do_press(x, y) - $start_x = x - $start_y = y - $current_line = Line.new($c, x, y, x, y) - start_random -end -def do_motion(x, y) - if $current_line - $current_line.coords $start_x, $start_y, x, y - end -end - -def do_release(x, y) - if $current_line - $current_line.coords $start_x, $start_y, x, y - $current_line.fill 'black' - $current_line = nil - end -end - -$c.bind("1", proc{|e| do_press e.x, e.y}) -$c.bind("B1-Motion", proc{|x, y| do_motion x, y}, "%x %y") -$c.bind("ButtonRelease-1", proc{|x, y| do_release x, y}, "%x %y") -Tk.mainloop diff --git a/ext/tk/sample/tktimer.rb b/ext/tk/sample/tktimer.rb deleted file mode 100644 index 34377e2f39..0000000000 --- a/ext/tk/sample/tktimer.rb +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/local/bin/ruby -# This script generates a counter with start and stop buttons. - -require "tk" -$label = TkLabel.new { - text '0.00' - relief 'raised' - width 10 - pack('side'=>'bottom', 'fill'=>'both') -} - -TkButton.new { - text 'Start' - command proc { - if $stopped - $stopped = FALSE - tick - end - } - pack('side'=>'left','fill'=>'both','expand'=>'yes') -} -TkButton.new { - text 'Stop' - command proc{ - exit if $stopped - $stopped = TRUE - } - pack('side'=>'right','fill'=>'both','expand'=>'yes') -} - -$seconds=0 -$hundredths=0 -$stopped=TRUE - -def tick - if $stopped then return end - Tk.after 50, proc{tick} - $hundredths+=5 - if $hundredths >= 100 - $hundredths=0 - $seconds+=1 - end - $label.text format("%d.%02d", $seconds, $hundredths) -end - -root = Tk.root -root.bind "Control-c", proc{root.destroy} -root.bind "Control-q", proc{root.destroy} -Tk.root.focus -Tk.mainloop diff --git a/ext/tk/tkutil.c b/ext/tk/tkutil.c deleted file mode 100644 index b42069e234..0000000000 --- a/ext/tk/tkutil.c +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************ - - tk.c - - - $Author$ - $Date$ - created at: Fri Nov 3 00:47:54 JST 1995 - -************************************************/ - -#include "ruby.h" - -static VALUE -tk_eval_cmd(argc, argv) - int argc; - VALUE argv[]; -{ - VALUE cmd, rest; - - rb_scan_args(argc, argv, "1*", &cmd, &rest); - return rb_eval_cmd(cmd, rest, 0); -} - -static VALUE -tk_s_new(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; -{ - VALUE obj = rb_class_new_instance(argc, argv, klass); - - if (rb_block_given_p()) rb_obj_instance_eval(0, 0, obj); - return obj; -} - -void -Init_tkutil() -{ - VALUE mTK = rb_define_module("TkUtil"); - VALUE cTK = rb_define_class("TkKernel", rb_cObject); - - rb_define_singleton_method(mTK, "eval_cmd", tk_eval_cmd, -1); - - rb_define_singleton_method(cTK, "new", tk_s_new, -1); -} |
