Bwidget Source Code
Check-in [85325e23c6]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:theme related mod's done
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 85325e23c6489faa13b1bed79616f21c3c5932a6
User & Date: oberdorfer 2009-09-06 21:28:51
Context
2009-09-06
21:36
theme related mod's done check-in: b8bf09501c user: oberdorfer tags: trunk
21:28
theme related mod's done check-in: 85325e23c6 user: oberdorfer tags: trunk
21:13
theme related mod's done check-in: 307eeef2b7 user: oberdorfer tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pagesmgr.tcl.

1
2
3
4
5
6
7
8
9
10
11
..
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
106
107
108
109
110
111
112

113
114
115
116
117
118
119
120
# ------------------------------------------------------------------------------
#  pagesmgr.tcl
#  This file is part of Unifix BWidget Toolkit
#  $Id: pagesmgr.tcl,v 1.6 2003/10/20 21:23:52 damonc Exp $
# ------------------------------------------------------------------------------
#  Index of commands:
#     - PagesManager::create
#     - PagesManager::configure
#     - PagesManager::cget
#     - PagesManager::compute_size
#     - PagesManager::add
................................................................................
# ------------------------------------------------------------------------------
package require Tcl 8.1.1

namespace eval PagesManager {
    Widget::define PagesManager pagesmgr

    Widget::declare PagesManager {
        {-background TkResource "" 0 frame}
        {-cursor     TkResource "" 0 frame}
        {-width      Int        0  0 "%d >= 0"}
        {-height     Int        0  0 "%d >= 0"}
    }

    Widget::addmap PagesManager "" :cmd { -width {} -height {} -cursor {} }
}
................................................................................
    Widget::init PagesManager $path $args

    set data(select)   ""
    set data(pages)    {}
    set data(cpt)      0
    set data(realized) 0

    # --- creation du canvas -----------------------------------------------------------------
    eval canvas $path -relief flat -bd 0 -highlightthickness 0 \
	    [Widget::subcget $path :cmd]

    bind $path <Configure> [list PagesManager::_realize $path]
    bind $path <Destroy>   [list PagesManager::_destroy $path]

    return [Widget::create PagesManager $path]
................................................................................

    if { [lsearch -exact $data(pages) $page] != -1 } {
        return -code error "page \"$page\" already exists"
    }

    lappend data(pages) $page


    frame $path.f$page -relief flat \
	    -background [Widget::cget $path -background] -borderwidth 0

    return $path.f$page
}


# ------------------------------------------------------------------------------


|







 







|







 







<







 







>
|







1
2
3
4
5
6
7
8
9
10
11
..
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
46
47
48
49
50
51
52

53
54
55
56
57
58
59
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# ------------------------------------------------------------------------------
#  pagesmgr.tcl
#  This file is part of Unifix BWidget Toolkit
#  $Id: pagesmgr.tcl,v 1.61 2009/09/06 21:28:51 oberdorfer Exp $
# ------------------------------------------------------------------------------
#  Index of commands:
#     - PagesManager::create
#     - PagesManager::configure
#     - PagesManager::cget
#     - PagesManager::compute_size
#     - PagesManager::add
................................................................................
# ------------------------------------------------------------------------------
package require Tcl 8.1.1

namespace eval PagesManager {
    Widget::define PagesManager pagesmgr

    Widget::declare PagesManager {
        {-background Color      "SystemWindow" 0}
        {-cursor     TkResource "" 0 frame}
        {-width      Int        0  0 "%d >= 0"}
        {-height     Int        0  0 "%d >= 0"}
    }

    Widget::addmap PagesManager "" :cmd { -width {} -height {} -cursor {} }
}
................................................................................
    Widget::init PagesManager $path $args

    set data(select)   ""
    set data(pages)    {}
    set data(cpt)      0
    set data(realized) 0


    eval canvas $path -relief flat -bd 0 -highlightthickness 0 \
	    [Widget::subcget $path :cmd]

    bind $path <Configure> [list PagesManager::_realize $path]
    bind $path <Destroy>   [list PagesManager::_destroy $path]

    return [Widget::create PagesManager $path]
................................................................................

    if { [lsearch -exact $data(pages) $page] != -1 } {
        return -code error "page \"$page\" already exists"
    }

    lappend data(pages) $page

    BWidget::wrap \
       frame $path.f$page -relief flat \
	    -background [Widget::cget $path -background] -borderwidth 0

    return $path.f$page
}


# ------------------------------------------------------------------------------

