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 virtual bool DeleteContents();
134 virtual bool Draw(wxDC
&);
135 virtual bool IsModified() const { return m_documentModified
; }
136 virtual void Modify(bool mod
);
138 virtual bool AddView(wxView
*view
);
139 virtual bool RemoveView(wxView
*view
);
140 wxList
& GetViews() { return m_documentViews
; }
141 const wxList
& GetViews() const { return m_documentViews
; }
142 wxView
*GetFirstView() const;
144 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
145 virtual void NotifyClosing();
147 // Remove all views (because we're closing the document)
148 virtual bool DeleteAllViews();
151 virtual wxDocManager
*GetDocumentManager() const;
152 virtual wxDocTemplate
*GetDocumentTemplate() const
153 { return m_documentTemplate
; }
154 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
155 { m_documentTemplate
= temp
; }
157 // Get the document name to be shown to the user: the title if there is
158 // any, otherwise the filename if the document was saved and, finally,
159 // "unnamed" otherwise
160 virtual wxString
GetUserReadableName() const;
162 #if WXWIN_COMPATIBILITY_2_8
163 // use GetUserReadableName() instead
164 wxDEPRECATED_BUT_USED_INTERNALLY(
165 virtual bool GetPrintableName(wxString
& buf
) const
167 #endif // WXWIN_COMPATIBILITY_2_8
169 // Returns a window that can be used as a parent for document-related
170 // dialogs. Override if necessary.
171 virtual wxWindow
*GetDocumentWindow() const;
174 wxList m_documentViews
;
175 wxString m_documentFile
;
176 wxString m_documentTitle
;
177 wxString m_documentTypeName
;
178 wxDocTemplate
* m_documentTemplate
;
179 bool m_documentModified
;
180 wxDocument
* m_documentParent
;
181 wxCommandProcessor
* m_commandProcessor
;
184 // Called by OnSaveDocument and OnOpenDocument to implement standard
185 // Save/Load behavior. Re-implement in derived class for custom
187 virtual bool DoSaveDocument(const wxString
& file
);
188 virtual bool DoOpenDocument(const wxString
& file
);
190 // the default implementation of GetUserReadableName()
191 wxString
DoGetUserReadableName() const;
194 DECLARE_ABSTRACT_CLASS(wxDocument
)
195 wxDECLARE_NO_COPY_CLASS(wxDocument
);
198 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
204 wxDocument
*GetDocument() const { return m_viewDocument
; }
205 virtual void SetDocument(wxDocument
*doc
);
207 wxString
GetViewName() const { return m_viewTypeName
; }
208 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
210 wxWindow
*GetFrame() const { return m_viewFrame
; }
211 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
213 virtual void OnActivateView(bool activate
,
215 wxView
*deactiveView
);
216 virtual void OnDraw(wxDC
*dc
) = 0;
217 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
218 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
219 virtual void OnClosingDocument() {}
220 virtual void OnChangeFilename();
222 // Called by framework if created automatically by the default document
223 // manager class: gives view a chance to initialise
224 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
227 // Checks if the view is the last one for the document; if so, asks user
228 // to confirm save data (if modified). If ok, deletes itself and returns
230 virtual bool Close(bool deleteWindow
= true);
232 // Override to do cleanup/veto close
233 virtual bool OnClose(bool deleteWindow
);
235 // A view's window can call this to notify the view it is (in)active.
236 // The function then notifies the document manager.
237 virtual void Activate(bool activate
);
239 wxDocManager
*GetDocumentManager() const
240 { return m_viewDocument
->GetDocumentManager(); }
242 #if wxUSE_PRINTING_ARCHITECTURE
243 virtual wxPrintout
*OnCreatePrintout();
246 // implementation only
247 // -------------------
249 // set the associated frame, it is used to reset its view when we're
251 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
254 // hook the document into event handlers chain here
255 virtual bool TryBefore(wxEvent
& event
);
257 wxDocument
* m_viewDocument
;
258 wxString m_viewTypeName
;
259 wxWindow
* m_viewFrame
;
261 wxDocChildFrameAnyBase
*m_docChildFrame
;
264 DECLARE_ABSTRACT_CLASS(wxView
)
265 wxDECLARE_NO_COPY_CLASS(wxView
);
268 // Represents user interface (and other) properties of documents and views
269 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
272 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
275 // Associate document and view types. They're for identifying what view is
276 // associated with what template/document type
277 wxDocTemplate(wxDocManager
*manager
,
278 const wxString
& descr
,
279 const wxString
& filter
,
282 const wxString
& docTypeName
,
283 const wxString
& viewTypeName
,
284 wxClassInfo
*docClassInfo
= NULL
,
285 wxClassInfo
*viewClassInfo
= NULL
,
286 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
288 virtual ~wxDocTemplate();
290 // By default, these two member functions dynamically creates document and
291 // view using dynamic instance construction. Override these if you need a
292 // different method of construction.
293 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
294 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
296 // Helper method for CreateDocument; also allows you to do your own document
298 virtual bool InitDocument(wxDocument
* doc
,
299 const wxString
& path
,
302 wxString
GetDefaultExtension() const { return m_defaultExt
; }
303 wxString
GetDescription() const { return m_description
; }
304 wxString
GetDirectory() const { return m_directory
; }
305 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
306 void SetDocumentManager(wxDocManager
*manager
)
307 { m_documentManager
= manager
; }
308 wxString
GetFileFilter() const { return m_fileFilter
; }
309 long GetFlags() const { return m_flags
; }
310 virtual wxString
GetViewName() const { return m_viewTypeName
; }
311 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
313 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
314 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
315 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
316 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
317 void SetFlags(long flags
) { m_flags
= flags
; }
319 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
321 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
322 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
324 virtual bool FileMatchesTemplate(const wxString
& path
);
328 wxString m_fileFilter
;
329 wxString m_directory
;
330 wxString m_description
;
331 wxString m_defaultExt
;
332 wxString m_docTypeName
;
333 wxString m_viewTypeName
;
334 wxDocManager
* m_documentManager
;
336 // For dynamic creation of appropriate instances.
337 wxClassInfo
* m_docClassInfo
;
338 wxClassInfo
* m_viewClassInfo
;
340 // Called by CreateDocument and CreateView to create the actual
341 // document/view object.
343 // By default uses the ClassInfo provided to the constructor. Override
344 // these functions to provide a different method of creation.
345 virtual wxDocument
*DoCreateDocument();
346 virtual wxView
*DoCreateView();
349 DECLARE_CLASS(wxDocTemplate
)
350 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
353 // One object of this class may be created in an application, to manage all
354 // the templates and documents.
355 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
358 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
359 wxDocManager(long flags
= 0, bool initialize
= true);
360 virtual ~wxDocManager();
362 virtual bool Initialize();
364 // Handlers for common user commands
365 void OnFileClose(wxCommandEvent
& event
);
366 void OnFileCloseAll(wxCommandEvent
& event
);
367 void OnFileNew(wxCommandEvent
& event
);
368 void OnFileOpen(wxCommandEvent
& event
);
369 void OnFileRevert(wxCommandEvent
& event
);
370 void OnFileSave(wxCommandEvent
& event
);
371 void OnFileSaveAs(wxCommandEvent
& event
);
372 void OnPrint(wxCommandEvent
& event
);
373 void OnPreview(wxCommandEvent
& event
);
374 void OnUndo(wxCommandEvent
& event
);
375 void OnRedo(wxCommandEvent
& event
);
377 // Handlers for UI update commands
378 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
379 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
380 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
381 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
382 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
383 void OnUpdateUndo(wxUpdateUIEvent
& event
);
384 void OnUpdateRedo(wxUpdateUIEvent
& event
);
386 // called when file format detection didn't work, can be overridden to do
387 // something in this case
388 virtual void OnOpenFileFailure() { }
390 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
392 // wrapper around CreateDocument() with a more clear name
393 wxDocument
*CreateNewDocument()
394 { return CreateDocument(wxString(), wxDOC_NEW
); }
396 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
397 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
398 virtual bool FlushDoc(wxDocument
*doc
);
399 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
400 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
401 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
402 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
403 int noTemplates
, bool sort
= false);
404 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
405 int noTemplates
, bool sort
= false);
406 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
408 void AssociateTemplate(wxDocTemplate
*temp
);
409 void DisassociateTemplate(wxDocTemplate
*temp
);
411 wxDocument
*GetCurrentDocument() const;
413 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
414 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
416 // Add and remove a document from the manager's list
417 void AddDocument(wxDocument
*doc
);
418 void RemoveDocument(wxDocument
*doc
);
420 // closes all currently open documents
421 bool CloseDocuments(bool force
= true);
423 // closes the specified document
424 bool CloseDocument(wxDocument
* doc
, bool force
= false);
426 // Clear remaining documents and templates
427 bool Clear(bool force
= true);
429 // Views or windows should inform the document manager
430 // when a view is going in or out of focus
431 virtual void ActivateView(wxView
*view
, bool activate
= true);
432 virtual wxView
*GetCurrentView() const { return m_currentView
; }
434 wxList
& GetDocuments() { return m_docs
; }
435 wxList
& GetTemplates() { return m_templates
; }
437 // Return the default name for a new document (by default returns strings
438 // in the form "unnamed <counter>" but can be overridden)
439 virtual wxString
MakeNewDocumentName();
441 // Make a frame title (override this to do something different)
442 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
444 virtual wxFileHistory
*OnCreateFileHistory();
445 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
447 // File history management
448 virtual void AddFileToHistory(const wxString
& file
);
449 virtual void RemoveFileFromHistory(size_t i
);
450 virtual size_t GetHistoryFilesCount() const;
451 virtual wxString
GetHistoryFile(size_t i
) const;
452 virtual void FileHistoryUseMenu(wxMenu
*menu
);
453 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
455 virtual void FileHistoryLoad(const wxConfigBase
& config
);
456 virtual void FileHistorySave(wxConfigBase
& config
);
457 #endif // wxUSE_CONFIG
459 virtual void FileHistoryAddFilesToMenu();
460 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
462 wxString
GetLastDirectory() const;
463 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
465 // Get the current document manager
466 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
468 #if WXWIN_COMPATIBILITY_2_8
469 // deprecated, override GetDefaultName() instead
470 wxDEPRECATED_BUT_USED_INTERNALLY(
471 virtual bool MakeDefaultName(wxString
& buf
)
475 #if WXWIN_COMPATIBILITY_2_6
476 // deprecated, use GetHistoryFilesCount() instead
477 wxDEPRECATED( size_t GetNoHistoryFiles() const );
478 #endif // WXWIN_COMPATIBILITY_2_6
481 #if wxUSE_PRINTING_ARCHITECTURE
482 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
484 const wxString
& title
);
485 #endif // wxUSE_PRINTING_ARCHITECTURE
487 // hook the currently active view into event handlers chain here
488 virtual bool TryBefore(wxEvent
& event
);
490 // return the command processor for the current document, if any
491 wxCommandProcessor
*GetCurrentCommandProcessor() const;
493 // this method tries to find an active view harder than GetCurrentView():
494 // if the latter is NULL, it also checks if we don't have just a single
495 // view and returns it then
496 wxView
*GetActiveView() const;
499 int m_defaultDocumentNameCounter
;
503 wxView
* m_currentView
;
504 wxFileHistory
* m_fileHistory
;
505 wxString m_lastDirectory
;
506 static wxDocManager
* sm_docManager
;
508 DECLARE_EVENT_TABLE()
509 DECLARE_DYNAMIC_CLASS(wxDocManager
)
510 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
513 #if WXWIN_COMPATIBILITY_2_6
514 inline size_t wxDocManager::GetNoHistoryFiles() const
516 return GetHistoryFilesCount();
518 #endif // WXWIN_COMPATIBILITY_2_6
520 // ----------------------------------------------------------------------------
521 // Base class for child frames -- this is what wxView renders itself into
523 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
524 // wxDocChildFrameAny does
525 // ----------------------------------------------------------------------------
527 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
530 // default ctor, use Create() after it
531 wxDocChildFrameAnyBase()
533 m_childDocument
= NULL
;
538 // full ctor equivalent to using the default one and Create(0
539 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
541 Create(doc
, view
, win
);
544 // method which must be called for an object created using the default ctor
546 // note that it returns bool just for consistency with Create() methods in
547 // other classes, we never return false from here
548 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
550 m_childDocument
= doc
;
555 view
->SetDocChildFrame(this);
560 // dtor doesn't need to be virtual, an object should never be destroyed via
561 // a pointer to this class
562 ~wxDocChildFrameAnyBase()
564 // prevent the view from deleting us if we're being deleted directly
565 // (and not via Close() + Destroy())
567 m_childView
->SetDocChildFrame(NULL
);
570 wxDocument
*GetDocument() const { return m_childDocument
; }
571 wxView
*GetView() const { return m_childView
; }
572 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
573 void SetView(wxView
*view
) { m_childView
= view
; }
575 wxWindow
*GetWindow() const { return m_win
; }
578 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
579 // which is called from TryBefore() of the derived classes to give our view
580 // a chance to process the message before the frame event handlers are used
581 bool TryProcessEvent(wxEvent
& event
)
583 return m_childView
&& m_childView
->ProcessEventHere(event
);
586 // called from EVT_CLOSE handler in the frame: check if we can close and do
587 // cleanup if so; veto the event otherwise
588 bool CloseView(wxCloseEvent
& event
);
591 wxDocument
* m_childDocument
;
594 // the associated window: having it here is not terribly elegant but it
595 // allows us to avoid having any virtual functions in this class
599 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
602 // ----------------------------------------------------------------------------
603 // Template implementing child frame concept using the given wxFrame-like class
605 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
606 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
607 // derived class as long as it provided a ctor with the same signature as
608 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
610 // ----------------------------------------------------------------------------
612 template <class ChildFrame
, class ParentFrame
>
613 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
614 public wxDocChildFrameAnyBase
617 typedef ChildFrame BaseClass
;
619 // default ctor, use Create after it
620 wxDocChildFrameAny() { }
622 // ctor for a frame showing the given view of the specified document
623 wxDocChildFrameAny(wxDocument
*doc
,
627 const wxString
& title
,
628 const wxPoint
& pos
= wxDefaultPosition
,
629 const wxSize
& size
= wxDefaultSize
,
630 long style
= wxDEFAULT_FRAME_STYLE
,
631 const wxString
& name
= wxFrameNameStr
)
633 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
636 bool Create(wxDocument
*doc
,
640 const wxString
& title
,
641 const wxPoint
& pos
= wxDefaultPosition
,
642 const wxSize
& size
= wxDefaultSize
,
643 long style
= wxDEFAULT_FRAME_STYLE
,
644 const wxString
& name
= wxFrameNameStr
)
646 if ( !wxDocChildFrameAnyBase::Create(doc
, view
, this) )
649 if ( !BaseClass::Create(parent
, id
, title
, pos
, size
, style
, name
) )
652 this->Connect(wxEVT_ACTIVATE
,
653 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
654 this->Connect(wxEVT_CLOSE_WINDOW
,
655 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
660 virtual bool Destroy()
662 // FIXME: why exactly do we do this? to avoid activation events during
663 // destructions maybe?
665 return BaseClass::Destroy();
669 // hook the child view into event handlers chain here
670 virtual bool TryBefore(wxEvent
& event
)
672 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
676 void OnActivate(wxActivateEvent
& event
)
678 BaseClass::OnActivate(event
);
681 m_childView
->Activate(event
.GetActive());
684 void OnCloseWindow(wxCloseEvent
& event
)
686 if ( CloseView(event
) )
691 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
692 ChildFrame
, ParentFrame
);
695 // ----------------------------------------------------------------------------
696 // A default child frame: we need to define it as a class just for wxRTTI,
697 // otherwise we could simply typedef it
698 // ----------------------------------------------------------------------------
701 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
702 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
703 // template will be DLL-exported but only once it is used as base class
705 #pragma warning (push)
706 #pragma warning (disable:4275)
709 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
711 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
718 wxDocChildFrame(wxDocument
*doc
,
722 const wxString
& title
,
723 const wxPoint
& pos
= wxDefaultPosition
,
724 const wxSize
& size
= wxDefaultSize
,
725 long style
= wxDEFAULT_FRAME_STYLE
,
726 const wxString
& name
= wxFrameNameStr
)
727 : wxDocChildFrameBase(doc
, view
,
728 parent
, id
, title
, pos
, size
, style
, name
)
732 bool Create(wxDocument
*doc
,
736 const wxString
& title
,
737 const wxPoint
& pos
= wxDefaultPosition
,
738 const wxSize
& size
= wxDefaultSize
,
739 long style
= wxDEFAULT_FRAME_STYLE
,
740 const wxString
& name
= wxFrameNameStr
)
742 return wxDocChildFrameBase::Create
745 parent
, id
, title
, pos
, size
, style
, name
750 DECLARE_CLASS(wxDocChildFrame
)
751 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
755 #pragma warning (pop)
758 // ----------------------------------------------------------------------------
759 // A default parent frame
760 // ----------------------------------------------------------------------------
762 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxFrame
766 wxDocParentFrame(wxDocManager
*manager
,
769 const wxString
& title
,
770 const wxPoint
& pos
= wxDefaultPosition
,
771 const wxSize
& size
= wxDefaultSize
,
772 long style
= wxDEFAULT_FRAME_STYLE
,
773 const wxString
& name
= wxFrameNameStr
);
775 bool Create(wxDocManager
*manager
,
778 const wxString
& title
,
779 const wxPoint
& pos
= wxDefaultPosition
,
780 const wxSize
& size
= wxDefaultSize
,
781 long style
= wxDEFAULT_FRAME_STYLE
,
782 const wxString
& name
= wxFrameNameStr
);
784 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
786 void OnExit(wxCommandEvent
& event
);
787 void OnMRUFile(wxCommandEvent
& event
);
788 void OnCloseWindow(wxCloseEvent
& event
);
791 // hook the document manager into event handling chain here
792 virtual bool TryBefore(wxEvent
& event
);
794 wxDocManager
*m_docManager
;
797 typedef wxFrame base_type
;
798 DECLARE_CLASS(wxDocParentFrame
)
799 DECLARE_EVENT_TABLE()
800 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
803 // ----------------------------------------------------------------------------
804 // Provide simple default printing facilities
805 // ----------------------------------------------------------------------------
807 #if wxUSE_PRINTING_ARCHITECTURE
808 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
811 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxT("Printout"));
813 // implement wxPrintout methods
814 virtual bool OnPrintPage(int page
);
815 virtual bool HasPage(int page
);
816 virtual bool OnBeginDocument(int startPage
, int endPage
);
817 virtual void GetPageInfo(int *minPage
, int *maxPage
,
818 int *selPageFrom
, int *selPageTo
);
820 virtual wxView
*GetView() { return m_printoutView
; }
823 wxView
* m_printoutView
;
826 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
827 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
829 #endif // wxUSE_PRINTING_ARCHITECTURE
831 // For compatibility with existing file formats:
832 // converts from/to a stream to/from a temporary file.
833 #if wxUSE_STD_IOSTREAM
834 bool WXDLLIMPEXP_CORE
835 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
836 bool WXDLLIMPEXP_CORE
837 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
839 bool WXDLLIMPEXP_CORE
840 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
841 bool WXDLLIMPEXP_CORE
842 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
843 #endif // wxUSE_STD_IOSTREAM
846 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
847 // case of existing user code using them for its own purposes
848 #ifdef WXWIN_COMPATIBILITY_2_8
853 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
855 #endif // WXWIN_COMPATIBILITY_2_8
857 #endif // wxUSE_DOC_VIEW_ARCHITECTURE