1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: GroupEntry - widget containing a group of controls |
---|
3 | # |
---|
4 | # This widget represents a <group> entry on a control panel. |
---|
5 | # It contains a series of other controls. Sort of a glorified |
---|
6 | # frame widget. |
---|
7 | # ====================================================================== |
---|
8 | # AUTHOR: Michael McLennan, Purdue University |
---|
9 | # Copyright (c) 2004-2005 |
---|
10 | # Purdue Research Foundation, West Lafayette, IN |
---|
11 | # ====================================================================== |
---|
12 | package require Itk |
---|
13 | |
---|
14 | option add *GroupEntry.headingBackground #cccccc widgetDefault |
---|
15 | option add *GroupEntry.headingForeground white widgetDefault |
---|
16 | option add *GroupEntry.font -*-helvetica-medium-r-normal-*-*-120-* widgetDefault |
---|
17 | |
---|
18 | itcl::class Rappture::GroupEntry { |
---|
19 | inherit itk::Widget |
---|
20 | |
---|
21 | itk_option define -heading heading Heading 1 |
---|
22 | |
---|
23 | constructor {owner path args} { # defined below } |
---|
24 | |
---|
25 | public method value {args} |
---|
26 | |
---|
27 | public method label {} |
---|
28 | public method tooltip {} |
---|
29 | |
---|
30 | protected method _fixheading {} |
---|
31 | |
---|
32 | private variable _owner "" ;# thing managing this control |
---|
33 | private variable _path "" ;# path in XML to this number |
---|
34 | } |
---|
35 | |
---|
36 | itk::usual GroupEntry { |
---|
37 | keep -cursor -font |
---|
38 | keep -foreground -background |
---|
39 | keep -textbackground |
---|
40 | keep -selectbackground -selectforeground -selectborderwidth |
---|
41 | } |
---|
42 | |
---|
43 | # ---------------------------------------------------------------------- |
---|
44 | # CONSTRUCTOR |
---|
45 | # ---------------------------------------------------------------------- |
---|
46 | itcl::body Rappture::GroupEntry::constructor {owner path args} { |
---|
47 | if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { |
---|
48 | error "bad object \"$owner\": should be Rappture::ControlOwner" |
---|
49 | } |
---|
50 | set _owner $owner |
---|
51 | set _path $path |
---|
52 | |
---|
53 | itk_component add heading { |
---|
54 | ::label $itk_interior.heading -anchor w |
---|
55 | } { |
---|
56 | usual |
---|
57 | rename -background -headingbackground headingBackground Background |
---|
58 | rename -foreground -headingforeground headingForeground Foreground |
---|
59 | } |
---|
60 | |
---|
61 | $itk_component(heading) configure \ |
---|
62 | -text [$_owner xml get $_path.about.label] |
---|
63 | Rappture::Tooltip::for $itk_component(heading) \ |
---|
64 | [$_owner xml get $_path.about.description] |
---|
65 | |
---|
66 | itk_component add outline { |
---|
67 | frame $itk_interior.outline -borderwidth 1 |
---|
68 | } { |
---|
69 | usual |
---|
70 | ignore -borderwidth |
---|
71 | rename -background -headingbackground headingBackground Background |
---|
72 | } |
---|
73 | pack $itk_component(outline) -expand yes -fill both |
---|
74 | |
---|
75 | itk_component add inner { |
---|
76 | frame $itk_component(outline).inner -borderwidth 3 |
---|
77 | } { |
---|
78 | usual |
---|
79 | ignore -borderwidth |
---|
80 | } |
---|
81 | pack $itk_component(inner) -expand yes -fill both |
---|
82 | |
---|
83 | eval itk_initialize $args |
---|
84 | } |
---|
85 | |
---|
86 | # ---------------------------------------------------------------------- |
---|
87 | # USAGE: value ?-check? ?<newval>? |
---|
88 | # |
---|
89 | # Clients use this to query/set the value for this widget. With |
---|
90 | # no args, it returns the current value for the widget. If the |
---|
91 | # <newval> is specified, it sets the value of the widget and |
---|
92 | # sends a <<Value>> event. If the -check flag is included, the |
---|
93 | # new value is not actually applied, but just checked for correctness. |
---|
94 | # ---------------------------------------------------------------------- |
---|
95 | itcl::body Rappture::GroupEntry::value {args} { |
---|
96 | # groups have no value |
---|
97 | return "" |
---|
98 | } |
---|
99 | |
---|
100 | # ---------------------------------------------------------------------- |
---|
101 | # USAGE: label |
---|
102 | # |
---|
103 | # Clients use this to query the label associated with this widget. |
---|
104 | # Reaches into the XML and pulls out the appropriate label string. |
---|
105 | # ---------------------------------------------------------------------- |
---|
106 | itcl::body Rappture::GroupEntry::label {} { |
---|
107 | return "" ;# manage the label inside this group |
---|
108 | } |
---|
109 | |
---|
110 | # ---------------------------------------------------------------------- |
---|
111 | # USAGE: tooltip |
---|
112 | # |
---|
113 | # Clients use this to query the tooltip associated with this widget. |
---|
114 | # Reaches into the XML and pulls out the appropriate description |
---|
115 | # string. Returns the string that should be used with the |
---|
116 | # Rappture::Tooltip facility. |
---|
117 | # ---------------------------------------------------------------------- |
---|
118 | itcl::body Rappture::GroupEntry::tooltip {} { |
---|
119 | return [$_owner xml get $_path.about.description] |
---|
120 | } |
---|
121 | |
---|
122 | # ---------------------------------------------------------------------- |
---|
123 | # CONFIGURATION OPTION: -heading |
---|
124 | # Turns the heading bar at the top of this group on/off. |
---|
125 | # ---------------------------------------------------------------------- |
---|
126 | itcl::configbody Rappture::GroupEntry::heading { |
---|
127 | if {![string is boolean -strict $itk_option(-heading)]} { |
---|
128 | error "bad value \"$itk_option(-heading)\": should be boolean" |
---|
129 | } |
---|
130 | |
---|
131 | set str [$itk_component(heading) cget -text] |
---|
132 | if {$itk_option(-heading) && "" != $str} { |
---|
133 | eval pack forget [pack slaves $itk_component(hull)] |
---|
134 | pack $itk_component(heading) -side top -fill x |
---|
135 | pack $itk_component(outline) -expand yes -fill both |
---|
136 | $itk_component(outline) configure -borderwidth 1 |
---|
137 | $itk_component(inner) configure -borderwidth 3 |
---|
138 | } else { |
---|
139 | pack forget $itk_component(heading) |
---|
140 | $itk_component(outline) configure -borderwidth 0 |
---|
141 | $itk_component(inner) configure -borderwidth 0 |
---|
142 | } |
---|
143 | } |
---|