Changes to panedw.tcl.

1
2
3

4
5
6
7
8
9
10
..
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
..
68
69
70
71
72
73
74






75
76
77
78
79
80
81
...
379
380
381
382
383
384
385













# ----------------------------------------------------------------------------
#  panedw.tcl
#  This file is part of Unifix BWidget Toolkit

# ----------------------------------------------------------------------------
#  Index of commands:
#     - PanedWindow::create
#     - PanedWindow::configure
#     - PanedWindow::cget
#     - PanedWindow::add
#     - PanedWindow::getframe
................................................................................
        }
    }

    Widget::declare PanedWindow {
        {-side       Enum       top   1 {top left bottom right}}
        {-width      Int        10    1 "%d >=3"}
        {-pad        Int        4     1 "%d >= 0"}
        {-background TkResource ""    0 frame}
        {-bg         Synonym    -background}
        {-activator  Enum       ""    1 {line button}}
	{-weights    Enum       extra 1 {extra available}}
    }

    variable _panedw







}



# ----------------------------------------------------------------------------
#  Command PanedWindow::create
# ----------------------------------------------------------------------------
proc PanedWindow::create { path args } {
    variable _panedw

    Widget::init PanedWindow $path $args



    frame $path -background [Widget::cget $path -background] -class PanedWindow
    set _panedw($path,nbpanes) 0
    set _panedw($path,weights) ""
    set _panedw($path,configuredone) 0

    set activator [Widget::getoption $path -activator]
    if {[string equal $activator ""]} {
        if { $::tcl_platform(platform) != "windows" } {
................................................................................
    }
    if {[string equal [Widget::getoption $path -activator] "line"]} {
        Widget::setMegawidgetOption $path -width 3
    }
    
    bind $path <Configure> [list PanedWindow::_realize $path %w %h]
    bind $path <Destroy>   [list PanedWindow::_destroy $path]







    return [Widget::create PanedWindow $path]
}


# ----------------------------------------------------------------------------
#  Command PanedWindow::configure
................................................................................

    for {set i 0} {$i < $_panedw($path,nbpanes)} {incr i} {
        Widget::destroy $path.f$i
    }
    unset _panedw($path,nbpanes)
    Widget::destroy $path
}















>







 







|






>
>
>
>
>
>
>











>
>

<







 







>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
..
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
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# ----------------------------------------------------------------------------
#  panedw.tcl
#  This file is part of Unifix BWidget Toolkit
#  $Id: panedw.tcl,v 1.15 2009/09/06 21:29:34 oberdorfer Exp $
# ----------------------------------------------------------------------------
#  Index of commands:
#     - PanedWindow::create
#     - PanedWindow::configure
#     - PanedWindow::cget
#     - PanedWindow::add
#     - PanedWindow::getframe
................................................................................
        }
    }

    Widget::declare PanedWindow {
        {-side       Enum       top   1 {top left bottom right}}
        {-width      Int        10    1 "%d >=3"}
        {-pad        Int        4     1 "%d >= 0"}
        {-background Color      "SystemWindowFrame" 0}
        {-bg         Synonym    -background}
        {-activator  Enum       ""    1 {line button}}
	{-weights    Enum       extra 1 {extra available}}
    }

    variable _panedw

    if { [BWidget::using ttk] } {
        if {[lsearch [bindtags .] PanedWThemeChanged] < 0} {
            bindtags . [linsert [bindtags .] 1 PanedWThemeChanged]
        }
    }

}



# ----------------------------------------------------------------------------
#  Command PanedWindow::create
# ----------------------------------------------------------------------------
proc PanedWindow::create { path args } {
    variable _panedw

    Widget::init PanedWindow $path $args
    frame $path -background [Widget::cget $path -background] \
                -class PanedWindow


    set _panedw($path,nbpanes) 0
    set _panedw($path,weights) ""
    set _panedw($path,configuredone) 0

    set activator [Widget::getoption $path -activator]
    if {[string equal $activator ""]} {
        if { $::tcl_platform(platform) != "windows" } {
................................................................................
    }
    if {[string equal [Widget::getoption $path -activator] "line"]} {
        Widget::setMegawidgetOption $path -width 3
    }
    
    bind $path <Configure> [list PanedWindow::_realize $path %w %h]
    bind $path <Destroy>   [list PanedWindow::_destroy $path]

    if { [BWidget::using ttk] } {
        bind PanedWThemeChanged <<ThemeChanged>> \
	       "+[namespace current]::_themechanged $path"
    }


    return [Widget::create PanedWindow $path]
}


# ----------------------------------------------------------------------------
#  Command PanedWindow::configure
................................................................................

    for {set i 0} {$i < $_panedw($path,nbpanes)} {incr i} {
        Widget::destroy $path.f$i
    }
    unset _panedw($path,nbpanes)
    Widget::destroy $path
}


