home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Xt / CH03 < prev    next >
Encoding:
Text File  |  1991-08-27  |  22.8 KB  |  759 lines

  1. .\" $XConsortium: CH03,v 1.8 91/08/27 10:00:40 swick Exp $
  2. .\"
  3. .\" Copyright 1985, 1986, 1987, 1988, 1991
  4. .\" Massachusetts Institute of Technology, Cambridge, Massachusetts,
  5. .\" and Digital Equipment Corporation, Maynard, Massachusetts.
  6. .\"
  7. .\" Permission to use, copy, modify and distribute this documentation for any
  8. .\" purpose and without fee is hereby granted, provided that the above copyright
  9. .\" notice appears in all copies and that both that copyright notice and this
  10. .\" permission notice appear in supporting documentation, and that the name of
  11. .\" M.I.T. or Digital not be used in in advertising or publicity pertaining
  12. .\" to distribution of the software without specific, written prior permission.
  13. .\" M.I.T and Digital makes no representations about the suitability of the
  14. .\" software described herein for any purpose.
  15. .\" It is provided ``as is'' without express or implied warranty.
  16. \&
  17. .sp 1
  18. .ce 3
  19. \s+1\fBChapter 3\fP\s-1
  20.  
  21. \s+1\fBComposite Widgets and Their Children\fP\s-1
  22. .sp 2
  23. .nr H1 3
  24. .nr H2 0
  25. .nr H3 0
  26. .nr H4 0
  27. .nr H5 0
  28. .LP
  29. .XS
  30. Chapter 3 \- Composite Widgets and Their Children
  31. .XE
  32. .IN "Composite widgets"
  33. Composite widgets (widgets whose class is a subclass of 
  34. .PN compositeWidgetClass )
  35. can have an arbitrary number of children.
  36. Consequently, they are responsible for much more than primitive widgets.
  37. Their responsibilities (either implemented directly by the widget class
  38. or indirectly by \*(xI functions) include
  39. .IP \(bu 5
  40. Overall management of children from creation to destruction.
  41. .IP \(bu 5
  42. Destruction of descendants when the composite widget is destroyed.
  43. .IP \(bu 5
  44. Physical arrangement (geometry management) of a displayable subset of
  45. children (that is, the managed children).
  46. .IP \(bu 5
  47. Mapping and unmapping of a subset of the managed children.
  48. .LP
  49. Overall management is handled by the generic procedures
  50. .PN XtCreateWidget
  51. and
  52. .PN XtDestroyWidget .
  53. .PN XtCreateWidget
  54. adds children to their parent by calling the parent's insert_child
  55. procedure.
  56. .PN XtDestroyWidget
  57. removes children from their parent by calling the parent's delete_child
  58. procedure and ensures that all children of a destroyed composite widget
  59. also get destroyed.
  60. .LP
  61. Only a subset of the total number of children is actually managed by
  62. the geometry manager and hence possibly visible.
  63. For example, a composite editor widget
  64. supporting multiple editing buffers might allocate one child
  65. widget for each file buffer,
  66. but it might only display a small number of the existing buffers.
  67. Widgets that are in this displayable subset are called managed widgets
  68. and enter into geometry manager calculations.
  69. The other children are called unmanaged widgets
  70. and, by definition, are not mapped by the \*(xI.
  71. .LP
  72. Children are added to and removed from their parent's managed set by using
  73. .PN XtManageChild ,
  74. .PN XtManageChildren ,
  75. .PN XtUnmanageChild ,
  76. and
  77. .PN XtUnmanageChildren ,
  78. which notify the parent to recalculate the physical layout of its children
  79. by calling the parent's change_managed procedure.
  80. The 
  81. .PN XtCreateManagedWidget
  82. convenience function calls
  83. .PN XtCreateWidget
  84. and
  85. .PN XtManageChild
  86. on the result.
  87. .LP
  88. Most managed children are mapped,
  89. but some widgets can be in a state where they take up physical space
  90. but do not show anything.
  91. Managed widgets are not mapped automatically
  92. if their \fImap_when_managed\fP field is 
  93. .PN False .
  94. The default is 
  95. .PN True 
  96. and is changed by using
  97. .PN XtSetMappedWhenManaged .
  98. .LP
  99. Each composite widget class declares a geometry manager,
  100. which is responsible for figuring out where the managed children
  101. should appear within the composite widget's window.
  102. Geometry management techniques fall into four classes:
  103. .IP "Fixed boxes" 1.6i
  104. Fixed boxes have a fixed number of children created by the parent.
  105. All these children are managed,
  106. and none ever makes geometry manager requests.
  107. .IP "Homogeneous boxes" 1.6i
  108. Homogeneous boxes treat all children equally and apply the same geometry
  109. constraints to each child.
  110. Many clients insert and delete widgets freely.
  111. .IP "Heterogeneous boxes" 1.6i
  112. Heterogeneous boxes have a specific location where each child is placed.
  113. This location usually is not specified in pixels,
  114. because the window may be resized, but is expressed rather
  115. in terms of the relationship between a child
  116. and the parent or between the child and other specific children.
  117. The class of heterogeneous boxes is usually a subclass of
  118. Constraint .
  119. .IP "Shell boxes" 1.6i
  120. Shell boxes typically have only one child,
  121. and the child's size is usually
  122. exactly the size of the shell.
  123. The geometry manager must communicate with the window manager, if it exists,
  124. and the box must also accept
  125. .PN ConfigureNotify
  126. events when the window size is changed by the window manager.
  127.  
  128. .NH 2
  129. Addition of Children to a Composite Widget: the insert_child Procedure
  130. .XS
  131. \*(SN Addition of Children to a Composite Widget: the insert_child Procedure
  132. .XE
  133. .LP
  134. .IN "insert_child procedure"
  135. To add a child to
  136. the parent's list of children, the
  137. .PN XtCreateWidget
  138. function calls the parent's class routine insert_child.
  139. The insert_child procedure pointer in a composite widget is of type
  140. .PN XtWidgetProc .
  141. .IN "insert_child procedure" "" "@DEF@"
  142. .FD 0
  143. typedef void (*XtWidgetProc)(Widget);
  144. .br
  145.       Widget \fIw\fP;
  146. .FN
  147. .IP \fIw\fP 1i
  148. Passes the newly created child.
  149. .LP
  150. Most composite widgets inherit their superclass's operation.
  151. The insert_child routine in
  152. .PN CompositeWidgetClass calls the insert_position procedure
  153. and inserts the child at the specified position
  154. in the \fIchildren\fP list, expanding it if necessary.
  155. .LP
  156. Some composite widgets define their own insert_child routine
  157. so that they can order their children in some convenient way,
  158. create companion controller widgets for a new widget,
  159. or limit the number or class of their child widgets.
  160. A composite widget class that wishes
  161. to allow nonwidget children (see Chapter 12) must specify a
  162. .PN CompositeClassExtension
  163. extension record as described
  164. in section 1.4.2.1 and set the \fIaccepts_objects\fP field in this record to
  165. .PN True .
  166. If the
  167. .PN CompositeClassExtension
  168. record is not specified or the
  169. \fIaccepts_objects\fP field is
  170. .PN False ,
  171. the composite widget can assume that all its children are of a subclass of Core
  172. without an explicit subclass test in the insert_child procedure.
  173. .LP
  174. If there is not enough room to insert a new child in the \fIchildren\fP array
  175. (that is, \fInum_children\fP is equal to \fInum_slots\fP),
  176. the insert_child procedure must first reallocate the array
  177. and update \fInum_slots\fP.
  178. The insert_child procedure then places the child at the appropriate position
  179. in the array and increments the \fInum_children\fP field.
  180.  
  181. .NH 2
  182. Insertion Order of Children: the insert_position Procedure
  183. .XS
  184. \fB\*(SN Insertion Order of Children: the insert_position Procedure\fP
  185. .XE
  186. .LP
  187. Instances of composite widgets sometimes need to specify more about the order in which
  188. their children are kept.
  189. For example,
  190. an application may want a set of command buttons in some logical order
  191. grouped by function,
  192. and it may want buttons that represent file names to be kept
  193. in alphabetical order without constraining the order in which the
  194. buttons are created.
  195. .LP
  196. An application controls the presentation order of a set of children by
  197. supplying an
  198. .IN XtNinsertPosition
  199. XtNinsertPosition
  200. resource.
  201. The insert_position procedure pointer in a composite widget instance is of type
  202. .PN XtOrderProc .
  203. .IN "XtOrderProc" "" "@DEF@"
  204. .FD 0
  205. typedef Cardinal (*XtOrderProc)(Widget);
  206. .br
  207.       Widget \fIw\fP;
  208. .FN
  209. .IP \fIw\fP 1i
  210. Passes the newly created widget.
  211. .LP
  212. Composite widgets that allow clients to order their children (usually
  213. homogeneous boxes) can call their widget instance's insert_position
  214. procedure from the class's insert_child procedure to determine where a new
  215. child should go in its \fIchildren\fP array.
  216. Thus, a client using a composite class can apply different sorting criteria
  217. to widget instances of the class, passing in a different insert_position
  218. procedure resource when it creates each composite widget instance.
  219. .LP
  220. The return value of the insert_position procedure
  221. indicates how many children should go before the widget.
  222. Returning zero indicates that the widget should go before all other children,
  223. and returning \fInum_children\fP indicates that it should go after all other children.
  224. The default insert_position function returns \fInum_children\fP
  225. and can be overridden by a specific composite widget's resource list
  226. or by the argument list provided when the composite widget is created.
  227.  
  228. .NH 2
  229. Deletion of Children: the delete_child Procedure
  230. .XS
  231. \*(SN Deletion of Children: the delete_child Procedure
  232. .XE
  233. .LP
  234. .IN "delete_child procedure"
  235. .LP
  236. To remove the child from the parent's \fIchildren\fP list, the
  237. .PN XtDestroyWidget
  238. function eventually causes a call to the Composite parent's class delete_child
  239. procedure.
  240. The delete_child procedure pointer is of type
  241. .PN XtWidgetProc .
  242. .FD 0
  243. typedef void (*XtWidgetProc)(Widget);
  244. .br
  245.       Widget \fIw\fP;
  246. .FN
  247. .IP \fIw\fP
  248. Passes the child being deleted.
  249. .LP
  250. Most widgets inherit the delete_child procedure from their superclass.
  251. Composite widgets that create companion widgets define their own
  252. delete_child procedure to remove these companion widgets.
  253.  
  254. .NH 2
  255. Adding and Removing Children from the Managed Set
  256. .XS
  257. \fB\*(SN Adding and Removing Children from the Managed Set\fP
  258. .XE
  259. .LP
  260. The \*(xI provide a set of generic routines to permit the addition of
  261. widgets to or the removal of widgets from a composite widget's managed set.
  262. .IN "change_managed procedure"
  263. These generic routines eventually call the composite widget's change_managed
  264. procedure if the procedure pointer is non-NULL.
  265. The change_managed procedure pointer is of type
  266. .PN XtWidgetProc .
  267. The widget argument specifies the composite widget whose managed child
  268. set has been modified.
  269.  
  270. .NH 3
  271. Managing Children
  272. .XS
  273. \fB\*(SN Managing Children\fP
  274. .XE
  275. .LP
  276. To add a list of widgets to the geometry-managed (and hence displayable)
  277. subset of their Composite parent, use
  278. .PN XtManageChildren .
  279. .IN "XtManageChildren" "" "@DEF@"
  280. .FD 0
  281. typedef Widget *WidgetList;
  282. .sp
  283. void XtManageChildren(\fIchildren\fP, \fInum_children\fP)
  284. .br
  285.       WidgetList \fIchildren\fP;
  286. .br
  287.       Cardinal \fInum_children\fP;
  288. .FN
  289. .IP \fIchildren\fP 1i
  290. Specifies a list of child widgets.  Each child must be of class
  291. RectObj or any subclass thereof.
  292. .IP \fInum_children\fP 1i
  293. Specifies the number of children in the list.
  294. .LP
  295. The
  296. .PN XtManageChildren
  297. function performs the following:
  298. .IP \(bu 5
  299. Issues an error if the children do not all have the same parent or
  300. if the parent's class is not a subclass of 
  301. .PN compositeWidgetClass .
  302. .IP \(bu 5
  303. Returns immediately if the common parent is being destroyed;
  304. otherwise, for each unique child on the list,
  305. .PN XtManageChildren
  306. ignores the child if it already is managed or is being destroyed,
  307. and marks it if not.
  308. .IP \(bu 5
  309. If the parent is realized and after all children have been marked,
  310. it makes some of the newly managed children viewable:
  311. .RS
  312. .IP \- 5
  313. Calls the change_managed routine of the widgets' parent.
  314. .IP \- 5
  315. Calls
  316. .PN XtRealizeWidget
  317. on each previously unmanaged child that is unrealized.
  318. .IP \- 5
  319. Maps each previously unmanaged child that has \fImap_when_managed\fP 
  320. .PN True .
  321. .RE
  322. .LP
  323. Managing children is independent of the ordering of children and
  324. independent of creating and deleting children.
  325. The layout routine of the parent
  326. should consider children whose \fImanaged\fP field is
  327. .PN True 
  328. and should ignore all other children.
  329. Note that some composite widgets, especially fixed boxes, call
  330. .PN XtManageChild
  331. from their insert_child procedure.
  332. .LP
  333. If the parent widget is realized,
  334. its change_managed procedure is called to notify it
  335. that its set of managed children has changed.
  336. The parent can reposition and resize any of its children.
  337. It moves each child as needed by calling 
  338. .PN XtMoveWidget ,
  339. which first updates the \fIx\fP and \fIy\fP fields and which then calls
  340. .PN XMoveWindow .
  341. .LP
  342. If the composite widget wishes to change the size or border width of any of
  343. its children, it calls 
  344. .PN XtResizeWidget ,
  345. which first updates the
  346. \fIwidth\fP, \fIheight\fP, and \fIborder_width\fP
  347. fields and then calls
  348. .PN XConfigureWindow .
  349. Simultaneous repositioning and resizing may be done with
  350. .PN XtConfigureWidget ;
  351. see Section 6.6.
  352. .sp
  353. .LP
  354. To add a single child to its parent widget's set of managed children, use
  355. .PN XtManageChild .
  356. .IN "XtManageChild" "" "@DEF@"
  357. .FD 0
  358. void XtManageChild(\fIchild\fP)
  359. .br
  360.       Widget \fIchild\fP;
  361. .FN
  362. .IP \fIchild\fP 1i
  363. Specifies the child.  \*(rI
  364. .LP
  365. The
  366. .PN XtManageChild
  367. function constructs a
  368. .PN WidgetList
  369. of length 1 and calls
  370. .PN XtManageChildren .
  371. .sp
  372. .LP
  373. To create and manage a child widget in a single procedure, use
  374. .PN XtCreateManagedWidget
  375. or
  376. .PN XtVaCreateManagedWidget .
  377. .IN "XtCreateManagedWidget" "" "@DEF@"
  378. .FD 0
  379. Widget XtCreateManagedWidget(\fIname\fP, \fIwidget_class\fP, \fIparent\fP, \
  380. \fIargs\fP, \fInum_args\fP)
  381. .br
  382.       String \fIname\fP;
  383. .br
  384.       WidgetClass \fIwidget_class\fP;
  385. .br
  386.       Widget \fIparent\fP;
  387. .br
  388.       ArgList \fIargs\fP;
  389. .br
  390.       Cardinal \fInum_args\fP;
  391. .FN
  392. .IP \fIname\fP 1i
  393. Specifies the resource instance name for the created widget.
  394. .IP \fIwidget_class\fP 1i
  395. Specifies the widget class pointer for the created widget.  \*(rC
  396. .IP \fIparent\fP 1i
  397. Specifies the parent widget.  Must be of class Composite or any
  398. subclass thereof.
  399. .IP \fIargs\fP 1i
  400. Specifies the argument list to override any other resource specifications.
  401. .IP \fInum_args\fP 1i
  402. Specifies the number of entries in the argument list.
  403. .LP
  404. The
  405. .PN XtCreateManagedWidget
  406. function is a convenience routine that calls
  407. .PN XtCreateWidget
  408. and
  409. .PN XtManageChild .
  410. .sp
  411. .LP
  412. .IN "XtVaCreateManagedWidget" "" "@DEF@"
  413. .FD 0
  414. Widget XtVaCreateManagedWidget(\fIname\fP, \fIwidget_class\fP, \fIparent\fP, ...)
  415. .br
  416.       String \fIname\fP;
  417. .br
  418.       WidgetClass \fIwidget_class\fP;
  419. .br
  420.       Widget \fIparent\fP;
  421. .FN
  422. .IP \fIname\fP 1i
  423. Specifies the resource instance name for the created widget.
  424. .IP \fIwidget_class\fP 1i
  425. Specifies the widget class pointer for the created widget.  \*(rC
  426. .IP \fIparent\fP 1i
  427. Specifies the parent widget.  Must be of class Composite or any
  428. subclass thereof.
  429. .IP ... 1i
  430. Specifies the variable argument list to override any other
  431. resource specifications.
  432. .LP
  433. .PN XtVaCreateManagedWidget
  434. is identical in function to
  435. .PN XtCreateManagedWidget
  436. with the \fIargs\fP and \fInum_args\fP parameters replaced
  437. by a varargs list, as described in Section 2.5.1.
  438.  
  439. .NH 3
  440. Unmanaging Children
  441. .XS
  442. \fB\*(SN Unmanaging Children\fP
  443. .XE
  444. .LP
  445. To remove a list of children from a parent widget's managed list, use
  446. .PN XtUnmanageChildren .
  447. .IN "XtUnmanageChildren" "" "@DEF@"
  448. .FD 0
  449. void XtUnmanageChildren(\fIchildren\fP, \fInum_children\fP)
  450. .br
  451.       WidgetList \fIchildren\fP;
  452. .br
  453.       Cardinal \fInum_children\fP;
  454. .FN
  455. .IP \fIchildren\fP 1i
  456. Specifies a list of child widgets.  Each child must be of class
  457. RectObj or any subclass thereof.
  458. .IP \fInum_children\fP 1i
  459. Specifies the number of children.
  460. .LP
  461. The
  462. .PN XtUnmanageChildren
  463. function performs the following:
  464. .IP \(bu 5
  465. Issues an error if the children do not all have the same parent
  466. or if the parent is not a subclass of 
  467. .PN compositeWidgetClass .
  468. .IP \(bu 5
  469. Returns immediately if the common parent is being destroyed;
  470. otherwise, for each unique child on the list, 
  471. .PN XtUnmanageChildren
  472. performs the following:
  473. .RS
  474. .IP \- 5
  475. Ignores the child if it already is unmanaged or is being destroyed,
  476. and marks it if not.
  477. .IP \- 5
  478. If the child is realized,
  479. it makes it nonvisible by unmapping it.
  480. .RE
  481. .IP \(bu 5
  482. Calls the change_managed routine of the widgets' parent
  483. after all children have been marked
  484. if the parent is realized.
  485. .LP
  486. .PN XtUnmanageChildren
  487. does not destroy the child widgets.
  488. Removing widgets from a parent's managed set is often a temporary banishment,
  489. and some time later the client may manage the children again.
  490. To destroy widgets entirely,
  491. .PN XtDestroyWidget
  492. should be called instead;
  493. see Section 2.9.
  494. .sp
  495. .LP
  496. To remove a single child from its parent widget's managed set, use
  497. .PN XtUnmanageChild .
  498. .IN "XtUnmanageChild" "" "@DEF@"
  499. .FD 0
  500. void XtUnmanageChild(\fIchild\fP)
  501. .br
  502.       Widget \fIchild\fP;
  503. .FN
  504. .IP \fIchild\fP 1i
  505. Specifies the child.  \*(rI
  506. .LP
  507. The
  508. .PN XtUnmanageChild
  509. function constructs a widget list
  510. of length 1 and calls
  511. .PN XtUnmanageChildren .
  512. .LP
  513. These functions are low-level routines that are used by generic
  514. composite widget building routines.
  515. In addition, composite widgets can provide widget-specific,
  516. high-level convenience procedures.
  517.  
  518. .NH 3
  519. Determining If a Widget Is Managed
  520. .XS
  521. \fB\*(SN Determining If a Widget Is Managed\fP
  522. .XE
  523. .LP
  524. To determine the managed state of a given child widget, use
  525. .PN XtIsManaged .
  526. .IN "XtIsManaged" "" "@DEF@"
  527. .FD 0
  528. Boolean XtIsManaged(\fIw\fP)
  529. .br
  530.        Widget \fIw\fP\^;
  531. .FN
  532. .IP \fIw\fP 1i
  533. Specifies the widget.  \*(oI
  534. .LP
  535. The
  536. .PN XtIsManaged
  537. function returns
  538. .PN True
  539. if the specified widget is of class RectObj or any subclass thereof
  540. and is managed, or
  541. .PN False
  542. otherwise.
  543.  
  544. .NH 2
  545. Controlling When Widgets Get Mapped
  546. .XS
  547. \fB\*(SN Controlling When Widgets Get Mapped\fP
  548. .XE
  549. .LP
  550. A widget is normally mapped if it is managed.
  551. However,
  552. this behavior can be overridden by setting the XtNmappedWhenManaged resource
  553. for the widget when it is created
  554. or by setting the \fImap_when_managed\fP field to 
  555. .PN False .
  556. .sp
  557. .LP
  558. To change the value of a given widget's \fImap_when_managed\fP field, use
  559. .PN XtSetMappedWhenManaged .
  560. .IN "XtSetMappedWhenManaged" "" "@DEF@"
  561. .FD 0
  562. void XtSetMappedWhenManaged(\fIw\fP, \fImap_when_managed\fP)
  563. .br
  564.       Widget \fIw\fP;
  565. .br
  566.       Boolean \fImap_when_managed\fP;
  567. .FN
  568. .IP \fIw\fP 1i
  569. Specifies the widget.  \*(cI
  570. .IP \fImap_when_managed\fP 1i
  571. Specifies a Boolean value that indicates the new value
  572. that is stored into the widget's \fImap_when_managed\fP 
  573. field.
  574. .LP
  575. If the widget is realized and managed
  576. and if \fImap_when_managed\fP is 
  577. .PN True ,
  578. .PN XtSetMappedWhenManaged
  579. maps the window.
  580. If the widget is realized and managed
  581. and if \fImap_when_managed\fP is 
  582. .PN False ,
  583. it unmaps the window.
  584. .PN XtSetMappedWhenManaged
  585. is a convenience function that is equivalent to (but slightly faster than)
  586. calling
  587. .PN XtSetValues
  588. and setting the new value for the XtNmappedWhenManaged resource
  589. then mapping the widget as appropriate.
  590. As an alternative to using
  591. .PN XtSetMappedWhenManaged
  592. to control mapping,
  593. a client may set \fImapped_when_managed\fP to
  594. .PN False
  595. and use
  596. .PN XtMapWidget
  597. and
  598. .PN XtUnmapWidget
  599. explicitly.
  600. .sp
  601. .LP
  602. To map a widget explicitly, use
  603. .PN XtMapWidget .
  604. .IN "XtMapWidget" "" "@DEF@"
  605. .FD 0
  606. XtMapWidget(\fIw\fP)
  607. .br
  608.      Widget \fIw\fP\^;
  609. .FN
  610. .IP \fIw\fP 1i
  611. Specifies the widget.  \*(cI
  612. .LP
  613. .sp
  614. To unmap a widget explicitly, use
  615. .PN XtUnmapWidget .
  616. .IN "XtUnmapWidget" "" "@DEF@"
  617. .FD 0
  618. XtUnmapWidget(\fIw\fP)
  619. .br
  620.      Widget \fIw\fP\^;
  621. .FN
  622. .IP \fIw\fP 1i
  623. Specifies the widget.  \*(cI
  624.  
  625. .NH 2
  626. Constrained Composite Widgets
  627. .XS
  628. \*(SN Constrained Composite Widgets
  629. .XE
  630. .LP
  631. The Constraint 
  632. widget class is a subclass of
  633. .PN compositeWidgetClass .
  634. The name is derived from the fact that constraint widgets
  635. may manage the geometry 
  636. of their children based on constraints associated with each child.
  637. These constraints can be as simple as the maximum width and height 
  638. the parent will allow the child to occupy or can be as complicated as
  639. how other children should change if this child is moved or resized.
  640. Constraint
  641. widgets let a parent define constraints as resources that are supplied for their children.
  642. For example, if the
  643. Constraint
  644. parent defines the maximum sizes for its children,
  645. these new size resources are retrieved for each child as if they were
  646. resources that were defined by the child widget's class.
  647. Accordingly,
  648. constraint resources may be included in the argument list or resource file just
  649. like any other resource for the child.
  650. .LP
  651. Constraint 
  652. widgets have all the responsibilities of normal composite widgets
  653. and, in addition, must process and act upon the constraint information
  654. associated with each of their children.
  655. .LP
  656. To make it easy for widgets and the \*(xI to keep track of the
  657. constraints associated with a child, 
  658. every widget has a \fIconstraints\fP field,
  659. which is the address of a parent-specific structure that contains
  660. constraint information about the child.
  661. If a child's parent does not belong to a subclass of
  662. .PN constraintWidgetClass ,
  663. then the child's \fIconstraints\fP field is NULL.
  664. .LP
  665. Subclasses of
  666. Constraint 
  667. can add constraint data to the constraint record defined by their superclass.
  668. To allow this, widget writers should define the constraint
  669. records in their private .h file by using the same conventions as used for
  670. widget records.
  671. For example, a widget class that needs to maintain a maximum
  672. width and height for each child might define its constraint record as
  673. follows:
  674. .LP
  675. .Ds
  676. .TA .5i 3i
  677. .ta .5i 3i
  678. typedef struct {
  679.     Dimension max_width, max_height;
  680. } MaxConstraintPart;
  681.  
  682. typedef struct {
  683.     MaxConstraintPart max;
  684. } MaxConstraintRecord, *MaxConstraint;
  685. .De
  686. .LP
  687. A subclass of this widget class that also needs to maintain a minimum size would
  688. define its constraint record as follows:
  689. .LP
  690. .Ds
  691. .TA .5i 3i
  692. .ta .5i 3i
  693. typedef struct {
  694.     Dimension min_width, min_height;
  695. } MinConstraintPart;
  696.  
  697. typedef struct {
  698.     MaxConstraintPart max;
  699.     MinConstraintPart min;
  700. } MaxMinConstraintRecord, *MaxMinConstraint;
  701. .De
  702. .LP
  703. Constraints are allocated, initialized, deallocated, and otherwise maintained
  704. insofar as possible by the \*(xI.
  705. The Constraint class record part has several entries that facilitate this.
  706. All entries in
  707. .PN ConstraintClassPart
  708. are fields and procedures that are defined and implemented by the parent,
  709. but they are called whenever actions are performed on the parent's children.
  710. .LP
  711. The
  712. .PN XtCreateWidget
  713. function uses the \fIconstraint_size\fP field in the parent's class record
  714. to allocate a constraint record when a child is created.
  715. .PN XtCreateWidget
  716. also uses the constraint resources to fill in resource fields in the
  717. constraint record associated with a child.
  718. It then calls the constraint initialize procedure so that the parent
  719. can compute constraint fields that are derived from constraint resources
  720. and can possibly move or resize the child to conform to the given constraints.
  721. .LP
  722. When the
  723. .PN XtGetValues
  724. and
  725. .PN XtSetValues
  726. functions are executed
  727. on a child, they use the constraint resources to get the values or
  728. set the values of constraints associated with that child.
  729. .PN XtSetValues
  730. then calls the constraint set_values procedures so that the parent can
  731. recompute derived constraint fields and move or resize the child
  732. as appropriate.
  733. If a
  734. Constraint
  735. widget class or any of its superclasses have declared a
  736. .PN ConstraintClassExtension
  737. record in the
  738. .PN ConstraintClassPart
  739. \fIextension\fP
  740. fields with a record type of
  741. .PN \s-1NULLQUARK\s+1
  742. and the \fIget_values_hook\fP field in
  743. .IN "get_values_hook procedure"
  744. .IN "Constraint" "get_values_hook"
  745. the extension record is non-NULL,
  746. .PN XtGetValues
  747. calls the get_values_hook
  748. procedure(s) to allow the parent to return derived constraint fields.
  749. .LP
  750. The
  751. .PN XtDestroyWidget
  752. function calls the constraint destroy procedure to deallocate any
  753. dynamic storage associated with a constraint record.
  754. The constraint record itself must not be deallocated by the constraint
  755. destroy procedure;
  756. .PN XtDestroyWidget
  757. does this automatically.
  758. .bp
  759.