home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / SWINDOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  4.7 KB  |  197 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Streamable object implementation for TWindow.
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/applicat.h>
  9. #include <owl/appdict.h>
  10. #include <owl/window.h>
  11. #include <owl/scroller.h>
  12.  
  13. extern WNDPROC CreateInstanceThunk(TWindow*);
  14.  
  15. IMPLEMENT_STREAMABLE(TWindow);
  16.  
  17. const int StreamIsTop      = 1;
  18. const int StreamIsTopChild = 2;
  19.  
  20. void *
  21. TWindow::Streamer::Read(ipstream& is, uint32 version) const
  22. {
  23.   TWindow* o = GetObject();
  24.   int flags;
  25.   is >> flags;
  26.   if (flags & StreamIsTop) {
  27.     o->ChildList = 0;   // indicate no children connected yet
  28.     return o;           // we only need to read our child list
  29.   }
  30.  
  31.   o->HWindow = 0;
  32.   o->Parent = 0;
  33.   o->SiblingList = 0;
  34.   o->ChildList = 0;
  35.   o->TransferBuffer = 0;
  36.   o->DefaultProc = 0;
  37.   o->hAccel = 0;
  38.   o->SetUniqueId();
  39.  
  40.   is >> o->Module;
  41.   TResId TempId;
  42.   is >> TempId;
  43.   o->Title = TempId;
  44.   is >> o->Flags;
  45.  
  46.   if (o->IsFlagSet(wfFromResource)) {
  47.     o->DefaultProc = (WNDPROC)::DefWindowProc;
  48.     memset(&o->Attr, 0, sizeof(o->Attr));
  49.   }
  50.   else {
  51.     long  temp;
  52.     is >> o->Attr.Style >> o->Attr.ExStyle >>
  53.           o->Attr.X >> o->Attr.Y >> o->Attr.W >> o->Attr.H >> temp;
  54.     o->Attr.Param = (char far*)temp;
  55.  
  56.     o->DefaultProc = (WNDPROC)::DefWindowProc;
  57.   }
  58.  
  59.   is >> o->Attr.Id
  60.      >> o->Attr.Menu
  61.      >> o->Attr.AccelTable;
  62.  
  63.   is >> o->ZOrder;
  64.  
  65.   is >> o->Parent;
  66.  
  67.   if (o->Parent) {
  68.     o->Application = o->Parent->GetApplication();
  69.  
  70.     // Version 1 and version 3 sibling streaming techniques
  71.     //
  72.     if (version == 1) {
  73.       if (flags & StreamIsTopChild)
  74.         o->Parent->ChildList = o;  // set parent's child pointer to this
  75.  
  76.       is >> o->ChildList;
  77.       is >> o->SiblingList;
  78.     }
  79.     else {
  80.       o->Parent->AddChild(o);
  81.  
  82.       static bool readSiblings = true;
  83.       bool saveReadSiblings = readSiblings;
  84.       readSiblings = true;
  85.       is >> o->ChildList;
  86.       readSiblings = saveReadSiblings;
  87.  
  88.       if (readSiblings) {
  89.         readSiblings = false;
  90.  
  91.         unsigned numSiblings;
  92.         is >> numSiblings;
  93.         for (unsigned i = 0; i < numSiblings; i++) {
  94.           TWindow* sibling;
  95.           is >> sibling;
  96.         }
  97.         readSiblings = true;
  98.       }
  99.     }
  100.   }
  101.   else {
  102.     o->Application = TYPESAFE_DOWNCAST(o->Module,TApplication);
  103.     if (!o->Application)
  104.       o->Application = ::GetApplicationObject();
  105.   }
  106.  
  107.   is >> o->Scroller;
  108.   if (o->Scroller)
  109.     o->Scroller->SetWindow(o);
  110.  
  111.   o->HCursor = 0;
  112.   is >> o->CursorModule >> o->CursorResId;
  113.   o->SetCursor(o->CursorModule, o->CursorResId);
  114.   is >> o->BkgndColor;
  115.  
  116.   o->Thunk = CreateInstanceThunk(o);
  117.  
  118.   return o;
  119. }
  120.  
  121. void
  122. TWindow::Streamer::Write(opstream& os) const
  123. {
  124.   TWindow* o = GetObject();
  125.  
  126.   o->AssignZOrder();
  127.   int flags = 0;
  128.   if (o->IsFlagSet(wfStreamTop) || o->IsFlagSet(wfMainWindow))
  129.     flags |= StreamIsTop;
  130.   else if (o->Parent) {
  131.     if ((o->Parent->IsFlagSet(wfStreamTop) || o->Parent->IsFlagSet(wfMainWindow))
  132.       && o->Parent->ChildList == o)
  133.     flags |= StreamIsTopChild;
  134.   }
  135.   os << flags;
  136.  
  137.   if (flags & StreamIsTop)
  138.     return;
  139.  
  140.   os << o->Module;
  141.   os << TResId(o->Title);
  142.  
  143.   uint32 saveFlags = o->Flags;
  144.   if (o->HWindow)
  145.     saveFlags |= wfAutoCreate;
  146.   os << saveFlags;
  147.  
  148.   if (!o->IsFlagSet(wfFromResource)) {
  149.     uint32 saveStyle = o->Attr.Style &
  150.                       ~(WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
  151.  
  152.     if (o->HWindow)
  153.       saveStyle |= o->GetWindowLong(GWL_STYLE) &
  154.                    (WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
  155.  
  156.     os << saveStyle << o->Attr.ExStyle <<
  157.           o->Attr.X << o->Attr.Y << o->Attr.W << o->Attr.H <<
  158.           long(o->Attr.Param);
  159.   }
  160.  
  161.   os << o->Attr.Id
  162.      << o->Attr.Menu
  163.      << o->Attr.AccelTable;
  164.  
  165.   os << o->ZOrder;
  166.  
  167.   os << o->Parent;
  168.  
  169. #if 0  // (TWindow::Streamer::ClassVersion() == 1)
  170.   os << o->ChildList;
  171.   os << o->SiblingList;
  172.  
  173. #else  // version >= 3
  174.   if (o->Parent) {
  175.     static bool writeSiblings = true;
  176.     bool saveWriteSiblings = writeSiblings;
  177.     writeSiblings = true;
  178.     os << o->ChildList;
  179.     writeSiblings = saveWriteSiblings;
  180.  
  181.     if (writeSiblings) {
  182.       writeSiblings = false;
  183.  
  184.       os << (o->Parent->NumChildren()-1);
  185.       for (TWindow* sibling = o->SiblingList; sibling != o; sibling = sibling->Next())
  186.         os << sibling;
  187.       writeSiblings = true;
  188.     }
  189.   }
  190. #endif
  191.  
  192.   os << o->Scroller;
  193.  
  194.   os << o->CursorModule << o->CursorResId;
  195.   os << o->BkgndColor;
  196. }
  197.