From 69ef4bae6203c567f3e6ffc0de9be16974443f5c Mon Sep 17 00:00:00 2001 From: nagai Date: Wed, 30 Mar 2005 08:44:55 +0000 Subject: [PATCH] * ext/tcltklib/tcltklib.c: add TclTkIp#_create_console() method to create a Tcl/Tk's console window. * ext/tk/lib/multi-tk.rb: support TclTkIp#_create_console() method. * ext/tk/lib/remote-tk.rb: ditto. * ext/tk/lib/tk/console.rb: ditto. * ext/tk/lib/tk.rb: update RELEASE_DATE * ext/tk/sample/demo-*/check2.rb: use 'return' in the Proc object. * ext/tk/sample/tkextlib/**: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 17 + ext/tcltklib/tcltklib.c | 88 ++- ext/tk/lib/multi-tk.rb | 4 + ext/tk/lib/remote-tk.rb | 4 + ext/tk/lib/tk.rb | 2 +- ext/tk/lib/tk/console.rb | 3 + ext/tk/sample/demos-en/check2.rb | 44 +- ext/tk/sample/demos-jp/check2.rb | 44 +- ext/tk/sample/tkextlib/bwidget/tree.rb | 2 +- ext/tk/sample/tkextlib/tkHTML/hv.rb | 89 +-- ext/tk/sample/tkextlib/tkHTML/ss.rb | 726 +++++++++++----------- ext/tk/sample/tkextlib/tktable/basic.rb | 4 +- ext/tk/sample/tkextlib/tktable/command.rb | 4 +- ext/tk/sample/tkextlib/tktable/debug.rb | 2 +- ext/tk/sample/tkextlib/tktable/maxsize.rb | 2 +- ext/tk/sample/tkextlib/treectrl/demo.rb | 1 + 16 files changed, 594 insertions(+), 442 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59147febcb..44b2059076 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +Wed Mar 30 17:41:48 2005 Hidetoshi NAGAI + + * ext/tcltklib/tcltklib.c: add TclTkIp#_create_console() method to + create a Tcl/Tk's console window. + + * ext/tk/lib/multi-tk.rb: support TclTkIp#_create_console() method. + + * ext/tk/lib/remote-tk.rb: ditto. + + * ext/tk/lib/tk/console.rb: ditto. + + * ext/tk/lib/tk.rb: update RELEASE_DATE + + * ext/tk/sample/demo-*/check2.rb: use 'return' in the Proc object. + + * ext/tk/sample/tkextlib/**: ditto. + Tue Mar 29 22:11:56 2005 Masatoshi SEKI * test/rinda/test_rinda.rb: use DRbObject.new_with instead of reinit. diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index 8756d54252..1a00c7e757 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -4,7 +4,7 @@ * Oct. 24, 1997 Y. Matsumoto */ -#define TCLTKLIB_RELEASE_DATE "2005-03-10" +#define TCLTKLIB_RELEASE_DATE "2005-03-30" #include "ruby.h" #include "rubysig.h" @@ -22,6 +22,12 @@ #include #include +#ifndef TCL_ALPHA_RELEASE +#define TCL_ALPHA_RELEASE 0 +#define TCL_BETA_RELEASE 1 +#define TCL_FINAL_RELEASE 2 +#endif + #ifdef __MACOS__ # include # include @@ -4945,6 +4951,84 @@ ip_create_slave(argc, argv, self) return retval; } +#if defined(MAC_TCL) || defined(__WIN32__) +#if TCL_MAJOR_VERSION < 8 \ + || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 0) \ + || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \ + && (TCL_RELEASE_LEVEL == TCL_ALPHA_RELEASE \ + || (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE \ + && TCL_RELEASE_SERIAL < 2) ) ) +EXTERN void TkConsoleCreate _((void)); +#endif +#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \ + && ( (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE \ + && TCL_RELEASE_SERIAL == 0) \ + || (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE \ + && TCL_RELEASE_SERIAL >= 2) ) +EXTERN void TkConsoleCreate_ _((void)); +#endif +#endif +static VALUE +ip_create_console_core(interp, argc, argv) + VALUE interp; + int argc; /* dummy */ + VALUE *argv; /* dummy */ +{ + struct tcltkip *ptr = get_ip(interp); + + if (Tcl_GetVar(ptr->ip,"tcl_interactive",TCL_GLOBAL_ONLY) == (char*)NULL) { + Tcl_SetVar(ptr->ip, "tcl_interactive", "0", TCL_GLOBAL_ONLY); + } + + +#if TCL_MAJOR_VERSION > 8 \ + || (TCL_MAJOR_VERSION == 8 \ + && (TCL_MINOR_VERSION > 1 \ + || (TCL_MINOR_VERSION == 1 \ + && TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE \ + && TCL_RELEASE_SERIAL >= 1) ) ) + Tk_InitConsoleChannels(ptr->ip); + + if (Tk_CreateConsoleWindow(ptr->ip) != TCL_OK) { + rb_raise(rb_eRuntimeError, "fail to create console-window"); + } +#else +#if defined(MAC_TCL) || defined(__WIN32__) +#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION == 1 \ + && ( (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE && TCL_RELEASE_SERIAL == 0) \ + || (TCL_RELEASE_LEVEL == TCL_BETA_RELEASE && TCL_RELEASE_SERIAL >= 2) ) + TkConsoleCreate_(); +#else + TkConsoleCreate(); +#endif + + if (TkConsoleInit(ptr->ip) != TCL_OK) { + rb_raise(rb_eRuntimeError, "fail to create console-window"); + } +#else + rb_notimplement(); +#endif +#endif + + return interp; +} + +static VALUE +ip_create_console(self) + VALUE self; +{ + struct tcltkip *ptr = get_ip(self); + + /* ip is deleted? */ + if (ptr == (struct tcltkip *)NULL || ptr->ip == (Tcl_Interp*)NULL + || Tcl_InterpDeleted(ptr->ip)) { + DUMP1("ip is deleted"); + rb_raise(rb_eRuntimeError, "interpreter is deleted"); + } + + return tk_funcall(ip_create_console_core, 0, (VALUE*)NULL, self); +} + /* make ip "safe" */ static VALUE ip_make_safe_core(interp, argc, argv) @@ -8349,6 +8433,8 @@ Init_tcltklib() rb_define_method(ip, "_invoke", ip_invoke, -1); rb_define_method(ip, "_return_value", ip_retval, 0); + rb_define_method(ip, "_create_console", ip_create_console, 0); + /* --------------------------------------------------------------- */ rb_define_method(ip, "_get_variable", ip_get_variable, 2); diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index a38f079ad2..49427575d2 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -1787,6 +1787,10 @@ class << MultiTkIp def _conv_listelement(arg) __getip._conv_listelement(arg) end + + def _create_console + __getip._create_console + end end diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb index 04d86d4cdb..03b6a45e50 100644 --- a/ext/tk/lib/remote-tk.rb +++ b/ext/tk/lib/remote-tk.rb @@ -400,6 +400,10 @@ class RemoteTkIp @interp._conv_listelement(str) end + def _create_console + fail RuntimeError, 'not support "_create_console" on the remote interpreter' + end + def mainloop fail RuntimeError, 'not support "mainloop" on the remote interpreter' end diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 61e76c29bc..1997bba9c3 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -4024,7 +4024,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2005-03-26'.freeze + RELEASE_DATE = '2005-03-30'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/console.rb b/ext/tk/lib/tk/console.rb index f0d2c7aa87..1a267b717c 100644 --- a/ext/tk/lib/tk/console.rb +++ b/ext/tk/lib/tk/console.rb @@ -9,6 +9,9 @@ module TkConsole TkCommandNames = ['console'.freeze].freeze + def self.create + TkCore::INTERP._create_console + end def self.title(str=None) tk_call 'console', str end diff --git a/ext/tk/sample/demos-en/check2.rb b/ext/tk/sample/demos-en/check2.rb index e2d5982d2d..97d61fba0c 100644 --- a/ext/tk/sample/demos-en/check2.rb +++ b/ext/tk/sample/demos-en/check2.rb @@ -76,31 +76,31 @@ TkCheckButton.new($check2_demo, :text=>'Safety Check', :variable=>safety, # tristate check in_check = false tristate_check = proc{|n1,n2,op| - return if in_check - - in_check = true - begin - if n1 == safety - if safety == 'none' - wipers.value = 0 - brakes.value = 0 - sober.value = 0 - elsif safety == 'all' - wipers.value = 1 - brakes.value = 1 - sober.value = 1 - end - else - if wipers == 1 && brakes == 1 && sober == 1 - safety.value = 'all' - elsif wipers == 1 || brakes == 1 || sober == 1 - safety.value = 'partial' + unless in_check + in_check = true + begin + if n1 == safety + if safety == 'none' + wipers.value = 0 + brakes.value = 0 + sober.value = 0 + elsif safety == 'all' + wipers.value = 1 + brakes.value = 1 + sober.value = 1 + end else - safety.value = 'none' + if wipers == 1 && brakes == 1 && sober == 1 + safety.value = 'all' + elsif wipers == 1 || brakes == 1 || sober == 1 + safety.value = 'partial' + else + safety.value = 'none' + end end + ensure + in_check = false end - ensure - in_check = false end } diff --git a/ext/tk/sample/demos-jp/check2.rb b/ext/tk/sample/demos-jp/check2.rb index 5d0c74a743..f681a4d684 100644 --- a/ext/tk/sample/demos-jp/check2.rb +++ b/ext/tk/sample/demos-jp/check2.rb @@ -76,31 +76,31 @@ TkCheckButton.new($check2_demo, :text=>' # tristate check in_check = false tristate_check = proc{|n1,n2,op| - return if in_check - - in_check = true - begin - if n1 == safety - if safety == 'none' - wipers.value = 0 - brakes.value = 0 - sober.value = 0 - elsif safety == 'all' - wipers.value = 1 - brakes.value = 1 - sober.value = 1 - end - else - if wipers == 1 && brakes == 1 && sober == 1 - safety.value = 'all' - elsif wipers == 1 || brakes == 1 || sober == 1 - safety.value = 'partial' + unless in_check + in_check = true + begin + if n1 == safety + if safety == 'none' + wipers.value = 0 + brakes.value = 0 + sober.value = 0 + elsif safety == 'all' + wipers.value = 1 + brakes.value = 1 + sober.value = 1 + end else - safety.value = 'none' + if wipers == 1 && brakes == 1 && sober == 1 + safety.value = 'all' + elsif wipers == 1 || brakes == 1 || sober == 1 + safety.value = 'partial' + else + safety.value = 'none' + end end + ensure + in_check = false end - ensure - in_check = false end } diff --git a/ext/tk/sample/tkextlib/bwidget/tree.rb b/ext/tk/sample/tkextlib/bwidget/tree.rb index 2b33962fa6..e1fcaa774f 100644 --- a/ext/tk/sample/tkextlib/bwidget/tree.rb +++ b/ext/tk/sample/tkextlib/bwidget/tree.rb @@ -119,7 +119,7 @@ module DemoTree Tk.root.bind_remove('Unmap') Tk.root.bind_remove('Map') Tk.root.bind_remove('Configure') - return true + true }) end diff --git a/ext/tk/sample/tkextlib/tkHTML/hv.rb b/ext/tk/sample/tkextlib/tkHTML/hv.rb index d9f3ea7d7c..a4d78ea5b1 100644 --- a/ext/tk/sample/tkextlib/tkHTML/hv.rb +++ b/ext/tk/sample/tkextlib/tkHTML/hv.rb @@ -78,38 +78,43 @@ big_imgs = {} hotkey = {} move_big_image = proc{|b| - return unless big_imgs.key?(b) - b.copy(big_imgs[b]) - big_imgs[b].delete - big_imgs.delete(b) - Tk.update + if big_imgs.key?(b) + b.copy(big_imgs[b]) + big_imgs[b].delete + big_imgs.delete(b) + Tk.update + end } image_cmd = proc{|*args| - return smgray unless show_img.bool - fn = args[0] - if old_imgs.key?(fn) - images[fn] = old_imgs[fn] - old_imgs.delete(fn) - return images[fn] + if show_img.bool + smgray + else + fn = args[0] + + if old_imgs.key?(fn) + images[fn] = old_imgs[fn] + old_imgs.delete(fn) + images[fn] + + else + begin + img = TkPhotoImage.new(:file=>fn) + rescue + smgray + else + if img.width * img.height > 20000 + b = TkPhotoImage.new(:width=>img.width, :height=>img.height) + big_imgs[b] = img + img = b + Tk.after_idle(proc{ move_big_image.call(b) }) + end + + images[fn] = img + img + end + end end - - begin - img = TkPhotoImage.new(:file=>fn) - rescue - return smgray - end - - if img.width * img.height > 20000 - b = TkPhotoImage.new(:width=>img.width, :height=>img.height) - big_imgs[b] = img - img = b - Tk.after_idle(proc{ move_big_image.call(b) }) - end - - images[fn] = img - - img } # @@ -183,12 +188,13 @@ clear_screen = proc{ # Load a file into the HTML widget # load_file = proc{|name| - return unless (doc = read_file.call(name)) - clear_screen.call - last_file = name - html.configure(:base=>name) - html.parse(doc) - old_imgs.clear + if (doc = read_file.call(name)) + clear_screen.call + last_file = name + html.configure(:base=>name) + html.parse(doc) + old_imgs.clear + end } href_binding = proc{|x, y| @@ -196,15 +202,16 @@ href_binding = proc{|x, y| html.selection_clear priv['mark'] = "@#{x},#{y}" lst = html.href(x, y) - return if lst.size.zero? - lnk, target = lst + unless lst.size.zero? + lnk, target = lst - if lnk != "" - if lnk =~ /^#{last_file}#(.*)$/ - html.yview($1) - else - load_file.call(lnk) + if lnk != "" + if lnk =~ /^#{last_file}#(.*)$/ + html.yview($1) + else + load_file.call(lnk) + end end end } diff --git a/ext/tk/sample/tkextlib/tkHTML/ss.rb b/ext/tk/sample/tkextlib/tkHTML/ss.rb index 3dbb7ec716..1c13d7ac34 100644 --- a/ext/tk/sample/tkextlib/tkHTML/ss.rb +++ b/ext/tk/sample/tkextlib/tkHTML/ss.rb @@ -6,401 +6,431 @@ require 'tk' require 'tkextlib/tkHTML' -root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV') -fswin = nil - -html = nil -html_fs = nil - -hotkey = {} - file = ARGV[0] +class TkHTML_File_Viewer + include TkComm # These are images to use with the actual image specified in a # "" markup can't be found. # -biggray = TkPhotoImage.new(:data=><<'EOD') +@@biggray = TkPhotoImage.new(:data=><<'EOD') R0lGODdhPAA+APAAALi4uAAAACwAAAAAPAA+AAACQISPqcvtD6OctNqLs968+w+G4kiW5omm 6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNFgsAO/// EOD -smgray = TkPhotoImage.new(:data=><<'EOD') +@@smgray = TkPhotoImage.new(:data=><<'EOD') R0lGODdhOAAYAPAAALi4uAAAACwAAAAAOAAYAAACI4SPqcvtD6OctNqLs968+w+G4kiW5omm 6sq27gvH8kzX9m0VADv/ EOD + def initialize(file = nil) + @root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV') + @fswin = nil -# -# A font chooser routine. -# -# html[:fontcommand] = pick_font -pick_font = proc{|size, attrs| - # puts "FontCmd: #{size} #{attrs}" - [ ((attrs =~ /fixed/)? 'courier': 'charter'), - (12 * (1.2**(size.to_f - 4.0))).to_i, - ((attrs =~ /italic/)? 'italic': 'roman'), - ((attrs =~ /bold/)? 'bold': 'normal') ].join(' ') -} + @html = nil + @html_fs = nil -# This routine is called to pick fonts for the fullscreen view. -# -baseFontSize = 24 -pick_font_fs = proc{|size, attrs| - # puts "FontCmd: #{size} #{attrs}" - [ ((attrs =~ /fixed/)? 'courier': 'charter'), - (baseFontSize * (1.2**(size.to_f - 4.0))).to_i, - ((attrs =~ /italic/)? 'italic': 'roman'), - ((attrs =~ /bold/)? 'bold': 'normal') ].join(' ') -} + @hotkey = {} -# -# -hyper_cmd = proc{|*args| - puts "HyperlinkCommand: #{args.inspect}" -} + @applet_arg = TkVarAccess.new_hash('AppletArg') -# This routine is called to run an applet -# -applet_arg = TkVarAccess.new_hash('AppletArg') -run_applet = proc{|size, w, arglist| - applet_arg.value = Hash[*simplelist(arglist)] + @images = {} + @old_imgs = {} + @big_imgs = {} - return unless applet_arg.key?('src') + @last_dir = Dir.pwd - src = html.remove(applet_arg['src']) + @last_file = '' - applet_arg['window'] = w - applet_arg['fontsize'] = size + @key_block = false - begin - Tk.load_tclscript(src) - rescue => e - puts "Applet error: #{e.message}" - end -} + Tk::HTML_Widget::ClippingWindow.bind('1', + proc{|w, ksym| key_press(w, ksym)}, + '%W Down') + Tk::HTML_Widget::ClippingWindow.bind('3', + proc{|w, ksym| key_press(w, ksym)}, + '%W Up') + Tk::HTML_Widget::ClippingWindow.bind('2', + proc{|w, ksym| key_press(w, ksym)}, + '%W Down') -# -# -form_cmd = proc{|n, cmd, *args| -} + Tk::HTML_Widget::ClippingWindow.bind('KeyPress', + proc{|w, ksym| key_press(w, ksym)}, + '%W %K') -# -# -images = {} -old_imgs = {} -big_imgs = {} + ############################################ + # + # Build the half-size view of the page + # + menu_spec = [ + [['File', 0], + ['Open', proc{sel_load()}, 0], + ['Full Screen', proc{fullscreen()}, 0], + ['Refresh', proc{refresh()}, 0], + '---', + ['Exit', proc{exit}, 1]] + ] -# -# -move_big_image = proc{|b| - return unless big_imgs.key?(b) - b.copy(big_imgs[b]) - big_imgs[b].delete - big_imgs.delete(b) -} + mbar = @root.add_menubar(menu_spec) -image_cmd = proc{|hs, *args| - fn = args[0] - - if old_imgs.key?(fn) - return (images[fn] = old_imgs.delete(fn)) - end - - begin - img = TkPhotoImage.new(:file=>fn) - rescue - return ((hs)? smallgray: biggray) - end - - if hs - img2 = TkPhotoImage.new - img2.copy(img, :subsample=>[2,2]) - img.delete - img = img2 - end - - if img.width * img.height > 20000 - b = TkPhotoImage.new(:width=>img.width, :height=>img.height) - big_imgs[b] = img - img = b - Tk.after_idle(proc{ move_big_image.call(b) }) - end - - images[fn] = img - - img -} - - -# -# This routine is called for every