summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tkentry.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-27 09:23:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-27 09:23:38 +0000
commitf54418b71f57e00d4a50bd86bf7d18b8b5195287 (patch)
treed5bd57142a0d4736fdfd1f35dcd864ac40cfb045 /ext/tk/lib/tkentry.rb
parent1f297b8bfc0fdacb8cfb19736cf224b2550281b3 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tkentry.rb')
-rw-r--r--ext/tk/lib/tkentry.rb123
1 files changed, 82 insertions, 41 deletions
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index 6c050d7cf16..6b25be376bc 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -14,6 +14,47 @@ class TkEntry<TkLabel
WidgetClassName
end
+ class ValidateCmd
+ include TkComm
+
+ class ValidateArgs
+ def initialize(d,i,s,v,pp,ss,vv,ww)
+ @action = d
+ @index = i
+ @current = s
+ @type = v
+ @value = pp
+ @string = ss
+ @triggered = vv
+ @widget = ww
+ end
+ attr :action
+ attr :index
+ attr :current
+ attr :type
+ attr :value
+ attr :string
+ attr :triggered
+ attr :widget
+ end
+
+ def initialize(cmd = Proc.new, args=nil)
+ if args
+ @id = install_cmd(proc{|*arg|
+ TkUtil.eval_cmd cmd, *arg
+ }) + " " + args
+ else
+ @id = install_cmd(proc{|arg|
+ TkUtil.eval_cmd cmd, ValidateArgs.new(*arg)
+ }) + ' %d %i %s %v %P %S %V %W'
+ end
+ end
+
+ def to_eval
+ @id
+ end
+ end
+
def create_self
tk_call 'entry', @path
end
@@ -26,6 +67,47 @@ class TkEntry<TkLabel
tk_send 'delete', s, e
end
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ if slot['vcmd'].kind_of? Array
+ cmd, *args = slot['vcmd']
+ slot['vcmd'] = ValidateCmd.new(cmd, args.join(' '))
+ elsif slot['vcmd'].kind_of? Proc
+ slot['vcmd'] = ValidateCmd.new(slot['vcmd'])
+ end
+ if slot['validatecommand'].kind_of? Array
+ cmd, *args = slot['validatecommand']
+ slot['validatecommand'] = ValidateCmd.new(cmd, args.join(' '))
+ elsif slot['validatecommand'].kind_of? Proc
+ slot['validatecommand'] = ValidateCmd.new(slot['validatecommand'])
+ end
+ if slot['invcmd'].kind_of? Array
+ cmd, *args = slot['invcmd']
+ slot['invcmd'] = ValidateCmd.new(cmd, args.join(' '))
+ elsif slot['invcmd'].kind_of? Proc
+ slot['invcmd'] = ValidateCmd.new(slot['invcmd'])
+ end
+ if slot['invalidcommand'].kind_of? Array
+ cmd, *args = slot['invalidcommand']
+ slot['invalidcommand'] = ValidateCmd.new(cmd, args.join(' '))
+ elsif slot['invalidcommand'].kind_of? Proc
+ slot['invalidcommand'] = ValidateCmd.new(slot['invalidcommand'])
+ end
+ super(slot)
+ else
+ if (slot == 'vcmd' || slot == 'validatecommand' ||
+ slot == 'invcmd' || slot == 'invalidcommand')
+ if value.kind_of? Array
+ cmd, *args = value
+ value = ValidateCmd.new(cmd, args.join(' '))
+ elsif value.kind_of? Proc
+ value = ValidateCmd.new(value)
+ end
+ end
+ super(slot, value)
+ end
+ end
+
def cursor
tk_send 'index', 'insert'
end
@@ -75,47 +157,6 @@ class TkEntry<TkLabel
end
end
- class ValidateCmd
- include TkComm
-
- class ValidateArgs
- def initialize(d,i,s,v,pp,ss,vv,ww)
- @action = d
- @index = i
- @current = s
- @type = v
- @value = pp
- @string = ss
- @triggered = vv
- @widget = ww
- end
- attr :action
- attr :index
- attr :current
- attr :type
- attr :value
- attr :string
- attr :triggered
- attr :widget
- end
-
- def initialize(cmd = Proc.new, args=nil)
- if args
- @id = install_cmd(proc{|*arg|
- TkUtil.eval_cmd cmd, *arg
- }) + " " + args
- else
- @id = install_cmd(proc{|arg|
- TkUtil.eval_cmd cmd, ValidateArgs.new(*arg)
- }) + ' %d %i %s %v %P %S %V %W'
- end
- end
-
- def to_eval
- @id
- end
- end
-
def validatecommand(cmd = ValidateCmd.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('validatecommand', cmd)