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"
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 class WXDLLIMPEXP_CORE wxDocument
: public wxEvtHandler
66 wxDocument(wxDocument
*parent
= NULL
);
67 virtual ~wxDocument();
70 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
71 wxString
GetFilename() const { return m_documentFile
; }
73 void SetTitle(const wxString
& title
) { m_documentTitle
= title
; }
74 wxString
GetTitle() const { return m_documentTitle
; }
76 void SetDocumentName(const wxString
& name
) { m_documentTypeName
= name
; }
77 wxString
GetDocumentName() const { return m_documentTypeName
; }
79 // access the flag indicating whether this document had been already saved,
80 // SetDocumentSaved() is only used internally, don't call it
81 bool GetDocumentSaved() const { return m_savedYet
; }
82 void SetDocumentSaved(bool saved
= true) { m_savedYet
= saved
; }
84 // return true if the document hasn't been modified since the last time it
85 // was saved (implying that it returns false if it was never saved, even if
86 // the document is not modified)
87 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
91 virtual bool SaveAs();
92 virtual bool Revert();
94 #if wxUSE_STD_IOSTREAM
95 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
96 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
98 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
99 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
102 // Called by wxWidgets
103 virtual bool OnSaveDocument(const wxString
& filename
);
104 virtual bool OnOpenDocument(const wxString
& filename
);
105 virtual bool OnNewDocument();
106 virtual bool OnCloseDocument();
108 // Prompts for saving if about to close a modified document. Returns true
109 // if ok to close the document (may have saved in the meantime, or set
110 // modified to false)
111 virtual bool OnSaveModified();
113 // if you override, remember to call the default
114 // implementation (wxDocument::OnChangeFilename)
115 virtual void OnChangeFilename(bool notifyViews
);
117 // Called by framework if created automatically by the default document
118 // manager: gives document a chance to initialise and (usually) create a
120 virtual bool OnCreate(const wxString
& path
, long flags
);
122 // By default, creates a base wxCommandProcessor.
123 virtual wxCommandProcessor
*OnCreateCommandProcessor();
124 virtual wxCommandProcessor
*GetCommandProcessor() const
125 { return m_commandProcessor
; }
126 virtual void SetCommandProcessor(wxCommandProcessor
*proc
)
127 { m_commandProcessor
= proc
; }
129 // Called after a view is added or removed. The default implementation
130 // deletes the document if this is there are no more views.
131 virtual void OnChangedViewList();
133 // Called from OnCloseDocument(), does nothing by default but may be
134 // overridden. Return value is ignored.
135 virtual bool DeleteContents();
137 virtual bool Draw(wxDC
&);
138 virtual bool IsModified() const { return m_documentModified
; }
139 virtual void Modify(bool mod
);
141 virtual bool AddView(wxView
*view
);
142 virtual bool RemoveView(wxView
*view
);
143 wxList
& GetViews() { return m_documentViews
; }
144 const wxList
& GetViews() const { return m_documentViews
; }
145 wxView
*GetFirstView() const;
147 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
148 virtual void NotifyClosing();
150 // Remove all views (because we're closing the document)
151 virtual bool DeleteAllViews();
154 virtual wxDocManager
*GetDocumentManager() const;
155 virtual wxDocTemplate
*GetDocumentTemplate() const
156 { return m_documentTemplate
; }
157 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
158 { m_documentTemplate
= temp
; }
160 // Get the document name to be shown to the user: the title if there is
161 // any, otherwise the filename if the document was saved and, finally,
162 // "unnamed" otherwise
163 virtual wxString
GetUserReadableName() const;
165 #if WXWIN_COMPATIBILITY_2_8
166 // use GetUserReadableName() instead
167 wxDEPRECATED_BUT_USED_INTERNALLY(
168 virtual bool GetPrintableName(wxString
& buf
) const
170 #endif // WXWIN_COMPATIBILITY_2_8
172 // Returns a window that can be used as a parent for document-related
173 // dialogs. Override if necessary.
174 virtual wxWindow
*GetDocumentWindow() const;
176 // Returns true if this document is a child document corresponding to a
177 // part of the parent document and not a disk file as usual.
178 bool IsChildDocument() const { return m_documentParent
!= NULL
; }
181 wxList m_documentViews
;
182 wxString m_documentFile
;
183 wxString m_documentTitle
;
184 wxString m_documentTypeName
;
185 wxDocTemplate
* m_documentTemplate
;
186 bool m_documentModified
;
188 // if the document parent is non-NULL, it's a pseudo-document corresponding
189 // to a part of the parent document which can't be saved or loaded
190 // independently of its parent and is always closed when its parent is
191 wxDocument
* m_documentParent
;
193 wxCommandProcessor
* m_commandProcessor
;
196 // Called by OnSaveDocument and OnOpenDocument to implement standard
197 // Save/Load behaviour. Re-implement in derived class for custom
199 virtual bool DoSaveDocument(const wxString
& file
);
200 virtual bool DoOpenDocument(const wxString
& file
);
202 // the default implementation of GetUserReadableName()
203 wxString
DoGetUserReadableName() const;
206 // list of all documents whose m_documentParent is this one
207 typedef wxDList
<wxDocument
> DocsList
;
208 DocsList m_childDocuments
;
210 DECLARE_ABSTRACT_CLASS(wxDocument
)
211 wxDECLARE_NO_COPY_CLASS(wxDocument
);
214 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
220 wxDocument
*GetDocument() const { return m_viewDocument
; }
221 virtual void SetDocument(wxDocument
*doc
);
223 wxString
GetViewName() const { return m_viewTypeName
; }
224 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
226 wxWindow
*GetFrame() const { return m_viewFrame
; }
227 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
229 virtual void OnActivateView(bool activate
,
231 wxView
*deactiveView
);
232 virtual void OnDraw(wxDC
*dc
) = 0;
233 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
234 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
235 virtual void OnClosingDocument() {}
236 virtual void OnChangeFilename();
238 // Called by framework if created automatically by the default document
239 // manager class: gives view a chance to initialise
240 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
243 // Checks if the view is the last one for the document; if so, asks user
244 // to confirm save data (if modified). If ok, deletes itself and returns
246 virtual bool Close(bool deleteWindow
= true);
248 // Override to do cleanup/veto close
249 virtual bool OnClose(bool deleteWindow
);
251 // A view's window can call this to notify the view it is (in)active.
252 // The function then notifies the document manager.
253 virtual void Activate(bool activate
);
255 wxDocManager
*GetDocumentManager() const
256 { return m_viewDocument
->GetDocumentManager(); }
258 #if wxUSE_PRINTING_ARCHITECTURE
259 virtual wxPrintout
*OnCreatePrintout();
262 // implementation only
263 // -------------------
265 // set the associated frame, it is used to reset its view when we're
267 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
270 // hook the document into event handlers chain here
271 virtual bool TryBefore(wxEvent
& event
);
273 wxDocument
* m_viewDocument
;
274 wxString m_viewTypeName
;
275 wxWindow
* m_viewFrame
;
277 wxDocChildFrameAnyBase
*m_docChildFrame
;
280 DECLARE_ABSTRACT_CLASS(wxView
)
281 wxDECLARE_NO_COPY_CLASS(wxView
);
284 // Represents user interface (and other) properties of documents and views
285 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
288 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
291 // Associate document and view types. They're for identifying what view is
292 // associated with what template/document type
293 wxDocTemplate(wxDocManager
*manager
,
294 const wxString
& descr
,
295 const wxString
& filter
,
298 const wxString
& docTypeName
,
299 const wxString
& viewTypeName
,
300 wxClassInfo
*docClassInfo
= NULL
,
301 wxClassInfo
*viewClassInfo
= NULL
,
302 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
304 virtual ~wxDocTemplate();
306 // By default, these two member functions dynamically creates document and
307 // view using dynamic instance construction. Override these if you need a
308 // different method of construction.
309 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
310 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
312 // Helper method for CreateDocument; also allows you to do your own document
314 virtual bool InitDocument(wxDocument
* doc
,
315 const wxString
& path
,
318 wxString
GetDefaultExtension() const { return m_defaultExt
; }
319 wxString
GetDescription() const { return m_description
; }
320 wxString
GetDirectory() const { return m_directory
; }
321 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
322 void SetDocumentManager(wxDocManager
*manager
)
323 { m_documentManager
= manager
; }
324 wxString
GetFileFilter() const { return m_fileFilter
; }
325 long GetFlags() const { return m_flags
; }
326 virtual wxString
GetViewName() const { return m_viewTypeName
; }
327 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
329 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
330 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
331 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
332 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
333 void SetFlags(long flags
) { m_flags
= flags
; }
335 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
337 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
338 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
340 virtual bool FileMatchesTemplate(const wxString
& path
);
344 wxString m_fileFilter
;
345 wxString m_directory
;
346 wxString m_description
;
347 wxString m_defaultExt
;
348 wxString m_docTypeName
;
349 wxString m_viewTypeName
;
350 wxDocManager
* m_documentManager
;
352 // For dynamic creation of appropriate instances.
353 wxClassInfo
* m_docClassInfo
;
354 wxClassInfo
* m_viewClassInfo
;
356 // Called by CreateDocument and CreateView to create the actual
357 // document/view object.
359 // By default uses the ClassInfo provided to the constructor. Override
360 // these functions to provide a different method of creation.
361 virtual wxDocument
*DoCreateDocument();
362 virtual wxView
*DoCreateView();
365 DECLARE_CLASS(wxDocTemplate
)
366 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
369 // One object of this class may be created in an application, to manage all
370 // the templates and documents.
371 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
374 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
375 wxDocManager(long flags
= 0, bool initialize
= true);
376 virtual ~wxDocManager();
378 virtual bool Initialize();
380 // Handlers for common user commands
381 void OnFileClose(wxCommandEvent
& event
);
382 void OnFileCloseAll(wxCommandEvent
& event
);
383 void OnFileNew(wxCommandEvent
& event
);
384 void OnFileOpen(wxCommandEvent
& event
);
385 void OnFileRevert(wxCommandEvent
& event
);
386 void OnFileSave(wxCommandEvent
& event
);
387 void OnFileSaveAs(wxCommandEvent
& event
);
388 void OnMRUFile(wxCommandEvent
& event
);
389 #if wxUSE_PRINTING_ARCHITECTURE
390 void OnPrint(wxCommandEvent
& event
);
391 void OnPreview(wxCommandEvent
& event
);
392 void OnPageSetup(wxCommandEvent
& event
);
393 #endif // wxUSE_PRINTING_ARCHITECTURE
394 void OnUndo(wxCommandEvent
& event
);
395 void OnRedo(wxCommandEvent
& event
);
397 // Handlers for UI update commands
398 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
399 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
400 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
401 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
402 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
403 void OnUpdateFileSaveAs(wxUpdateUIEvent
& event
);
404 void OnUpdateUndo(wxUpdateUIEvent
& event
);
405 void OnUpdateRedo(wxUpdateUIEvent
& event
);
407 // called when file format detection didn't work, can be overridden to do
408 // something in this case
409 virtual void OnOpenFileFailure() { }
411 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
413 // wrapper around CreateDocument() with a more clear name
414 wxDocument
*CreateNewDocument()
415 { return CreateDocument(wxString(), wxDOC_NEW
); }
417 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
418 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
419 virtual bool FlushDoc(wxDocument
*doc
);
420 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
421 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
422 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
423 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
424 int noTemplates
, bool sort
= false);
425 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
426 int noTemplates
, bool sort
= false);
427 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
429 void AssociateTemplate(wxDocTemplate
*temp
);
430 void DisassociateTemplate(wxDocTemplate
*temp
);
432 // Find template from document class info, may return NULL.
433 wxDocTemplate
* FindTemplate(const wxClassInfo
* documentClassInfo
);
435 wxDocument
*GetCurrentDocument() const;
437 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
438 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
440 // Add and remove a document from the manager's list
441 void AddDocument(wxDocument
*doc
);
442 void RemoveDocument(wxDocument
*doc
);
444 // closes all currently open documents
445 bool CloseDocuments(bool force
= true);
447 // closes the specified document
448 bool CloseDocument(wxDocument
* doc
, bool force
= false);
450 // Clear remaining documents and templates
451 bool Clear(bool force
= true);
453 // Views or windows should inform the document manager
454 // when a view is going in or out of focus
455 virtual void ActivateView(wxView
*view
, bool activate
= true);
456 virtual wxView
*GetCurrentView() const { return m_currentView
; }
458 wxList
& GetDocuments() { return m_docs
; }
459 wxList
& GetTemplates() { return m_templates
; }
461 // Return the default name for a new document (by default returns strings
462 // in the form "unnamed <counter>" but can be overridden)
463 virtual wxString
MakeNewDocumentName();
465 // Make a frame title (override this to do something different)
466 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
468 virtual wxFileHistory
*OnCreateFileHistory();
469 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
471 // File history management
472 virtual void AddFileToHistory(const wxString
& file
);
473 virtual void RemoveFileFromHistory(size_t i
);
474 virtual size_t GetHistoryFilesCount() const;
475 virtual wxString
GetHistoryFile(size_t i
) const;
476 virtual void FileHistoryUseMenu(wxMenu
*menu
);
477 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
479 virtual void FileHistoryLoad(const wxConfigBase
& config
);
480 virtual void FileHistorySave(wxConfigBase
& config
);
481 #endif // wxUSE_CONFIG
483 virtual void FileHistoryAddFilesToMenu();
484 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
486 wxString
GetLastDirectory() const;
487 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
489 // Get the current document manager
490 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
492 #if wxUSE_PRINTING_ARCHITECTURE
493 wxPageSetupDialogData
& GetPageSetupDialogData()
494 { return m_pageSetupDialogData
; }
495 const wxPageSetupDialogData
& GetPageSetupDialogData() const
496 { return m_pageSetupDialogData
; }
497 #endif // wxUSE_PRINTING_ARCHITECTURE
499 #if WXWIN_COMPATIBILITY_2_8
500 // deprecated, override GetDefaultName() instead
501 wxDEPRECATED_BUT_USED_INTERNALLY(
502 virtual bool MakeDefaultName(wxString
& buf
)
506 #if WXWIN_COMPATIBILITY_2_6
507 // deprecated, use GetHistoryFilesCount() instead
508 wxDEPRECATED( size_t GetNoHistoryFiles() const );
509 #endif // WXWIN_COMPATIBILITY_2_6
513 // Open the MRU file with the given index in our associated file history.
514 void DoOpenMRUFile(unsigned n
);
515 #if wxUSE_PRINTING_ARCHITECTURE
516 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
518 const wxString
& title
);
519 #endif // wxUSE_PRINTING_ARCHITECTURE
521 // hook the currently active view into event handlers chain here
522 virtual bool TryBefore(wxEvent
& event
);
524 // return the command processor for the current document, if any
525 wxCommandProcessor
*GetCurrentCommandProcessor() const;
527 // this method tries to find an active view harder than GetCurrentView():
528 // if the latter is NULL, it also checks if we don't have just a single
529 // view and returns it then
530 wxView
*GetActiveView() const;
532 // activate the first view of the given document if any
533 void ActivateDocument(wxDocument
*doc
);
536 int m_defaultDocumentNameCounter
;
540 wxView
* m_currentView
;
541 wxFileHistory
* m_fileHistory
;
542 wxString m_lastDirectory
;
543 static wxDocManager
* sm_docManager
;
545 #if wxUSE_PRINTING_ARCHITECTURE
546 wxPageSetupDialogData m_pageSetupDialogData
;
547 #endif // wxUSE_PRINTING_ARCHITECTURE
549 DECLARE_EVENT_TABLE()
550 DECLARE_DYNAMIC_CLASS(wxDocManager
)
551 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
554 #if WXWIN_COMPATIBILITY_2_6
555 inline size_t wxDocManager::GetNoHistoryFiles() const
557 return GetHistoryFilesCount();
559 #endif // WXWIN_COMPATIBILITY_2_6
561 // ----------------------------------------------------------------------------
562 // Base class for child frames -- this is what wxView renders itself into
564 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
565 // wxDocChildFrameAny does
566 // ----------------------------------------------------------------------------
568 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
571 // default ctor, use Create() after it
572 wxDocChildFrameAnyBase()
574 m_childDocument
= NULL
;
579 // full ctor equivalent to using the default one and Create(0
580 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
582 Create(doc
, view
, win
);
585 // method which must be called for an object created using the default ctor
587 // note that it returns bool just for consistency with Create() methods in
588 // other classes, we never return false from here
589 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
591 m_childDocument
= doc
;
596 view
->SetDocChildFrame(this);
601 // dtor doesn't need to be virtual, an object should never be destroyed via
602 // a pointer to this class
603 ~wxDocChildFrameAnyBase()
605 // prevent the view from deleting us if we're being deleted directly
606 // (and not via Close() + Destroy())
608 m_childView
->SetDocChildFrame(NULL
);
611 wxDocument
*GetDocument() const { return m_childDocument
; }
612 wxView
*GetView() const { return m_childView
; }
613 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
614 void SetView(wxView
*view
) { m_childView
= view
; }
616 wxWindow
*GetWindow() const { return m_win
; }
619 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
620 // which is called from TryBefore() of the derived classes to give our view
621 // a chance to process the message before the frame event handlers are used
622 bool TryProcessEvent(wxEvent
& event
)
624 return m_childView
&& m_childView
->ProcessEventLocally(event
);
627 // called from EVT_CLOSE handler in the frame: check if we can close and do
628 // cleanup if so; veto the event otherwise
629 bool CloseView(wxCloseEvent
& event
);
632 wxDocument
* m_childDocument
;
635 // the associated window: having it here is not terribly elegant but it
636 // allows us to avoid having any virtual functions in this class
640 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
643 // ----------------------------------------------------------------------------
644 // Template implementing child frame concept using the given wxFrame-like class
646 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
647 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
648 // derived class as long as it provided a ctor with the same signature as
649 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
651 // ----------------------------------------------------------------------------
653 template <class ChildFrame
, class ParentFrame
>
654 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
655 public wxDocChildFrameAnyBase
658 typedef ChildFrame BaseClass
;
660 // default ctor, use Create after it
661 wxDocChildFrameAny() { }
663 // ctor for a frame showing the given view of the specified document
664 wxDocChildFrameAny(wxDocument
*doc
,
668 const wxString
& title
,
669 const wxPoint
& pos
= wxDefaultPosition
,
670 const wxSize
& size
= wxDefaultSize
,
671 long style
= wxDEFAULT_FRAME_STYLE
,
672 const wxString
& name
= wxFrameNameStr
)
674 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
677 bool Create(wxDocument
*doc
,
681 const wxString
& title
,
682 const wxPoint
& pos
= wxDefaultPosition
,
683 const wxSize
& size
= wxDefaultSize
,
684 long style
= wxDEFAULT_FRAME_STYLE
,
685 const wxString
& name
= wxFrameNameStr
)
687 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
690 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
693 this->Connect(wxEVT_ACTIVATE
,
694 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
695 this->Connect(wxEVT_CLOSE_WINDOW
,
696 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
701 virtual bool Destroy()
703 // FIXME: why exactly do we do this? to avoid activation events during
704 // destructions maybe?
706 return BaseClass::Destroy();
710 // hook the child view into event handlers chain here
711 virtual bool TryBefore(wxEvent
& event
)
713 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
717 void OnActivate(wxActivateEvent
& event
)
719 BaseClass::OnActivate(event
);
722 m_childView
->Activate(event
.GetActive());
725 void OnCloseWindow(wxCloseEvent
& event
)
727 if ( CloseView(event
) )
732 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
733 ChildFrame
, ParentFrame
);
736 // ----------------------------------------------------------------------------
737 // A default child frame: we need to define it as a class just for wxRTTI,
738 // otherwise we could simply typedef it
739 // ----------------------------------------------------------------------------
742 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
743 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
744 // template will be DLL-exported but only once it is used as base class
746 #pragma warning (push)
747 #pragma warning (disable:4275)
750 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
752 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
759 wxDocChildFrame(wxDocument
*doc
,
763 const wxString
& title
,
764 const wxPoint
& pos
= wxDefaultPosition
,
765 const wxSize
& size
= wxDefaultSize
,
766 long style
= wxDEFAULT_FRAME_STYLE
,
767 const wxString
& name
= wxFrameNameStr
)
768 : wxDocChildFrameBase(doc
, view
,
769 parent
, id
, title
, pos
, size
, style
, name
)
773 bool Create(wxDocument
*doc
,
777 const wxString
& title
,
778 const wxPoint
& pos
= wxDefaultPosition
,
779 const wxSize
& size
= wxDefaultSize
,
780 long style
= wxDEFAULT_FRAME_STYLE
,
781 const wxString
& name
= wxFrameNameStr
)
783 return wxDocChildFrameBase::Create
786 parent
, id
, title
, pos
, size
, style
, name
791 DECLARE_CLASS(wxDocChildFrame
)
792 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
795 // ----------------------------------------------------------------------------
796 // wxDocParentFrame and related classes.
798 // As with wxDocChildFrame we define a template base class used by both normal
800 // ----------------------------------------------------------------------------
802 // Base class containing type-independent code of wxDocParentFrameAny
804 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
805 // derive from wxWindow.
806 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
809 wxDocParentFrameAnyBase() { m_docManager
= NULL
; }
811 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
814 wxDocManager
*m_docManager
;
816 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
819 // This is similar to wxDocChildFrameAny and is used to provide common
820 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
821 template <class BaseFrame
>
822 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
823 public wxDocParentFrameAnyBase
826 wxDocParentFrameAny() { }
827 wxDocParentFrameAny(wxDocManager
*manager
,
830 const wxString
& title
,
831 const wxPoint
& pos
= wxDefaultPosition
,
832 const wxSize
& size
= wxDefaultSize
,
833 long style
= wxDEFAULT_FRAME_STYLE
,
834 const wxString
& name
= wxFrameNameStr
)
836 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
839 bool Create(wxDocManager
*manager
,
842 const wxString
& title
,
843 const wxPoint
& pos
= wxDefaultPosition
,
844 const wxSize
& size
= wxDefaultSize
,
845 long style
= wxDEFAULT_FRAME_STYLE
,
846 const wxString
& name
= wxFrameNameStr
)
848 m_docManager
= manager
;
850 if ( !BaseFrame::Create(frame
, id
, title
, pos
, size
, style
, name
) )
853 this->Connect(wxID_EXIT
, wxEVT_COMMAND_MENU_SELECTED
,
854 wxCommandEventHandler(wxDocParentFrameAny::OnExit
));
855 this->Connect(wxEVT_CLOSE_WINDOW
,
856 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow
));
862 // hook the document manager into event handling chain here
863 virtual bool TryBefore(wxEvent
& event
)
865 if ( m_docManager
&& m_docManager
->ProcessEventLocally(event
) )
868 return BaseFrame::TryBefore(event
);
872 void OnExit(wxCommandEvent
& WXUNUSED(event
))
877 void OnCloseWindow(wxCloseEvent
& event
)
879 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
881 // The user decided not to close finally, abort.
886 // Just skip the event, base class handler will destroy the window.
892 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
895 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
897 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
900 wxDocParentFrame() : wxDocParentFrameBase() { }
902 wxDocParentFrame(wxDocManager
*manager
,
905 const wxString
& title
,
906 const wxPoint
& pos
= wxDefaultPosition
,
907 const wxSize
& size
= wxDefaultSize
,
908 long style
= wxDEFAULT_FRAME_STYLE
,
909 const wxString
& name
= wxFrameNameStr
)
910 : wxDocParentFrameBase(manager
,
911 parent
, id
, title
, pos
, size
, style
, name
)
915 bool Create(wxDocManager
*manager
,
918 const wxString
& title
,
919 const wxPoint
& pos
= wxDefaultPosition
,
920 const wxSize
& size
= wxDefaultSize
,
921 long style
= wxDEFAULT_FRAME_STYLE
,
922 const wxString
& name
= wxFrameNameStr
)
924 return wxDocParentFrameBase::Create(manager
,
926 pos
, size
, style
, name
);
930 DECLARE_CLASS(wxDocParentFrame
)
931 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
935 // reenable warning 4275
936 #pragma warning (pop)
939 // ----------------------------------------------------------------------------
940 // Provide simple default printing facilities
941 // ----------------------------------------------------------------------------
943 #if wxUSE_PRINTING_ARCHITECTURE
944 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
947 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
949 // implement wxPrintout methods
950 virtual bool OnPrintPage(int page
);
951 virtual bool HasPage(int page
);
952 virtual bool OnBeginDocument(int startPage
, int endPage
);
953 virtual void GetPageInfo(int *minPage
, int *maxPage
,
954 int *selPageFrom
, int *selPageTo
);
956 virtual wxView
*GetView() { return m_printoutView
; }
959 wxView
* m_printoutView
;
962 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
963 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
965 #endif // wxUSE_PRINTING_ARCHITECTURE
967 // For compatibility with existing file formats:
968 // converts from/to a stream to/from a temporary file.
969 #if wxUSE_STD_IOSTREAM
970 bool WXDLLIMPEXP_CORE
971 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
972 bool WXDLLIMPEXP_CORE
973 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
975 bool WXDLLIMPEXP_CORE
976 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
977 bool WXDLLIMPEXP_CORE
978 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
979 #endif // wxUSE_STD_IOSTREAM
982 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
983 // case of existing user code using them for its own purposes
984 #ifdef WXWIN_COMPATIBILITY_2_8
989 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
991 #endif // WXWIN_COMPATIBILITY_2_8
993 #endif // wxUSE_DOC_VIEW_ARCHITECTURE