allow 2 step creation of wxDocChildFrameAnyBase and derived classes
[wxWidgets.git] / include / wx / docview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/docview.h
3 // Purpose: Doc/View classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DOCH__
13 #define _WX_DOCH__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DOC_VIEW_ARCHITECTURE
18
19 #include "wx/list.h"
20 #include "wx/string.h"
21 #include "wx/frame.h"
22
23 #if wxUSE_PRINTING_ARCHITECTURE
24 #include "wx/print.h"
25 #endif
26
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;
36
37 class wxDocChildFrameAnyBase;
38
39 #if wxUSE_STD_IOSTREAM
40 #include "wx/iosfwrap.h"
41 #else
42 #include "wx/stream.h"
43 #endif
44
45 // Flags for wxDocManager (can be combined).
46 enum
47 {
48 wxDOC_NEW = 1,
49 wxDOC_SILENT = 2
50 };
51
52 // Document template flags
53 enum
54 {
55 wxTEMPLATE_VISIBLE = 1,
56 wxTEMPLATE_INVISIBLE = 2,
57 wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
58 };
59
60 #define wxMAX_FILE_HISTORY 9
61
62 class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler
63 {
64 public:
65 wxDocument(wxDocument *parent = NULL);
66 virtual ~wxDocument();
67
68 // accessors
69 void SetFilename(const wxString& filename, bool notifyViews = false);
70 wxString GetFilename() const { return m_documentFile; }
71
72 void SetTitle(const wxString& title) { m_documentTitle = title; }
73 wxString GetTitle() const { return m_documentTitle; }
74
75 void SetDocumentName(const wxString& name) { m_documentTypeName = name; }
76 wxString GetDocumentName() const { return m_documentTypeName; }
77
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; }
82
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(); }
87
88 virtual bool Close();
89 virtual bool Save();
90 virtual bool SaveAs();
91 virtual bool Revert();
92
93 #if wxUSE_STD_IOSTREAM
94 virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
95 virtual wxSTD istream& LoadObject(wxSTD istream& stream);
96 #else
97 virtual wxOutputStream& SaveObject(wxOutputStream& stream);
98 virtual wxInputStream& LoadObject(wxInputStream& stream);
99 #endif
100
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();
106
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();
111
112 // if you override, remember to call the default
113 // implementation (wxDocument::OnChangeFilename)
114 virtual void OnChangeFilename(bool notifyViews);
115
116 // Called by framework if created automatically by the default document
117 // manager: gives document a chance to initialise and (usually) create a
118 // view
119 virtual bool OnCreate(const wxString& path, long flags);
120
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; }
127
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();
131
132 virtual bool DeleteContents();
133
134 virtual bool Draw(wxDC&);
135 virtual bool IsModified() const { return m_documentModified; }
136 virtual void Modify(bool mod) { m_documentModified = mod; }
137
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;
143
144 virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL);
145 virtual void NotifyClosing();
146
147 // Remove all views (because we're closing the document)
148 virtual bool DeleteAllViews();
149
150 // Other stuff
151 virtual wxDocManager *GetDocumentManager() const;
152 virtual wxDocTemplate *GetDocumentTemplate() const
153 { return m_documentTemplate; }
154 virtual void SetDocumentTemplate(wxDocTemplate *temp)
155 { m_documentTemplate = temp; }
156
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;
161
162 #if WXWIN_COMPATIBILITY_2_8
163 // use GetUserReadableName() instead
164 wxDEPRECATED_BUT_USED_INTERNALLY(
165 virtual bool GetPrintableName(wxString& buf) const
166 );
167 #endif // WXWIN_COMPATIBILITY_2_8
168
169 // Returns a window that can be used as a parent for document-related
170 // dialogs. Override if necessary.
171 virtual wxWindow *GetDocumentWindow() const;
172
173 protected:
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;
182 bool m_savedYet;
183
184 // Called by OnSaveDocument and OnOpenDocument to implement standard
185 // Save/Load behavior. Re-implement in derived class for custom
186 // behavior.
187 virtual bool DoSaveDocument(const wxString& file);
188 virtual bool DoOpenDocument(const wxString& file);
189
190 // the default implementation of GetUserReadableName()
191 wxString DoGetUserReadableName() const;
192
193 private:
194 DECLARE_ABSTRACT_CLASS(wxDocument)
195 wxDECLARE_NO_COPY_CLASS(wxDocument);
196 };
197
198 class WXDLLIMPEXP_CORE wxView: public wxEvtHandler
199 {
200 public:
201 wxView();
202 virtual ~wxView();
203
204 wxDocument *GetDocument() const { return m_viewDocument; }
205 virtual void SetDocument(wxDocument *doc);
206
207 wxString GetViewName() const { return m_viewTypeName; }
208 void SetViewName(const wxString& name) { m_viewTypeName = name; }
209
210 wxWindow *GetFrame() const { return m_viewFrame ; }
211 void SetFrame(wxWindow *frame) { m_viewFrame = frame; }
212
213 virtual void OnActivateView(bool activate,
214 wxView *activeView,
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();
221
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))
225 { return true; }
226
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
229 // true.
230 virtual bool Close(bool deleteWindow = true);
231
232 // Override to do cleanup/veto close
233 virtual bool OnClose(bool deleteWindow);
234
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);
238
239 wxDocManager *GetDocumentManager() const
240 { return m_viewDocument->GetDocumentManager(); }
241
242 #if wxUSE_PRINTING_ARCHITECTURE
243 virtual wxPrintout *OnCreatePrintout();
244 #endif
245
246 // implementation only
247 // -------------------
248
249 // set the associated frame, it is used to reset its view when we're
250 // destroyed
251 void SetDocChildFrame(wxDocChildFrameAnyBase *docChildFrame);
252
253 protected:
254 // hook the document into event handlers chain here
255 virtual bool TryBefore(wxEvent& event);
256
257 wxDocument* m_viewDocument;
258 wxString m_viewTypeName;
259 wxWindow* m_viewFrame;
260
261 wxDocChildFrameAnyBase *m_docChildFrame;
262
263 private:
264 DECLARE_ABSTRACT_CLASS(wxView)
265 wxDECLARE_NO_COPY_CLASS(wxView);
266 };
267
268 // Represents user interface (and other) properties of documents and views
269 class WXDLLIMPEXP_CORE wxDocTemplate: public wxObject
270 {
271
272 friend class WXDLLIMPEXP_FWD_CORE wxDocManager;
273
274 public:
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,
280 const wxString& dir,
281 const wxString& ext,
282 const wxString& docTypeName,
283 const wxString& viewTypeName,
284 wxClassInfo *docClassInfo = NULL,
285 wxClassInfo *viewClassInfo = NULL,
286 long flags = wxDEFAULT_TEMPLATE_FLAGS);
287
288 virtual ~wxDocTemplate();
289
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);
295
296 // Helper method for CreateDocument; also allows you to do your own document
297 // creation
298 virtual bool InitDocument(wxDocument* doc,
299 const wxString& path,
300 long flags = 0);
301
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; }
312
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; }
318
319 bool IsVisible() const { return (m_flags & wxTEMPLATE_VISIBLE) != 0; }
320
321 wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; }
322 wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; }
323
324 virtual bool FileMatchesTemplate(const wxString& path);
325
326 protected:
327 long m_flags;
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;
335
336 // For dynamic creation of appropriate instances.
337 wxClassInfo* m_docClassInfo;
338 wxClassInfo* m_viewClassInfo;
339
340 // Called by CreateDocument and CreateView to create the actual
341 // document/view object.
342 //
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();
347
348 private:
349 DECLARE_CLASS(wxDocTemplate)
350 wxDECLARE_NO_COPY_CLASS(wxDocTemplate);
351 };
352
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
356 {
357 public:
358 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
359 wxDocManager(long flags = 0, bool initialize = true);
360 virtual ~wxDocManager();
361
362 virtual bool Initialize();
363
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);
376
377 // Handlers for UI update commands
378 void OnUpdateFileOpen(wxUpdateUIEvent& event);
379 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event);
380 void OnUpdateFileNew(wxUpdateUIEvent& event);
381 void OnUpdateFileSave(wxUpdateUIEvent& event);
382 void OnUpdateUndo(wxUpdateUIEvent& event);
383 void OnUpdateRedo(wxUpdateUIEvent& event);
384
385 // called when file format detection didn't work, can be overridden to do
386 // something in this case
387 virtual void OnOpenFileFailure() { }
388
389 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
390
391 // wrapper around CreateDocument() with a more clear name
392 wxDocument *CreateNewDocument()
393 { return CreateDocument(wxString(), wxDOC_NEW); }
394
395 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
396 virtual void DeleteTemplate(wxDocTemplate *temp, long flags = 0);
397 virtual bool FlushDoc(wxDocument *doc);
398 virtual wxDocTemplate *MatchTemplate(const wxString& path);
399 virtual wxDocTemplate *SelectDocumentPath(wxDocTemplate **templates,
400 int noTemplates, wxString& path, long flags, bool save = false);
401 virtual wxDocTemplate *SelectDocumentType(wxDocTemplate **templates,
402 int noTemplates, bool sort = false);
403 virtual wxDocTemplate *SelectViewType(wxDocTemplate **templates,
404 int noTemplates, bool sort = false);
405 virtual wxDocTemplate *FindTemplateForPath(const wxString& path);
406
407 void AssociateTemplate(wxDocTemplate *temp);
408 void DisassociateTemplate(wxDocTemplate *temp);
409
410 wxDocument *GetCurrentDocument() const;
411
412 void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
413 int GetMaxDocsOpen() const { return m_maxDocsOpen; }
414
415 // Add and remove a document from the manager's list
416 void AddDocument(wxDocument *doc);
417 void RemoveDocument(wxDocument *doc);
418
419 // closes all currently open documents
420 bool CloseDocuments(bool force = true);
421
422 // closes the specified document
423 bool CloseDocument(wxDocument* doc, bool force = false);
424
425 // Clear remaining documents and templates
426 bool Clear(bool force = true);
427
428 // Views or windows should inform the document manager
429 // when a view is going in or out of focus
430 virtual void ActivateView(wxView *view, bool activate = true);
431 virtual wxView *GetCurrentView() const { return m_currentView; }
432
433 wxList& GetDocuments() { return m_docs; }
434 wxList& GetTemplates() { return m_templates; }
435
436 // Return the default name for a new document (by default returns strings
437 // in the form "unnamed <counter>" but can be overridden)
438 virtual wxString MakeNewDocumentName();
439
440 // Make a frame title (override this to do something different)
441 virtual wxString MakeFrameTitle(wxDocument* doc);
442
443 virtual wxFileHistory *OnCreateFileHistory();
444 virtual wxFileHistory *GetFileHistory() const { return m_fileHistory; }
445
446 // File history management
447 virtual void AddFileToHistory(const wxString& file);
448 virtual void RemoveFileFromHistory(size_t i);
449 virtual size_t GetHistoryFilesCount() const;
450 virtual wxString GetHistoryFile(size_t i) const;
451 virtual void FileHistoryUseMenu(wxMenu *menu);
452 virtual void FileHistoryRemoveMenu(wxMenu *menu);
453 #if wxUSE_CONFIG
454 virtual void FileHistoryLoad(const wxConfigBase& config);
455 virtual void FileHistorySave(wxConfigBase& config);
456 #endif // wxUSE_CONFIG
457
458 virtual void FileHistoryAddFilesToMenu();
459 virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
460
461 wxString GetLastDirectory() const;
462 void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
463
464 // Get the current document manager
465 static wxDocManager* GetDocumentManager() { return sm_docManager; }
466
467 #if WXWIN_COMPATIBILITY_2_8
468 // deprecated, override GetDefaultName() instead
469 wxDEPRECATED_BUT_USED_INTERNALLY(
470 virtual bool MakeDefaultName(wxString& buf)
471 );
472 #endif
473
474 #if WXWIN_COMPATIBILITY_2_6
475 // deprecated, use GetHistoryFilesCount() instead
476 wxDEPRECATED( size_t GetNoHistoryFiles() const );
477 #endif // WXWIN_COMPATIBILITY_2_6
478
479 protected:
480 // hook the currently active view into event handlers chain here
481 virtual bool TryBefore(wxEvent& event);
482
483 // return the command processor for the current document, if any
484 wxCommandProcessor *GetCurrentCommandProcessor() const;
485
486 // this method tries to find an active view harder than GetCurrentView():
487 // if the latter is NULL, it also checks if we don't have just a single
488 // view and returns it then
489 wxView *GetActiveView() const;
490
491
492 int m_defaultDocumentNameCounter;
493 int m_maxDocsOpen;
494 wxList m_docs;
495 wxList m_templates;
496 wxView* m_currentView;
497 wxFileHistory* m_fileHistory;
498 wxString m_lastDirectory;
499 static wxDocManager* sm_docManager;
500
501 DECLARE_EVENT_TABLE()
502 DECLARE_DYNAMIC_CLASS(wxDocManager)
503 wxDECLARE_NO_COPY_CLASS(wxDocManager);
504 };
505
506 #if WXWIN_COMPATIBILITY_2_6
507 inline size_t wxDocManager::GetNoHistoryFiles() const
508 {
509 return GetHistoryFilesCount();
510 }
511 #endif // WXWIN_COMPATIBILITY_2_6
512
513 // ----------------------------------------------------------------------------
514 // Base class for child frames -- this is what wxView renders itself into
515 //
516 // Notice that this is a mix-in class so it doesn't derive from wxWindow, only
517 // wxDocChildFrameAny does
518 // ----------------------------------------------------------------------------
519
520 class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
521 {
522 public:
523 // default ctor, use Create() after it
524 wxDocChildFrameAnyBase() { m_win = NULL; }
525
526 // full ctor equivalent to using the default one and Create(0
527 wxDocChildFrameAnyBase(wxDocument *doc, wxView *view, wxWindow *win)
528 {
529 Create(doc, view, win);
530 }
531
532 // method which must be called for an object created using the default ctor
533 //
534 // note that it returns bool just for consistency with Create() methods in
535 // other classes, we never return false from here
536 bool Create(wxDocument *doc, wxView *view, wxWindow *win)
537 {
538 m_childDocument = doc;
539 m_childView = view;
540 m_win = win;
541
542 if ( view )
543 view->SetDocChildFrame(this);
544
545 return true;
546 }
547
548 // dtor doesn't need to be virtual, an object should never be destroyed via
549 // a pointer to this class
550 ~wxDocChildFrameAnyBase()
551 {
552 // prevent the view from deleting us if we're being deleted directly
553 // (and not via Close() + Destroy())
554 if ( m_childView )
555 m_childView->SetDocChildFrame(NULL);
556 }
557
558 wxDocument *GetDocument() const { return m_childDocument; }
559 wxView *GetView() const { return m_childView; }
560 void SetDocument(wxDocument *doc) { m_childDocument = doc; }
561 void SetView(wxView *view) { m_childView = view; }
562
563 wxWindow *GetWindow() const { return m_win; }
564
565 protected:
566 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
567 // which is called from TryBefore() of the derived classes to give our view
568 // a chance to process the message before the frame event handlers are used
569 bool TryProcessEvent(wxEvent& event)
570 {
571 return m_childView && m_childView->ProcessEventHere(event);
572 }
573
574 // called from EVT_CLOSE handler in the frame: check if we can close and do
575 // cleanup if so; veto the event otherwise
576 bool CloseView(wxCloseEvent& event);
577
578
579 wxDocument* m_childDocument;
580 wxView* m_childView;
581
582 // the associated window: having it here is not terribly elegant but it
583 // allows us to avoid having any virtual functions in this class
584 wxWindow* m_win;
585
586
587 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase);
588 };
589
590 // ----------------------------------------------------------------------------
591 // Template implementing child frame concept using the given wxFrame-like class
592 //
593 // This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
594 // a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
595 // derived class as long as it provided a ctor with the same signature as
596 // wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
597 // wxMDIParentFrame.
598 // ----------------------------------------------------------------------------
599
600 template <class ChildFrame, class ParentFrame>
601 class WXDLLIMPEXP_CORE wxDocChildFrameAny : public ChildFrame,
602 public wxDocChildFrameAnyBase
603 {
604 public:
605 typedef ChildFrame BaseClass;
606
607 // default ctor, use Create after it
608 wxDocChildFrameAny() { }
609
610 // ctor for a frame showing the given view of the specified document
611 wxDocChildFrameAny(wxDocument *doc,
612 wxView *view,
613 ParentFrame *parent,
614 wxWindowID id,
615 const wxString& title,
616 const wxPoint& pos = wxDefaultPosition,
617 const wxSize& size = wxDefaultSize,
618 long style = wxDEFAULT_FRAME_STYLE,
619 const wxString& name = wxFrameNameStr)
620 {
621 Create(doc, view, parent, id, title, pos, size, style, name);
622 }
623
624 bool Create(wxDocument *doc,
625 wxView *view,
626 ParentFrame *parent,
627 wxWindowID id,
628 const wxString& title,
629 const wxPoint& pos = wxDefaultPosition,
630 const wxSize& size = wxDefaultSize,
631 long style = wxDEFAULT_FRAME_STYLE,
632 const wxString& name = wxFrameNameStr)
633 {
634 if ( !BaseClass::Create(parent, id, title, pos, size, style, name) )
635 return false;
636
637 if ( !wxDocChildFrameAnyBase::Create(doc, view, this) )
638 return false;
639
640 this->Connect(wxEVT_ACTIVATE,
641 wxActivateEventHandler(wxDocChildFrameAny::OnActivate));
642 this->Connect(wxEVT_CLOSE_WINDOW,
643 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow));
644
645 return true;
646 }
647
648 virtual bool Destroy()
649 {
650 // FIXME: why exactly do we do this? to avoid activation events during
651 // destructions maybe?
652 m_childView = NULL;
653 return BaseClass::Destroy();
654 }
655
656 protected:
657 // hook the child view into event handlers chain here
658 virtual bool TryBefore(wxEvent& event)
659 {
660 return TryProcessEvent(event) || BaseClass::TryBefore(event);
661 }
662
663 private:
664 void OnActivate(wxActivateEvent& event)
665 {
666 BaseClass::OnActivate(event);
667
668 if ( m_childView )
669 m_childView->Activate(event.GetActive());
670 }
671
672 void OnCloseWindow(wxCloseEvent& event)
673 {
674 if ( CloseView(event) )
675 Destroy();
676 //else: vetoed
677 }
678
679 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny,
680 ChildFrame, ParentFrame);
681 };
682
683 // ----------------------------------------------------------------------------
684 // A default child frame: we need to define it as a class just for wxRTTI,
685 // otherwise we could simply typedef it
686 // ----------------------------------------------------------------------------
687
688 #ifdef __VISUALC6__
689 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
690 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
691 // template will be DLL-exported but only once it is used as base class
692 // here!
693 #pragma warning (disable:4275)
694 #endif
695
696 typedef wxDocChildFrameAny<wxFrame, wxFrame> wxDocChildFrameBase;
697
698 class WXDLLIMPEXP_CORE wxDocChildFrame : public wxDocChildFrameBase
699 {
700 public:
701 wxDocChildFrame()
702 {
703 }
704
705 wxDocChildFrame(wxDocument *doc,
706 wxView *view,
707 wxFrame *parent,
708 wxWindowID id,
709 const wxString& title,
710 const wxPoint& pos = wxDefaultPosition,
711 const wxSize& size = wxDefaultSize,
712 long style = wxDEFAULT_FRAME_STYLE,
713 const wxString& name = wxFrameNameStr)
714 : wxDocChildFrameBase(doc, view,
715 parent, id, title, pos, size, style, name)
716 {
717 }
718
719 bool Create(wxDocument *doc,
720 wxView *view,
721 wxFrame *parent,
722 wxWindowID id,
723 const wxString& title,
724 const wxPoint& pos = wxDefaultPosition,
725 const wxSize& size = wxDefaultSize,
726 long style = wxDEFAULT_FRAME_STYLE,
727 const wxString& name = wxFrameNameStr)
728 {
729 return wxDocChildFrameBase::Create
730 (
731 doc, view,
732 parent, id, title, pos, size, style, name
733 );
734 }
735
736 private:
737 DECLARE_CLASS(wxDocChildFrame)
738 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame);
739 };
740
741 #ifdef __VISUALC6__
742 #pragma warning (default:4275)
743 #endif
744
745 // ----------------------------------------------------------------------------
746 // A default parent frame
747 // ----------------------------------------------------------------------------
748
749 class WXDLLIMPEXP_CORE wxDocParentFrame : public wxFrame
750 {
751 public:
752 wxDocParentFrame();
753 wxDocParentFrame(wxDocManager *manager,
754 wxFrame *frame,
755 wxWindowID id,
756 const wxString& title,
757 const wxPoint& pos = wxDefaultPosition,
758 const wxSize& size = wxDefaultSize,
759 long style = wxDEFAULT_FRAME_STYLE,
760 const wxString& name = wxFrameNameStr);
761
762 bool Create(wxDocManager *manager,
763 wxFrame *frame,
764 wxWindowID id,
765 const wxString& title,
766 const wxPoint& pos = wxDefaultPosition,
767 const wxSize& size = wxDefaultSize,
768 long style = wxDEFAULT_FRAME_STYLE,
769 const wxString& name = wxFrameNameStr);
770
771 wxDocManager *GetDocumentManager() const { return m_docManager; }
772
773 void OnExit(wxCommandEvent& event);
774 void OnMRUFile(wxCommandEvent& event);
775 void OnCloseWindow(wxCloseEvent& event);
776
777 protected:
778 // hook the document manager into event handling chain here
779 virtual bool TryBefore(wxEvent& event);
780
781 wxDocManager *m_docManager;
782
783 private:
784 typedef wxFrame base_type;
785 DECLARE_CLASS(wxDocParentFrame)
786 DECLARE_EVENT_TABLE()
787 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame);
788 };
789
790 // ----------------------------------------------------------------------------
791 // Provide simple default printing facilities
792 // ----------------------------------------------------------------------------
793
794 #if wxUSE_PRINTING_ARCHITECTURE
795 class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
796 {
797 public:
798 wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout"));
799
800 // implement wxPrintout methods
801 virtual bool OnPrintPage(int page);
802 virtual bool HasPage(int page);
803 virtual bool OnBeginDocument(int startPage, int endPage);
804 virtual void GetPageInfo(int *minPage, int *maxPage,
805 int *selPageFrom, int *selPageTo);
806
807 virtual wxView *GetView() { return m_printoutView; }
808
809 protected:
810 wxView* m_printoutView;
811
812 private:
813 DECLARE_DYNAMIC_CLASS(wxDocPrintout)
814 wxDECLARE_NO_COPY_CLASS(wxDocPrintout);
815 };
816 #endif // wxUSE_PRINTING_ARCHITECTURE
817
818 // ----------------------------------------------------------------------------
819 // File history management
820 // ----------------------------------------------------------------------------
821
822 class WXDLLIMPEXP_CORE wxFileHistory : public wxObject
823 {
824 public:
825 wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
826
827 // Operations
828 virtual void AddFileToHistory(const wxString& file);
829 virtual void RemoveFileFromHistory(size_t i);
830 virtual int GetMaxFiles() const { return (int)m_fileMaxFiles; }
831 virtual void UseMenu(wxMenu *menu);
832
833 // Remove menu from the list (MDI child may be closing)
834 virtual void RemoveMenu(wxMenu *menu);
835
836 #if wxUSE_CONFIG
837 virtual void Load(const wxConfigBase& config);
838 virtual void Save(wxConfigBase& config);
839 #endif // wxUSE_CONFIG
840
841 virtual void AddFilesToMenu();
842 virtual void AddFilesToMenu(wxMenu* menu); // Single menu
843
844 // Accessors
845 virtual wxString GetHistoryFile(size_t i) const { return m_fileHistory[i]; }
846 virtual size_t GetCount() const { return m_fileHistory.GetCount(); }
847
848 const wxList& GetMenus() const { return m_fileMenus; }
849
850 // Set/get base id
851 void SetBaseId(wxWindowID baseId) { m_idBase = baseId; }
852 wxWindowID GetBaseId() const { return m_idBase; }
853
854 #if WXWIN_COMPATIBILITY_2_6
855 // deprecated, use GetCount() instead
856 wxDEPRECATED( size_t GetNoHistoryFiles() const );
857 #endif // WXWIN_COMPATIBILITY_2_6
858
859 protected:
860 // Last n files
861 wxArrayString m_fileHistory;
862
863 // Menus to maintain (may need several for an MDI app)
864 wxList m_fileMenus;
865
866 // Max files to maintain
867 size_t m_fileMaxFiles;
868
869 private:
870 // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
871 wxWindowID m_idBase;
872
873 DECLARE_DYNAMIC_CLASS(wxFileHistory)
874 wxDECLARE_NO_COPY_CLASS(wxFileHistory);
875 };
876
877 #if WXWIN_COMPATIBILITY_2_6
878 inline size_t wxFileHistory::GetNoHistoryFiles() const
879 {
880 return m_fileHistory.GetCount();
881 }
882 #endif // WXWIN_COMPATIBILITY_2_6
883
884 // For compatibility with existing file formats:
885 // converts from/to a stream to/from a temporary file.
886 #if wxUSE_STD_IOSTREAM
887 bool WXDLLIMPEXP_CORE
888 wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
889 bool WXDLLIMPEXP_CORE
890 wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
891 #else
892 bool WXDLLIMPEXP_CORE
893 wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
894 bool WXDLLIMPEXP_CORE
895 wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
896 #endif // wxUSE_STD_IOSTREAM
897
898
899 // these flags are not used anywhere by wxWidgets and kept only for an unlikely
900 // case of existing user code using them for its own purposes
901 #ifdef WXWIN_COMPATIBILITY_2_8
902 enum
903 {
904 wxDOC_SDI = 1,
905 wxDOC_MDI,
906 wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
907 };
908 #endif // WXWIN_COMPATIBILITY_2_8
909
910 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
911
912 #endif // _WX_DOCH__