summaryrefslogtreecommitdiff
path: root/ext/tk/lib
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-03 22:07:47 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-03 22:07:47 +0000
commita09c02a600e06aa4f90bc4cb5ccd5f5f1a56a97a (patch)
tree31fe3f70e93ec2024d7eae6a6f25c9bd69ddcfff /ext/tk/lib
parent381ff055059337befcdf33ef8590ac2c065cb9cc (diff)
* ready to use 'validatecommand' option of TkEntry/TkSpinbox widget
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r--ext/tk/lib/tkentry.rb56
1 files changed, 39 insertions, 17 deletions
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index ab69e76550..fc52b9435d 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -15,9 +15,19 @@ class TkEntry<TkLabel
class ValidateCmd
include TkComm
+ module Action
+ Insert = 1
+ Delete = 0
+ Others = -1
+ Focus = -1
+ Forced = -1
+ Textvariable = -1
+ TextVariable = -1
+ end
+
class ValidateArgs
VARG_KEY = 'disvPSVW'
- VARG_TYPE = 'nnsssssw'
+ VARG_TYPE = 'nxsssssw'
def self.scan_args(arg_str, arg_val)
arg_cnv = []
@@ -31,6 +41,13 @@ class TkEntry<TkLabel
arg_cnv << TkComm::string(arg_val[idx])
when ?w
arg_cnv << TkComm::window(arg_val[idx])
+ when ?x
+ idx = TkComm::number(arg_val[idx])
+ if idx < 0
+ arg_cnv << nil
+ else
+ arg_cnv << idx
+ end
else
arg_cnv << arg_val[idx]
end
@@ -68,16 +85,16 @@ class TkEntry<TkLabel
if args
@id =
install_cmd(proc{|*arg|
- TkUtil.eval_cmd(cmd, ValidateArgs.scan_args(args, arg))
+ TkUtil.eval_cmd(proc{|*v| (cmd.call(*v))? '1': '0'},
+ *ValidateArgs.scan_args(args, arg))
}) + " " + args
else
args = ' %d %i %s %v %P %S %V %W'
@id =
install_cmd(proc{|*arg|
- TkUtil.eval_cmd(
- cmd,
- ValidateArgs.new(ValidateArgs.scan_args(args, arg))
- )
+ TkUtil.eval_cmd(proc{|*v| (cmd.call(*v))? '1': '0'},
+ ValidateArgs.new(*ValidateArgs \
+ .scan_args(args,arg)))
}) + args
end
end
@@ -88,10 +105,9 @@ class TkEntry<TkLabel
end
def create_self(keys)
+ tk_call 'entry', @path
if keys and keys != None
- tk_call 'entry', @path, *hash_kv(keys)
- else
- tk_call 'entry', @path
+ configure(keys)
end
end
@@ -193,28 +209,35 @@ class TkEntry<TkLabel
self
end
+ def invoke_validate
+ bool(tk_send('validate'))
+ end
def validate(mode = nil)
if mode
configure 'validate', mode
else
- bool(tk_send('validate'))
+ invoke_validate
end
end
- def validatecommand(cmd = ValidateCmd.new, args = nil)
+ def validatecommand(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('validatecommand', cmd)
+ elsif args
+ configure('validatecommand', [cmd, args])
else
- configure('validatecommand', ValidateCmd.new(cmd, args))
+ configure('validatecommand', cmd)
end
end
alias vcmd validatecommand
- def invalidcommand(cmd = ValidateCmd.new, args = nil)
+ def invalidcommand(cmd = Proc.new, args = nil)
if cmd.kind_of?(ValidateCmd)
configure('invalidcommand', cmd)
+ elsif args
+ configure('invalidcommand', [cmd, args])
else
- configure('invalidcommand', ValidateCmd.new(cmd, args))
+ configure('invalidcommand', cmd)
end
end
alias invcmd invalidcommand
@@ -234,10 +257,9 @@ class TkSpinbox<TkEntry
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
+ tk_call 'spinbox', @path
if keys and keys != None
- tk_call 'spinbox', @path, *hash_kv(keys)
- else
- tk_call 'spinbox', @path
+ configure(keys)
end
end