1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Doc/View classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #if wxUSE_DOC_VIEW_ARCHITECTURE
21 #include "wx/string.h"
23 #include "wx/filehistory.h"
24 #include "wx/vector.h"
26 #if wxUSE_PRINTING_ARCHITECTURE
30 class WXDLLIMPEXP_FWD_CORE wxWindow
;
31 class WXDLLIMPEXP_FWD_CORE wxDocument
;
32 class WXDLLIMPEXP_FWD_CORE wxView
;
33 class WXDLLIMPEXP_FWD_CORE wxDocTemplate
;
34 class WXDLLIMPEXP_FWD_CORE wxDocManager
;
35 class WXDLLIMPEXP_FWD_CORE wxPrintInfo
;
36 class WXDLLIMPEXP_FWD_CORE wxCommandProcessor
;
37 class WXDLLIMPEXP_FWD_BASE wxConfigBase
;
39 class wxDocChildFrameAnyBase
;
41 #if wxUSE_STD_IOSTREAM
42 #include "wx/iosfwrap.h"
44 #include "wx/stream.h"
47 // Flags for wxDocManager (can be combined).
54 // Document template flags
57 wxTEMPLATE_VISIBLE
= 1,
58 wxTEMPLATE_INVISIBLE
= 2,
59 wxDEFAULT_TEMPLATE_FLAGS
= wxTEMPLATE_VISIBLE
62 #define wxMAX_FILE_HISTORY 9
64 typedef wxVector
<wxDocument
*> wxDocVector
;
65 typedef wxVector
<wxView
*> wxViewVector
;
66 typedef wxVector
<wxDocTemplate
*> wxDocTemplateVector
;
68 class WXDLLIMPEXP_CORE wxDocument
: public wxEvtHandler
71 wxDocument(wxDocument
*parent
= NULL
);
72 virtual ~wxDocument();
75 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
76 wxString
GetFilename() const { return m_documentFile
; }
78 void SetTitle(const wxString
& title
) { m_documentTitle
= title
; }
79 wxString
GetTitle() const { return m_documentTitle
; }
81 void SetDocumentName(const wxString
& name
) { m_documentTypeName
= name
; }
82 wxString
GetDocumentName() const { return m_documentTypeName
; }
84 // access the flag indicating whether this document had been already saved,
85 // SetDocumentSaved() is only used internally, don't call it
86 bool GetDocumentSaved() const { return m_savedYet
; }
87 void SetDocumentSaved(bool saved
= true) { m_savedYet
= saved
; }
89 // return true if the document hasn't been modified since the last time it
90 // was saved (implying that it returns false if it was never saved, even if
91 // the document is not modified)
92 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
96 virtual bool SaveAs();
97 virtual bool Revert();
99 #if wxUSE_STD_IOSTREAM
100 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
101 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
103 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
104 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
107 // Called by wxWidgets
108 virtual bool OnSaveDocument(const wxString
& filename
);
109 virtual bool OnOpenDocument(const wxString
& filename
);
110 virtual bool OnNewDocument();
111 virtual bool OnCloseDocument();
113 // Prompts for saving if about to close a modified document. Returns true
114 // if ok to close the document (may have saved in the meantime, or set
115 // modified to false)
116 virtual bool OnSaveModified();
118 // if you override, remember to call the default
119 // implementation (wxDocument::OnChangeFilename)
120 virtual void OnChangeFilename(bool notifyViews
);
122 // Called by framework if created automatically by the default document
123 // manager: gives document a chance to initialise and (usually) create a
125 virtual bool OnCreate(const wxString
& path
, long flags
);
127 // By default, creates a base wxCommandProcessor.
128 virtual wxCommandProcessor
*OnCreateCommandProcessor();
129 virtual wxCommandProcessor
*GetCommandProcessor() const
130 { return m_commandProcessor
; }
131 virtual void SetCommandProcessor(wxCommandProcessor
*proc
)
132 { m_commandProcessor
= proc
; }
134 // Called after a view is added or removed. The default implementation
135 // deletes the document if this is there are no more views.
136 virtual void OnChangedViewList();
138 // Called from OnCloseDocument(), does nothing by default but may be
139 // overridden. Return value is ignored.
140 virtual bool DeleteContents();
142 virtual bool Draw(wxDC
&);
143 virtual bool IsModified() const { return m_documentModified
; }
144 virtual void Modify(bool mod
);
146 virtual bool AddView(wxView
*view
);
147 virtual bool RemoveView(wxView
*view
);
150 wxViewVector
GetViewsVector() const;
151 #endif // !__VISUALC6__
153 wxList
& GetViews() { return m_documentViews
; }
154 const wxList
& GetViews() const { return m_documentViews
; }
156 wxView
*GetFirstView() const;
158 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
159 virtual void NotifyClosing();
161 // Remove all views (because we're closing the document)
162 virtual bool DeleteAllViews();
165 virtual wxDocManager
*GetDocumentManager() const;
166 virtual wxDocTemplate
*GetDocumentTemplate() const
167 { return m_documentTemplate
; }
168 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
169 { m_documentTemplate
= temp
; }
171 // Get the document name to be shown to the user: the title if there is
172 // any, otherwise the filename if the document was saved and, finally,
173 // "unnamed" otherwise
174 virtual wxString
GetUserReadableName() const;
176 #if WXWIN_COMPATIBILITY_2_8
177 // use GetUserReadableName() instead
178 wxDEPRECATED_BUT_USED_INTERNALLY(
179 virtual bool GetPrintableName(wxString
& buf
) const
181 #endif // WXWIN_COMPATIBILITY_2_8
183 // Returns a window that can be used as a parent for document-related
184 // dialogs. Override if necessary.
185 virtual wxWindow
*GetDocumentWindow() const;
187 // Returns true if this document is a child document corresponding to a
188 // part of the parent document and not a disk file as usual.
189 bool IsChildDocument() const { return m_documentParent
!= NULL
; }
192 wxList m_documentViews
;
193 wxString m_documentFile
;
194 wxString m_documentTitle
;
195 wxString m_documentTypeName
;
196 wxDocTemplate
* m_documentTemplate
;
197 bool m_documentModified
;
199 // if the document parent is non-NULL, it's a pseudo-document corresponding
200 // to a part of the parent document which can't be saved or loaded
201 // independently of its parent and is always closed when its parent is
202 wxDocument
* m_documentParent
;
204 wxCommandProcessor
* m_commandProcessor
;
207 // Called by OnSaveDocument and OnOpenDocument to implement standard
208 // Save/Load behaviour. Re-implement in derived class for custom
210 virtual bool DoSaveDocument(const wxString
& file
);
211 virtual bool DoOpenDocument(const wxString
& file
);
213 // the default implementation of GetUserReadableName()
214 wxString
DoGetUserReadableName() const;
217 // list of all documents whose m_documentParent is this one
218 typedef wxDList
<wxDocument
> DocsList
;
219 DocsList m_childDocuments
;
221 DECLARE_ABSTRACT_CLASS(wxDocument
)
222 wxDECLARE_NO_COPY_CLASS(wxDocument
);
225 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
231 wxDocument
*GetDocument() const { return m_viewDocument
; }
232 virtual void SetDocument(wxDocument
*doc
);
234 wxString
GetViewName() const { return m_viewTypeName
; }
235 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
237 wxWindow
*GetFrame() const { return m_viewFrame
; }
238 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
240 virtual void OnActivateView(bool activate
,
242 wxView
*deactiveView
);
243 virtual void OnDraw(wxDC
*dc
) = 0;
244 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
245 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
246 virtual void OnClosingDocument() {}
247 virtual void OnChangeFilename();
249 // Called by framework if created automatically by the default document
250 // manager class: gives view a chance to initialise
251 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
254 // Checks if the view is the last one for the document; if so, asks user
255 // to confirm save data (if modified). If ok, deletes itself and returns
257 virtual bool Close(bool deleteWindow
= true);
259 // Override to do cleanup/veto close
260 virtual bool OnClose(bool deleteWindow
);
262 // A view's window can call this to notify the view it is (in)active.
263 // The function then notifies the document manager.
264 virtual void Activate(bool activate
);
266 wxDocManager
*GetDocumentManager() const
267 { return m_viewDocument
->GetDocumentManager(); }
269 #if wxUSE_PRINTING_ARCHITECTURE
270 virtual wxPrintout
*OnCreatePrintout();
273 // implementation only
274 // -------------------
276 // set the associated frame, it is used to reset its view when we're
278 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
281 // hook the document into event handlers chain here
282 virtual bool TryBefore(wxEvent
& event
);
284 wxDocument
* m_viewDocument
;
285 wxString m_viewTypeName
;
286 wxWindow
* m_viewFrame
;
288 wxDocChildFrameAnyBase
*m_docChildFrame
;
291 DECLARE_ABSTRACT_CLASS(wxView
)
292 wxDECLARE_NO_COPY_CLASS(wxView
);
295 // Represents user interface (and other) properties of documents and views
296 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
299 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
302 // Associate document and view types. They're for identifying what view is
303 // associated with what template/document type
304 wxDocTemplate(wxDocManager
*manager
,
305 const wxString
& descr
,
306 const wxString
& filter
,
309 const wxString
& docTypeName
,
310 const wxString
& viewTypeName
,
311 wxClassInfo
*docClassInfo
= NULL
,
312 wxClassInfo
*viewClassInfo
= NULL
,
313 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
315 virtual ~wxDocTemplate();
317 // By default, these two member functions dynamically creates document and
318 // view using dynamic instance construction. Override these if you need a
319 // different method of construction.
320 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
321 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
323 // Helper method for CreateDocument; also allows you to do your own document
325 virtual bool InitDocument(wxDocument
* doc
,
326 const wxString
& path
,
329 wxString
GetDefaultExtension() const { return m_defaultExt
; }
330 wxString
GetDescription() const { return m_description
; }
331 wxString
GetDirectory() const { return m_directory
; }
332 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
333 void SetDocumentManager(wxDocManager
*manager
)
334 { m_documentManager
= manager
; }
335 wxString
GetFileFilter() const { return m_fileFilter
; }
336 long GetFlags() const { return m_flags
; }
337 virtual wxString
GetViewName() const { return m_viewTypeName
; }
338 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
340 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
341 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
342 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
343 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
344 void SetFlags(long flags
) { m_flags
= flags
; }
346 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
348 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
349 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
351 virtual bool FileMatchesTemplate(const wxString
& path
);
355 wxString m_fileFilter
;
356 wxString m_directory
;
357 wxString m_description
;
358 wxString m_defaultExt
;
359 wxString m_docTypeName
;
360 wxString m_viewTypeName
;
361 wxDocManager
* m_documentManager
;
363 // For dynamic creation of appropriate instances.
364 wxClassInfo
* m_docClassInfo
;
365 wxClassInfo
* m_viewClassInfo
;
367 // Called by CreateDocument and CreateView to create the actual
368 // document/view object.
370 // By default uses the ClassInfo provided to the constructor. Override
371 // these functions to provide a different method of creation.
372 virtual wxDocument
*DoCreateDocument();
373 virtual wxView
*DoCreateView();
376 DECLARE_CLASS(wxDocTemplate
)
377 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
380 // One object of this class may be created in an application, to manage all
381 // the templates and documents.
382 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
385 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
386 wxDocManager(long flags
= 0, bool initialize
= true);
387 virtual ~wxDocManager();
389 virtual bool Initialize();
391 // Handlers for common user commands
392 void OnFileClose(wxCommandEvent
& event
);
393 void OnFileCloseAll(wxCommandEvent
& event
);
394 void OnFileNew(wxCommandEvent
& event
);
395 void OnFileOpen(wxCommandEvent
& event
);
396 void OnFileRevert(wxCommandEvent
& event
);
397 void OnFileSave(wxCommandEvent
& event
);
398 void OnFileSaveAs(wxCommandEvent
& event
);
399 void OnMRUFile(wxCommandEvent
& event
);
400 #if wxUSE_PRINTING_ARCHITECTURE
401 void OnPrint(wxCommandEvent
& event
);
402 void OnPreview(wxCommandEvent
& event
);
403 void OnPageSetup(wxCommandEvent
& event
);
404 #endif // wxUSE_PRINTING_ARCHITECTURE
405 void OnUndo(wxCommandEvent
& event
);
406 void OnRedo(wxCommandEvent
& event
);
408 // Handlers for UI update commands
409 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
410 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
411 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
412 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
413 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
414 void OnUpdateFileSaveAs(wxUpdateUIEvent
& event
);
415 void OnUpdateUndo(wxUpdateUIEvent
& event
);
416 void OnUpdateRedo(wxUpdateUIEvent
& event
);
418 // called when file format detection didn't work, can be overridden to do
419 // something in this case
420 virtual void OnOpenFileFailure() { }
422 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
424 // wrapper around CreateDocument() with a more clear name
425 wxDocument
*CreateNewDocument()
426 { return CreateDocument(wxString(), wxDOC_NEW
); }
428 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
429 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
430 virtual bool FlushDoc(wxDocument
*doc
);
431 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
432 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
433 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
434 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
435 int noTemplates
, bool sort
= false);
436 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
437 int noTemplates
, bool sort
= false);
438 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
440 void AssociateTemplate(wxDocTemplate
*temp
);
441 void DisassociateTemplate(wxDocTemplate
*temp
);
443 // Find template from document class info, may return NULL.
444 wxDocTemplate
* FindTemplate(const wxClassInfo
* documentClassInfo
);
446 wxDocument
*GetCurrentDocument() const;
448 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
449 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
451 // Add and remove a document from the manager's list
452 void AddDocument(wxDocument
*doc
);
453 void RemoveDocument(wxDocument
*doc
);
455 // closes all currently open documents
456 bool CloseDocuments(bool force
= true);
458 // closes the specified document
459 bool CloseDocument(wxDocument
* doc
, bool force
= false);
461 // Clear remaining documents and templates
462 bool Clear(bool force
= true);
464 // Views or windows should inform the document manager
465 // when a view is going in or out of focus
466 virtual void ActivateView(wxView
*view
, bool activate
= true);
467 virtual wxView
*GetCurrentView() const { return m_currentView
; }
470 wxDocVector
GetDocumentsVector() const;
471 wxDocTemplateVector
GetTemplatesVector() const;
472 #endif // !__VISUALC6__
474 wxList
& GetDocuments() { return m_docs
; }
475 wxList
& GetTemplates() { return m_templates
; }
477 // Return the default name for a new document (by default returns strings
478 // in the form "unnamed <counter>" but can be overridden)
479 virtual wxString
MakeNewDocumentName();
481 // Make a frame title (override this to do something different)
482 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
484 virtual wxFileHistory
*OnCreateFileHistory();
485 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
487 // File history management
488 virtual void AddFileToHistory(const wxString
& file
);
489 virtual void RemoveFileFromHistory(size_t i
);
490 virtual size_t GetHistoryFilesCount() const;
491 virtual wxString
GetHistoryFile(size_t i
) const;
492 virtual void FileHistoryUseMenu(wxMenu
*menu
);
493 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
495 virtual void FileHistoryLoad(const wxConfigBase
& config
);
496 virtual void FileHistorySave(wxConfigBase
& config
);
497 #endif // wxUSE_CONFIG
499 virtual void FileHistoryAddFilesToMenu();
500 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
502 wxString
GetLastDirectory() const;
503 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
505 // Get the current document manager
506 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
508 #if wxUSE_PRINTING_ARCHITECTURE
509 wxPageSetupDialogData
& GetPageSetupDialogData()
510 { return m_pageSetupDialogData
; }
511 const wxPageSetupDialogData
& GetPageSetupDialogData() const
512 { return m_pageSetupDialogData
; }
513 #endif // wxUSE_PRINTING_ARCHITECTURE
515 #if WXWIN_COMPATIBILITY_2_8
516 // deprecated, override GetDefaultName() instead
517 wxDEPRECATED_BUT_USED_INTERNALLY(
518 virtual bool MakeDefaultName(wxString
& buf
)
522 #if WXWIN_COMPATIBILITY_2_6
523 // deprecated, use GetHistoryFilesCount() instead
524 wxDEPRECATED( size_t GetNoHistoryFiles() const );
525 #endif // WXWIN_COMPATIBILITY_2_6
529 // Called when a file selected from the MRU list doesn't exist any more.
530 // The default behaviour is to remove the file from the MRU and notify the
531 // user about it but this method can be overridden to customize it.
532 virtual void OnMRUFileNotExist(unsigned n
, const wxString
& filename
);
534 // Open the MRU file with the given index in our associated file history.
535 void DoOpenMRUFile(unsigned n
);
536 #if wxUSE_PRINTING_ARCHITECTURE
537 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
539 const wxString
& title
);
540 #endif // wxUSE_PRINTING_ARCHITECTURE
542 // hook the currently active view into event handlers chain here
543 virtual bool TryBefore(wxEvent
& event
);
545 // return the command processor for the current document, if any
546 wxCommandProcessor
*GetCurrentCommandProcessor() const;
548 // this method tries to find an active view harder than GetCurrentView():
549 // if the latter is NULL, it also checks if we don't have just a single
550 // view and returns it then
551 wxView
*GetActiveView() const;
553 // activate the first view of the given document if any
554 void ActivateDocument(wxDocument
*doc
);
557 int m_defaultDocumentNameCounter
;
561 wxView
* m_currentView
;
562 wxFileHistory
* m_fileHistory
;
563 wxString m_lastDirectory
;
564 static wxDocManager
* sm_docManager
;
566 #if wxUSE_PRINTING_ARCHITECTURE
567 wxPageSetupDialogData m_pageSetupDialogData
;
568 #endif // wxUSE_PRINTING_ARCHITECTURE
570 DECLARE_EVENT_TABLE()
571 DECLARE_DYNAMIC_CLASS(wxDocManager
)
572 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
575 #if WXWIN_COMPATIBILITY_2_6
576 inline size_t wxDocManager::GetNoHistoryFiles() const
578 return GetHistoryFilesCount();
580 #endif // WXWIN_COMPATIBILITY_2_6
582 // ----------------------------------------------------------------------------
583 // Base class for child frames -- this is what wxView renders itself into
585 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
586 // wxDocChildFrameAny does
587 // ----------------------------------------------------------------------------
589 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
592 // default ctor, use Create() after it
593 wxDocChildFrameAnyBase()
595 m_childDocument
= NULL
;
600 // full ctor equivalent to using the default one and Create(0
601 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
603 Create(doc
, view
, win
);
606 // method which must be called for an object created using the default ctor
608 // note that it returns bool just for consistency with Create() methods in
609 // other classes, we never return false from here
610 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
612 m_childDocument
= doc
;
617 view
->SetDocChildFrame(this);
622 // dtor doesn't need to be virtual, an object should never be destroyed via
623 // a pointer to this class
624 ~wxDocChildFrameAnyBase()
626 // prevent the view from deleting us if we're being deleted directly
627 // (and not via Close() + Destroy())
629 m_childView
->SetDocChildFrame(NULL
);
632 wxDocument
*GetDocument() const { return m_childDocument
; }
633 wxView
*GetView() const { return m_childView
; }
634 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
635 void SetView(wxView
*view
) { m_childView
= view
; }
637 wxWindow
*GetWindow() const { return m_win
; }
640 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
641 // which is called from TryBefore() of the derived classes to give our view
642 // a chance to process the message before the frame event handlers are used
643 bool TryProcessEvent(wxEvent
& event
)
645 return m_childView
&& m_childView
->ProcessEventLocally(event
);
648 // called from EVT_CLOSE handler in the frame: check if we can close and do
649 // cleanup if so; veto the event otherwise
650 bool CloseView(wxCloseEvent
& event
);
653 wxDocument
* m_childDocument
;
656 // the associated window: having it here is not terribly elegant but it
657 // allows us to avoid having any virtual functions in this class
661 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
664 // ----------------------------------------------------------------------------
665 // Template implementing child frame concept using the given wxFrame-like class
667 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
668 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
669 // derived class as long as it provided a ctor with the same signature as
670 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
672 // ----------------------------------------------------------------------------
674 template <class ChildFrame
, class ParentFrame
>
675 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
676 public wxDocChildFrameAnyBase
679 typedef ChildFrame BaseClass
;
681 // default ctor, use Create after it
682 wxDocChildFrameAny() { }
684 // ctor for a frame showing the given view of the specified document
685 wxDocChildFrameAny(wxDocument
*doc
,
689 const wxString
& title
,
690 const wxPoint
& pos
= wxDefaultPosition
,
691 const wxSize
& size
= wxDefaultSize
,
692 long style
= wxDEFAULT_FRAME_STYLE
,
693 const wxString
& name
= wxFrameNameStr
)
695 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
698 bool Create(wxDocument
*doc
,
702 const wxString
& title
,
703 const wxPoint
& pos
= wxDefaultPosition
,
704 const wxSize
& size
= wxDefaultSize
,
705 long style
= wxDEFAULT_FRAME_STYLE
,
706 const wxString
& name
= wxFrameNameStr
)
708 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
711 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
714 this->Connect(wxEVT_ACTIVATE
,
715 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
716 this->Connect(wxEVT_CLOSE_WINDOW
,
717 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
722 virtual bool Destroy()
724 // FIXME: why exactly do we do this? to avoid activation events during
725 // destructions maybe?
727 return BaseClass::Destroy();
731 // hook the child view into event handlers chain here
732 virtual bool TryBefore(wxEvent
& event
)
734 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
738 void OnActivate(wxActivateEvent
& event
)
740 BaseClass::OnActivate(event
);
743 m_childView
->Activate(event
.GetActive());
746 void OnCloseWindow(wxCloseEvent
& event
)
748 if ( CloseView(event
) )
753 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
754 ChildFrame
, ParentFrame
);
757 // ----------------------------------------------------------------------------
758 // A default child frame: we need to define it as a class just for wxRTTI,
759 // otherwise we could simply typedef it
760 // ----------------------------------------------------------------------------
763 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
764 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
765 // template will be DLL-exported but only once it is used as base class
767 #pragma warning (push)
768 #pragma warning (disable:4275)
771 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
773 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
780 wxDocChildFrame(wxDocument
*doc
,
784 const wxString
& title
,
785 const wxPoint
& pos
= wxDefaultPosition
,
786 const wxSize
& size
= wxDefaultSize
,
787 long style
= wxDEFAULT_FRAME_STYLE
,
788 const wxString
& name
= wxFrameNameStr
)
789 : wxDocChildFrameBase(doc
, view
,
790 parent
, id
, title
, pos
, size
, style
, name
)
794 bool Create(wxDocument
*doc
,
798 const wxString
& title
,
799 const wxPoint
& pos
= wxDefaultPosition
,
800 const wxSize
& size
= wxDefaultSize
,
801 long style
= wxDEFAULT_FRAME_STYLE
,
802 const wxString
& name
= wxFrameNameStr
)
804 return wxDocChildFrameBase::Create
807 parent
, id
, title
, pos
, size
, style
, name
812 DECLARE_CLASS(wxDocChildFrame
)
813 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
816 // ----------------------------------------------------------------------------
817 // wxDocParentFrame and related classes.
819 // As with wxDocChildFrame we define a template base class used by both normal
821 // ----------------------------------------------------------------------------
823 // Base class containing type-independent code of wxDocParentFrameAny
825 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
826 // derive from wxWindow.
827 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
830 wxDocParentFrameAnyBase() { m_docManager
= NULL
; }
832 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
835 wxDocManager
*m_docManager
;
837 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
840 // This is similar to wxDocChildFrameAny and is used to provide common
841 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
842 template <class BaseFrame
>
843 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
844 public wxDocParentFrameAnyBase
847 wxDocParentFrameAny() { }
848 wxDocParentFrameAny(wxDocManager
*manager
,
851 const wxString
& title
,
852 const wxPoint
& pos
= wxDefaultPosition
,
853 const wxSize
& size
= wxDefaultSize
,
854 long style
= wxDEFAULT_FRAME_STYLE
,
855 const wxString
& name
= wxFrameNameStr
)
857 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
860 bool Create(wxDocManager
*manager
,
863 const wxString
& title
,
864 const wxPoint
& pos
= wxDefaultPosition
,
865 const wxSize
& size
= wxDefaultSize
,
866 long style
= wxDEFAULT_FRAME_STYLE
,
867 const wxString
& name
= wxFrameNameStr
)
869 m_docManager
= manager
;
871 if ( !BaseFrame::Create(frame
, id
, title
, pos
, size
, style
, name
) )
874 this->Connect(wxID_EXIT
, wxEVT_COMMAND_MENU_SELECTED
,
875 wxCommandEventHandler(wxDocParentFrameAny::OnExit
));
876 this->Connect(wxEVT_CLOSE_WINDOW
,
877 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow
));
883 // hook the document manager into event handling chain here
884 virtual bool TryBefore(wxEvent
& event
)
886 if ( m_docManager
&& m_docManager
->ProcessEventLocally(event
) )
889 return BaseFrame::TryBefore(event
);
893 void OnExit(wxCommandEvent
& WXUNUSED(event
))
898 void OnCloseWindow(wxCloseEvent
& event
)
900 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
902 // The user decided not to close finally, abort.
907 // Just skip the event, base class handler will destroy the window.
913 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
916 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
918 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
921 wxDocParentFrame() : wxDocParentFrameBase() { }
923 wxDocParentFrame(wxDocManager
*manager
,
926 const wxString
& title
,
927 const wxPoint
& pos
= wxDefaultPosition
,
928 const wxSize
& size
= wxDefaultSize
,
929 long style
= wxDEFAULT_FRAME_STYLE
,
930 const wxString
& name
= wxFrameNameStr
)
931 : wxDocParentFrameBase(manager
,
932 parent
, id
, title
, pos
, size
, style
, name
)
936 bool Create(wxDocManager
*manager
,
939 const wxString
& title
,
940 const wxPoint
& pos
= wxDefaultPosition
,
941 const wxSize
& size
= wxDefaultSize
,
942 long style
= wxDEFAULT_FRAME_STYLE
,
943 const wxString
& name
= wxFrameNameStr
)
945 return wxDocParentFrameBase::Create(manager
,
947 pos
, size
, style
, name
);
951 DECLARE_CLASS(wxDocParentFrame
)
952 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
956 // reenable warning 4275
957 #pragma warning (pop)
960 // ----------------------------------------------------------------------------
961 // Provide simple default printing facilities
962 // ----------------------------------------------------------------------------
964 #if wxUSE_PRINTING_ARCHITECTURE
965 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
968 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
970 // implement wxPrintout methods
971 virtual bool OnPrintPage(int page
);
972 virtual bool HasPage(int page
);
973 virtual bool OnBeginDocument(int startPage
, int endPage
);
974 virtual void GetPageInfo(int *minPage
, int *maxPage
,
975 int *selPageFrom
, int *selPageTo
);
977 virtual wxView
*GetView() { return m_printoutView
; }
980 wxView
* m_printoutView
;
983 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
984 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
986 #endif // wxUSE_PRINTING_ARCHITECTURE
988 // For compatibility with existing file formats:
989 // converts from/to a stream to/from a temporary file.
990 #if wxUSE_STD_IOSTREAM
991 bool WXDLLIMPEXP_CORE
992 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
993 bool WXDLLIMPEXP_CORE
994 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
996 bool WXDLLIMPEXP_CORE
997 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
998 bool WXDLLIMPEXP_CORE
999 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
1000 #endif // wxUSE_STD_IOSTREAM
1003 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
1004 // case of existing user code using them for its own purposes
1005 #if WXWIN_COMPATIBILITY_2_8
1010 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
1012 #endif // WXWIN_COMPATIBILITY_2_8
1014 #ifndef __VISUALC6__
1015 inline wxViewVector
wxDocument::GetViewsVector() const
1017 return m_documentViews
.AsVector
<wxView
*>();
1020 inline wxDocVector
wxDocManager::GetDocumentsVector() const
1022 return m_docs
.AsVector
<wxDocument
*>();
1025 inline wxDocTemplateVector
wxDocManager::GetTemplatesVector() const
1027 return m_templates
.AsVector
<wxDocTemplate
*>();
1029 #endif // !__VISUALC6__
1031 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
1033 #endif // _WX_DOCH__