summaryrefslogtreecommitdiff
path: root/ext/tk/lib
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-04-14 14:35:50 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-04-14 14:35:50 +0000
commited131ebad88c2948d7b40f93ff6ce39f1eb8a2f7 (patch)
tree7bbf62c5e0d0bb8ff971637cf432c6f16824f8f6 /ext/tk/lib
parentbe1fea072cd0d22788ef8a931c0c6b64a2503b5d (diff)
This commit was manufactured by cvs2svn to create tag 'v1_4_4'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_4_4@668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r--ext/tk/lib/tk.rb340
-rw-r--r--ext/tk/lib/tkcanvas.rb31
-rw-r--r--ext/tk/lib/tkentry.rb10
-rw-r--r--ext/tk/lib/tkfont.rb15
-rw-r--r--ext/tk/lib/tktext.rb65
5 files changed, 287 insertions, 174 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index f831dbc78a..c344a2bf8e 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -196,7 +196,9 @@ module TkComm
def _get_eval_string(str)
return nil if str == None
- if str.kind_of?(Hash)
+ if str.kind_of?(String)
+ # do nothing
+ elsif str.kind_of?(Hash)
str = hash_kv(str).join(" ")
elsif str.kind_of?(Array)
str = array2tk_list(str)
@@ -235,7 +237,7 @@ module TkComm
return format("rb_out %s", id);
end
def uninstall_cmd(id)
- id = $1 if /rb_out (c\d+)/
+ id = $1 if /rb_out (c\d+)/ =~ id
Tk_CMDTBL[id] = nil
end
private :install_cmd, :uninstall_cmd
@@ -347,15 +349,6 @@ module TkComm
def _bind_append(what, context, cmd, args=nil)
_bind_core('+', what, context, cmd, args)
end
- private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append
-
- def bind_all(context, cmd=Proc.new, args=nil)
- _bind(['bind', 'all'], context, cmd, args)
- end
-
- def bind_append_all(context, cmd=Proc.new, args=nil)
- _bind_append(['bind', 'all'], context, cmd, args)
- end
def _bindinfo(what, context=nil)
if context
@@ -372,11 +365,33 @@ module TkComm
}
end
end
+ private :install_bind, :tk_event_sequence,
+ :_bind_core, :_bind, :_bind_append, :_bindinfo
+
+ def bind(tagOrClass, context, cmd=Proc.new, args=nil)
+ _bind(["bind", tagOrClass], context, cmd, args)
+ end
+
+ def bind_append(tagOrClass, context, cmd=Proc.new, args=nil)
+ _bind_append(["bind", tagOrClass], context, cmd, args)
+ end
def bindinfo(tagOrClass, context=nil)
_bindinfo(['bind', tagOrClass], context)
end
+ def bind_all(context, cmd=Proc.new, args=nil)
+ _bind(['bind', 'all'], context, cmd, args)
+ end
+
+ def bind_append_all(context, cmd=Proc.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
@@ -401,14 +416,14 @@ module TkCore
INTERP = TclTkIp.new
- INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {return -code $st $ret} {return $ret}")
+ INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {if {[regsub -all {!} $args {\\!} newargs] == 0} {return -code $st $ret} {if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $newargs]} ret]] != 0} {return -code $st $ret} {return $ret}}} {return $ret}")
def callback_break
- raise TkCallbackBreak, "Tk callback returns 'break' status"
+ fail TkCallbackBreak, "Tk callback returns 'break' status"
end
def callback_continue
- raise TkCallbackContinue, "Tk callback returns 'continue' status"
+ fail TkCallbackContinue, "Tk callback returns 'continue' status"
end
def after(ms, cmd=Proc.new)
@@ -514,8 +529,8 @@ module TkCore
args.unshift "unknown"
res = INTERP._invoke(*args)
rescue
- raise unless /^invalid command/ =~ $!
- raise err
+ fail unless /^invalid command/ =~ $!
+ fail err
end
end
if INTERP._return_value() != 0
@@ -570,13 +585,39 @@ module Tk
def yscrollcommand(cmd=Proc.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 = window(tk_call('wm', 'grid', path, *args))
- w.split.collect{|s|s.to_i} if args.length == 0
+ w = tk_call('wm', 'aspect', path, *args)
+ list(w) if args.length == 0
end
def client(name=None)
tk_call 'wm', 'client', path, name
@@ -594,17 +635,18 @@ module Tk
tk_call 'wm', 'focusmodel', path, *args
end
def frame
- tk_call 'wm', 'frame', path
+ tk_call('wm', 'frame', path)
end
def geometry(*args)
- list(tk_call('wm', 'geometry', path, *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)
- tk_call 'wm', 'group', path, *args
+ w = tk_call 'wm', 'group', path, *args
+ window(w) if args.size == 0
end
def iconbitmap(*args)
tk_call 'wm', 'iconbitmap', path, *args
@@ -628,7 +670,7 @@ module Tk
end
def maxsize(*args)
w = tk_call('wm', 'maxsize', path, *args)
- list(w) if not args.size == 0
+ list(w) if args.size == 0
end
def minsize(*args)
w = tk_call('wm', 'minsize', path, *args)
@@ -661,7 +703,7 @@ module Tk
end
end
def sizefrom(*args)
- list(tk_call('wm', 'sizefrom', path, *args))
+ tk_call('wm', 'sizefrom', path, *args)
end
def state
tk_call 'wm', 'state', path
@@ -670,7 +712,7 @@ module Tk
tk_call 'wm', 'title', path, *args
end
def transient(*args)
- tk_call 'wm', 'transient', path, *args
+ window(tk_call 'wm', 'transient', path, *args)
end
def withdraw
tk_call 'wm', 'withdraw', path
@@ -678,6 +720,46 @@ module Tk
end
end
+module TkBindCore
+ def bind(context, cmd=Proc.new, args=nil)
+ Tk.bind(to_eval, context, cmd, args)
+ end
+
+ def bind_append(context, cmd=Proc.new, args=nil)
+ Tk.bind_append(to_eval, context, cmd, args)
+ 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
+
+ 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 TkVariable
include Tk
extend TkCore
@@ -730,7 +812,7 @@ class TkVariable
INTERP._eval(format('global %s; set %s', @id, @id))
rescue
if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1"
- raise
+ fail
else
Hash[*tk_split_simplelist(INTERP._eval(format('global %s; array get %s',
@id, @id)))]
@@ -744,7 +826,7 @@ class TkVariable
INTERP._eval(format('global %s; set %s %s', @id, @id, s))
rescue
if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1"
- raise
+ fail
else
if val == []
INTERP._eval(format('global %s; unset %s; set %s(0) 0; unset %s(0)',
@@ -761,7 +843,7 @@ class TkVariable
INTERP._eval(format('global %s; unset %s; array set %s %s',
@id, @id, @id, s))
else
- raise
+ fail
end
end
end
@@ -790,7 +872,7 @@ class TkVariable
end
def inspect
- format "<TkVariable: %s>", @id
+ format "#<TkVariable: %s>", @id
end
def ==(other)
@@ -1063,19 +1145,19 @@ module TkWinfo
include Tk
extend Tk
def TkWinfo.atom(name)
- tk_call 'winfo', name
+ number(tk_call 'winfo', 'atom', name)
end
def winfo_atom(name)
TkWinfo.atom name
end
def TkWinfo.atomname(id)
- tk_call 'winfo', id
+ tk_call 'winfo', 'atomname', id
end
def winfo_atomname(id)
TkWinfo.atomname id
end
def TkWinfo.cells(window)
- number(tk_call('winfo', window.path))
+ number(tk_call('winfo', 'cells', window.path))
end
def winfo_cells
TkWinfo.cells self
@@ -1093,6 +1175,12 @@ module TkWinfo
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)
@@ -1119,7 +1207,7 @@ module TkWinfo
TkWinfo.fpixels self, number
end
def TkWinfo.geometry(window)
- list(tk_call('winfo', 'geometry', window.path))
+ tk_call('winfo', 'geometry', window.path)
end
def winfo_geometry
TkWinfo.geometry self
@@ -1131,15 +1219,15 @@ module TkWinfo
TkWinfo.height self
end
def TkWinfo.id(window)
- number(tk_call('winfo', 'id', window.path))
+ 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', '-displayof', window.path,
- 'interps'))
+ tk_split_simplelist(tk_call('winfo', 'interps',
+ '-displayof', window.path))
else
tk_split_simplelist(tk_call('winfo', 'interps'))
end
@@ -1153,8 +1241,14 @@ module TkWinfo
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)
- bool(tk_call('winfo', 'name', window.path))
+ tk_call('winfo', 'name', window.path)
end
def winfo_appname
TkWinfo.appname self
@@ -1255,6 +1349,12 @@ module TkWinfo
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
@@ -1267,7 +1367,24 @@ module TkWinfo
def winfo_visual
TkWinfo.visual self
end
- def TkWinfo.vrootheigh(window)
+ 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
@@ -1452,24 +1569,20 @@ module TkTreatFont
alias fontobj font_configinfo
def font_configure(slot)
- if (fnt = slot['font'])
- slot['font'] = nil
+ 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['latinfont'])
- slot['latinfont'] = nil
+ if (ltn = slot.delete('latinfont'))
latinfont_configure(ltn) if ltn
end
- if (ltn = slot['asciifont'])
- slot['asciifont'] = nil
+ if (ltn = slot.delete('asciifont'))
latinfont_configure(ltn) if ltn
end
- if (knj = slot['kanjifont'])
- slot['kanjifont'] = nil
+ if (knj = slot.delete('kanjifont'))
kanjifont_configure(knj) if knj
end
@@ -1544,6 +1657,7 @@ end
class TkObject<TkKernel
include Tk
include TkTreatFont
+ include TkBindCore
def path
return @path
@@ -1640,18 +1754,6 @@ class TkObject<TkKernel
end
end
- def bind(context, cmd=Proc.new, args=nil)
- _bind(["bind", to_eval], context, cmd, args)
- end
-
- def bind_append(context, cmd=Proc.new, args=nil)
- _bind_append(["bind", to_eval], context, cmd, args)
- end
-
- def bindinfo(context=nil)
- _bindinfo(['bind', to_eval], context)
- end
-
def event_generate(context, keys=nil)
if keys
tk_call('event', 'generate', path,
@@ -1675,7 +1777,7 @@ class TkObject<TkKernel
end
class TkWindow<TkObject
-# extend TkClassBind
+ extend TkBindCore
def initialize(parent=nil, keys=nil)
install_win(if parent then parent.path end)
@@ -1823,11 +1925,15 @@ class TkWindow<TkObject
fail unless taglist.kind_of? Array
tk_call('bindtags', path, taglist)
else
- tk_split_list(tk_call('bindtags', path)).collect{|tag|
- if tag == nil
- '.'
- elsif tag.kind_of?(String) && (cls = WidgetClassNames[tag])
- cls
+ 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
@@ -1878,42 +1984,24 @@ class TkToplevel<TkWindow
@classname = classname
if keys.kind_of? Hash
keys = keys.dup
- if keys['classname']
- @classname = keys['classname']
- keys['classname'] = nil
- end
- if keys['colormap']
- @colormap = keys['colormap']
- keys['colormap'] = nil
- end
- if keys['container']
- @classname = keys['container']
- keys['classname'] = nil
- end
- if keys['screen']
- @screen = keys['screen']
- keys['screen'] = nil
- end
- if keys['use']
- @use = keys['use']
- keys['use'] = nil
- end
- if keys['visual']
- @screen = keys['visual']
- keys['visual'] = nil
- end
+ @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.push << "-class" << @classname if @classname
- s.push << "-colormap" << @colormap if @colormap
- s.push << "-container" << @container if @container
- s.push << "-screen" << @screen if @screen
- s.push << "-use" << @use if @use
- s.push << "-visual" << @visual if @visual
+ 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
@@ -1932,32 +2020,20 @@ class TkFrame<TkWindow
def initialize(parent=nil, keys=nil)
if keys.kind_of? Hash
keys = keys.dup
- if keys['classname']
- @classname = keys['classname']
- keys['classname'] = nil
- end
- if keys['colormap']
- @colormap = keys['colormap']
- keys['colormap'] = nil
- end
- if keys['container']
- @classname = keys['container']
- keys['classname'] = nil
- end
- if keys['visual']
- @screen = keys['visual']
- keys['visual'] = nil
- end
+ @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.push << "-class" << @classname if @classname
- s.push << "-colormap" << @colormap if @colormap
- s.push << "-container" << @container if @container
- s.push << "-visual" << @visual if @visual
+ 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
end
@@ -2101,7 +2177,7 @@ end
class TkTextWin<TkWindow
def create_self
- raise TypeError, "TkTextWin is abstract class"
+ fail TypeError, "TkTextWin is abstract class"
end
def bbox(index)
@@ -2131,6 +2207,8 @@ class TkTextWin<TkWindow
end
class TkListbox<TkTextWin
+ include Scrollable
+
WidgetClassNames['Listbox'] = self
def TkListbox.to_eval
'Listbox'
@@ -2145,10 +2223,18 @@ class TkListbox<TkTextWin
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(y)
+ def size
tk_send('size').to_i
end
def selection_anchor(index)
@@ -2157,20 +2243,12 @@ class TkListbox<TkTextWin
def selection_clear(first, last=None)
tk_send 'selection', 'clear', first, last
end
- def selection_includes
- bool(tk_send('selection', 'includes'))
+ 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 xview(cmd, *more)
- v = tk_send('xview', cmd, *more)
- v.to_i if more.size == 0
- end
- def yview(cmd, *more)
- v = tk_send('yview', cmd, *more)
- v.to_i if more.size == 0
- end
end
module TkTreatMenuEntryFont
@@ -2187,8 +2265,7 @@ module TkTreatMenuEntryFont
def tagfont_configure(index, slot)
pathname = self.path + ';' + index
- if (fnt = slot['font'])
- slot['font'] = nil
+ if (fnt = slot.delete('font'))
if fnt.kind_of? TkFont
return fnt.call_font_configure(pathname,
self.path,'entryconfigure',index,slot)
@@ -2196,16 +2273,13 @@ module TkTreatMenuEntryFont
latintagfont_configure(index, fnt) if fnt
end
end
- if (ltn = slot['latinfont'])
- slot['latinfont'] = nil
+ if (ltn = slot.delete('latinfont'))
latintagfont_configure(index, ltn) if ltn
end
- if (ltn = slot['asciifont'])
- slot['asciifont'] = nil
+ if (ltn = slot.delete('asciifont'))
latintagfont_configure(index, ltn) if ltn
end
- if (knj = slot['kanjifont'])
- slot['kanjifont'] = nil
+ if (knj = slot.delete('kanjifont'))
kanjitagfont_configure(index, knj) if knj
end
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index 40bfa54846..80c36f6ed8 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -30,8 +30,7 @@ module TkTreatCItemFont
else
pathname = self.path + ';' + tagOrId.to_s
end
- if (fnt = slot['font'])
- slot['font'] = nil
+ if (fnt = slot.delete('font'))
if fnt.kind_of? TkFont
return fnt.call_font_configure(pathname,
self.path,'itemconfigure',tagOrId,slot)
@@ -39,16 +38,13 @@ module TkTreatCItemFont
latintagfont_configure(tagOrId, fnt) if fnt
end
end
- if (ltn = slot['latinfont'])
- slot['latinfont'] = nil
+ if (ltn = slot.delete('latinfont'))
latintagfont_configure(tagOrId, ltn) if ltn
end
- if (ltn = slot['asciifont'])
- slot['asciifont'] = nil
+ if (ltn = slot.delete('asciifont'))
latintagfont_configure(tagOrId, ltn) if ltn
end
- if (knj = slot['kanjifont'])
- slot['kanjifont'] = nil
+ if (knj = slot.delete('kanjifont'))
kanjitagfont_configure(tagOrId, knj) if knj
end
@@ -129,6 +125,7 @@ end
class TkCanvas<TkWindow
include TkTreatCItemFont
+ include Scrollable
WidgetClassName = 'Canvas'.freeze
WidgetClassNames[WidgetClassName] = self
@@ -492,15 +489,15 @@ class TkcTag<TkObject
CTagID_TBL[id]? CTagID_TBL[id]: id
end
- $tk_canvas_tag = 'ctag0000'
+ Tk_CanvasTag_ID = ['ctag0000']
def initialize(parent, mode=nil, *args)
if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect)
end
@c = parent
- @path = @id = $tk_canvas_tag
+ @path = @id = Tk_CanvasTag_ID[0]
CTagID_TBL[@id] = self
- $tk_canvas_tag = $tk_canvas_tag.succ
+ Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ
if mode
tk_call @c.path, "addtag", @id, mode, *args
end
@@ -575,15 +572,15 @@ class TkcTagCurrent<TkcTag
end
class TkcGroup<TkcTag
- $tk_group_id = 'tkg00000'
+ 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
- @path = @id = $tk_group_id
+ @path = @id = Tk_cGroup_ID[0]
CTagID_TBL[@id] = self
- $tk_group_id = $tk_group_id.succ
+ Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ
add(*args) if args != []
end
@@ -705,10 +702,10 @@ class TkImage<TkObject
Tk_IMGTBL = {}
- $tk_image_id = 'i00000'
+ Tk_Image_ID = ['i00000']
def initialize(keys=nil)
- @path = $tk_image_id
- $tk_image_id = $tk_image_id.succ
+ @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
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index 5822c00e53..f35d2eef00 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -6,6 +6,8 @@
require 'tk.rb'
class TkEntry<TkLabel
+ include Scrollable
+
WidgetClassName = 'Entry'.freeze
WidgetClassNames[WidgetClassName] = self
def self.to_eval
@@ -15,9 +17,6 @@ class TkEntry<TkLabel
def create_self
tk_call 'entry', @path
end
- def scrollcommand(cmd)
- configure 'scrollcommand', cmd
- end
def delete(s, e=None)
tk_send 'delete', s, e
@@ -45,7 +44,7 @@ class TkEntry<TkLabel
tk_send 'selection', 'adjust', index
end
def selection_clear
- tk_send 'selection', 'clear', 'end'
+ tk_send 'selection', 'clear'
end
def selection_from(index)
tk_send 'selection', 'from', index
@@ -59,9 +58,6 @@ class TkEntry<TkLabel
def selection_to(index)
tk_send 'selection', 'to', index
end
- def xview(*index)
- tk_send 'xview', *index
- end
def value
tk_send 'get'
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index c680d166e7..2683260d69 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -667,7 +667,20 @@ class TkFont
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
- when /^8\.1/
+ when /^8\.[12]/
+ alias create_latinfont create_latinfont_tk8x
+ alias create_kanjifont create_kanjifont_tk81
+ alias create_compoundfont create_compoundfont_tk81
+ 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_tk81
+ 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_tk81
alias create_compoundfont create_compoundfont_tk81
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index 83999cb3e2..7872e6a078 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -28,8 +28,7 @@ module TkTreatTextTagFont
else
pathname = self.path + ';' + tag
end
- if (fnt = slot['font'])
- slot['font'] = nil
+ if (fnt = slot.delete('font'))
if fnt.kind_of? TkFont
return fnt.call_font_configure(pathname,
self.path,'tag','configure',tag,slot)
@@ -37,16 +36,13 @@ module TkTreatTextTagFont
latintagfont_configure(tag, fnt) if fnt
end
end
- if (ltn = slot['latinfont'])
- slot['latinfont'] = nil
+ if (ltn = slot.delete('latinfont'))
latintagfont_configure(tag, ltn) if ltn
end
- if (ltn = slot['asciifont'])
- slot['asciifont'] = nil
+ if (ltn = slot.delete('asciifont'))
latintagfont_configure(tag, ltn) if ltn
end
- if (knj = slot['kanjifont'])
- slot['kanjifont'] = nil
+ if (knj = slot.delete('kanjifont'))
kanjitagfont_configure(tag, knj) if knj
end
@@ -127,30 +123,48 @@ end
class TkText<TkTextWin
include TkTreatTextTagFont
+ include Scrollable
WidgetClassName = 'Text'.freeze
WidgetClassNames[WidgetClassName] = self
+
def self.to_eval
WidgetClassName
end
- include Scrollable
+
+ def self.new(*args)
+ 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
tk_call 'text', @path
- @tags = {}
+ 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
@@ -168,11 +182,19 @@ class TkText<TkTextWin
tagid2obj(elt)
}
end
+
+ def mark_names
+ tk_split_list(tk_send('mark', 'names')).collect{|elt|
+ tagid2obj(elt)
+ }
+ end
+
def window_names
tk_send('window', 'names').collect{|elt|
tagid2obj(elt)
}
end
+
def image_names
tk_send('image', 'names').collect{|elt|
tagid2obj(elt)
@@ -182,6 +204,7 @@ class TkText<TkTextWin
def set_insert(index)
tk_send 'mark', 'set', 'insert', index
end
+
def set_current(index)
tk_send 'mark', 'set', 'current', index
end
@@ -191,6 +214,7 @@ class TkText<TkTextWin
end
def destroy
+ @tags = {} unless @tags
@tags.each_value do |t|
t.destroy
end
@@ -408,14 +432,15 @@ end
class TkTextTag<TkObject
include TkTreatTagFont
- $tk_text_tag = 'tag0000'
+ Tk_TextTag_ID = ['tag0000']
+
def initialize(parent, *args)
if not parent.kind_of?(TkText)
fail format("%s need to be TkText", parent.inspect)
end
@parent = @t = parent
- @path = @id = $tk_text_tag
- $tk_text_tag = $tk_text_tag.succ
+ @path = @id = Tk_TextTag_ID[0]
+ 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
@@ -541,14 +566,14 @@ class TkTextTagSel<TkTextTag
end
class TkTextMark<TkObject
- $tk_text_mark = 'mark0000'
+ 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_text_mark
- $tk_text_mark = $tk_text_mark.succ
+ @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
@@ -572,6 +597,14 @@ class TkTextMark<TkObject
def gravity=(direction)
tk_call @t.path, 'mark', 'gravity', @id, direction
end
+
+ def next(index)
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))
+ end
+
+ def previous(index)
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))
+ end
end
class TkTextMarkInsert<TkTextMark