Debian Codegraph @

Tk/MsgBox.pm

raw
1 # -*- perl -*-
2
3 # msgbox.tcl --
4 #
5 # Implements messageboxes for platforms that do not have native
6 # messagebox support.
7 #
8 # RCS: @(#) $Id: msgbox.tcl,v 1.30 2006/01/25 18:22:04 dgp Exp $
9 #
10 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
11 #
12 # See the file "license.terms" for information on usage and redistribution
13 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 #
15
16 # Translated to Perl/Tk by Slaven Rezic
17
18 package Tk::MsgBox;
19
20 use Tk qw(Ev);
21
22 use strict;
23 use vars qw($VERSION);
24 $VERSION = '4.002';
25
26 use base qw(Tk::Toplevel);
27 Construct Tk::Widget 'MsgBox';
28
29 sub import {
30 if (defined $_[1] and $_[1] eq 'as_default') {
31 local $^W = 0;
32 package Tk;
33 *tk_messageBox = sub {
34 Tk::MsgBox::_tk_messageBox(@_);
35 };
36 }
37 }
38
39 use vars qw(%image);
40
41 sub ClassInit {
42 my($class, $mw) = @_;
43 $class->SUPER::ClassInit($mw);
44
45 $image{b1}{$mw} = $mw->Bitmap(-foreground => 'black',
46 -data => "#define b1_width 32\n#define b1_height 32
47 static unsigned char q1_bits[] = {
48 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x07, 0xe0, 0x00, 0xc0, 0x00, 0x00, 0x03,
49 0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x10,
50 0x04, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
51 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80,
52 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80,
53 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
54 0x04, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x08,
55 0x60, 0x00, 0x00, 0x04, 0x80, 0x03, 0x80, 0x03, 0x00, 0x0c, 0x78, 0x00,
56 0x00, 0x30, 0x04, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x40, 0x04, 0x00,
57 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
59
60 $image{b2}{$mw} = $mw->Bitmap(-foreground => 'white',
61 -data => "#define b2_width 32\n#define b2_height 32
62 static unsigned char b2_bits[] = {
63 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x00,
64 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f,
65 0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
66 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
67 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
68 0xfe, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
69 0xf8, 0xff, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x07,
70 0x80, 0xff, 0xff, 0x03, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xf0, 0x07, 0x00,
71 0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00,
72 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
74
75 $image{'q'}{$mw} = $mw->Bitmap(-foreground => 'blue',
76 -data => "#define q_width 32\n#define q_height 32
77 static unsigned char q_bits[] = {
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00,
80 0x00, 0x10, 0x0f, 0x00, 0x00, 0x18, 0x1e, 0x00, 0x00, 0x38, 0x1e, 0x00,
81 0x00, 0x38, 0x1e, 0x00, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x80, 0x07, 0x00,
82 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00,
84 0x00, 0xe0, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
89
90 $image{'i'}{$mw} = $mw->Bitmap(-foreground => 'blue',
91 -data => "#define i_width 32\n#define i_height 32
92 static unsigned char i_bits[] = {
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0xe0, 0x01, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xf0, 0x03, 0x00,
95 0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0xf8, 0x03, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00,
97 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00,
98 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
99 0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
104
105 $image{'w1'}{$mw} = $mw->Bitmap(-foreground => 'black',
106 -data => "#define w1_width 32\n#define w1_height 32
107 static unsigned char w1_bits[] = {
108 0x00, 0x80, 0x01, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x20, 0x04, 0x00,
109 0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00,
110 0x00, 0x08, 0x10, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x04, 0x20, 0x00,
111 0x00, 0x02, 0x20, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01, 0x40, 0x00,
112 0x00, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x01,
113 0x40, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x02,
114 0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08,
115 0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10,
116 0x04, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x40,
117 0x01, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x20,
118 0xfc, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00};");
119
120 $image{'w2'}{$mw} = $mw->Bitmap(-foreground => 'yellow',
121 -data => "#define w2_width 32\n#define w2_height 32
122 static unsigned char w2_bits[] = {
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00,
124 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x07, 0x00,
125 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf8, 0x1f, 0x00,
126 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xfe, 0x3f, 0x00,
127 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00,
128 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x01,
129 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
130 0xf0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
131 0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0xff, 0x3f,
132 0xfe, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x1f,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
134
135 $image{'w3'}{$mw} = $mw->Bitmap(-foreground => 'black',
136 -data => "#define w3_width 32\n#define w3_height 32
137 static unsigned char w3_bits[] = {
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 0x00, 0xc0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
142 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
143 0x00, 0xc0, 0x03, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xc0, 0x03, 0x00,
144 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00,
146 0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};");
149
150 $class;
151 }
152
153 # ::tk::MessageBox --
154 #
155 # Pops up a messagebox with an application-supplied message with
156 # an icon and a list of buttons. This procedure will be called
157 # by tk_messageBox if the platform does not have native
158 # messagebox support, or if the particular type of messagebox is
159 # not supported natively.
160 #
161 # Color icons are used on Unix displays that have a color
162 # depth of 4 or more and $tk_strictMotif is not on.
163 #
164 # This procedure is a private procedure shouldn't be called
165 # directly. Call tk_messageBox instead.
166 #
167 # See the user documentation for details on what tk_messageBox does.
168 #
169 sub Populate {
170 my($w, $args) = @_;
171
172 $w->SUPER::Populate($args);
173
174 {
175 my $icon = delete $args->{-icon};
176 if (!defined $icon) {
177 $icon = 'info';
178 }
179 if (!grep {$icon eq $_} qw(info warning error question)) {
180 die "bad -icon value \"$icon\": must be error, info, question, or warning";
181 }
182 if ($Tk::platform eq 'aqua') {
183 if ($icon eq 'error') {
184 $icon = 'stop';
185 } elsif ($icon eq 'warning') {
186 $icon = 'caution';
187 } elsif ($icon eq 'info') {
188 $icon = 'note';
189 }
190 }
191 $w->{Configure}{icon} = $icon;
192 }
193
194 {
195 my $type = delete $args->{-type};
196 if (!defined $type) {
197 $type = 'ok';
198 }
199 if ($type =~ m{^abortretryignore$}i) {
200 $w->{Names} = [qw(abort retry ignore)];
201 $w->{Labels} = [qw(&Abort &Retry &Ignore)];
202 $w->{Cancel} = 'abort';
203 } elsif ($type =~ m{^ok$}i) {
204 $w->{Names} = [qw(ok)];
205 $w->{Labels} = [qw(&OK)];
206 $w->{Cancel} = 'ok';
207 } elsif ($type =~ m{^okcancel$}i) {
208 $w->{Names} = [qw(ok cancel)];
209 $w->{Labels} = [qw(&OK &Cancel)];
210 $w->{Cancel} = 'cancel';
211 } elsif ($type =~ m{^retrycancel$}i) {
212 $w->{Names} = [qw(retry cancel)];
213 $w->{Labels} = [qw(&Retry &Cancel)];
214 $w->{Cancel} = 'cancel';
215 } elsif ($type =~ m{^yesno$}i) {
216 $w->{Names} = [qw(yes no)];
217 $w->{Labels} = [qw(&Yes &No)];
218 $w->{Cancel} = 'no';
219 } elsif ($type =~ m{^yesnocancel$}i) {
220 $w->{Names} = [qw(yes no cancel)];
221 $w->{Labels} = [qw(&Yes &No &Cancel)];
222 $w->{Cancel} = 'cancel';
223 } else {
224 die "bad -type value \"$type\": must be abortretryignore, ok, okcancel, retrycancel, yesno, or yesnocancel";
225 }
226 $w->{Configure}{type} = $type;
227 }
228
229 $w->iconname('Dialog');
230
231 $w->withdraw;
232 #
233 # The default value of the title is space (" ") not the empty string
234 # because for some window managers, a
235 # wm title .foo ""
236 # causes the window title to be "foo" instead of the empty string.
237 #
238 $w->ConfigSpecs
239 ('-default' => ['PASSIVE',undef,undef,''],
240 '-detail' => ['PASSIVE',undef,undef,''],
241 '-message' => ['PASSIVE',undef,undef,''],
242 #not needed, we can do it different way in perl: '-parent' => ['PASSIVE' ...],
243 '-title' => ['PASSIVE',undef,undef," "],
244 );
245 $w;
246 }
247
248 sub Show {
249 my $w = shift;
250
251 # If reusing the widget:
252 $_->destroy for ($w->children);
253
254 my @buttons;
255 for my $i (0 .. $#{ $w->{Names} }) {
256 my($name, $lab) = ($w->{Names}[$i], $w->{Labels}[$i]);
257 push @buttons, [$name, -text => $lab]; # XXX missing: mc (message catalog)
258 }
259
260 # If no default button was specified, the default default is the
261 # first button (Bug: 2218).
262
263 if ($w->cget(-default) eq "") {
264 $w->configure(-default => $buttons[0][0]);
265 }
266
267 my $valid = 0;
268 foreach my $btn (@buttons) {
269 if ($btn->[0] eq $w->cget(-default)) {
270 $valid = 1;
271 last;
272 }
273 }
274 if (!$valid) {
275 die "invalid default button \"" . $w->cget(-default) . "\"";
276 }
277
278 ### skip the step 2, not needed in Perl/Tk
279
280 # 3. Create the top-level window and divide it into top
281 # and bottom parts.
282
283 $w->title($w->cget(-title));
284 $w->protocol('WM_DELETE_WINDOW' => sub {
285 $w->Subwidget($w->{Cancel})->invoke;
286 });
287 # There is only one background colour for the whole dialog
288 my $bg = $w->cget(-background);
289
290 # Message boxes should be transient with respect to their parent so that
291 # they always stay on top of the parent window. But some window managers
292 # will simply create the child window as withdrawn if the parent is not
293 # viewable (because it is withdrawn or iconified). This is not good for
294 # "grab"bed windows. So only make the message box transient if the parent
295 # is viewable.
296 #
297 if ($w->parent->toplevel->viewable) {
298 $w->transient($w->parent);
299 }
300
301 #XXX?
302 # if {$windowingsystem eq "aqua"} {
303 # unsupported::MacWindowStyle style $w dBoxProc # XXX what's that?
304 # }
305
306 my $w_bot = $w->Frame(-background => $bg)->pack(qw(-side bottom -fill both));
307 #XXX??? NYI? $w_bot->gridAnchor('center');
308 my $w_top = $w->Frame(-background => $bg)->pack(qw(-side top -fill both -expand 1));
309 if ($Tk::platform ne "aqua") {
310 $w_bot->configure(qw(-relief raised -bd 1));
311 $w_top->configure(qw(-relief raised -bd 1));
312 }
313
314 # 4. Fill the top part with bitmap, message and detail (use the
315 # option database for -wraplength and -font so that they can be
316 # overridden by the caller).
317
318 $w->optionAdd('*MsgBox.msg.wrapLength', '3i', 'widgetDefault');
319 $w->optionAdd('*MsgBox.dtl.wrapLength', '3i', 'widgetDefault');
320 if ($Tk::platform eq "aqua") {
321 $w->optionAdd('*MsgBox.msg.font', 'system', 'widgetDefault');
322 $w->optionAdd('*MsgBox.dtl.font', 'system', 'widgetDefault');
323 } else {
324 $w->optionAdd('*MsgBox.msg.font', [qw(Times 14)], 'widgetDefault');
325 $w->optionAdd('*MsgBox.dtl.font', [qw(Times 10)], 'widgetDefault');
326 }
327
328 my $w_msg = $w->Label(qw(Name msg -anchor nw -justify left),
329 -text => $w->cget(-message),
330 -background => $bg,
331 );
332 my $w_dtl;
333 if ($w->cget(-detail) ne "") {
334 $w_dtl = $w->Label(qw(Name dtl -anchor nw -justify left),
335 -text => $w->cget(-detail),
336 -background => $bg,
337 );
338 }
339 my $w_bitmap;
340 my $icon = $w->{Configure}{icon};
341 if ($icon ne "") {
342 if ($Tk::platform eq "aqua"
343 || ($w->depth < 4) || $Tk::strictMotif) {
344 $w_bitmap = $w->Label(Name => "bitmap",
345 -bitmap => $icon,
346 -background => $bg,
347 );
348 } else {
349 $w_bitmap = $w->Canvas(Name => "bitmap",
350 qw(-width 32 -height 32 -highlightthickness 0),
351 -background => $bg,
352 );
353 my $mw = $w->MainWindow;
354 if ($icon eq 'error') {
355 $w_bitmap->create(qw(oval 0 0 31 31 -fill red -outline black));
356 $w_bitmap->create(qw(line 9 9 23 23 -fill white -width 4));
357 $w_bitmap->create(qw(line 9 23 23 9 -fill white -width 4));
358 } elsif ($icon eq 'info') {
359 $w_bitmap->create(qw(image 0 0 -anchor nw),
360 -image => $image{b1}{$mw});
361 $w_bitmap->create(qw(image 0 0 -anchor nw),
362 -image => $image{b2}{$mw});
363 $w_bitmap->create(qw(image 0 0 -anchor nw),
364 -image => $image{i}{$mw});
365 } elsif ($icon eq 'question') {
366 $w_bitmap->create(qw(image 0 0 -anchor nw),
367 -image => $image{b1}{$mw});
368 $w_bitmap->create(qw(image 0 0 -anchor nw),
369 -image => $image{b2}{$mw});
370 $w_bitmap->create(qw(image 0 0 -anchor nw),
371 -image => $image{'q'}{$mw});
372 } else {
373 $w_bitmap->create(qw(image 0 0 -anchor nw),
374 -image => $image{w1}{$mw});
375 $w_bitmap->create(qw(image 0 0 -anchor nw),
376 -image => $image{w2}{$mw});
377 $w_bitmap->create(qw(image 0 0 -anchor nw),
378 -image => $image{w3}{$mw});
379 }
380 }
381 } else {
382 # Unlike in Tcl/Tk, a placeholder is needed here
383 $w_bitmap = $w->Label;
384 }
385 Tk::grid($w_bitmap, $w_msg, -in => $w_top, qw(-sticky news -padx 2m -pady 2m));
386 $w_top->gridColumnconfigure(qw(1 -weight 1));
387 if (Tk::Exists($w_dtl)) {
388 Tk::grid('^', $w_dtl, -in => $w_top, qw(-sticky news -padx 2m), -pady => [0, '2m']);
389 $w_top->gridRowconfigure(qw(1 -weight 1));
390 } else {
391 $w_top->gridRowconfigure(qw(0 -weight 1));
392 }
393
394 # 5. Create a row of buttons at the bottom of the dialog.
395
396 my $i = 0;
397 for my $but (@buttons) {
398 my($name, @opts) = @$but;
399 if (!@opts) {
400 # Capitalize the first letter of $name
401 @opts = (-text => ucfirst $name);
402 }
403
404 my $cw = $w->AmpWidget('Button', -padx => '3m', @opts,
405 -command => sub { $w->{selectedButton} = $name });
406 $w->Advertise($name => $cw);
407 if ($name eq $w->cget(-default)) {
408 $cw->configure(qw(-default active));
409 } else {
410 $cw->configure(qw(-default normal));
411 }
412 $cw->grid(-in => $w_bot, -row => 0, -column => $i,
413 qw(-padx 3m -pady 2m -sticky ew));
414 $w_bot->gridColumnconfigure($i, -uniform => 'buttons');
415 $i++;
416
417 # create the binding for the key accelerator, based on the underline
418 #
419 # set underIdx [$w.$name cget -under]
420 # if {$underIdx >= 0} {
421 # set key [string index [$w.$name cget -text] $underIdx]
422 # bind $w <Alt-[string tolower $key]> [list $w.$name invoke]
423 # bind $w <Alt-[string toupper $key]> [list $w.$name invoke]
424 # }
425 }
426 $w->bind('<Alt-Key>', [sub { $w->AltKeyInDialog($_[1]) }, Ev('%A')]);
427
428 if ($w->cget(-default) ne "") {
429 $w->bind('<FocusIn>', sub {
430 my $e = shift->XEvent;
431 my $w = $e->W;
432 if ($w->isa('Tk::Button')) {
433 $w->configure(qw(-default active));
434 }
435 });
436 $w->bind('<FocusOut>', sub {
437 my $e = shift->XEvent;
438 my $w = $e->W;
439 if ($w->isa('Tk::Button')) {
440 $w->configure(qw(-default normal));
441 }
442 });
443 }
444
445 # 6. Create bindings for <Return>, <Escape> and <Destroy> on the dialog
446
447 $w->bind('<Return>' => sub {
448 my $e = shift->XEvent;
449 my $w = $e->W;
450 if ($w->isa('Tk::Button')) {
451 $w->invoke;
452 }
453 });
454
455 # Invoke the designated cancelling operation
456 $w->bind('<Escape>' => sub { $w->Subwidget($w->{Cancel})->invoke });
457
458 # At <Destroy> the buttons have vanished, so must do this directly.
459 $w_msg->bind('<Destroy>' => sub { $w->{selectedButton} = $w->{Cancel} });
460
461 # 7. Withdraw the window, then update all the geometry information
462 # so we know how big it wants to be, then center the window in the
463 # display and de-iconify it.
464
465 # ::tk::PlaceWindow $w widget $data(-parent)
466 $w->withdraw;
467 $w->Popup;
468
469 # 8. Set a grab and claim the focus too.
470
471 my $focus;
472 if ($w->cget(-default) ne "") {
473 $focus = $w->Subwidget($w->cget(-default));
474 } else {
475 $focus = $w;
476 }
477 $w->SetFocusGrab($focus);
478
479 # 9. Wait for the user to respond, then restore the focus and
480 # return the index of the selected button. Restore the focus
481 # before deleting the window, since otherwise the window manager
482 # may take the focus away so we can't redirect it. Finally,
483 # restore any grab that was in effect.
484
485 $w->waitVariable(\$w->{selectedButton});
486 # Copy the result now so any <Destroy> that happens won't cause
487 # trouble
488 my $result = $w->{selectedButton};
489
490 $w->RestoreFocusGrab($focus, 'withdraw');
491
492 return $result;
493 }
494
495 sub _tk_messageBox {
496 my(%args) = @_;
497 my $parent = delete $args{-parent};
498 my $md = $parent->MsgBox(%args);
499 my $an = $md->Show;
500 $md->destroy;
501 $an;
502 }
503
504 1;
505
506 __END__