Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "COMPOSITE 1" | |
132 | .TH COMPOSITE 1 "2000-12-30" "perl v5.8.0" "User Contributed Perl Documentation" | |
133 | .SH "NAME" | |
134 | Tk::composite \- Defining a new composite widget class | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 1 | |
138 | \& package Tk::Whatever; | |
139 | .Ve | |
140 | .PP | |
141 | .Vb 3 | |
142 | \& require Tk::Derived; | |
143 | \& require Tk::Frame; # or Tk::Toplevel | |
144 | \& @ISA = qw(Tk::Derived Tk::Frame)'; # or Tk::Toplevel | |
145 | .Ve | |
146 | .PP | |
147 | .Vb 1 | |
148 | \& Construct Tk::Widget 'Whatever'; | |
149 | .Ve | |
150 | .PP | |
151 | .Vb 3 | |
152 | \& sub ClassInit | |
153 | \& { | |
154 | \& my ($class,$mw) = @_; | |
155 | .Ve | |
156 | .PP | |
157 | .Vb 3 | |
158 | \& #... e.g., class bindings here ... | |
159 | \& $class->SUPER::ClassInit($mw); | |
160 | \& } | |
161 | .Ve | |
162 | .PP | |
163 | .Vb 3 | |
164 | \& sub Populate | |
165 | \& { | |
166 | \& my ($cw,$args) = @_; | |
167 | .Ve | |
168 | .PP | |
169 | .Vb 7 | |
170 | \& my $flag = delete $args->{-flag}; | |
171 | \& if (defined $flag) | |
172 | \& { | |
173 | \& # handle -flag => xxx which can only be done at create | |
174 | \& # time the delete above ensures that new() does not try | |
175 | \& # and do $cw->configure(-flag => xxx); | |
176 | \& } | |
177 | .Ve | |
178 | .PP | |
179 | .Vb 1 | |
180 | \& $cw->SUPER::Populate($args); | |
181 | .Ve | |
182 | .PP | |
183 | .Vb 1 | |
184 | \& $w = $cw->Component(...); | |
185 | .Ve | |
186 | .PP | |
187 | .Vb 1 | |
188 | \& $cw->Delegates(...); | |
189 | .Ve | |
190 | .PP | |
191 | .Vb 8 | |
192 | \& $cw->ConfigSpecs( | |
193 | \& '-cursor' => [SELF,'cursor','Cursor',undef], | |
194 | \& '-something' => [METHOD,dbName,dbClass,'default'], | |
195 | \& '-text' => [$label,dbName,dbClass,'default'], | |
196 | \& '-heading' => [{-text=>$head}, | |
197 | \& heading,Heading,'My Heading'], | |
198 | \& ); | |
199 | \& } | |
200 | .Ve | |
201 | .PP | |
202 | .Vb 9 | |
203 | \& sub something | |
204 | \& { | |
205 | \& my ($cw,$value) = @_; | |
206 | \& if (@_ > 1) | |
207 | \& { | |
208 | \& # set it | |
209 | \& } | |
210 | \& return # current value | |
211 | \& } | |
212 | .Ve | |
213 | .PP | |
214 | .Vb 1 | |
215 | \& 1; | |
216 | .Ve | |
217 | .PP | |
218 | .Vb 1 | |
219 | \& __END__ | |
220 | .Ve | |
221 | .PP | |
222 | .Vb 1 | |
223 | \& # Anything not documented is *private* - your POD is god, so to speak. | |
224 | .Ve | |
225 | .PP | |
226 | .Vb 1 | |
227 | \& =head1 NAME | |
228 | .Ve | |
229 | .PP | |
230 | .Vb 1 | |
231 | \& Tk::Whatever - a whatever widget | |
232 | .Ve | |
233 | .PP | |
234 | .Vb 1 | |
235 | \& =head1 SYNOPSIS | |
236 | .Ve | |
237 | .PP | |
238 | .Vb 1 | |
239 | \& use Tk::Whatever; | |
240 | .Ve | |
241 | .PP | |
242 | .Vb 1 | |
243 | \& $widget = $parent->Whatever(...); | |
244 | .Ve | |
245 | .PP | |
246 | .Vb 1 | |
247 | \& =head1 DESCRIPTION | |
248 | .Ve | |
249 | .PP | |
250 | .Vb 1 | |
251 | \& You forgot to document your widget, didn't you? :-) | |
252 | .Ve | |
253 | .PP | |
254 | .Vb 1 | |
255 | \& ... | |
256 | .Ve | |
257 | .SH "DESCRIPTION" | |
258 | .IX Header "DESCRIPTION" | |
259 | The intention behind a composite is to create a higher-level widget, | |
260 | sometimes called a \*(L"super\-widget\*(R" or \*(L"meta\-widget\*(R". Most often, | |
261 | a composite will be | |
262 | built upon other widgets by \fBusing\fR them, as opposed to specializing on them. | |
263 | For example, the supplied composite widget \fBLabEntry\fR is \fImade of\fR an | |
264 | \&\fBEntry\fR and a \fBLabel\fR; it is neither a \fIkind-of\fR \fBLabel\fR | |
265 | nor is it a \fIkind-of\fR \fBEntry\fR. | |
266 | .PP | |
267 | Most of the work of a composite widget consist in creating subwidgets, | |
268 | arrange to dispatch configure options to the proper subwidgets and manage | |
269 | composite-specific configure options. | |
270 | .SH "GLORY DETAILS" | |
271 | .IX Header "GLORY DETAILS" | |
272 | Depending on your perl/Tk knowledget this section may be enlighting | |
273 | or confusing. | |
274 | .Sh "Composite Widget" | |
275 | .IX Subsection "Composite Widget" | |
276 | Since perl/Tk is heavilly using an object-oriented approach, it is no | |
277 | suprise that creating a composite goes through a \fB\f(BInew()\fB\fR method. | |
278 | However, the composite does not normally define a \fB\f(BInew()\fB\fR method | |
279 | itself: it is usually sufficient to simply inherit it from | |
280 | \&\fBTk::Widget\fR. | |
281 | .PP | |
282 | This is what happens when the composite use | |
283 | .PP | |
284 | .Vb 1 | |
285 | \& @ISA = qw(Tk::Frame); # or Tk::Toplevel | |
286 | .Ve | |
287 | .PP | |
288 | to specify its inheritance chain. To complete the initialisation of the | |
289 | widget, it must call the \fBConstruct\fR method from class \fBWidget\fR. That | |
290 | method accepts the name of the new class to create, i.e. the package name | |
291 | of your composite widget: | |
292 | .PP | |
293 | .Vb 1 | |
294 | \& Construct Tk::Widget 'Whatever'; | |
295 | .Ve | |
296 | .PP | |
297 | Here, \fBWhatever\fR is the package name (aka the widget's \fBclass\fR). This | |
298 | will define a constructor method for \fBWhatever\fR, normally named after the | |
299 | widget's class. Instanciating that composite in client code would | |
300 | the look like: | |
301 | .PP | |
302 | .Vb 1 | |
303 | \& $mw = MainWindow->new(); # Creates a top-level main window | |
304 | .Ve | |
305 | .PP | |
306 | .Vb 2 | |
307 | \& $cw = $mw->Whatever(); # Creates an instance of the | |
308 | \& # composite widget Whatever | |
309 | .Ve | |
310 | .PP | |
311 | Whenever a composite is instanciated in client code, | |
312 | \&\f(CW\*(C`Tk::Widget::new()\*(C'\fR will be invoked via the widget's class | |
313 | constructor. That \fBnew\fR method will call | |
314 | .PP | |
315 | .Vb 1 | |
316 | \& $cw->InitObject(\e%args); | |
317 | .Ve | |
318 | .PP | |
319 | where \fI%args\fR is the arguments passed to the widget's constructor. Note | |
320 | that \fBInitObject\fR receives a \fBreference\fR to the hash array | |
321 | containing all arguments. | |
322 | .PP | |
323 | For composite widgets that needs an underlying frame, \fBInitObject\fR | |
324 | will typically be inherited from \fBTk::Frame\fR, that is, no method of | |
325 | this name will appear in the composite package. For composites that | |
326 | don't need a frame, \fBInitObject\fR will typically be defined in the | |
327 | composite class (package). Compare the \fBLabEntry\fR composite with | |
328 | \&\fBOptionmenu\fR: the former is \fBFrame\fR based while the latter is \fBWidget\fR | |
329 | based. | |
330 | .PP | |
331 | In \fBFrame\fR based composites, \fB\f(BITk::Frame::InitObject()\fB\fR will call | |
332 | \&\fB\f(BIPopulate()\fB\fR, which should be defined to create the characteristic | |
333 | subwidgets of the class. | |
334 | .PP | |
335 | \&\fBWidget\fR based composites don't need an extra \fBPopulate\fR layer; they | |
336 | typically have their own \fBInitObject\fR method that will create subwidgets. | |
337 | .Sh "Creating Subwidgets" | |
338 | .IX Subsection "Creating Subwidgets" | |
339 | Subwidget creation happens usually in \fB\f(BIPopulate()\fB\fR (\fBFrame\fR based) | |
340 | or \fB\f(BIInitObject()\fB\fR (\fBWidget\fR based). The composite usually calls the | |
341 | subwidget's constructor method either directly, for \*(L"private\*(R" subwidgets, | |
342 | or indirectly through the \fBComponent\fR method for subwidgets that should | |
343 | be advertised to clients. | |
344 | .PP | |
345 | \&\fBPopulate\fR may call \fBDelegates\fR to direct calls to methods | |
346 | of chosen subwidgets. For simple composites, typically most if not all | |
347 | methods are directed | |
348 | to a single subwidget \- e.g. \fBScrListbox\fR directs all methods to the core | |
349 | \&\fBListbox\fR so that \fI$composite\fR\->\fBget\fR(...) calls | |
350 | \&\fI$listbox\fR\->\fBget\fR(...). | |
351 | .Sh "Further steps for Frame based composites" | |
352 | .IX Subsection "Further steps for Frame based composites" | |
353 | \&\fBPopulate\fR should also call \fB\f(BIConfigSpecs()\fB\fR to specify the | |
354 | way that configure-like options should be handled in the composite. | |
355 | Once \fBPopulate\fR returns, method \fBTk::Frame::ConfigDefault\fR | |
356 | walks through the \fBConfigSpecs\fR entries and populates | |
357 | %$args hash with defaults for options from X resources (\fI.Xdefaults\fR, etc). | |
358 | .PP | |
359 | When \fB\f(BIInitObject()\fB\fR returns to \fB\f(BITk::Widget::new()\fB\fR, | |
360 | a call to \fB$cw\fR\->\fIconfigure\fR(%$args) is made which sets *all* | |
361 | the options. | |
362 | .SH "SEE ALSO" | |
363 | .IX Header "SEE ALSO" | |
364 | Tk::ConfigSpecs | |
365 | Tk::Derived |