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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Implementation of class TStatic.  This defines the basic behavior of static
  8. // text controls
  9. //----------------------------------------------------------------------------
  10. #pragma hdrignore SECTION
  11. #include <owl/pch.h>
  12. #if !defined(OWL_STATIC_H)
  13. # include <owl/static.h>
  14. #endif
  15. #if !defined(OWL_APPLICAT_H)
  16. # include <owl/applicat.h>
  17. #endif
  18.  
  19. #if defined(BI_COMP_BORLANDC)
  20. # include <bwcc.h>
  21. #endif
  22.  
  23. OWL_DIAGINFO;
  24.  
  25. #if !defined(SECTION) || SECTION == 1
  26.  
  27. DEFINE_RESPONSE_TABLE1(TStatic,TControl)
  28.   EV_WM_SIZE,
  29. END_RESPONSE_TABLE;
  30.  
  31. //
  32. // Constructor for a TStatic object
  33. //
  34. // By default, static controls have left-justified text
  35. //
  36. TStatic::TStatic(TWindow*        parent,
  37.                  int             id,
  38.                  const char far* title,
  39.                  int x, int y, int w, int h,
  40.                  uint            textLimit,
  41.                  TModule*        module)
  42. :
  43.   TControl(parent, id, title, x, y, w, h, module),
  44.   TextLimit(textLimit)
  45. {
  46.   Attr.Style = (Attr.Style | SS_LEFT) & ~WS_TABSTOP;
  47. }
  48.  
  49. //
  50. // Constructor for a TStatic to be associated with a MS-Windows
  51. // interface element created by MS-Windows from a resource definition
  52. //
  53. // Initializes its data fields using passed parameters
  54. //
  55. // Data transfer is disabled, by default, for the TStatic
  56. //
  57. TStatic::TStatic(TWindow*   parent,
  58.                  int        resourceId,
  59.                  uint       textLimit,
  60.                  TModule*   module)
  61. :
  62.   TControl(parent, resourceId, module),
  63.   TextLimit(textLimit)
  64. {
  65.   DisableTransfer();
  66. }
  67.  
  68. //
  69. // Static controls don't repaint when they are re-sized
  70. // This will force them to be re-painted
  71. //
  72. void
  73. TStatic::EvSize(uint sizeType, TSize& size)
  74. {
  75.   Invalidate();
  76.   TControl::EvSize(sizeType, size);
  77. }
  78.  
  79. //
  80. // Returns name of predefined BWCC or Windows static class
  81. //
  82. char far*
  83. TStatic::GetClassName()
  84. {
  85. #if defined(BI_COMP_BORLANDC)
  86.   if (GetApplication()->BWCCEnabled())
  87.     return STATIC_CLASS;
  88.   else
  89. #endif
  90.     return "STATIC";
  91. }
  92.  
  93. //
  94. // Transfers state information for TStatic controls
  95. //
  96. // The direction passed specifies whether data is to be read from or
  97. // written to the passed buffer, or whether the data element size is simply to
  98. // be returned
  99. //
  100. // The return value is the size (in bytes) of the transfer data
  101. //
  102. uint
  103. TStatic::Transfer(void* buffer, TTransferDirection direction)
  104. {
  105.   if (direction == tdGetData)
  106.     GetText((char far*)buffer, TextLimit);
  107.  
  108.   else if (direction == tdSetData)
  109.     SetText((char far*)buffer);
  110.  
  111.   return TextLimit;
  112. }
  113.  
  114. //
  115. // Clears the text contents of this control
  116. //
  117. void
  118. TStatic::Clear()
  119. {
  120.   SetText("");
  121. }
  122.  
  123. #endif
  124. #if !defined(SECTION) || SECTION == 2
  125.  
  126. IMPLEMENT_STREAMABLE1(TStatic, TControl);
  127.  
  128. #if !defined(BI_NO_OBJ_STREAMING)
  129.  
  130. //
  131. // Reads an instance of TStatic from the passed ipstream
  132. //
  133. void*
  134. TStatic::Streamer::Read(ipstream& is, uint32 /*version*/) const
  135. {
  136.   ReadBaseObject((TControl*)GetObject(), is);
  137.   is >> GetObject()->TextLimit;
  138.   return GetObject();
  139. }
  140.  
  141. #if !defined(BI_NO_OBJ_STREAMING)
  142.  
  143. //
  144. // Writes the TStatic to the passed opstream
  145. //
  146. void
  147. TStatic::Streamer::Write(opstream& os) const
  148. {
  149.   WriteBaseObject((TControl*)GetObject(), os);
  150.   os << GetObject()->TextLimit;
  151. }
  152.  
  153. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  154.  
  155. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  156.  
  157. #endif
  158.  
  159.