summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/lib/tk')
-rw-r--r--ext/tk/lib/tk/canvas.rb9
-rw-r--r--ext/tk/lib/tk/canvastag.rb3
-rw-r--r--ext/tk/lib/tk/composite.rb52
-rw-r--r--ext/tk/lib/tk/image.rb19
-rw-r--r--ext/tk/lib/tk/itemconfig.rb57
-rw-r--r--ext/tk/lib/tk/itemfont.rb33
-rw-r--r--ext/tk/lib/tk/menu.rb13
-rw-r--r--ext/tk/lib/tk/namespace.rb14
-rw-r--r--ext/tk/lib/tk/panedwindow.rb23
-rw-r--r--ext/tk/lib/tk/text.rb34
-rw-r--r--ext/tk/lib/tk/textimage.rb4
-rw-r--r--ext/tk/lib/tk/texttag.rb3
-rw-r--r--ext/tk/lib/tk/textwindow.rb3
13 files changed, 242 insertions, 25 deletions
diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb
index fceadd5e9c..36ea008a17 100644
--- a/ext/tk/lib/tk/canvas.rb
+++ b/ext/tk/lib/tk/canvas.rb
@@ -168,6 +168,8 @@ class Tk::Canvas<TkWindow
#tk_tcl2ruby(tk_send_without_enc('canvasy', screen_y, *args))
number(tk_send_without_enc('canvasy', screen_y, *args))
end
+ alias canvas_x canvasx
+ alias canvas_y canvasy
def coords(tag, *args)
if args == []
@@ -642,6 +644,13 @@ class TkcItem<TkObject
fontkeys[fkey] = keys.delete(fkey) if keys.key?(fkey)
}
+ __item_optkey_aliases(nil).each{|alias_name, real_name|
+ alias_name = alias_name.to_s
+ if keys.has_key?(alias_name)
+ keys[real_name.to_s] = keys.delete(alias_name)
+ end
+ }
+
__item_methodcall_optkeys(nil).each{|key|
key = key.to_s
methodkeys[key] = keys.delete(key) if keys.key?(key)
diff --git a/ext/tk/lib/tk/canvastag.rb b/ext/tk/lib/tk/canvastag.rb
index 7feea1575c..49796d80b2 100644
--- a/ext/tk/lib/tk/canvastag.rb
+++ b/ext/tk/lib/tk/canvastag.rb
@@ -63,6 +63,9 @@ module TkcTagAccess
def cget(option)
@c.itemcget(@id, option)
end
+ def cget_strict(option)
+ @c.itemcget_strict(@id, option)
+ end
def configure(key, value=None)
@c.itemconfigure(@id, key, value)
diff --git a/ext/tk/lib/tk/composite.rb b/ext/tk/lib/tk/composite.rb
index 728b02f608..883d43c3ea 100644
--- a/ext/tk/lib/tk/composite.rb
+++ b/ext/tk/lib/tk/composite.rb
@@ -181,6 +181,57 @@ module TkComposite
delegate_alias(option, option, *wins)
end
+ def __cget_delegates(slot)
+ slot = slot.to_s
+
+ if @option_methods.include?(slot)
+ if @option_methods[slot][:cget]
+ return self.__send__(@option_methods[slot][:cget])
+ else
+ if @option_setting[slot]
+ return @option_setting[slot]
+ else
+ return ''
+ end
+ end
+ end
+
+ tbl = @delegates[slot]
+ tbl = @delegates['DEFAULT'] unless tbl
+
+ begin
+ if tbl
+ opt, wins = tbl[-1]
+ opt = slot if opt == 'DEFAULT'
+ if wins && wins[-1]
+ # return wins[-1].cget(opt)
+ return wins[-1].cget_strict(opt)
+ end
+ end
+ rescue
+ end
+
+ return None
+ end
+ private :__cget_delegates
+
+ def cget(slot)
+ if (ret = __cget_delegates(slot)) == None
+ super(slot)
+ else
+ ret
+ end
+ end
+
+ def cget_strict(slot)
+ if (ret = __cget_delegates(slot)) == None
+ super(slot)
+ else
+ ret
+ end
+ end
+
+=begin
def cget(slot)
slot = slot.to_s
@@ -212,6 +263,7 @@ module TkComposite
super(slot)
end
+=end
def configure(slot, value=None)
if slot.kind_of? Hash
diff --git a/ext/tk/lib/tk/image.rb b/ext/tk/lib/tk/image.rb
index 57f82cb812..dffdc19644 100644
--- a/ext/tk/lib/tk/image.rb
+++ b/ext/tk/lib/tk/image.rb
@@ -156,7 +156,7 @@ class TkPhotoImage<TkImage
self
end
- def cget(option)
+ def cget_strict(option)
case option.to_s
when 'data', 'file'
tk_send 'cget', '-' << option.to_s
@@ -164,6 +164,23 @@ class TkPhotoImage<TkImage
tk_tcl2ruby(tk_send('cget', '-' << option.to_s))
end
end
+ def cget(option)
+ unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
+ cget_strict(option)
+ else
+ begin
+ cget_strict(option)
+ rescue => e
+ if current_configinfo.has_key?(option.to_s)
+ # error on known option
+ fail e
+ else
+ # unknown option
+ nil
+ end
+ end
+ end
+ end
def copy(src, *opts)
if opts.size == 0
diff --git a/ext/tk/lib/tk/itemconfig.rb b/ext/tk/lib/tk/itemconfig.rb
index abff676d78..9c6a98d0f8 100644
--- a/ext/tk/lib/tk/itemconfig.rb
+++ b/ext/tk/lib/tk/itemconfig.rb
@@ -8,6 +8,11 @@ require 'tk/itemfont.rb'
module TkItemConfigOptkeys
include TkUtil
+ def __item_optkey_aliases(id)
+ {}
+ end
+ private :__item_optkey_aliases
+
def __item_numval_optkeys(id)
[]
end
@@ -165,6 +170,11 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_opt.inspect}'"
end
+ alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == option}
+ if real_name
+ option = real_name.to_s
+ end
+
if ( method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[option] )
optval = tk_call_without_enc(*(__item_cget_cmd(tagid(tagOrId)) << "-#{option}"))
begin
@@ -242,20 +252,35 @@ module TkItemConfigMethod
__itemcget_core(tagOrId, option)
rescue => e
begin
- __itemcget_core(tagOrId)
- # not tag error -> option is unknown
- nil
+ if __current_itemconfiginfo(tagOrId).has_key?(option.to_s)
+ # not tag error & option is known -> error on known option
+ fail e
+ else
+ # not tag error & option is unknown
+ nil
+ end
rescue
fail e # tag error
end
end
end
end
+ def itemcget_strict(tagOrId, option)
+ # never use TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
+ __itemcget_core(tagOrId, option)
+ end
def __itemconfigure_core(tagOrId, slot, value=None)
if slot.kind_of? Hash
slot = _symbolkey2str(slot)
+ __item_optkey_aliases(tagid(tagOrId)).each{|alias_name, real_name|
+ alias_name = alias_name.to_s
+ if slot.has_key?(alias_name)
+ slot[real_name.to_s] = slot.delete(alias_name)
+ end
+ }
+
__item_methodcall_optkeys(tagid(tagOrId)).each{|key, method|
value = slot.delete(key.to_s)
self.__send__(method, tagOrId, value) if value
@@ -292,6 +317,11 @@ module TkItemConfigMethod
fail ArgumentError, "Invalid option `#{orig_slot.inspect}'"
end
+ alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
+ if real_name
+ slot = real_name.to_s
+ end
+
if ( conf = __item_keyonly_optkeys(tagid(tagOrId)).find{|k, v| k.to_s == slot } )
defkey, undefkey = conf
if value
@@ -350,8 +380,13 @@ module TkItemConfigMethod
__itemconfigure_core(tagOrId, slot, value)
rescue => e
begin
- __itemconfiginfo_core(tagOrId)
- # not tag error -> option is unknown
+ if __current_itemconfiginfo(tagOrId).has_key?(slot.to_s)
+ # not tag error & option is known -> error on known option
+ fail e
+ else
+ # not tag error & option is unknown
+ nil
+ end
rescue
fail e # tag error
end
@@ -386,6 +421,12 @@ module TkItemConfigMethod
else
if slot
slot = slot.to_s
+
+ alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
+ if real_name
+ slot = real_name.to_s
+ end
+
case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
@@ -757,6 +798,12 @@ module TkItemConfigMethod
else
if slot
slot = slot.to_s
+
+ alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
+ if real_name
+ slot = real_name.to_s
+ end
+
case slot
when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
diff --git a/ext/tk/lib/tk/itemfont.rb b/ext/tk/lib/tk/itemfont.rb
index 11d443b597..4c5c917c57 100644
--- a/ext/tk/lib/tk/itemfont.rb
+++ b/ext/tk/lib/tk/itemfont.rb
@@ -94,11 +94,14 @@ module TkTreatItemFont
*(__item_config_cmd(tagid(tagOrId)) << {}))
next
else
- begin
+ fnt = hash_kv(fnt) if fnt.kind_of?(Hash)
+ unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
- rescue => e
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- fail e
+ else
+ begin
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << fnt))
+ rescue => e
+ # ignore
end
end
end
@@ -153,11 +156,14 @@ module TkTreatItemFont
elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object
else
- begin
+ ltn = hash_kv(ltn) if ltn.kind_of?(Hash)
+ unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
- rescue => e
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- fail e
+ else
+ begin
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << ltn))
+ rescue => e
+ # ignore
end
end
next
@@ -210,11 +216,14 @@ module TkTreatItemFont
elsif Tk::JAPANIZED_TK
fobj = fontobj # create a new TkFont object
else
- begin
+ knj = hash_kv(knj) if knj.kind_of?(Hash)
+ unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
- rescue => e
- unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
- fail e
+ else
+ begin
+ tk_call(*(__item_config_cmd(tagid(tagOrId)) << "-#{optkey}" << knj))
+ rescue => e
+ # ignore
end
end
next
diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb
index 8ba3156293..3ae0548dd1 100644
--- a/ext/tk/lib/tk/menu.rb
+++ b/ext/tk/lib/tk/menu.rb
@@ -34,12 +34,13 @@ module TkMenuEntryConfig
private :__item_val2ruby_optkeys
alias entrycget itemcget
+ alias entrycget_strict itemcget_strict
alias entryconfigure itemconfigure
alias entryconfiginfo itemconfiginfo
alias current_entryconfiginfo current_itemconfiginfo
- private :itemcget, :itemconfigure
- private :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemcget_strict
+ private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end
class Tk::Menu<TkWindow
@@ -518,7 +519,7 @@ class Tk::Menubutton<Tk::Label
tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys)
unless keys.empty?
- tk_call_without_enc('destroy', @path)
+ tk_call_without_enc('destroy', @path) rescue nil
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
end
@@ -642,6 +643,9 @@ class Tk::OptionMenubutton<Tk::Menubutton
def menucget(key)
@menu.cget(key)
end
+ def menucget_strict(key)
+ @menu.cget_strict(key)
+ end
def menuconfigure(key, val=None)
@menu.configure(key, val)
self
@@ -655,6 +659,9 @@ class Tk::OptionMenubutton<Tk::Menubutton
def entrycget(index, key)
@menu.entrycget(index, key)
end
+ def entrycget_strict(index, key)
+ @menu.entrycget_strict(index, key)
+ end
def entryconfigure(index, key, val=None)
@menu.entryconfigure(index, key, val)
self
diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb
index 9d2213ff51..20a8d65215 100644
--- a/ext/tk/lib/tk/namespace.rb
+++ b/ext/tk/lib/tk/namespace.rb
@@ -83,6 +83,20 @@ class TkNamespace < TkObject
super(slot)
end
end
+ def cget_strict(slot)
+ if slot == :namespace || slot == 'namespace'
+ ns = super(slot)
+ Tk_Namespace_ID_TBL.mutex.synchronize{
+ if TkNamespace::Tk_Namespace_ID_TBL.key?(ns)
+ TkNamespace::Tk_Namespace_ID_TBL[ns]
+ else
+ ns
+ end
+ }
+ else
+ super(slot)
+ end
+ end
def configinfo(slot = nil)
if slot
diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb
index ba8a7e9743..030144e677 100644
--- a/ext/tk/lib/tk/panedwindow.rb
+++ b/ext/tk/lib/tk/panedwindow.rb
@@ -76,11 +76,32 @@ class Tk::PanedWindow<TkWindow
self
end
- def panecget(win, key)
+ def panecget_strict(win, key)
# win = win.epath if win.kind_of?(TkObject)
win = _epath(win)
tk_tcl2ruby(tk_send_without_enc('panecget', win, "-#{key}"))
end
+ def panecget(win, key)
+ unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
+ panecget_strict(win, key)
+ else
+ begin
+ panecget_strict(win, key)
+ rescue => e
+ begin
+ if current_paneconfiginfo(win).has_key?(option.to_s)
+ # not tag error & option is known -> error on known option
+ fail e
+ else
+ # not tag error & option is unknown
+ nil
+ end
+ rescue
+ fail e # tag error
+ end
+ end
+ end
+ end
def paneconfigure(win, key, value=nil)
# win = win.epath if win.kind_of?(TkObject)
diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb
index a4c63c70a3..4ec82bed1d 100644
--- a/ext/tk/lib/tk/text.rb
+++ b/ext/tk/lib/tk/text.rb
@@ -32,6 +32,9 @@ module TkTextTagConfig
def tag_cget(tagOrId, option)
itemcget(['tag', tagOrId], option)
end
+ def tag_cget_strict(tagOrId, option)
+ itemcget_strict(['tag', tagOrId], option)
+ end
def tag_configure(tagOrId, slot, value=None)
itemconfigure(['tag', tagOrId], slot, value)
end
@@ -45,6 +48,9 @@ module TkTextTagConfig
def window_cget(tagOrId, option)
itemcget(['window', tagOrId], option)
end
+ def window_cget_strict(tagOrId, option)
+ itemcget_strict(['window', tagOrId], option)
+ end
def window_configure(tagOrId, slot, value=None)
itemconfigure(['window', tagOrId], slot, value)
end
@@ -55,8 +61,8 @@ module TkTextTagConfig
current_itemconfiginfo(['window', tagOrId], slot)
end
- private :itemcget, :itemconfigure
- private :itemconfiginfo, :current_itemconfiginfo
+ private :itemcget, :itemcget_strict
+ private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
end
class Tk::Text<TkTextWin
@@ -403,7 +409,7 @@ class Tk::Text<TkTextWin
end
alias previous_mark mark_previous
- def image_cget(index, slot)
+ def image_cget_strict(index, slot)
case slot.to_s
when 'text', 'label', 'show', 'data', 'file'
_fromUTF8(tk_send_without_enc('image', 'cget',
@@ -415,6 +421,28 @@ class Tk::Text<TkTextWin
end
end
+ def image_cget(index, slot)
+ unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
+ image_cget_strict(index, slot)
+ else
+ begin
+ image_cget_strict(index, slot)
+ rescue => e
+ begin
+ if current_image_configinfo(index).has_key?(slot.to_s)
+ # not tag error & option is known -> error on known option
+ fail e
+ else
+ # not tag error & option is unknown
+ nil
+ end
+ rescue
+ fail e # tag error
+ end
+ end
+ end
+ end
+
def image_configure(index, slot, value=None)
if slot.kind_of?(Hash)
_fromUTF8(tk_send_without_enc('image', 'configure',
diff --git a/ext/tk/lib/tk/textimage.rb b/ext/tk/lib/tk/textimage.rb
index d4c973213d..fb306a9c17 100644
--- a/ext/tk/lib/tk/textimage.rb
+++ b/ext/tk/lib/tk/textimage.rb
@@ -52,6 +52,10 @@ class TkTextImage<TkObject
@t.image_cget(@index, slot)
end
+ def cget_strict(slot)
+ @t.image_cget_strict(@index, slot)
+ end
+
def configure(slot, value=None)
@t.image_configure(@index, slot, value)
self
diff --git a/ext/tk/lib/tk/texttag.rb b/ext/tk/lib/tk/texttag.rb
index 792d544fe7..b08d923ea1 100644
--- a/ext/tk/lib/tk/texttag.rb
+++ b/ext/tk/lib/tk/texttag.rb
@@ -132,6 +132,9 @@ class TkTextTag<TkObject
def cget(key)
@t.tag_cget @id, key
end
+ def cget_strict(key)
+ @t.tag_cget_strict @id, key
+ end
=begin
def cget(key)
case key.to_s
diff --git a/ext/tk/lib/tk/textwindow.rb b/ext/tk/lib/tk/textwindow.rb
index a577329358..004422e4f3 100644
--- a/ext/tk/lib/tk/textwindow.rb
+++ b/ext/tk/lib/tk/textwindow.rb
@@ -72,6 +72,9 @@ class TkTextWindow<TkObject
def cget(slot)
@t.window_cget(@index, slot)
end
+ def cget_strict(slot)
+ @t.window_cget_strict(@index, slot)
+ end
def configure(slot, value=None)
if slot.kind_of?(Hash)