# ----------------------------------------------------------------------------
#  Command PanedWindow::_themechanged
# ----------------------------------------------------------------------------
proc PanedWindow::_themechanged { path } {

    if { ![winfo exists $path] } { return }
    BWidget::set_themedefaults
    
    $path configure \
           -background $BWidget::colors(SystemWindowFrame)
}

Changes to panelframe.tcl.

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



# ----------------------------------------------------------------------------

#  panelframe.tcl

#	Create PanelFrame widgets.

#	A PanelFrame is a boxed frame that allows you to place items

#	in the label area (liked combined frame+toolbar).  It uses the

#	highlight colors the default frame color.

#  $Id: panelframe.tcl,v 1.1 2004/09/09 22:17:51 hobbs Exp $

# ----------------------------------------------------------------------------

#  Index of commands:

#     - PanelFrame::create

#     - PanelFrame::configure

#     - PanelFrame::cget

#     - PanelFrame::getframe

#     - PanelFrame::add

#     - PanelFrame::remove

#     - PanelFrame::items

# ----------------------------------------------------------------------------



namespace eval PanelFrame {

    Widget::define PanelFrame panelframe



    Widget::declare PanelFrame {

	{-background	   TkResource "" 0 frame}

	{-borderwidth	   TkResource 1	 0 frame}

	{-relief	   TkResource flat 0 frame}
	{-panelbackground  TkResource "" 0 {entry -selectbackground}}
	{-panelforeground  TkResource "" 0 {entry -selectforeground}}





	{-width		   Int	      0	 0}

	{-height	   Int	      0	 0}
	{-font		   TkResource "" 0 label}



	{-text		   String     "" 0}

	{-textvariable	   String     "" 0}

	{-ipad		   String      1 0}

	{-bg		   Synonym    -background}

	{-bd		   Synonym    -borderwidth}
    }


    # Should we have automatic state handling?

    #{-state            TkResource "" 0 label}



    Widget::addmap PanelFrame "" :cmd {

	-panelbackground -background

	-width {} -height {} -borderwidth {} -relief {}
    }


    Widget::addmap PanelFrame "" .title	  {

	-panelbackground -background
    }


    Widget::addmap PanelFrame "" .title.text   {

	-panelbackground -background

	-panelforeground -foreground

	-text {} -textvariable {} -font {}
    }


    Widget::addmap PanelFrame "" .frame {

	-background {}
    }




    if {0} {

	# This would be code to have an automated close button

	#{-closebutton	   Boolean    0	 0}

	Widget::addmap PanelFrame "" .title.close   {

	    -panelbackground -background

	    -panelforeground -foreground
	}


	variable HaveMarlett \

	    [expr {[lsearch -exact [font families] "Marlett"] != -1}]



	variable imgdata {

	    #define close_width 16

	    #define close_height 16

	    static char close_bits[] = {

		0x00, 0x00, 0x00, 0x00,

		0x00, 0x00, 0x10, 0x08,

		0x38, 0x1c, 0x70, 0x0e,

		0xe0, 0x07, 0xc0, 0x03,

		0xc0, 0x03, 0xe0, 0x07,

		0x70, 0x0e, 0x38, 0x1c,

		0x10, 0x08, 0x00, 0x00,

		0x00, 0x00, 0x00, 0x00};
	}


	# We use the same -foreground as the default -panelbackground

	image create bitmap ::PanelFrame::X -data $imgdata \

	    -foreground [lindex $Widget::PanelFrame::opt(-panelbackground) 1]
    }




    bind PanelFrame <Destroy> [list Widget::destroy %W]
}






# ----------------------------------------------------------------------------

#  Command PanelFrame::create

# ----------------------------------------------------------------------------

