3 # Some functions needed for the common dialog boxes. Probably need to go
6 # RCS: @(#) $Id: comdlg.tcl,v 1.1 2006-02-24 18:59:53 vitus Exp $
8 # Copyright (c) 1996 Sun Microsystems, Inc.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # tclParseConfigSpec --
16 # Parses a list of "-option value" pairs. If all options and
17 # values are legal, the values are stored in
18 # $data($option). Otherwise an error message is returned. When
19 # an error happens, the data() array may have been partially
20 # modified, but all the modified members of the data(0 array are
21 # guaranteed to have valid values. This is different than
22 # Tk_ConfigureWidget() which does not modify the value of a
23 # widget record if any error occurs.
27 # w = widget record to modify. Must be the pathname of a widget.
30 # {-commandlineswitch resourceName ResourceClass defaultValue verifier}
34 # flags = currently unused.
36 # argList = The list of "-option value" pairs.
38 proc tclParseConfigSpec {w specs flags argList} {
41 # 1: Put the specs in associative arrays for faster access
44 if {[llength $spec] < 4} {
45 error "\"spec\" should contain 5 or 4 elements"
47 set cmdsw [lindex $spec 0]
49 set rname($cmdsw) [lindex $spec 1]
50 set rclass($cmdsw) [lindex $spec 2]
51 set def($cmdsw) [lindex $spec 3]
52 set verproc($cmdsw) [lindex $spec 4]
55 if {([llength $argList]%2) != 0} {
56 foreach {cmdsw value} $argList {
57 if {![info exists cmd($cmdsw)]} {
58 error "unknown option \"$cmdsw\", must be [tclListValidFlags cmd]"
61 error "value for \"[lindex $argList end]\" missing"
64 # 2: set the default values
66 foreach cmdsw [array names cmd] {
67 set data($cmdsw) $def($cmdsw)
70 # 3: parse the argument list
72 foreach {cmdsw value} $argList {
73 if {![info exists cmd($cmdsw)]} {
74 error "unknown option \"$cmdsw\", must be [tclListValidFlags cmd]"
76 set data($cmdsw) $value
82 proc tclListValidFlags {v} {
85 set len [llength [array names cmd]]
89 foreach cmdsw [lsort [array names cmd]] {
90 append errormsg "$separator$cmdsw"
101 # This procedure is used to sort strings in a case-insenstive mode.
103 proc tclSortNoCase {str1 str2} {
104 return [string compare [string toupper $str1] [string toupper $str2]]
108 # Gives an error if the string does not contain a valid integer
111 proc tclVerifyInteger {string} {
112 lindex {1 2 3} $string
115 # ckFDGetFileTypes --
117 # Process the string given by the -filetypes option of the file
118 # dialogs. Similar to the C function TkGetFileFilters() on the Mac
119 # and Windows platform.
121 proc ckFDGetFileTypes {string} {
123 if {[llength $t] < 2 || [llength $t] > 3} {
124 error "bad file type \"$t\", should be \"typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?\""
126 eval lappend [list fileTypes([lindex $t 0])] [lindex $t 1]
131 set label [lindex $t 0]
134 if {[info exists hasDoneType($label)]} {
140 foreach ext $fileTypes($label) {
141 if {![string compare $ext ""]} {
144 regsub {^[.]} $ext "*." ext
145 if {![info exists hasGotExt($label,$ext)]} {
148 set hasGotExt($label,$ext) 1
153 lappend types [list $name $exts]
155 set hasDoneType($label) 1