]> git.saurik.com Git - wxWidgets.git/blame - include/wx/docview.h
Add lambda-friendly wxDialog::ShowWindowModalThenDo().
[wxWidgets.git] / include / wx / docview.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
ca3e85cf 2// Name: wx/docview.h
c801d85f
KB
3// Purpose: Doc/View classes
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
99d80019 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_DOCH__
12#define _WX_DOCH__
c801d85f 13
c801d85f 14#include "wx/defs.h"
e30285ab
VZ
15
16#if wxUSE_DOC_VIEW_ARCHITECTURE
17
c801d85f 18#include "wx/list.h"
4db97e24 19#include "wx/dlist.h"
c801d85f 20#include "wx/string.h"
2f7adba0 21#include "wx/frame.h"
a0219e45 22#include "wx/filehistory.h"
288de46c 23#include "wx/vector.h"
c801d85f 24
47d67540 25#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 26 #include "wx/print.h"
c801d85f
KB
27#endif
28
b5dbe15d
VS
29class WXDLLIMPEXP_FWD_CORE wxWindow;
30class WXDLLIMPEXP_FWD_CORE wxDocument;
31class WXDLLIMPEXP_FWD_CORE wxView;
32class WXDLLIMPEXP_FWD_CORE wxDocTemplate;
33class WXDLLIMPEXP_FWD_CORE wxDocManager;
34class WXDLLIMPEXP_FWD_CORE wxPrintInfo;
35class WXDLLIMPEXP_FWD_CORE wxCommandProcessor;
4f7d425f 36class WXDLLIMPEXP_FWD_BASE wxConfigBase;
c801d85f 37
a9e2e6e5
VZ
38class wxDocChildFrameAnyBase;
39
a533f5c1 40#if wxUSE_STD_IOSTREAM
65f19af1 41 #include "wx/iosfwrap.h"
a533f5c1
RR
42#else
43 #include "wx/stream.h"
44#endif
c801d85f 45
c77049a0 46// Flags for wxDocManager (can be combined).
caf0debf
VZ
47enum
48{
c77049a0
VZ
49 wxDOC_NEW = 1,
50 wxDOC_SILENT = 2
caf0debf 51};
c801d85f
KB
52
53// Document template flags
caf0debf
VZ
54enum
55{
56 wxTEMPLATE_VISIBLE = 1,
89d94e04 57 wxTEMPLATE_INVISIBLE = 2,
caf0debf
VZ
58 wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
59};
c801d85f 60
caf0debf 61#define wxMAX_FILE_HISTORY 9
c801d85f 62
93d0805b
VZ
63typedef wxVector<wxDocument*> wxDocVector;
64typedef wxVector<wxView*> wxViewVector;
65typedef wxVector<wxDocTemplate*> wxDocTemplateVector;
93d0805b 66
53a2db12 67class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler
c801d85f 68{
caf0debf 69public:
c77049a0 70 wxDocument(wxDocument *parent = NULL);
d3c7fc99 71 virtual ~wxDocument();
caf0debf
VZ
72
73 // accessors
68379eaf 74 void SetFilename(const wxString& filename, bool notifyViews = false);
caf0debf
VZ
75 wxString GetFilename() const { return m_documentFile; }
76
47b378bd 77 void SetTitle(const wxString& title) { m_documentTitle = title; }
caf0debf
VZ
78 wxString GetTitle() const { return m_documentTitle; }
79
47b378bd 80 void SetDocumentName(const wxString& name) { m_documentTypeName = name; }
caf0debf
VZ
81 wxString GetDocumentName() const { return m_documentTypeName; }
82
d7b3a73d
VZ
83 // access the flag indicating whether this document had been already saved,
84 // SetDocumentSaved() is only used internally, don't call it
caf0debf 85 bool GetDocumentSaved() const { return m_savedYet; }
68379eaf 86 void SetDocumentSaved(bool saved = true) { m_savedYet = saved; }
caf0debf 87
beba4fa6
VZ
88 // activate the first view of the document if any
89 void Activate();
90
de56f240
VZ
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(); }
95
caf0debf
VZ
96 virtual bool Close();
97 virtual bool Save();
98 virtual bool SaveAs();
99 virtual bool Revert();
100
a533f5c1 101#if wxUSE_STD_IOSTREAM
dd107c50
VZ
102 virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
103 virtual wxSTD istream& LoadObject(wxSTD istream& stream);
a533f5c1 104#else
23a54e14
RR
105 virtual wxOutputStream& SaveObject(wxOutputStream& stream);
106 virtual wxInputStream& LoadObject(wxInputStream& stream);
a533f5c1 107#endif
caf0debf 108
77ffb593 109 // Called by wxWidgets
caf0debf
VZ
110 virtual bool OnSaveDocument(const wxString& filename);
111 virtual bool OnOpenDocument(const wxString& filename);
112 virtual bool OnNewDocument();
113 virtual bool OnCloseDocument();
114
68379eaf 115 // Prompts for saving if about to close a modified document. Returns true
caf0debf 116 // if ok to close the document (may have saved in the meantime, or set
68379eaf 117 // modified to false)
caf0debf
VZ
118 virtual bool OnSaveModified();
119
8cc208e3 120 // if you override, remember to call the default
00e3ea1c
FM
121 // implementation (wxDocument::OnChangeFilename)
122 virtual void OnChangeFilename(bool notifyViews);
123
caf0debf
VZ
124 // Called by framework if created automatically by the default document
125 // manager: gives document a chance to initialise and (usually) create a
126 // view
127 virtual bool OnCreate(const wxString& path, long flags);
128
129 // By default, creates a base wxCommandProcessor.
130 virtual wxCommandProcessor *OnCreateCommandProcessor();
89d94e04
VZ
131 virtual wxCommandProcessor *GetCommandProcessor() const
132 { return m_commandProcessor; }
133 virtual void SetCommandProcessor(wxCommandProcessor *proc)
134 { m_commandProcessor = proc; }
caf0debf
VZ
135
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();
139
29548835
VZ
140 // Called from OnCloseDocument(), does nothing by default but may be
141 // overridden. Return value is ignored.
caf0debf
VZ
142 virtual bool DeleteContents();
143
144 virtual bool Draw(wxDC&);
145 virtual bool IsModified() const { return m_documentModified; }
250ab35a 146 virtual void Modify(bool mod);
caf0debf
VZ
147
148 virtual bool AddView(wxView *view);
149 virtual bool RemoveView(wxView *view);
93d0805b
VZ
150
151#ifndef __VISUALC6__
8f2a8df4 152 wxViewVector GetViewsVector() const;
288de46c
VZ
153#endif // !__VISUALC6__
154
b80388aa
VZ
155 wxList& GetViews() { return m_documentViews; }
156 const wxList& GetViews() const { return m_documentViews; }
93d0805b 157
caf0debf
VZ
158 wxView *GetFirstView() const;
159
c77049a0 160 virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL);
b23e843b 161 virtual void NotifyClosing();
caf0debf
VZ
162
163 // Remove all views (because we're closing the document)
164 virtual bool DeleteAllViews();
165
166 // Other stuff
167 virtual wxDocManager *GetDocumentManager() const;
89d94e04
VZ
168 virtual wxDocTemplate *GetDocumentTemplate() const
169 { return m_documentTemplate; }
170 virtual void SetDocumentTemplate(wxDocTemplate *temp)
171 { m_documentTemplate = temp; }
caf0debf 172
724b119a
VZ
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;
177
178#if WXWIN_COMPATIBILITY_2_8
179 // use GetUserReadableName() instead
180 wxDEPRECATED_BUT_USED_INTERNALLY(
181 virtual bool GetPrintableName(wxString& buf) const
182 );
183#endif // WXWIN_COMPATIBILITY_2_8
caf0debf
VZ
184
185 // Returns a window that can be used as a parent for document-related
186 // dialogs. Override if necessary.
187 virtual wxWindow *GetDocumentWindow() const;
188
4db97e24
VZ
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; }
192
caf0debf
VZ
193protected:
194 wxList m_documentViews;
195 wxString m_documentFile;
196 wxString m_documentTitle;
197 wxString m_documentTypeName;
198 wxDocTemplate* m_documentTemplate;
199 bool m_documentModified;
4db97e24
VZ
200
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
caf0debf 204 wxDocument* m_documentParent;
4db97e24 205
caf0debf
VZ
206 wxCommandProcessor* m_commandProcessor;
207 bool m_savedYet;
b5f159ac 208
69936aea 209 // Called by OnSaveDocument and OnOpenDocument to implement standard
4c51a665
DS
210 // Save/Load behaviour. Re-implement in derived class for custom
211 // behaviour.
69936aea
VZ
212 virtual bool DoSaveDocument(const wxString& file);
213 virtual bool DoOpenDocument(const wxString& file);
214
724b119a
VZ
215 // the default implementation of GetUserReadableName()
216 wxString DoGetUserReadableName() const;
217
2b5f62a0 218private:
4db97e24
VZ
219 // list of all documents whose m_documentParent is this one
220 typedef wxDList<wxDocument> DocsList;
221 DocsList m_childDocuments;
222
2b5f62a0 223 DECLARE_ABSTRACT_CLASS(wxDocument)
c0c133e1 224 wxDECLARE_NO_COPY_CLASS(wxDocument);
c801d85f
KB
225};
226
53a2db12 227class WXDLLIMPEXP_CORE wxView: public wxEvtHandler
c801d85f 228{
caf0debf 229public:
caf0debf 230 wxView();
d3c7fc99 231 virtual ~wxView();
c801d85f 232
caf0debf 233 wxDocument *GetDocument() const { return m_viewDocument; }
bb28b477 234 virtual void SetDocument(wxDocument *doc);
c801d85f 235
caf0debf 236 wxString GetViewName() const { return m_viewTypeName; }
47b378bd 237 void SetViewName(const wxString& name) { m_viewTypeName = name; }
c801d85f 238
b9f933ab
JS
239 wxWindow *GetFrame() const { return m_viewFrame ; }
240 void SetFrame(wxWindow *frame) { m_viewFrame = frame; }
c801d85f 241
89d94e04
VZ
242 virtual void OnActivateView(bool activate,
243 wxView *activeView,
244 wxView *deactiveView);
caf0debf
VZ
245 virtual void OnDraw(wxDC *dc) = 0;
246 virtual void OnPrint(wxDC *dc, wxObject *info);
c77049a0 247 virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
6fb99eb3 248 virtual void OnClosingDocument() {}
caf0debf 249 virtual void OnChangeFilename();
c801d85f 250
caf0debf
VZ
251 // Called by framework if created automatically by the default document
252 // manager class: gives view a chance to initialise
c77049a0
VZ
253 virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags))
254 { return true; }
c801d85f 255
caf0debf
VZ
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
68379eaf
WS
258 // true.
259 virtual bool Close(bool deleteWindow = true);
caf0debf
VZ
260
261 // Override to do cleanup/veto close
262 virtual bool OnClose(bool deleteWindow);
2b854a32 263
caf0debf
VZ
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);
c801d85f 267
caf0debf
VZ
268 wxDocManager *GetDocumentManager() const
269 { return m_viewDocument->GetDocumentManager(); }
c801d85f 270
47d67540 271#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 272 virtual wxPrintout *OnCreatePrintout();
c801d85f
KB
273#endif
274
a9e2e6e5
VZ
275 // implementation only
276 // -------------------
277
278 // set the associated frame, it is used to reset its view when we're
279 // destroyed
ada1ff0d 280 void SetDocChildFrame(wxDocChildFrameAnyBase *docChildFrame);
a9e2e6e5 281
caf0debf 282protected:
bba5e72a 283 // hook the document into event handlers chain here
8cc208e3 284 virtual bool TryBefore(wxEvent& event);
bba5e72a 285
caf0debf
VZ
286 wxDocument* m_viewDocument;
287 wxString m_viewTypeName;
b9f933ab 288 wxWindow* m_viewFrame;
22f3361e 289
a9e2e6e5
VZ
290 wxDocChildFrameAnyBase *m_docChildFrame;
291
2b5f62a0
VZ
292private:
293 DECLARE_ABSTRACT_CLASS(wxView)
c0c133e1 294 wxDECLARE_NO_COPY_CLASS(wxView);
c801d85f
KB
295};
296
297// Represents user interface (and other) properties of documents and views
53a2db12 298class WXDLLIMPEXP_CORE wxDocTemplate: public wxObject
c801d85f 299{
caf0debf 300
b5dbe15d 301friend class WXDLLIMPEXP_FWD_CORE wxDocManager;
caf0debf
VZ
302
303public:
304 // Associate document and view types. They're for identifying what view is
305 // associated with what template/document type
306 wxDocTemplate(wxDocManager *manager,
307 const wxString& descr,
308 const wxString& filter,
309 const wxString& dir,
310 const wxString& ext,
311 const wxString& docTypeName,
312 const wxString& viewTypeName,
c77049a0
VZ
313 wxClassInfo *docClassInfo = NULL,
314 wxClassInfo *viewClassInfo = NULL,
caf0debf
VZ
315 long flags = wxDEFAULT_TEMPLATE_FLAGS);
316
d3c7fc99 317 virtual ~wxDocTemplate();
caf0debf
VZ
318
319 // By default, these two member functions dynamically creates document and
320 // view using dynamic instance construction. Override these if you need a
321 // different method of construction.
322 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
323 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
324
217b7140
JS
325 // Helper method for CreateDocument; also allows you to do your own document
326 // creation
89d94e04
VZ
327 virtual bool InitDocument(wxDocument* doc,
328 const wxString& path,
329 long flags = 0);
217b7140 330
47b378bd 331 wxString GetDefaultExtension() const { return m_defaultExt; }
caf0debf 332 wxString GetDescription() const { return m_description; }
47b378bd 333 wxString GetDirectory() const { return m_directory; }
caf0debf 334 wxDocManager *GetDocumentManager() const { return m_documentManager; }
89d94e04
VZ
335 void SetDocumentManager(wxDocManager *manager)
336 { m_documentManager = manager; }
47b378bd
VS
337 wxString GetFileFilter() const { return m_fileFilter; }
338 long GetFlags() const { return m_flags; }
caf0debf
VZ
339 virtual wxString GetViewName() const { return m_viewTypeName; }
340 virtual wxString GetDocumentName() const { return m_docTypeName; }
341
47b378bd
VS
342 void SetFileFilter(const wxString& filter) { m_fileFilter = filter; }
343 void SetDirectory(const wxString& dir) { m_directory = dir; }
344 void SetDescription(const wxString& descr) { m_description = descr; }
345 void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; }
346 void SetFlags(long flags) { m_flags = flags; }
caf0debf 347
89d94e04 348 bool IsVisible() const { return (m_flags & wxTEMPLATE_VISIBLE) != 0; }
caf0debf 349
04129514
JS
350 wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; }
351 wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; }
352
caf0debf
VZ
353 virtual bool FileMatchesTemplate(const wxString& path);
354
355protected:
356 long m_flags;
357 wxString m_fileFilter;
358 wxString m_directory;
359 wxString m_description;
360 wxString m_defaultExt;
361 wxString m_docTypeName;
362 wxString m_viewTypeName;
363 wxDocManager* m_documentManager;
364
365 // For dynamic creation of appropriate instances.
366 wxClassInfo* m_docClassInfo;
367 wxClassInfo* m_viewClassInfo;
b5f159ac 368
89d94e04
VZ
369 // Called by CreateDocument and CreateView to create the actual
370 // document/view object.
371 //
372 // By default uses the ClassInfo provided to the constructor. Override
373 // these functions to provide a different method of creation.
69936aea
VZ
374 virtual wxDocument *DoCreateDocument();
375 virtual wxView *DoCreateView();
376
2b5f62a0
VZ
377private:
378 DECLARE_CLASS(wxDocTemplate)
c0c133e1 379 wxDECLARE_NO_COPY_CLASS(wxDocTemplate);
c801d85f
KB
380};
381
caf0debf
VZ
382// One object of this class may be created in an application, to manage all
383// the templates and documents.
53a2db12 384class WXDLLIMPEXP_CORE wxDocManager: public wxEvtHandler
c801d85f 385{
caf0debf 386public:
c77049a0
VZ
387 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
388 wxDocManager(long flags = 0, bool initialize = true);
d3c7fc99 389 virtual ~wxDocManager();
caf0debf
VZ
390
391 virtual bool Initialize();
392
393 // Handlers for common user commands
394 void OnFileClose(wxCommandEvent& event);
33a20136 395 void OnFileCloseAll(wxCommandEvent& event);
caf0debf
VZ
396 void OnFileNew(wxCommandEvent& event);
397 void OnFileOpen(wxCommandEvent& event);
398 void OnFileRevert(wxCommandEvent& event);
399 void OnFileSave(wxCommandEvent& event);
400 void OnFileSaveAs(wxCommandEvent& event);
c70da1a2 401 void OnMRUFile(wxCommandEvent& event);
b99017ce 402#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 403 void OnPrint(wxCommandEvent& event);
caf0debf 404 void OnPreview(wxCommandEvent& event);
b99017ce
VZ
405 void OnPageSetup(wxCommandEvent& event);
406#endif // wxUSE_PRINTING_ARCHITECTURE
caf0debf
VZ
407 void OnUndo(wxCommandEvent& event);
408 void OnRedo(wxCommandEvent& event);
409
f2506310
JS
410 // Handlers for UI update commands
411 void OnUpdateFileOpen(wxUpdateUIEvent& event);
c77049a0 412 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event);
4311588b 413 void OnUpdateFileRevert(wxUpdateUIEvent& event);
f2506310
JS
414 void OnUpdateFileNew(wxUpdateUIEvent& event);
415 void OnUpdateFileSave(wxUpdateUIEvent& event);
4db97e24 416 void OnUpdateFileSaveAs(wxUpdateUIEvent& event);
f2506310
JS
417 void OnUpdateUndo(wxUpdateUIEvent& event);
418 void OnUpdateRedo(wxUpdateUIEvent& event);
419
5f170f33
VZ
420 // called when file format detection didn't work, can be overridden to do
421 // something in this case
0a0352f2 422 virtual void OnOpenFileFailure() { }
5f170f33 423
caf0debf 424 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
b5412983
VZ
425
426 // wrapper around CreateDocument() with a more clear name
427 wxDocument *CreateNewDocument()
428 { return CreateDocument(wxString(), wxDOC_NEW); }
429
caf0debf
VZ
430 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
431 virtual void DeleteTemplate(wxDocTemplate *temp, long flags = 0);
432 virtual bool FlushDoc(wxDocument *doc);
433 virtual wxDocTemplate *MatchTemplate(const wxString& path);
434 virtual wxDocTemplate *SelectDocumentPath(wxDocTemplate **templates,
68379eaf 435 int noTemplates, wxString& path, long flags, bool save = false);
caf0debf 436 virtual wxDocTemplate *SelectDocumentType(wxDocTemplate **templates,
68379eaf 437 int noTemplates, bool sort = false);
caf0debf 438 virtual wxDocTemplate *SelectViewType(wxDocTemplate **templates,
68379eaf 439 int noTemplates, bool sort = false);
caf0debf
VZ
440 virtual wxDocTemplate *FindTemplateForPath(const wxString& path);
441
442 void AssociateTemplate(wxDocTemplate *temp);
443 void DisassociateTemplate(wxDocTemplate *temp);
444
a70d268a
VZ
445 // Find template from document class info, may return NULL.
446 wxDocTemplate* FindTemplate(const wxClassInfo* documentClassInfo);
447
1127eb3a
VZ
448 // Find document from file name, may return NULL.
449 wxDocument* FindDocumentByPath(const wxString& path) const;
450
caf0debf
VZ
451 wxDocument *GetCurrentDocument() const;
452
453 void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
454 int GetMaxDocsOpen() const { return m_maxDocsOpen; }
455
456 // Add and remove a document from the manager's list
457 void AddDocument(wxDocument *doc);
458 void RemoveDocument(wxDocument *doc);
459
33a20136 460 // closes all currently open documents
68379eaf 461 bool CloseDocuments(bool force = true);
33a20136 462
b72b1920 463 // closes the specified document
68379eaf 464 bool CloseDocument(wxDocument* doc, bool force = false);
b72b1920 465
caf0debf 466 // Clear remaining documents and templates
68379eaf 467 bool Clear(bool force = true);
caf0debf
VZ
468
469 // Views or windows should inform the document manager
470 // when a view is going in or out of focus
68379eaf 471 virtual void ActivateView(wxView *view, bool activate = true);
575e4cd6 472 virtual wxView *GetCurrentView() const { return m_currentView; }
caf0debf 473
de280423
VZ
474 // This method tries to find an active view harder than GetCurrentView():
475 // if the latter is NULL, it also checks if we don't have just a single
476 // view and returns it then.
477 wxView *GetAnyUsableView() const;
478
479
93d0805b 480#ifndef __VISUALC6__
8f2a8df4
VZ
481 wxDocVector GetDocumentsVector() const;
482 wxDocTemplateVector GetTemplatesVector() const;
288de46c
VZ
483#endif // !__VISUALC6__
484
0b237b67
JS
485 wxList& GetDocuments() { return m_docs; }
486 wxList& GetTemplates() { return m_templates; }
caf0debf 487
724b119a
VZ
488 // Return the default name for a new document (by default returns strings
489 // in the form "unnamed <counter>" but can be overridden)
490 virtual wxString MakeNewDocumentName();
caf0debf 491
f2506310
JS
492 // Make a frame title (override this to do something different)
493 virtual wxString MakeFrameTitle(wxDocument* doc);
494
caf0debf
VZ
495 virtual wxFileHistory *OnCreateFileHistory();
496 virtual wxFileHistory *GetFileHistory() const { return m_fileHistory; }
497
498 // File history management
499 virtual void AddFileToHistory(const wxString& file);
e49c85af 500 virtual void RemoveFileFromHistory(size_t i);
7af6b69e 501 virtual size_t GetHistoryFilesCount() const;
e49c85af 502 virtual wxString GetHistoryFile(size_t i) const;
caf0debf
VZ
503 virtual void FileHistoryUseMenu(wxMenu *menu);
504 virtual void FileHistoryRemoveMenu(wxMenu *menu);
702ca7c0 505#if wxUSE_CONFIG
9c8116f8 506 virtual void FileHistoryLoad(const wxConfigBase& config);
caf0debf
VZ
507 virtual void FileHistorySave(wxConfigBase& config);
508#endif // wxUSE_CONFIG
509
510 virtual void FileHistoryAddFilesToMenu();
511 virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
512
d8efd219 513 wxString GetLastDirectory() const;
7af6b69e 514 void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
ac0ac824 515
f2506310
JS
516 // Get the current document manager
517 static wxDocManager* GetDocumentManager() { return sm_docManager; }
518
61490d3b
VZ
519#if wxUSE_PRINTING_ARCHITECTURE
520 wxPageSetupDialogData& GetPageSetupDialogData()
521 { return m_pageSetupDialogData; }
522 const wxPageSetupDialogData& GetPageSetupDialogData() const
523 { return m_pageSetupDialogData; }
524#endif // wxUSE_PRINTING_ARCHITECTURE
525
724b119a
VZ
526#if WXWIN_COMPATIBILITY_2_8
527 // deprecated, override GetDefaultName() instead
528 wxDEPRECATED_BUT_USED_INTERNALLY(
529 virtual bool MakeDefaultName(wxString& buf)
530 );
531#endif
532
ca3e85cf 533#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
534 // deprecated, use GetHistoryFilesCount() instead
535 wxDEPRECATED( size_t GetNoHistoryFiles() const );
ca3e85cf 536#endif // WXWIN_COMPATIBILITY_2_6
7af6b69e 537
b99017ce 538
caf0debf 539protected:
d38eb01c
VZ
540 // Called when a file selected from the MRU list doesn't exist any more.
541 // The default behaviour is to remove the file from the MRU and notify the
542 // user about it but this method can be overridden to customize it.
543 virtual void OnMRUFileNotExist(unsigned n, const wxString& filename);
544
c70da1a2
VZ
545 // Open the MRU file with the given index in our associated file history.
546 void DoOpenMRUFile(unsigned n);
94dc70d1
VZ
547#if wxUSE_PRINTING_ARCHITECTURE
548 virtual wxPreviewFrame* CreatePreviewFrame(wxPrintPreviewBase* preview,
549 wxWindow *parent,
550 const wxString& title);
551#endif // wxUSE_PRINTING_ARCHITECTURE
552
bba5e72a 553 // hook the currently active view into event handlers chain here
8cc208e3 554 virtual bool TryBefore(wxEvent& event);
bba5e72a 555
89d94e04
VZ
556 // return the command processor for the current document, if any
557 wxCommandProcessor *GetCurrentCommandProcessor() const;
558
caf0debf
VZ
559 int m_defaultDocumentNameCounter;
560 int m_maxDocsOpen;
561 wxList m_docs;
562 wxList m_templates;
563 wxView* m_currentView;
564 wxFileHistory* m_fileHistory;
ac0ac824 565 wxString m_lastDirectory;
f2506310 566 static wxDocManager* sm_docManager;
caf0debf 567
b99017ce
VZ
568#if wxUSE_PRINTING_ARCHITECTURE
569 wxPageSetupDialogData m_pageSetupDialogData;
570#endif // wxUSE_PRINTING_ARCHITECTURE
571
caf0debf 572 DECLARE_EVENT_TABLE()
b5f159ac 573 DECLARE_DYNAMIC_CLASS(wxDocManager)
c0c133e1 574 wxDECLARE_NO_COPY_CLASS(wxDocManager);
c801d85f
KB
575};
576
ca3e85cf 577#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
578inline size_t wxDocManager::GetNoHistoryFiles() const
579{
580 return GetHistoryFilesCount();
581}
ca3e85cf 582#endif // WXWIN_COMPATIBILITY_2_6
b5f159ac 583
caf0debf 584// ----------------------------------------------------------------------------
a9e2e6e5
VZ
585// Base class for child frames -- this is what wxView renders itself into
586//
587// Notice that this is a mix-in class so it doesn't derive from wxWindow, only
588// wxDocChildFrameAny does
caf0debf 589// ----------------------------------------------------------------------------
c801d85f 590
73bde1ef 591class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase
c801d85f 592{
caf0debf 593public:
c65c67be 594 // default ctor, use Create() after it
e5033ed2
VZ
595 wxDocChildFrameAnyBase()
596 {
597 m_childDocument = NULL;
598 m_childView = NULL;
599 m_win = NULL;
600 }
c65c67be
VZ
601
602 // full ctor equivalent to using the default one and Create(0
ada1ff0d 603 wxDocChildFrameAnyBase(wxDocument *doc, wxView *view, wxWindow *win)
c65c67be
VZ
604 {
605 Create(doc, view, win);
606 }
607
608 // method which must be called for an object created using the default ctor
609 //
610 // note that it returns bool just for consistency with Create() methods in
611 // other classes, we never return false from here
612 bool Create(wxDocument *doc, wxView *view, wxWindow *win)
a9e2e6e5
VZ
613 {
614 m_childDocument = doc;
615 m_childView = view;
c65c67be 616 m_win = win;
caf0debf 617
a9e2e6e5
VZ
618 if ( view )
619 view->SetDocChildFrame(this);
c65c67be
VZ
620
621 return true;
a9e2e6e5 622 }
caf0debf 623
c65c67be
VZ
624 // dtor doesn't need to be virtual, an object should never be destroyed via
625 // a pointer to this class
b7341fe0
VZ
626 ~wxDocChildFrameAnyBase()
627 {
628 // prevent the view from deleting us if we're being deleted directly
629 // (and not via Close() + Destroy())
630 if ( m_childView )
631 m_childView->SetDocChildFrame(NULL);
632 }
633
caf0debf
VZ
634 wxDocument *GetDocument() const { return m_childDocument; }
635 wxView *GetView() const { return m_childView; }
636 void SetDocument(wxDocument *doc) { m_childDocument = doc; }
637 void SetView(wxView *view) { m_childView = view; }
638
ada1ff0d
VZ
639 wxWindow *GetWindow() const { return m_win; }
640
caf0debf 641protected:
a9e2e6e5
VZ
642 // we're not a wxEvtHandler but we provide this wxEvtHandler-like function
643 // which is called from TryBefore() of the derived classes to give our view
644 // a chance to process the message before the frame event handlers are used
a7c0de8a 645 bool TryProcessEvent(wxEvent& event);
a9e2e6e5
VZ
646
647 // called from EVT_CLOSE handler in the frame: check if we can close and do
648 // cleanup if so; veto the event otherwise
649 bool CloseView(wxCloseEvent& event);
650
bba5e72a 651
caf0debf
VZ
652 wxDocument* m_childDocument;
653 wxView* m_childView;
654
ada1ff0d
VZ
655 // the associated window: having it here is not terribly elegant but it
656 // allows us to avoid having any virtual functions in this class
c65c67be 657 wxWindow* m_win;
ada1ff0d
VZ
658
659
a9e2e6e5
VZ
660 wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase);
661};
662
663// ----------------------------------------------------------------------------
664// Template implementing child frame concept using the given wxFrame-like class
665//
666// This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
667// a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
668// derived class as long as it provided a ctor with the same signature as
669// wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
670// wxMDIParentFrame.
671// ----------------------------------------------------------------------------
672
673template <class ChildFrame, class ParentFrame>
674class WXDLLIMPEXP_CORE wxDocChildFrameAny : public ChildFrame,
675 public wxDocChildFrameAnyBase
676{
677public:
678 typedef ChildFrame BaseClass;
679
c65c67be
VZ
680 // default ctor, use Create after it
681 wxDocChildFrameAny() { }
682
a9e2e6e5
VZ
683 // ctor for a frame showing the given view of the specified document
684 wxDocChildFrameAny(wxDocument *doc,
685 wxView *view,
686 ParentFrame *parent,
687 wxWindowID id,
688 const wxString& title,
689 const wxPoint& pos = wxDefaultPosition,
690 const wxSize& size = wxDefaultSize,
691 long style = wxDEFAULT_FRAME_STYLE,
692 const wxString& name = wxFrameNameStr)
a9e2e6e5 693 {
c65c67be
VZ
694 Create(doc, view, parent, id, title, pos, size, style, name);
695 }
696
697 bool Create(wxDocument *doc,
698 wxView *view,
699 ParentFrame *parent,
700 wxWindowID id,
701 const wxString& title,
702 const wxPoint& pos = wxDefaultPosition,
703 const wxSize& size = wxDefaultSize,
704 long style = wxDEFAULT_FRAME_STYLE,
705 const wxString& name = wxFrameNameStr)
706 {
e5033ed2 707 if ( !wxDocChildFrameAnyBase::Create(doc, view, this) )
c65c67be
VZ
708 return false;
709
e5033ed2 710 if ( !BaseClass::Create(parent, id, title, pos, size, style, name) )
c65c67be
VZ
711 return false;
712
a9e2e6e5
VZ
713 this->Connect(wxEVT_ACTIVATE,
714 wxActivateEventHandler(wxDocChildFrameAny::OnActivate));
715 this->Connect(wxEVT_CLOSE_WINDOW,
716 wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow));
c65c67be
VZ
717
718 return true;
a9e2e6e5
VZ
719 }
720
721 virtual bool Destroy()
722 {
723 // FIXME: why exactly do we do this? to avoid activation events during
724 // destructions maybe?
725 m_childView = NULL;
726 return BaseClass::Destroy();
727 }
728
729protected:
730 // hook the child view into event handlers chain here
731 virtual bool TryBefore(wxEvent& event)
732 {
733 return TryProcessEvent(event) || BaseClass::TryBefore(event);
734 }
735
736private:
737 void OnActivate(wxActivateEvent& event)
738 {
739 BaseClass::OnActivate(event);
740
741 if ( m_childView )
742 m_childView->Activate(event.GetActive());
743 }
744
745 void OnCloseWindow(wxCloseEvent& event)
746 {
747 if ( CloseView(event) )
748 Destroy();
749 //else: vetoed
750 }
751
752 wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny,
753 ChildFrame, ParentFrame);
754};
755
756// ----------------------------------------------------------------------------
757// A default child frame: we need to define it as a class just for wxRTTI,
758// otherwise we could simply typedef it
759// ----------------------------------------------------------------------------
760
27d77a59
VZ
761#ifdef __VISUALC6__
762 // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
763 // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the
764 // template will be DLL-exported but only once it is used as base class
765 // here!
fb330c2e 766 #pragma warning (push)
27d77a59
VZ
767 #pragma warning (disable:4275)
768#endif
769
a9e2e6e5
VZ
770typedef wxDocChildFrameAny<wxFrame, wxFrame> wxDocChildFrameBase;
771
772class WXDLLIMPEXP_CORE wxDocChildFrame : public wxDocChildFrameBase
773{
774public:
c65c67be
VZ
775 wxDocChildFrame()
776 {
777 }
778
a9e2e6e5
VZ
779 wxDocChildFrame(wxDocument *doc,
780 wxView *view,
781 wxFrame *parent,
782 wxWindowID id,
783 const wxString& title,
784 const wxPoint& pos = wxDefaultPosition,
785 const wxSize& size = wxDefaultSize,
786 long style = wxDEFAULT_FRAME_STYLE,
787 const wxString& name = wxFrameNameStr)
788 : wxDocChildFrameBase(doc, view,
789 parent, id, title, pos, size, style, name)
790 {
791 }
792
c65c67be
VZ
793 bool Create(wxDocument *doc,
794 wxView *view,
795 wxFrame *parent,
796 wxWindowID id,
797 const wxString& title,
798 const wxPoint& pos = wxDefaultPosition,
799 const wxSize& size = wxDefaultSize,
800 long style = wxDEFAULT_FRAME_STYLE,
801 const wxString& name = wxFrameNameStr)
802 {
803 return wxDocChildFrameBase::Create
804 (
805 doc, view,
806 parent, id, title, pos, size, style, name
807 );
808 }
809
2b5f62a0
VZ
810private:
811 DECLARE_CLASS(wxDocChildFrame)
c0c133e1 812 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame);
caf0debf 813};
c801d85f 814
caf0debf 815// ----------------------------------------------------------------------------
c48bdb0c
VZ
816// wxDocParentFrame and related classes.
817//
818// As with wxDocChildFrame we define a template base class used by both normal
819// and MDI versions
caf0debf 820// ----------------------------------------------------------------------------
c801d85f 821
c48bdb0c
VZ
822// Base class containing type-independent code of wxDocParentFrameAny
823//
824// Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
825// derive from wxWindow.
826class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
caf0debf 827{
caf0debf 828public:
a7c0de8a
VZ
829 wxDocParentFrameAnyBase(wxWindow* frame)
830 : m_frame(frame)
831 {
832 m_docManager = NULL;
833 }
c48bdb0c
VZ
834
835 wxDocManager *GetDocumentManager() const { return m_docManager; }
836
837protected:
a7c0de8a
VZ
838 // This is similar to wxDocChildFrameAnyBase method with the same name:
839 // while we're not an event handler ourselves and so can't override
840 // TryBefore(), we provide a helper that the derived template class can use
841 // from its TryBefore() implementation.
842 bool TryProcessEvent(wxEvent& event);
843
844 wxWindow* const m_frame;
c48bdb0c
VZ
845 wxDocManager *m_docManager;
846
847 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase);
848};
849
850// This is similar to wxDocChildFrameAny and is used to provide common
851// implementation for both wxDocParentFrame and wxDocMDIParentFrame
852template <class BaseFrame>
853class WXDLLIMPEXP_CORE wxDocParentFrameAny : public BaseFrame,
854 public wxDocParentFrameAnyBase
855{
856public:
a7c0de8a 857 wxDocParentFrameAny() : wxDocParentFrameAnyBase(this) { }
c48bdb0c
VZ
858 wxDocParentFrameAny(wxDocManager *manager,
859 wxFrame *frame,
860 wxWindowID id,
861 const wxString& title,
862 const wxPoint& pos = wxDefaultPosition,
863 const wxSize& size = wxDefaultSize,
864 long style = wxDEFAULT_FRAME_STYLE,
865 const wxString& name = wxFrameNameStr)
a7c0de8a 866 : wxDocParentFrameAnyBase(this)
c48bdb0c
VZ
867 {
868 Create(manager, frame, id, title, pos, size, style, name);
869 }
0c246b3c
PC
870
871 bool Create(wxDocManager *manager,
872 wxFrame *frame,
873 wxWindowID id,
874 const wxString& title,
875 const wxPoint& pos = wxDefaultPosition,
876 const wxSize& size = wxDefaultSize,
877 long style = wxDEFAULT_FRAME_STYLE,
c48bdb0c
VZ
878 const wxString& name = wxFrameNameStr)
879 {
880 m_docManager = manager;
c801d85f 881
c48bdb0c
VZ
882 if ( !BaseFrame::Create(frame, id, title, pos, size, style, name) )
883 return false;
884
ce7fe42e 885 this->Connect(wxID_EXIT, wxEVT_MENU,
c48bdb0c 886 wxCommandEventHandler(wxDocParentFrameAny::OnExit));
c48bdb0c
VZ
887 this->Connect(wxEVT_CLOSE_WINDOW,
888 wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow));
c801d85f 889
c48bdb0c
VZ
890 return true;
891 }
c801d85f 892
caf0debf 893protected:
bba5e72a 894 // hook the document manager into event handling chain here
c48bdb0c
VZ
895 virtual bool TryBefore(wxEvent& event)
896 {
a7c0de8a 897 return TryProcessEvent(event) || BaseFrame::TryBefore(event);
c48bdb0c
VZ
898 }
899
900private:
901 void OnExit(wxCommandEvent& WXUNUSED(event))
902 {
903 this->Close();
904 }
905
c48bdb0c
VZ
906 void OnCloseWindow(wxCloseEvent& event)
907 {
908 if ( m_docManager && !m_docManager->Clear(!event.CanVeto()) )
909 {
910 // The user decided not to close finally, abort.
911 event.Veto();
912 }
913 else
914 {
915 // Just skip the event, base class handler will destroy the window.
916 event.Skip();
917 }
918 }
919
920
921 wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny);
922};
923
924typedef wxDocParentFrameAny<wxFrame> wxDocParentFrameBase;
925
926class WXDLLIMPEXP_CORE wxDocParentFrame : public wxDocParentFrameBase
927{
928public:
929 wxDocParentFrame() : wxDocParentFrameBase() { }
930
931 wxDocParentFrame(wxDocManager *manager,
932 wxFrame *parent,
933 wxWindowID id,
934 const wxString& title,
935 const wxPoint& pos = wxDefaultPosition,
936 const wxSize& size = wxDefaultSize,
937 long style = wxDEFAULT_FRAME_STYLE,
938 const wxString& name = wxFrameNameStr)
939 : wxDocParentFrameBase(manager,
940 parent, id, title, pos, size, style, name)
941 {
942 }
943
944 bool Create(wxDocManager *manager,
945 wxFrame *parent,
946 wxWindowID id,
947 const wxString& title,
948 const wxPoint& pos = wxDefaultPosition,
949 const wxSize& size = wxDefaultSize,
950 long style = wxDEFAULT_FRAME_STYLE,
951 const wxString& name = wxFrameNameStr)
952 {
953 return wxDocParentFrameBase::Create(manager,
954 parent, id, title,
955 pos, size, style, name);
956 }
caf0debf 957
2b5f62a0
VZ
958private:
959 DECLARE_CLASS(wxDocParentFrame)
c0c133e1 960 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame);
caf0debf 961};
c801d85f 962
c48bdb0c
VZ
963#ifdef __VISUALC6__
964 // reenable warning 4275
965 #pragma warning (pop)
966#endif
967
caf0debf
VZ
968// ----------------------------------------------------------------------------
969// Provide simple default printing facilities
970// ----------------------------------------------------------------------------
c801d85f 971
caf0debf 972#if wxUSE_PRINTING_ARCHITECTURE
53a2db12 973class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
caf0debf 974{
caf0debf 975public:
302674fe 976 wxDocPrintout(wxView *view = NULL, const wxString& title = wxString());
89d94e04
VZ
977
978 // implement wxPrintout methods
979 virtual bool OnPrintPage(int page);
980 virtual bool HasPage(int page);
981 virtual bool OnBeginDocument(int startPage, int endPage);
982 virtual void GetPageInfo(int *minPage, int *maxPage,
983 int *selPageFrom, int *selPageTo);
c801d85f 984
caf0debf 985 virtual wxView *GetView() { return m_printoutView; }
c801d85f 986
caf0debf
VZ
987protected:
988 wxView* m_printoutView;
2b5f62a0
VZ
989
990private:
991 DECLARE_DYNAMIC_CLASS(wxDocPrintout)
c0c133e1 992 wxDECLARE_NO_COPY_CLASS(wxDocPrintout);
c801d85f 993};
caf0debf 994#endif // wxUSE_PRINTING_ARCHITECTURE
c801d85f 995
c801d85f
KB
996// For compatibility with existing file formats:
997// converts from/to a stream to/from a temporary file.
89d94e04
VZ
998#if wxUSE_STD_IOSTREAM
999bool WXDLLIMPEXP_CORE
1000wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
1001bool WXDLLIMPEXP_CORE
1002wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
dc1efb1d 1003#else
89d94e04
VZ
1004bool WXDLLIMPEXP_CORE
1005wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
1006bool WXDLLIMPEXP_CORE
1007wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
e30285ab
VZ
1008#endif // wxUSE_STD_IOSTREAM
1009
c77049a0
VZ
1010
1011// these flags are not used anywhere by wxWidgets and kept only for an unlikely
1012// case of existing user code using them for its own purposes
7bc57fd9 1013#if WXWIN_COMPATIBILITY_2_8
c77049a0
VZ
1014enum
1015{
1016 wxDOC_SDI = 1,
1017 wxDOC_MDI,
1018 wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
1019};
1020#endif // WXWIN_COMPATIBILITY_2_8
1021
8f2a8df4
VZ
1022#ifndef __VISUALC6__
1023inline wxViewVector wxDocument::GetViewsVector() const
1024{
1025 return m_documentViews.AsVector<wxView*>();
1026}
1027
1028inline wxDocVector wxDocManager::GetDocumentsVector() const
1029{
1030 return m_docs.AsVector<wxDocument*>();
1031}
1032
1033inline wxDocTemplateVector wxDocManager::GetTemplatesVector() const
1034{
1035 return m_templates.AsVector<wxDocTemplate*>();
1036}
1037#endif // !__VISUALC6__
1038
e30285ab 1039#endif // wxUSE_DOC_VIEW_ARCHITECTURE
c801d85f 1040
caf0debf 1041#endif // _WX_DOCH__