home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / CONTROL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.2 KB  |  197 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   source\owl\control.cpp
  4. //   Implementation of class TControl.  This defines the basic behavior
  5. //   of all controls.
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl\owlpch.h>
  9. #include <owl\control.h>
  10.  
  11. #if !defined(SECTION) || SECTION == 1
  12.  
  13. DEFINE_RESPONSE_TABLE1(TControl, TWindow)
  14.   EV_WM_PAINT,
  15.   EV_WM_COMPAREITEM,
  16.   EV_WM_DELETEITEM,
  17.   EV_WM_DRAWITEM,
  18.   EV_WM_MEASUREITEM,
  19. END_RESPONSE_TABLE;
  20.  
  21. //
  22. // constructor for a TControl
  23. //
  24. TControl::TControl(TWindow*        parent,
  25.                    int             id,
  26.                    const char far* title,
  27.                    int x, int y, int w, int h,
  28.                    TModule*        module)
  29.   : TWindow(parent, title, module)
  30. {
  31.   Attr.Id = id;
  32.   Attr.X = x;
  33.   Attr.Y = y;
  34.   Attr.W = w;
  35.   Attr.H = h;
  36.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP;
  37. }
  38.  
  39. //
  40. // constructor for a TControl to be associated with a MS-Windows
  41. // interface element created by MS-Windows from a resource definition
  42. //
  43. // data transfer is enabled for the TControl
  44. //
  45. TControl::TControl(TWindow*   parent,
  46.                    int        resourceId,
  47.                    TModule*   module)
  48.   : TWindow(parent, 0, module)
  49. {
  50.   if (HIWORD(Title))
  51.     delete Title;     // Free memory allocated by TWindow's constructor
  52.   Title = 0;
  53.  
  54.   SetFlag(wfFromResource);
  55.   memset(&Attr, 0x0, sizeof(Attr));
  56.   Attr.Id = resourceId;
  57.   EnableTransfer();
  58. }
  59.  
  60. void
  61. TControl::EvPaint()
  62. {
  63.   if (IsFlagSet(wfPredefinedClass))
  64.     DefaultProcessing();  // don't call TWindow::EvPaint()
  65.  
  66.   else
  67.     TWindow::EvPaint();
  68. }
  69.  
  70. //
  71. // handles WM_COMPAREITEM message (for owner draw controls)
  72. //
  73. LRESULT
  74. TControl::EvCompareItem(UINT /*ctrlId*/, COMPAREITEMSTRUCT far& compareInfo)
  75. {
  76.   return CompareItem(compareInfo);
  77. }
  78.  
  79. //
  80. // Function called when a WM_COMPAREITEM is sent to parent on our behalf
  81. //
  82. int
  83. TControl::CompareItem(COMPAREITEMSTRUCT far&)
  84. {
  85.   return 0;
  86. }
  87.  
  88. //
  89. // handles WM_DELETEITEM message(for owner draw controls)
  90. //
  91. void
  92. TControl::EvDeleteItem(UINT /*ctrlId*/, DELETEITEMSTRUCT far& deleteInfo)
  93. {
  94.   DeleteItem(deleteInfo);
  95. }
  96.  
  97. //
  98. // Function called when a WM_DELETEITEM is sent to parent on our behalf
  99. //
  100. void
  101. TControl::DeleteItem(DELETEITEMSTRUCT far&)
  102. {
  103. }
  104.  
  105. void
  106. TControl::EvDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT far& drawInfo)
  107. {
  108.   DrawItem(drawInfo);
  109. }
  110.  
  111. //
  112. // Function called when a WM_DRAWITEM is sent to parent on our behalf
  113. //
  114. void
  115. TControl::DrawItem(DRAWITEMSTRUCT far& drawInfo)
  116. {
  117.   switch (drawInfo.itemAction) {
  118.     case ODA_DRAWENTIRE:
  119.          ODADrawEntire(drawInfo);
  120.          break;
  121.  
  122.     case ODA_FOCUS:
  123.          ODAFocus(drawInfo);
  124.          break;
  125.  
  126.     case ODA_SELECT:
  127.          ODASelect(drawInfo);
  128.          break;
  129.   }
  130. }
  131.  
  132. void
  133. TControl::EvMeasureItem(UINT /*ctrlId*/, MEASUREITEMSTRUCT far& measureInfo)
  134. {
  135.   MeasureItem(measureInfo);
  136. }
  137.  
  138. //
  139. // Function called when a WM_MEASUREITEM is sent to parent on our behalf
  140. //
  141. void
  142. TControl::MeasureItem(MEASUREITEMSTRUCT far&)
  143. {
  144. }
  145.  
  146. //
  147. // function called when an "owner-draw" control needs to be redrawn
  148. //
  149. // will usually be redefined by descendants of TControl which use owner draw
  150. // style
  151. //
  152. void
  153. TControl::ODADrawEntire(DRAWITEMSTRUCT far&)
  154. {
  155. }
  156.  
  157. //
  158. // function called when an "owner-draw" control gains or loses focus
  159. //
  160. // will usually be redefined by descendants of TControl which use owner draw
  161. // style
  162. //
  163. void
  164. TControl::ODAFocus(DRAWITEMSTRUCT far&)
  165. {
  166. }
  167.  
  168. //
  169. // function called when an "owner-draw" control's selection status changes
  170. //
  171. // will usually be redefined by descendants of TControl which use owner draw
  172. // style
  173. //
  174. void
  175. TControl::ODASelect(DRAWITEMSTRUCT far&)
  176. {
  177. }
  178.  
  179. #endif
  180. #if !defined(SECTION) || SECTION == 2
  181.  
  182. IMPLEMENT_STREAMABLE1(TControl, TWindow);
  183.  
  184. void*
  185. TControl::Streamer::Read(ipstream& is, uint32 /*version*/) const
  186. {
  187.   ReadBaseObject((TWindow*)GetObject(), is);
  188.   return GetObject();
  189. }
  190.  
  191. void
  192. TControl::Streamer::Write(opstream& os) const
  193. {
  194.   WriteBaseObject((TWindow*)GetObject(), os);
  195. }
  196. #endif
  197.