summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/extmk.rb.in4
-rw-r--r--ext/tk/lib/tk.rb205
-rw-r--r--ext/tk/lib/tkcanvas.rb107
-rw-r--r--ext/tk/lib/tkentry.rb8
-rw-r--r--ext/tk/lib/tkfont.rb14
5 files changed, 304 insertions, 34 deletions
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in
index 44232da7a1..c97f86a687 100644
--- a/ext/extmk.rb.in
+++ b/ext/extmk.rb.in
@@ -425,10 +425,12 @@ all: $(DLLIB)
clean:; @$(RM) *.#{$OBJEXT} *.so *.sl *.#{$LIBEXT} $(DLLIB)
@$(RM) *.ilk *.exp *.pdb *.bak
+
+distclean: clean
@$(RM) Makefile extconf.h conftest.*
@$(RM) core ruby$(EXEEXT) *~
-realclean: clean
+realclean: distclean
EOS
mfile.printf <<EOS
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index bb3f7f6ab8..a18a0e4587 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -457,6 +457,21 @@ module TkCore
_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
@@ -772,6 +787,24 @@ class TkBindTag
end
end
+class TkBindTagAll<TkBindTag
+ BindTagALL = []
+ def TkBindTagAll.new(*args)
+ if BindTagALL[0]
+ BindTagALL[0].bind(*args) if args != []
+ else
+ new = super()
+ BindTagALL[0] = new
+ end
+ BindTagALL[0]
+ end
+
+ def initialize(*args)
+ @id = 'all'
+ BindTagALL[0].bind(*args) if args != []
+ end
+end
+
class TkVariable
include Tk
extend TkCore
@@ -1151,6 +1184,31 @@ module TkKinput
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 useinputmethods(value=nil)
+ TkXIM.useinputmethods(self,value)
+ end
+end
+
module TkWinfo
include Tk
extend Tk
@@ -1807,7 +1865,7 @@ class TkWindow<TkObject
self
end
- def unpack(keys = nil)
+ def unpack
tk_call 'pack', 'forget', epath
self
end
@@ -1817,7 +1875,7 @@ class TkWindow<TkObject
self
end
- def ungrid(keys = nil)
+ def ungrid
tk_call 'grid', 'forget', epath
self
end
@@ -1827,8 +1885,8 @@ class TkWindow<TkObject
self
end
- def unplace(keys = nil)
- tk_call 'place', 'forget', epath, *hash_kv(keys)
+ def unplace
+ tk_call 'place', 'forget', epath
self
end
alias place_forget unplace
@@ -1894,11 +1952,11 @@ class TkWindow<TkObject
end
def lower(below=None)
- tk_call 'lower', path, below
+ tk_call 'lower', epath, below
self
end
def raise(above=None)
- tk_call 'raise', path, above
+ tk_call 'raise', epath, above
self
end
@@ -1912,7 +1970,7 @@ class TkWindow<TkObject
end
def destroy
- tk_call 'destroy', path
+ tk_call 'destroy', epath
if @cmdtbl
for id in @cmdtbl
uninstall_cmd id
@@ -1927,7 +1985,7 @@ class TkWindow<TkObject
alias wait wait_visibility
def wait_destroy
- tk_call 'tkwait', 'window', path
+ tk_call 'tkwait', 'window', epath
end
def bindtags(taglist=nil)
@@ -2259,6 +2317,41 @@ class TkListbox<TkTextWin
def selection_set(first, last=None)
tk_send 'selection', 'set', first, last
end
+
+ def itemcget(index, key)
+ tk_tcl2ruby tk_send 'itemcget', index, "-#{key}"
+ end
+ def itemconfigure(index, key, val=None)
+ if key.kind_of? Hash
+ if (key['font'] || key['kanjifont'] ||
+ key['latinfont'] || key['asciifont'])
+ tagfont_configure(index, key.dup)
+ else
+ tk_send 'itemconfigure', index, *hash_kv(key)
+ end
+
+ else
+ if (key == 'font' || key == 'kanjifont' ||
+ key == 'latinfont' || key == 'asciifont' )
+ tagfont_configure({key=>val})
+ else
+ tk_call 'itemconfigure', index, "-#{key}", val
+ end
+ end
+ end
+
+ def itemconfiginfo(index, key=nil)
+ if key
+ conf = tk_split_list(tk_send('itemconfigure',index,"-#{key}"))
+ conf[0] = conf[0][1..-1]
+ conf
+ else
+ tk_split_list(tk_send('itemconfigure', index)).collect{|conf|
+ conf[0] = conf[0][1..-1]
+ conf
+ }
+ end
+ end
end
module TkTreatMenuEntryFont
@@ -2397,6 +2490,9 @@ class TkMenu<TkWindow
def delete(index, last=None)
tk_send 'delete', index, last
end
+ def popup(x, y, index=nil)
+ tk_call 'tk_popup', path, x, y, index
+ end
def post(x, y)
tk_send 'post', x, y
end
@@ -2451,6 +2547,34 @@ class TkMenu<TkWindow
end
end
+module TkSystemMenu
+ def initialize(parent, keys=nil)
+ fail unless parent.kind_of? TkMenu
+ @path = format("%s.%s", parent.path, self.type::SYSMENU_NAME)
+ TkComm::Tk_WINDOWS[@path] = self
+ create_self
+ configure(keys) if keys
+ 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
@@ -2461,6 +2585,71 @@ class TkMenubutton<TkLabel
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)
+ 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
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index 914bfe01e3..5f4bdadaee 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -217,7 +217,7 @@ class TkCanvas<TkWindow
def find(mode, *args)
list(tk_send 'find', mode, *args).collect!{|id|
- TkcItem.id2obj(id)
+ TkcItem.id2obj(self, id)
}
end
def find_above(target)
@@ -250,14 +250,14 @@ class TkCanvas<TkWindow
if ret == ""
nil
else
- TkcItem.id2obj(ret)
+ TkcItem.id2obj(self, ret)
end
end
end
def gettags(tagOrId)
list(tk_send('gettags', tagid(tagOrId))).collect{|tag|
- TkcTag.id2obj(tag)
+ TkcTag.id2obj(self, tag)
}
end
@@ -471,6 +471,41 @@ module TkcTagAccess
def itemtype
@c.itemtype @id
end
+
+ # Followings operators supports 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
@@ -478,8 +513,10 @@ class TkcTag<TkObject
CTagID_TBL = {}
- def TkcTag.id2obj(id)
- CTagID_TBL[id]? CTagID_TBL[id]: id
+ def TkcTag.id2obj(canvas, id)
+ cpath = canvas.path
+ return id unless CTagID_TBL[cpath]
+ CTagID_TBL[cpath][id]? CTagID_TBL[cpath][id]: id
end
Tk_CanvasTag_ID = ['ctag0000']
@@ -488,8 +525,10 @@ class TkcTag<TkObject
fail format("%s need to be TkCanvas", parent.inspect)
end
@c = parent
+ @cpath = parent.path
@path = @id = Tk_CanvasTag_ID[0]
- CTagID_TBL[@id] = self
+ 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
@@ -501,7 +540,7 @@ class TkcTag<TkObject
def delete
@c.delete @id
- CTagID_TBL[@id] = nil
+ CTagID_TBL[@path][@id] = nil if CTagID_TBL[@path]
end
alias remove delete
alias destroy delete
@@ -527,7 +566,7 @@ class TkcTag<TkObject
alias closest set_to_closest
def set_to_enclosed(x1, y1, x2, y2)
- @c.addtag_enclosest(@id, x1, y1, x2, y2)
+ @c.addtag_enclosed(@id, x1, y1, x2, y2)
end
alias enclosed set_to_enclosed
@@ -542,14 +581,40 @@ class TkcTag<TkObject
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
+
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[@id] = self
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
end
end
@@ -559,8 +624,10 @@ class TkcTagCurrent<TkcTag
fail format("%s need to be TkCanvas", parent.inspect)
end
@c = parent
+ @cpath = parent.path
@path = @id = 'current'
- CTagID_TBL[@id] = self
+ CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath]
+ CTagID_TBL[@cpath][@id] = self
end
end
@@ -571,8 +638,10 @@ class TkcGroup<TkcTag
fail format("%s need to be TkCanvas", parent.inspect)
end
@c = parent
+ @cpath = parent.path
@path = @id = Tk_cGroup_ID[0]
- CTagID_TBL[@id] = self
+ 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
@@ -590,7 +659,6 @@ class TkcGroup<TkcTag
end
end
-
class TkcItem<TkObject
include TkcTagAccess
@@ -601,8 +669,10 @@ class TkcItem<TkObject
CItemTypeToClass[type]
end
- def TkcItem.id2obj(id)
- CItemID_TBL[id]? CItemID_TBL[id]: id
+ 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)
@@ -615,7 +685,8 @@ class TkcItem<TkObject
keys = args.pop
end
@id = create_self(*args).to_i ;# 'canvas item id' is integer number
- CItemID_TBL[@id] = self
+ 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
@@ -629,7 +700,7 @@ class TkcItem<TkObject
def delete
@c.delete @id
- CItemID_TBL[@id] = nil
+ CItemID_TBL[@path][@id] = nil if CItemID_TBL[@path]
end
alias remove delete
alias destroy delete
@@ -761,6 +832,10 @@ class TkPhotoImage<TkImage
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
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index f35d2eef00..5207d9b895 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -59,6 +59,14 @@ class TkEntry<TkLabel
tk_send 'selection', 'to', index
end
+ def validate
+ if tk_send('validate') == '0'
+ false
+ else
+ true
+ end
+ end
+
def value
tk_send 'get'
end
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index 2683260d69..363839d3d3 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -49,7 +49,7 @@ class TkFont
def TkFont.create_copy(font)
keys = {}
- font.configure.each{|key,value| keys[key] = value }
+ font.configinfo.each{|key,value| keys[key] = value }
new_font = TkFont.new(font.latin_font, font.kanji_font, keys)
end
@@ -123,17 +123,13 @@ class TkFont
###################################
private
###################################
- def initialize(ltn=nil, knj=nil, keys=nil)
+ def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=DEFAULT_KANJI_FONT_NAME,
+ keys=nil)
@id = format("@font%.4d", Tk_FontID[0])
Tk_FontID[0] += 1
Tk_FontNameTBL[@id] = self
-
- ltn = DEFAULT_LATIN_FONT_NAME unless ltn
create_latinfont(ltn)
-
- knj = DEFAULT_KANJI_FONT_NAME unless knj
create_kanjifont(knj)
-
create_compoundfont(keys)
end
@@ -714,7 +710,7 @@ class TkFont
if winobj.kind_of? TkText
ret.push([winobj, winobj.tagid2obj(tag)])
elsif winobj.kind_of? TkCanvas
- if (tagobj = TkcTag.id2obj(tag)).kind_of? TkcTag
+ 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])
@@ -822,7 +818,7 @@ class TkFont
if JAPANIZED_TK
configinfo_core(@latinfont, slot)
else
- configure(slot, value)
+ configinfo(slot)
end
end