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