mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
e6697a6405
* ext/tk/tcltklib.c: avoid error on a shared object. * ext/tk/extconf.rb: support --with-tcltkversion * ext/tk/README.tcltklib: add document about --with-tcltkversion * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb, ext/tk/lib/remote-tk.rb: not work on $SAFE==4 * ext/tk/lib/multi-tk.rb: Object#methods returns Symbols on Ruby1.9. * ext/tk/lib/tk/timer.rb: add TkTimer#at_end(proc) to register the procedure which called at end of the timer. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemfont.rb, ext/tk/lib/font.rb: support __IGNORE_UNKNOWN_CONFIGURE_OPTION__ about font options. * ext/tk/lib/*: treat __IGNORE_UNKNOWN_CONFIGURE_OPTION__ * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb, ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb, ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: bug fix. * ext/tk/lib/tk/text.rb: typo. call a wrong method. * ext/tk/lib/tk/itemconfig.rb: ditto. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemconfig.rb, ext/tk/lib/tk/canvas.rb: support alias names of option keys. * ext/tk/lib/tk/grid.rb: lack of module-method definitions. * ext/tk/lib/tk/pack.rb, ext/tk/lib/tk/grid.rb: increase supported parameter patterns of configure method. * ext/tk/lib/tk.rb: add TkWindow#grid_anchor, grid_column, grid_row. * ext/tk/lib/tk/wm.rb: methods of Tk::Wm_for_General module cannot pass the given block to methods of Tk::Wm module. * ext/tk/lib/tk/wm.rb: Wm#overrideredirect overwrites arguemnt to an invalid value. * ext/tk/lib/tk.rb: fix memory (object) leak bug. * ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak. * ext/tk/sample/demos-jp/aniwave.rb, ext/tk/sample/demos-en/aniwave.rb: bug fix. * ext/tk/lib/tkextlib/blt/component.rb, ext/tk/lib/tkextlib/tile/tentry.rb, ext/tk/lib/tkextlib/tile/treeview.rb: ditto. * ext/tk/lib/tkextlib/tile/tpaned.rb: improve TPaned#add. * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget, ext/tk/sample/demos-jp/style.rb, ext/tk/sample/demos-en/style.rb, ext/tk/sample/demos-jp/bind.rb, ext/tk/sample/demos-en/bind.rb: bug fix. * ext/tk/sample/ttk_wrapper.rb: ditto. * ext/tk/sample/ttk_wrapper.rb: support "if __FILE__ == $0" idiom. * ext/tk/sample/tktextio.rb: add binding for 'Ctrl-u' at console mode. * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb, ext/tk/sample/ttk_wrapper.rb: improve treating and control themes. add Tk::Tile.themes and Tk::Tile.set_theme(theme). * ext/tk/lib/tkextlib/tile.rb: lack of autoload definitions. * ext/tk/lib/tkextlib/tile/tnotebook.rb: cannot use kanji (not UTF-8) characters for headings. * ext/tk/lib/tkextlib/tkDND/shape.rb: wrong package name. * ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys. Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g. :widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on; those are attributes of event object). It means that Ruby/Tk accepts not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }". It is potentially incompatible, when user passes symbols to the arguments of the callback block (the block receives the symbols as strings). I think that is very rare case (probably, used by Ruby/Tk experts only). When causes such trouble, please give strings instead of such symbol parameters (e.g. call Symbol#to_s method). * ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb, ext/tk/lib/tkextlib/blt/treeview.rb, ext/tk/lib/tkextlib/winico/winico.rb: ditto. * ext/tk/tkutil/tkutil.c: strings are available on subst_tables on TkUtil::CallbackSubst class (it is useful on Ruby 1.9). * ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb, ext/tk/lib/tkextlib/iwidgets/spinner.rb, ext/tk/lib/tkextlib/iwidgets/entryfield.rb, ext/tk/lib/tkextlib/iwidgets/calendar.rb, ext/tk/lib/tkextlib/blt/dragdrop.rb, ext/tk/lib/tkextlib/tkDND/tkdnd.rb, ext/tk/lib/tkextlib/treectrl/tktreectrl.rb, ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c. * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb: change strategy to define the constant WITH_ENCODING. * ext/tk/lib/tk.rb: fix bug on Tk::Encoding.tk_encoding_names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
247 lines
8.8 KiB
Ruby
247 lines
8.8 KiB
Ruby
# -*- coding: euc-jp -*-
|
||
#
|
||
# arrowhead widget demo (called by 'widget')
|
||
#
|
||
|
||
# arrowSetup --
|
||
# This method regenerates all the text and graphics in the canvas
|
||
# window. It's called when the canvas is initially created, and also
|
||
# whenever any of the parameters of the arrow head are changed
|
||
# interactively.
|
||
#
|
||
# Arguments:
|
||
# c - Name of the canvas widget.
|
||
|
||
def arrowSetup(c)
|
||
v = $demo_arrowInfo
|
||
|
||
# Remember the current box, if there is one.
|
||
tags = c.gettags('current')
|
||
if tags != []
|
||
cur = tags.find{|t| t.kind_of?(String) && t =~ /^box[1-3]$/ }
|
||
else
|
||
cur = nil
|
||
end
|
||
|
||
# Create the arrow and outline.
|
||
c.delete('all')
|
||
TkcLine.new(c, v.x1, v.y, v.x2, v.y,
|
||
{ 'width'=>10 * v.width,
|
||
'arrowshape'=>[10*v.a, 10*v.b, 10*v.c],
|
||
'arrow'=>'last'
|
||
}.update(v.bigLineStyle) )
|
||
xtip = v.x2 - 10*v.b
|
||
deltaY = 10*v.c + 5*v.width
|
||
TkcLine.new(c, v.x2, v.y, xtip, v.y + deltaY,
|
||
v.x2 - 10*v.a, v.y, xtip, v.y - deltaY, v.x2, v.y,
|
||
'width'=>2, 'capstyle'=>'round', 'joinstyle'=>'round')
|
||
|
||
# Create the boxes for reshaping the line and arrowhead.
|
||
TkcRectangle.new(c, v.x2-10*v.a-5, v.y-5, v.x2-10*v.a+5, v.y+5,
|
||
{'tags'=>['box1', $arrowTag_box]}.update(v.boxStyle) )
|
||
TkcRectangle.new(c, xtip-5, v.y-deltaY-5, xtip+5, v.y-deltaY+5,
|
||
{'tags'=>['box2', $arrowTag_box]}.update(v.boxStyle) )
|
||
TkcRectangle.new(c, v.x1-5, v.y-5*v.width-5, v.x1+5, v.y-5*v.width+5,
|
||
{'tags'=>['box3', $arrowTag_box]}.update(v.boxStyle) )
|
||
c.itemconfigure cur, v.activeStyle if cur
|
||
|
||
# Create three arrows in actual size with the same parameters
|
||
TkcLine.new(c, v.x2+50, 0, v.x2+50, 1000, 'width'=>2)
|
||
tmp = v.x2+100
|
||
TkcLine.new(c, tmp, v.y-125, tmp, v.y-75, 'width'=>v.width,
|
||
'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])
|
||
TkcLine.new(c, tmp-25, v.y, tmp+25, v.y, 'width'=>v.width,
|
||
'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])
|
||
TkcLine.new(c, tmp-25, v.y+75, tmp+25, v.y+125, 'width'=>v.width,
|
||
'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])
|
||
|
||
# Create a bunch of other arrows and text items showing the
|
||
# current dimensions.
|
||
tmp = v.x2+10
|
||
TkcLine.new(c, tmp, v.y-5*v.width, tmp, v.y-deltaY,
|
||
'arrow'=>'both', 'arrowshape'=>v.smallTips)
|
||
TkcText.new(c, v.x2+15, v.y-deltaY+5*v.c, 'text'=>v.c, 'anchor'=>'w')
|
||
tmp = v.x1-10
|
||
TkcLine.new(c, tmp, v.y-5*v.width, tmp, v.y+5*v.width,
|
||
'arrow'=>'both', 'arrowshape'=>v.smallTips)
|
||
TkcText.new(c, v.x1-15, v.y, 'text'=>v.width, 'anchor'=>'e')
|
||
tmp = v.y+5*v.width+10*v.c+10
|
||
TkcLine.new(c, v.x2-10*v.a, tmp, v.x2, tmp,
|
||
'arrow'=>'both', 'arrowshape'=>v.smallTips)
|
||
TkcText.new(c, v.x2-5*v.a, tmp+5, 'text'=>v.a, 'anchor'=>'n')
|
||
tmp = tmp+25
|
||
TkcLine.new(c, v.x2-10*v.b, tmp, v.x2, tmp,
|
||
'arrow'=>'both', 'arrowshape'=>v.smallTips)
|
||
TkcText.new(c, v.x2-5*v.b, tmp+5, 'text'=>v.b, 'anchor'=>'n')
|
||
|
||
if $tk_version =~ /^4.*/
|
||
TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
|
||
'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
|
||
TkcText.new(c, v.x1, 330,
|
||
'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",'anchor'=>'w',
|
||
'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
|
||
else
|
||
TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
|
||
'font'=>'Helvetica 18')
|
||
TkcText.new(c, v.x1, 330,
|
||
'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",
|
||
'anchor'=>'w', 'font'=>'Helvetica 18')
|
||
end
|
||
|
||
v.count += 1
|
||
end
|
||
|
||
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if defined?($arrow_demo) && $arrow_demo
|
||
$arrow_demo.destroy
|
||
$arrow_demo = nil
|
||
end
|
||
|
||
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
$arrow_demo = TkToplevel.new {|w|
|
||
title("Arrowhead Editor Demonstration")
|
||
iconname("arrow")
|
||
positionWindow(w)
|
||
}
|
||
|
||
base_frame = TkFrame.new($arrow_demo).pack(:fill=>:both, :expand=>true)
|
||
|
||
# label <20><><EFBFBD><EFBFBD>
|
||
TkLabel.new(base_frame, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
|
||
'text'=>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD> widget <20>ǡ<EFBFBD><C7A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Х<EFBFBD><D0A5>ǻȤ<C7BB><C8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>饤<EFBFBD><E9A5A4><EFBFBD>ˤĤ<CBA4><C4A4><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƭ<EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD>Ƥߤ뤳<DFA4>Ȥ<EFBFBD><C8A4>Ǥ<EFBFBD><C7A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD>Ѥ<EFBFBD><D1A4><EFBFBD><EFBFBD>ˤϡ<CBA4><CFA1><EFBFBD><EFBFBD>礵<EFBFBD>줿<EFBFBD><ECA4BF><EFBFBD><EFBFBD><EFBFBD>ˤĤ<CBA4><C4A4>Ƥ<EFBFBD><C6A4><EFBFBD> 3<>ĤλͳѤ<CDB3><D1A4>ɥ<EFBFBD><C9A5>å<EFBFBD><C3A5><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¦<EFBFBD><C2A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̤<EFBFBD><CCA4>礭<EFBFBD><E7A4AD><EFBFBD>ǤΥ<C7A4><CEA5><EFBFBD><EFBFBD>ץ<EFBFBD><D7A5><EFBFBD><F2BCA8A4>Ƥ<EFBFBD><C6A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υƥ<CEA5><C6A5><EFBFBD><EFBFBD>Ȥϥ饤<CFA5><EFBFBD><F3A5A2A5>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>Ф<EFBFBD><D0A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ꥪ<EFBFBD>ץ<EFBFBD><D7A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><C7A4><EFBFBD>"){
|
||
pack('side'=>'top')
|
||
}
|
||
|
||
# frame <20><><EFBFBD><EFBFBD>
|
||
$arrow_buttons = TkFrame.new(base_frame) {|frame|
|
||
TkButton.new(frame) {
|
||
#text 'λ<><CEBB>'
|
||
text '<27>Ĥ<EFBFBD><C4A4><EFBFBD>'
|
||
command proc{
|
||
tmppath = $arrow_demo
|
||
$arrow_demo = nil
|
||
tmppath.destroy
|
||
}
|
||
}.pack('side'=>'left', 'expand'=>'yes')
|
||
|
||
TkButton.new(frame) {
|
||
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
|
||
command proc{showCode 'arrow'}
|
||
}.pack('side'=>'left', 'expand'=>'yes')
|
||
}
|
||
$arrow_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
|
||
|
||
# canvas <20><><EFBFBD><EFBFBD>
|
||
$arrow_canvas = TkCanvas.new(base_frame, 'width'=>500, 'height'=>350,
|
||
'relief'=>'sunken', 'borderwidth'=>2)
|
||
$arrow_canvas.pack('expand'=>'yes', 'fill'=>'both')
|
||
|
||
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
unless Struct.const_defined?("ArrowInfo")
|
||
$demo_arrowInfo = Struct.new("ArrowInfo", :a, :b, :c, :width, :motionProc,
|
||
:x1, :x2, :y, :smallTips, :count,
|
||
:bigLineStyle, :boxStyle, :activeStyle).new
|
||
end
|
||
$demo_arrowInfo.a = 8
|
||
$demo_arrowInfo.b = 10
|
||
$demo_arrowInfo.c = 3
|
||
$demo_arrowInfo.width = 2
|
||
$demo_arrowInfo.motionProc = proc{}
|
||
$demo_arrowInfo.x1 = 40
|
||
$demo_arrowInfo.x2 = 350
|
||
$demo_arrowInfo.y = 150
|
||
$demo_arrowInfo.smallTips = [5, 5, 2]
|
||
$demo_arrowInfo.count = 0
|
||
if TkWinfo.depth($arrow_canvas) > 1
|
||
$demo_arrowInfo.bigLineStyle = {'fill'=>'SkyBlue1'}
|
||
$demo_arrowInfo.boxStyle = {'fill'=>'', 'outline'=>'black', 'width'=>1}
|
||
$demo_arrowInfo.activeStyle = {'fill'=>'red', 'outline'=>'black', 'width'=>1}
|
||
else
|
||
$demo_arrowInfo.bigLineStyle = {'fill'=>'black',
|
||
'stipple'=>'@'+[$demo_dir,'..','images','grey.25'].join(File::Separator)}
|
||
$demo_arrowInfo.boxStyle = {'fill'=>'', 'outline'=>'black', 'width'=>1}
|
||
$demo_arrowInfo.activeStyle = {'fill'=>'black','outline'=>'black','width'=>1}
|
||
end
|
||
$arrowTag_box = TkcTag.new($arrow_canvas)
|
||
arrowSetup $arrow_canvas
|
||
$arrowTag_box.bind('Enter', proc{$arrow_canvas.itemconfigure('current', $demo_arrowInfo.activeStyle)})
|
||
$arrowTag_box.bind('Leave', proc{$arrow_canvas.itemconfigure('current', $demo_arrowInfo.boxStyle)})
|
||
$arrowTag_box.bind('B1-Enter', proc{})
|
||
$arrowTag_box.bind('B1-Leave', proc{})
|
||
$arrow_canvas.itembind('box1', '1',
|
||
proc{$demo_arrowInfo.motionProc \
|
||
= proc{|x,y| arrowMove1 $arrow_canvas, x, y}})
|
||
$arrow_canvas.itembind('box2', '1',
|
||
proc{$demo_arrowInfo.motionProc \
|
||
= proc{|x,y| arrowMove2 $arrow_canvas, x, y}})
|
||
$arrow_canvas.itembind('box3', '1',
|
||
proc{$demo_arrowInfo.motionProc \
|
||
= proc{|x,y| arrowMove3 $arrow_canvas, x, y}})
|
||
$arrowTag_box.bind('B1-Motion',
|
||
proc{|x,y| $demo_arrowInfo.motionProc.call(x,y)}, "%x %y")
|
||
$arrow_canvas.bind('Any-ButtonRelease-1', proc{arrowSetup $arrow_canvas})
|
||
|
||
# arrowMove1 --
|
||
# This method is called for each mouse motion event on box1 (the
|
||
# one at the vertex of the arrow). It updates the controlling parameters
|
||
# for the line and arrowhead.
|
||
#
|
||
# Arguments:
|
||
# c - The name of the canvas window.
|
||
# x, y - The coordinates of the mouse.
|
||
|
||
def arrowMove1(c,x,y)
|
||
v = $demo_arrowInfo
|
||
newA = (v.x2+5-c.canvasx(x).round)/10
|
||
newA = 0 if newA < 0
|
||
newA = 25 if newA > 25
|
||
if newA != v.a
|
||
c.move('box1', 10*(v.a-newA), 0)
|
||
v.a = newA
|
||
end
|
||
end
|
||
|
||
# arrowMove2 --
|
||
# This method is called for each mouse motion event on box2 (the
|
||
# one at the trailing tip of the arrowhead). It updates the controlling
|
||
# parameters for the line and arrowhead.
|
||
#
|
||
# Arguments:
|
||
# c - The name of the canvas window.
|
||
# x, y - The coordinates of the mouse.
|
||
|
||
def arrowMove2(c,x,y)
|
||
v = $demo_arrowInfo
|
||
newB = (v.x2+5-c.canvasx(x).round)/10
|
||
newB = 0 if newB < 0
|
||
newB = 25 if newB > 25
|
||
newC = (v.y+5-c.canvasy(y).round-5*v.width)/10
|
||
newC = 0 if newC < 0
|
||
newC = 20 if newC > 20
|
||
if newB != v.b || newC != v.c
|
||
c.move('box2', 10*(v.b-newB), 10*(v.c-newC))
|
||
v.b = newB
|
||
v.c = newC
|
||
end
|
||
end
|
||
|
||
# arrowMove3 --
|
||
# This method is called for each mouse motion event on box3 (the
|
||
# one that controls the thickness of the line). It updates the
|
||
# controlling parameters for the line and arrowhead.
|
||
#
|
||
# Arguments:
|
||
# c - The name of the canvas window.
|
||
# x, y - The coordinates of the mouse.
|
||
|
||
def arrowMove3(c,x,y)
|
||
v = $demo_arrowInfo
|
||
newWidth = (v.y+2-c.canvasy(y).round)/5
|
||
newWidth = 0 if newWidth < 0
|
||
newWidth = 20 if newWidth > 20
|
||
if newWidth != v.width
|
||
c.move('box3', 0, 5*(v.width-newWidth))
|
||
v.width = newWidth
|
||
end
|
||
end
|
||
|