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