home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / DOCVIEW.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  15.9 KB  |  416 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //  include\owl\docview.h
  4. //  Defines classes TDocument, TView,TWindowView, TStream,TInStream,TOutStream
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_DOCVIEW_H)
  7. #define __OWL_DOCVIEW_H
  8.  
  9. #if !defined(__OWL_APPLICAT_H)
  10.   #include <owl\applicat.h>
  11. #endif
  12. #if !defined(__OWL_FRAMEWIN_H)
  13.   #include <owl\framewin.h>
  14. #endif
  15. #if !defined(__COMMDLG_H)
  16.   #include <commdlg.h>
  17. #endif
  18. #include <string.h>
  19. #include <alloc.h>
  20. #if !defined(__WIN32__)
  21.   #if !defined( _OLE2_H_ )
  22.     struct FAR FILETIME {DWORD dwLowDateTime; DWORD dwHighDateTime;};
  23.   #endif
  24.   #include <io.h>
  25. void DateTimeToFileTime(struct date* dosd, struct time* dost, FILETIME FAR* pft);
  26. BOOL FileTimeToDateTime(FILETIME FAR* pft, struct date* dosd, struct time* dost);
  27. int  FormatDateTime(struct date, struct time, void far* dest, int textlen);
  28. #endif
  29. int  FormatFileTime(FILETIME* pft, void far* dest, int textlen);
  30.  
  31. //
  32. // document open and sharing modes - used in storage and stream constructors
  33. //   note: the bits values are those of file streams, not same as RTL or OLE
  34. //
  35. enum {
  36.   ofParent    = 0,      // use open mode of parent storage
  37.   ofRead      = 0x0001, // ios::in,  open for reading
  38.   ofWrite     = 0x0002, // ios::out, open for writing
  39.   ofReadWrite = (ofRead|ofWrite),
  40.   ofAtEnd     = 0x0004, // ios::ate, seek to eof upon original open
  41.   ofAppend    = 0x0008, // ios::app, append mode: all additions at eof
  42.   ofTruncate  = 0x0010, // ios::trunc, truncate file if already exists
  43.   ofNoCreate  = 0x0020, // ios::nocreate,  open fails if file doesn't exist
  44.   ofNoReplace = 0x0040, // ios::noreplace, open fails if file already exists
  45.   ofBinary    = 0x0080, // ios::binary, binary (not text) file, no CR stripping
  46.   ofIosMask   = 0x00FF, // all of the above bits as used by class ios
  47.  
  48.   ofTransacted= 0x1000, // STGM_TRANSACTED, supports commit and revert
  49.   ofPreserve  = 0x2000, // STGM_CONVERT, backup old data of same name
  50.   ofPriority  = 0x4000, // STGM_PRIORITY, temporary efficient peeking
  51.   ofTemporary = 0x8000, // STGM_DELETEONRELEASE, delete when destructed
  52.  
  53.   shCompat    = 0x0600, // for non-compliant applications, avoid if possible
  54.   shNone      = 0x0800, // DENY_ALL functionality
  55.   shRead      = 0x0A00, // DENY_WRITE functionality
  56.   shWrite     = 0x0C00, // DENY_READ functionality
  57.   shReadWrite = 0x0E00, // DENY_NONE functionality
  58.   shDefault   = 0,      // use stream implementation default value
  59.   shMask      = (shCompat|shNone|shRead|shWrite)
  60. };
  61. #define PREV_OPEN (ofNoCreate|ofNoReplace)
  62. #define IS_PREV_OPEN(omode) ((omode & PREV_OPEN)==PREV_OPEN)
  63.  
  64. //
  65. // definitions of vnXxxx view notification event IDs
  66. // event ID's up to vnCustomBase reserved for general doc-view notifications
  67. //
  68. const int vnViewOpened = 1;   // a new view has just been constructed
  69. const int vnViewClosed = 2;   // another view is about to be destructed
  70. const int vnDocOpened  = 3;   // document has just been opened
  71. const int vnDocClosed  = 4;   // document has just been closed
  72. const int vnCommit     = 5;   // document is committing, flush cached changes
  73. const int vnRevert     = 6;   // document has reverted, reload data from doc
  74. const int vnIsDirty    = 7;   // respond TRUE if uncommitted changes present
  75. const int vnIsWindow   = 8;   // respond TRUE if passed HWND is that of view
  76. const int vnCustomBase = 100; // base of document class specific notifications
  77.  
  78. //
  79. // document and view property access flags
  80. //
  81. const int pfGetText   =  1;   // property accessible as text format
  82. const int pfGetBinary =  2;   // property accessible as native non-text format
  83. const int pfConstant  =  4;   // property is invariant for object instance
  84. const int pfSettable  =  8;   // property settable as native format
  85. const int pfUnknown   = 16;   // property defined but unavailable in object  
  86. const int pfHidden    = 32;   // property should be hidden from normal browse
  87. const int pfUserDef   =128;   // property has been user-defined at run time
  88.  
  89. class _OWLCLASS TDocManager;
  90. class _OWLCLASS TDocTemplate;
  91. class _OWLCLASS_RTL TStream;
  92. class _OWLCLASS_RTL TInStream;
  93. class _OWLCLASS_RTL TOutStream;
  94. class _OWLCLASS TDocument;
  95. class _OWLCLASS TView;
  96. class _OWLCLASS TMenuDescr;
  97.  
  98. //
  99. //  class TDocument - abstract base class for document/view management
  100. //  ----- ---------
  101. //
  102. class _OWLCLASS TDocument : public TStreamableBase {
  103.   public:
  104.     enum {
  105.       PrevProperty = 0,
  106.       DocumentClass,     // text
  107.       TemplateName,      // text
  108.       ViewCount,         // int
  109.       StoragePath,       // text
  110.       DocTitle,          // text
  111.       NextProperty,
  112.     };
  113.  
  114.     class _OWLCLASS List {
  115.       public:
  116.         List() : DocList(0) {}
  117.        ~List() {Destroy();}
  118.         BOOL Insert(TDocument* doc);  // insert new document, fails if there
  119.         BOOL Remove(TDocument* doc);  // remove document, fails if not there
  120.         TDocument* Next(const TDocument* doc); // returns first if doc=0
  121.         void Destroy();               // deletes all documents
  122.       private:
  123.         TDocument* DocList;
  124.     };
  125.  
  126.     LPVOID        Tag;          // application hook, not used internally
  127.     List          ChildDoc;     // linked child document chain
  128.  
  129.     TDocument(TDocument* parent = 0);
  130.     virtual ~TDocument();
  131.     virtual TInStream*  InStream  (int mode, LPCSTR strmId=0) {return 0;}
  132.     virtual TOutStream* OutStream (int mode, LPCSTR strmId=0) {return 0;}
  133.     virtual BOOL   Open(int mode, LPCSTR path=0) {return TRUE;}
  134.     virtual BOOL   Close();      // close document, does not delete or detach
  135.     virtual BOOL   Commit(BOOL force=FALSE); // save current data, force write
  136.     virtual BOOL   Revert(BOOL clear=FALSE); // abort changes, no reload if TRUE
  137.     virtual TDocument& RootDocument();
  138.     TDocManager&   GetDocManager() {return *DocManager;}
  139.     void           SetDocManager(TDocManager& dm);
  140.     TDocument*     GetParentDoc() {return ParentDoc;}
  141.  
  142.     TDocTemplate*  GetTemplate() {return Template;}
  143.     BOOL           SetTemplate(TDocTemplate* tpl);
  144.     virtual BOOL   SetDocPath(LPCSTR path);
  145.     LPCSTR         GetDocPath() {return DocPath;}
  146.     virtual void   SetTitle(LPCSTR title);
  147.     LPCSTR         GetTitle() {return Title;}
  148.     virtual BOOL   IsDirty();           // also queries doc and view hierarchy
  149.     void           SetDirty(BOOL dirty = TRUE){DirtyFlag = dirty;}
  150.     virtual BOOL   IsOpen()                   {return StreamList != 0;}
  151.     virtual BOOL   CanClose();           // returns FALSE if unable to close
  152.     BOOL           HasFocus(HWND hwnd);
  153.     BOOL           NotifyViews(int event, long item=0, TView* exclude=0);
  154.     TView*         QueryViews(int event, long item=0, TView* exclude=0);
  155.     virtual UINT   PostError(UINT sid, UINT choice = MB_OK);
  156.  
  157.     virtual int    PropertyCount() {return NextProperty-1;}
  158.     virtual int    FindProperty(const char far* name);// return property index
  159.     virtual int    PropertyFlags(int index);          // pfXxxxx bit array
  160.     virtual const char*  PropertyName(int index);     // locale invariant name
  161.     virtual int    GetProperty(int index, void far* dest, int textlen=0);
  162.     virtual BOOL   SetProperty(int index, const void far* src); // native type
  163.     TStream*       NextStream(const TStream* strm);
  164.     TView*         NextView(const TView* view);
  165.     int            GetOpenMode();
  166.     void           SetOpenMode(int mode);
  167.  
  168.   protected:
  169.     BOOL          DirtyFlag;    // document changed, might not represent views
  170.     virtual void  AttachStream(TStream& strm);// called from TStream constructor
  171.     virtual void  DetachStream(TStream& strm);// called from TStream destructor
  172.  
  173.   private:
  174.     TDocManager*  DocManager;   // pointer back to document manager
  175.     TDocument*    NextDoc;      // next in linked chain of active documents
  176.     TView*        ViewList;     // head of linked view chain, 0 if no views
  177.     TStream*      StreamList;   // head of linked stream chain, 0 if no streams
  178.     int           OpenMode;     // mode and protection flags
  179.     LPSTR         DocPath;      // path used to open/save document
  180.     LPSTR         Title;        // current document title, 0 if untitled
  181.     TDocument*    ParentDoc;    // parent document, 0 if this is root document
  182.     TDocTemplate* Template;     // template associated with this document
  183.  
  184.     void   ReindexFrames();          // force view title and index update
  185.     void   AttachView(TView& view);  // called from TView constructor
  186.     BOOL   DetachView(TView& view);  // called from TView destructor
  187.     TView* InitView(TView* view);    // called from template InitView
  188.  
  189.   DECLARE_ABSTRACT_STREAMABLE (_OWLCLASS,TDocument,1);
  190.   friend class _OWLCLASS TDocTemplate;  // access to InitView()
  191.   friend class _OWLCLASS TView;         // access to AttachView(), DetatchView()
  192.   friend class _OWLCLASS_RTL TStream;   // access to AttachStream(), DetachStream()
  193.   friend class _OWLCLASS TDocManager;
  194.   friend class _OWLCLASS List;          // access to NextDoc
  195. };
  196.  
  197. //
  198. //  class TStream - abstract base class for storage stream access
  199. //  ----- -------
  200. //
  201.  
  202. class _OWLCLASS_RTL TStream {
  203.   public:
  204.     TDocument& GetDocument() {return Doc;}
  205.    ~TStream()                {Doc.DetachStream(*this);}
  206.     int        GetOpenMode();
  207.     const char far* GetStreamName();
  208.  
  209.   protected:
  210.     TDocument& Doc;        // document owning this stream
  211.     TStream* NextStream;   // next stream in linked list of active streams
  212.  
  213.     TStream(TDocument& doc,     LPCSTR name,       int mode)
  214.                  : Doc(doc), StreamName(name), OpenMode(mode)
  215.               {Doc.AttachStream(*this);}
  216.  
  217.   private:
  218.     int             OpenMode;
  219.     const char far* StreamName;
  220.  
  221.   friend class TDocument;
  222. };
  223.  
  224. //
  225. //  class TInStream - base class for input streams
  226. //  ----- ---------
  227. //
  228. class _OWLCLASS_RTL TInStream : public TStream, public istream {
  229.   public:
  230.     TInStream(TDocument& doc, LPCSTR name, int mode)
  231.                : TStream(doc,        name,     mode), istream() {}
  232. };
  233.  
  234. //
  235. //  class TOutStream - base class for output streams
  236. //  ----- ---------
  237. //
  238. class _OWLCLASS_RTL TOutStream : public TStream, public ostream {
  239.   public:
  240.     TOutStream(TDocument& doc, LPCSTR name, int mode)
  241.                 : TStream(doc,        name,     mode), ostream() {}
  242. };
  243.  
  244. //
  245. //  class TView - abstract base class for view access from document
  246. //  ----- -----
  247. //
  248. class _OWLCLASS TView : virtual public TEventHandler,
  249.                         virtual public TStreamableBase {
  250.   public:
  251.     enum {
  252.       PrevProperty = 0,
  253.       ViewClass,                  // text
  254.       ViewName,                   // text
  255.       NextProperty,
  256.     };
  257.     LPVOID          Tag;        // application hook, not used internally
  258.  
  259.     TView(TDocument& doc);
  260.     virtual ~TView();
  261.     TDocument&  GetDocument() {return *Doc;}
  262.     unsigned    GetViewId()   {return ViewId;}
  263.     TMenuDescr* GetViewMenu() {return ViewMenu;} 
  264.     void        SetViewMenu(TMenuDescr* menu);
  265.     BOOL        IsOK() {return ViewId != 0;}  // TRUE if successfully created
  266.     static unsigned GetNextViewId() {return NextViewId;} // next ID to assign
  267.  
  268.     // must implement, used by template manager for selection
  269.     // static LPCSTR StaticName() {return "name of view";}
  270.     virtual LPCSTR GetViewName()=0;         // return static name of view
  271.  
  272.     virtual TWindow* GetWindow() {return 0;} // if not derived from TWindow
  273.     virtual BOOL   SetDocTitle(LPCSTR docname, int index) {return FALSE;}
  274.  
  275.     virtual int    PropertyCount() {return NextProperty - 1;}
  276.     virtual int    FindProperty(const char far* name);// return property index
  277.     virtual int    PropertyFlags(int index);          // pfXxxxx bit array
  278.     virtual const char*  PropertyName(int index);     // locale invariant name
  279.     virtual int    GetProperty(int index, void far* dest, int textlen=0);
  280.     virtual BOOL   SetProperty(int index, const void far* src) {return FALSE;}
  281.  
  282.   protected:
  283.     TDocument*   Doc;
  284.     void         NotOK() {ViewId = 0;}  // to flag errors in creation
  285.   private:
  286.     TView*       NextView;   // linked view chain, 0 if no more views
  287.     unsigned     ViewId;     // unique ID for this view, used for controls
  288.     TMenuDescr*  ViewMenu;   // menu descriptor specific for this view or 0
  289.     static unsigned NextViewId; // next view ID to be assigned
  290.  
  291.   DECLARE_ABSTRACT_STREAMABLE (_OWLCLASS,TView,1);
  292.   friend class _OWLCLASS TDocument;   // needs access to NextView
  293.   friend class TDocument::Streamer;   // needs access to NextView
  294. };
  295.  
  296. //
  297. //  class TWindowView
  298. //  ----- -----------
  299. //
  300. class _OWLCLASS TWindowView : public TWindow, public TView {
  301.   public:
  302.     TWindowView(TDocument& doc, TWindow* parent = 0)
  303.       : TView(doc), TWindow(parent) {}
  304.    ~TWindowView() {}
  305.     static LPCSTR StaticName() {return "Window View";}  // put in resource
  306.     //
  307.     // inherited virtuals from TWindow
  308.     //
  309.     BOOL     CanClose()  {return TWindow::CanClose() && Doc->CanClose();}
  310.     //
  311.     // inherited virtuals from TView
  312.     //
  313.     LPCSTR   GetViewName() {return StaticName();}
  314.     TWindow* GetWindow() {return (TWindow*)this;}
  315.     BOOL     SetDocTitle(LPCSTR docname, int index)
  316.              { return TWindow::SetDocTitle(docname, index); }
  317.   private:
  318.     //
  319.     // event handlers
  320.     //
  321.     BOOL     VnIsWindow(HWND hWnd) {return HWindow == hWnd;}
  322.  
  323.   DECLARE_RESPONSE_TABLE(TWindowView);
  324.   DECLARE_STREAMABLE (_OWLCLASS, TWindowView,1);
  325. };
  326.  
  327. //
  328. // View Notification Handler Definitions
  329. //
  330.  
  331. // Dispatchers passing data in LPARAM and returning BOOL
  332.  
  333. LRESULT _OWLFUNC
  334. B_long_Dispatch(GENERIC& generic, int (GENERIC::*pmf)(long), WPARAM, LPARAM);
  335. LRESULT _OWLFUNC
  336. B_int_Dispatch(GENERIC& generic, int (GENERIC::*pmf)(int), WPARAM, LPARAM);
  337. LRESULT _OWLFUNC
  338. B_void_Dispatch(GENERIC& generic, int (GENERIC::*pmf)(), WPARAM, LPARAM);
  339. LRESULT _OWLFUNC
  340. B_pointer_Dispatch(GENERIC& generic, int (GENERIC::*pmf)(void*), WPARAM, LPARAM);
  341.  
  342. //
  343. // handlers for new document and view notifications
  344. //
  345.  
  346. #define EV_OWLDOCUMENT(id, method)\
  347.   {WM_OWLDOCUMENT, id, (TAnyDispatcher)::v_POINTER_Dispatch,\
  348.    (TMyPMF)v_OWLDOCUMENT_Sig(&TMyClass::method)}
  349.  
  350. #define EV_OWLVIEW(id, method)\
  351.   {WM_OWLVIEW, id, (TAnyDispatcher)::v_POINTER_Dispatch,\
  352.    (TMyPMF)v_OWLVIEW_Sig(&TMyClass::method)}
  353.  
  354. #define EV_OWLNOTIFY(id, method)\
  355.   {WM_OWLNOTIFY, id, (TAnyDispatcher)::i_LPARAM_Dispatch,\
  356.    (TMyPMF)B_LPARAM_Sig(&TMyClass::method)}
  357.  
  358. #define EV_VIEWNOTIFY(id, method) \
  359.   {WM_OWLNOTIFY, id, (TAnyDispatcher)::B_long_Dispatch, \
  360.   (TMyPMF)B_LPARAM_Sig(&TMyClass::method)}
  361.  
  362. #define NOTIFY_SIG(id, arg) \
  363.   template <class T> \
  364.   inline BOOL (T::*id##_Sig(BOOL (T::*pmf)(arg)))(arg) { return pmf; }
  365.  
  366. #define VN_DEFINE(id, method, disp) \
  367.   {WM_OWLNOTIFY, id, \
  368.   (TAnyDispatcher) ::B_##disp##_Dispatch, \
  369.   (TMyPMF)id##_Sig(&TMyClass::method)}
  370.  
  371. NOTIFY_SIG(vnViewOpened,TView*)
  372. NOTIFY_SIG(vnViewClosed,TView*)
  373. NOTIFY_SIG(vnDocOpened, int)
  374. NOTIFY_SIG(vnDocClosed, int)
  375. NOTIFY_SIG(vnCommit, BOOL)
  376. NOTIFY_SIG(vnRevert, BOOL)
  377. NOTIFY_SIG(vnIsDirty, void)
  378. NOTIFY_SIG(vnIsWindow, HWND)
  379.  
  380. #define EV_VN_VIEWOPENED VN_DEFINE(vnViewOpened,VnViewOpened,pointer)
  381. #define EV_VN_VIEWCLOSED VN_DEFINE(vnViewClosed,VnViewClosed,pointer)
  382. #define EV_VN_DOCOPENED  VN_DEFINE(vnDocOpened, VnDocOpened, int)
  383. #define EV_VN_DOCCLOSED  VN_DEFINE(vnDocClosed, VnDocClosed, int)
  384. #define EV_VN_COMMIT     VN_DEFINE(vnCommit,    VnCommit,    int)
  385. #define EV_VN_REVERT     VN_DEFINE(vnRevert,    VnRevert,    int)
  386. #define EV_VN_ISDIRTY    VN_DEFINE(vnIsDirty,   VnIsDirty,   void)
  387. #define EV_VN_ISWINDOW   VN_DEFINE(vnIsWindow,  VnIsWindow,  int)
  388.  
  389. // inline implementations
  390.  
  391. inline int
  392. TDocument::GetOpenMode()
  393. {
  394.   return OpenMode;
  395. }
  396.  
  397. inline void
  398. TDocument::SetOpenMode(int mode)
  399. {
  400.   OpenMode = mode;
  401. }
  402.  
  403. inline const char far*
  404. TStream::GetStreamName()
  405. {
  406.   return StreamName;
  407. }
  408.  
  409. inline int
  410. TStream::GetOpenMode()
  411. {
  412.   return OpenMode;
  413. }
  414.  
  415. #endif  // __OWL_DOCVIEW_H
  416.