home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWL1.PAK / BUTTON.CPP < prev    next >
Text File  |  1995-08-29  |  3KB  |  107 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* --------------------------------------------------------
  4.   BUTTON.CPP
  5.   Defines type TButton.  This defines the basic behavior
  6.   of all buttons.
  7.   -------------------------------------------------------- */
  8.  
  9. #include "button.h"
  10.  
  11. /* Constructor for a TButton object.  Initializes its data members using
  12.   parameters passed and default values. */
  13. TButton::TButton(PTWindowsObject AParent, int AnId, LPSTR AText, int X,
  14.                  int Y, int W, int H, BOOL IsDefault, PTModule AModule)
  15.                       : TControl(AParent, AnId, AText, X, Y, W, H, AModule)
  16. {
  17.   IsCurrentDefPB = FALSE;      // not used for buttons in windows
  18.   IsDefPB = FALSE;             // not used for buttons in windows
  19.  
  20.   if ( IsDefault )
  21.     Attr.Style |= BS_DEFPUSHBUTTON;
  22.   else
  23.     Attr.Style |= BS_PUSHBUTTON;
  24. }
  25.  
  26. /* Constructor for a TButton to be associated with a MS-Windows
  27.    interface element created by MS-Windows from a resource definition.
  28.    Initializes its data members using passed parameters.  Disables
  29.    transfer of state data for the TButton. */
  30. TButton::TButton(PTWindowsObject AParent, int ResourceId, PTModule AModule)
  31.                  : TControl(AParent, ResourceId, AModule)
  32. {
  33.   DisableTransfer();
  34.   IsDefPB = FALSE;             // needed for drawable buttons
  35.   IsCurrentDefPB = FALSE;  // needed for drawable buttons
  36. }
  37.  
  38. /* If this is a drawable button which is supposed to act like a
  39.    DefPushButton, send DM_SETDEFID to Parent to make this into
  40.    Parent's default pushbutton. This only works (and IsDefPB should
  41.    only be TRUE) if Parent is a dialog. */
  42. void TButton::SetupWindow()
  43. {
  44.   if ( IsDefPB && ( (Attr.Style & BS_OWNERDRAW) == BS_OWNERDRAW ) )
  45.     SendMessage(Parent->HWindow, DM_SETDEFID, Attr.Id, 0);
  46. }
  47.  
  48. /* If this is a drawable button we tell Windows whether we want to
  49.     be treated as the current default push button or not. */
  50. void TButton::WMGetDlgCode(RTMessage Msg)
  51. {
  52.   if ( (Attr.Style & BS_OWNERDRAW) == BS_OWNERDRAW )
  53.   {
  54.     if ( IsCurrentDefPB )
  55.       Msg.Result = DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
  56.     else
  57.       Msg.Result = DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
  58.   }
  59.   else
  60.     DefWndProc(Msg);
  61. }
  62.  
  63. /* A Button can't have both BS_OWNERDRAW and BS_(DEF)PUSHBUTTON
  64.    styles so when Windows tries to make us a DEF- or non-DEFPUSHBUTTON
  65.    we keep track of the desired style in IsCurrentDefPB. */
  66. void TButton::BMSetStyle(RTMessage Msg)
  67. {
  68.    if ( (Attr.Style & BS_OWNERDRAW) == BS_OWNERDRAW )
  69.    {
  70.      if ( Msg.WParam == BS_DEFPUSHBUTTON )
  71.      {
  72.        IsCurrentDefPB = TRUE;
  73.        InvalidateRect(HWindow, 0L, 0);
  74.      }
  75.      else
  76.       if ( Msg.WParam == BS_PUSHBUTTON )
  77.       {
  78.         IsCurrentDefPB = FALSE;
  79.         InvalidateRect(HWindow, 0L, 0);
  80.       }
  81.       else
  82.         DefWndProc(Msg);
  83.     }
  84.     else
  85.       DefWndProc(Msg);
  86. }
  87.  
  88. void *TButton::read(ipstream& is)
  89. {
  90.   TControl::read(is);
  91.   is >> IsDefPB;
  92.   return this;
  93. }
  94.  
  95. void TButton::write(Ropstream os)
  96. {
  97.   TControl::write(os);
  98.   os << IsDefPB;
  99. }
  100.  
  101. TStreamable *TButton::build()
  102. {
  103.   return new TButton(streamableInit);
  104. }
  105.  
  106. TStreamableClass RegButton("TButton", TButton::build, __DELTA(TButton));
  107.