home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / CONTROL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  4.2 KB  |  200 lines

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