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"
23 #if wxUSE_PRINTING_ARCHITECTURE
27 class WXDLLIMPEXP_FWD_CORE wxWindow
;
28 class WXDLLIMPEXP_FWD_CORE wxDocument
;
29 class WXDLLIMPEXP_FWD_CORE wxView
;
30 class WXDLLIMPEXP_FWD_CORE wxDocTemplate
;
31 class WXDLLIMPEXP_FWD_CORE wxDocManager
;
32 class WXDLLIMPEXP_FWD_CORE wxPrintInfo
;
33 class WXDLLIMPEXP_FWD_CORE wxCommandProcessor
;
34 class WXDLLIMPEXP_FWD_CORE wxFileHistory
;
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
) { m_documentModified
= 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
)
253 m_docChildFrame
= docChildFrame
;
257 // hook the document into event handlers chain here
258 virtual bool TryBefore(wxEvent
& event
);
260 wxDocument
* m_viewDocument
;
261 wxString m_viewTypeName
;
262 wxWindow
* m_viewFrame
;
264 wxDocChildFrameAnyBase
*m_docChildFrame
;
267 DECLARE_ABSTRACT_CLASS(wxView
)
268 wxDECLARE_NO_COPY_CLASS(wxView
);
271 // Represents user interface (and other) properties of documents and views
272 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
275 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
278 // Associate document and view types. They're for identifying what view is
279 // associated with what template/document type
280 wxDocTemplate(wxDocManager
*manager
,
281 const wxString
& descr
,
282 const wxString
& filter
,
285 const wxString
& docTypeName
,
286 const wxString
& viewTypeName
,
287 wxClassInfo
*docClassInfo
= NULL
,
288 wxClassInfo
*viewClassInfo
= NULL
,
289 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
291 virtual ~wxDocTemplate();
293 // By default, these two member functions dynamically creates document and
294 // view using dynamic instance construction. Override these if you need a
295 // different method of construction.
296 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
297 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
299 // Helper method for CreateDocument; also allows you to do your own document
301 virtual bool InitDocument(wxDocument
* doc
,
302 const wxString
& path
,
305 wxString
GetDefaultExtension() const { return m_defaultExt
; }
306 wxString
GetDescription() const { return m_description
; }
307 wxString
GetDirectory() const { return m_directory
; }
308 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
309 void SetDocumentManager(wxDocManager
*manager
)
310 { m_documentManager
= manager
; }
311 wxString
GetFileFilter() const { return m_fileFilter
; }
312 long GetFlags() const { return m_flags
; }
313 virtual wxString
GetViewName() const { return m_viewTypeName
; }
314 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
316 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
317 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
318 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
319 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
320 void SetFlags(long flags
) { m_flags
= flags
; }
322 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
324 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
325 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
327 virtual bool FileMatchesTemplate(const wxString
& path
);
331 wxString m_fileFilter
;
332 wxString m_directory
;
333 wxString m_description
;
334 wxString m_defaultExt
;
335 wxString m_docTypeName
;
336 wxString m_viewTypeName
;
337 wxDocManager
* m_documentManager
;
339 // For dynamic creation of appropriate instances.
340 wxClassInfo
* m_docClassInfo
;
341 wxClassInfo
* m_viewClassInfo
;
343 // Called by CreateDocument and CreateView to create the actual
344 // document/view object.
346 // By default uses the ClassInfo provided to the constructor. Override
347 // these functions to provide a different method of creation.
348 virtual wxDocument
*DoCreateDocument();
349 virtual wxView
*DoCreateView();
352 DECLARE_CLASS(wxDocTemplate
)
353 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
356 // One object of this class may be created in an application, to manage all
357 // the templates and documents.
358 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
361 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
362 wxDocManager(long flags
= 0, bool initialize
= true);
363 virtual ~wxDocManager();
365 virtual bool Initialize();
367 // Handlers for common user commands
368 void OnFileClose(wxCommandEvent
& event
);
369 void OnFileCloseAll(wxCommandEvent
& event
);
370 void OnFileNew(wxCommandEvent
& event
);
371 void OnFileOpen(wxCommandEvent
& event
);
372 void OnFileRevert(wxCommandEvent
& event
);
373 void OnFileSave(wxCommandEvent
& event
);
374 void OnFileSaveAs(wxCommandEvent
& event
);
375 void OnPrint(wxCommandEvent
& event
);
376 void OnPreview(wxCommandEvent
& event
);
377 void OnUndo(wxCommandEvent
& event
);
378 void OnRedo(wxCommandEvent
& event
);
380 // Handlers for UI update commands
381 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
382 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
383 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
384 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
385 void OnUpdateUndo(wxUpdateUIEvent
& event
);
386 void OnUpdateRedo(wxUpdateUIEvent
& event
);
388 // called when file format detection didn't work, can be overridden to do
389 // something in this case
390 virtual void OnOpenFileFailure() { }
392 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
394 // wrapper around CreateDocument() with a more clear name
395 wxDocument
*CreateNewDocument()
396 { return CreateDocument(wxString(), wxDOC_NEW
); }
398 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
399 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
400 virtual bool FlushDoc(wxDocument
*doc
);
401 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
402 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
403 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
404 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
405 int noTemplates
, bool sort
= false);
406 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
407 int noTemplates
, bool sort
= false);
408 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
410 void AssociateTemplate(wxDocTemplate
*temp
);
411 void DisassociateTemplate(wxDocTemplate
*temp
);
413 wxDocument
*GetCurrentDocument() const;
415 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
416 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
418 // Add and remove a document from the manager's list
419 void AddDocument(wxDocument
*doc
);
420 void RemoveDocument(wxDocument
*doc
);
422 // closes all currently open documents
423 bool CloseDocuments(bool force
= true);
425 // closes the specified document
426 bool CloseDocument(wxDocument
* doc
, bool force
= false);
428 // Clear remaining documents and templates
429 bool Clear(bool force
= true);
431 // Views or windows should inform the document manager
432 // when a view is going in or out of focus
433 virtual void ActivateView(wxView
*view
, bool activate
= true);
434 virtual wxView
*GetCurrentView() const { return m_currentView
; }
436 wxList
& GetDocuments() { return m_docs
; }
437 wxList
& GetTemplates() { return m_templates
; }
439 // Return the default name for a new document (by default returns strings
440 // in the form "unnamed <counter>" but can be overridden)
441 virtual wxString
MakeNewDocumentName();
443 // Make a frame title (override this to do something different)
444 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
446 virtual wxFileHistory
*OnCreateFileHistory();
447 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
449 // File history management
450 virtual void AddFileToHistory(const wxString
& file
);
451 virtual void RemoveFileFromHistory(size_t i
);
452 virtual size_t GetHistoryFilesCount() const;
453 virtual wxString
GetHistoryFile(size_t i
) const;
454 virtual void FileHistoryUseMenu(wxMenu
*menu
);
455 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
457 virtual void FileHistoryLoad(const wxConfigBase
& config
);
458 virtual void FileHistorySave(wxConfigBase
& config
);
459 #endif // wxUSE_CONFIG
461 virtual void FileHistoryAddFilesToMenu();
462 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
464 wxString
GetLastDirectory() const;
465 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
467 // Get the current document manager
468 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
470 #if WXWIN_COMPATIBILITY_2_8
471 // deprecated, override GetDefaultName() instead
472 wxDEPRECATED_BUT_USED_INTERNALLY(
473 virtual bool MakeDefaultName(wxString
& buf
)
477 #if WXWIN_COMPATIBILITY_2_6
478 // deprecated, use GetHistoryFilesCount() instead
479 wxDEPRECATED( size_t GetNoHistoryFiles() const );
480 #endif // WXWIN_COMPATIBILITY_2_6
483 // hook the currently active view into event handlers chain here
484 virtual bool TryBefore(wxEvent
& event
);
486 // return the command processor for the current document, if any
487 wxCommandProcessor
*GetCurrentCommandProcessor() const;
489 // this method tries to find an active view harder than GetCurrentView():
490 // if the latter is NULL, it also checks if we don't have just a single
491 // view and returns it then
492 wxView
*GetActiveView() const;
495 int m_defaultDocumentNameCounter
;
499 wxView
* m_currentView
;
500 wxFileHistory
* m_fileHistory
;
501 wxString m_lastDirectory
;
502 static wxDocManager
* sm_docManager
;
504 DECLARE_EVENT_TABLE()
505 DECLARE_DYNAMIC_CLASS(wxDocManager
)
506 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
509 #if WXWIN_COMPATIBILITY_2_6
510 inline size_t wxDocManager::GetNoHistoryFiles() const
512 return GetHistoryFilesCount();
514 #endif // WXWIN_COMPATIBILITY_2_6
516 // ----------------------------------------------------------------------------
517 // Base class for child frames -- this is what wxView renders itself into
519 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
520 // wxDocChildFrameAny does
521 // ----------------------------------------------------------------------------
523 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
526 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
)
528 m_childDocument
= doc
;
532 view
->SetDocChildFrame(this);
535 wxDocument
*GetDocument() const { return m_childDocument
; }
536 wxView
*GetView() const { return m_childView
; }
537 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
538 void SetView(wxView
*view
) { m_childView
= view
; }
541 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
542 // which is called from TryBefore() of the derived classes to give our view
543 // a chance to process the message before the frame event handlers are used
544 bool TryProcessEvent(wxEvent
& event
)
546 return m_childView
&& m_childView
->ProcessEventHere(event
);
549 // called from EVT_CLOSE handler in the frame: check if we can close and do
550 // cleanup if so; veto the event otherwise
551 bool CloseView(wxCloseEvent
& event
);
554 wxDocument
* m_childDocument
;
557 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
560 // ----------------------------------------------------------------------------
561 // Template implementing child frame concept using the given wxFrame-like class
563 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
564 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
565 // derived class as long as it provided a ctor with the same signature as
566 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
568 // ----------------------------------------------------------------------------
570 template <class ChildFrame
, class ParentFrame
>
571 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
572 public wxDocChildFrameAnyBase
575 typedef ChildFrame BaseClass
;
577 // ctor for a frame showing the given view of the specified document
578 wxDocChildFrameAny(wxDocument
*doc
,
582 const wxString
& title
,
583 const wxPoint
& pos
= wxDefaultPosition
,
584 const wxSize
& size
= wxDefaultSize
,
585 long style
= wxDEFAULT_FRAME_STYLE
,
586 const wxString
& name
= wxFrameNameStr
)
587 : BaseClass(parent
, id
, title
, pos
, size
, style
, name
),
588 wxDocChildFrameAnyBase(doc
, view
)
591 view
->SetFrame(this);
593 this->Connect(wxEVT_ACTIVATE
,
594 wxActivateEventHandler(wxDocChildFrameAny::OnActivate
));
595 this->Connect(wxEVT_CLOSE_WINDOW
,
596 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow
));
599 virtual bool Destroy()
601 // FIXME: why exactly do we do this? to avoid activation events during
602 // destructions maybe?
604 return BaseClass::Destroy();
608 // hook the child view into event handlers chain here
609 virtual bool TryBefore(wxEvent
& event
)
611 return TryProcessEvent(event
) || BaseClass::TryBefore(event
);
615 void OnActivate(wxActivateEvent
& event
)
617 BaseClass::OnActivate(event
);
620 m_childView
->Activate(event
.GetActive());
623 void OnCloseWindow(wxCloseEvent
& event
)
625 if ( CloseView(event
) )
630 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
631 ChildFrame
, ParentFrame
);
634 // ----------------------------------------------------------------------------
635 // A default child frame: we need to define it as a class just for wxRTTI,
636 // otherwise we could simply typedef it
637 // ----------------------------------------------------------------------------
640 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
641 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
642 // template will be DLL-exported but only once it is used as base class
644 #pragma warning (disable:4275)
647 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
649 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
652 wxDocChildFrame(wxDocument
*doc
,
656 const wxString
& title
,
657 const wxPoint
& pos
= wxDefaultPosition
,
658 const wxSize
& size
= wxDefaultSize
,
659 long style
= wxDEFAULT_FRAME_STYLE
,
660 const wxString
& name
= wxFrameNameStr
)
661 : wxDocChildFrameBase(doc
, view
,
662 parent
, id
, title
, pos
, size
, style
, name
)
667 DECLARE_CLASS(wxDocChildFrame
)
668 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
672 #pragma warning (default:4275)
675 // ----------------------------------------------------------------------------
676 // A default parent frame
677 // ----------------------------------------------------------------------------
679 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxFrame
683 wxDocParentFrame(wxDocManager
*manager
,
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 bool Create(wxDocManager
*manager
,
695 const wxString
& title
,
696 const wxPoint
& pos
= wxDefaultPosition
,
697 const wxSize
& size
= wxDefaultSize
,
698 long style
= wxDEFAULT_FRAME_STYLE
,
699 const wxString
& name
= wxFrameNameStr
);
701 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
703 void OnExit(wxCommandEvent
& event
);
704 void OnMRUFile(wxCommandEvent
& event
);
705 void OnCloseWindow(wxCloseEvent
& event
);
708 // hook the document manager into event handling chain here
709 virtual bool TryBefore(wxEvent
& event
);
711 wxDocManager
*m_docManager
;
714 typedef wxFrame base_type
;
715 DECLARE_CLASS(wxDocParentFrame
)
716 DECLARE_EVENT_TABLE()
717 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
720 // ----------------------------------------------------------------------------
721 // Provide simple default printing facilities
722 // ----------------------------------------------------------------------------
724 #if wxUSE_PRINTING_ARCHITECTURE
725 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
728 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxT("Printout"));
730 // implement wxPrintout methods
731 virtual bool OnPrintPage(int page
);
732 virtual bool HasPage(int page
);
733 virtual bool OnBeginDocument(int startPage
, int endPage
);
734 virtual void GetPageInfo(int *minPage
, int *maxPage
,
735 int *selPageFrom
, int *selPageTo
);
737 virtual wxView
*GetView() { return m_printoutView
; }
740 wxView
* m_printoutView
;
743 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
744 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
746 #endif // wxUSE_PRINTING_ARCHITECTURE
748 // ----------------------------------------------------------------------------
749 // File history management
750 // ----------------------------------------------------------------------------
752 class WXDLLIMPEXP_CORE wxFileHistory
: public wxObject
755 wxFileHistory(size_t maxFiles
= 9, wxWindowID idBase
= wxID_FILE1
);
758 virtual void AddFileToHistory(const wxString
& file
);
759 virtual void RemoveFileFromHistory(size_t i
);
760 virtual int GetMaxFiles() const { return (int)m_fileMaxFiles
; }
761 virtual void UseMenu(wxMenu
*menu
);
763 // Remove menu from the list (MDI child may be closing)
764 virtual void RemoveMenu(wxMenu
*menu
);
767 virtual void Load(const wxConfigBase
& config
);
768 virtual void Save(wxConfigBase
& config
);
769 #endif // wxUSE_CONFIG
771 virtual void AddFilesToMenu();
772 virtual void AddFilesToMenu(wxMenu
* menu
); // Single menu
775 virtual wxString
GetHistoryFile(size_t i
) const { return m_fileHistory
[i
]; }
776 virtual size_t GetCount() const { return m_fileHistory
.GetCount(); }
778 const wxList
& GetMenus() const { return m_fileMenus
; }
781 void SetBaseId(wxWindowID baseId
) { m_idBase
= baseId
; }
782 wxWindowID
GetBaseId() const { return m_idBase
; }
784 #if WXWIN_COMPATIBILITY_2_6
785 // deprecated, use GetCount() instead
786 wxDEPRECATED( size_t GetNoHistoryFiles() const );
787 #endif // WXWIN_COMPATIBILITY_2_6
791 wxArrayString m_fileHistory
;
793 // Menus to maintain (may need several for an MDI app)
796 // Max files to maintain
797 size_t m_fileMaxFiles
;
800 // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
803 DECLARE_DYNAMIC_CLASS(wxFileHistory
)
804 wxDECLARE_NO_COPY_CLASS(wxFileHistory
);
807 #if WXWIN_COMPATIBILITY_2_6
808 inline size_t wxFileHistory::GetNoHistoryFiles() const
810 return m_fileHistory
.GetCount();
812 #endif // WXWIN_COMPATIBILITY_2_6
814 // For compatibility with existing file formats:
815 // converts from/to a stream to/from a temporary file.
816 #if wxUSE_STD_IOSTREAM
817 bool WXDLLIMPEXP_CORE
818 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
819 bool WXDLLIMPEXP_CORE
820 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
822 bool WXDLLIMPEXP_CORE
823 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
824 bool WXDLLIMPEXP_CORE
825 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
826 #endif // wxUSE_STD_IOSTREAM
829 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
830 // case of existing user code using them for its own purposes
831 #ifdef WXWIN_COMPATIBILITY_2_8
836 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
838 #endif // WXWIN_COMPATIBILITY_2_8
840 #endif // wxUSE_DOC_VIEW_ARCHITECTURE