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