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