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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //   source\owl\checkbox.cpp
  4. //   Implemenation ofclass TCheckBox.  This defines the basic behavior
  5. //   for all check boxes.
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl\owlpch.h>
  9. #include <owl\checkbox.h>
  10. #include <owl\groupbox.h>
  11. #include <owl\applicat.h>
  12. #include <bwcc.h>
  13.  
  14. #if !defined(SECTION) || SECTION == 1
  15.  
  16. DEFINE_RESPONSE_TABLE1(TCheckBox, TButton)
  17.   EV_WM_GETDLGCODE,
  18.   EV_NOTIFY_AT_CHILD(BN_CLICKED, BNClicked),
  19. END_RESPONSE_TABLE;
  20.  
  21. //
  22. // constructor for a TCheckBox object
  23. //
  24. TCheckBox::TCheckBox(TWindow*        parent,
  25.                      int             id,
  26.                      const char far* title,
  27.                      int x, int y, int w, int h,
  28.                      TGroupBox*      group,
  29.                      TModule*        module)
  30.   : TButton(parent, id, title, x, y, w, h, FALSE, module)
  31. {
  32.   Group = group;
  33.   //
  34.   // Don't use TButton's inherited style - it conflicts with BS_AUTOCHECKBOX
  35.   //
  36.   Attr.Style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX;
  37. }
  38.  
  39. //
  40. // constructor for a TCheckBox to be associated with a MS-Windows interface
  41. // element created by MS-Windows from a resource definition
  42. //
  43. // data transfer is enabled for the TCheckBox
  44. //
  45. TCheckBox::TCheckBox(TWindow*   parent,
  46.                      int        resourceId,
  47.                      TGroupBox* group,
  48.                      TModule*   module)
  49.   : TButton(parent, resourceId, module)
  50. {
  51.   Group = group;
  52.   EnableTransfer();
  53. }
  54.  
  55. //
  56. // Return name of predefined BWCC or Windows check box class
  57. //
  58. char far*
  59. TCheckBox::GetClassName()
  60. {
  61.   if (GetApplication()->BWCCEnabled())
  62.     return CHECK_CLASS;
  63.   else
  64.     return "BUTTON";
  65. }
  66.  
  67. //
  68. // transfers state information for the TCheckBox
  69. //
  70. // the direction passed specifies whether data is to be read from or
  71. // written to the passed buffer, or whether the data element size is simply
  72. // to be returned
  73. //
  74. // the return value is the size (in bytes) of the transfer data
  75. //
  76. UINT
  77. TCheckBox::Transfer(void* buffer, TTransferDirection direction)
  78. {
  79.   if (direction == tdGetData)
  80.     *(UINT*)buffer = GetCheck();
  81.  
  82.   else if (direction == tdSetData)
  83.     SetCheck(*(UINT*)buffer);
  84.  
  85.   return sizeof(UINT);
  86. }
  87.  
  88. //
  89. // sets the check state
  90. //
  91. // unchecks, checks, or grays the checkbox (if 3-state) according to the
  92. // CheckFlag passed (pass BF_UNCHECKED(0), BF_CHECKED(1), or BF_GRAYED(2))
  93. //
  94. // if a Group has been specified for the TCheckBox, notifies the Group that
  95. // the state of the check box has changed
  96. //
  97. void
  98. TCheckBox::SetCheck(UINT check)
  99. {
  100.   HandleMessage(BM_SETCHECK, check);
  101.  
  102.   if (Group)
  103.     Group->SelectionChanged(Attr.Id);
  104. }
  105.  
  106. //
  107. // toggles the check state of the check box
  108. //
  109. void
  110. TCheckBox::Toggle()
  111. {
  112.   if ((GetWindowLong(GWL_STYLE) & BS_AUTO3STATE) == BS_AUTO3STATE)
  113.     SetCheck((GetCheck() + 1) % 3);
  114.  
  115.   else
  116.     SetCheck((GetCheck() + 1) % 2);
  117. }
  118.  
  119. //
  120. // responds to an incoming BN_CLICKED message
  121. //
  122. // if a Group has been specified for the TCheckBox, notifies the Group that
  123. // the state of this TCheckBox has changed
  124. //
  125. void
  126. TCheckBox::BNClicked()
  127. {
  128.   if (Group)
  129.     Group->SelectionChanged(Attr.Id);
  130.  
  131.   DefaultProcessing();  // give parent an opportunity to handle...
  132. }
  133.  
  134. #endif
  135. #if !defined(SECTION) || SECTION == 2
  136.  
  137. IMPLEMENT_STREAMABLE1(TCheckBox, TButton);
  138.  
  139. //
  140. // reads an instance of TCheckBox from the passed ipstream
  141. //
  142. void*
  143. TCheckBox::Streamer::Read(ipstream& is, uint32 /*version*/) const
  144. {
  145.   ReadBaseObject((TButton*)GetObject(), is);
  146.   is >> GetObject()->Group;
  147.   return GetObject();
  148. }
  149.  
  150. //
  151. // writes the TCheckBox to the passed opstream
  152. //
  153. void
  154. TCheckBox::Streamer::Write(opstream& os) const
  155. {
  156.   WriteBaseObject((TButton*)GetObject(), os);
  157.   os << GetObject()->Group;
  158. }
  159. #endif
  160.