summaryrefslogtreecommitdiff
path: root/itcl/iwidgets3.0.0/generic/dialogshell.itk
blob: d4a52e998ef39958c263bb3945c534df56f3fa2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Dialogshell
# ----------------------------------------------------------------------
# This class is implements a dialog shell which is a top level widget
# composed of a button box, separator, and child site area.  The class
# also has methods to control button construction.
#    
# ----------------------------------------------------------------------
#  AUTHOR: Mark L. Ulferts              EMAIL: mulferts@austin.dsccc.com
#
#  @(#) $Id$
# ----------------------------------------------------------------------
#            Copyright (c) 1995 DSC Technologies Corporation
# ======================================================================
# Permission to use, copy, modify, distribute and license this software 
# and its documentation for any purpose, and without fee or written 
# agreement with DSC, is hereby granted, provided that the above copyright 
# notice appears in all copies and that both the copyright notice and 
# warranty disclaimer below appear in supporting documentation, and that 
# the names of DSC Technologies Corporation or DSC Communications 
# Corporation not be used in advertising or publicity pertaining to the 
# software without specific, written prior permission.
# 
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, 
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL 
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 
# SOFTWARE.
# ======================================================================

#
# Usual options.
#
itk::usual Dialogshell {
    keep -background -cursor -foreground -modality 
}

# ------------------------------------------------------------------
#                            DIALOGSHELL
# ------------------------------------------------------------------
class iwidgets::Dialogshell {
    inherit iwidgets::Shell

    constructor {args} {}

    itk_option define -thickness thickness Thickness 3
    itk_option define -buttonboxpos buttonBoxPos Position s
    itk_option define -separator separator Separator on
    itk_option define -padx padX Pad 10
    itk_option define -pady padY Pad 10

    public method childsite {}
    public method index {args}
    public method add {args}
    public method insert {args}
    public method delete {args}
    public method hide {args}
    public method show {args}
    public method default {args}
    public method invoke {args}
    public method buttonconfigure {args}
    public method buttoncget {index option}
}

#
# Provide a lowercased access method for the Dialogshell class.
# 
proc ::iwidgets::dialogshell {pathName args} {
    uplevel ::iwidgets::Dialogshell $pathName $args
}

#
# Use option database to override default resources of base classes.
#
option add *Dialogshell.master "." widgetDefault

# ------------------------------------------------------------------
#                        CONSTRUCTOR
# ------------------------------------------------------------------
body iwidgets::Dialogshell::constructor {args} {
    itk_option remove iwidgets::Shell::padx iwidgets::Shell::pady

    #
    # Create the user child site, separator, and button box,
    #
    itk_component add -protected dschildsite {
	frame $itk_interior.dschildsite
    } 
    
    itk_component add separator {
	frame $itk_interior.separator -relief sunken 
    } 
    
    itk_component add bbox {
	iwidgets::Buttonbox $itk_interior.bbox
    } {
	usual

	rename -padx -buttonboxpadx buttonBoxPadX Pad
	rename -pady -buttonboxpady buttonBoxPadY Pad
    }
    
    #
    # Set the itk_interior variable to be the childsite for derived 
    # classes.
    #
    set itk_interior $itk_component(dschildsite)
    
    #
    # Set up the default button so that if <Return> is pressed in
    # any widget, it will invoke the default button.
    #
    bind $itk_component(hull) <Return> [code $this invoke]
    
    #
    # Initialize the widget based on the command line options.
    #
    eval itk_initialize $args
}

# ------------------------------------------------------------------
#                             OPTIONS
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# OPTION: -thickness
#
# Specifies the thickness of the separator.  It sets the width and
# height of the separator to the thickness value and the borderwidth
# to half the thickness.
# ------------------------------------------------------------------
configbody iwidgets::Dialogshell::thickness {
    $itk_component(separator) config -height $itk_option(-thickness)
    $itk_component(separator) config -width $itk_option(-thickness)
    $itk_component(separator) config \
	    -borderwidth [expr $itk_option(-thickness) / 2]
}

