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