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 // Called when a file selected from the MRU list doesn't exist any more.
514 // The default behaviour is to remove the file from the MRU and notify the
515 // user about it but this method can be overridden to customize it.
516 virtual void OnMRUFileNotExist(unsigned n
, const wxString
& filename
);
518 // Open the MRU file with the given index in our associated file history.
519 void DoOpenMRUFile(unsigned n
);
520 #if wxUSE_PRINTING_ARCHITECTURE
521 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
523 const wxString
& title
);
524 #endif // wxUSE_PRINTING_ARCHITECTURE
526 // hook the currently active view into event handlers chain here
527 virtual bool TryBefore(wxEvent
& event
);
529 // return the command processor for the current document, if any
530 wxCommandProcessor
*GetCurrentCommandProcessor() const;
532 // this method tries to find an active view harder than GetCurrentView():
533 // if the latter is NULL, it also checks if we don't have just a single
534 // view and returns it then
535 wxView
*GetActiveView() const;
537 // activate the first view of the given document if any
538 void ActivateDocument(wxDocument
*doc
);
541 int m_defaultDocumentNameCounter
;
545 wxView
* m_currentView
;
546 wxFileHistory
* m_fileHistory
;
547 wxString m_lastDirectory
;
548 static wxDocManager
* sm_docManager
;
550 #if wxUSE_PRINTING_ARCHITECTURE
551 wxPageSetupDialogData m_pageSetupDialogData
;
552 #endif // wxUSE_PRINTING_ARCHITECTURE
554 DECLARE_EVENT_TABLE()
555 DECLARE_DYNAMIC_CLASS(wxDocManager
)
556 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
559 #if WXWIN_COMPATIBILITY_2_6
560 inline size_t wxDocManager::GetNoHistoryFiles() const
562 return GetHistoryFilesCount();
564 #endif // WXWIN_COMPATIBILITY_2_6
566 // ----------------------------------------------------------------------------
567 // Base class for child frames -- this is what wxView renders itself into
569 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
570 // wxDocChildFrameAny does
571 // ----------------------------------------------------------------------------
573 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
576 // default ctor, use Create() after it
577 wxDocChildFrameAnyBase()
579 m_childDocument
= NULL
;
584 // full ctor equivalent to using the default one and Create(0
585 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
587 Create(doc
, view
, win
);
590 // method which must be called for an object created using the default ctor
592 // note that it returns bool just for consistency with Create() methods in
593 // other classes, we never return false from here
594 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
596 m_childDocument
= doc
;
601 view
->SetDocChildFrame(this);
606 // dtor doesn't need to be virtual, an object should never be destroyed via
607 // a pointer to this class
608 ~wxDocChildFrameAnyBase()
610 // prevent the view from deleting us if we're being deleted directly
611 // (and not via Close() + Destroy())
613 m_childView
->SetDocChildFrame(NULL
);
616 wxDocument
*GetDocument() const { return m_childDocument
; }
617 wxView
*GetView() const { return m_childView
; }
618 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
619 void SetView(wxView
*view
) { m_childView
= view
; }
621 wxWindow
*GetWindow() const { return m_win
; }
624 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
625 // which is called from TryBefore() of the derived classes to give our view
626 // a chance to process the message before the frame event handlers are used
627 bool TryProcessEvent(wxEvent
& event
)
629 return m_childView
&& m_childView
->ProcessEventLocally(event
);
632 // called from EVT_CLOSE handler in the frame: check if we can close and do
633 // cleanup if so; veto the event otherwise
634 bool CloseView(wxCloseEvent
& event
);
637 wxDocument
* m_childDocument
;
640 // the associated window: having it here is not terribly elegant but it
641 // allows us to avoid having any virtual functions in this class
645 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
648 // ----------------------------------------------------------------------------
649 // Template implementing child frame concept using the given wxFrame-like class
651 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
652 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
653 // derived class as long as it provided a ctor with the same signature as
654 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
656 // ----------------------------------------------------------------------------
658 template <class ChildFrame
, class ParentFrame
>
659 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
660 public wxDocChildFrameAnyBase
663 typedef ChildFrame BaseClass
;
665 // default ctor, use Create after it
666 wxDocChildFrameAny() { }
668 // ctor for a frame showing the given view of the specified document
669 wxDocChildFrameAny(wxDocument
*doc
,
673 const wxString
& title
,
674 const wxPoint
& pos
= wxDefaultPosition
,
675 const wxSize
& size
= wxDefaultSize
,
676 long style
= wxDEFAULT_FRAME_STYLE
,
677 const wxString
& name
= wxFrameNameStr
)
679 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
682 bool Create(wxDocument
*doc
,
686 const wxString
& title
,
687 const wxPoint
& pos
= wxDefaultPosition
,
688 const wxSize
& size
= wxDefaultSize
,
689 long style
= wxDEFAULT_FRAME_STYLE
,
690 const wxString
& name
= wxFrameNameStr
)
692 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
695 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
698 this->Connect(wxEVT_ACTIVATE
,
699 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
700 this->Connect(wxEVT_CLOSE_WINDOW
,
701 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
706 virtual bool Destroy()
708 // FIXME: why exactly do we do this? to avoid activation events during
709 // destructions maybe?
711 return BaseClass::Destroy();
715 // hook the child view into event handlers chain here
716 virtual bool TryBefore(wxEvent
& event
)
718 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
722 void OnActivate(wxActivateEvent
& event
)
724 BaseClass::OnActivate(event
);
727 m_childView
->Activate(event
.GetActive());
730 void OnCloseWindow(wxCloseEvent
& event
)
732 if ( CloseView(event
) )
737 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
738 ChildFrame
, ParentFrame
);
741 // ----------------------------------------------------------------------------
742 // A default child frame: we need to define it as a class just for wxRTTI,
743 // otherwise we could simply typedef it
744 // ----------------------------------------------------------------------------
747 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
748 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
749 // template will be DLL-exported but only once it is used as base class
751 #pragma warning (push)
752 #pragma warning (disable:4275)
755 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
757 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
764 wxDocChildFrame(wxDocument
*doc
,
768 const wxString
& title
,
769 const wxPoint
& pos
= wxDefaultPosition
,
770 const wxSize
& size
= wxDefaultSize
,
771 long style
= wxDEFAULT_FRAME_STYLE
,
772 const wxString
& name
= wxFrameNameStr
)
773 : wxDocChildFrameBase(doc
, view
,
774 parent
, id
, title
, pos
, size
, style
, name
)
778 bool Create(wxDocument
*doc
,
782 const wxString
& title
,
783 const wxPoint
& pos
= wxDefaultPosition
,
784 const wxSize
& size
= wxDefaultSize
,
785 long style
= wxDEFAULT_FRAME_STYLE
,
786 const wxString
& name
= wxFrameNameStr
)
788 return wxDocChildFrameBase::Create
791 parent
, id
, title
, pos
, size
, style
, name
796 DECLARE_CLASS(wxDocChildFrame
)
797 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
800 // ----------------------------------------------------------------------------
801 // wxDocParentFrame and related classes.
803 // As with wxDocChildFrame we define a template base class used by both normal
805 // ----------------------------------------------------------------------------
807 // Base class containing type-independent code of wxDocParentFrameAny
809 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
810 // derive from wxWindow.
811 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
814 wxDocParentFrameAnyBase() { m_docManager
= NULL
; }
816 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
819 wxDocManager
*m_docManager
;
821 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
824 // This is similar to wxDocChildFrameAny and is used to provide common
825 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
826 template <class BaseFrame
>
827 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
828 public wxDocParentFrameAnyBase
831 wxDocParentFrameAny() { }
832 wxDocParentFrameAny(wxDocManager
*manager
,
835 const wxString
& title
,
836 const wxPoint
& pos
= wxDefaultPosition
,
837 const wxSize
& size
= wxDefaultSize
,
838 long style
= wxDEFAULT_FRAME_STYLE
,
839 const wxString
& name
= wxFrameNameStr
)
841 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
844 bool Create(wxDocManager
*manager
,
847 const wxString
& title
,
848 const wxPoint
& pos
= wxDefaultPosition
,
849 const wxSize
& size
= wxDefaultSize
,
850 long style
= wxDEFAULT_FRAME_STYLE
,
851 const wxString
& name
= wxFrameNameStr
)
853 m_docManager
= manager
;
855 if ( !BaseFrame::Create(frame
, id
, title
, pos
, size
, style
, name
) )
858 this->Connect(wxID_EXIT
, wxEVT_COMMAND_MENU_SELECTED
,
859 wxCommandEventHandler(wxDocParentFrameAny::OnExit
));
860 this->Connect(wxEVT_CLOSE_WINDOW
,
861 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow
));
867 // hook the document manager into event handling chain here
868 virtual bool TryBefore(wxEvent
& event
)
870 if ( m_docManager
&& m_docManager
->ProcessEventLocally(event
) )
873 return BaseFrame::TryBefore(event
);
877 void OnExit(wxCommandEvent
& WXUNUSED(event
))
882 void OnCloseWindow(wxCloseEvent
& event
)
884 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
886 // The user decided not to close finally, abort.
891 // Just skip the event, base class handler will destroy the window.
897 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
900 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
902 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
905 wxDocParentFrame() : wxDocParentFrameBase() { }
907 wxDocParentFrame(wxDocManager
*manager
,
910 const wxString
& title
,
911 const wxPoint
& pos
= wxDefaultPosition
,
912 const wxSize
& size
= wxDefaultSize
,
913 long style
= wxDEFAULT_FRAME_STYLE
,
914 const wxString
& name
= wxFrameNameStr
)
915 : wxDocParentFrameBase(manager
,
916 parent
, id
, title
, pos
, size
, style
, name
)
920 bool Create(wxDocManager
*manager
,
923 const wxString
& title
,
924 const wxPoint
& pos
= wxDefaultPosition
,
925 const wxSize
& size
= wxDefaultSize
,
926 long style
= wxDEFAULT_FRAME_STYLE
,
927 const wxString
& name
= wxFrameNameStr
)
929 return wxDocParentFrameBase::Create(manager
,
931 pos
, size
, style
, name
);
935 DECLARE_CLASS(wxDocParentFrame
)
936 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
940 // reenable warning 4275
941 #pragma warning (pop)
944 // ----------------------------------------------------------------------------
945 // Provide simple default printing facilities
946 // ----------------------------------------------------------------------------
948 #if wxUSE_PRINTING_ARCHITECTURE
949 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
952 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
954 // implement wxPrintout methods
955 virtual bool OnPrintPage(int page
);
956 virtual bool HasPage(int page
);
957 virtual bool OnBeginDocument(int startPage
, int endPage
);
958 virtual void GetPageInfo(int *minPage
, int *maxPage
,
959 int *selPageFrom
, int *selPageTo
);
961 virtual wxView
*GetView() { return m_printoutView
; }
964 wxView
* m_printoutView
;
967 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
968 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
970 #endif // wxUSE_PRINTING_ARCHITECTURE
972 // For compatibility with existing file formats:
973 // converts from/to a stream to/from a temporary file.
974 #if wxUSE_STD_IOSTREAM
975 bool WXDLLIMPEXP_CORE
976 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
977 bool WXDLLIMPEXP_CORE
978 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
980 bool WXDLLIMPEXP_CORE
981 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
982 bool WXDLLIMPEXP_CORE
983 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
984 #endif // wxUSE_STD_IOSTREAM
987 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
988 // case of existing user code using them for its own purposes
989 #ifdef WXWIN_COMPATIBILITY_2_8
994 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
996 #endif // WXWIN_COMPATIBILITY_2_8
998 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
1000 #endif // _WX_DOCH__