summaryrefslogtreecommitdiff
path: root/ext/tk
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-04 03:56:00 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-04 03:56:00 +0000
commit581ca6097ea061e7b348ed098ca56f809aba4499 (patch)
tree790b6e523c308dc06dd9e6a3ab007f6988554a3c /ext/tk
parent6e8ae612bac85ad5bb421170d62b41c4533d8165 (diff)
* ext/tk/lib/tk/image.rb: bug fix
* ext/tk/lib/tk/optiondb.rb: support definition of command resources on widgets git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r--ext/tk/MANIFEST2
-rw-r--r--ext/tk/lib/tk/image.rb2
-rw-r--r--ext/tk/lib/tk/optiondb.rb58
-rw-r--r--ext/tk/sample/cmd_res_test.rb17
-rw-r--r--ext/tk/sample/cmd_resource5
5 files changed, 83 insertions, 1 deletions
diff --git a/ext/tk/MANIFEST b/ext/tk/MANIFEST
index 64d260a672..28a9e23ee2 100644
--- a/ext/tk/MANIFEST
+++ b/ext/tk/MANIFEST
@@ -263,6 +263,8 @@ sample/binding_sample.rb
sample/bindtag_sample.rb
sample/binstr_usage.rb
sample/btn_with_frame.rb
+sample/cmd_res_test.rb
+sample/cmd_resource
sample/encstr_usage.rb
sample/iso2022-kr.txt
sample/menubar1.rb
diff --git a/ext/tk/lib/tk/image.rb b/ext/tk/lib/tk/image.rb
index e7da1ba207..7868ed0c8f 100644
--- a/ext/tk/lib/tk/image.rb
+++ b/ext/tk/lib/tk/image.rb
@@ -107,7 +107,7 @@ class TkPhotoImage<TkImage
term
end
}.flatten
- tk_send('copy', source, *args)
+ tk_send('copy', src, *args)
end
self
end
diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb
index 1211dda4a8..1f455dfa05 100644
--- a/ext/tk/lib/tk/optiondb.rb
+++ b/ext/tk/lib/tk/optiondb.rb
@@ -8,6 +8,7 @@ module TkOptionDB
extend Tk
TkCommandNames = ['option'.freeze].freeze
+ CmdClassID = ['CMD_CLASS'.freeze, '00000'.taint].freeze
module Priority
WidgetDefault = 20
@@ -193,6 +194,7 @@ module TkOptionDB
end
@@resource_proc_class.freeze
+=begin
def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
klass = klass.to_s if klass.kind_of? Symbol
unless (?A..?Z) === klass[0]
@@ -229,12 +231,55 @@ module TkOptionDB
eval('TkOptionDB::' + klass)
end
end
+=end
+ def __create_new_class(klass, func, safe = 4, add = false, parent = nil)
+ if klass.kind_of?(TkWindow)
+ carrier = klass.path
+ klass = CmdClassID.join(TkCore::INTERP._ip_id_)
+ CmdClassID[1].succ!
+ parent = nil # ignore parent
+ else
+ klass = klass.to_s if klass.kind_of? Symbol
+ unless (?A..?Z) === klass[0]
+ fail ArgumentError, "bad string '#{klass}' for class name"
+ end
+ if parent == nil
+ install_win(nil)
+ elsif parent.kind_of?(TkWindow)
+ install_win(parent.path)
+ elsif parent <= @@resource_proc_class
+ install_win(parent::CARRIER)
+ else
+ fail ArgumentError, "parent must be Resource-Proc class"
+ end
+ carrier = Tk.tk_call_without_enc('frame', @path, '-class', klass)
+ end
+
+ unless func.kind_of? Array
+ fail ArgumentError, "method-list must be Array"
+ end
+ func_str = func.join(' ')
+
+ if parent.kind_of?(Class) && parent <= @@resource_proc_class
+ cmd_klass = Class.new(parent)
+ else
+ cmd_klass = Class.new(TkOptionDB.module_eval('@@resource_proc_class'))
+ end
+ cmd_klass.const_set(:CARRIER, carrier.dup.freeze)
+ cmd_klass.const_set(:METHOD_TBL, TkCore::INTERP.create_table)
+ cmd_klass.const_set(:ADD_METHOD, add)
+ cmd_klass.const_set(:SAFE_MODE, safe)
+ func.each{|f| cmd_klass::METHOD_TBL[f.to_s.intern] = nil }
+
+ cmd_klass
+ end
module_function :__create_new_class
private_class_method :__create_new_class
def __remove_methods_of_proc_class(klass)
# for security, make these methods invalid
class << klass
+=begin
attr_reader :class_eval, :name, :superclass,
:ancestors, :const_defined?, :const_get, :const_set,
:constants, :included_modules, :instance_methods,
@@ -244,6 +289,19 @@ module TkOptionDB
:to_s, :inspect, :display, :method, :methods,
:instance_eval, :instance_variables, :kind_of?, :is_a?,
:private_methods, :protected_methods, :public_methods
+=end
+ def __null_method(*args); nil; end
+ [ :class_eval, :name, :superclass,
+ :ancestors, :const_defined?, :const_get, :const_set,
+ :constants, :included_modules, :instance_methods,
+ :method_defined?, :module_eval, :private_instance_methods,
+ :protected_instance_methods, :public_instance_methods,
+ :remove_const, :remove_method, :undef_method,
+ :to_s, :inspect, :display, :method, :methods,
+ :instance_eval, :instance_variables, :kind_of?, :is_a?,
+ :private_methods, :protected_methods, :public_methods ].each{|m|
+ alias_method(m, :__null_method)
+ }
end
end
module_function :__remove_methods_of_proc_class
diff --git a/ext/tk/sample/cmd_res_test.rb b/ext/tk/sample/cmd_res_test.rb
new file mode 100644
index 0000000000..9bbb2044ce
--- /dev/null
+++ b/ext/tk/sample/cmd_res_test.rb
@@ -0,0 +1,17 @@
+require 'tk'
+TkOptionDB.readfile(File.expand_path('cmd_resource',
+ File.dirname(__FILE__)))
+f = TkFrame.new(:class=>'BtnFrame').pack
+b = TkButton.new(:parent=>f, :widgetname=>'hello').pack
+cmd1 = TkOptionDB.new_proc_class(b, [:show_msg, :bye_msg], 3)
+cmd2 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, cmd1)
+cmd3 = TkOptionDB.new_proc_class(:ZZZ, [:show_msg, :bye_msg], 3, false, b)
+cmd4 = TkOptionDB.new_proc_class(:BTN_CMD, [:show_msg, :bye_msg], 3){
+ def self.__check_proc_string__(str)
+ "{|arg| print [arg, $SAFE].inspect, ': '; Proc.new#{str}.call(arg)}"
+ end
+}
+cmd1.show_msg('cmd1')
+cmd2.show_msg('cmd2')
+cmd3.show_msg('cmd3')
+cmd4.show_msg('cmd4')
diff --git a/ext/tk/sample/cmd_resource b/ext/tk/sample/cmd_resource
new file mode 100644
index 0000000000..9cc4915546
--- /dev/null
+++ b/ext/tk/sample/cmd_resource
@@ -0,0 +1,5 @@
+*BtnFrame.hello.text: HELLO
+*BtnFrame.hello.command: ruby {puts "Hello World!!"}
+*BTN_CMD.show_msg: {|arg| print "Hello, #{arg}!!\n"}
+*hello.show_msg: {|arg| print "Hello, Hello, #{arg}!!\n"}
+*hello.ZZZ.show_msg: {|arg| print "Hello, Hello, ZZZ:#{arg}!!\n"}