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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.9  $
  6. //
  7. // Implementation of classes TView & TWindowView
  8. //----------------------------------------------------------------------------
  9. #pragma hdrignore SECTION
  10. #include <owl/pch.h>
  11. #if !defined(OWL_DOCMANAG_H)
  12. # include <owl/docmanag.h>
  13. #endif
  14. #if !defined(OWL_APPDICT_H)
  15. # include <owl/appdict.h>
  16. #endif
  17. #if !defined(OWL_DOCVIEW_RH)
  18. # include <owl/docview.rh>
  19. #endif
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. OWL_DIAGINFO;
  24. DIAG_DECLARE_GROUP(OwlDocView);        // General Doc/View diagnostic group
  25.  
  26. #if !defined(SECTION) || SECTION == 1
  27.  
  28. const uint MinUniqueViewId = 0x8000;
  29. uint TView::NextViewId = MinUniqueViewId;
  30.  
  31. //
  32. //
  33. //
  34. TView::TView(TDocument& doc)
  35. :
  36.   Tag(0), ViewMenu(0)
  37. {
  38.   ViewId = NextViewId;
  39.   doc.AttachView(*this);
  40. }
  41.  
  42. //
  43. //
  44. //
  45. TView::~TView()
  46. {
  47.   delete ViewMenu;
  48.  
  49.   CHECK(Doc);
  50.   if (Doc->DetachView(*this)) {
  51.     delete Doc;
  52.   }
  53. }
  54.  
  55. //
  56. //
  57. //
  58. void
  59. TView::SetViewMenu(TMenuDescr* menu)
  60. {
  61.   delete ViewMenu;
  62.   ViewMenu = menu;
  63.   TDocTemplate* tpl = Doc->GetTemplate();
  64.   if (tpl && ViewMenu && *ViewMenu->GetModule() == *tpl->GetModule())
  65.     ViewMenu->SetModule(tpl->GetModule());// force same module alias as template
  66. }
  67.  
  68. static char* TView_PropertyNames[] = {
  69.   "View Class",      // ViewClass
  70.   "View Name",       // ViewName
  71. };
  72.  
  73. static int TView_PropertyFlags[] = {
  74.   pfGetText|pfConstant,  // ViewClass
  75.   pfGetText|pfConstant,  // ViewName
  76. };
  77.  
  78. //
  79. //
  80. //
  81. const char*
  82. TView::PropertyName(int index)
  83. {
  84.   if (index <= PrevProperty) {
  85.     TRACEX(OwlDocView, 0, "PropertyName(): index <= PrevProperty!");
  86.     return 0;
  87.   }
  88.   else if (index < NextProperty)
  89.     return TView_PropertyNames[index-PrevProperty-1];
  90.   else {
  91.     TRACEX(OwlDocView, 0, "PropertyName(): index >= NextProperty!");
  92.     return 0;
  93.   }
  94. }
  95.  
  96. //
  97. //
  98. //
  99. int
  100. TView::PropertyFlags(int index)
  101. {
  102.   if (index <= PrevProperty) {
  103.     TRACEX(OwlDocView, 0, "PropertyFlags(): index <= PrevProperty!");
  104.     return 0;
  105.   }
  106.   else if (index < NextProperty)
  107.     return TView_PropertyFlags[index-PrevProperty-1];
  108.   else {
  109.     TRACEX(OwlDocView, 0, "PropertyFlags(): index >= NextProperty!");
  110.     return 0;
  111.   }
  112. }
  113.  
  114. //
  115. //
  116. //
  117. int
  118. TView::FindProperty(const char far* name)
  119. {
  120.   int i;
  121.   for (i=0; i < NextProperty-PrevProperty-1; i++)
  122.     if (strcmp(TView_PropertyNames[i], name) == 0)
  123.       return i+PrevProperty+1;
  124.  
  125.   TRACEX(OwlDocView, 0, "FindProperty(): " \
  126.         "index of [" << string(name) << "] not found" );
  127.   return 0;
  128. }
  129.  
  130. //
  131. //
  132. //
  133. int
  134. TView::GetProperty(int prop, void far* dest, int textlen)
  135. {
  136.   const char far* src;
  137.   switch (prop) {
  138.  
  139.     case ViewClass:
  140.       src = _TYPENAME(this);
  141.       break;
  142.  
  143.     case ViewName:
  144.       src = GetViewName();
  145.       break;
  146.  
  147.     default:
  148.       TRACEX(OwlDocView, 0, "GetProperty(): " \
  149.             "invalid property [" << prop << "] specified!" );
  150.       return 0;
  151.   }
  152.  
  153.   if (!textlen) {
  154.     TRACEX(OwlDocView, 0, "GetProperty(): 0-Length buffer specified!");
  155.     return 0;
  156.   }
  157.  
  158.   int srclen = src ? strlen(src) : 0;
  159.   if (textlen > srclen)
  160.     textlen = srclen;
  161.   if (textlen)
  162.     memcpy(dest, src, textlen);
  163.   *((char far*)dest + textlen) = 0;
  164.   return srclen;
  165. }
  166.  
  167. //
  168. // Increment an internal count used by the Doc/View subsystem to identify
  169. // each view.
  170. //
  171. void
  172. TView::BumpNextViewId()
  173. {
  174.   if (++NextViewId < MinUniqueViewId)
  175.     NextViewId = MinUniqueViewId;
  176. }
  177.  
  178. //----------------------------------------------------------------------------
  179. // TWindowView Implementation
  180. //
  181.  
  182. DEFINE_RESPONSE_TABLE1(TWindowView, TWindow)
  183.   EV_VN_ISWINDOW,
  184. END_RESPONSE_TABLE;
  185.  
  186. //
  187. //
  188. //
  189. TWindowView::TWindowView(TDocument& doc, TWindow* parent)
  190. :
  191.   TView(doc),
  192.   TWindow(parent, 0, doc.GetDocManager().GetApplication())
  193. {
  194. }
  195.  
  196. //
  197. // Does a given HWND belong to this view? Yes if it is us, or a child of us
  198. //
  199. bool
  200. TWindowView::VnIsWindow(HWND hWnd)
  201. {
  202.   return hWnd == GetHandle() || IsChild(hWnd);
  203. }
  204.  
  205. #endif
  206. //----------------------------------------------------------------------------
  207. #if !defined(SECTION) || SECTION == 2
  208.  
  209. IMPLEMENT_ABSTRACT_STREAMABLE(TView);
  210. IMPLEMENT_STREAMABLE2(TWindowView, TWindow, TView);
  211.  
  212. #if !defined(BI_NO_OBJ_STREAMING)
  213.  
  214. //
  215. //
  216. //
  217. void*
  218. TView::Streamer::Read(ipstream& is, uint32 /*version*/) const
  219. {
  220.   TView* o = GetObject();
  221.   bool hasViewMenu = is.readByte();
  222.   if (hasViewMenu) {
  223.     o->ViewMenu = new TMenuDescr;
  224.     is >> *o->ViewMenu;
  225.   }
  226.   else
  227.     o->ViewMenu = 0;
  228.   is >> o->ViewId;
  229.   is >> o->Doc;
  230.   is >> o->NextView;
  231.   return o;
  232. }
  233.  
  234. //
  235. //
  236. //
  237. void
  238. TView::Streamer::Write(opstream& os) const
  239. {
  240.   TView* o = GetObject();
  241.   os.writeByte(int16(o->ViewMenu ? 1 : 0));
  242.   if (o->ViewMenu)
  243.     os << *o->ViewMenu;
  244.   os << o->ViewId;
  245.   os << o->Doc;
  246.   os << o->NextView;
  247. }
  248.  
  249. //
  250. //
  251. //
  252. void*
  253. TWindowView::Streamer::Read(ipstream& is, uint32 /*version*/) const
  254. {
  255.   ReadBaseObject((TWindow*)GetObject(), is);
  256.   ReadBaseObject((TView*)GetObject(), is);
  257.   return GetObject();
  258. }
  259.  
  260. //
  261. //
  262. //
  263. void
  264. TWindowView::Streamer::Write(opstream& os) const
  265. {
  266.   WriteBaseObject((TWindow*)GetObject(), os);
  267.   WriteBaseObject((TView*)GetObject(), os);
  268. }
  269.  
  270. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  271.  
  272. #endif
  273.