proc PanelFrame::create { path args } {

    variable HaveMarlett



    Widget::init PanelFrame $path $args



    set lblopts [list -bd 0 -highlightthickness 0]

    set outer [eval [list frame $path -class PanelFrame] \

		   [Widget::subcget $path :cmd]]

    set title [eval [list frame $path.title] \

		   [Widget::subcget $path .title]]

    set tlbl  [eval [list label $path.title.text] $lblopts -anchor w \

		   [Widget::subcget $path .title.text]]

    set inner [eval [list frame $path.frame] \

		   [Widget::subcget $path .frame]]



    foreach {ipadx ipady} [_padval [Widget::cget $path -ipad]] { break }



    if {0} {

	set btnopts [list -padx 0 -pady 0 -relief flat -overrelief raised \

			 -bd 1 -highlightthickness 0]

	set clbl  [eval [list button $path.title.close] $btnopts \

		       [Widget::subcget $path .title.close]]

	set close [Widget::cget $path -closebutton]

	if {$HaveMarlett} {

	    $clbl configure -font "Marlett -14" -text \u0072

	} else {

	    $clbl configure -image ::PanelFrame::X
	}


	if {$close} {

	    pack $path.title.close -side right -padx $ipadx -pady $ipady
	}
    }





    grid $path.title -row 0 -column 0 -sticky ew

    grid $path.frame -row 1 -column 0 -sticky news

    grid columnconfigure $path 0 -weight 1

    grid rowconfigure $path 1 -weight 1



    pack $path.title.text -side left -fill x -anchor w \

	-padx $ipadx -pady $ipady



    return [Widget::create PanelFrame $path]
}






# ----------------------------------------------------------------------------

#  Command PanelFrame::configure

# ----------------------------------------------------------------------------

proc PanelFrame::configure { path args } {

    set res [Widget::configure $path $args]



    if {[Widget::hasChanged $path -ipad ipad]} {
    }




    return $res































}


# ----------------------------------------------------------------------------
#  Command PanelFrame::cget
# ----------------------------------------------------------------------------
proc PanelFrame::cget { path option } {
    return [Widget::cget $path $option]
}

# ----------------------------------------------------------------------------
#  Command PanelFrame::getframe
# ----------------------------------------------------------------------------
proc PanelFrame::getframe { path } {
    return $path.frame
}


# ------------------------------------------------------------------------
#  Command PanelFrame::add
# ------------------------------------------------------------------------

proc PanelFrame::add {path w args} {

    variable _widget



    array set opts [list \

			-side   right \

			-fill   none \

			-expand 0 \

			-pad    [Widget::cget $path -ipad] \
		       ]


    foreach {key val} $args {

	if {[info exists opts($key)]} {

	    set opts($key) $val

	} else {

	    set msg "unknown option \"$key\", must be one of: "

	    append msg [join [lsort [array names opts]] {, }]

	    return -code error $msg
	}
    }



    foreach {ipadx ipady} [_padval $opts(-pad)] { break }



    set f $path.title



    lappend _widget($path,items) $w

    pack $w -in $f -padx $ipadx -pady $ipady -side $opts(-side) \

	-fill $opts(-fill) -expand $opts(-expand)



    return $w
}




# ------------------------------------------------------------------------

#  Command PanelFrame::remove

# ------------------------------------------------------------------------

proc PanelFrame::remove {path args} {

    variable _widget



    set destroy [string equal [lindex $args 0] "-destroy"]

    if {$destroy} {

	set args [lrange $args 1 end]
    }


    foreach w $args {

	set idx [lsearch -exact $_widget($path,items) $w]

	if {$idx == -1} {

	    # ignore unknown

	    continue
	}


	if {$destroy} {

	    destroy $w

	} elseif {[winfo exists $w]} {

	    pack forget $w
	}


	set _widget($path,items) [lreplace $_widget($path,items) $idx $idx]
    }
}





# ------------------------------------------------------------------------

#  Command PanelFrame::delete

# ------------------------------------------------------------------------

proc PanelFrame::delete {path args} {

    return [PanelFrame::remove $path -destroy $args]
}




# ------------------------------------------------------------------------

#  Command PanelFrame::items

# ------------------------------------------------------------------------

proc PanelFrame::items {path} {

    variable _widget

    return $_widget($path,items)
}




proc PanelFrame::_padval {padval} {

    set len [llength $padval]

    foreach {a b} $padval { break }

    if {$len == 0 || $len > 2} {

	return -code error \

	    "invalid pad value \"$padval\", must be 1 or 2 pixel values"

    } elseif {$len == 1} {

	return [list $a $a]

    } elseif {$len == 2} {

	return $padval
    }
}



