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