diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 08:57:35 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-21 08:57:35 +0000 |
commit | 59a07a0690ea964aa1f6d2f250a9ef176cac49ab (patch) | |
tree | b75ba8b89ab8151fdcb14b9b358bb18c88afbc41 /ext/tk/lib | |
parent | d66a188c4a1aa269be94c5707df3aeff185dd076 (diff) | |
download | ruby-59a07a0690ea964aa1f6d2f250a9ef176cac49ab.tar.gz |
Ruby/Tk :: provisional support on Ruby-VM and Tcl/Tk8.5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
35 files changed, 753 insertions, 233 deletions
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index 78ed1aa6ee..7b25c22063 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -130,10 +130,10 @@ class MultiTkIp class << @@TK_CMD_TBL allow = [ - '__send__', '__id__', 'freeze', 'inspect', 'kind_of?', + '__send__', '__id__', 'freeze', 'inspect', 'kind_of?', 'object_id', '[]', '[]=', 'delete', 'each', 'has_key?' ] - instance_methods.each{|m| undef_method(m) unless allow.index(m)} + instance_methods.each{|m| undef_method(m) unless allow.index(m.to_s)} def kind_of?(klass) @tbl.kind_of?(klass) @@ -206,7 +206,7 @@ class MultiTkIp def initialize(ip, cmd) @ip = ip @cmd = cmd - freeze + self.freeze end attr_reader :ip, :cmd def inspect @@ -723,7 +723,30 @@ class MultiTkIp fail ArgumentError, "expecting a Hash object for the 2nd argument" end - @interp = TclTkIp.new(name, _keys2opts(keys)) + if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! + @interp = TclTkIp.new(name, _keys2opts(keys)) + else + @interp_thread = Thread.new{ + Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(keys)) + #sleep + interp.mainloop(true) + } + until @interp_thread[:interp] + Thread.pass + end + # INTERP_THREAD.run + @interp = @interp_thread[:interp] + + def self.mainloop(check_root = true) + begin + TclTkLib.set_eventloop_window_mode(true) + @interp_thread.value + ensure + TclTkLib.set_eventloop_window_mode(false) + end + end + end + @ip_name = nil @callback_status = [].taint @@ -868,7 +891,7 @@ class MultiTkIp ret = [] mtx = Mutex.new.lock @init_ip_env_queue.enq([mtx, ret, table, script]) - mtx.lock + # mtx.lock if ret[0].kind_of?(Exception) raise ret[0] else @@ -1206,7 +1229,20 @@ class MultiTkIp if safeip == nil # create master-ip - @interp = TclTkIp.new(name, _keys2opts(tk_opts)) + if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! + @interp = TclTkIp.new(name, _keys2opts(tk_opts)) + else + @interp_thread = Thread.new{ + Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts)) + #sleep + TclTkLib.mainloop(true) + } + until @interp_thread[:interp] + Thread.pass + end + # INTERP_THREAD.run + @interp = @interp_thread[:interp] + end @ip_name = nil if safe @@ -1221,6 +1257,7 @@ class MultiTkIp @safe_base = true @interp, @ip_name = master.__create_safe_slave_obj(safe_opts, name, tk_opts) + @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! if safe safe = master.safe_level if safe < master.safe_level @safe_level = [safe] @@ -1229,6 +1266,7 @@ class MultiTkIp end else @interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts) + @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! if safe safe = master.safe_level if safe < master.safe_level @safe_level = [safe] @@ -2338,6 +2376,11 @@ end class MultiTkIp def mainloop(check_root = true, restart_on_dead = true) raise SecurityError, "no permission to manipulate" unless self.manipulable? + + if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!! + return @interp_thread.value if @interp_thread + end + #return self if self.slave? #return self if self != @@DEFAULT_MASTER if self != @@DEFAULT_MASTER diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 32b5e20bc5..d079bb9ed9 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -1077,11 +1077,14 @@ module TkComm end end - module TkCore include TkComm extend TkComm + unless self.const_defined? :RUN_EVENTLOOP_ON_MAIN_THREAD + RUN_EVENTLOOP_ON_MAIN_THREAD = false + end + unless self.const_defined? :INTERP if self.const_defined? :IP_NAME name = IP_NAME.to_s @@ -1099,7 +1102,40 @@ module TkCore opts = '' end - INTERP = TclTkIp.new(name, opts) + if RUBY_VERSION < '1.9.0' || RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! + INTERP = TclTkIp.new(name, opts) + else + require 'thread' + INTERP_MUTEX = Mutex.new + INTERP_ROOT_CHECK = ConditionVariable.new + INTERP_THREAD = Thread.new{ + begin + Thread.current[:interp] = interp = TclTkIp.new(name, opts) + rescue => e + Thread.current[:interp] = e + raise e + end + Thread.current[:status] = nil + #sleep + + begin + Thread.current[:status] = TclTkLib.mainloop(true) + rescue Exception=>e + Thread.current[:status] = e + ensure + INTERP_MUTEX.synchronize{ INTERP_ROOT_CHECK.broadcast } + end + Thread.current[:status] = TclTkLib.mainloop(false) + } + + until INTERP_THREAD[:interp] + Thread.pass + end + # INTERP_THREAD.run + raise INTERP_THREAD[:interp] if INTERP_THREAD[:interp].kind_of? Exception + + INTERP = INTERP_THREAD[:interp] + end def INTERP.__getip self @@ -1554,7 +1590,28 @@ module TkCore end def mainloop(check_root = true) - TclTkLib.mainloop(check_root) + if RUBY_VERSION < '1.9.0' || + TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! + TclTkLib.mainloop(check_root) + else + begin + TclTkLib.set_eventloop_window_mode(true) + if check_root + INTERP_MUTEX.synchronize{ + INTERP_ROOT_CHECK.wait(INTERP_MUTEX) + status = INTERP_THREAD[:status] + if status + INTERP_THREAD[:status] = nil + raise status if status.kind_of?(Exception) + end + } + else + INTERP_THREAD.value + end + ensure + TclTkLib.set_eventloop_window_mode(false) + end + end end def mainloop_thread? @@ -1562,7 +1619,12 @@ module TkCore # nil : there is no mainloop # false : mainloop is running on the other thread # ( At then, it is dangerous to call Tk interpreter directly. ) - TclTkLib.mainloop_thread? + if RUBY_VERSION < '1.9.0' || + TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD ### !!!!!!!!!!! + TclTkLib.mainloop_thread? + else + Thread.current == INTERP_THREAD + end end def mainloop_exist? @@ -1798,7 +1860,6 @@ module TkCore end end - module Tk include TkCore extend Tk @@ -2405,34 +2466,101 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) end # estimate encoding - case $KCODE - when /^e/i # EUC - Tk.encoding = 'euc-jp' - Tk.encoding_system = 'euc-jp' - when /^s/i # SJIS - begin - if Tk.encoding_system == 'cp932' - Tk.encoding = 'cp932' - else + if RUBY_VERSION < '1.9.0' + case $KCODE + when /^e/i # EUC + Tk.encoding = 'euc-jp' + Tk.encoding_system = 'euc-jp' + when /^s/i # SJIS + begin + if Tk.encoding_system == 'cp932' + Tk.encoding = 'cp932' + else + Tk.encoding = 'shiftjis' + Tk.encoding_system = 'shiftjis' + end + rescue StandardError, NameError Tk.encoding = 'shiftjis' Tk.encoding_system = 'shiftjis' end - rescue StandardError, NameError - Tk.encoding = 'shiftjis' - Tk.encoding_system = 'shiftjis' - end - when /^u/i # UTF8 - Tk.encoding = 'utf-8' - Tk.encoding_system = 'utf-8' - else # NONE - if defined? DEFAULT_TK_ENCODING - Tk.encoding_system = DEFAULT_TK_ENCODING + when /^u/i # UTF8 + Tk.encoding = 'utf-8' + Tk.encoding_system = 'utf-8' + else # NONE + if defined? DEFAULT_TK_ENCODING + Tk.encoding_system = DEFAULT_TK_ENCODING + end + begin + Tk.encoding = Tk.encoding_system + rescue StandardError, NameError + Tk.encoding = 'utf-8' + Tk.encoding_system = 'utf-8' + end end - begin - Tk.encoding = Tk.encoding_system - rescue StandardError, NameError + else ######################### + $TK_ENCODING ||= Encoding.default_external.name + case $TK_ENCODING + when 'US_ASCII' + Tk.encoding = 'ascii' + Tk.encoding_system = 'ascii' + when 'BIG5' + Tk.encoding = 'big5' + Tk.encoding_system = 'big5' + when 'CP1251' + Tk.encoding = 'cp1251' + Tk.encoding_system = 'cp1251' + when 'EUC-JP' + Tk.encoding = 'euc-jp' + Tk.encoding_system = 'euc-jp' + when 'EUC-KR' + Tk.encoding = 'euc-kr' + Tk.encoding_system = 'euc-kr' + when 'EUC-TW', 'EUC-CN' + Tk.encoding = 'euc-cn' + Tk.encoding_system = 'euc-cn' + #when 'GB18030' + # Tk.encoding = 'gb12345' # ???????????? + # Tk.encoding_system = 'gb12345' # ???????????? + when 'ISO-2022-JP' + Tk.encoding = 'iso2022-jp' + Tk.encoding_system = 'iso2022-jp' + when /ISO-8859-(.*)/ + Tk.encoding = 'iso8859-' << $1 + Tk.encoding_system = 'iso8859-' << $1 + #when 'KOI8', 'KOI8-U' + # Tk.encoding = 'koi8-u' # ???????????? + # Tk.encoding_system = 'koi8-u' # ???????????? + when 'KOI8-R' + Tk.encoding = 'koi8-r' + Tk.encoding_system = 'koi8-r' + when 'Shift_JIS' + begin + if Tk.encoding_system == 'cp932' + Tk.encoding = 'cp932' + else + Tk.encoding = 'shiftjis' + Tk.encoding_system = 'shiftjis' + end + rescue StandardError, NameError + Tk.encoding = 'shiftjis' + Tk.encoding_system = 'shiftjis' + end + when 'UNICODE' + Tk.encoding = 'unicode' + Tk.encoding_system = 'unicode' + when 'UTF-8' Tk.encoding = 'utf-8' Tk.encoding_system = 'utf-8' + else ###### 'ASCII-8BIT' + if defined? DEFAULT_TK_ENCODING + Tk.encoding_system = DEFAULT_TK_ENCODING + end + begin + Tk.encoding = Tk.encoding_system + rescue StandardError, NameError + Tk.encoding = 'utf-8' + Tk.encoding_system = 'utf-8' + end end end @@ -4076,6 +4204,11 @@ class TkWindow<TkObject end private :create_self + def inspect + str = super + str[0..(str.index(' '))] << '@path=' << @path.inspect << '>' + end + def exist? TkWinfo.exist?(self) end @@ -4586,7 +4719,6 @@ class TkWindow<TkObject end end - # freeze core modules #TclTkLib.freeze #TclTkIp.freeze @@ -4598,7 +4730,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2007-01-26'.freeze + RELEASE_DATE = '2007-12-21'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/autoload.rb b/ext/tk/lib/tk/autoload.rb index 6b3773f4ea..ace0787fc2 100644 --- a/ext/tk/lib/tk/autoload.rb +++ b/ext/tk/lib/tk/autoload.rb @@ -1,9 +1,33 @@ # # autoload # +major, minor, type, type_name, patchlevel = TclTkLib.get_version + +###################################### +# depend on version of Tcl/Tk +if major > 8 || + (major == 8 && minor > 5) || + (major == 8 && minor == 5 && type >= TclTkLib::RELEASE_TYPE::BETA) + # Tcl/Tk 8.5 beta or later + autoload :Ttk, 'tkextlib/tile' + module Tk + autoload :Tile, 'tkextlib/tile' + end +end -####################### +###################################### # geometry manager +module Tk + autoload :Grid, 'tk/grid' + def Grid(*args); TkGrid.configure(*args); end + + autoload :Pack, 'tk/pack' + def Pack(*args); TkPack.configure(*args); end + + autoload :Place, 'tk/place' + def Place(*args); TkPlace.configure(*args); end +end + autoload :TkGrid, 'tk/grid' def TkGrid(*args); TkGrid.configure(*args); end @@ -14,183 +38,275 @@ autoload :TkPlace, 'tk/place' def TkPlace(*args); TkPlace.configure(*args); end -####################### -# others -autoload :TkBgError, 'tk/bgerror' +###################################### +# Ttk (Tile) support +require 'tk/ttk_selector' -autoload :TkBindTag, 'tk/bindtag' -autoload :TkBindTagAll, 'tk/bindtag' -autoload :TkDatabaseClass, 'tk/bindtag' -autoload :TkButton, 'tk/button' +###################################### +# classes on Tk module +module Tk + autoload :Button, 'tk/button' -autoload :TkConsole, 'tk/console' + autoload :Canvas, 'tk/canvas' -autoload :TkCanvas, 'tk/canvas' + autoload :CheckButton, 'tk/checkbutton' + autoload :Checkbutton, 'tk/checkbutton' -autoload :TkcTagAccess, 'tk/canvastag' -autoload :TkcTag, 'tk/canvastag' -autoload :TkcTagString, 'tk/canvastag' -autoload :TkcNamedTag, 'tk/canvastag' -autoload :TkcTagAll, 'tk/canvastag' -autoload :TkcTagCurrent, 'tk/canvastag' -autoload :TkcTagGroup, 'tk/canvastag' + autoload :Entry, 'tk/entry' -autoload :TkCheckButton, 'tk/checkbutton' -autoload :TkCheckbutton, 'tk/checkbutton' + autoload :Frame, 'tk/frame' -autoload :TkClipboard, 'tk/clipboard' + autoload :Label, 'tk/label' -autoload :TkComposite, 'tk/composite' + autoload :LabelFrame, 'tk/labelframe' + autoload :Labelframe, 'tk/labelframe' -autoload :TkConsole, 'tk/console' + autoload :Listbox, 'tk/listbox' -autoload :TkDialog, 'tk/dialog' -autoload :TkDialog2, 'tk/dialog' -autoload :TkDialogObj, 'tk/dialog' -autoload :TkWarning, 'tk/dialog' -autoload :TkWarning2, 'tk/dialog' -autoload :TkWarningObj, 'tk/dialog' + autoload :Menu, 'tk/menu' + autoload :MenuClone, 'tk/menu' + autoload :SystemMenu, 'tk/menu' + autoload :SysMenu_Help, 'tk/menu' + autoload :SysMenu_System, 'tk/menu' + autoload :SysMenu_Apple, 'tk/menu' + autoload :Menubutton, 'tk/menu' + autoload :OptionMenubutton, 'tk/menu' -autoload :TkEntry, 'tk/entry' + autoload :Message, 'tk/message' -autoload :TkEvent, 'tk/event' + autoload :PanedWindow, 'tk/panedwindow' + autoload :Panedwindow, 'tk/panedwindow' -autoload :TkFont, 'tk/font' -autoload :TkTreatTagFont, 'tk/font' + autoload :RadioButton, 'tk/radiobutton' + autoload :Radiobutton, 'tk/radiobutton' -autoload :TkFrame, 'tk/frame' + autoload :Root, 'tk/root' -autoload :TkImage, 'tk/image' -autoload :TkBitmapImage, 'tk/image' -autoload :TkPhotoImage, 'tk/image' + autoload :Scale, 'tk/scale' -autoload :TkItemConfigMethod, 'tk/itemconfig' + autoload :Scrollbar, 'tk/scrollbar' + autoload :XScrollbar, 'tk/scrollbar' + autoload :YScrollbar, 'tk/scrollbar' -autoload :TkTreatItemFont, 'tk/itemfont' + autoload :Spinbox, 'tk/spinbox' -autoload :TkKinput, 'tk/kinput' + autoload :Text, 'tk/text' -autoload :TkLabel, 'tk/label' + autoload :Toplevel, 'tk/toplevel' +end -autoload :TkLabelFrame, 'tk/labelframe' -autoload :TkLabelframe, 'tk/labelframe' -autoload :TkListbox, 'tk/listbox' +###################################### +# sub-module of Tk +module Tk + autoload :Clock, 'tk/clock' -autoload :TkMacResource, 'tk/macpkg' + autoload :OptionObj, 'tk/optionobj' -autoload :TkMenu, 'tk/menu' -autoload :TkMenuClone, 'tk/menu' -autoload :TkSystemMenu, 'tk/menu' -autoload :TkSysMenu_Help, 'tk/menu' -autoload :TkSysMenu_System, 'tk/menu' -autoload :TkSysMenu_Apple, 'tk/menu' -autoload :TkMenubutton, 'tk/menu' -autoload :TkOptionMenubutton, 'tk/menu' + autoload :X_Scrollable, 'tk/scrollable' + autoload :Y_Scrollable, 'tk/scrollable' + autoload :Scrollable, 'tk/scrollable' -autoload :TkMenubar, 'tk/menubar' + autoload :Wm, 'tk/wm' -autoload :TkMenuSpec, 'tk/menuspec' + autoload :MacResource, 'tk/macpkg' -autoload :TkMessage, 'tk/message' + autoload :WinDDE, 'tk/winpkg' + autoload :WinRegistry, 'tk/winpkg' -autoload :TkManageFocus, 'tk/mngfocus' + autoload :ValidateConfigure, 'tk/validation' + autoload :ItemValidateConfigure, 'tk/validation' -autoload :TkMsgCatalog, 'tk/msgcat' -autoload :TkMsgCat, 'tk/msgcat' + autoload :EncodedString, 'tk/encodedstr' + def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end -autoload :TkNamespace, 'tk/namespace' + autoload :BinaryString, 'tk/encodedstr' + def Tk.BinaryString(str); Tk::BinaryString.new(str); end -autoload :TkOptionDB, 'tk/optiondb' -autoload :TkOption, 'tk/optiondb' -autoload :TkResourceDB, 'tk/optiondb' + autoload :UTF8_String, 'tk/encodedstr' + def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end -autoload :TkPackage, 'tk/package' +end -autoload :TkPalette, 'tk/palette' +###################################### +# toplevel classes/modules +autoload_list = { + :TkBgError => 'tk/bgerror', -autoload :TkPanedWindow, 'tk/panedwindow' -autoload :TkPanedwindow, 'tk/panedwindow' + :TkBindTag => 'tk/bindtag', + :TkBindTagAll => 'tk/bindtag', + :TkDatabaseClass => 'tk/bindtag', -autoload :TkRadioButton, 'tk/radiobutton' -autoload :TkRadiobutton, 'tk/radiobutton' + :TkButton => 'tk/button', -autoload :TkRoot, 'tk/root' + :TkCanvas => 'tk/canvas', -autoload :TkScale, 'tk/scale' + :TkcItem => 'tk/canvas', + :TkcArc => 'tk/canvas', + :TkcBitmap => 'tk/canvas', + :TkcImage => 'tk/canvas', + :TkcLine => 'tk/canvas', + :TkcOval => 'tk/canvas', + :TkcPolygon => 'tk/canvas', + :TkcRectangle => 'tk/canvas', + :TkcText => 'tk/canvas', + :TkcWindow => 'tk/canvas', -autoload :TkScrollbar, 'tk/scrollbar' -autoload :TkXScrollbar, 'tk/scrollbar' -autoload :TkYScrollbar, 'tk/scrollbar' + :TkcTagAccess => 'tk/canvastag', + :TkcTag => 'tk/canvastag', + :TkcTagString => 'tk/canvastag', + :TkcNamedTag => 'tk/canvastag', + :TkcTagAll => 'tk/canvastag', + :TkcTagCurrent => 'tk/canvastag', + :TkcTagGroup => 'tk/canvastag', -autoload :TkScrollbox, 'tk/scrollbox' + :TkCheckButton => 'tk/checkbutton', + :TkCheckbutton => 'tk/checkbutton', -autoload :TkSelection, 'tk/selection' + :TkClipboard => 'tk/clipboard', -autoload :TkSpinbox, 'tk/spinbox' + :TkComposite => 'tk/composite', -autoload :TkTreatTagFont, 'tk/tagfont' + :TkConsole => 'tk/console', -autoload :TkText, 'tk/text' + :TkDialog => 'tk/dialog', + :TkDialog2 => 'tk/dialog', + :TkDialogObj => 'tk/dialog', + :TkWarning => 'tk/dialog', + :TkWarning2 => 'tk/dialog', + :TkWarningObj => 'tk/dialog', -autoload :TkTextImage, 'tk/textimage' + :TkEntry => 'tk/entry', -autoload :TkTextMark, 'tk/textmark' -autoload :TkTextNamedMark, 'tk/textmark' -autoload :TkTextMarkInsert, 'tk/textmark' -autoload :TkTextMarkCurrent, 'tk/textmark' -autoload :TkTextMarkAnchor, 'tk/textmark' + :TkEvent => 'tk/event', -autoload :TkTextTag, 'tk/texttag' -autoload :TkTextNamedTag, 'tk/texttag' -autoload :TkTextTagSel, 'tk/texttag' + :TkFont => 'tk/font', + :TkTreatTagFont => 'tk/font', -autoload :TkTextWindow, 'tk/textwindow' + :TkFrame => 'tk/frame', -autoload :TkAfter, 'tk/timer' -autoload :TkTimer, 'tk/timer' -autoload :TkRTTimer, 'tk/timer' + :TkImage => 'tk/image', + :TkBitmapImage => 'tk/image', + :TkPhotoImage => 'tk/image', -autoload :TkToplevel, 'tk/toplevel' + :TkItemConfigMethod => 'tk/itemconfig', -autoload :TkTextWin, 'tk/txtwin_abst' + :TkTreatItemFont => 'tk/itemfont', -autoload :TkValidation, 'tk/validation' + :TkKinput => 'tk/kinput', -autoload :TkVariable, 'tk/variable' -autoload :TkVarAccess, 'tk/variable' + :TkLabel => 'tk/label', -autoload :TkVirtualEvent, 'tk/virtevent' -autoload :TkNamedVirtualEvent,'tk/virtevent' + :TkLabelFrame => 'tk/labelframe', + :TkLabelframe => 'tk/labelframe', -autoload :TkWinfo, 'tk/winfo' + :TkListbox => 'tk/listbox', -autoload :TkWinDDE, 'tk/winpkg' -autoload :TkWinRegistry, 'tk/winpkg' + :TkMacResource => 'tk/macpkg', -autoload :TkXIM, 'tk/xim' + :TkMenu => 'tk/menu', + :TkMenuClone => 'tk/menu', + :TkSystemMenu => 'tk/menu', + :TkSysMenu_Help => 'tk/menu', + :TkSysMenu_System => 'tk/menu', + :TkSysMenu_Apple => 'tk/menu', + :TkMenubutton => 'tk/menu', + :TkOptionMenubutton => 'tk/menu', + :TkMenubar => 'tk/menubar', -####################### -# sub-module of Tk -module Tk - autoload :Clock, 'tk/clock' - autoload :OptionObj, 'tk/optionobj' - autoload :X_Scrollable, 'tk/scrollable' - autoload :Y_Scrollable, 'tk/scrollable' - autoload :Scrollable, 'tk/scrollable' - autoload :Wm, 'tk/wm' + :TkMenuSpec => 'tk/menuspec', - autoload :ValidateConfigure, 'tk/validation' - autoload :ItemValidateConfigure, 'tk/validation' + :TkMessage => 'tk/message', - autoload :EncodedString, 'tk/encodedstr' - def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end + :TkManageFocus => 'tk/mngfocus', - autoload :BinaryString, 'tk/encodedstr' - def Tk.BinaryString(str); Tk::BinaryString.new(str); end + :TkMsgCatalog => 'tk/msgcat', + :TkMsgCat => 'tk/msgcat', - autoload :UTF8_String, 'tk/encodedstr' - def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end -end + :TkNamespace => 'tk/namespace', + + :TkOptionDB => 'tk/optiondb', + :TkOption => 'tk/optiondb', + :TkResourceDB => 'tk/optiondb', + + :TkPackage => 'tk/package', + + :TkPalette => 'tk/palette', + + :TkPanedWindow => 'tk/panedwindow', + :TkPanedwindow => 'tk/panedwindow', + + :TkRadioButton => 'tk/radiobutton', + :TkRadiobutton => 'tk/radiobutton', + + :TkRoot => 'tk/root', + + :TkScale => 'tk/scale', + + :TkScrollbar => 'tk/scrollbar', + :TkXScrollbar => 'tk/scrollbar', + :TkYScrollbar => 'tk/scrollbar', + + :TkScrollbox => 'tk/scrollbox', + + :TkSelection => 'tk/selection', + + :TkSpinbox => 'tk/spinbox', + + :TkTreatTagFont => 'tk/tagfont', + + :TkText => 'tk/text', + + :TkTextImage => 'tk/textimage', + :TktImage => 'tk/textimage', + + :TkTextMark => 'tk/textmark', + :TkTextNamedMark => 'tk/textmark', + :TkTextMarkInsert => 'tk/textmark', + :TkTextMarkCurrent => 'tk/textmark', + :TkTextMarkAnchor => 'tk/textmark', + :TktMark => 'tk/textmark', + :TktNamedMark => 'tk/textmark', + :TktMarkInsert => 'tk/textmark', + :TktMarkCurrent => 'tk/textmark', + :TktMarkAnchor => 'tk/textmark', + + :TkTextTag => 'tk/texttag', + :TkTextNamedTag => 'tk/texttag', + :TkTextTagSel => 'tk/texttag', + :TktTag => 'tk/texttag', + :TktNamedTag => 'tk/texttag', + :TktTagSel => 'tk/texttag', + + :TkTextWindow => 'tk/textwindow', + :TktWindow => 'tk/textwindow', + + :TkAfter => 'tk/timer', + :TkTimer => 'tk/timer', + :TkRTTimer => 'tk/timer', + + :TkToplevel => 'tk/toplevel', + + :TkTextWin => 'tk/txtwin_abst', + + :TkValidation => 'tk/validation', + + :TkVariable => 'tk/variable', + :TkVarAccess => 'tk/variable', + + :TkVirtualEvent => 'tk/virtevent', + :TkNamedVirtualEvent => 'tk/virtevent', + + :TkWinfo => 'tk/winfo', + + :TkWinDDE => 'tk/winpkg', + :TkWinRegistry => 'tk/winpkg', + + :TkXIM => 'tk/xim', +} +autoload_list.each{|mod, lib| + #autoload mod, lib unless + autoload mod, lib unless (Object.const_defined? mod) && (autoload? mod) +} diff --git a/ext/tk/lib/tk/button.rb b/ext/tk/lib/tk/button.rb index 407a47c400..04454cc6f7 100644 --- a/ext/tk/lib/tk/button.rb +++ b/ext/tk/lib/tk/button.rb @@ -4,7 +4,7 @@ require 'tk' require 'tk/label' -class TkButton<TkLabel +class Tk::Button<TkLabel TkCommandNames = ['button'.freeze].freeze WidgetClassName = 'Button'.freeze WidgetClassNames[WidgetClassName] = self @@ -25,3 +25,5 @@ class TkButton<TkLabel self end end + +TkButton = Tk::Button unless Object.const_defined? :TkButton diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index c30fd79bb9..70cace3382 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -40,7 +40,7 @@ module TkCanvasItemConfig private :__item_pathname end -class TkCanvas<TkWindow +class Tk::Canvas<TkWindow include TkCanvasItemConfig include Tk::Scrollable @@ -573,6 +573,9 @@ class TkCanvas<TkWindow end end +TkCanvas = Tk::Canvas unless Object.const_defined? :TkCanvas + + class TkcItem<TkObject extend Tk include TkcTagAccess diff --git a/ext/tk/lib/tk/checkbutton.rb b/ext/tk/lib/tk/checkbutton.rb index d76d99c0f2..40d502ebf7 100644 --- a/ext/tk/lib/tk/checkbutton.rb +++ b/ext/tk/lib/tk/checkbutton.rb @@ -4,7 +4,7 @@ require 'tk' require 'tk/radiobutton' -class TkCheckButton<TkRadioButton +class Tk::CheckButton<TkRadioButton TkCommandNames = ['checkbutton'.freeze].freeze WidgetClassName = 'Checkbutton'.freeze WidgetClassNames[WidgetClassName] = self @@ -22,4 +22,7 @@ class TkCheckButton<TkRadioButton self end end -TkCheckbutton = TkCheckButton + +Tk::Checkbutton = Tk::CheckButton +TkCheckButton = Tk::CheckButton unless Object.const_defined? :TkCheckButton +TkCheckbutton = Tk::Checkbutton unless Object.const_defined? :TkCheckbutton diff --git a/ext/tk/lib/tk/composite.rb b/ext/tk/lib/tk/composite.rb index eaed8ed363..d3dad4d268 100644 --- a/ext/tk/lib/tk/composite.rb +++ b/ext/tk/lib/tk/composite.rb @@ -133,6 +133,11 @@ module TkComposite def initialize_composite(*args) end private :initialize_composite + def inspect + str = super + str.chop << ' @epath=' << @epath.inspect << '>' + end + def option_methods(*opts) opts.each{|m_set, m_cget, m_info| m_set = m_set.to_s diff --git a/ext/tk/lib/tk/entry.rb b/ext/tk/lib/tk/entry.rb index 4ac3f28229..2b55a0cafb 100644 --- a/ext/tk/lib/tk/entry.rb +++ b/ext/tk/lib/tk/entry.rb @@ -8,7 +8,7 @@ require 'tk/label' require 'tk/scrollable' require 'tk/validation' -class TkEntry<TkLabel +class Tk::Entry<TkLabel include X_Scrollable include TkValidation @@ -115,3 +115,5 @@ class TkEntry<TkLabel val end end + +TkEntry = Tk::Entry unless Object.const_defined? :TkEntry diff --git a/ext/tk/lib/tk/frame.rb b/ext/tk/lib/tk/frame.rb index 6636fef5b5..471bb3cd00 100644 --- a/ext/tk/lib/tk/frame.rb +++ b/ext/tk/lib/tk/frame.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkFrame<TkWindow +class Tk::Frame<TkWindow TkCommandNames = ['frame'.freeze].freeze WidgetClassName = 'Frame'.freeze WidgetClassNames[WidgetClassName] = self @@ -126,3 +126,5 @@ class TkFrame<TkWindow end end end + +TkFrame = Tk::Frame unless Object.const_defined? :TkFrame diff --git a/ext/tk/lib/tk/label.rb b/ext/tk/lib/tk/label.rb index 8b45db9b30..9904953e81 100644 --- a/ext/tk/lib/tk/label.rb +++ b/ext/tk/lib/tk/label.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkLabel<TkWindow +class Tk::Label<TkWindow TkCommandNames = ['label'.freeze].freeze WidgetClassName = 'Label'.freeze WidgetClassNames[WidgetClassName] = self @@ -16,3 +16,5 @@ class TkLabel<TkWindow #end #private :create_self end + +TkLabel = Tk::Label unless Object.const_defined? :TkLabel diff --git a/ext/tk/lib/tk/labelframe.rb b/ext/tk/lib/tk/labelframe.rb index 73d5603200..e1712889ce 100644 --- a/ext/tk/lib/tk/labelframe.rb +++ b/ext/tk/lib/tk/labelframe.rb @@ -4,7 +4,7 @@ require 'tk' require 'tk/frame' -class TkLabelFrame<TkFrame +class Tk::LabelFrame<TkFrame TkCommandNames = ['labelframe'.freeze].freeze WidgetClassName = 'Labelframe'.freeze WidgetClassNames[WidgetClassName] = self @@ -22,4 +22,7 @@ class TkLabelFrame<TkFrame end private :__val2ruby_optkeys end -TkLabelframe = TkLabelFrame + +Tk::Labelframe = TkLabelFrame +TkLabelFrame = Tk::LabelFrame unless Object.const_defined? :TkLabelFrame +TkLabelframe = Tk::Labelframe unless Object.const_defined? :TkLabelframe diff --git a/ext/tk/lib/tk/listbox.rb b/ext/tk/lib/tk/listbox.rb index 41d02d279e..1937fd22ef 100644 --- a/ext/tk/lib/tk/listbox.rb +++ b/ext/tk/lib/tk/listbox.rb @@ -15,7 +15,7 @@ module TkListItemConfig private :__item_listval_optkeys end -class TkListbox<TkTextWin +class Tk::Listbox<TkTextWin include TkListItemConfig include Scrollable @@ -277,3 +277,5 @@ class TkListbox<TkTextWin end =end end + +TkListbox = Tk::Listbox unless Object.const_defined? :TkListbox diff --git a/ext/tk/lib/tk/macpkg.rb b/ext/tk/lib/tk/macpkg.rb index 1802073f46..3975c5255c 100644 --- a/ext/tk/lib/tk/macpkg.rb +++ b/ext/tk/lib/tk/macpkg.rb @@ -20,9 +20,13 @@ module Tk end end -module TkMacResource +module Tk::MacResource +end +TkMacResource = Tk::MacResource + +module Tk::MacResource extend Tk - extend TkMacResource + extend Tk::MacResource TkCommandNames = ['resource'.freeze].freeze diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index ddddc8e53e..1a6c1bd06a 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -42,7 +42,7 @@ module TkMenuEntryConfig private :itemconfiginfo, :current_itemconfiginfo end -class TkMenu<TkWindow +class Tk::Menu<TkWindow include Wm include TkMenuEntryConfig extend TkMenuSpec @@ -381,8 +381,10 @@ class TkMenu<TkWindow =end end +TkMenu = Tk::Menu unless Object.const_defined? :TkMenu -class TkMenuClone<TkMenu + +class Tk::MenuClone<TkMenu =begin def initialize(parent, type=None) widgetname = nil @@ -436,7 +438,9 @@ class TkMenuClone<TkMenu @src_menu end end -TkCloneMenu = TkMenuClone +Tk::CloneMenu = Tk::MenuClone +TkMenuClone = Tk::MenuClone unless Object.const_defined? :TkMenuClone +TkCloneMenu = Tk::CloneMenu unless Object.const_defined? :TkCloneMenu module TkSystemMenu def initialize(parent, keys=nil) @@ -463,28 +467,31 @@ module TkSystemMenu end -class TkSysMenu_Help<TkMenu +class Tk::SysMenu_Help<TkMenu # for all platform include TkSystemMenu SYSMENU_NAME = 'help' end +TkSysMenu_Help = Tk::SysMenu_Help unless Object.const_defined? :TkSysMenu_Help -class TkSysMenu_System<TkMenu +class Tk::SysMenu_System<TkMenu # for Windows include TkSystemMenu SYSMENU_NAME = 'system' end +TkSysMenu_System = Tk::SysMenu_System unless Object.const_defined? :TkSysMenu_System -class TkSysMenu_Apple<TkMenu +class Tk::SysMenu_Apple<TkMenu # for Machintosh include TkSystemMenu SYSMENU_NAME = 'apple' end +TkSysMenu_Apple = Tk::SysMenu_Apple unless Object.const_defined? :TkSysMenu_Apple -class TkMenubutton<TkLabel +class Tk::Menubutton<TkLabel TkCommandNames = ['menubutton'.freeze].freeze WidgetClassName = 'Menubutton'.freeze WidgetClassNames[WidgetClassName] = self @@ -506,10 +513,12 @@ class TkMenubutton<TkLabel private :__boolval_optkeys end -TkMenuButton = TkMenubutton +Tk::MenuButton = Tk::Menubutton +TkMenubutton = Tk::Menubutton unless Object.const_defined? :TkMenubutton +TkMenuButton = Tk::MenuButton unless Object.const_defined? :TkMenuButton -class TkOptionMenubutton<TkMenubutton +class Tk::OptionMenubutton<TkMenubutton TkCommandNames = ['tk_optionMenu'.freeze].freeze class OptionMenu<TkMenu @@ -629,4 +638,7 @@ class TkOptionMenubutton<TkMenubutton @menu.current_entryconfiginfo(index, key) end end -TkOptionMenuButton = TkOptionMenubutton + +Tk::OptionMenuButton = Tk::OptionMenubutton +TkOptionMenubutton = Tk::OptionMenubutton unless Object.const_defined? :TkOptionMenubutton +TkOptionMenuButton = Tk::OptionMenuButton unless Object.const_defined? :TkOptionMenuButton diff --git a/ext/tk/lib/tk/message.rb b/ext/tk/lib/tk/message.rb index 79121bebb3..e91e057a00 100644 --- a/ext/tk/lib/tk/message.rb +++ b/ext/tk/lib/tk/message.rb @@ -4,7 +4,7 @@ require 'tk' require 'tk/label' -class TkMessage<TkLabel +class Tk::Message<TkLabel TkCommandNames = ['message'.freeze].freeze WidgetClassName = 'Message'.freeze WidgetClassNames[WidgetClassName] = self @@ -17,3 +17,5 @@ class TkMessage<TkLabel #end private :create_self end + +TkMessage = Tk::Message unless Object.const_defined? :TkMessage diff --git a/ext/tk/lib/tk/package.rb b/ext/tk/lib/tk/package.rb index d1eb27674d..0c329732f5 100644 --- a/ext/tk/lib/tk/package.rb +++ b/ext/tk/lib/tk/package.rb @@ -136,4 +136,8 @@ module TkPackage def vsatisfies(version1, version2) bool(tk_call('package', 'vsatisfies', version1, version2)) end + + def prefer(setting = None) + tk_call('package', 'prefer', setting) + end end diff --git a/ext/tk/lib/tk/panedwindow.rb b/ext/tk/lib/tk/panedwindow.rb index c6cf3cd11f..7e818fc928 100644 --- a/ext/tk/lib/tk/panedwindow.rb +++ b/ext/tk/lib/tk/panedwindow.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkPanedWindow<TkWindow +class Tk::PanedWindow<TkWindow TkCommandNames = ['panedwindow'.freeze].freeze WidgetClassName = 'Panedwindow'.freeze WidgetClassNames[WidgetClassName] = self @@ -229,4 +229,7 @@ class TkPanedWindow<TkWindow list(tk_send_without_enc('panes')) end end -TkPanedwindow = TkPanedWindow + +Tk::Panedwindow = Tk::PanedWindow +TkPanedWindow = Tk::PanedWindow unless Object.const_defined? :TkPanedWindow +TkPanedwindow = Tk::Panedwindow unless Object.const_defined? :TkPanedwindow diff --git a/ext/tk/lib/tk/radiobutton.rb b/ext/tk/lib/tk/radiobutton.rb index f8f67d709a..15b29ccd26 100644 --- a/ext/tk/lib/tk/radiobutton.rb +++ b/ext/tk/lib/tk/radiobutton.rb @@ -4,7 +4,7 @@ require 'tk' require 'tk/button' -class TkRadioButton<TkButton +class Tk::RadioButton<TkButton TkCommandNames = ['radiobutton'.freeze].freeze WidgetClassName = 'Radiobutton'.freeze WidgetClassNames[WidgetClassName] = self @@ -63,4 +63,7 @@ class TkRadioButton<TkButton end end end -TkRadiobutton = TkRadioButton + +Tk::Radiobutton = Tk::RadioButton +TkRadioButton = Tk::RadioButton unless Object.const_defined? :TkRadioButton +TkRadiobutton = Tk::Radiobutton unless Object.const_defined? :TkRadiobutton diff --git a/ext/tk/lib/tk/root.rb b/ext/tk/lib/tk/root.rb index 0e5584c7c1..a66c9fe454 100644 --- a/ext/tk/lib/tk/root.rb +++ b/ext/tk/lib/tk/root.rb @@ -5,7 +5,7 @@ require 'tk' require 'tk/wm' require 'tk/menuspec' -class TkRoot<TkWindow +class Tk::Root<TkWindow include Wm include TkMenuSpec @@ -106,3 +106,5 @@ class TkRoot<TkWindow TkCore::INTERP._invoke('destroy', '.') end end + +TkRoot = Tk::Root unless Object.const_defined? :TkRoot diff --git a/ext/tk/lib/tk/scale.rb b/ext/tk/lib/tk/scale.rb index 0b703aa055..d9e88080cf 100644 --- a/ext/tk/lib/tk/scale.rb +++ b/ext/tk/lib/tk/scale.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkScale<TkWindow +class Tk::Scale<TkWindow TkCommandNames = ['scale'.freeze].freeze WidgetClassName = 'Scale'.freeze WidgetClassNames[WidgetClassName] = self @@ -84,3 +84,5 @@ class TkScale<TkWindow val end end + +TkScale = Tk::Scale unless Object.const_defined? :TkScale diff --git a/ext/tk/lib/tk/scrollbar.rb b/ext/tk/lib/tk/scrollbar.rb index 70aadfdd4c..dda7a96d87 100644 --- a/ext/tk/lib/tk/scrollbar.rb +++ b/ext/tk/lib/tk/scrollbar.rb @@ -3,7 +3,7 @@ # require 'tk' -class TkScrollbar<TkWindow +class Tk::Scrollbar<TkWindow TkCommandNames = ['scrollbar'.freeze].freeze WidgetClassName = 'Scrollbar'.freeze WidgetClassNames[WidgetClassName] = self @@ -105,7 +105,10 @@ class TkScrollbar<TkWindow end end -class TkXScrollbar<TkScrollbar +TkScrollbar = Tk::Scrollbar unless Object.const_defined? :TkScrollbar + + +class Tk::XScrollbar<TkScrollbar def create_self(keys) keys = {} unless keys keys['orient'] = 'horizontal' @@ -114,7 +117,10 @@ class TkXScrollbar<TkScrollbar private :create_self end -class TkYScrollbar<TkScrollbar +TkXScrollbar = Tk::XScrollbar unless Object.const_defined? :TkXScrollbar + + +class Tk::YScrollbar<TkScrollbar def create_self(keys) keys = {} unless keys keys['orient'] = 'vertical' @@ -122,3 +128,5 @@ class TkYScrollbar<TkScrollbar end private :create_self end + +TkYScrollbar = Tk::YScrollbar unless Object.const_defined? :TkYScrollbar diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb index 9a10977d12..157efcc2a3 100644 --- a/ext/tk/lib/tk/spinbox.rb +++ b/ext/tk/lib/tk/spinbox.rb @@ -6,7 +6,7 @@ require 'tk' require 'tk/entry' -class TkSpinbox<TkEntry +class Tk::Spinbox<TkEntry TkCommandNames = ['spinbox'.freeze].freeze WidgetClassName = 'Spinbox'.freeze WidgetClassNames[WidgetClassName] = self @@ -97,3 +97,5 @@ class TkSpinbox<TkEntry _fromUTF8(tk_send_without_enc('set', _get_eval_enc_str(str))) end end + +TkSpinbox = Tk::Spinbox unless Object.const_defined? :TkSpinbox diff --git a/ext/tk/lib/tk/text.rb b/ext/tk/lib/tk/text.rb index 49d4b5625b..352d0903f4 100644 --- a/ext/tk/lib/tk/text.rb +++ b/ext/tk/lib/tk/text.rb @@ -60,7 +60,7 @@ module TkTextTagConfig private :itemconfiginfo, :current_itemconfiginfo end -class TkText<TkTextWin +class Tk::Text<TkTextWin ItemConfCMD = ['tag'.freeze, 'configure'.freeze].freeze #include TkTreatTextTagFont include TkTextTagConfig @@ -1183,6 +1183,11 @@ class TkText<TkTextWin end def _ktext_length(txt) + if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!! + return txt.length + end + ########################### + if $KCODE !~ /n/i return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length end @@ -1527,6 +1532,9 @@ class TkText<TkTextWin end end +TkText = Tk::Text unless Object.const_defined? :TkText + + ####################################### class TkText::Peer < TkText diff --git a/ext/tk/lib/tk/textimage.rb b/ext/tk/lib/tk/textimage.rb index a29b23c7dd..ea2b7c6a36 100644 --- a/ext/tk/lib/tk/textimage.rb +++ b/ext/tk/lib/tk/textimage.rb @@ -80,3 +80,5 @@ class TkTextImage<TkObject value end end + +TktImage = TkTextImage diff --git a/ext/tk/lib/tk/textmark.rb b/ext/tk/lib/tk/textmark.rb index 650d95af70..9f7ad751e5 100644 --- a/ext/tk/lib/tk/textmark.rb +++ b/ext/tk/lib/tk/textmark.rb @@ -121,6 +121,7 @@ class TkTextMark<TkObject end end end +TktMark = TkTextMark class TkTextNamedMark<TkTextMark def self.new(parent, name, *args) @@ -146,21 +147,25 @@ class TkTextNamedMark<TkTextMark @t._addtag id, self end end +TktNamedMark = TkTextNamedMark class TkTextMarkInsert<TkTextNamedMark def self.new(parent,*args) super(parent, 'insert', *args) end end +TktMarkInsert = TkTextMarkInsert class TkTextMarkCurrent<TkTextNamedMark def self.new(parent,*args) super(parent, 'current', *args) end end +TktMarkCurrent = TkTextMarkCurrent class TkTextMarkAnchor<TkTextNamedMark def self.new(parent,*args) super(parent, 'anchor', *args) end end +TktMarkAnchor = TkTextMarkAnchor diff --git a/ext/tk/lib/tk/texttag.rb b/ext/tk/lib/tk/texttag.rb index cc2c56210f..731e6bebd6 100644 --- a/ext/tk/lib/tk/texttag.rb +++ b/ext/tk/lib/tk/texttag.rb @@ -225,6 +225,7 @@ class TkTextTag<TkObject self end end +TktTag = TkTextTag class TkTextNamedTag<TkTextTag def self.new(parent, name, *args) @@ -271,9 +272,11 @@ class TkTextNamedTag<TkTextTag @t._addtag id, self end end +TktNamedTag = TkTextNamedTag class TkTextTagSel<TkTextNamedTag def self.new(parent, *args) super(parent, 'sel', *args) end end +TktTagSel = TkTextTagSel diff --git a/ext/tk/lib/tk/textwindow.rb b/ext/tk/lib/tk/textwindow.rb index 605c40addd..6735f2585a 100644 --- a/ext/tk/lib/tk/textwindow.rb +++ b/ext/tk/lib/tk/textwindow.rb @@ -147,3 +147,5 @@ class TkTextWindow<TkObject value end end + +TktWindow = TkTextWindow diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index 5e199e1330..87229aaba9 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -5,7 +5,7 @@ require 'tk' require 'tk/wm' require 'tk/menuspec' -class TkToplevel<TkWindow +class Tk::Toplevel<TkWindow include Wm include TkMenuSpec @@ -117,9 +117,10 @@ class TkToplevel<TkWindow end if @classname.kind_of? TkBindTag @db_class = @classname - @classname = @classname.id + keys['class'] = @classname = @classname.id elsif @classname @db_class = TkDatabaseClass.new(@classname) + keys['class'] = @classname else @db_class = self.class @classname = @db_class::WidgetClassName @@ -165,9 +166,10 @@ class TkToplevel<TkWindow end if @classname.kind_of? TkBindTag @db_class = @classname - @classname = @classname.id + keys['class'] = @classname = @classname.id elsif @classname @db_class = TkDatabaseClass.new(@classname) + keys['class'] = @classname else @db_class = self.class @classname = @db_class::WidgetClassName @@ -255,3 +257,5 @@ class TkToplevel<TkWindow end end end + +TkToplevel = Tk::Toplevel unless Object.const_defined? :TkToplevel diff --git a/ext/tk/lib/tk/ttk_selector.rb b/ext/tk/lib/tk/ttk_selector.rb new file mode 100644 index 0000000000..8960da95a2 --- /dev/null +++ b/ext/tk/lib/tk/ttk_selector.rb @@ -0,0 +1,55 @@ +# +# ttk_selector +# +module Ttk_Selector + @TTK_CLASS_NAMES = {} + + def self.use_ttk_as_default(mode = true) + if mode # Use Ttk widgets + @TTK_CLASS_NAMES.each{|name, status| + eval("::Tk#{name} = ::Tk::#{(status)? 'Tile::': '::'}#{name}", + TOPLEVEL_BINDING) + } + else # Use standard Tk widagets + @TTK_CLASS_NAMES.each{|name, status| + eval("::Tk#{name} = ::Tk::#{name}", TOPLEVEL_BINDING) + } + end + end + + def self.add(name) + @TTK_CLASS_NAMES[name] = true + end + + def self.remove(name) + @TTK_CLASS_NAMES[name] = false + end +end + +#-------------------------------------------------------------------- + +Ttk_Selector.add('Button') +Ttk_Selector.add('Checkbutton') +Ttk_Selector.add('Entry') +##(ttk only) Ttk_Selector.add('Combobox') +##(ttk only) Ttk_Selector.add('Dialog') +Ttk_Selector.add('Frame') +Ttk_Selector.add('Label') +Ttk_Selector.add('Labelframe') +##(std only) Ttk_Selector.add('Listbox') +Ttk_Selector.add('Menubutton') +##(ttk only) Ttk_Selector.add('Notebook') +Ttk_Selector.add('Panedwindow') +##(ttk only) Ttk_Selector.add('Progressbar') +Ttk_Selector.add('Radiobutton') +Ttk_Selector.add('Scale') +##(ttk only) Ttk_Selector.add('Progress') +Ttk_Selector.add('Scrollbar') +Ttk_Selector.add('XScrollbar') +Ttk_Selector.add('YScrollbar') +##(ttk only) Ttk_Selector.add('Separator') +##(ttk only) Ttk_Selector.add('SizeGrip') +##(ttk only) Ttk_Selector.add('Square') +##(ttk only) Ttk_Selector.add('Treeview') + +#-------------------------------------------------------------------- diff --git a/ext/tk/lib/tk/winpkg.rb b/ext/tk/lib/tk/winpkg.rb index 737fb959b5..6c168da01b 100644 --- a/ext/tk/lib/tk/winpkg.rb +++ b/ext/tk/lib/tk/winpkg.rb @@ -7,9 +7,13 @@ # require 'tk' -module TkWinDDE +module Tk::WinDDE +end +TkWinDDE = Tk::WinDDE + +module Tk::WinDDE extend Tk - extend TkWinDDE + extend Tk::WinDDE TkCommandNames = ['dde'.freeze].freeze @@ -85,9 +89,13 @@ module TkWinDDE :poke, :request, :services, :eval end -module TkWinRegistry +module Tk::WinRegistry +end +TkWinRegistry = Tk::WinRegistry + +module Tk::WinRegistry extend Tk - extend TkWinRegistry + extend Tk::WinRegistry TkCommandNames = ['registry'.freeze].freeze diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb index fdafc8dc7f..12fc453e26 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb @@ -322,6 +322,11 @@ class Tk::Iwidgets::Scrolledtext def _ktext_length(txt) + if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!!! + return txt.length + end + ########################### + if $KCODE !~ /n/i return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length end diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb index acc7bebe4e..7ed33b03e8 100644 --- a/ext/tk/lib/tkextlib/tile.rb +++ b/ext/tk/lib/tkextlib/tile.rb @@ -15,33 +15,69 @@ require 'tkextlib/tile/setup.rb' # TkPackage.require('tile', '0.4') # TkPackage.require('tile', '0.6') # TkPackage.require('tile', '0.7') -verstr = TkPackage.require('tile') +if Tk::TK_MAJOR_VERSION > 8 || + (Tk::TK_MAJOR_VERSION == 8 && Tk::TK_MINOR_VERSION >= 5) + begin + verstr = TkPackage.require('Ttk') + rescue RuntimeError + verstr = TkPackage.require('tile') + end +else + verstr = TkPackage.require('tile') +end + ver = verstr.split('.') -if ver[0].to_i == 0 && ver[1].to_i <= 4 - # version 0.4 or former - module Tk - module Tile - USE_TILE_NAMESPACE = true - USE_TTK_NAMESPACE = false - TILE_SPEC_VERSION_ID = 0 +if ver[0].to_i == 0 + # Tile extension package + if ver[1].to_i <= 4 + # version 0.4 or former + module Tk + module Tile + USE_TILE_NAMESPACE = true + USE_TTK_NAMESPACE = false + TILE_SPEC_VERSION_ID = 0 + end end - end -elsif ver[0].to_i == 0 && ver[1].to_i <= 6 - # version 0.5 -- version 0.6 - module Tk - module Tile - USE_TILE_NAMESPACE = true - USE_TTK_NAMESPACE = true - TILE_SPEC_VERSION_ID = 5 + elsif ver[1].to_i <= 6 + # version 0.5 -- version 0.6 + module Tk + module Tile + USE_TILE_NAMESPACE = true + USE_TTK_NAMESPACE = true + TILE_SPEC_VERSION_ID = 5 + end + end + elsif ver[1].to_i <= 7 + module Tk + module Tile + USE_TILE_NAMESPACE = false + USE_TTK_NAMESPACE = true + TILE_SPEC_VERSION_ID = 7 + end + end + else + # version 0.8 or later + module Tk + module Tile + USE_TILE_NAMESPACE = false + USE_TTK_NAMESPACE = true + TILE_SPEC_VERSION_ID = 8 + end end end + + module Tk::Tile + PACKAGE_NAME = 'tile'.freeze + end else - # version 0.7 or later + # Ttk package merged Tcl/Tk core (Tcl/Tk 8.5+) module Tk module Tile USE_TILE_NAMESPACE = false USE_TTK_NAMESPACE = true - TILE_SPEC_VERSION_ID = 7 + TILE_SPEC_VERSION_ID = 8 + + PACKAGE_NAME = 'Ttk'.freeze end end end @@ -51,14 +87,13 @@ module Tk module Tile TkComm::TkExtlibAutoloadModule.unshift(self) - PACKAGE_NAME = 'tile'.freeze def self.package_name PACKAGE_NAME end def self.package_version begin - TkPackage.require('tile') + TkPackage.require(PACKAGE_NAME) rescue '' end @@ -200,6 +235,8 @@ module Tk autoload :TPaned, 'tkextlib/tile/tpaned' autoload :Paned, 'tkextlib/tile/tpaned' + autoload :PanedWindow, 'tkextlib/tile/tpaned' + autoload :Panedwindow, 'tkextlib/tile/tpaned' autoload :TProgressbar, 'tkextlib/tile/tprogressbar' autoload :Progressbar, 'tkextlib/tile/tprogressbar' @@ -216,6 +253,8 @@ module Tk autoload :TScrollbar, 'tkextlib/tile/tscrollbar' autoload :Scrollbar, 'tkextlib/tile/tscrollbar' + autoload :XScrollbar, 'tkextlib/tile/tscrollbar' + autoload :YScrollbar, 'tkextlib/tile/tscrollbar' autoload :TSeparator, 'tkextlib/tile/tseparator' autoload :Separator, 'tkextlib/tile/tseparator' @@ -228,3 +267,5 @@ module Tk autoload :Style, 'tkextlib/tile/style' end end + +Ttk = Tk::Tile diff --git a/ext/tk/lib/tkextlib/tile/style.rb b/ext/tk/lib/tkextlib/tile/style.rb index 59bc4b0d78..b319d24d54 100644 --- a/ext/tk/lib/tkextlib/tile/style.rb +++ b/ext/tk/lib/tkextlib/tile/style.rb @@ -17,6 +17,12 @@ module Tk::Tile::Style end class << Tk::Tile::Style + if Tk::Tile::TILE_SPEC_VERSION_ID < 8 + TkCommandNames = ['style'.freeze].freeze + else + TkCommandNames = ['::ttk::style'.freeze].freeze + end + def configure(style=nil, keys=nil) if style.kind_of?(Hash) keys = style @@ -31,9 +37,9 @@ class << Tk::Tile::Style end if keys && keys != None - tk_call('style', sub_cmd, style, *hash_kv(keys)) + tk_call(TkCommandNames[0], sub_cmd, style, *hash_kv(keys)) else - tk_call('style', sub_cmd, style) + tk_call(TkCommandNames[0], sub_cmd, style) end end alias default configure @@ -46,14 +52,15 @@ class << Tk::Tile::Style style = '.' unless style if keys && keys != None - tk_call('style', 'map', style, *hash_kv(keys)) + tk_call(TkCommandNames[0], 'map', style, *hash_kv(keys)) else - tk_call('style', 'map', style) + tk_call(TkCommandNames[0], 'map', style) end end def lookup(style, opt, state=None, fallback_value=None) - tk_call('style', 'lookup', style, '-' << opt.to_s, state, fallback_value) + tk_call(TkCommandNames[0], 'lookup', style, + '-' << opt.to_s, state, fallback_value) end include Tk::Tile::ParseStyleLayout @@ -66,42 +73,42 @@ class << Tk::Tile::Style style = '.' unless style if spec - tk_call('style', 'layout', style, spec) + tk_call(TkCommandNames[0], 'layout', style, spec) else - _style_layout(list(tk_call('style', 'layout', style))) + _style_layout(list(tk_call(TkCommandNames[0], 'layout', style))) end end def element_create(name, type, *args) - tk_call('style', 'element', 'create', name, type, *args) + tk_call(TkCommandNames[0], 'element', 'create', name, type, *args) end def element_names() - list(tk_call('style', 'element', 'names')) + list(tk_call(TkCommandNames[0], 'element', 'names')) end def element_options(elem) - simplelist(tk_call('style', 'element', 'options', elem)) + simplelist(tk_call(TkCommandNames[0], 'element', 'options', elem)) end def theme_create(name, keys=nil) if keys && keys != None - tk_call('style', 'theme', 'create', name, *hash_kv(keys)) + tk_call(TkCommandNames[0], 'theme', 'create', name, *hash_kv(keys)) else - tk_call('style', 'theme', 'create', name) + tk_call(TkCommandNames[0], 'theme', 'create', name) end end def theme_settings(name, cmd=nil, &b) cmd = Proc.new(&b) if !cmd && b - tk_call('style', 'theme', 'settings', name, cmd) + tk_call(TkCommandNames[0], 'theme', 'settings', name, cmd) end def theme_names() - list(tk_call('style', 'theme', 'names')) + list(tk_call(TkCommandNames[0], 'theme', 'names')) end def theme_use(name) - tk_call('style', 'theme', 'use', name) + tk_call(TkCommandNames[0], 'theme', 'use', name) end end diff --git a/ext/tk/lib/tkextlib/tile/tpaned.rb b/ext/tk/lib/tkextlib/tile/tpaned.rb index 11178b19d3..2a2a25ea59 100644 --- a/ext/tk/lib/tkextlib/tile/tpaned.rb +++ b/ext/tk/lib/tkextlib/tile/tpaned.rb @@ -9,7 +9,7 @@ module Tk module Tile class TPaned < TkWindow end - Paned = TPaned + PanedWindow = Panedwindow = Paned = TPaned end end @@ -17,7 +17,11 @@ class Tk::Tile::TPaned < TkWindow include Tk::Tile::TileWidget if Tk::Tile::USE_TTK_NAMESPACE - TkCommandNames = ['::ttk::paned'.freeze].freeze + if Tk::Tile::TILE_SPEC_VERSION_ID < 8 + TkCommandNames = ['::ttk::paned'.freeze].freeze + else + TkCommandNames = ['::ttk::panedwindow'.freeze].freeze + end else TkCommandNames = ['::tpaned'.freeze].freeze end diff --git a/ext/tk/lib/tkextlib/tile/tscrollbar.rb b/ext/tk/lib/tkextlib/tile/tscrollbar.rb index bd49ae18e3..10b84e84a0 100644 --- a/ext/tk/lib/tkextlib/tile/tscrollbar.rb +++ b/ext/tk/lib/tkextlib/tile/tscrollbar.rb @@ -28,3 +28,22 @@ class Tk::Tile::TScrollbar < TkScrollbar [self::WidgetClassName, *(args.map!{|a| _get_eval_string(a)})].join('.') end end + +class Tk::Tile::XScrollbar < Tk::Tile::TScrollbar + def create_self(keys) + keys = {} unless keys + keys['orient'] = 'horizontal' + super(keys) + end + private :create_self +end + +class Tk::Tile::YScrollbar < Tk::Tile::TScrollbar + def create_self(keys) + keys = {} unless keys + keys['orient'] = 'vertical' + super(keys) + end + private :create_self +end + |