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

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