1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Doc/View classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
16 #if wxUSE_DOC_VIEW_ARCHITECTURE
20 #include "wx/string.h"
22 #include "wx/filehistory.h"
23 #include "wx/vector.h"
25 #if wxUSE_PRINTING_ARCHITECTURE
29 class WXDLLIMPEXP_FWD_CORE wxWindow
;
30 class WXDLLIMPEXP_FWD_CORE wxDocument
;
31 class WXDLLIMPEXP_FWD_CORE wxView
;
32 class WXDLLIMPEXP_FWD_CORE wxDocTemplate
;
33 class WXDLLIMPEXP_FWD_CORE wxDocManager
;
34 class WXDLLIMPEXP_FWD_CORE wxPrintInfo
;
35 class WXDLLIMPEXP_FWD_CORE wxCommandProcessor
;
36 class WXDLLIMPEXP_FWD_BASE wxConfigBase
;
38 class wxDocChildFrameAnyBase
;
40 #if wxUSE_STD_IOSTREAM
41 #include "wx/iosfwrap.h"
43 #include "wx/stream.h"
46 // Flags for wxDocManager (can be combined).
53 // Document template flags
56 wxTEMPLATE_VISIBLE
= 1,
57 wxTEMPLATE_INVISIBLE
= 2,
58 wxDEFAULT_TEMPLATE_FLAGS
= wxTEMPLATE_VISIBLE
61 #define wxMAX_FILE_HISTORY 9
63 typedef wxVector
<wxDocument
*> wxDocVector
;
64 typedef wxVector
<wxView
*> wxViewVector
;
65 typedef wxVector
<wxDocTemplate
*> wxDocTemplateVector
;
67 class WXDLLIMPEXP_CORE wxDocument
: public wxEvtHandler
70 wxDocument(wxDocument
*parent
= NULL
);
71 virtual ~wxDocument();
74 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
75 wxString
GetFilename() const { return m_documentFile
; }
77 void SetTitle(const wxString
& title
) { m_documentTitle
= title
; }
78 wxString
GetTitle() const { return m_documentTitle
; }
80 void SetDocumentName(const wxString
& name
) { m_documentTypeName
= name
; }
81 wxString
GetDocumentName() const { return m_documentTypeName
; }
83 // access the flag indicating whether this document had been already saved,
84 // SetDocumentSaved() is only used internally, don't call it
85 bool GetDocumentSaved() const { return m_savedYet
; }
86 void SetDocumentSaved(bool saved
= true) { m_savedYet
= saved
; }
88 // activate the first view of the document if any
91 // return true if the document hasn't been modified since the last time it
92 // was saved (implying that it returns false if it was never saved, even if
93 // the document is not modified)
94 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
98 virtual bool SaveAs();
99 virtual bool Revert();
101 #if wxUSE_STD_IOSTREAM
102 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
103 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
105 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
106 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
109 // Called by wxWidgets
110 virtual bool OnSaveDocument(const wxString
& filename
);
111 virtual bool OnOpenDocument(const wxString
& filename
);
112 virtual bool OnNewDocument();
113 virtual bool OnCloseDocument();
115 // Prompts for saving if about to close a modified document. Returns true
116 // if ok to close the document (may have saved in the meantime, or set
117 // modified to false)
118 virtual bool OnSaveModified();
120 // if you override, remember to call the default
121 // implementation (wxDocument::OnChangeFilename)
122 virtual void OnChangeFilename(bool notifyViews
);
124 // Called by framework if created automatically by the default document
125 // manager: gives document a chance to initialise and (usually) create a
127 virtual bool OnCreate(const wxString
& path
, long flags
);
129 // By default, creates a base wxCommandProcessor.
130 virtual wxCommandProcessor
*OnCreateCommandProcessor();
131 virtual wxCommandProcessor
*GetCommandProcessor() const
132 { return m_commandProcessor
; }
133 virtual void SetCommandProcessor(wxCommandProcessor
*proc
)
134 { m_commandProcessor
= proc
; }
136 // Called after a view is added or removed. The default implementation
137 // deletes the document if this is there are no more views.
138 virtual void OnChangedViewList();
140 // Called from OnCloseDocument(), does nothing by default but may be
141 // overridden. Return value is ignored.
142 virtual bool DeleteContents();
144 virtual bool Draw(wxDC
&);
145 virtual bool IsModified() const { return m_documentModified
; }
146 virtual void Modify(bool mod
);
148 virtual bool AddView(wxView
*view
);
149 virtual bool RemoveView(wxView
*view
);
152 wxViewVector
GetViewsVector() const;
153 #endif // !__VISUALC6__
155 wxList
& GetViews() { return m_documentViews
; }
156 const wxList
& GetViews() const { return m_documentViews
; }
158 wxView
*GetFirstView() const;
160 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
161 virtual void NotifyClosing();
163 // Remove all views (because we're closing the document)
164 virtual bool DeleteAllViews();
167 virtual wxDocManager
*GetDocumentManager() const;
168 virtual wxDocTemplate
*GetDocumentTemplate() const
169 { return m_documentTemplate
; }
170 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
171 { m_documentTemplate
= temp
; }
173 // Get the document name to be shown to the user: the title if there is
174 // any, otherwise the filename if the document was saved and, finally,
175 // "unnamed" otherwise
176 virtual wxString
GetUserReadableName() const;
178 #if WXWIN_COMPATIBILITY_2_8
179 // use GetUserReadableName() instead
180 wxDEPRECATED_BUT_USED_INTERNALLY(
181 virtual bool GetPrintableName(wxString
& buf
) const
183 #endif // WXWIN_COMPATIBILITY_2_8
185 // Returns a window that can be used as a parent for document-related
186 // dialogs. Override if necessary.
187 virtual wxWindow
*GetDocumentWindow() const;
189 // Returns true if this document is a child document corresponding to a
190 // part of the parent document and not a disk file as usual.
191 bool IsChildDocument() const { return m_documentParent
!= NULL
; }
194 wxList m_documentViews
;
195 wxString m_documentFile
;
196 wxString m_documentTitle
;
197 wxString m_documentTypeName
;
198 wxDocTemplate
* m_documentTemplate
;
199 bool m_documentModified
;
201 // if the document parent is non-NULL, it's a pseudo-document corresponding
202 // to a part of the parent document which can't be saved or loaded
203 // independently of its parent and is always closed when its parent is
204 wxDocument
* m_documentParent
;
206 wxCommandProcessor
* m_commandProcessor
;
209 // Called by OnSaveDocument and OnOpenDocument to implement standard
210 // Save/Load behaviour. Re-implement in derived class for custom
212 virtual bool DoSaveDocument(const wxString
& file
);
213 virtual bool DoOpenDocument(const wxString
& file
);
215 // the default implementation of GetUserReadableName()
216 wxString
DoGetUserReadableName() const;
219 // list of all documents whose m_documentParent is this one
220 typedef wxDList
<wxDocument
> DocsList
;
221 DocsList m_childDocuments
;
223 DECLARE_ABSTRACT_CLASS(wxDocument
)
224 wxDECLARE_NO_COPY_CLASS(wxDocument
);
227 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
233 wxDocument
*GetDocument() const { return m_viewDocument
; }
234 virtual void SetDocument(wxDocument
*doc
);
236 wxString
GetViewName() const { return m_viewTypeName
; }
237 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
239 wxWindow
*GetFrame() const { return m_viewFrame
; }
240 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
242 virtual void OnActivateView(bool activate
,
244 wxView
*deactiveView
);
245 virtual void OnDraw(wxDC
*dc
) = 0;
246 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
247 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
248 virtual void OnClosingDocument() {}
249 virtual void OnChangeFilename();
251 // Called by framework if created automatically by the default document
252 // manager class: gives view a chance to initialise
253 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
256 // Checks if the view is the last one for the document; if so, asks user
257 // to confirm save data (if modified). If ok, deletes itself and returns
259 virtual bool Close(bool deleteWindow
= true);
261 // Override to do cleanup/veto close
262 virtual bool OnClose(bool deleteWindow
);
264 // A view's window can call this to notify the view it is (in)active.
265 // The function then notifies the document manager.
266 virtual void Activate(bool activate
);
268 wxDocManager
*GetDocumentManager() const
269 { return m_viewDocument
->GetDocumentManager(); }
271 #if wxUSE_PRINTING_ARCHITECTURE
272 virtual wxPrintout
*OnCreatePrintout();
275 // implementation only
276 // -------------------
278 // set the associated frame, it is used to reset its view when we're
280 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
283 // hook the document into event handlers chain here
284 virtual bool TryBefore(wxEvent
& event
);
286 wxDocument
* m_viewDocument
;
287 wxString m_viewTypeName
;
288 wxWindow
* m_viewFrame
;
290 wxDocChildFrameAnyBase
*m_docChildFrame
;
293 DECLARE_ABSTRACT_CLASS(wxView
)
294 wxDECLARE_NO_COPY_CLASS(wxView
);
297 // Represents user interface (and other) properties of documents and views
298 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
301 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
304 // Associate document and view types. They're for identifying what view is
305 // associated with what template/document type
306 wxDocTemplate(wxDocManager
*manager
,
307 const wxString
& descr
,
308 const wxString
& filter
,
311 const wxString
& docTypeName
,
312 const wxString
& viewTypeName
,
313 wxClassInfo
*docClassInfo
= NULL
,
314 wxClassInfo
*viewClassInfo
= NULL
,
315 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
317 virtual ~wxDocTemplate();
319 // By default, these two member functions dynamically creates document and
320 // view using dynamic instance construction. Override these if you need a
321 // different method of construction.
322 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
323 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
325 // Helper method for CreateDocument; also allows you to do your own document
327 virtual bool InitDocument(wxDocument
* doc
,
328 const wxString
& path
,
331 wxString
GetDefaultExtension() const { return m_defaultExt
; }
332 wxString
GetDescription() const { return m_description
; }
333 wxString
GetDirectory() const { return m_directory
; }
334 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
335 void SetDocumentManager(wxDocManager
*manager
)
336 { m_documentManager
= manager
; }
337 wxString
GetFileFilter() const { return m_fileFilter
; }
338 long GetFlags() const { return m_flags
; }
339 virtual wxString
GetViewName() const { return m_viewTypeName
; }
340 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
342 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
343 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
344 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
345 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
346 void SetFlags(long flags
) { m_flags
= flags
; }
348 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
350 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
351 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
353 virtual bool FileMatchesTemplate(const wxString
& path
);
357 wxString m_fileFilter
;
358 wxString m_directory
;
359 wxString m_description
;
360 wxString m_defaultExt
;
361 wxString m_docTypeName
;
362 wxString m_viewTypeName
;
363 wxDocManager
* m_documentManager
;
365 // For dynamic creation of appropriate instances.
366 wxClassInfo
* m_docClassInfo
;
367 wxClassInfo
* m_viewClassInfo
;
369 // Called by CreateDocument and CreateView to create the actual
370 // document/view object.
372 // By default uses the ClassInfo provided to the constructor. Override
373 // these functions to provide a different method of creation.
374 virtual wxDocument
*DoCreateDocument();
375 virtual wxView
*DoCreateView();
378 DECLARE_CLASS(wxDocTemplate
)
379 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
382 // One object of this class may be created in an application, to manage all
383 // the templates and documents.
384 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
387 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
388 wxDocManager(long flags
= 0, bool initialize
= true);
389 virtual ~wxDocManager();
391 virtual bool Initialize();
393 // Handlers for common user commands
394 void OnFileClose(wxCommandEvent
& event
);
395 void OnFileCloseAll(wxCommandEvent
& event
);
396 void OnFileNew(wxCommandEvent
& event
);
397 void OnFileOpen(wxCommandEvent
& event
);
398 void OnFileRevert(wxCommandEvent
& event
);
399 void OnFileSave(wxCommandEvent
& event
);
400 void OnFileSaveAs(wxCommandEvent
& event
);
401 void OnMRUFile(wxCommandEvent
& event
);
402 #if wxUSE_PRINTING_ARCHITECTURE
403 void OnPrint(wxCommandEvent
& event
);
404 void OnPreview(wxCommandEvent
& event
);
405 void OnPageSetup(wxCommandEvent
& event
);
406 #endif // wxUSE_PRINTING_ARCHITECTURE
407 void OnUndo(wxCommandEvent
& event
);
408 void OnRedo(wxCommandEvent
& event
);
410 // Handlers for UI update commands
411 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
412 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
413 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
414 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
415 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
416 void OnUpdateFileSaveAs(wxUpdateUIEvent
& event
);
417 void OnUpdateUndo(wxUpdateUIEvent
& event
);
418 void OnUpdateRedo(wxUpdateUIEvent
& event
);
420 // called when file format detection didn't work, can be overridden to do
421 // something in this case
422 virtual void OnOpenFileFailure() { }
424 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
426 // wrapper around CreateDocument() with a more clear name
427 wxDocument
*CreateNewDocument()
428 { return CreateDocument(wxString(), wxDOC_NEW
); }
430 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
431 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
432 virtual bool FlushDoc(wxDocument
*doc
);
433 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
434 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
435 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
436 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
437 int noTemplates
, bool sort
= false);
438 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
439 int noTemplates
, bool sort
= false);
440 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
442 void AssociateTemplate(wxDocTemplate
*temp
);
443 void DisassociateTemplate(wxDocTemplate
*temp
);
445 // Find template from document class info, may return NULL.
446 wxDocTemplate
* FindTemplate(const wxClassInfo
* documentClassInfo
);
448 // Find document from file name, may return NULL.
449 wxDocument
* FindDocumentByPath(const wxString
& path
) const;
451 wxDocument
*GetCurrentDocument() const;
453 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
454 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
456 // Add and remove a document from the manager's list
457 void AddDocument(wxDocument
*doc
);
458 void RemoveDocument(wxDocument
*doc
);
460 // closes all currently open documents
461 bool CloseDocuments(bool force
= true);
463 // closes the specified document
464 bool CloseDocument(wxDocument
* doc
, bool force
= false);
466 // Clear remaining documents and templates
467 bool Clear(bool force
= true);
469 // Views or windows should inform the document manager
470 // when a view is going in or out of focus
471 virtual void ActivateView(wxView
*view
, bool activate
= true);
472 virtual wxView
*GetCurrentView() const { return m_currentView
; }
474 // This method tries to find an active view harder than GetCurrentView():
475 // if the latter is NULL, it also checks if we don't have just a single
476 // view and returns it then.
477 wxView
*GetAnyUsableView() const;
481 wxDocVector
GetDocumentsVector() const;
482 wxDocTemplateVector
GetTemplatesVector() const;
483 #endif // !__VISUALC6__
485 wxList
& GetDocuments() { return m_docs
; }
486 wxList
& GetTemplates() { return m_templates
; }
488 // Return the default name for a new document (by default returns strings
489 // in the form "unnamed <counter>" but can be overridden)
490 virtual wxString
MakeNewDocumentName();
492 // Make a frame title (override this to do something different)
493 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
495 virtual wxFileHistory
*OnCreateFileHistory();
496 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
498 // File history management
499 virtual void AddFileToHistory(const wxString
& file
);
500 virtual void RemoveFileFromHistory(size_t i
);
501 virtual size_t GetHistoryFilesCount() const;
502 virtual wxString
GetHistoryFile(size_t i
) const;
503 virtual void FileHistoryUseMenu(wxMenu
*menu
);
504 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
506 virtual void FileHistoryLoad(const wxConfigBase
& config
);
507 virtual void FileHistorySave(wxConfigBase
& config
);
508 #endif // wxUSE_CONFIG
510 virtual void FileHistoryAddFilesToMenu();
511 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
513 wxString
GetLastDirectory() const;
514 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
516 // Get the current document manager
517 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
519 #if wxUSE_PRINTING_ARCHITECTURE
520 wxPageSetupDialogData
& GetPageSetupDialogData()
521 { return m_pageSetupDialogData
; }
522 const wxPageSetupDialogData
& GetPageSetupDialogData() const
523 { return m_pageSetupDialogData
; }
524 #endif // wxUSE_PRINTING_ARCHITECTURE
526 #if WXWIN_COMPATIBILITY_2_8
527 // deprecated, override GetDefaultName() instead
528 wxDEPRECATED_BUT_USED_INTERNALLY(
529 virtual bool MakeDefaultName(wxString
& buf
)
533 #if WXWIN_COMPATIBILITY_2_6
534 // deprecated, use GetHistoryFilesCount() instead
535 wxDEPRECATED( size_t GetNoHistoryFiles() const );
536 #endif // WXWIN_COMPATIBILITY_2_6
540 // Called when a file selected from the MRU list doesn't exist any more.
541 // The default behaviour is to remove the file from the MRU and notify the
542 // user about it but this method can be overridden to customize it.
543 virtual void OnMRUFileNotExist(unsigned n
, const wxString
& filename
);
545 // Open the MRU file with the given index in our associated file history.
546 void DoOpenMRUFile(unsigned n
);
547 #if wxUSE_PRINTING_ARCHITECTURE
548 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
550 const wxString
& title
);
551 #endif // wxUSE_PRINTING_ARCHITECTURE
553 // hook the currently active view into event handlers chain here
554 virtual bool TryBefore(wxEvent
& event
);
556 // return the command processor for the current document, if any
557 wxCommandProcessor
*GetCurrentCommandProcessor() const;
559 int m_defaultDocumentNameCounter
;
563 wxView
* m_currentView
;
564 wxFileHistory
* m_fileHistory
;
565 wxString m_lastDirectory
;
566 static wxDocManager
* sm_docManager
;
568 #if wxUSE_PRINTING_ARCHITECTURE
569 wxPageSetupDialogData m_pageSetupDialogData
;
570 #endif // wxUSE_PRINTING_ARCHITECTURE
572 DECLARE_EVENT_TABLE()
573 DECLARE_DYNAMIC_CLASS(wxDocManager
)
574 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
577 #if WXWIN_COMPATIBILITY_2_6
578 inline size_t wxDocManager::GetNoHistoryFiles() const
580 return GetHistoryFilesCount();
582 #endif // WXWIN_COMPATIBILITY_2_6
584 // ----------------------------------------------------------------------------
585 // Base class for child frames -- this is what wxView renders itself into
587 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
588 // wxDocChildFrameAny does
589 // ----------------------------------------------------------------------------
591 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
594 // default ctor, use Create() after it
595 wxDocChildFrameAnyBase()
597 m_childDocument
= NULL
;
602 // full ctor equivalent to using the default one and Create(0
603 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
605 Create(doc
, view
, win
);
608 // method which must be called for an object created using the default ctor
610 // note that it returns bool just for consistency with Create() methods in
611 // other classes, we never return false from here
612 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
614 m_childDocument
= doc
;
619 view
->SetDocChildFrame(this);
624 // dtor doesn't need to be virtual, an object should never be destroyed via
625 // a pointer to this class
626 ~wxDocChildFrameAnyBase()
628 // prevent the view from deleting us if we're being deleted directly
629 // (and not via Close() + Destroy())
631 m_childView
->SetDocChildFrame(NULL
);
634 wxDocument
*GetDocument() const { return m_childDocument
; }
635 wxView
*GetView() const { return m_childView
; }
636 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
637 void SetView(wxView
*view
) { m_childView
= view
; }
639 wxWindow
*GetWindow() const { return m_win
; }
642 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
643 // which is called from TryBefore() of the derived classes to give our view
644 // a chance to process the message before the frame event handlers are used
645 bool TryProcessEvent(wxEvent
& event
);
647 // called from EVT_CLOSE handler in the frame: check if we can close and do
648 // cleanup if so; veto the event otherwise
649 bool CloseView(wxCloseEvent
& event
);
652 wxDocument
* m_childDocument
;
655 // the associated window: having it here is not terribly elegant but it
656 // allows us to avoid having any virtual functions in this class
660 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
663 // ----------------------------------------------------------------------------
664 // Template implementing child frame concept using the given wxFrame-like class
666 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
667 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
668 // derived class as long as it provided a ctor with the same signature as
669 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
671 // ----------------------------------------------------------------------------
673 template <class ChildFrame
, class ParentFrame
>
674 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
675 public wxDocChildFrameAnyBase
678 typedef ChildFrame BaseClass
;
680 // default ctor, use Create after it
681 wxDocChildFrameAny() { }
683 // ctor for a frame showing the given view of the specified document
684 wxDocChildFrameAny(wxDocument
*doc
,
688 const wxString
& title
,
689 const wxPoint
& pos
= wxDefaultPosition
,
690 const wxSize
& size
= wxDefaultSize
,
691 long style
= wxDEFAULT_FRAME_STYLE
,
692 const wxString
& name
= wxFrameNameStr
)
694 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
697 bool Create(wxDocument
*doc
,
701 const wxString
& title
,
702 const wxPoint
& pos
= wxDefaultPosition
,
703 const wxSize
& size
= wxDefaultSize
,
704 long style
= wxDEFAULT_FRAME_STYLE
,
705 const wxString
& name
= wxFrameNameStr
)
707 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
710 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
713 this->Connect(wxEVT_ACTIVATE
,
714 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
715 this->Connect(wxEVT_CLOSE_WINDOW
,
716 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
721 virtual bool Destroy()
723 // FIXME: why exactly do we do this? to avoid activation events during
724 // destructions maybe?
726 return BaseClass::Destroy();
730 // hook the child view into event handlers chain here
731 virtual bool TryBefore(wxEvent
& event
)
733 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
737 void OnActivate(wxActivateEvent
& event
)
739 BaseClass::OnActivate(event
);
742 m_childView
->Activate(event
.GetActive());
745 void OnCloseWindow(wxCloseEvent
& event
)
747 if ( CloseView(event
) )
752 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
753 ChildFrame
, ParentFrame
);
756 // ----------------------------------------------------------------------------
757 // A default child frame: we need to define it as a class just for wxRTTI,
758 // otherwise we could simply typedef it
759 // ----------------------------------------------------------------------------
762 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
763 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
764 // template will be DLL-exported but only once it is used as base class
766 #pragma warning (push)
767 #pragma warning (disable:4275)
770 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
772 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
779 wxDocChildFrame(wxDocument
*doc
,
783 const wxString
& title
,
784 const wxPoint
& pos
= wxDefaultPosition
,
785 const wxSize
& size
= wxDefaultSize
,
786 long style
= wxDEFAULT_FRAME_STYLE
,
787 const wxString
& name
= wxFrameNameStr
)
788 : wxDocChildFrameBase(doc
, view
,
789 parent
, id
, title
, pos
, size
, style
, name
)
793 bool Create(wxDocument
*doc
,
797 const wxString
& title
,
798 const wxPoint
& pos
= wxDefaultPosition
,
799 const wxSize
& size
= wxDefaultSize
,
800 long style
= wxDEFAULT_FRAME_STYLE
,
801 const wxString
& name
= wxFrameNameStr
)
803 return wxDocChildFrameBase::Create
806 parent
, id
, title
, pos
, size
, style
, name
811 DECLARE_CLASS(wxDocChildFrame
)
812 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
815 // ----------------------------------------------------------------------------
816 // wxDocParentFrame and related classes.
818 // As with wxDocChildFrame we define a template base class used by both normal
820 // ----------------------------------------------------------------------------
822 // Base class containing type-independent code of wxDocParentFrameAny
824 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
825 // derive from wxWindow.
826 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
829 wxDocParentFrameAnyBase(wxWindow
* frame
)
835 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
838 // This is similar to wxDocChildFrameAnyBase method with the same name:
839 // while we're not an event handler ourselves and so can't override
840 // TryBefore(), we provide a helper that the derived template class can use
841 // from its TryBefore() implementation.
842 bool TryProcessEvent(wxEvent
& event
);
844 wxWindow
* const m_frame
;
845 wxDocManager
*m_docManager
;
847 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
850 // This is similar to wxDocChildFrameAny and is used to provide common
851 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
852 template <class BaseFrame
>
853 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
854 public wxDocParentFrameAnyBase
857 wxDocParentFrameAny() : wxDocParentFrameAnyBase(this) { }
858 wxDocParentFrameAny(wxDocManager
*manager
,
861 const wxString
& title
,
862 const wxPoint
& pos
= wxDefaultPosition
,
863 const wxSize
& size
= wxDefaultSize
,
864 long style
= wxDEFAULT_FRAME_STYLE
,
865 const wxString
& name
= wxFrameNameStr
)
866 : wxDocParentFrameAnyBase(this)
868 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
871 bool Create(wxDocManager
*manager
,
874 const wxString
& title
,
875 const wxPoint
& pos
= wxDefaultPosition
,
876 const wxSize
& size
= wxDefaultSize
,
877 long style
= wxDEFAULT_FRAME_STYLE
,
878 const wxString
& name
= wxFrameNameStr
)
880 m_docManager
= manager
;
882 if ( !BaseFrame::Create(frame
, id
, title
, pos
, size
, style
, name
) )
885 this->Connect(wxID_EXIT
, wxEVT_MENU
,
886 wxCommandEventHandler(wxDocParentFrameAny::OnExit
));
887 this->Connect(wxEVT_CLOSE_WINDOW
,
888 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow
));
894 // hook the document manager into event handling chain here
895 virtual bool TryBefore(wxEvent
& event
)
897 return TryProcessEvent(event
) || BaseFrame::TryBefore(event
);
901 void OnExit(wxCommandEvent
& WXUNUSED(event
))
906 void OnCloseWindow(wxCloseEvent
& event
)
908 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
910 // The user decided not to close finally, abort.
915 // Just skip the event, base class handler will destroy the window.
921 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
924 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
926 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
929 wxDocParentFrame() : wxDocParentFrameBase() { }
931 wxDocParentFrame(wxDocManager
*manager
,
934 const wxString
& title
,
935 const wxPoint
& pos
= wxDefaultPosition
,
936 const wxSize
& size
= wxDefaultSize
,
937 long style
= wxDEFAULT_FRAME_STYLE
,
938 const wxString
& name
= wxFrameNameStr
)
939 : wxDocParentFrameBase(manager
,
940 parent
, id
, title
, pos
, size
, style
, name
)
944 bool Create(wxDocManager
*manager
,
947 const wxString
& title
,
948 const wxPoint
& pos
= wxDefaultPosition
,
949 const wxSize
& size
= wxDefaultSize
,
950 long style
= wxDEFAULT_FRAME_STYLE
,
951 const wxString
& name
= wxFrameNameStr
)
953 return wxDocParentFrameBase::Create(manager
,
955 pos
, size
, style
, name
);
959 DECLARE_CLASS(wxDocParentFrame
)
960 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
964 // reenable warning 4275
965 #pragma warning (pop)
968 // ----------------------------------------------------------------------------
969 // Provide simple default printing facilities
970 // ----------------------------------------------------------------------------
972 #if wxUSE_PRINTING_ARCHITECTURE
973 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
976 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
978 // implement wxPrintout methods
979 virtual bool OnPrintPage(int page
);
980 virtual bool HasPage(int page
);
981 virtual bool OnBeginDocument(int startPage
, int endPage
);
982 virtual void GetPageInfo(int *minPage
, int *maxPage
,
983 int *selPageFrom
, int *selPageTo
);
985 virtual wxView
*GetView() { return m_printoutView
; }
988 wxView
* m_printoutView
;
991 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
992 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
994 #endif // wxUSE_PRINTING_ARCHITECTURE
996 // For compatibility with existing file formats:
997 // converts from/to a stream to/from a temporary file.
998 #if wxUSE_STD_IOSTREAM
999 bool WXDLLIMPEXP_CORE
1000 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
1001 bool WXDLLIMPEXP_CORE
1002 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
1004 bool WXDLLIMPEXP_CORE
1005 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
1006 bool WXDLLIMPEXP_CORE
1007 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
1008 #endif // wxUSE_STD_IOSTREAM
1011 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
1012 // case of existing user code using them for its own purposes
1013 #if WXWIN_COMPATIBILITY_2_8
1018 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
1020 #endif // WXWIN_COMPATIBILITY_2_8
1022 #ifndef __VISUALC6__
1023 inline wxViewVector
wxDocument::GetViewsVector() const
1025 return m_documentViews
.AsVector
<wxView
*>();
1028 inline wxDocVector
wxDocManager::GetDocumentsVector() const
1030 return m_docs
.AsVector
<wxDocument
*>();
1033 inline wxDocTemplateVector
wxDocManager::GetTemplatesVector() const
1035 return m_templates
.AsVector
<wxDocTemplate
*>();
1037 #endif // !__VISUALC6__
1039 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
1041 #endif // _WX_DOCH__