1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Doc/View classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
16 #if wxUSE_DOC_VIEW_ARCHITECTURE
20 #include "wx/string.h"
22 #include "wx/filehistory.h"
23 #include "wx/vector.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 typedef wxVector
<wxDocument
*> wxDocVector
;
64 typedef wxVector
<wxView
*> wxViewVector
;
65 typedef wxVector
<wxDocTemplate
*> wxDocTemplateVector
;
67 class WXDLLIMPEXP_CORE wxDocument
: public wxEvtHandler
70 wxDocument(wxDocument
*parent
= NULL
);
71 virtual ~wxDocument();
74 void SetFilename(const wxString
& filename
, bool notifyViews
= false);
75 wxString
GetFilename() const { return m_documentFile
; }
77 void SetTitle(const wxString
& title
) { m_documentTitle
= title
; }
78 wxString
GetTitle() const { return m_documentTitle
; }
80 void SetDocumentName(const wxString
& name
) { m_documentTypeName
= name
; }
81 wxString
GetDocumentName() const { return m_documentTypeName
; }
83 // access the flag indicating whether this document had been already saved,
84 // SetDocumentSaved() is only used internally, don't call it
85 bool GetDocumentSaved() const { return m_savedYet
; }
86 void SetDocumentSaved(bool saved
= true) { m_savedYet
= saved
; }
88 // activate the first view of the document if any
91 // return true if the document hasn't been modified since the last time it
92 // was saved (implying that it returns false if it was never saved, even if
93 // the document is not modified)
94 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
98 virtual bool SaveAs();
99 virtual bool Revert();
101 #if wxUSE_STD_IOSTREAM
102 virtual wxSTD ostream
& SaveObject(wxSTD ostream
& stream
);
103 virtual wxSTD istream
& LoadObject(wxSTD istream
& stream
);
105 virtual wxOutputStream
& SaveObject(wxOutputStream
& stream
);
106 virtual wxInputStream
& LoadObject(wxInputStream
& stream
);
109 // Called by wxWidgets
110 virtual bool OnSaveDocument(const wxString
& filename
);
111 virtual bool OnOpenDocument(const wxString
& filename
);
112 virtual bool OnNewDocument();
113 virtual bool OnCloseDocument();
115 // Prompts for saving if about to close a modified document. Returns true
116 // if ok to close the document (may have saved in the meantime, or set
117 // modified to false)
118 virtual bool OnSaveModified();
120 // if you override, remember to call the default
121 // implementation (wxDocument::OnChangeFilename)
122 virtual void OnChangeFilename(bool notifyViews
);
124 // Called by framework if created automatically by the default document
125 // manager: gives document a chance to initialise and (usually) create a
127 virtual bool OnCreate(const wxString
& path
, long flags
);
129 // By default, creates a base wxCommandProcessor.
130 virtual wxCommandProcessor
*OnCreateCommandProcessor();
131 virtual wxCommandProcessor
*GetCommandProcessor() const
132 { return m_commandProcessor
; }
133 virtual void SetCommandProcessor(wxCommandProcessor
*proc
)
134 { m_commandProcessor
= proc
; }
136 // Called after a view is added or removed. The default implementation
137 // deletes the document if this is there are no more views.
138 virtual void OnChangedViewList();
140 // Called from OnCloseDocument(), does nothing by default but may be
141 // overridden. Return value is ignored.
142 virtual bool DeleteContents();
144 virtual bool Draw(wxDC
&);
145 virtual bool IsModified() const { return m_documentModified
; }
146 virtual void Modify(bool mod
);
148 virtual bool AddView(wxView
*view
);
149 virtual bool RemoveView(wxView
*view
);
152 wxViewVector
GetViewsVector() const;
153 #endif // !__VISUALC6__
155 wxList
& GetViews() { return m_documentViews
; }
156 const wxList
& GetViews() const { return m_documentViews
; }
158 wxView
*GetFirstView() const;
160 virtual void UpdateAllViews(wxView
*sender
= NULL
, wxObject
*hint
= NULL
);
161 virtual void NotifyClosing();
163 // Remove all views (because we're closing the document)
164 virtual bool DeleteAllViews();
167 virtual wxDocManager
*GetDocumentManager() const;
168 virtual wxDocTemplate
*GetDocumentTemplate() const
169 { return m_documentTemplate
; }
170 virtual void SetDocumentTemplate(wxDocTemplate
*temp
)
171 { m_documentTemplate
= temp
; }
173 // Get the document name to be shown to the user: the title if there is
174 // any, otherwise the filename if the document was saved and, finally,
175 // "unnamed" otherwise
176 virtual wxString
GetUserReadableName() const;
178 #if WXWIN_COMPATIBILITY_2_8
179 // use GetUserReadableName() instead
180 wxDEPRECATED_BUT_USED_INTERNALLY(
181 virtual bool GetPrintableName(wxString
& buf
) const
183 #endif // WXWIN_COMPATIBILITY_2_8
185 // Returns a window that can be used as a parent for document-related
186 // dialogs. Override if necessary.
187 virtual wxWindow
*GetDocumentWindow() const;
189 // Returns true if this document is a child document corresponding to a
190 // part of the parent document and not a disk file as usual.
191 bool IsChildDocument() const { return m_documentParent
!= NULL
; }
194 wxList m_documentViews
;
195 wxString m_documentFile
;
196 wxString m_documentTitle
;
197 wxString m_documentTypeName
;
198 wxDocTemplate
* m_documentTemplate
;
199 bool m_documentModified
;
201 // if the document parent is non-NULL, it's a pseudo-document corresponding
202 // to a part of the parent document which can't be saved or loaded
203 // independently of its parent and is always closed when its parent is
204 wxDocument
* m_documentParent
;
206 wxCommandProcessor
* m_commandProcessor
;
209 // Called by OnSaveDocument and OnOpenDocument to implement standard
210 // Save/Load behaviour. Re-implement in derived class for custom
212 virtual bool DoSaveDocument(const wxString
& file
);
213 virtual bool DoOpenDocument(const wxString
& file
);
215 // the default implementation of GetUserReadableName()
216 wxString
DoGetUserReadableName() const;
219 // list of all documents whose m_documentParent is this one
220 typedef wxDList
<wxDocument
> DocsList
;
221 DocsList m_childDocuments
;
223 DECLARE_ABSTRACT_CLASS(wxDocument
)
224 wxDECLARE_NO_COPY_CLASS(wxDocument
);
227 class WXDLLIMPEXP_CORE wxView
: public wxEvtHandler
233 wxDocument
*GetDocument() const { return m_viewDocument
; }
234 virtual void SetDocument(wxDocument
*doc
);
236 wxString
GetViewName() const { return m_viewTypeName
; }
237 void SetViewName(const wxString
& name
) { m_viewTypeName
= name
; }
239 wxWindow
*GetFrame() const { return m_viewFrame
; }
240 void SetFrame(wxWindow
*frame
) { m_viewFrame
= frame
; }
242 virtual void OnActivateView(bool activate
,
244 wxView
*deactiveView
);
245 virtual void OnDraw(wxDC
*dc
) = 0;
246 virtual void OnPrint(wxDC
*dc
, wxObject
*info
);
247 virtual void OnUpdate(wxView
*sender
, wxObject
*hint
= NULL
);
248 virtual void OnClosingDocument() {}
249 virtual void OnChangeFilename();
251 // Called by framework if created automatically by the default document
252 // manager class: gives view a chance to initialise
253 virtual bool OnCreate(wxDocument
*WXUNUSED(doc
), long WXUNUSED(flags
))
256 // Checks if the view is the last one for the document; if so, asks user
257 // to confirm save data (if modified). If ok, deletes itself and returns
259 virtual bool Close(bool deleteWindow
= true);
261 // Override to do cleanup/veto close
262 virtual bool OnClose(bool deleteWindow
);
264 // A view's window can call this to notify the view it is (in)active.
265 // The function then notifies the document manager.
266 virtual void Activate(bool activate
);
268 wxDocManager
*GetDocumentManager() const
269 { return m_viewDocument
->GetDocumentManager(); }
271 #if wxUSE_PRINTING_ARCHITECTURE
272 virtual wxPrintout
*OnCreatePrintout();
275 // implementation only
276 // -------------------
278 // set the associated frame, it is used to reset its view when we're
280 void SetDocChildFrame(wxDocChildFrameAnyBase
*docChildFrame
);
282 // get the associated frame, may be NULL during destruction
283 wxDocChildFrameAnyBase
* GetDocChildFrame() const { return m_docChildFrame
; }
286 // hook the document into event handlers chain here
287 virtual bool TryBefore(wxEvent
& event
);
289 wxDocument
* m_viewDocument
;
290 wxString m_viewTypeName
;
291 wxWindow
* m_viewFrame
;
293 wxDocChildFrameAnyBase
*m_docChildFrame
;
296 DECLARE_ABSTRACT_CLASS(wxView
)
297 wxDECLARE_NO_COPY_CLASS(wxView
);
300 // Represents user interface (and other) properties of documents and views
301 class WXDLLIMPEXP_CORE wxDocTemplate
: public wxObject
304 friend class WXDLLIMPEXP_FWD_CORE wxDocManager
;
307 // Associate document and view types. They're for identifying what view is
308 // associated with what template/document type
309 wxDocTemplate(wxDocManager
*manager
,
310 const wxString
& descr
,
311 const wxString
& filter
,
314 const wxString
& docTypeName
,
315 const wxString
& viewTypeName
,
316 wxClassInfo
*docClassInfo
= NULL
,
317 wxClassInfo
*viewClassInfo
= NULL
,
318 long flags
= wxDEFAULT_TEMPLATE_FLAGS
);
320 virtual ~wxDocTemplate();
322 // By default, these two member functions dynamically creates document and
323 // view using dynamic instance construction. Override these if you need a
324 // different method of construction.
325 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
326 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
328 // Helper method for CreateDocument; also allows you to do your own document
330 virtual bool InitDocument(wxDocument
* doc
,
331 const wxString
& path
,
334 wxString
GetDefaultExtension() const { return m_defaultExt
; }
335 wxString
GetDescription() const { return m_description
; }
336 wxString
GetDirectory() const { return m_directory
; }
337 wxDocManager
*GetDocumentManager() const { return m_documentManager
; }
338 void SetDocumentManager(wxDocManager
*manager
)
339 { m_documentManager
= manager
; }
340 wxString
GetFileFilter() const { return m_fileFilter
; }
341 long GetFlags() const { return m_flags
; }
342 virtual wxString
GetViewName() const { return m_viewTypeName
; }
343 virtual wxString
GetDocumentName() const { return m_docTypeName
; }
345 void SetFileFilter(const wxString
& filter
) { m_fileFilter
= filter
; }
346 void SetDirectory(const wxString
& dir
) { m_directory
= dir
; }
347 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
348 void SetDefaultExtension(const wxString
& ext
) { m_defaultExt
= ext
; }
349 void SetFlags(long flags
) { m_flags
= flags
; }
351 bool IsVisible() const { return (m_flags
& wxTEMPLATE_VISIBLE
) != 0; }
353 wxClassInfo
* GetDocClassInfo() const { return m_docClassInfo
; }
354 wxClassInfo
* GetViewClassInfo() const { return m_viewClassInfo
; }
356 virtual bool FileMatchesTemplate(const wxString
& path
);
360 wxString m_fileFilter
;
361 wxString m_directory
;
362 wxString m_description
;
363 wxString m_defaultExt
;
364 wxString m_docTypeName
;
365 wxString m_viewTypeName
;
366 wxDocManager
* m_documentManager
;
368 // For dynamic creation of appropriate instances.
369 wxClassInfo
* m_docClassInfo
;
370 wxClassInfo
* m_viewClassInfo
;
372 // Called by CreateDocument and CreateView to create the actual
373 // document/view object.
375 // By default uses the ClassInfo provided to the constructor. Override
376 // these functions to provide a different method of creation.
377 virtual wxDocument
*DoCreateDocument();
378 virtual wxView
*DoCreateView();
381 DECLARE_CLASS(wxDocTemplate
)
382 wxDECLARE_NO_COPY_CLASS(wxDocTemplate
);
385 // One object of this class may be created in an application, to manage all
386 // the templates and documents.
387 class WXDLLIMPEXP_CORE wxDocManager
: public wxEvtHandler
390 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
391 wxDocManager(long flags
= 0, bool initialize
= true);
392 virtual ~wxDocManager();
394 virtual bool Initialize();
396 // Handlers for common user commands
397 void OnFileClose(wxCommandEvent
& event
);
398 void OnFileCloseAll(wxCommandEvent
& event
);
399 void OnFileNew(wxCommandEvent
& event
);
400 void OnFileOpen(wxCommandEvent
& event
);
401 void OnFileRevert(wxCommandEvent
& event
);
402 void OnFileSave(wxCommandEvent
& event
);
403 void OnFileSaveAs(wxCommandEvent
& event
);
404 void OnMRUFile(wxCommandEvent
& event
);
405 #if wxUSE_PRINTING_ARCHITECTURE
406 void OnPrint(wxCommandEvent
& event
);
407 void OnPreview(wxCommandEvent
& event
);
408 void OnPageSetup(wxCommandEvent
& event
);
409 #endif // wxUSE_PRINTING_ARCHITECTURE
410 void OnUndo(wxCommandEvent
& event
);
411 void OnRedo(wxCommandEvent
& event
);
413 // Handlers for UI update commands
414 void OnUpdateFileOpen(wxUpdateUIEvent
& event
);
415 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent
& event
);
416 void OnUpdateFileRevert(wxUpdateUIEvent
& event
);
417 void OnUpdateFileNew(wxUpdateUIEvent
& event
);
418 void OnUpdateFileSave(wxUpdateUIEvent
& event
);
419 void OnUpdateFileSaveAs(wxUpdateUIEvent
& event
);
420 void OnUpdateUndo(wxUpdateUIEvent
& event
);
421 void OnUpdateRedo(wxUpdateUIEvent
& event
);
423 // called when file format detection didn't work, can be overridden to do
424 // something in this case
425 virtual void OnOpenFileFailure() { }
427 virtual wxDocument
*CreateDocument(const wxString
& path
, long flags
= 0);
429 // wrapper around CreateDocument() with a more clear name
430 wxDocument
*CreateNewDocument()
431 { return CreateDocument(wxString(), wxDOC_NEW
); }
433 virtual wxView
*CreateView(wxDocument
*doc
, long flags
= 0);
434 virtual void DeleteTemplate(wxDocTemplate
*temp
, long flags
= 0);
435 virtual bool FlushDoc(wxDocument
*doc
);
436 virtual wxDocTemplate
*MatchTemplate(const wxString
& path
);
437 virtual wxDocTemplate
*SelectDocumentPath(wxDocTemplate
**templates
,
438 int noTemplates
, wxString
& path
, long flags
, bool save
= false);
439 virtual wxDocTemplate
*SelectDocumentType(wxDocTemplate
**templates
,
440 int noTemplates
, bool sort
= false);
441 virtual wxDocTemplate
*SelectViewType(wxDocTemplate
**templates
,
442 int noTemplates
, bool sort
= false);
443 virtual wxDocTemplate
*FindTemplateForPath(const wxString
& path
);
445 void AssociateTemplate(wxDocTemplate
*temp
);
446 void DisassociateTemplate(wxDocTemplate
*temp
);
448 // Find template from document class info, may return NULL.
449 wxDocTemplate
* FindTemplate(const wxClassInfo
* documentClassInfo
);
451 // Find document from file name, may return NULL.
452 wxDocument
* FindDocumentByPath(const wxString
& path
) const;
454 wxDocument
*GetCurrentDocument() const;
456 void SetMaxDocsOpen(int n
) { m_maxDocsOpen
= n
; }
457 int GetMaxDocsOpen() const { return m_maxDocsOpen
; }
459 // Add and remove a document from the manager's list
460 void AddDocument(wxDocument
*doc
);
461 void RemoveDocument(wxDocument
*doc
);
463 // closes all currently open documents
464 bool CloseDocuments(bool force
= true);
466 // closes the specified document
467 bool CloseDocument(wxDocument
* doc
, bool force
= false);
469 // Clear remaining documents and templates
470 bool Clear(bool force
= true);
472 // Views or windows should inform the document manager
473 // when a view is going in or out of focus
474 virtual void ActivateView(wxView
*view
, bool activate
= true);
475 virtual wxView
*GetCurrentView() const { return m_currentView
; }
477 // This method tries to find an active view harder than GetCurrentView():
478 // if the latter is NULL, it also checks if we don't have just a single
479 // view and returns it then.
480 wxView
*GetAnyUsableView() const;
484 wxDocVector
GetDocumentsVector() const;
485 wxDocTemplateVector
GetTemplatesVector() const;
486 #endif // !__VISUALC6__
488 wxList
& GetDocuments() { return m_docs
; }
489 wxList
& GetTemplates() { return m_templates
; }
491 // Return the default name for a new document (by default returns strings
492 // in the form "unnamed <counter>" but can be overridden)
493 virtual wxString
MakeNewDocumentName();
495 // Make a frame title (override this to do something different)
496 virtual wxString
MakeFrameTitle(wxDocument
* doc
);
498 virtual wxFileHistory
*OnCreateFileHistory();
499 virtual wxFileHistory
*GetFileHistory() const { return m_fileHistory
; }
501 // File history management
502 virtual void AddFileToHistory(const wxString
& file
);
503 virtual void RemoveFileFromHistory(size_t i
);
504 virtual size_t GetHistoryFilesCount() const;
505 virtual wxString
GetHistoryFile(size_t i
) const;
506 virtual void FileHistoryUseMenu(wxMenu
*menu
);
507 virtual void FileHistoryRemoveMenu(wxMenu
*menu
);
509 virtual void FileHistoryLoad(const wxConfigBase
& config
);
510 virtual void FileHistorySave(wxConfigBase
& config
);
511 #endif // wxUSE_CONFIG
513 virtual void FileHistoryAddFilesToMenu();
514 virtual void FileHistoryAddFilesToMenu(wxMenu
* menu
);
516 wxString
GetLastDirectory() const;
517 void SetLastDirectory(const wxString
& dir
) { m_lastDirectory
= dir
; }
519 // Get the current document manager
520 static wxDocManager
* GetDocumentManager() { return sm_docManager
; }
522 #if wxUSE_PRINTING_ARCHITECTURE
523 wxPageSetupDialogData
& GetPageSetupDialogData()
524 { return m_pageSetupDialogData
; }
525 const wxPageSetupDialogData
& GetPageSetupDialogData() const
526 { return m_pageSetupDialogData
; }
527 #endif // wxUSE_PRINTING_ARCHITECTURE
529 #if WXWIN_COMPATIBILITY_2_8
530 // deprecated, override GetDefaultName() instead
531 wxDEPRECATED_BUT_USED_INTERNALLY(
532 virtual bool MakeDefaultName(wxString
& buf
)
536 #if WXWIN_COMPATIBILITY_2_6
537 // deprecated, use GetHistoryFilesCount() instead
538 wxDEPRECATED( size_t GetNoHistoryFiles() const );
539 #endif // WXWIN_COMPATIBILITY_2_6
543 // Called when a file selected from the MRU list doesn't exist any more.
544 // The default behaviour is to remove the file from the MRU and notify the
545 // user about it but this method can be overridden to customize it.
546 virtual void OnMRUFileNotExist(unsigned n
, const wxString
& filename
);
548 // Open the MRU file with the given index in our associated file history.
549 void DoOpenMRUFile(unsigned n
);
550 #if wxUSE_PRINTING_ARCHITECTURE
551 virtual wxPreviewFrame
* CreatePreviewFrame(wxPrintPreviewBase
* preview
,
553 const wxString
& title
);
554 #endif // wxUSE_PRINTING_ARCHITECTURE
556 // hook the currently active view into event handlers chain here
557 virtual bool TryBefore(wxEvent
& event
);
559 // return the command processor for the current document, if any
560 wxCommandProcessor
*GetCurrentCommandProcessor() const;
562 int m_defaultDocumentNameCounter
;
566 wxView
* m_currentView
;
567 wxFileHistory
* m_fileHistory
;
568 wxString m_lastDirectory
;
569 static wxDocManager
* sm_docManager
;
571 #if wxUSE_PRINTING_ARCHITECTURE
572 wxPageSetupDialogData m_pageSetupDialogData
;
573 #endif // wxUSE_PRINTING_ARCHITECTURE
575 DECLARE_EVENT_TABLE()
576 DECLARE_DYNAMIC_CLASS(wxDocManager
)
577 wxDECLARE_NO_COPY_CLASS(wxDocManager
);
580 #if WXWIN_COMPATIBILITY_2_6
581 inline size_t wxDocManager
::GetNoHistoryFiles() const
583 return GetHistoryFilesCount();
585 #endif // WXWIN_COMPATIBILITY_2_6
587 // ----------------------------------------------------------------------------
588 // Base class for child frames -- this is what wxView renders itself into
590 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
591 // wxDocChildFrameAny does
592 // ----------------------------------------------------------------------------
594 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
597 // default ctor, use Create() after it
598 wxDocChildFrameAnyBase()
600 m_childDocument
= NULL
;
606 // full ctor equivalent to using the default one and Create()
607 wxDocChildFrameAnyBase(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
609 Create(doc
, view
, win
);
612 // method which must be called for an object created using the default ctor
614 // note that it returns bool just for consistency with Create() methods in
615 // other classes, we never return false from here
616 bool Create(wxDocument
*doc
, wxView
*view
, wxWindow
*win
)
618 m_childDocument
= doc
;
623 view
->SetDocChildFrame(this);
628 // dtor doesn't need to be virtual, an object should never be destroyed via
629 // a pointer to this class
630 ~wxDocChildFrameAnyBase()
632 // prevent the view from deleting us if we're being deleted directly
633 // (and not via Close() + Destroy())
635 m_childView
->SetDocChildFrame(NULL
);
638 wxDocument
*GetDocument() const { return m_childDocument
; }
639 wxView
*GetView() const { return m_childView
; }
640 void SetDocument(wxDocument
*doc
) { m_childDocument
= doc
; }
641 void SetView(wxView
*view
) { m_childView
= view
; }
643 wxWindow
*GetWindow() const { return m_win
; }
645 // implementation only
647 // Check if this event had been just processed in this frame.
648 bool HasAlreadyProcessed(wxEvent
& event
) const
650 return m_lastEvent
== &event
;
654 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
655 // which is called from TryBefore() of the derived classes to give our view
656 // a chance to process the message before the frame event handlers are used
657 bool TryProcessEvent(wxEvent
& event
);
659 // called from EVT_CLOSE handler in the frame: check if we can close and do
660 // cleanup if so; veto the event otherwise
661 bool CloseView(wxCloseEvent
& event
);
664 wxDocument
* m_childDocument
;
667 // the associated window: having it here is not terribly elegant but it
668 // allows us to avoid having any virtual functions in this class
672 // Pointer to the last processed event used to avoid sending the same event
673 // twice to wxDocManager, from here and from wxDocParentFrameAnyBase.
674 wxEvent
* m_lastEvent
;
676 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase
);
679 // ----------------------------------------------------------------------------
680 // Template implementing child frame concept using the given wxFrame-like class
682 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
683 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
684 // derived class as long as it provided a ctor with the same signature as
685 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
687 // ----------------------------------------------------------------------------
689 template <class ChildFrame
, class ParentFrame
>
690 class WXDLLIMPEXP_CORE wxDocChildFrameAny
: public ChildFrame
,
691 public wxDocChildFrameAnyBase
694 typedef ChildFrame BaseClass
;
696 // default ctor, use Create after it
697 wxDocChildFrameAny() { }
699 // ctor for a frame showing the given view of the specified document
700 wxDocChildFrameAny(wxDocument
*doc
,
704 const wxString
& title
,
705 const wxPoint
& pos
= wxDefaultPosition
,
706 const wxSize
& size
= wxDefaultSize
,
707 long style
= wxDEFAULT_FRAME_STYLE
,
708 const wxString
& name
= wxFrameNameStr
)
710 Create(doc
, view
, parent
, id
, title
, pos
, size
, style
, name
);
713 bool Create(wxDocument
*doc
,
717 const wxString
& title
,
718 const wxPoint
& pos
= wxDefaultPosition
,
719 const wxSize
& size
= wxDefaultSize
,
720 long style
= wxDEFAULT_FRAME_STYLE
,
721 const wxString
& name
= wxFrameNameStr
)
723 if ( !wxDocChildFrameAnyBase
::Create(doc
, view
, this) )
726 if ( !BaseClass
::Create(parent
, id
, title
, pos
, size
, style
, name
) )
729 this->Connect(wxEVT_ACTIVATE
,
730 wxActivateEventHandler(wxDocChildFrameAny
::OnActivate
));
731 this->Connect(wxEVT_CLOSE_WINDOW
,
732 wxCloseEventHandler(wxDocChildFrameAny
::OnCloseWindow
));
737 virtual bool Destroy()
739 // FIXME: why exactly do we do this? to avoid activation events during
740 // destructions maybe?
742 return BaseClass
::Destroy();
746 // hook the child view into event handlers chain here
747 virtual bool TryBefore(wxEvent
& event
)
749 return TryProcessEvent(event
) || BaseClass
::TryBefore(event
);
753 void OnActivate(wxActivateEvent
& event
)
755 BaseClass
::OnActivate(event
);
758 m_childView
->Activate(event
.GetActive());
761 void OnCloseWindow(wxCloseEvent
& event
)
763 if ( CloseView(event
) )
768 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny
,
769 ChildFrame
, ParentFrame
);
772 // ----------------------------------------------------------------------------
773 // A default child frame: we need to define it as a class just for wxRTTI,
774 // otherwise we could simply typedef it
775 // ----------------------------------------------------------------------------
778 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
779 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
780 // template will be DLL-exported but only once it is used as base class
782 #pragma warning (push)
783 #pragma warning (disable:4275)
786 typedef wxDocChildFrameAny
<wxFrame
, wxFrame
> wxDocChildFrameBase
;
788 class WXDLLIMPEXP_CORE wxDocChildFrame
: public wxDocChildFrameBase
795 wxDocChildFrame(wxDocument
*doc
,
799 const wxString
& title
,
800 const wxPoint
& pos
= wxDefaultPosition
,
801 const wxSize
& size
= wxDefaultSize
,
802 long style
= wxDEFAULT_FRAME_STYLE
,
803 const wxString
& name
= wxFrameNameStr
)
804 : wxDocChildFrameBase(doc
, view
,
805 parent
, id
, title
, pos
, size
, style
, name
)
809 bool Create(wxDocument
*doc
,
813 const wxString
& title
,
814 const wxPoint
& pos
= wxDefaultPosition
,
815 const wxSize
& size
= wxDefaultSize
,
816 long style
= wxDEFAULT_FRAME_STYLE
,
817 const wxString
& name
= wxFrameNameStr
)
819 return wxDocChildFrameBase
::Create
822 parent
, id
, title
, pos
, size
, style
, name
827 DECLARE_CLASS(wxDocChildFrame
)
828 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame
);
831 // ----------------------------------------------------------------------------
832 // wxDocParentFrame and related classes.
834 // As with wxDocChildFrame we define a template base class used by both normal
836 // ----------------------------------------------------------------------------
838 // Base class containing type-independent code of wxDocParentFrameAny
840 // Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
841 // derive from wxWindow.
842 class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
845 wxDocParentFrameAnyBase(wxWindow
* frame
)
851 wxDocManager
*GetDocumentManager() const { return m_docManager
; }
854 // This is similar to wxDocChildFrameAnyBase method with the same name:
855 // while we're not an event handler ourselves and so can't override
856 // TryBefore(), we provide a helper that the derived template class can use
857 // from its TryBefore() implementation.
858 bool TryProcessEvent(wxEvent
& event
);
860 wxWindow
* const m_frame
;
861 wxDocManager
*m_docManager
;
863 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase
);
866 // This is similar to wxDocChildFrameAny and is used to provide common
867 // implementation for both wxDocParentFrame and wxDocMDIParentFrame
868 template <class BaseFrame
>
869 class WXDLLIMPEXP_CORE wxDocParentFrameAny
: public BaseFrame
,
870 public wxDocParentFrameAnyBase
873 wxDocParentFrameAny() : wxDocParentFrameAnyBase(this) { }
874 wxDocParentFrameAny(wxDocManager
*manager
,
877 const wxString
& title
,
878 const wxPoint
& pos
= wxDefaultPosition
,
879 const wxSize
& size
= wxDefaultSize
,
880 long style
= wxDEFAULT_FRAME_STYLE
,
881 const wxString
& name
= wxFrameNameStr
)
882 : wxDocParentFrameAnyBase(this)
884 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
887 bool Create(wxDocManager
*manager
,
890 const wxString
& title
,
891 const wxPoint
& pos
= wxDefaultPosition
,
892 const wxSize
& size
= wxDefaultSize
,
893 long style
= wxDEFAULT_FRAME_STYLE
,
894 const wxString
& name
= wxFrameNameStr
)
896 m_docManager
= manager
;
898 if ( !BaseFrame
::Create(frame
, id
, title
, pos
, size
, style
, name
) )
901 this->Connect(wxID_EXIT
, wxEVT_MENU
,
902 wxCommandEventHandler(wxDocParentFrameAny
::OnExit
));
903 this->Connect(wxEVT_CLOSE_WINDOW
,
904 wxCloseEventHandler(wxDocParentFrameAny
::OnCloseWindow
));
910 // hook the document manager into event handling chain here
911 virtual bool TryBefore(wxEvent
& event
)
913 // It is important to send the event to the base class first as
914 // wxMDIParentFrame overrides its TryBefore() to send the menu events
915 // to the currently active child frame and the child must get them
916 // before our own TryProcessEvent() is executed, not afterwards.
917 return BaseFrame
::TryBefore(event
) || TryProcessEvent(event
);
921 void OnExit(wxCommandEvent
& WXUNUSED(event
))
926 void OnCloseWindow(wxCloseEvent
& event
)
928 if ( m_docManager
&& !m_docManager
->Clear(!event
.CanVeto()) )
930 // The user decided not to close finally, abort.
935 // Just skip the event, base class handler will destroy the window.
941 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny
);
944 typedef wxDocParentFrameAny
<wxFrame
> wxDocParentFrameBase
;
946 class WXDLLIMPEXP_CORE wxDocParentFrame
: public wxDocParentFrameBase
949 wxDocParentFrame() : wxDocParentFrameBase() { }
951 wxDocParentFrame(wxDocManager
*manager
,
954 const wxString
& title
,
955 const wxPoint
& pos
= wxDefaultPosition
,
956 const wxSize
& size
= wxDefaultSize
,
957 long style
= wxDEFAULT_FRAME_STYLE
,
958 const wxString
& name
= wxFrameNameStr
)
959 : wxDocParentFrameBase(manager
,
960 parent
, id
, title
, pos
, size
, style
, name
)
964 bool Create(wxDocManager
*manager
,
967 const wxString
& title
,
968 const wxPoint
& pos
= wxDefaultPosition
,
969 const wxSize
& size
= wxDefaultSize
,
970 long style
= wxDEFAULT_FRAME_STYLE
,
971 const wxString
& name
= wxFrameNameStr
)
973 return wxDocParentFrameBase
::Create(manager
,
975 pos
, size
, style
, name
);
979 DECLARE_CLASS(wxDocParentFrame
)
980 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame
);
984 // reenable warning 4275
985 #pragma warning (pop)
988 // ----------------------------------------------------------------------------
989 // Provide simple default printing facilities
990 // ----------------------------------------------------------------------------
992 #if wxUSE_PRINTING_ARCHITECTURE
993 class WXDLLIMPEXP_CORE wxDocPrintout
: public wxPrintout
996 wxDocPrintout(wxView
*view
= NULL
, const wxString
& title
= wxString());
998 // implement wxPrintout methods
999 virtual bool OnPrintPage(int page
);
1000 virtual bool HasPage(int page
);
1001 virtual bool OnBeginDocument(int startPage
, int endPage
);
1002 virtual void GetPageInfo(int *minPage
, int *maxPage
,
1003 int *selPageFrom
, int *selPageTo
);
1005 virtual wxView
*GetView() { return m_printoutView
; }
1008 wxView
* m_printoutView
;
1011 DECLARE_DYNAMIC_CLASS(wxDocPrintout
)
1012 wxDECLARE_NO_COPY_CLASS(wxDocPrintout
);
1014 #endif // wxUSE_PRINTING_ARCHITECTURE
1016 // For compatibility with existing file formats:
1017 // converts from/to a stream to/from a temporary file.
1018 #if wxUSE_STD_IOSTREAM
1019 bool WXDLLIMPEXP_CORE
1020 wxTransferFileToStream(const wxString
& filename
, wxSTD ostream
& stream
);
1021 bool WXDLLIMPEXP_CORE
1022 wxTransferStreamToFile(wxSTD istream
& stream
, const wxString
& filename
);
1024 bool WXDLLIMPEXP_CORE
1025 wxTransferFileToStream(const wxString
& filename
, wxOutputStream
& stream
);
1026 bool WXDLLIMPEXP_CORE
1027 wxTransferStreamToFile(wxInputStream
& stream
, const wxString
& filename
);
1028 #endif // wxUSE_STD_IOSTREAM
1031 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
1032 // case of existing user code using them for its own purposes
1033 #if WXWIN_COMPATIBILITY_2_8
1038 wxDEFAULT_DOCMAN_FLAGS
= wxDOC_SDI
1040 #endif // WXWIN_COMPATIBILITY_2_8
1042 #ifndef __VISUALC6__
1043 inline wxViewVector wxDocument
::GetViewsVector() const
1045 return m_documentViews
.AsVector
<wxView
*>();
1048 inline wxDocVector wxDocManager
::GetDocumentsVector() const
1050 return m_docs
.AsVector
<wxDocument
*>();
1053 inline wxDocTemplateVector wxDocManager
::GetTemplatesVector() const
1055 return m_templates
.AsVector
<wxDocTemplate
*>();
1057 #endif // !__VISUALC6__
1059 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
1061 #endif // _WX_DOCH__