From 5d11f0072c0a9b1e2dacd9b21fc6db0974c62d4f Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 13 Jul 2006 13:27:20 +0000 Subject: [PATCH] * ext/tk/lib/tk/composite.rb: improve handling of the classname on the option database for the widget class which includes TkComposite. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++ ext/tk/lib/tk.rb | 2 +- ext/tk/lib/tk/composite.rb | 101 +++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 01e113f087..832e599368 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jul 13 22:23:56 2006 Hidetoshi NAGAI + + * ext/tk/lib/tk/composite.rb: improve handling of the classname on the + option database for the widget class which includes TkComposite. + Thu Jul 13 00:40:57 2006 Yukihiro Matsumoto * ruby.h (FIX2LONG): returns integer of size of VALUE. diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 4e05af5ccc..499cfce927 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -4581,7 +4581,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2006-07-11'.freeze + RELEASE_DATE = '2006-07-13'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/composite.rb b/ext/tk/lib/tk/composite.rb index 58cca736db..eaed8ed363 100644 --- a/ext/tk/lib/tk/composite.rb +++ b/ext/tk/lib/tk/composite.rb @@ -7,6 +7,7 @@ module TkComposite include Tk extend Tk +=begin def initialize(parent=nil, *args) @delegates = {} @option_methods = {} @@ -24,6 +25,106 @@ module TkComposite initialize_composite(*args) end end +=end + + def _choice_classname_of_baseframe + base_class_name = nil + + klass = WidgetClassNames[self.class::WidgetClassName] + + if klass + # WidgetClassName is a known class + if klass <= TkFrame || klass < TkComposite + # klass is valid for the base frame + if self.class <= klass + # use my classname + base_class_name = self.class.name + if base_class_name == '' + # anonymous class -> use ancestor's name + base_class_name = klass.name + end + else + # not subclass -> use WidgetClassName + base_class_name = klass.name + end + + else + # klass is invalid for the base frame + if self.class < TkFrame || self.class.superclass < TkComposite + # my class name is valid for the base frame -> use my classname + base_class_name = self.class.name + if base_class_name == '' + # anonymous class -> use TkFrame + base_class_name = nil + end + else + # no idea for the base frame -> use TkFrame + base_class_name = nil + end + end + + elsif self.class::WidgetClassName && ! self.class::WidgetClassName.empty? + # unknown WidgetClassName is defined -> use it for the base frame + base_class_name = self.class::WidgetClassName + + else + # no valid WidgetClassName + if self.class < TkFrame || self.class.superclass < TkComposite + # my class name is valid for the base frame -> use my classname + base_class_name = self.class.name + if base_class_name == '' + # anonymous class -> use TkFrame + base_class_name = nil + end + else + # no idea for the base frame -> use TkFrame + base_class_name = nil + end + end + + base_class_name + end + private :_choice_classname_of_baseframe + + # def initialize(parent=nil, *args) + def initialize(*args) + @delegates = {} + @option_methods = {} + @option_setting = {} + + if args[-1].kind_of?(Hash) + keys = _symbolkey2str(args.pop) + else + keys = {} + end + parent = args.shift + parent = keys.delete('parent') if keys.has_key?('parent') + + if keys.key?('classname') + keys['class'] = keys.delete('classname') + end + if (base_class_name = (keys.delete('class')).to_s).empty? + base_class_name = _choice_classname_of_baseframe + end + + if base_class_name + @frame = TkFrame.new(parent, :class=>base_class_name) + else + @frame = TkFrame.new(parent) + end + @path = @epath = @frame.path + + args.push(keys) unless keys.empty? + initialize_composite(*args) + end + + def database_classname + @frame.database_classname + end + + def database_class + @frame.database_class + end def epath @epath