home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Xaw / CH7.intro < prev    next >
Encoding:
Text File  |  1989-12-22  |  3.6 KB  |  100 lines

  1. .LP
  2. .bp
  3. .if e .bp  \" make sure we break on an odd page.
  4. \&
  5. .sp 1
  6. .ce 5
  7. \s+1\fBChapter 7\fP\s-1
  8.  
  9. \s+1\fBCreating New Widgets (Subclassing)\fP\s-1
  10.  
  11. \s+1Written By: Ralph Swick\s-1
  12. .sp 2
  13. .nr H1 7
  14. .nr H2 0
  15. .nr H3 0
  16. .nr H4 0
  17. .nr H5 0
  18. .na
  19. .LP
  20. .XS
  21. Chapter 7 - Creating New Widgets (Subclassing)
  22. .XE
  23. .IN "subclassing" "" "@DEF@"
  24. .IN "creating new widgets" "" "@DEF@"
  25. .LP
  26. Although the task of creating a new widget may at first appear a little
  27. daunting, there is a basic simple pattern that all widgets follow.  The
  28. Athena Widget library contains a special widget called the
  29. \fITemplate\fP widget that is intended to assist the novice widget
  30. programmer in writing a custom widget.
  31. .LP
  32. Reasons for wishing to write a custom widget include:
  33. .IP \(bu 3
  34. Providing a graphical interface not currently supported by any existing
  35. widget set.
  36. .IP \(bu 3
  37. Convenient access to resource management procedures to obtain fonts,
  38. colors, etc., even if user customization is not desired.
  39. .IP \(bu 3
  40. Convenient access to user input dispatch and translation management procedures.
  41. .IP \(bu 3
  42. Access to callback mechanism for building higher-level application libraries.
  43. .IP \(bu 3
  44. Customizing the interface or behavior of an existing widget to suit a
  45. special application need.
  46. .IP \(bu 3
  47. Desire to allow user customization of resources such as fonts, colors,
  48. etc., or to allow convenient re-binding of keys and buttons to internal
  49. functions.
  50. .IP \(bu 3
  51. Converting a non-Toolkit application to use the Toolkit.
  52. .LP
  53. In each of these cases, the operation needed to create a new widget is
  54. to "subclass" an existing one.  If the desired semantics of the new
  55. widget are similar to an existing one, then the implementation of the
  56. existing widget should be examined to see how much work would be
  57. required to create a subclass that will then be
  58. able to share the existing class methods.  Much time will be saved in
  59. writing the new widget if an existing widget class Expose, Resize and/or
  60. GeometryManager method can be used by the subclass.
  61. .LP
  62. Note that some trivial uses of a ``bare-bones'' widget may be achieved by
  63. simply creating an instance of the Core
  64. widget.  The class variable to use when creating a Core widget is
  65. .PN widgetClass .
  66. The geometry of the Core widget is determined entirely by the parent
  67. widget.
  68. .LP
  69. It is very often the case than an application will have a special need
  70. for a certain set of functions and that many copies of these functions
  71. will be needed.  For example, when converting an older application to use
  72. the Toolkit, it may be desirable to have a "Window Widget" class that
  73. might have the following semantics:
  74. .IN "Window widget"
  75. .IN "Core widget"
  76. .IN "widgetClass"
  77. .IP \(bu 3
  78. Allocate 2 drawing colors in addition to a background color.
  79. .IP \(bu 3
  80. Allocate a text font.
  81. .IP \(bu 3
  82. Execute an application-supplied function to handle exposure events.
  83. .IP \(bu 3
  84. Execute an application-supplied function to handle user input events.
  85. .LP
  86. It is obvious that a completely general-purpose WindowWidgetClass could
  87. be constructed that would export all class methods as callbacks lists,
  88. but such a widget would be very large and would have to choose some
  89. arbitrary number of resources such as colors to allocate.  An application
  90. that used many instances of the general-purpose widget would therefore
  91. un-necessarily waste many resources.
  92. .LP
  93. .sp
  94. In this section, an outline will be given of the procedure to follow to
  95. construct a special-purpose widget to address the items listed above.
  96. The reader should refer to the appropriate sections of the \fI\*(xT\fP
  97. for complete details of the material outlined here.  Section 1.4 of
  98. the \fI\*(xI\fP should be read in conjunction with this section.
  99. .LP
  100.