]> git.saurik.com Git - wxWidgets.git/blame - include/wx/docview.h
check for self-assignment in operator=
[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
a533f5c1 37#if wxUSE_STD_IOSTREAM
65f19af1 38 #include "wx/iosfwrap.h"
a533f5c1
RR
39#else
40 #include "wx/stream.h"
41#endif
c801d85f 42
c77049a0 43// Flags for wxDocManager (can be combined).
caf0debf
VZ
44enum
45{
c77049a0
VZ
46 wxDOC_NEW = 1,
47 wxDOC_SILENT = 2
caf0debf 48};
c801d85f
KB
49
50// Document template flags
caf0debf
VZ
51enum
52{
53 wxTEMPLATE_VISIBLE = 1,
89d94e04 54 wxTEMPLATE_INVISIBLE = 2,
caf0debf
VZ
55 wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
56};
c801d85f 57
caf0debf 58#define wxMAX_FILE_HISTORY 9
c801d85f 59
53a2db12 60class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler
c801d85f 61{
caf0debf 62public:
c77049a0 63 wxDocument(wxDocument *parent = NULL);
d3c7fc99 64 virtual ~wxDocument();
caf0debf
VZ
65
66 // accessors
68379eaf 67 void SetFilename(const wxString& filename, bool notifyViews = false);
caf0debf
VZ
68 wxString GetFilename() const { return m_documentFile; }
69
47b378bd 70 void SetTitle(const wxString& title) { m_documentTitle = title; }
caf0debf
VZ
71 wxString GetTitle() const { return m_documentTitle; }
72
47b378bd 73 void SetDocumentName(const wxString& name) { m_documentTypeName = name; }
caf0debf
VZ
74 wxString GetDocumentName() const { return m_documentTypeName; }
75
d7b3a73d
VZ
76 // access the flag indicating whether this document had been already saved,
77 // SetDocumentSaved() is only used internally, don't call it
caf0debf 78 bool GetDocumentSaved() const { return m_savedYet; }
68379eaf 79 void SetDocumentSaved(bool saved = true) { m_savedYet = saved; }
caf0debf 80
de56f240
VZ
81 // return true if the document hasn't been modified since the last time it
82 // was saved (implying that it returns false if it was never saved, even if
83 // the document is not modified)
84 bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
85
caf0debf
VZ
86 virtual bool Close();
87 virtual bool Save();
88 virtual bool SaveAs();
89 virtual bool Revert();
90
a533f5c1 91#if wxUSE_STD_IOSTREAM
dd107c50
VZ
92 virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
93 virtual wxSTD istream& LoadObject(wxSTD istream& stream);
a533f5c1 94#else
23a54e14
RR
95 virtual wxOutputStream& SaveObject(wxOutputStream& stream);
96 virtual wxInputStream& LoadObject(wxInputStream& stream);
a533f5c1 97#endif
caf0debf 98
77ffb593 99 // Called by wxWidgets
caf0debf
VZ
100 virtual bool OnSaveDocument(const wxString& filename);
101 virtual bool OnOpenDocument(const wxString& filename);
102 virtual bool OnNewDocument();
103 virtual bool OnCloseDocument();
104
68379eaf 105 // Prompts for saving if about to close a modified document. Returns true
caf0debf 106 // if ok to close the document (may have saved in the meantime, or set
68379eaf 107 // modified to false)
caf0debf
VZ
108 virtual bool OnSaveModified();
109
00e3ea1c
FM
110 // if you override, remember to call the default
111 // implementation (wxDocument::OnChangeFilename)
112 virtual void OnChangeFilename(bool notifyViews);
113
caf0debf
VZ
114 // Called by framework if created automatically by the default document
115 // manager: gives document a chance to initialise and (usually) create a
116 // view
117 virtual bool OnCreate(const wxString& path, long flags);
118
119 // By default, creates a base wxCommandProcessor.
120 virtual wxCommandProcessor *OnCreateCommandProcessor();
89d94e04
VZ
121 virtual wxCommandProcessor *GetCommandProcessor() const
122 { return m_commandProcessor; }
123 virtual void SetCommandProcessor(wxCommandProcessor *proc)
124 { m_commandProcessor = proc; }
caf0debf
VZ
125
126 // Called after a view is added or removed. The default implementation
127 // deletes the document if this is there are no more views.
128 virtual void OnChangedViewList();
129
130 virtual bool DeleteContents();
131
132 virtual bool Draw(wxDC&);
133 virtual bool IsModified() const { return m_documentModified; }
134 virtual void Modify(bool mod) { m_documentModified = mod; }
135
136 virtual bool AddView(wxView *view);
137 virtual bool RemoveView(wxView *view);
b80388aa
VZ
138 wxList& GetViews() { return m_documentViews; }
139 const wxList& GetViews() const { return m_documentViews; }
caf0debf
VZ
140 wxView *GetFirstView() const;
141
c77049a0 142 virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL);
b23e843b 143 virtual void NotifyClosing();
caf0debf
VZ
144
145 // Remove all views (because we're closing the document)
146 virtual bool DeleteAllViews();
147
148 // Other stuff
149 virtual wxDocManager *GetDocumentManager() const;
89d94e04
VZ
150 virtual wxDocTemplate *GetDocumentTemplate() const
151 { return m_documentTemplate; }
152 virtual void SetDocumentTemplate(wxDocTemplate *temp)
153 { m_documentTemplate = temp; }
caf0debf 154
724b119a
VZ
155 // Get the document name to be shown to the user: the title if there is
156 // any, otherwise the filename if the document was saved and, finally,
157 // "unnamed" otherwise
158 virtual wxString GetUserReadableName() const;
159
160#if WXWIN_COMPATIBILITY_2_8
161 // use GetUserReadableName() instead
162 wxDEPRECATED_BUT_USED_INTERNALLY(
163 virtual bool GetPrintableName(wxString& buf) const
164 );
165#endif // WXWIN_COMPATIBILITY_2_8
caf0debf
VZ
166
167 // Returns a window that can be used as a parent for document-related
168 // dialogs. Override if necessary.
169 virtual wxWindow *GetDocumentWindow() const;
170
171protected:
172 wxList m_documentViews;
173 wxString m_documentFile;
174 wxString m_documentTitle;
175 wxString m_documentTypeName;
176 wxDocTemplate* m_documentTemplate;
177 bool m_documentModified;
178 wxDocument* m_documentParent;
179 wxCommandProcessor* m_commandProcessor;
180 bool m_savedYet;
b5f159ac 181
69936aea
VZ
182 // Called by OnSaveDocument and OnOpenDocument to implement standard
183 // Save/Load behavior. Re-implement in derived class for custom
184 // behavior.
185 virtual bool DoSaveDocument(const wxString& file);
186 virtual bool DoOpenDocument(const wxString& file);
187
724b119a
VZ
188 // the default implementation of GetUserReadableName()
189 wxString DoGetUserReadableName() const;
190
2b5f62a0
VZ
191private:
192 DECLARE_ABSTRACT_CLASS(wxDocument)
c0c133e1 193 wxDECLARE_NO_COPY_CLASS(wxDocument);
c801d85f
KB
194};
195
53a2db12 196class WXDLLIMPEXP_CORE wxView: public wxEvtHandler
c801d85f 197{
caf0debf 198public:
caf0debf 199 wxView();
d3c7fc99 200 virtual ~wxView();
c801d85f 201
caf0debf 202 wxDocument *GetDocument() const { return m_viewDocument; }
bb28b477 203 virtual void SetDocument(wxDocument *doc);
c801d85f 204
caf0debf 205 wxString GetViewName() const { return m_viewTypeName; }
47b378bd 206 void SetViewName(const wxString& name) { m_viewTypeName = name; }
c801d85f 207
b9f933ab
JS
208 wxWindow *GetFrame() const { return m_viewFrame ; }
209 void SetFrame(wxWindow *frame) { m_viewFrame = frame; }
c801d85f 210
89d94e04
VZ
211 virtual void OnActivateView(bool activate,
212 wxView *activeView,
213 wxView *deactiveView);
caf0debf
VZ
214 virtual void OnDraw(wxDC *dc) = 0;
215 virtual void OnPrint(wxDC *dc, wxObject *info);
c77049a0 216 virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
6fb99eb3 217 virtual void OnClosingDocument() {}
caf0debf 218 virtual void OnChangeFilename();
c801d85f 219
caf0debf
VZ
220 // Called by framework if created automatically by the default document
221 // manager class: gives view a chance to initialise
c77049a0
VZ
222 virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags))
223 { return true; }
c801d85f 224
caf0debf
VZ
225 // Checks if the view is the last one for the document; if so, asks user
226 // to confirm save data (if modified). If ok, deletes itself and returns
68379eaf
WS
227 // true.
228 virtual bool Close(bool deleteWindow = true);
caf0debf
VZ
229
230 // Override to do cleanup/veto close
231 virtual bool OnClose(bool deleteWindow);
2b854a32 232
caf0debf
VZ
233 // A view's window can call this to notify the view it is (in)active.
234 // The function then notifies the document manager.
235 virtual void Activate(bool activate);
c801d85f 236
caf0debf
VZ
237 wxDocManager *GetDocumentManager() const
238 { return m_viewDocument->GetDocumentManager(); }
c801d85f 239
47d67540 240#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 241 virtual wxPrintout *OnCreatePrintout();
c801d85f
KB
242#endif
243
caf0debf 244protected:
bba5e72a
VZ
245 // hook the document into event handlers chain here
246 virtual bool TryValidator(wxEvent& event);
247
caf0debf
VZ
248 wxDocument* m_viewDocument;
249 wxString m_viewTypeName;
b9f933ab 250 wxWindow* m_viewFrame;
22f3361e 251
2b5f62a0
VZ
252private:
253 DECLARE_ABSTRACT_CLASS(wxView)
c0c133e1 254 wxDECLARE_NO_COPY_CLASS(wxView);
c801d85f
KB
255};
256
257// Represents user interface (and other) properties of documents and views
53a2db12 258class WXDLLIMPEXP_CORE wxDocTemplate: public wxObject
c801d85f 259{
caf0debf 260
b5dbe15d 261friend class WXDLLIMPEXP_FWD_CORE wxDocManager;
caf0debf
VZ
262
263public:
264 // Associate document and view types. They're for identifying what view is
265 // associated with what template/document type
266 wxDocTemplate(wxDocManager *manager,
267 const wxString& descr,
268 const wxString& filter,
269 const wxString& dir,
270 const wxString& ext,
271 const wxString& docTypeName,
272 const wxString& viewTypeName,
c77049a0
VZ
273 wxClassInfo *docClassInfo = NULL,
274 wxClassInfo *viewClassInfo = NULL,
caf0debf
VZ
275 long flags = wxDEFAULT_TEMPLATE_FLAGS);
276
d3c7fc99 277 virtual ~wxDocTemplate();
caf0debf
VZ
278
279 // By default, these two member functions dynamically creates document and
280 // view using dynamic instance construction. Override these if you need a
281 // different method of construction.
282 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
283 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
284
217b7140
JS
285 // Helper method for CreateDocument; also allows you to do your own document
286 // creation
89d94e04
VZ
287 virtual bool InitDocument(wxDocument* doc,
288 const wxString& path,
289 long flags = 0);
217b7140 290
47b378bd 291 wxString GetDefaultExtension() const { return m_defaultExt; }
caf0debf 292 wxString GetDescription() const { return m_description; }
47b378bd 293 wxString GetDirectory() const { return m_directory; }
caf0debf 294 wxDocManager *GetDocumentManager() const { return m_documentManager; }
89d94e04
VZ
295 void SetDocumentManager(wxDocManager *manager)
296 { m_documentManager = manager; }
47b378bd
VS
297 wxString GetFileFilter() const { return m_fileFilter; }
298 long GetFlags() const { return m_flags; }
caf0debf
VZ
299 virtual wxString GetViewName() const { return m_viewTypeName; }
300 virtual wxString GetDocumentName() const { return m_docTypeName; }
301
47b378bd
VS
302 void SetFileFilter(const wxString& filter) { m_fileFilter = filter; }
303 void SetDirectory(const wxString& dir) { m_directory = dir; }
304 void SetDescription(const wxString& descr) { m_description = descr; }
305 void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; }
306 void SetFlags(long flags) { m_flags = flags; }
caf0debf 307
89d94e04 308 bool IsVisible() const { return (m_flags & wxTEMPLATE_VISIBLE) != 0; }
caf0debf 309
04129514
JS
310 wxClassInfo* GetDocClassInfo() const { return m_docClassInfo; }
311 wxClassInfo* GetViewClassInfo() const { return m_viewClassInfo; }
312
caf0debf
VZ
313 virtual bool FileMatchesTemplate(const wxString& path);
314
315protected:
316 long m_flags;
317 wxString m_fileFilter;
318 wxString m_directory;
319 wxString m_description;
320 wxString m_defaultExt;
321 wxString m_docTypeName;
322 wxString m_viewTypeName;
323 wxDocManager* m_documentManager;
324
325 // For dynamic creation of appropriate instances.
326 wxClassInfo* m_docClassInfo;
327 wxClassInfo* m_viewClassInfo;
b5f159ac 328
89d94e04
VZ
329 // Called by CreateDocument and CreateView to create the actual
330 // document/view object.
331 //
332 // By default uses the ClassInfo provided to the constructor. Override
333 // these functions to provide a different method of creation.
69936aea
VZ
334 virtual wxDocument *DoCreateDocument();
335 virtual wxView *DoCreateView();
336
2b5f62a0
VZ
337private:
338 DECLARE_CLASS(wxDocTemplate)
c0c133e1 339 wxDECLARE_NO_COPY_CLASS(wxDocTemplate);
c801d85f
KB
340};
341
caf0debf
VZ
342// One object of this class may be created in an application, to manage all
343// the templates and documents.
53a2db12 344class WXDLLIMPEXP_CORE wxDocManager: public wxEvtHandler
c801d85f 345{
caf0debf 346public:
c77049a0
VZ
347 // NB: flags are unused, don't pass wxDOC_XXX to this ctor
348 wxDocManager(long flags = 0, bool initialize = true);
d3c7fc99 349 virtual ~wxDocManager();
caf0debf
VZ
350
351 virtual bool Initialize();
352
353 // Handlers for common user commands
354 void OnFileClose(wxCommandEvent& event);
33a20136 355 void OnFileCloseAll(wxCommandEvent& event);
caf0debf
VZ
356 void OnFileNew(wxCommandEvent& event);
357 void OnFileOpen(wxCommandEvent& event);
358 void OnFileRevert(wxCommandEvent& event);
359 void OnFileSave(wxCommandEvent& event);
360 void OnFileSaveAs(wxCommandEvent& event);
361 void OnPrint(wxCommandEvent& event);
caf0debf
VZ
362 void OnPreview(wxCommandEvent& event);
363 void OnUndo(wxCommandEvent& event);
364 void OnRedo(wxCommandEvent& event);
365
f2506310
JS
366 // Handlers for UI update commands
367 void OnUpdateFileOpen(wxUpdateUIEvent& event);
c77049a0 368 void OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event);
f2506310
JS
369 void OnUpdateFileNew(wxUpdateUIEvent& event);
370 void OnUpdateFileSave(wxUpdateUIEvent& event);
f2506310
JS
371 void OnUpdateUndo(wxUpdateUIEvent& event);
372 void OnUpdateRedo(wxUpdateUIEvent& event);
373
5f170f33
VZ
374 // called when file format detection didn't work, can be overridden to do
375 // something in this case
0a0352f2 376 virtual void OnOpenFileFailure() { }
5f170f33 377
caf0debf 378 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
b5412983
VZ
379
380 // wrapper around CreateDocument() with a more clear name
381 wxDocument *CreateNewDocument()
382 { return CreateDocument(wxString(), wxDOC_NEW); }
383
caf0debf
VZ
384 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
385 virtual void DeleteTemplate(wxDocTemplate *temp, long flags = 0);
386 virtual bool FlushDoc(wxDocument *doc);
387 virtual wxDocTemplate *MatchTemplate(const wxString& path);
388 virtual wxDocTemplate *SelectDocumentPath(wxDocTemplate **templates,
68379eaf 389 int noTemplates, wxString& path, long flags, bool save = false);
caf0debf 390 virtual wxDocTemplate *SelectDocumentType(wxDocTemplate **templates,
68379eaf 391 int noTemplates, bool sort = false);
caf0debf 392 virtual wxDocTemplate *SelectViewType(wxDocTemplate **templates,
68379eaf 393 int noTemplates, bool sort = false);
caf0debf
VZ
394 virtual wxDocTemplate *FindTemplateForPath(const wxString& path);
395
396 void AssociateTemplate(wxDocTemplate *temp);
397 void DisassociateTemplate(wxDocTemplate *temp);
398
399 wxDocument *GetCurrentDocument() const;
400
401 void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
402 int GetMaxDocsOpen() const { return m_maxDocsOpen; }
403
404 // Add and remove a document from the manager's list
405 void AddDocument(wxDocument *doc);
406 void RemoveDocument(wxDocument *doc);
407
33a20136 408 // closes all currently open documents
68379eaf 409 bool CloseDocuments(bool force = true);
33a20136 410
b72b1920 411 // closes the specified document
68379eaf 412 bool CloseDocument(wxDocument* doc, bool force = false);
b72b1920 413
caf0debf 414 // Clear remaining documents and templates
68379eaf 415 bool Clear(bool force = true);
caf0debf
VZ
416
417 // Views or windows should inform the document manager
418 // when a view is going in or out of focus
68379eaf 419 virtual void ActivateView(wxView *view, bool activate = true);
575e4cd6 420 virtual wxView *GetCurrentView() const { return m_currentView; }
caf0debf 421
0b237b67
JS
422 wxList& GetDocuments() { return m_docs; }
423 wxList& GetTemplates() { return m_templates; }
caf0debf 424
724b119a
VZ
425 // Return the default name for a new document (by default returns strings
426 // in the form "unnamed <counter>" but can be overridden)
427 virtual wxString MakeNewDocumentName();
caf0debf 428
f2506310
JS
429 // Make a frame title (override this to do something different)
430 virtual wxString MakeFrameTitle(wxDocument* doc);
431
caf0debf
VZ
432 virtual wxFileHistory *OnCreateFileHistory();
433 virtual wxFileHistory *GetFileHistory() const { return m_fileHistory; }
434
435 // File history management
436 virtual void AddFileToHistory(const wxString& file);
e49c85af 437 virtual void RemoveFileFromHistory(size_t i);
7af6b69e 438 virtual size_t GetHistoryFilesCount() const;
e49c85af 439 virtual wxString GetHistoryFile(size_t i) const;
caf0debf
VZ
440 virtual void FileHistoryUseMenu(wxMenu *menu);
441 virtual void FileHistoryRemoveMenu(wxMenu *menu);
702ca7c0 442#if wxUSE_CONFIG
9c8116f8 443 virtual void FileHistoryLoad(const wxConfigBase& config);
caf0debf
VZ
444 virtual void FileHistorySave(wxConfigBase& config);
445#endif // wxUSE_CONFIG
446
447 virtual void FileHistoryAddFilesToMenu();
448 virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
449
d8efd219 450 wxString GetLastDirectory() const;
7af6b69e 451 void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
ac0ac824 452
f2506310
JS
453 // Get the current document manager
454 static wxDocManager* GetDocumentManager() { return sm_docManager; }
455
724b119a
VZ
456#if WXWIN_COMPATIBILITY_2_8
457 // deprecated, override GetDefaultName() instead
458 wxDEPRECATED_BUT_USED_INTERNALLY(
459 virtual bool MakeDefaultName(wxString& buf)
460 );
461#endif
462
ca3e85cf 463#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
464 // deprecated, use GetHistoryFilesCount() instead
465 wxDEPRECATED( size_t GetNoHistoryFiles() const );
ca3e85cf 466#endif // WXWIN_COMPATIBILITY_2_6
7af6b69e 467
caf0debf 468protected:
bba5e72a
VZ
469 // hook the currently active view into event handlers chain here
470 virtual bool TryValidator(wxEvent& event);
471
89d94e04
VZ
472 // return the command processor for the current document, if any
473 wxCommandProcessor *GetCurrentCommandProcessor() const;
474
575e4cd6
VZ
475 // this method tries to find an active view harder than GetCurrentView():
476 // if the latter is NULL, it also checks if we don't have just a single
477 // view and returns it then
478 wxView *GetActiveView() const;
479
89d94e04 480
caf0debf
VZ
481 int m_defaultDocumentNameCounter;
482 int m_maxDocsOpen;
483 wxList m_docs;
484 wxList m_templates;
485 wxView* m_currentView;
486 wxFileHistory* m_fileHistory;
ac0ac824 487 wxString m_lastDirectory;
f2506310 488 static wxDocManager* sm_docManager;
caf0debf
VZ
489
490 DECLARE_EVENT_TABLE()
b5f159ac 491 DECLARE_DYNAMIC_CLASS(wxDocManager)
c0c133e1 492 wxDECLARE_NO_COPY_CLASS(wxDocManager);
c801d85f
KB
493};
494
ca3e85cf 495#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
496inline size_t wxDocManager::GetNoHistoryFiles() const
497{
498 return GetHistoryFilesCount();
499}
ca3e85cf 500#endif // WXWIN_COMPATIBILITY_2_6
b5f159ac 501
caf0debf
VZ
502// ----------------------------------------------------------------------------
503// A default child frame
504// ----------------------------------------------------------------------------
c801d85f 505
53a2db12 506class WXDLLIMPEXP_CORE wxDocChildFrame : public wxFrame
c801d85f 507{
caf0debf
VZ
508public:
509 wxDocChildFrame(wxDocument *doc,
510 wxView *view,
511 wxFrame *frame,
512 wxWindowID id,
513 const wxString& title,
514 const wxPoint& pos = wxDefaultPosition,
515 const wxSize& size = wxDefaultSize,
516 long type = wxDEFAULT_FRAME_STYLE,
3366d55c 517 const wxString& name = wxFrameNameStr);
d3c7fc99 518 virtual ~wxDocChildFrame(){}
caf0debf 519
caf0debf
VZ
520 void OnActivate(wxActivateEvent& event);
521 void OnCloseWindow(wxCloseEvent& event);
522
523 wxDocument *GetDocument() const { return m_childDocument; }
524 wxView *GetView() const { return m_childView; }
525 void SetDocument(wxDocument *doc) { m_childDocument = doc; }
526 void SetView(wxView *view) { m_childView = view; }
c77049a0 527 bool Destroy() { m_childView = NULL; return wxFrame::Destroy(); }
caf0debf
VZ
528
529protected:
bba5e72a
VZ
530 // hook the child view into event handlers chain here
531 virtual bool TryValidator(wxEvent& event);
532
caf0debf
VZ
533 wxDocument* m_childDocument;
534 wxView* m_childView;
535
2b5f62a0
VZ
536private:
537 DECLARE_CLASS(wxDocChildFrame)
caf0debf 538 DECLARE_EVENT_TABLE()
c0c133e1 539 wxDECLARE_NO_COPY_CLASS(wxDocChildFrame);
caf0debf 540};
c801d85f 541
caf0debf
VZ
542// ----------------------------------------------------------------------------
543// A default parent frame
544// ----------------------------------------------------------------------------
c801d85f 545
53a2db12 546class WXDLLIMPEXP_CORE wxDocParentFrame : public wxFrame
caf0debf 547{
caf0debf 548public:
0c246b3c 549 wxDocParentFrame();
caf0debf
VZ
550 wxDocParentFrame(wxDocManager *manager,
551 wxFrame *frame,
552 wxWindowID id,
553 const wxString& title,
554 const wxPoint& pos = wxDefaultPosition,
555 const wxSize& size = wxDefaultSize,
0c246b3c
PC
556 long style = wxDEFAULT_FRAME_STYLE,
557 const wxString& name = wxFrameNameStr);
558
559 bool Create(wxDocManager *manager,
560 wxFrame *frame,
561 wxWindowID id,
562 const wxString& title,
563 const wxPoint& pos = wxDefaultPosition,
564 const wxSize& size = wxDefaultSize,
565 long style = wxDEFAULT_FRAME_STYLE,
566 const wxString& name = wxFrameNameStr);
c801d85f 567
caf0debf 568 wxDocManager *GetDocumentManager() const { return m_docManager; }
c801d85f 569
caf0debf
VZ
570 void OnExit(wxCommandEvent& event);
571 void OnMRUFile(wxCommandEvent& event);
572 void OnCloseWindow(wxCloseEvent& event);
c801d85f 573
caf0debf 574protected:
bba5e72a
VZ
575 // hook the document manager into event handling chain here
576 virtual bool TryValidator(wxEvent& event);
577
caf0debf
VZ
578 wxDocManager *m_docManager;
579
2b5f62a0 580private:
0c246b3c 581 typedef wxFrame base_type;
2b5f62a0 582 DECLARE_CLASS(wxDocParentFrame)
caf0debf 583 DECLARE_EVENT_TABLE()
c0c133e1 584 wxDECLARE_NO_COPY_CLASS(wxDocParentFrame);
caf0debf 585};
c801d85f 586
caf0debf
VZ
587// ----------------------------------------------------------------------------
588// Provide simple default printing facilities
589// ----------------------------------------------------------------------------
c801d85f 590
caf0debf 591#if wxUSE_PRINTING_ARCHITECTURE
53a2db12 592class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
caf0debf 593{
caf0debf 594public:
c77049a0 595 wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout"));
89d94e04
VZ
596
597 // implement wxPrintout methods
598 virtual bool OnPrintPage(int page);
599 virtual bool HasPage(int page);
600 virtual bool OnBeginDocument(int startPage, int endPage);
601 virtual void GetPageInfo(int *minPage, int *maxPage,
602 int *selPageFrom, int *selPageTo);
c801d85f 603
caf0debf 604 virtual wxView *GetView() { return m_printoutView; }
c801d85f 605
caf0debf
VZ
606protected:
607 wxView* m_printoutView;
2b5f62a0
VZ
608
609private:
610 DECLARE_DYNAMIC_CLASS(wxDocPrintout)
c0c133e1 611 wxDECLARE_NO_COPY_CLASS(wxDocPrintout);
c801d85f 612};
caf0debf 613#endif // wxUSE_PRINTING_ARCHITECTURE
c801d85f 614
caf0debf 615// ----------------------------------------------------------------------------
7f555861 616// File history management
caf0debf 617// ----------------------------------------------------------------------------
7f555861 618
53a2db12 619class WXDLLIMPEXP_CORE wxFileHistory : public wxObject
c801d85f 620{
caf0debf 621public:
e49c85af 622 wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
7f555861 623
caf0debf
VZ
624 // Operations
625 virtual void AddFileToHistory(const wxString& file);
e49c85af 626 virtual void RemoveFileFromHistory(size_t i);
37c2aa46 627 virtual int GetMaxFiles() const { return (int)m_fileMaxFiles; }
caf0debf 628 virtual void UseMenu(wxMenu *menu);
7f555861 629
caf0debf
VZ
630 // Remove menu from the list (MDI child may be closing)
631 virtual void RemoveMenu(wxMenu *menu);
7f555861 632
caf0debf 633#if wxUSE_CONFIG
9c8116f8 634 virtual void Load(const wxConfigBase& config);
caf0debf
VZ
635 virtual void Save(wxConfigBase& config);
636#endif // wxUSE_CONFIG
637
638 virtual void AddFilesToMenu();
639 virtual void AddFilesToMenu(wxMenu* menu); // Single menu
640
641 // Accessors
b4a980f4
VZ
642 virtual wxString GetHistoryFile(size_t i) const { return m_fileHistory[i]; }
643 virtual size_t GetCount() const { return m_fileHistory.GetCount(); }
caf0debf 644
ae500232 645 const wxList& GetMenus() const { return m_fileMenus; }
caf0debf 646
fc2b0e31 647 // Set/get base id
5d389b04
JS
648 void SetBaseId(wxWindowID baseId) { m_idBase = baseId; }
649 wxWindowID GetBaseId() const { return m_idBase; }
650
ca3e85cf 651#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
652 // deprecated, use GetCount() instead
653 wxDEPRECATED( size_t GetNoHistoryFiles() const );
ca3e85cf 654#endif // WXWIN_COMPATIBILITY_2_6
7af6b69e 655
caf0debf
VZ
656protected:
657 // Last n files
b4a980f4
VZ
658 wxArrayString m_fileHistory;
659
caf0debf
VZ
660 // Menus to maintain (may need several for an MDI app)
661 wxList m_fileMenus;
b4a980f4 662
caf0debf 663 // Max files to maintain
e49c85af 664 size_t m_fileMaxFiles;
b5f159ac 665
2b5f62a0 666private:
e49c85af
VZ
667 // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
668 wxWindowID m_idBase;
669
2b5f62a0 670 DECLARE_DYNAMIC_CLASS(wxFileHistory)
c0c133e1 671 wxDECLARE_NO_COPY_CLASS(wxFileHistory);
c801d85f
KB
672};
673
ca3e85cf 674#if WXWIN_COMPATIBILITY_2_6
b5f159ac
VZ
675inline size_t wxFileHistory::GetNoHistoryFiles() const
676{
8e4ac1a0 677 return m_fileHistory.GetCount();
b5f159ac 678}
ca3e85cf 679#endif // WXWIN_COMPATIBILITY_2_6
b5f159ac 680
c801d85f
KB
681// For compatibility with existing file formats:
682// converts from/to a stream to/from a temporary file.
89d94e04
VZ
683#if wxUSE_STD_IOSTREAM
684bool WXDLLIMPEXP_CORE
685wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
686bool WXDLLIMPEXP_CORE
687wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
dc1efb1d 688#else
89d94e04
VZ
689bool WXDLLIMPEXP_CORE
690wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
691bool WXDLLIMPEXP_CORE
692wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
e30285ab
VZ
693#endif // wxUSE_STD_IOSTREAM
694
c77049a0
VZ
695
696// these flags are not used anywhere by wxWidgets and kept only for an unlikely
697// case of existing user code using them for its own purposes
698#ifdef WXWIN_COMPATIBILITY_2_8
699enum
700{
701 wxDOC_SDI = 1,
702 wxDOC_MDI,
703 wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
704};
705#endif // WXWIN_COMPATIBILITY_2_8
706
e30285ab 707#endif // wxUSE_DOC_VIEW_ARCHITECTURE
c801d85f 708
caf0debf 709#endif // _WX_DOCH__