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

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