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