1package require tk
2package require tcltest 2.2
3namespace import -force tcltest::*
4loadTestedCommands
5
6test labelframe-1.0 "Setup" -body {
7    pack [ttk::labelframe .lf] -expand true -fill both
8}
9
10test labelframe-2.1 "Can't use indirect descendant as labelwidget" -body {
11    ttk::frame .lf.t
12    ttk::checkbutton .lf.t.cb
13    .lf configure -labelwidget .lf.t.cb
14} -returnCodes error -result "can't *" -match glob \
15  -cleanup { destroy .lf.t } ;
16
17test labelframe-2.2 "Can't use toplevel as labelwidget" -body {
18    toplevel .lf.t
19    .lf configure -labelwidget .lf.t
20} -returnCodes error -result "can't *" -match glob \
21  -cleanup { destroy .lf.t } ;
22
23test labelframe-2.3 "Can't use non-windows as -labelwidget" -body {
24    .lf configure -labelwidget BogusWindowName
25} -returnCodes error -result {bad window path name "BogusWindowName"}
26
27test labelframe-2.4 "Can't use nonexistent-windows as -labelwidget" -body {
28    .lf configure -labelwidget .nosuchwindow
29} -returnCodes error -result {bad window path name ".nosuchwindow"}
30
31
32###
33# See also series labelframe-4.x
34#
35test labelframe-3.1 "Add child content" -body {
36    checkbutton .lf.cb -text "abcde"
37    .lf configure -labelwidget .lf.cb
38    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
39} -result [list 1 labelframe]
40
41test labelframe-3.2 "Remove child content" -body {
42    .lf configure -labelwidget {}
43    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
44} -result [list 0 {}]
45
46test labelframe-3.3 "Re-add child content" -body {
47    .lf configure -labelwidget .lf.cb
48    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
49} -result [list 1 labelframe]
50
51test labelframe-3.4 "Re-manage child content" -body {
52    pack .lf.cb -side right
53    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb] [.lf cget -labelwidget]
54} -result [list 1 pack {}]
55
56test labelframe-3.5 "Re-add child content" -body {
57    .lf configure -labelwidget .lf.cb
58    list [update; winfo viewable .lf.cb] [winfo manager .lf.cb]
59} -result [list 1 labelframe]
60
61test labelframe-3.6 "Destroy child content" -body {
62    destroy .lf.cb
63    .lf cget -labelwidget
64} -result {}
65
66###
67# Re-run series labelframe-3.x with nonchild content.
68#
69# @@@ ODDITY, 14 Nov 2005:
70# @@@ labelframe-4.1 fails if .cb is a [checkbutton],
71# @@@ but seems to succeed if it's some other widget class.
72# @@@ I suspect a race condition; unable to track it down ATM.
73#
74# @@@ FOLLOWUP: This *may* have been caused by a bug in ManagerIdleProc
75# @@@ (see manager.c r1.11). There's still probably a race condition in here.
76#
77test labelframe-4.1 "Add nonchild content" -body {
78    checkbutton .cb -text "abcde"
79    .lf configure -labelwidget .cb
80    update
81    list [winfo ismapped .cb] [winfo viewable .cb] [winfo manager .cb]
82
83} -result [list 1 1 labelframe]
84
85test labelframe-4.2 "Remove nonchild content" -body {
86    .lf configure -labelwidget {}
87    update;
88    list [winfo ismapped .cb] [winfo viewable .cb] [winfo manager .cb]
89} -result [list 0 0 {}]
90
91test labelframe-4.3 "Re-add nonchild content" -body {
92    .lf configure -labelwidget .cb
93    list [update; winfo viewable .cb] [winfo manager .cb]
94} -result [list 1 labelframe]
95
96test labelframe-4.4 "Re-manage nonchild content" -body {
97    pack .cb -side right
98    list [update; winfo viewable .cb] \
99    	[winfo manager .cb] \
100	[.lf cget -labelwidget]
101} -result [list 1 pack {}]
102
103test labelframe-4.5 "Re-add nonchild content" -body {
104    .lf configure -labelwidget .cb
105    list [update; winfo viewable .cb] \
106    	[winfo manager .cb] \
107	[.lf cget -labelwidget]
108} -result [list 1 labelframe .cb]
109
110test labelframe-4.6 "Destroy nonchild content" -body {
111    destroy .cb
112    .lf cget -labelwidget
113} -result {}
114
115test labelframe-5.0 "Cleanup" -body {
116    destroy .lf
117}
118
119# 1342876 -- labelframe should raise sibling -labelwidget above self.
120#
121test labelframe-6.1 "Stacking order" -body {
122    toplevel .t
123    pack [ttk::checkbutton .t.x1]
124    pack [ttk::labelframe .t.lf -labelwidget [ttk::label .t.lb]]
125    pack [ttk::checkbutton .t.x2]
126    winfo children .t
127} -cleanup {
128    destroy .t
129} -result [list .t.x1 .t.lf .t.lb .t.x2]
130
131test labelframe-7.1 "style command" -body {
132    ttk::labelframe .w
133    list [.w cget -style] [.w style] [winfo class .w]
134} -cleanup {
135    destroy .w
136} -result {{} TLabelframe TLabelframe}
137test labelframe-7.2 "style command" -body {
138    ttk::style configure customStyle.TLabelframe
139    ttk::labelframe .w -style customStyle.TLabelframe
140    list [.w cget -style] [.w style] [winfo class .w]
141} -cleanup {
142    destroy .w
143} -result {customStyle.TLabelframe customStyle.TLabelframe TLabelframe}
144
145tcltest::cleanupTests
146