source: tol/tolbase/lib/mkWidgets1.3/Window.tcl

devel
Last change on this file was 32535cc, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

adding more types to config, added mkWidget1.3

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@16 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 3.5 KB
Line 
1package require Metawidget
2
3# name: Window
4# args: option-value pairs
5# this class merges the commands wm and toplevel (that is, the most
6# common functions of wm and those that apply to the Windows platform),
7# making the control of toplevel Windows easier and more consistent.
8# the Window metawidget is basically identical with the toplevel widget,
9# except that it defines some additional methods and options that use
10# wm functions.
11metawidget create Window {} {} -type toplevel
12
13# name: resize
14# args: iWidth, iHeight: new size of the Window
15metawidget proc Window resize { iWidth iHeight } {
16  wm geometry $this =${iWidth}x$iHeight
17}
18
19# name: move
20# args: iX, iY: new position of the Window
21metawidget proc Window move { iX iY } {
22  wm geometry $this +${iX}+$iY
23}
24
25# name: protocol
26# args: args: passed directly to 'wm protocol'
27metawidget proc Window protocol { args } {
28  eval wm protocol $this $args
29}
30
31# name: -geometry
32# args: sArg: geometry a la 'wm geometry'
33metawidget proc Window -geometry { {sArg {}} } {
34  eval wm geometry $this $sArg
35}
36
37# name: -minsize
38# args: sArg: width and height as a two-element list
39metawidget proc Window -minsize { {sArg {}} } {
40  eval wm minsize $this $sArg
41}
42
43# name: -maxsize
44# args: sArg: width and height as a two-element list
45metawidget proc Window -maxsize { {sArg {}} } {
46  eval wm maxsize $this $sArg
47}
48
49# name: -resizable
50# args: sArg: flags a la 'wm resizable' in a two-element list
51metawidget proc Window -resizable { {sArg {}} } {
52  eval wm resizable $this $sArg
53}
54
55# name: -override
56# args: sArg: flag for 'wm overrideredirect'
57metawidget proc Window -override { {sArg {}} } {
58  eval wm overrideredirect $this $sArg
59}
60
61# name: -ondelete
62# args: sArg: command for 'wm protocol ... WM_DELETE_WINDOW' or nothing
63metawidget proc Window -ondelete { {sArg ?} } {
64  if { $sArg == "?" } {
65    wm protocol $this WM_DELETE_WINDOW
66  } elseif { $sArg == {} } {
67    wm protocol $this WM_DELETE_WINDOW {}
68  } else {
69    wm protocol $this WM_DELETE_WINDOW $sArg
70  }
71}
72
73# name: -title
74# args: sArg: new Window title
75metawidget proc Window -title { {sArg {}} } {
76  if { $sArg == {} } {
77    wm title $this
78  } else {
79    wm title $this $sArg
80  }
81}
82
83# name: -state
84# args: sArg: option value as returned by 'wm state', except 'icon'
85metawidget proc Window -state { {sArg {}} } {
86  if { $sArg == {} } {
87    return [wm state $this]
88  }
89
90  switch [complete $sArg {normal iconic withdrawn}] {
91    normal    { wm deiconify $this }
92    iconic    { wm iconify   $this }
93    withdrawn { wm withdraw  $this }
94  }
95}
96
97metawidget command Window resize     resize
98metawidget command Window move       move
99metawidget command Window protocol   protocol
100
101metawidget option  Window -geometry  -geometry  -geometry
102metawidget option  Window -minsize   -minsize   -minsize
103metawidget option  Window -maxsize   -maxsize   -maxsize
104metawidget option  Window -resizable -resizable -resizable
105metawidget option  Window -override  -override  -override
106metawidget option  Window -ondelete  -ondelete  -ondelete
107metawidget option  Window -title     -title     -title
108metawidget option  Window -state     -state     -state
109
110# maps the "." toplevel to a Window object. a bit tricky.
111bindtags . [lreplace [bindtags .] 1 1 Window]
112rename ::. ::.::.         ;# ain't that funny...
113
114proc . { sCmd args } {
115  ::Window::__dispatch . $sCmd $args
116}
117
118
119proc test {} {
120  . config -title {Main Window}
121
122  window .w
123  .w config -title {New Window} -minsize {320 200}
124  .w config -ondelete {
125    if { [tk_messageBox -icon question -message "Close it?" -type yesno] == "yes" } {
126      destroy .w
127    }
128  }
129}
130
131#test
Note: See TracBrowser for help on using the repository browser.