>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
>
>
|
>
|
>
|
>
|
<
<
>
>
>
>
>
|
>
|
<
>
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
>
>
|
>
|
>
|
|
>
>
|
>
|
|
>
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
|
>
>
>
|
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
>
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
>
|
|
|
>
>
>
|
|
|
|
>
>
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
|
>
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
>
>
|
|
>
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
|
|
>
>
>
>
|
>
|
>
|
>
|
|
>
>
|
>
|
|
>
>
|
|
|
|
>
>
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<
<
<
<
<
|
<
|
<
<
<
<
|
>
|
|
<
<
>
|
>
|
|
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
|
>
>
>
|
|
>
>
|
|
>
>
|
>
|
>
|
|
>
>
|
|
|
>
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
>
|
|
>
>
|
>
|
>
|
>
|
>
|
|
>
>
|
>
|
>
|
>
|
|
>
>
|
|
|
|
>
>
>
>
|
>
|
>
|
>
|
>
|
|
|
>
>
>
|
>
|
>
|
>
|
>
|
>
|
|
|
>
>
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
>
|
|
|
>
>
>
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# ----------------------------------------------------------------------------

#  panelframe.tcl

#	Create PanelFrame widgets.

#	A PanelFrame is a boxed frame that allows you to place items

#	in the label area (liked combined frame+toolbar).  It uses the

#	highlight colors the default frame color.

#  $Id: panelframe.tcl,v 1.11 2009/09/06 21:31:16 oberdorfer Exp $

# ----------------------------------------------------------------------------

#  Index of commands:

#     - PanelFrame::create

#     - PanelFrame::configure

#     - PanelFrame::cget

#     - PanelFrame::getframe

#     - PanelFrame::add

#     - PanelFrame::remove

#     - PanelFrame::items

# ----------------------------------------------------------------------------



namespace eval PanelFrame {

    Widget::define PanelFrame panelframe



    Widget::declare PanelFrame {

	{-background	   Color "SystemWindowFrame" 0}

	{-borderwidth	   TkResource 1	 0 frame}

	{-relief	   TkResource flat 0 frame}



	{-panelbackground  Color "SystemHighlight" 0}

	{-panelforeground  Color "SystemHighlightText" 0}

	{-width		   Int	      0	 0}

	{-height	   Int	      0	 0}


	{-font		   String     "TkTextFont" 0}

	{-text		   String     "" 0}

	{-textvariable	   String     "" 0}

	{-ipad		   String      1 0}

	{-bg		   Synonym    -background}

	{-bd		   Synonym    -borderwidth}

    }

    # Should we have automatic state handling?

    #{-state            TkResource "" 0 label}



    Widget::addmap PanelFrame "" :cmd {

	-panelbackground -background

	-width {} -height {} -borderwidth {} -relief {}

    }

    Widget::addmap PanelFrame "" .title	  {

	-panelbackground -background

    }

    Widget::addmap PanelFrame "" .title.text   {

	-panelbackground -background

	-panelforeground -foreground

	-text {} -textvariable {} -font {}

    }

    Widget::addmap PanelFrame "" .frame {

	-background {}

    }



    if {0} {

	# This would be code to have an automated close button

	#{-closebutton	   Boolean    0	 0}

	Widget::addmap PanelFrame "" .title.close   {

	    -panelbackground -background

	    -panelforeground -foreground

	}

	variable HaveMarlett \

	    [expr {[lsearch -exact [font families] "Marlett"] != -1}]



	variable imgdata {

	    #define close_width 16

	    #define close_height 16

	    static char close_bits[] = {

		0x00, 0x00, 0x00, 0x00,

		0x00, 0x00, 0x10, 0x08,

		0x38, 0x1c, 0x70, 0x0e,

		0xe0, 0x07, 0xc0, 0x03,

		0xc0, 0x03, 0xe0, 0x07,

		0x70, 0x0e, 0x38, 0x1c,

		0x10, 0x08, 0x00, 0x00,

		0x00, 0x00, 0x00, 0x00};

	}

	# We use the same -foreground as the default -panelbackground

	image create bitmap ::PanelFrame::X -data $imgdata \

	    -foreground [lindex $Widget::PanelFrame::opt(-panelbackground) 1]

    }



    bind PanelFrame <Destroy> [list Widget::destroy %W]

}





# ----------------------------------------------------------------------------

#  Command PanelFrame::create

# ----------------------------------------------------------------------------

