]> git.saurik.com Git - wxWidgets.git/blame - include/wx/docview.h
split wxBase into wxBase and wxNet libraries
[wxWidgets.git] / include / wx / docview.h
CommitLineData
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$
8// Copyright: (c)
3f4a0c5b 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_DOCH__
13#define _WX_DOCH__
c801d85f 14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
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
32class WXDLLEXPORT wxWindow;
33class WXDLLEXPORT wxDocument;
34class WXDLLEXPORT wxView;
35class WXDLLEXPORT wxDocTemplate;
36class WXDLLEXPORT wxDocManager;
37class WXDLLEXPORT wxPrintInfo;
c801d85f
KB
38class WXDLLEXPORT wxCommandProcessor;
39class WXDLLEXPORT wxFileHistory;
7f555861 40class 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
49enum
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
59enum
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
68class WXDLLEXPORT wxDocument : public wxEvtHandler
69{
caf0debf
VZ
70public:
71 wxDocument(wxDocument *parent = (wxDocument *) NULL);
72 ~wxDocument();
73
74 // accessors
75 void SetFilename(const wxString& filename, bool notifyViews = FALSE);
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; }
85 void SetDocumentSaved(bool saved = TRUE) { m_savedYet = saved; }
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
VZ
99
100 // Called by wxWindows
101 virtual bool OnSaveDocument(const wxString& filename);
102 virtual bool OnOpenDocument(const wxString& filename);
103 virtual bool OnNewDocument();
104 virtual bool OnCloseDocument();
105
106 // Prompts for saving if about to close a modified document. Returns TRUE
107 // if ok to close the document (may have saved in the meantime, or set
108 // modified to FALSE)
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
154protected:
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
2b5f62a0
VZ
165private:
166 DECLARE_ABSTRACT_CLASS(wxDocument)
22f3361e 167 DECLARE_NO_COPY_CLASS(wxDocument)
c801d85f
KB
168};
169
170class WXDLLEXPORT wxView: public wxEvtHandler
171{
caf0debf
VZ
172public:
173 // wxView(wxDocument *doc = (wxDocument *) NULL);
174 wxView();
175 ~wxView();
c801d85f 176
caf0debf 177 wxDocument *GetDocument() const { return m_viewDocument; }
bb28b477 178 virtual void SetDocument(wxDocument *doc);
c801d85f 179
caf0debf
VZ
180 wxString GetViewName() const { return m_viewTypeName; }
181 void SetViewName(const wxString& name) { m_viewTypeName = name; };
c801d85f 182
b9f933ab
JS
183 wxWindow *GetFrame() const { return m_viewFrame ; }
184 void SetFrame(wxWindow *frame) { m_viewFrame = frame; }
c801d85f 185
caf0debf
VZ
186 virtual void OnActivateView(bool activate, wxView *activeView, wxView *deactiveView);
187 virtual void OnDraw(wxDC *dc) = 0;
188 virtual void OnPrint(wxDC *dc, wxObject *info);
189 virtual void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
b23e843b 190 virtual void OnClosingDocument() {};
caf0debf 191 virtual void OnChangeFilename();
c801d85f 192
caf0debf
VZ
193 // Called by framework if created automatically by the default document
194 // manager class: gives view a chance to initialise
195 virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags)) { return TRUE; };
c801d85f 196
caf0debf
VZ
197 // Checks if the view is the last one for the document; if so, asks user
198 // to confirm save data (if modified). If ok, deletes itself and returns
199 // TRUE.
200 virtual bool Close(bool deleteWindow = TRUE);
201
202 // Override to do cleanup/veto close
203 virtual bool OnClose(bool deleteWindow);
2b854a32 204
e3065973 205#if WXWIN_COMPATIBILITY
caf0debf
VZ
206 // Defeat compiler warning
207 bool OnClose() { return wxEvtHandler::OnClose(); }
2b854a32 208#endif
c801d85f 209
caf0debf
VZ
210 // Extend event processing to search the document's event table
211 virtual bool ProcessEvent(wxEvent& event);
c801d85f 212
caf0debf
VZ
213 // A view's window can call this to notify the view it is (in)active.
214 // The function then notifies the document manager.
215 virtual void Activate(bool activate);
c801d85f 216
caf0debf
VZ
217 wxDocManager *GetDocumentManager() const
218 { return m_viewDocument->GetDocumentManager(); }
c801d85f 219
47d67540 220#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 221 virtual wxPrintout *OnCreatePrintout();
c801d85f
KB
222#endif
223
caf0debf
VZ
224protected:
225 wxDocument* m_viewDocument;
226 wxString m_viewTypeName;
b9f933ab 227 wxWindow* m_viewFrame;
22f3361e 228
2b5f62a0
VZ
229private:
230 DECLARE_ABSTRACT_CLASS(wxView)
22f3361e 231 DECLARE_NO_COPY_CLASS(wxView)
c801d85f
KB
232};
233
234// Represents user interface (and other) properties of documents and views
235class WXDLLEXPORT wxDocTemplate: public wxObject
236{
caf0debf
VZ
237
238friend class WXDLLEXPORT wxDocManager;
239
240public:
241 // Associate document and view types. They're for identifying what view is
242 // associated with what template/document type
243 wxDocTemplate(wxDocManager *manager,
244 const wxString& descr,
245 const wxString& filter,
246 const wxString& dir,
247 const wxString& ext,
248 const wxString& docTypeName,
249 const wxString& viewTypeName,
250 wxClassInfo *docClassInfo = (wxClassInfo *) NULL,
251 wxClassInfo *viewClassInfo = (wxClassInfo *)NULL,
252 long flags = wxDEFAULT_TEMPLATE_FLAGS);
253
254 ~wxDocTemplate();
255
256 // By default, these two member functions dynamically creates document and
257 // view using dynamic instance construction. Override these if you need a
258 // different method of construction.
259 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
260 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
261
262 wxString GetDefaultExtension() const { return m_defaultExt; };
263 wxString GetDescription() const { return m_description; }
264 wxString GetDirectory() const { return m_directory; };
265 wxDocManager *GetDocumentManager() const { return m_documentManager; }
266 void SetDocumentManager(wxDocManager *manager) { m_documentManager = manager; }
267 wxString GetFileFilter() const { return m_fileFilter; };
268 long GetFlags() const { return m_flags; };
269 virtual wxString GetViewName() const { return m_viewTypeName; }
270 virtual wxString GetDocumentName() const { return m_docTypeName; }
271
272 void SetFileFilter(const wxString& filter) { m_fileFilter = filter; };
273 void SetDirectory(const wxString& dir) { m_directory = dir; };
274 void SetDescription(const wxString& descr) { m_description = descr; };
275 void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; };
276 void SetFlags(long flags) { m_flags = flags; };
277
278 bool IsVisible() const { return ((m_flags & wxTEMPLATE_VISIBLE) == wxTEMPLATE_VISIBLE); }
279
280 virtual bool FileMatchesTemplate(const wxString& path);
281
282protected:
283 long m_flags;
284 wxString m_fileFilter;
285 wxString m_directory;
286 wxString m_description;
287 wxString m_defaultExt;
288 wxString m_docTypeName;
289 wxString m_viewTypeName;
290 wxDocManager* m_documentManager;
291
292 // For dynamic creation of appropriate instances.
293 wxClassInfo* m_docClassInfo;
294 wxClassInfo* m_viewClassInfo;
b5f159ac 295
2b5f62a0
VZ
296private:
297 DECLARE_CLASS(wxDocTemplate)
22f3361e 298 DECLARE_NO_COPY_CLASS(wxDocTemplate)
c801d85f
KB
299};
300
caf0debf
VZ
301// One object of this class may be created in an application, to manage all
302// the templates and documents.
c801d85f
KB
303class WXDLLEXPORT wxDocManager: public wxEvtHandler
304{
caf0debf
VZ
305public:
306 wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS, bool initialize = TRUE);
307 ~wxDocManager();
308
309 virtual bool Initialize();
310
311 // Handlers for common user commands
312 void OnFileClose(wxCommandEvent& event);
33a20136 313 void OnFileCloseAll(wxCommandEvent& event);
caf0debf
VZ
314 void OnFileNew(wxCommandEvent& event);
315 void OnFileOpen(wxCommandEvent& event);
316 void OnFileRevert(wxCommandEvent& event);
317 void OnFileSave(wxCommandEvent& event);
318 void OnFileSaveAs(wxCommandEvent& event);
319 void OnPrint(wxCommandEvent& event);
320 void OnPrintSetup(wxCommandEvent& event);
321 void OnPreview(wxCommandEvent& event);
322 void OnUndo(wxCommandEvent& event);
323 void OnRedo(wxCommandEvent& event);
324
f2506310
JS
325 // Handlers for UI update commands
326 void OnUpdateFileOpen(wxUpdateUIEvent& event);
327 void OnUpdateFileClose(wxUpdateUIEvent& event);
328 void OnUpdateFileRevert(wxUpdateUIEvent& event);
329 void OnUpdateFileNew(wxUpdateUIEvent& event);
330 void OnUpdateFileSave(wxUpdateUIEvent& event);
331 void OnUpdateFileSaveAs(wxUpdateUIEvent& event);
332 void OnUpdateUndo(wxUpdateUIEvent& event);
333 void OnUpdateRedo(wxUpdateUIEvent& event);
334
335 void OnUpdatePrint(wxUpdateUIEvent& event);
336 void OnUpdatePrintSetup(wxUpdateUIEvent& event);
337 void OnUpdatePreview(wxUpdateUIEvent& event);
338
caf0debf
VZ
339 // Extend event processing to search the view's event table
340 virtual bool ProcessEvent(wxEvent& event);
341
5f170f33
VZ
342 // called when file format detection didn't work, can be overridden to do
343 // something in this case
0a0352f2 344 virtual void OnOpenFileFailure() { }
5f170f33 345
caf0debf
VZ
346 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
347 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
348 virtual void DeleteTemplate(wxDocTemplate *temp, long flags = 0);
349 virtual bool FlushDoc(wxDocument *doc);
350 virtual wxDocTemplate *MatchTemplate(const wxString& path);
351 virtual wxDocTemplate *SelectDocumentPath(wxDocTemplate **templates,
352 int noTemplates, wxString& path, long flags, bool save = FALSE);
353 virtual wxDocTemplate *SelectDocumentType(wxDocTemplate **templates,
52b9ca21 354 int noTemplates, bool sort = FALSE);
caf0debf 355 virtual wxDocTemplate *SelectViewType(wxDocTemplate **templates,
52b9ca21 356 int noTemplates, bool sort = FALSE);
caf0debf
VZ
357 virtual wxDocTemplate *FindTemplateForPath(const wxString& path);
358
359 void AssociateTemplate(wxDocTemplate *temp);
360 void DisassociateTemplate(wxDocTemplate *temp);
361
362 wxDocument *GetCurrentDocument() const;
363
364 void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
365 int GetMaxDocsOpen() const { return m_maxDocsOpen; }
366
367 // Add and remove a document from the manager's list
368 void AddDocument(wxDocument *doc);
369 void RemoveDocument(wxDocument *doc);
370
33a20136
VZ
371 // closes all currently open documents
372 bool CloseDocuments(bool force = TRUE);
373
b72b1920
JS
374 // closes the specified document
375 bool CloseDocument(wxDocument* doc, bool force = FALSE);
376
caf0debf
VZ
377 // Clear remaining documents and templates
378 bool Clear(bool force = TRUE);
379
380 // Views or windows should inform the document manager
381 // when a view is going in or out of focus
18759f78 382 virtual void ActivateView(wxView *view, bool activate = TRUE);
caf0debf
VZ
383 virtual wxView *GetCurrentView() const;
384
0b237b67
JS
385 wxList& GetDocuments() { return m_docs; }
386 wxList& GetTemplates() { return m_templates; }
caf0debf
VZ
387
388 // Make a default document name
389 virtual bool MakeDefaultName(wxString& buf);
390
f2506310
JS
391 // Make a frame title (override this to do something different)
392 virtual wxString MakeFrameTitle(wxDocument* doc);
393
caf0debf
VZ
394 virtual wxFileHistory *OnCreateFileHistory();
395 virtual wxFileHistory *GetFileHistory() const { return m_fileHistory; }
396
397 // File history management
398 virtual void AddFileToHistory(const wxString& file);
e49c85af 399 virtual void RemoveFileFromHistory(size_t i);
7af6b69e 400 virtual size_t GetHistoryFilesCount() const;
e49c85af 401 virtual wxString GetHistoryFile(size_t i) const;
caf0debf
VZ
402 virtual void FileHistoryUseMenu(wxMenu *menu);
403 virtual void FileHistoryRemoveMenu(wxMenu *menu);
702ca7c0 404#if wxUSE_CONFIG
caf0debf
VZ
405 virtual void FileHistoryLoad(wxConfigBase& config);
406 virtual void FileHistorySave(wxConfigBase& config);
407#endif // wxUSE_CONFIG
408
409 virtual void FileHistoryAddFilesToMenu();
410 virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
411
7af6b69e
VZ
412 wxString GetLastDirectory() const { return m_lastDirectory; }
413 void SetLastDirectory(const wxString& dir) { m_lastDirectory = dir; }
ac0ac824 414
f2506310
JS
415 // Get the current document manager
416 static wxDocManager* GetDocumentManager() { return sm_docManager; }
417
b5f159ac
VZ
418 // deprecated, use GetHistoryFilesCount() instead
419 wxDEPRECATED( size_t GetNoHistoryFiles() const );
7af6b69e 420
caf0debf
VZ
421protected:
422 long m_flags;
423 int m_defaultDocumentNameCounter;
424 int m_maxDocsOpen;
425 wxList m_docs;
426 wxList m_templates;
427 wxView* m_currentView;
428 wxFileHistory* m_fileHistory;
ac0ac824 429 wxString m_lastDirectory;
f2506310 430 static wxDocManager* sm_docManager;
caf0debf
VZ
431
432 DECLARE_EVENT_TABLE()
b5f159ac 433 DECLARE_DYNAMIC_CLASS(wxDocManager)
22f3361e 434 DECLARE_NO_COPY_CLASS(wxDocManager)
c801d85f
KB
435};
436
b5f159ac
VZ
437inline size_t wxDocManager::GetNoHistoryFiles() const
438{
439 return GetHistoryFilesCount();
440}
441
caf0debf
VZ
442// ----------------------------------------------------------------------------
443// A default child frame
444// ----------------------------------------------------------------------------
c801d85f 445
caf0debf 446class WXDLLEXPORT wxDocChildFrame : public wxFrame
c801d85f 447{
caf0debf
VZ
448public:
449 wxDocChildFrame(wxDocument *doc,
450 wxView *view,
451 wxFrame *frame,
452 wxWindowID id,
453 const wxString& title,
454 const wxPoint& pos = wxDefaultPosition,
455 const wxSize& size = wxDefaultSize,
456 long type = wxDEFAULT_FRAME_STYLE,
2b5f62a0 457 const wxString& name = wxT("frame"));
caf0debf
VZ
458 ~wxDocChildFrame();
459
460 // Extend event processing to search the view's event table
461 virtual bool ProcessEvent(wxEvent& event);
462
463 void OnActivate(wxActivateEvent& event);
464 void OnCloseWindow(wxCloseEvent& event);
465
466 wxDocument *GetDocument() const { return m_childDocument; }
467 wxView *GetView() const { return m_childView; }
468 void SetDocument(wxDocument *doc) { m_childDocument = doc; }
469 void SetView(wxView *view) { m_childView = view; }
0d8737fd 470 bool Destroy() { m_childView = (wxView *)NULL; return wxFrame::Destroy(); }
caf0debf
VZ
471
472protected:
473 wxDocument* m_childDocument;
474 wxView* m_childView;
475
2b5f62a0
VZ
476private:
477 DECLARE_CLASS(wxDocChildFrame)
caf0debf 478 DECLARE_EVENT_TABLE()
22f3361e 479 DECLARE_NO_COPY_CLASS(wxDocChildFrame)
caf0debf 480};
c801d85f 481
caf0debf
VZ
482// ----------------------------------------------------------------------------
483// A default parent frame
484// ----------------------------------------------------------------------------
c801d85f 485
caf0debf
VZ
486class WXDLLEXPORT wxDocParentFrame : public wxFrame
487{
caf0debf
VZ
488public:
489 wxDocParentFrame(wxDocManager *manager,
490 wxFrame *frame,
491 wxWindowID id,
492 const wxString& title,
493 const wxPoint& pos = wxDefaultPosition,
494 const wxSize& size = wxDefaultSize,
495 long type = wxDEFAULT_FRAME_STYLE,
2b5f62a0 496 const wxString& name = wxT("frame"));
c801d85f 497
caf0debf
VZ
498 // Extend event processing to search the document manager's event table
499 virtual bool ProcessEvent(wxEvent& event);
c801d85f 500
caf0debf 501 wxDocManager *GetDocumentManager() const { return m_docManager; }
c801d85f 502
caf0debf
VZ
503 void OnExit(wxCommandEvent& event);
504 void OnMRUFile(wxCommandEvent& event);
505 void OnCloseWindow(wxCloseEvent& event);
c801d85f 506
caf0debf
VZ
507protected:
508 wxDocManager *m_docManager;
509
2b5f62a0
VZ
510private:
511 DECLARE_CLASS(wxDocParentFrame)
caf0debf 512 DECLARE_EVENT_TABLE()
22f3361e 513 DECLARE_NO_COPY_CLASS(wxDocParentFrame)
caf0debf 514};
c801d85f 515
caf0debf
VZ
516// ----------------------------------------------------------------------------
517// Provide simple default printing facilities
518// ----------------------------------------------------------------------------
c801d85f 519
caf0debf
VZ
520#if wxUSE_PRINTING_ARCHITECTURE
521class WXDLLEXPORT wxDocPrintout : public wxPrintout
522{
caf0debf 523public:
2b5f62a0 524 wxDocPrintout(wxView *view = (wxView *) NULL, const wxString& title = wxT("Printout"));
caf0debf
VZ
525 bool OnPrintPage(int page);
526 bool HasPage(int page);
527 bool OnBeginDocument(int startPage, int endPage);
528 void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
c801d85f 529
caf0debf 530 virtual wxView *GetView() { return m_printoutView; }
c801d85f 531
caf0debf
VZ
532protected:
533 wxView* m_printoutView;
2b5f62a0
VZ
534
535private:
536 DECLARE_DYNAMIC_CLASS(wxDocPrintout)
22f3361e 537 DECLARE_NO_COPY_CLASS(wxDocPrintout)
c801d85f 538};
caf0debf 539#endif // wxUSE_PRINTING_ARCHITECTURE
c801d85f 540
caf0debf 541// ----------------------------------------------------------------------------
7f555861 542// File history management
caf0debf 543// ----------------------------------------------------------------------------
7f555861 544
caf0debf 545class WXDLLEXPORT wxFileHistory : public wxObject
c801d85f 546{
caf0debf 547public:
e49c85af 548 wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
caf0debf 549 ~wxFileHistory();
7f555861 550
caf0debf
VZ
551 // Operations
552 virtual void AddFileToHistory(const wxString& file);
e49c85af 553 virtual void RemoveFileFromHistory(size_t i);
caf0debf
VZ
554 virtual int GetMaxFiles() const { return m_fileMaxFiles; }
555 virtual void UseMenu(wxMenu *menu);
7f555861 556
caf0debf
VZ
557 // Remove menu from the list (MDI child may be closing)
558 virtual void RemoveMenu(wxMenu *menu);
7f555861 559
caf0debf
VZ
560#if wxUSE_CONFIG
561 virtual void Load(wxConfigBase& config);
562 virtual void Save(wxConfigBase& config);
563#endif // wxUSE_CONFIG
564
565 virtual void AddFilesToMenu();
566 virtual void AddFilesToMenu(wxMenu* menu); // Single menu
567
568 // Accessors
e49c85af 569 virtual wxString GetHistoryFile(size_t i) const;
e49c85af 570 virtual size_t GetCount() const { return m_fileHistoryN; }
caf0debf 571
ae500232 572 const wxList& GetMenus() const { return m_fileMenus; }
caf0debf 573
b5f159ac
VZ
574 // deprecated, use GetCount() instead
575 wxDEPRECATED( size_t GetNoHistoryFiles() const );
7af6b69e 576
caf0debf
VZ
577protected:
578 // Last n files
579 wxChar** m_fileHistory;
580 // Number of files saved
e49c85af 581 size_t m_fileHistoryN;
caf0debf
VZ
582 // Menus to maintain (may need several for an MDI app)
583 wxList m_fileMenus;
584 // Max files to maintain
e49c85af 585 size_t m_fileMaxFiles;
b5f159ac 586
2b5f62a0 587private:
e49c85af
VZ
588 // The ID of the first history menu item (Doesn't have to be wxID_FILE1)
589 wxWindowID m_idBase;
590
2b5f62a0 591 DECLARE_DYNAMIC_CLASS(wxFileHistory)
22f3361e 592 DECLARE_NO_COPY_CLASS(wxFileHistory)
c801d85f
KB
593};
594
b5f159ac
VZ
595inline size_t wxFileHistory::GetNoHistoryFiles() const
596{
597 return m_fileHistoryN;
598}
599
a533f5c1 600#if wxUSE_STD_IOSTREAM
c801d85f
KB
601// For compatibility with existing file formats:
602// converts from/to a stream to/from a temporary file.
dd107c50
VZ
603bool WXDLLEXPORT wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream);
604bool WXDLLEXPORT wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename);
dc1efb1d
JS
605#else
606// For compatibility with existing file formats:
607// converts from/to a stream to/from a temporary file.
608bool WXDLLEXPORT wxTransferFileToStream(const wxString& filename, wxOutputStream& stream);
609bool WXDLLEXPORT wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
e30285ab
VZ
610#endif // wxUSE_STD_IOSTREAM
611
612#endif // wxUSE_DOC_VIEW_ARCHITECTURE
c801d85f 613
caf0debf 614#endif // _WX_DOCH__