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