# ------------------------------------------------------------------
# OPTION: -buttonboxpos
#
# Specifies the position of the button box relative to the child site.
# The separator appears between the child site and button box.
# ------------------------------------------------------------------
configbody iwidgets::Dialogshell::buttonboxpos {
    set parent [winfo parent $itk_component(bbox)]

    switch $itk_option(-buttonboxpos) {
	n {
	    $itk_component(bbox) configure -orient horizontal

	    grid $itk_component(bbox) -row 0 -column 0 -sticky ew
	    grid $itk_component(separator) -row 1 -column 0 -sticky ew
	    grid $itk_component(dschildsite) -row 2 -column 0 -sticky nsew

	    grid rowconfigure $parent 0 -weight 0
	    grid rowconfigure $parent 1 -weight 0
	    grid rowconfigure $parent 2 -weight 1
	    grid columnconfigure $parent 0 -weight 1
	    grid columnconfigure $parent 1 -weight 0
	    grid columnconfigure $parent 2 -weight 0
	}
	s {
	    $itk_component(bbox) configure -orient horizontal

	    grid $itk_component(dschildsite) -row 0 -column 0 -sticky nsew
	    grid $itk_component(separator) -row 1 -column 0 -sticky ew
	    grid $itk_component(bbox) -row 2 -column 0 -sticky ew

	    grid rowconfigure $parent 0 -weight 1
	    grid rowconfigure $parent 1 -weight 0
	    grid rowconfigure $parent 2 -weight 0
	    grid columnconfigure $parent 0 -weight 1
	    grid columnconfigure $parent 1 -weight 0
	    grid columnconfigure $parent 2 -weight 0
	}
	w {
	    $itk_component(bbox) configure -orient vertical

	    grid $itk_component(bbox) -row 0 -column 0 -sticky ns
	    grid $itk_component(separator) -row 0 -column 1 -sticky ns
	    grid $itk_component(dschildsite) -row 0 -column 2 -sticky nsew

	    grid rowconfigure $parent 0 -weight 1
	    grid rowconfigure $parent 1 -weight 0
	    grid rowconfigure $parent 2 -weight 0
	    grid columnconfigure $parent 0 -weight 0
	    grid columnconfigure $parent 1 -weight 0
	    grid columnconfigure $parent 2 -weight 1
	}
	e {
	    $itk_component(bbox) configure -orient vertical

	    grid $itk_component(dschildsite) -row 0 -column 0 -sticky nsew
	    grid $itk_component(separator) -row 0 -column 1 -sticky ns
	    grid $itk_component(bbox) -row 0 -column 2 -sticky ns

	    grid rowconfigure $parent 0 -weight 1
	    grid rowconfigure $parent 1 -weight 0
	    grid rowconfigure $parent 2 -weight 0
	    grid columnconfigure $parent 0 -weight 1
	    grid columnconfigure $parent 1 -weight 0
	    grid columnconfigure $parent 2 -weight 0
	}
	default {
	    error "bad buttonboxpos option\
		    \"$itk_option(-buttonboxpos)\": should be n,\
		    s, e, or w"
	}
    }
}

# ------------------------------------------------------------------
# OPTION: -separator 
#
# Boolean option indicating wheather to display the separator.
# ------------------------------------------------------------------
configbody iwidgets::Dialogshell::separator {
    if {$itk_option(-separator)} {
	$itk_component(separator) configure -relief sunken
    } else {
	$itk_component(separator) configure -relief flat
    }
}

# ------------------------------------------------------------------
# OPTION: -padx
#
# Specifies a padding distance for the childsite in the X-direction.
# ------------------------------------------------------------------
configbody iwidgets::Dialogshell::padx {
    grid configure $itk_component(dschildsite) -padx $itk_option(-padx)
}

# ------------------------------------------------------------------
# OPTION: -pady
#
# Specifies a padding distance for the childsite in the Y-direction.
# ------------------------------------------------------------------
configbody iwidgets::Dialogshell::pady {
    grid configure $itk_component(dschildsite) -pady $itk_option(-pady)
}
    
# ------------------------------------------------------------------
#                            METHODS
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# METHOD: childsite
#
# Return the pathname of the user accessible area.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::childsite {} {
    return $itk_component(dschildsite)
}

# ------------------------------------------------------------------
# METHOD: index index
#
# Thin wrapper of Buttonbox's index method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::index {args} {
    uplevel $itk_component(bbox) index $args
}

# ------------------------------------------------------------------
# METHOD: add tag ?option value ...?
#
# Thin wrapper of Buttonbox's add method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::add {args} {
    uplevel $itk_component(bbox) add $args
}

# ------------------------------------------------------------------
# METHOD: insert index tag ?option value ...?
#
# Thin wrapper of Buttonbox's insert method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::insert {args} {
    uplevel $itk_component(bbox) insert $args
}

# ------------------------------------------------------------------
# METHOD: delete tag
#
# Thin wrapper of Buttonbox's delete method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::delete {args} {
    uplevel $itk_component(bbox) delete $args
}

# ------------------------------------------------------------------
# METHOD: hide index
#
# Thin wrapper of Buttonbox's hide method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::hide {args} {
    uplevel $itk_component(bbox) hide $args
}

# ------------------------------------------------------------------
# METHOD: show index
#
# Thin wrapper of Buttonbox's show method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::show {args} {
    uplevel $itk_component(bbox) show $args
}

# ------------------------------------------------------------------
# METHOD: default index
#
# Thin wrapper of Buttonbox's default method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::default {args} {
    uplevel $itk_component(bbox) default $args
}

# ------------------------------------------------------------------
# METHOD: invoke ?index?
#
# Thin wrapper of Buttonbox's invoke method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::invoke {args} {
    uplevel $itk_component(bbox) invoke $args
}

# ------------------------------------------------------------------
# METHOD: buttonconfigure index ?option? ?value option value ...?
#
# Thin wrapper of Buttonbox's buttonconfigure method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::buttonconfigure {args} {
    uplevel $itk_component(bbox) buttonconfigure $args
}

# ------------------------------------------------------------------
# METHOD: buttoncget index option
#
# Thin wrapper of Buttonbox's buttoncget method.
# ------------------------------------------------------------------
body iwidgets::Dialogshell::buttoncget {index option} {
  uplevel $itk_component(bbox) buttoncget [list $index] \
  	[list $option]
}