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

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