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
20 #include "wx/string.h"
22 #include "wx/filehistory.h"
24 #if wxUSE_PRINTING_ARCHITECTURE
28 class WXDLLIMPEXP_FWD_CORE wxWindow
;
29 class WXDLLIMPEXP_FWD_CORE wxDocument
;
30 class WXDLLIMPEXP_FWD_CORE wxView
;
31 class WXDLLIMPEXP_FWD_CORE wxDocTemplate
;
32 class WXDLLIMPEXP_FWD_CORE wxDocManager
;
33 class WXDLLIMPEXP_FWD_CORE wxPrintInfo
;
34 class WXDLLIMPEXP_FWD_CORE wxCommandProcessor
;
35 class WXDLLIMPEXP_FWD_BASE wxConfigBase
;
37 class wxDocChildFrameAnyBase
;
39 #if wxUSE_STD_IOSTREAM
40 #include "wx/iosfwrap.h"
42 #include "wx/stream.h"
45 // Flags for wxDocManager (can be combined).
52 // Document template flags
55 wxTEMPLATE_VISIBLE
= 1,
56 wxTEMPLATE_INVISIBLE
= 2,
57 wxDEFAULT_TEMPLATE_FLAGS
= wxTEMPLATE_VISIBLE
60 #define wxMAX_FILE_HISTORY 9
62 class WXDLLIMPEXP_CORE wxDocument
: public wxEvtHandler
65 wxDocument(wxDocument
*parent
= NULL
);
66 virtual ~wxDocument();
69 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
70 wxString
GetFilename() const { return m_documentFile
; }
72 void SetTitle(const wxString
& title
) { m_documentTitle
= title
; }
73 wxString
GetTitle() const { return m_documentTitle
; }
75 void SetDocumentName(const wxString
& name
) { m_documentTypeName
= name
; }
76 wxString
GetDocumentName() const { return m_documentTypeName
; }
78 // access the flag indicating whether this document had been already saved,
79 // SetDocumentSaved() is only used internally, don't call it
80 bool GetDocumentSaved() const { return m_savedYet
; }
81 void SetDocumentSaved(bool saved
= true) { m_savedYet
= saved
; }
83 // return true if the document hasn't been modified since the last time it
84 // was saved (implying that it returns false if it was never saved, even if
85 // the document is not modified)
86 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
90 virtual bool SaveAs();
91 virtual bool Revert();
93 #if wxUSE_STD_IOSTREAM
94 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
95 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
97 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
98 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
101 // Called by wxWidgets
102 virtual bool OnSaveDocument(const wxString
& filename
);
103 virtual bool OnOpenDocument(const wxString
& filename
);
104 virtual bool OnNewDocument();
105 virtual bool OnCloseDocument();
107 // Prompts for saving if about to close a modified document. Returns true
108 // if ok to close the document (may have saved in the meantime, or set
109 // modified to false)
110 virtual bool OnSaveModified();
112 // if you override, remember to call the default
113 // implementation (wxDocument::OnChangeFilename)
114 virtual void OnChangeFilename(bool notifyViews
);
116 // Called by framework if created automatically by the default document
117 // manager: gives document a chance to initialise and (usually) create a
119 virtual bool OnCreate(const wxString
& path
, long flags
);
121 // By default, creates a base wxCommandProcessor.
122 virtual wxCommandProcessor
*OnCreateCommandProcessor();
123 virtual wxCommandProcessor
*GetCommandProcessor() const
124 { return m_commandProcessor
; }
125 virtual void SetCommandProcessor(wxCommandProcessor
*proc
)
126 { m_commandProcessor
= proc
; }
128 // Called after a view is added or removed. The default implementation
129 // deletes the document if this is there are no more views.
130 virtual void OnChangedViewList();
132 // Called from OnCloseDocument(), does nothing by default but may be
133 // overridden. Return value is ignored.
134 virtual bool DeleteContents();
136 virtual bool Draw(wxDC
&);
137 virtual bool IsModified() const { return m_documentModified
; }
138 virtual void Modify(bool mod
);
140 virtual bool AddView(wxView
*view
);
141 virtual bool RemoveView(wxView
*view
);
142 wxList
& GetViews() { return m_documentViews
; }
143 const wxList
& GetViews() const { return m_documentViews
; }
144 wxView
*GetFirstView() const;
146 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
147 virtual void NotifyClosing();
149 // Remove all views (because we're closing the document)
150 virtual bool DeleteAllViews();
153 virtual wxDocManager
*GetDocumentManager() const;
154 virtual wxDocTemplate
*GetDocumentTemplate() const
155 { return m_documentTemplate
; }
156 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
157 { m_documentTemplate
= temp
; }
159 // Get the document name to be shown to the user: the title if there is
160 // any, otherwise the filename if the document was saved and, finally,
161 // "unnamed" otherwise
162 virtual wxString
GetUserReadableName() const;
164 #if WXWIN_COMPATIBILITY_2_8
165 // use GetUserReadableName() instead
166 wxDEPRECATED_BUT_USED_INTERNALLY(
167 virtual bool GetPrintableName(wxString
& buf
) const
169 #endif // WXWIN_COMPATIBILITY_2_8
171 // Returns a window that can be used as a parent for document-related
172 // dialogs. Override if necessary.
173 virtual wxWindow
*GetDocumentWindow() const;
176 wxList m_documentViews
;
177 wxString m_documentFile
;
178 wxString m_documentTitle
;
179 wxString m_documentTypeName
;
180 wxDocTemplate
* m_documentTemplate
;
181 bool m_documentModified
;
182 wxDocument
* m_documentParent
;
183 wxCommandProcessor
* m_commandProcessor
;
186 // Called by OnSaveDocument and OnOpenDocument to implement standard
187 // Save/Load behavior. Re-implement in derived class for custom
189 virtual bool DoSaveDocument(const wxString
& file
);
190 virtual bool DoOpenDocument(const wxString
& file
);
192 // the default implementation of GetUserReadableName()
193 wxString
DoGetUserReadableName() const;
196 DECLARE_ABSTRACT_CLASS(wxDocument
)
197 wxDECLARE_NO_COPY_CLASS(wxDocument
);
200 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
206 wxDocument
*GetDocument() const { return m_viewDocument
; }
207 virtual void SetDocument(wxDocument
*doc
);
209 wxString
GetViewName() const { return m_viewTypeName
; }
210 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
212 wxWindow
*GetFrame() const { return m_viewFrame
; }
213 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
215 virtual void OnActivateView(bool activate
,
217 wxView
*deactiveView
);
218 virtual void OnDraw(wxDC
*dc
) = 0;
219 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
220 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
221 virtual void OnClosingDocument() {}
222 virtual void OnChangeFilename();
224 // Called by framework if created automatically by the default document
225 // manager class: gives view a chance to initialise
226 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
229 // Checks if the view is the last one for the document; if so, asks user
230 // to confirm save data (if modified). If ok, deletes itself and returns
232 virtual bool Close(bool deleteWindow
= true);
234 // Override to do cleanup/veto close
235 virtual bool OnClose(bool deleteWindow
);
237 // A view's window can call this to notify the view it is (in)active.
238 // The function then notifies the document manager.
239 virtual void Activate(bool activate
);
241 wxDocManager
*GetDocumentManager() const
242 { return m_viewDocument
->GetDocumentManager(); }
244 #if wxUSE_PRINTING_ARCHITECTURE
245 virtual wxPrintout
*OnCreatePrintout();
248 // implementation only
249 // -------------------
251 // set the associated frame, it is used to reset its view when we're
253 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
256 // hook the document into event handlers chain here
257 virtual bool TryBefore(wxEvent
& event
);
259 wxDocument
* m_viewDocument
;
260 wxString m_viewTypeName
;
261 wxWindow
* m_viewFrame
;
263 wxDocChildFrameAnyBase
*m_docChildFrame
;
266 DECLARE_ABSTRACT_CLASS(wxView
)
267 wxDECLARE_NO_COPY_CLASS(wxView
);
270 // Represents user interface (and other) properties of documents and views
271 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
274 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
277 // Associate document and view types. They're for identifying what view is
278 // associated with what template/document type
279 wxDocTemplate(wxDocManager
*manager
,
280 const wxString
& descr
,
281 const wxString
& filter
,
284 const wxString
& docTypeName
,
285 const wxString
& viewTypeName
,
286 wxClassInfo
*docClassInfo
= NULL
,
287 wxClassInfo
*viewClassInfo
= NULL
,
288 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
290 virtual ~wxDocTemplate();
292 // By default, these two member functions dynamically creates document and
293 // view using dynamic instance construction. Override these if you need a
294 // different method of construction.
295 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
296 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
298 // Helper method for CreateDocument; also allows you to do your own document
300 virtual bool InitDocument(wxDocument
* doc
,
301 const wxString
& path
,
304 wxString
GetDefaultExtension() const { return m_defaultExt
; }
305 wxString
GetDescription() const { return m_description
; }
306 wxString
GetDirectory() const { return m_directory
; }
307 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
308 void SetDocumentManager(wxDocManager
*manager
)
309 { m_documentManager
= manager
; }
310 wxString
GetFileFilter() const { return m_fileFilter
; }
311 long GetFlags() const { return m_flags
; }
312 virtual wxString
GetViewName() const { return m_viewTypeName
; }
313 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
315 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
316 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
317 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
318 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
319 void SetFlags(long flags
) { m_flags
= flags
; }
321 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
323 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
324 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
326 virtual bool FileMatchesTemplate(const wxString
& path
);
330 wxString m_fileFilter
;
331 wxString m_directory
;
332 wxString m_description
;
333 wxString m_defaultExt
;
334 wxString m_docTypeName
;
335 wxString m_viewTypeName
;
336 wxDocManager
* m_documentManager
;
338 // For dynamic creation of appropriate instances.
339 wxClassInfo
* m_docClassInfo
;
340 wxClassInfo
* m_viewClassInfo
;
342 // Called by CreateDocument and CreateView to create the actual
343 // document/view object.
345 // By default uses the ClassInfo provided to the constructor. Override
346 // these functions to provide a different method of creation.
347 virtual wxDocument
*DoCreateDocument();
348 virtual wxView
*DoCreateView();
351 DECLARE_CLASS(wxDocTemplate
)
352 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
355 // One object of this class may be created in an application, to manage all
356 // the templates and documents.
357 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
360 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
361 wxDocManager(long flags
= 0, bool initialize
= true);
362 virtual ~wxDocManager();
364 virtual bool Initialize();
366 // Handlers for common user commands
367 void OnFileClose(wxCommandEvent
& event
);
368 void OnFileCloseAll(wxCommandEvent
& event
);
369 void OnFileNew(wxCommandEvent
& event
);
370 void OnFileOpen(wxCommandEvent
& event
);
371 void OnFileRevert(wxCommandEvent
& event
);
372 void OnFileSave(wxCommandEvent
& event
);
373 void OnFileSaveAs(wxCommandEvent
& event
);
374 void OnMRUFile(wxCommandEvent
& event
);
375 #if wxUSE_PRINTING_ARCHITECTURE
376 void OnPrint(wxCommandEvent
& event
);
377 void OnPreview(wxCommandEvent
& event
);
378 void OnPageSetup(wxCommandEvent
& event
);
379 #endif // wxUSE_PRINTING_ARCHITECTURE
380 void OnUndo(wxCommandEvent
& event
);
381 void OnRedo(wxCommandEvent
& event
);
383 // Handlers for UI update commands
384 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
385 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
386 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
387 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
388 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
389 void OnUpdateUndo(wxUpdateUIEvent
& event
);
390 void OnUpdateRedo(wxUpdateUIEvent
& event
);
392 // called when file format detection didn't work, can be overridden to do
393 // something in this case
394 virtual void OnOpenFileFailure() { }
396 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
398 // wrapper around CreateDocument() with a more clear name
399 wxDocument
*CreateNewDocument()
400 { return CreateDocument(wxString(), wxDOC_NEW
); }
402 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
403 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
404 virtual bool FlushDoc(wxDocument
*doc
);
405 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
406 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
407 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
408 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
409 int noTemplates
, bool sort
= false);
410 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
411 int noTemplates
, bool sort
= false);
412 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
414 void AssociateTemplate(wxDocTemplate
*temp
);
415 void DisassociateTemplate(wxDocTemplate
*temp
);
417 // Find template from document class info, may return NULL.
418 wxDocTemplate
* FindTemplate(const wxClassInfo
* documentClassInfo
);
420 wxDocument
*GetCurrentDocument() const;
422 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
423 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
425 // Add and remove a document from the manager's list
426 void AddDocument(wxDocument
*doc
);
427 void RemoveDocument(wxDocument
*doc
);
429 // closes all currently open documents
430 bool CloseDocuments(bool force
= true);
432 // closes the specified document
433 bool CloseDocument(wxDocument
* doc
, bool force
= false);
435 // Clear remaining documents and templates
436 bool Clear(bool force
= true);
438 // Views or windows should inform the document manager
439 // when a view is going in or out of focus
440 virtual void ActivateView(wxView
*view
, bool activate
= true);
441 virtual wxView
*GetCurrentView() const { return m_currentView
; }
443 wxList
& GetDocuments() { return m_docs
; }
444 wxList
& GetTemplates() { return m_templates
; }
446 // Return the default name for a new document (by default returns strings
447 // in the form "unnamed <counter>" but can be overridden)
448 virtual wxString
MakeNewDocumentName();
450 // Make a frame title (override this to do something different)
451 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
453 virtual wxFileHistory
*OnCreateFileHistory();
454 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
456 // File history management
457 virtual void AddFileToHistory(const wxString
& file
);
458 virtual void RemoveFileFromHistory(size_t i
);
459 virtual size_t GetHistoryFilesCount() const;
460 virtual wxString
GetHistoryFile(size_t i
) const;
461 virtual void FileHistoryUseMenu(wxMenu
*menu
);
462 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
464 virtual void FileHistoryLoad(const wxConfigBase
& config
);
465 virtual void FileHistorySave(wxConfigBase
& config
);
466 #endif // wxUSE_CONFIG
468 virtual void FileHistoryAddFilesToMenu();
469 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
471 wxString
GetLastDirectory() const;
472 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
474 // Get the current document manager
475 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
477 #if WXWIN_COMPATIBILITY_2_8
478 // deprecated, override GetDefaultName() instead
479 wxDEPRECATED_BUT_USED_INTERNALLY(
480 virtual bool MakeDefaultName(wxString
& buf
)
484 #if WXWIN_COMPATIBILITY_2_6
485 // deprecated, use GetHistoryFilesCount() instead
486 wxDEPRECATED( size_t GetNoHistoryFiles() const );
487 #endif // WXWIN_COMPATIBILITY_2_6
491 // Open the MRU file with the given index in our associated file history.
492 void DoOpenMRUFile(unsigned n
);
493 #if wxUSE_PRINTING_ARCHITECTURE
494 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
496 const wxString
& title
);
497 #endif // wxUSE_PRINTING_ARCHITECTURE
499 // hook the currently active view into event handlers chain here
500 virtual bool TryBefore(wxEvent
& event
);
502 // return the command processor for the current document, if any
503 wxCommandProcessor
*GetCurrentCommandProcessor() const;
505 // this method tries to find an active view harder than GetCurrentView():
506 // if the latter is NULL, it also checks if we don't have just a single
507 // view and returns it then
508 wxView
*GetActiveView() const;
510 // activate the first view of the given document if any
511 void ActivateDocument(wxDocument
*doc
);
514 int m_defaultDocumentNameCounter
;
518 wxView
* m_currentView
;
519 wxFileHistory
* m_fileHistory
;
520 wxString m_lastDirectory
;
521 static wxDocManager
* sm_docManager
;
523 #if wxUSE_PRINTING_ARCHITECTURE
524 wxPageSetupDialogData m_pageSetupDialogData
;
525 #endif // wxUSE_PRINTING_ARCHITECTURE
527 DECLARE_EVENT_TABLE()
528 DECLARE_DYNAMIC_CLASS(wxDocManager
)
529 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
532 #if WXWIN_COMPATIBILITY_2_6
533 inline size_t wxDocManager::GetNoHistoryFiles() const
535 return GetHistoryFilesCount();
537 #endif // WXWIN_COMPATIBILITY_2_6
539 // ----------------------------------------------------------------------------
540 // Base class for child frames -- this is what wxView renders itself into
542 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
543 // wxDocChildFrameAny does
544 // ----------------------------------------------------------------------------
546 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
549 // default ctor, use Create() after it
550 wxDocChildFrameAnyBase()
552 m_childDocument
= NULL
;
557 // full ctor equivalent to using the default one and Create(0
558 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
560 Create(doc
, view
, win
);
563 // method which must be called for an object created using the default ctor
565 // note that it returns bool just for consistency with Create() methods in
566 // other classes, we never return false from here
567 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
569 m_childDocument
= doc
;
574 view
->SetDocChildFrame(this);
579 // dtor doesn't need to be virtual, an object should never be destroyed via
580 // a pointer to this class
581 ~wxDocChildFrameAnyBase()
583 // prevent the view from deleting us if we're being deleted directly
584 // (and not via Close() + Destroy())
586 m_childView
->SetDocChildFrame(NULL
);
589 wxDocument
*GetDocument() const { return m_childDocument
; }
590 wxView
*GetView() const { return m_childView
; }
591 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
592 void SetView(wxView
*view
) { m_childView
= view
; }
594 wxWindow
*GetWindow() const { return m_win
; }
597 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
598 // which is called from TryBefore() of the derived classes to give our view
599 // a chance to process the message before the frame event handlers are used
600 bool TryProcessEvent(wxEvent
& event
)
602 return m_childView
&& m_childView
->ProcessEventLocally(event
);
605 // called from EVT_CLOSE handler in the frame: check if we can close and do
606 // cleanup if so; veto the event otherwise
607 bool CloseView(wxCloseEvent
& event
);
610 wxDocument
* m_childDocument
;
613 // the associated window: having it here is not terribly elegant but it
614 // allows us to avoid having any virtual functions in this class
618 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
621 // ----------------------------------------------------------------------------
622 // Template implementing child frame concept using the given wxFrame-like class
624 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
625 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
626 // derived class as long as it provided a ctor with the same signature as
627 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
629 // ----------------------------------------------------------------------------
631 template <class ChildFrame
, class ParentFrame
>
632 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
633 public wxDocChildFrameAnyBase
636 typedef ChildFrame BaseClass
;
638 // default ctor, use Create after it
639 wxDocChildFrameAny() { }
641 // ctor for a frame showing the given view of the specified document
642 wxDocChildFrameAny(wxDocument
*doc
,
646 const wxString
& title
,
647 const wxPoint
& pos
= wxDefaultPosition
,
648 const wxSize
& size
= wxDefaultSize
,
649 long style
= wxDEFAULT_FRAME_STYLE
,
650 const wxString
& name
= wxFrameNameStr
)
652 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
655 bool Create(wxDocument
*doc
,
659 const wxString
& title
,
660 const wxPoint
& pos
= wxDefaultPosition
,
661 const wxSize
& size
= wxDefaultSize
,
662 long style
= wxDEFAULT_FRAME_STYLE
,
663 const wxString
& name
= wxFrameNameStr
)
665 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
668 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
671 this->Connect(wxEVT_ACTIVATE
,
672 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
673 this->Connect(wxEVT_CLOSE_WINDOW
,
674 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
679 virtual bool Destroy()
681 // FIXME: why exactly do we do this? to avoid activation events during
682 // destructions maybe?
684 return BaseClass::Destroy();
688 // hook the child view into event handlers chain here
689 virtual bool TryBefore(wxEvent
& event
)
691 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
695 void OnActivate(wxActivateEvent
& event
)
697 BaseClass::OnActivate(event
);
700 m_childView
->Activate(event
.GetActive());
703 void OnCloseWindow(wxCloseEvent
& event
)
705 if ( CloseView(event
) )
710 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
711 ChildFrame
, ParentFrame
);
714 // ----------------------------------------------------------------------------
715 // A default child frame: we need to define it as a class just for wxRTTI,
716 // otherwise we could simply typedef it
717 // ----------------------------------------------------------------------------
720 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
721 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
722 // template will be DLL-exported but only once it is used as base class
724 #pragma warning (push)
725 #pragma warning (disable:4275)
728 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
730 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
737 wxDocChildFrame(wxDocument
*doc
,
741 const wxString
& title
,
742 const wxPoint
& pos
= wxDefaultPosition
,
743 const wxSize
& size
= wxDefaultSize
,
744 long style
= wxDEFAULT_FRAME_STYLE
,
745 const wxString
& name
= wxFrameNameStr
)
746 : wxDocChildFrameBase(doc
, view
,
747 parent
, id
, title
, pos
, size
, style
, name
)
751 bool Create(wxDocument
*doc
,
755 const wxString
& title
,
756 const wxPoint
& pos
= wxDefaultPosition
,
757 const wxSize
& size
= wxDefaultSize
,
758 long style
= wxDEFAULT_FRAME_STYLE
,
759 const wxString
& name
= wxFrameNameStr
)
761 return wxDocChildFrameBase::Create
764 parent
, id
, title
, pos
, size
, style
, name
769 DECLARE_CLASS(wxDocChildFrame
)
770 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
773 // ----------------------------------------------------------------------------
774 // wxDocParentFrame and related classes.
776 // As with wxDocChildFrame we define a template base class used by both normal
778 // ----------------------------------------------------------------------------
780 // Base class containing type-independent code of wxDocParentFrameAny
782 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
783 // derive from wxWindow.
784 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
787 wxDocParentFrameAnyBase() { m_docManager
= NULL
; }
789 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
792 wxDocManager
*m_docManager
;
794 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
797 // This is similar to wxDocChildFrameAny and is used to provide common
798 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
799 template <class BaseFrame
>
800 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
801 public wxDocParentFrameAnyBase
804 wxDocParentFrameAny() { }
805 wxDocParentFrameAny(wxDocManager
*manager
,
808 const wxString
& title
,
809 const wxPoint
& pos
= wxDefaultPosition
,
810 const wxSize
& size
= wxDefaultSize
,
811 long style
= wxDEFAULT_FRAME_STYLE
,
812 const wxString
& name
= wxFrameNameStr
)
814 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
817 bool Create(wxDocManager
*manager
,
820 const wxString
& title
,
821 const wxPoint
& pos
= wxDefaultPosition
,
822 const wxSize
& size
= wxDefaultSize
,
823 long style
= wxDEFAULT_FRAME_STYLE
,
824 const wxString
& name
= wxFrameNameStr
)
826 m_docManager
= manager
;
828 if ( !BaseFrame::Create(frame
, id
, title
, pos
, size
, style
, name
) )
831 this->Connect(wxID_EXIT
, wxEVT_COMMAND_MENU_SELECTED
,
832 wxCommandEventHandler(wxDocParentFrameAny::OnExit
));
833 this->Connect(wxEVT_CLOSE_WINDOW
,
834 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow
));
840 // hook the document manager into event handling chain here
841 virtual bool TryBefore(wxEvent
& event
)
843 if ( m_docManager
&& m_docManager
->ProcessEventLocally(event
) )
846 return BaseFrame::TryBefore(event
);
850 void OnExit(wxCommandEvent
& WXUNUSED(event
))
855 void OnCloseWindow(wxCloseEvent
& event
)
857 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
859 // The user decided not to close finally, abort.
864 // Just skip the event, base class handler will destroy the window.
870 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
873 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
875 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
878 wxDocParentFrame() : wxDocParentFrameBase() { }
880 wxDocParentFrame(wxDocManager
*manager
,
883 const wxString
& title
,
884 const wxPoint
& pos
= wxDefaultPosition
,
885 const wxSize
& size
= wxDefaultSize
,
886 long style
= wxDEFAULT_FRAME_STYLE
,
887 const wxString
& name
= wxFrameNameStr
)
888 : wxDocParentFrameBase(manager
,
889 parent
, id
, title
, pos
, size
, style
, name
)
893 bool Create(wxDocManager
*manager
,
896 const wxString
& title
,
897 const wxPoint
& pos
= wxDefaultPosition
,
898 const wxSize
& size
= wxDefaultSize
,
899 long style
= wxDEFAULT_FRAME_STYLE
,
900 const wxString
& name
= wxFrameNameStr
)
902 return wxDocParentFrameBase::Create(manager
,
904 pos
, size
, style
, name
);
908 DECLARE_CLASS(wxDocParentFrame
)
909 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
913 // reenable warning 4275
914 #pragma warning (pop)
917 // ----------------------------------------------------------------------------
918 // Provide simple default printing facilities
919 // ----------------------------------------------------------------------------
921 #if wxUSE_PRINTING_ARCHITECTURE
922 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
925 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
927 // implement wxPrintout methods
928 virtual bool OnPrintPage(int page
);
929 virtual bool HasPage(int page
);
930 virtual bool OnBeginDocument(int startPage
, int endPage
);
931 virtual void GetPageInfo(int *minPage
, int *maxPage
,
932 int *selPageFrom
, int *selPageTo
);
934 virtual wxView
*GetView() { return m_printoutView
; }
937 wxView
* m_printoutView
;
940 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
941 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
943 #endif // wxUSE_PRINTING_ARCHITECTURE
945 // For compatibility with existing file formats:
946 // converts from/to a stream to/from a temporary file.
947 #if wxUSE_STD_IOSTREAM
948 bool WXDLLIMPEXP_CORE
949 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
950 bool WXDLLIMPEXP_CORE
951 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
953 bool WXDLLIMPEXP_CORE
954 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
955 bool WXDLLIMPEXP_CORE
956 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
957 #endif // wxUSE_STD_IOSTREAM
960 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
961 // case of existing user code using them for its own purposes
962 #ifdef WXWIN_COMPATIBILITY_2_8
967 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
969 #endif // WXWIN_COMPATIBILITY_2_8
971 #endif // wxUSE_DOC_VIEW_ARCHITECTURE