home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / BUTTON.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.5 KB  |  183 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Implementation of class TButton.  This defines the basic behavior of all
  8. // buttons.
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_BUTTON_H)
  13. # include <owl/button.h>
  14. #endif
  15. #if !defined(OWL_APPLICAT_H)
  16. # include <owl/applicat.h>
  17. #endif
  18. #if defined(BI_COMP_BORLANDC)
  19. # include <bwcc.h>
  20. #endif
  21.  
  22. OWL_DIAGINFO;
  23. DIAG_DECLARE_GROUP(OwlControl);
  24.  
  25. #if !defined(SECTION) || SECTION == 1
  26.  
  27. DEFINE_RESPONSE_TABLE1(TButton, TControl)
  28.   EV_WM_GETDLGCODE,
  29.   EV_MESSAGE(BM_SETSTYLE, BMSetStyle),
  30. END_RESPONSE_TABLE;
  31.  
  32. //
  33. // constructor for a TButton object
  34. //
  35. TButton::TButton(TWindow*        parent,
  36.                  int             id,
  37.                  const char far* text,
  38.                  int x, int y, int w, int h,
  39.                  bool            isDefault,
  40.                  TModule*        module)
  41. :
  42.   TControl(parent, id, text, x, y, w, h, module)
  43. {
  44.   IsCurrentDefPB = false;    // not used for buttons in windows
  45.   IsDefPB = false;           // not used for buttons in windows
  46.  
  47.   if (isDefault)
  48.     Attr.Style |= BS_DEFPUSHBUTTON;
  49.  
  50.   else
  51.     Attr.Style |= BS_PUSHBUTTON;
  52.   TRACEX(OwlControl, OWL_CDLEVEL, "TButton constructed @" << (void*)this);
  53. }
  54.  
  55. //
  56. // constructor for a TButton to be associated with a MS-Windows
  57. // interface element created by MS-Windows from a resource definition
  58. //
  59. // disables transfer of state data for the TButton
  60. //
  61. TButton::TButton(TWindow*   parent,
  62.                  int        resourceId,
  63.                  TModule*   module)
  64. :
  65.   TControl(parent, resourceId, module)
  66. {
  67.   DisableTransfer();
  68.   IsDefPB = false;         // needed for drawable buttons
  69.   IsCurrentDefPB = false;  // needed for drawable buttons
  70.   TRACEX(OwlControl, OWL_CDLEVEL, "TButton constructed from resource @" << (void*)this);
  71. }
  72.  
  73. //
  74. // Output a debug message if using the diagnostic libraries.
  75. //
  76. TButton::~TButton()
  77. {
  78.   TRACEX(OwlControl, OWL_CDLEVEL, "TButton destructed @" << (void*)this);
  79. }
  80.  
  81. //
  82. // Return name of predefined Windows button class
  83. //
  84. char far*
  85. TButton::GetClassName()
  86. {
  87. #if defined(BI_COMP_BORLANDC)
  88.   if (GetApplication()->BWCCEnabled()) {
  89.     TRACEX(OwlControl, 1, "BWCC button used for classname @" << (void*)this);
  90.     return BUTTON_CLASS;
  91.   }
  92. #endif
  93.   TRACEX(OwlControl, 1, "Regular button used for classname @" << (void*)this);
  94.   return "BUTTON";
  95. }
  96.  
  97. //
  98. // if this is a drawable button which is supposed to act like a DefPushButton,
  99. // send DM_SETDEFID to Parent to make this into Parent's default pushbutton
  100. //
  101. // this only works (and IsDefPB should only be true) if Parent is a dialog
  102. //
  103. void
  104. TButton::SetupWindow()
  105. {
  106.   TRACEX(OwlControl, 1, "TButton::SetupWindow() @" << (void*)this);
  107.   if (IsDefPB && ((Attr.Style & BS_OWNERDRAW) == BS_OWNERDRAW))
  108.     Parent->HandleMessage(DM_SETDEFID, Attr.Id);
  109. }
  110.  
  111. //
  112. // if this is a drawable button we tell Windows whether we want to
  113. // be treated as the current default push button or not
  114. //
  115. uint
  116. TButton::EvGetDlgCode(MSG far* msg)
  117. {
  118.   if ((Attr.Style & BS_OWNERDRAW) != BS_OWNERDRAW)
  119.     return TControl::EvGetDlgCode(msg);
  120.  
  121.   else if (IsCurrentDefPB)
  122.     return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
  123.  
  124.   else
  125.     return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
  126. }
  127.  
  128. //
  129. // a Button can't have both BS_OWNERDRAW and BS_(DEF)PUSHBUTTON styles so
  130. // when Windows tries to make us a DEF- or non-DEFPUSHBUTTON we keep track
  131. // of the desired style in IsCurrentDefPB
  132. //
  133. TResult
  134. TButton::BMSetStyle(TParam1 param1, TParam2)
  135. {
  136.   if ((Attr.Style & BS_OWNERDRAW) != BS_OWNERDRAW)
  137.     DefaultProcessing();
  138.   else if (param1 == BS_DEFPUSHBUTTON) {
  139.     IsCurrentDefPB = true;
  140.     Invalidate();
  141.   }
  142.   else if (param1 == BS_PUSHBUTTON) {
  143.     IsCurrentDefPB = false;
  144.     Invalidate();
  145.   }
  146.   else {
  147.     DefaultProcessing();
  148.   }
  149.  
  150.   return 0;
  151. }
  152.  
  153. #endif
  154. #if !defined(SECTION) || SECTION == 2
  155.  
  156. IMPLEMENT_STREAMABLE1(TButton, TControl);
  157.  
  158. #if !defined(BI_NO_OBJ_STREAMING)
  159.  
  160. //
  161. //
  162. //
  163. void*
  164. TButton::Streamer::Read(ipstream& is, uint32 /*version*/) const
  165. {
  166.   ReadBaseObject((TControl*)GetObject(), is);
  167.   is >> GetObject()->IsDefPB;
  168.   return GetObject();
  169. }
  170.  
  171. //
  172. //
  173. //
  174. void
  175. TButton::Streamer::Write(opstream& os) const
  176. {
  177.   WriteBaseObject((TControl*)GetObject(), os);
  178.   os << GetObject()->IsDefPB;
  179. }
  180. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  181.  
  182. #endif
  183.