home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWL1.PAK / SWINDOBJ.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  216 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* --------------------------------------------------------
  4.   SWINDOBJ.CPP
  5.   Streamable object implementation for TWindowsObject.
  6.   -------------------------------------------------------- */
  7.  
  8. // For asm in GetChildren:
  9. #pragma inline
  10.  
  11. #include "applicat.h"
  12. #include "windobj.h"
  13.  
  14. extern WNDPROC MakeObjectInstance(PTWindowsObject);
  15.  
  16. typedef char far *TFixupList[4096];
  17. static TFixupList far *FixupList = NULL;
  18.  
  19. /* Reads the children of "this" which were stored on the given stream
  20.    using PutChildren.  Used by TWindowsObject::read.  IMPORTANT: This
  21.    method assumes that the current child list is empty! */
  22. void TWindowsObject::GetChildren(ipstream& is)
  23. {
  24.   int ChildCount, I;
  25.   TFixupList far *SaveFixup;
  26.   TWindowsObject *W, *TmpWindowsObject;
  27.   char * far *P;
  28.   char * far *Q;
  29.  
  30.   SaveFixup = FixupList;
  31.   is >> ChildCount;
  32.   asm {
  33.         MOV     CX,ChildCount
  34.     SHL     CX,1
  35.     SHL     CX,1
  36.     SUB     SP,CX
  37.   }
  38.  
  39. #if defined(_ALLOW_po)      // probably compiled with -po
  40.     #if defined(__DLL__)    // and compiled with -WD (for a DLL)
  41.     asm {
  42.         MOV AX, DGROUP
  43.         MOV ES, AX
  44.         MOV word ptr ES:FixupList, SP
  45.         MOV word ptr ES:FixupList+2, SS
  46.     }
  47.     #else   // compiled as a static library (and probably with -po)
  48.     asm MOV word ptr SS:FixupList, SP
  49.     asm MOV word ptr SS:FixupList+2, SS
  50.     #endif
  51. #else    // !defined(_ALLOW_po)
  52.   asm    MOV word ptr DGROUP:FixupList, SP
  53.   asm    MOV word ptr DGROUP:FixupList+2, SS
  54. #endif    // defined(_ALLOW_po)
  55.  
  56.   asm {
  57.     MOV     DI,SP
  58.     PUSH    SS
  59.     POP     ES
  60.     XOR     AL,AL
  61.     CLD
  62.     REP     STOSB
  63.   };
  64.   for (I = 1; I <= ChildCount; ++I)
  65.   {
  66.     is >> TmpWindowsObject;
  67.     AddChild(TmpWindowsObject);
  68.     ChildList->Parent = this;
  69.     ChildList->Application = Application;
  70.   }
  71.   W = (PTWindowsObject)ChildList;
  72.   for (I = 0; I < ChildCount; ++I)
  73.   {
  74.     W = W->Next();
  75.     P = (char * far *)((*FixupList)[I]);
  76.     while ( P )
  77.     {
  78.       Q = P;
  79.       if ( *P  == 0 )
  80.         P = NULL;
  81.       else
  82.         P = (char * far *)*P;
  83.       *Q = (char *)W;
  84.     }
  85.   }
  86.   FixupList = SaveFixup;
  87.  
  88.   // get rid of temporary buffer on the stack
  89.   asm {
  90.   MOV     CX,ChildCount
  91.   SHL     CX,1
  92.   SHL     CX,1
  93.   ADD     SP,CX
  94.   };
  95. }
  96.  
  97. /* Writes a pointer to a child window onto the passed stream */
  98. void TWindowsObject::PutChildPtr(opstream& os, TWindowsObject *P)
  99. {
  100.   int Index = IndexOf(P);   // -1 if P == NULL
  101.   os << Index;
  102. }
  103.  
  104. /* Reads a pointer to a child window from the passed stream */
  105. void TWindowsObject::GetChildPtr(ipstream& is, TWindowsObject *&P)
  106. {
  107.   int Index;
  108.  
  109.   is >> Index;
  110.   P = At(Index);            // NULL if Index == -1
  111. }
  112.  
  113. /* Gets a pointer to a sibling window from the passed stream.  This
  114.    function is only valid during a read and is not valid until
  115.    the read returns.  The pointer will not be given a valid value
  116.    until the parent window's read  loads all of the window's
  117.    sibling windows. */
  118. void TWindowsObject::GetSiblingPtr(ipstream& is, TWindowsObject *&P)
  119. {
  120.   int Index;
  121.  
  122.   is >> Index;
  123.   if ( (Index == -1) || (FixupList == NULL) )
  124.     P = NULL;
  125.   else
  126.   {
  127.     P = (TWindowsObject *)(*FixupList)[Index];
  128.     (*FixupList)[Index] = (char far *)&P;
  129.   }
  130. }
  131.  
  132. /* Puts a pointer to a sibling window on to a stream.  The pointer can
  133.    be read from the stream using GetSiblingPtr.  This function is only
  134.    valid during a write procedure. */
  135. void TWindowsObject::PutSiblingPtr(opstream& os, TWindowsObject *P)
  136. {
  137.   int Index = Parent->IndexOf(P);
  138.   os << Index;
  139. }
  140.  
  141. static void DoPutChildren(void *P, void *os)
  142. {
  143.   *(opstream *)os
  144.         << (TWindowsObject *)P;
  145. }
  146.  
  147. void TWindowsObject::PutChildren(opstream& os)
  148. {
  149.   int ChildCount;
  150.  
  151.   AssignCreateOrder();
  152.   ChildCount = IndexOf(ChildList) + 1;
  153.   os << ChildCount;
  154.   ForEach(DoPutChildren, &os);
  155. }
  156.  
  157. void *TWindowsObject::read(ipstream& is)
  158. {
  159.   BOOL TitleIsNumeric;
  160.  
  161.   HWindow = 0;
  162.   Parent = NULL;
  163.   SiblingList = NULL;
  164.   ChildList = NULL;
  165.   TransferBuffer = NULL;
  166.   DefaultProc = NULL;
  167.  
  168.   Application = GetApplicationObject();
  169.   /* For now, set Module to Application. This is not a general solution */
  170.   Module = (PTModule)Application;
  171.  
  172.   Instance = MakeObjectInstance((PTWindowsObject)this);
  173.  
  174.   is >> TitleIsNumeric;
  175.   // if TitleIsNumeric is TRUE then it's probably a dialog with Title == -1
  176.   // i.e. unchanged from resource
  177.   if ( TitleIsNumeric )
  178.     is >> (long)(Title);
  179.   else
  180.     Title = is.freadString();
  181.  
  182.   is >> Status >> Flags >> CreateOrder;
  183.   GetChildren(is);
  184.   return this;
  185. }
  186.  
  187. void TWindowsObject::write(opstream& os)
  188. {
  189.   WORD SavedFlags;
  190.   BOOL TitleIsNumeric;
  191.  
  192.   TitleIsNumeric = HIWORD(Title) == NULL;
  193.   os << TitleIsNumeric;
  194.   // if TitleIsNumeric is TRUE then it's probably a dialog with Title == -1
  195.   // i.e. unchanged from resource
  196.   if ( TitleIsNumeric )
  197.     os << (long)(Title);
  198.   else
  199.     os.fwriteString(Title);
  200.  
  201.   SavedFlags = Flags;
  202.   if ( HWindow )
  203.     SavedFlags |= WB_AUTOCREATE;
  204.  
  205.   os << Status << SavedFlags << CreateOrder;
  206.   PutChildren(os);
  207. }
  208.  
  209. TStreamable * TWindowsObject::build()
  210. {
  211.   return NULL;
  212. }
  213.  
  214. TStreamableClass RegWindowsObject("TWindowsObject", TWindowsObject::build,
  215.                 __DELTA(TWindowsObject));
  216.