OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
docmanag.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TDocManager
7//------------------------------------------------------------------------------
8
9#if !defined(OWL_DOCMANAG_H)
10#define OWL_DOCMANAG_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/docview.h>
18#include <owl/applicat.h>
19#include <owl/doctpl.h>
20#include <owl/opensave.h>
21
22
23namespace owl {
24
25/// \addtogroup docview
26/// @{
27
28
29//
30/// \name Definitions of dmXxx document manager operational mode flags
31/// @{
32const uint dmSDI = 0x0001; ///< Does not support multiple open documents
33const uint dmMDI = 0x0002; ///< Supports multiple open documents
34const uint dmMenu = 0x0004; ///< Set IDs for file menu
35const uint dmSaveEnable = 0x0010; ///< Enable FileSave even if doc is unmodified
36const uint dmNoRevert = 0x0020; ///< Disable FileRevert menu item
37/// @}
38
39//
40/// Flags which are stripped off when invoking Open/Save dialogs [See
41/// SelectDocPath() method for more information ]
42//
47
48//
49/// Definitions of dnXxx document/view message notifications
50//
51enum {
52 dnCreate, ///< New document or view has been created
53 dnClose, ///< Document or view has been closed
54 dnRename ///< Document has been renamed
55};
56
57#include <owl/preclass.h>
58
59//
60/// \class TDocManager
61// ~~~~~ ~~~~~~~~~~~
62/// TDocManager creates a document manager object that manages the list of current
63/// documents and registered templates, handles standard file menu commands, and
64/// displays the user-interface for file and view selection boxes. To provide
65/// support for documents and views, an instance of TDocManager must be created by
66/// the application and attached to the application.
67///
68/// The document manager normally handles events on behalf of the documents by using
69/// a response table to process the standard CM_FILENEW, CM_FILEOPEN, CM_FILECLOSE,
70/// CM_FILESAVE, CM_FILESAVEAS, CM_FILEREVERT, CM_FILEPRINT, CM_FILEPRINTERSETUP,
71/// and CM_VIEWCREATE File menu commands. In response to a CM_FILENEW or a
72/// CM_FILEOPEN command, the document manager creates the appropriate document based
73/// on the user's selections. In response to the other commands, the document
74/// manager determines which of the open documents contains the view associated with
75/// the window that has focus. The menu commands are first sent to the window that
76/// is in focus and then through the parent window chain to the main window and
77/// finally to the application, which forwards the commands to the document manager.
78///
79/// When you create a TDocManager or a derived class, you must specify that it has
80/// either a multi-document (dmMDI) or single-document (dmSDI) interface. In
81/// addition, if you want the document manager to handle the standard file commands,
82/// you must OR dmMDI or dmSDI with dmMenu.
83///
84/// You can also enable or disable the document manager menu options by passing
85/// dmSaveEnable or dmNoRevert in the constructor. If you want to enable the
86/// File|Save menu option if the document is unmodified, pass the dmSaveEnable flag
87/// in the constructor. To disable the "Revert to Saved" menu option, pass
88/// dmNoRevert in the constructor.
89///
90/// When the application directly creates a new document and view, it can attach the
91/// view to its frame window, create MDI children, float the window, or create a
92/// splitter. However, when the document manager creates a new document and view
93/// from the File|Open or File|New menu selection, the application doesn't control
94/// the process. To give the application control, the document manager sends
95/// messages after the new document and view are successfully created. Then, the
96/// application can use the information contained in the template to determine how
97/// to install the new document or view object.
98//
99class _OWLCLASS TDocManager : virtual public TEventHandler,
100 virtual public TStreamableBase {
101 public:
102 TDocManager(int mode, TApplication* app,
104 virtual ~TDocManager();
105
106 // Retrieve template info: count, list or descriptions
107 //
108 int GetTemplateCount(TDocument* ofDocType = nullptr,
109 TView* ofViewType = nullptr);
110 virtual int GetNewTemplates(TDocTemplate** tplList, int size,
111 bool newDoc);
112 virtual int GetSaveTemplates(TDocTemplate** tplList, int size,
113 TDocument& doc, bool sameDoc);
114 virtual int GetViewTemplates(TDocTemplate** tplList, int size,
115 TDocument& doc);
116 virtual int GetTemplateDescription(TDocTemplate** tpllist,
117 int tplcount, tchar* buff = nullptr,
118 int size = 0);
119
120 // Create (construct & initialize) document and views
121 //
122 virtual TDocument* CreateAnyDoc(LPCTSTR path, long flags = 0);
123 //Sirma (Krasi)
124 virtual TDocument* CreateDoc(TDocTemplate* tpl, LPCTSTR path,
125 TDocument* parent=nullptr, long flags=0);
127 long flags);
128 // Sirma (Kalin)
129 TDocument* CreateDummyDoc();
130
131 virtual TView* CreateAnyView(TDocument& doc,long flags = 0);
132 TView* CreateView(TDocument& doc, TDocTemplate* tpl=nullptr);
133
134 // Save document
135 //
136 bool SelectSave(TDocument& doc);
137 virtual TDocTemplate* SelectAnySave(TDocument& doc, bool samedoc = true);
138 virtual bool FlushDoc(TDocument& doc); // Attempt to update changes
139
140 // Find related template or document
141 //
142 virtual TDocTemplate* MatchTemplate(LPCTSTR path);
143 virtual TDocument* GetCurrentDoc(); ///< Return doc with focus, else 0
144 TDocument* FindDocument(LPCTSTR path); ///< 0 if not found
145 static bool IsAMatch(LPCTSTR path, LPCTSTR fltr);
146 static bool MatchFilter(LPCTSTR path, LPCTSTR filters);
147
148 // Accessors
149 //
150 TApplication* GetApplication() const;
151 int& GetUntitledIndex();
152 TDocTemplate* GetTemplateList() const;
153 TDocument::List& GetDocList();
154
155 // Check Document Manager's state
156 //
157 bool IsFlagSet(int flag) const;
158 int GetModeFlags() const;
159
160 // Get or set additional OPENFILENAME flags used for Open and Save dialogs.
161 // See SelectDocPath for details.
162 //
163 long GetAdditionalFileDialogFlags() const;
164 void SetAdditionalFileDialogFlags(long);
165
166 // Manipulate template List [add, remove, etc]
167 //
168 TDocTemplate* GetNextTemplate(TDocTemplate* tpl) const;
169 void RefTemplate(TDocTemplate&); ///< add template ref
170 void UnRefTemplate(TDocTemplate&); ///< drop template ref
171 void DeleteTemplate(TDocTemplate&); ///< remove from list
172 void AttachTemplate(TDocTemplate&); ///< append to list
173
174 // Primary event handlers, public to allow direct invocation from app
175 // For backward compatibility call virtual member instead
176 void CmFileOpen();
177 void CmFileNew();
178 void CmFileClose();
179 void CmFileSave();
180 void CmFileSaveAs();
181 void CmFileRevert();
182 void CmViewCreate();
183
184 // Overridable handlers
185 virtual void FileOpen();
186 virtual void FileNew();
187 virtual void FileClose();
188 virtual void FileSave();
189 virtual void FileSaveAs();
190 virtual void FileRevert();
191 virtual void ViewCreate();
192
193 // Overrideable document manager UI functions
194 //
195 virtual uint PostDocError(TDocument& doc, uint sid,
196 uint choice = MB_OK);
197 virtual void PostEvent(int id, TDocument& doc); ///< changed doc status
198 virtual void PostEvent(int id, TView& view); ///< changed view status
199 virtual void UpdateFileMenu(TMenu& menubar);
200
201 bool NotifyAllDocs(int event, long item, TView* exclude);
202 // Delegated methods from TApplication
203 //
204 void EvPreProcessMenu(HMENU hMenu);
205 bool EvCanClose();
206 void EvWakeUp();
207
208 protected:
209
210 /// Index of last untitled document
211 //
213
214 /// Next ID to be assigned to a view
215 //
217
218 /// Helper routine used by constructor(s)
219 //
220 void Init(int mode, TApplication* app,
222
223 // Overrideable document manager UI functions
224 //
225 virtual int SelectDocType(TDocTemplate** tpllist,
226 int tplcount);
227 virtual int SelectDocPath(TDocTemplate** tpllist, int tplcount,
228 tchar * path, int buflen,
229 long flags, bool save=false, TDocument* doc = nullptr);
230 virtual int SelectViewType(TDocTemplate** tpllist,
231 int tplcount);
232
233 // Overrideable method invoked just before DocManager creates a document
234 //
235 virtual bool CreatingDoc(TDocTemplate* tpl);
236
238
239/// Holds the list of attached documents, or 0 if no documents exist.
240 TDocument::List DocList;
241
242 private:
243 int Mode; ///< Mode flags: dmxxx
244 TDocTemplate* TemplateList; ///< Chained list of doc templates
245 TApplication* Application; ///< Current application
246 TDocTemplate** TemplateHead; ///< Saved pointer Template Head
247 long AdditionalFileDialogFlags; ///< OPENFILENAME flags
248
249 // Command enabler handlers
250 //
251 void CeFileNew(TCommandEnabler& ce);
252 void CeFileOpen(TCommandEnabler& ce);
253 void CeFileSave(TCommandEnabler& ce);
254 void CeFileSaveAs(TCommandEnabler& ce);
255 void CeFileRevert(TCommandEnabler& ce);
256 void CeFileClose(TCommandEnabler& ce);
257 void CeViewCreate(TCommandEnabler& ce);
258
260
261 friend class TDocTemplate; // access to template list, PostEvent()
262 friend class TDocument; // access to Application
263
265};
266
268
269//
270/// \class TDvOpenSaveData
271// ~~~~~ ~~~~~~~~~~~~~~~
272/// TDvOpenSaveData encapsulates the information used to initialized
273/// the Open or Save As dialog box by ObjectWindows' DocView manager.
274/// Besides the typically 'OPENFILENAME' related information, it also
275/// provides methods to retrieve the template list and template count
276/// of the current Document Manager.
277//
279 public:
283
284 TDocTemplate** GetTmplList() const;
285 int GetTmplCount() const;
286
287 protected:
288 int TmplCount; ///< Number of Doc/View templates in 'TmplList'
289 int TmplIndex; ///< Index of the default template.
290 TDocTemplate** TmplList; ///< List of Doc/View templates displayed in
291 ///< Common Dialog during a File|Open or
292 ///< File|SaveAs operation.
293};
294
295//
296/// \class TDvOpenSaveDataOwner
297// ~~~~~ ~~~~~~~~~~~~~~~~~~~~
298/// TDvOpenSaveDataOwner is a mixin class used by the DocView encapsulation
299/// of the FileOpen and FileSave dialogs. It provides accessors to the
300/// template list and template count used by these dialogs. It purpose is to
301/// provide an encapsulation of code shared by the TDvFileOpenDialog an
302/// TDvFileSaveDialog class.
303//
305 public:
306 TDocTemplate** GetTmplList() const;
307 int GetTmplCount() const;
308
309 protected:
312};
313
314
315//
316/// \class TDvFileOpenDialog
317// ~~~~~ ~~~~~~~~~~~~~~~~~
318/// TDvFileOpenDialog encapsulates the FileOpen dialog used by the
319/// DocView manager. It enhances the standard ObjectWindows TFileOpenDialog
320/// by providing logic to update the dialog as the user switches amoung
321/// file types.
322//
324 public:
326 LPCTSTR title = nullptr, TModule* module = nullptr);
327 protected:
328 virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2);
329};
330
331//
332/// \class TDvFileSaveDialog
333// ~~~~~ ~~~~~~~~~~~~~~~~~
334/// TDvFileSaveDialog encapsulates the FileSave dialog used by the
335/// DocView manager. It enhances the standard ObjectWindows TFileSaveDialog
336/// by providing logic to update the dialog as the user switches amoung
337/// file types.
338//
340 public:
342 LPCTSTR title = nullptr, TModule* module = nullptr);
343 protected:
344 virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2);
345};
346
347/// \name Custom OWL Window Messages
348/// These macros handle OWL-defined window messages used internally by the
349/// framework:
350/// @{
351
352#define EV_WM_PREPROCMENU OWL_EV_(WM_OWLPREPROCMENU, EvPreProcessMenu)
353#define EV_WM_CANCLOSE OWL_EV_(WM_OWLCANCLOSE, EvCanClose)
354#define EV_WM_WAKEUP OWL_EV_(WM_OWLWAKEUP, EvWakeUp)
355
356/// @}
357
358/// @}
359
360
361#include <owl/posclass.h>
362
363
364//----------------------------------------------------------------------------
365// Inline implementations
366//
367
368//
369/// Increment the reference count of a DocView template to indicate that it's
370/// currently in use by the DocManager.
371//
373{
374 ::InterlockedIncrement(&tpl.RefCnt); //Staso: ++ is very vulnerable under multi-threading
375}
376
377//
378/// Decrement the reference count of a DocView template.
379/// \note The template is deleted when the reference count reaches zero.
380//
382{
383 if (::InterlockedDecrement(&tpl.RefCnt) == 0)//Staso: -- is very vulnerable under multi-threading
384 delete &tpl;
385}
386
387//
388/// Returns the TApplication* object associated with this DocManager.
389//
391{
392 return Application;
393}
394
395//
396/// Returns true if the specified flag is currently enabled by the
397/// DocManager or false otherwise.
398//
399inline bool TDocManager::IsFlagSet(int flag) const
400{
401 return (Mode & flag) != 0;
402}
403
404//
405/// Returns variable representing the dtXXXX flags [see DOCTPL.H for list]
406/// of the DocManager.
407//
409{
410 return Mode;
411}
412
413//
414/// Returns template following specified template - Pass in '0' as
415/// parameter to get pointer to the template list.
416//
418{
419 return tpl ? static_cast<TDocTemplate*>(tpl->GetNextTemplate()) : TemplateList;
420}
421
422//
423/// Returns the index to be used by an untitled document.
424/// \note Untitled indices start at '0' and are incremented
425/// after a new document is created.
426//
428{
429 return UntitledIndex;
430}
431
432//
433/// Returns a pointer to the list of DocView templates currently
434/// registered with the DocManager.
435//
437{
438 return TemplateList;
439}
440
441//
442/// Returns a List of document currently managed by the DocManager.
443//
445{
446 return DocList;
447}
448
449//
450/// See SelectDocPath for details.
451//
453{
454 return AdditionalFileDialogFlags;
455}
456
457//
458/// See SelectDocPath for details.
459//
461{
462 AdditionalFileDialogFlags = flags;
463}
464
465//
466/// Creates dummy document
467//
468inline
470{
471 return new TDocument(this);
472}
473
474//
475/// Public to allow direct invocation from app; for backward compatibility. Call
476/// virtual member FileOpen() instead.
477//
479{
480 FileOpen();
481}
482//
483/// Public to allow direct invocation from app; for backward compatibility. Call
484/// virtual member FileNew() instead.
485//
487{
488 FileNew();
489}
490//
491/// Public to allow direct invocation from app; for backward compatibility. Call
492/// virtual member FileClose() instead.
493//
495{
496 FileClose();
497}
498//
499/// Public to allow direct invocation from app; for backward compatibility. Call
500/// virtual member FileSave() instead.
501//
503{
504 FileSave();
505}
506//
507/// Public to allow direct invocation from app; for backward compatibility. Call
508/// virtual member FileSaveAs() instead.
509//
511{
512 FileSaveAs();
513}
514//
515/// Public to allow direct invocation from app; for backward compatibility. Call
516/// virtual member FileRevert() instead.
517//
519{
520 FileRevert();
521}
522
523//
524/// Public to allow direct invocation from app; for backward compatibility. Call
525/// virtual member ViewCreate() instead.
526//
528{
529 ViewCreate();
530}
531
532//
533/// Returns the list of templates displayed in the Open or Save
534/// dialogs used by the DocManager.
535//
537{
538 return TmplList;
539}
540
541//
542/// Returns the number of DocView templates currently displayed in the
543/// Open or Save dialogs used by the DocManager.
544//
546{
547 return TmplCount;
548}
549
550//
551/// Returns the list of templates displayed in the Open or Save
552/// dialogs used by the DocManager.
553//
555{
556 return DvData.GetTmplList();
557}
558
559//
560/// Returns the number of DocView templates currently displayed in the
561/// Open or Save dialogs used by the DocManager.
562//
564{
565 return DvData.GetTmplCount();
566}
567
568
569} // OWL namespace
570
571
572#endif // OWL_DOCMANAG_H
Definition of class TApplication.
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
TDocManager creates a document manager object that manages the list of current documents and register...
Definition docmanag.h:100
virtual void ViewCreate()
Calls CreateAnyView(*doc) where doc is the current document.
void CmFileSaveAs()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:510
TDocument * CreateDummyDoc()
Creates dummy document.
Definition docmanag.h:469
virtual void FileSave()
int GetModeFlags() const
Returns variable representing the dtXXXX flags [see DOCTPL.H for list] of the DocManager.
Definition docmanag.h:408
uint NextViewId
Next ID to be assigned to a view.
Definition docmanag.h:216
bool IsFlagSet(int flag) const
Returns true if the specified flag is currently enabled by the DocManager or false otherwise.
Definition docmanag.h:399
virtual void FileSaveAs()
SelectAnySave() is called to get a template.
friend class TDocument
Definition docmanag.h:262
virtual void FileOpen()
int UntitledIndex
Index of last untitled document.
Definition docmanag.h:212
TApplication * GetApplication() const
Returns the TApplication* object associated with this DocManager.
Definition docmanag.h:390
void CmFileOpen()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:478
long GetAdditionalFileDialogFlags() const
See SelectDocPath for details.
Definition docmanag.h:452
void CmFileSave()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:502
void CmViewCreate()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:527
TDocument::List & GetDocList()
Returns a List of document currently managed by the DocManager.
Definition docmanag.h:444
void UnRefTemplate(TDocTemplate &)
drop template ref
Definition docmanag.h:381
void SetAdditionalFileDialogFlags(long)
See SelectDocPath for details.
Definition docmanag.h:460
virtual void FileNew()
virtual void FileClose()
If the document can be closed it is closed.
int & GetUntitledIndex()
Returns the index to be used by an untitled document.
Definition docmanag.h:427
virtual void FileRevert()
void CmFileRevert()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:518
void CmFileNew()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:486
void RefTemplate(TDocTemplate &)
add template ref
Definition docmanag.h:372
void CmFileClose()
Public to allow direct invocation from app; for backward compatibility.
Definition docmanag.h:494
TDocTemplate * GetNextTemplate(TDocTemplate *tpl) const
Returns template following specified template - Pass in '0' as parameter to get pointer to the templa...
Definition docmanag.h:417
TDocTemplate * GetTemplateList() const
Returns a pointer to the list of DocView templates currently registered with the DocManager.
Definition docmanag.h:436
TDocTemplate is an abstract base class that contains document template functionality.
Definition doctpl.h:54
Document list class.
Definition docview.h:210
An abstract base class, TDocument is the base class for all document objects and serves as an interfa...
Definition docview.h:187
TDvFileOpenDialog encapsulates the FileOpen dialog used by the DocView manager.
Definition docmanag.h:323
TDvFileSaveDialog encapsulates the FileSave dialog used by the DocView manager.
Definition docmanag.h:339
TDvOpenSaveData encapsulates the information used to initialized the Open or Save As dialog box by Ob...
Definition docmanag.h:278
int TmplIndex
Index of the default template.
Definition docmanag.h:289
int TmplCount
Number of Doc/View templates in 'TmplList'.
Definition docmanag.h:288
TDocTemplate ** TmplList
List of Doc/View templates displayed in Common Dialog during a File|Open or File|SaveAs operation.
Definition docmanag.h:290
TDocTemplate ** GetTmplList() const
Returns the list of templates displayed in the Open or Save dialogs used by the DocManager.
Definition docmanag.h:536
int GetTmplCount() const
Returns the number of DocView templates currently displayed in the Open or Save dialogs used by the D...
Definition docmanag.h:545
TDvOpenSaveDataOwner is a mixin class used by the DocView encapsulation of the FileOpen and FileSave ...
Definition docmanag.h:304
int GetTmplCount() const
Returns the number of DocView templates currently displayed in the Open or Save dialogs used by the D...
Definition docmanag.h:563
TDocTemplate ** GetTmplList() const
Returns the list of templates displayed in the Open or Save dialogs used by the DocManager.
Definition docmanag.h:554
TDvOpenSaveData & DvData
Definition docmanag.h:311
TEventHandler is a base class from which you can derive classes that handle messages.
Definition eventhan.h:162
TFileOpenDialog is a modal dialog box that lets you specify the name of a file to open.
Definition opensave.h:264
TFileSaveDialog is a modal dialog box that lets you enter the name of a file to save.
Definition opensave.h:311
The TMenu class encapsulates window menus.
Definition menu.h:77
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TOpenSaveDialog structure contains information about the user's file open or save selection.
Definition opensave.h:44
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
Definition objstrm.h:108
Abstract base class for view access from document.
Definition docview.h:397
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Definition of class TDocTemplate, and class template TDocTemplateT<D,V>
owl::TDocTemplate * DocTemplateStaticHead
Templates constructed before app get linked onto this head pointer.
Definition global.cpp:66
Definition of classes TDocument, TView, TWindowView, TStream, TInStream, TOutStream.
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
#define DECLARE_STREAMABLE_OWL(cls, ver)
Definition objstrm.h:1529
#define DECLARE_STREAMABLE_INLINES(cls)
Definition objstrm.h:1538
const uint dtProhibited
Flags which are stripped off when invoking Open/Save dialogs [See SelectDocPath() method for more inf...
Definition docmanag.h:43
const uint dmNoRevert
Disable FileRevert menu item.
Definition docmanag.h:36
const uint dmSDI
Does not support multiple open documents.
Definition docmanag.h:32
const uint dmMenu
Set IDs for file menu.
Definition docmanag.h:34
const uint dmSaveEnable
Enable FileSave even if doc is unmodified.
Definition docmanag.h:35
const uint dmMDI
Supports multiple open documents.
Definition docmanag.h:33
@ dnRename
Document has been renamed.
Definition docmanag.h:54
@ dnCreate
New document or view has been created.
Definition docmanag.h:52
@ dnClose
Document or view has been closed.
Definition docmanag.h:53
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
unsigned int uint
Definition number.h:25
Definition of TOpenSave abstract, TFileOpen, TFileSave common Dialog classes.
#define public_data
Definition defs.h:207
#define _OWLCLASS
Definition defs.h:338