proc PanelFrame::create { path args } {

    variable HaveMarlett



    Widget::init PanelFrame $path $args



    set lblopts [list -bd 0 -highlightthickness 0]

    set outer [eval [list frame $path -class PanelFrame] \

		   [Widget::subcget $path :cmd]]

    set title [eval [list frame $path.title] \

		   [Widget::subcget $path .title]]

    set tlbl  [eval [list label $path.title.text] $lblopts -anchor w \

		   [Widget::subcget $path .title.text]]

    set inner [eval [list frame $path.frame] \

		   [Widget::subcget $path .frame]]



    foreach {ipadx ipady} [_padval [Widget::cget $path -ipad]] { break }



    if {0} {

	set btnopts [list -padx 0 -pady 0 -relief flat -overrelief raised \

			 -bd 1 -highlightthickness 0]

	set clbl  [eval [list button $path.title.close] $btnopts \

		       [Widget::subcget $path .title.close]]

	set close [Widget::cget $path -closebutton]

	if {$HaveMarlett} {

	    $clbl configure -font "Marlett -14" -text \u0072

	} else {

	    $clbl configure -image ::PanelFrame::X

	}

	if {$close} {

	    pack $path.title.close -side right -padx $ipadx -pady $ipady

	}

    }



    grid $path.title -row 0 -column 0 -sticky ew

    grid $path.frame -row 1 -column 0 -sticky news

    grid columnconfigure $path 0 -weight 1

    grid rowconfigure $path 1 -weight 1



    pack $path.title.text -side left -fill x -anchor w \

	-padx $ipadx -pady $ipady



    return [Widget::create PanelFrame $path]

}





# ----------------------------------------------------------------------------

#  Command PanelFrame::configure

# ----------------------------------------------------------------------------

proc PanelFrame::configure { path args } {

    set res [Widget::configure $path $args]



    if {[Widget::hasChanged $path -ipad ipad]} {

    }



    return $res

}





# ----------------------------------------------------------------------------

#  Command PanelFrame::cget

# ----------------------------------------------------------------------------

proc PanelFrame::cget { path option } {

    return [Widget::cget $path $option]

}



# ----------------------------------------------------------------------------

#  Command PanelFrame::getframe

# ----------------------------------------------------------------------------

proc PanelFrame::getframe { path } {

    return $path.frame

}









# ------------------------------------------------------------------------





#  Command PanelFrame::add

# ------------------------------------------------------------------------



proc PanelFrame::add {path w args} {

    variable _widget



    array set opts [list \

			-side   right \

			-fill   none \

			-expand 0 \

			-pad    [Widget::cget $path -ipad] \

		       ]

    foreach {key val} $args {

	if {[info exists opts($key)]} {

	    set opts($key) $val

	} else {

	    set msg "unknown option \"$key\", must be one of: "

	    append msg [join [lsort [array names opts]] {, }]

	    return -code error $msg

	}

    }

    foreach {ipadx ipady} [_padval $opts(-pad)] { break }



    set f $path.title



    lappend _widget($path,items) $w

    pack $w -in $f -padx $ipadx -pady $ipady -side $opts(-side) \

	-fill $opts(-fill) -expand $opts(-expand)



    return $w

}



# ------------------------------------------------------------------------

#  Command PanelFrame::remove

# ------------------------------------------------------------------------

proc PanelFrame::remove {path args} {

    variable _widget



    set destroy [string equal [lindex $args 0] "-destroy"]

    if {$destroy} {

	set args [lrange $args 1 end]

    }

    foreach w $args {

	set idx [lsearch -exact $_widget($path,items) $w]

	if {$idx == -1} {

	    # ignore unknown

	    continue

	}

	if {$destroy} {

	    destroy $w

	} elseif {[winfo exists $w]} {

	    pack forget $w

	}

	set _widget($path,items) [lreplace $_widget($path,items) $idx $idx]

    }

}



# ------------------------------------------------------------------------

#  Command PanelFrame::delete

# ------------------------------------------------------------------------

proc PanelFrame::delete {path args} {

    return [PanelFrame::remove $path -destroy $args]

}



# ------------------------------------------------------------------------

#  Command PanelFrame::items

# ------------------------------------------------------------------------

proc PanelFrame::items {path} {

    variable _widget

    return $_widget($path,items)

}



proc PanelFrame::_padval {padval} {

    set len [llength $padval]

    foreach {a b} $padval { break }

    if {$len == 0 || $len > 2} {

	return -code error \

	    "invalid pad value \"$padval\", must be 1 or 2 pixel values"

    } elseif {$len == 1} {

	return [list $a $a]

    } elseif {$len == 2} {

	return $padval

    }

}