]> git.saurik.com Git - wxWidgets.git/blame - include/wx/docview.h
1. warnings suppressed in wave.cpp
[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
KB
14
15#ifdef __GNUG__
caf0debf 16 #pragma interface "docview.h"
c801d85f
KB
17#endif
18
19#include "wx/defs.h"
20#include "wx/list.h"
21#include "wx/cmndata.h"
22#include "wx/string.h"
23
47d67540 24#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 25 #include "wx/print.h"
c801d85f
KB
26#endif
27
28class WXDLLEXPORT wxWindow;
29class WXDLLEXPORT wxDocument;
30class WXDLLEXPORT wxView;
31class WXDLLEXPORT wxDocTemplate;
32class WXDLLEXPORT wxDocManager;
33class WXDLLEXPORT wxPrintInfo;
34class WXDLLEXPORT wxCommand;
35class WXDLLEXPORT wxCommandProcessor;
36class WXDLLEXPORT wxFileHistory;
7f555861 37class WXDLLEXPORT wxConfigBase;
c801d85f 38
caf0debf 39#include "wx/ioswrap.h"
c801d85f
KB
40
41// Document manager flags
caf0debf
VZ
42enum
43{
44 wxDOC_SDI = 1,
45 wxDOC_MDI,
46 wxDOC_NEW,
47 wxDOC_SILENT,
48 wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
49};
c801d85f
KB
50
51// Document template flags
caf0debf
VZ
52enum
53{
54 wxTEMPLATE_VISIBLE = 1,
55 wxTEMPLATE_INVISIBLE,
56 wxDEFAULT_TEMPLATE_FLAGS = wxTEMPLATE_VISIBLE
57};
c801d85f 58
caf0debf 59#define wxMAX_FILE_HISTORY 9
c801d85f
KB
60
61class WXDLLEXPORT wxDocument : public wxEvtHandler
62{
caf0debf
VZ
63 DECLARE_ABSTRACT_CLASS(wxDocument)
64
65public:
66 wxDocument(wxDocument *parent = (wxDocument *) NULL);
67 ~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 virtual ostream& SaveObject(ostream& stream);
88 virtual istream& LoadObject(istream& stream);
89
90 // Called by wxWindows
91 virtual bool OnSaveDocument(const wxString& filename);
92 virtual bool OnOpenDocument(const wxString& filename);
93 virtual bool OnNewDocument();
94 virtual bool OnCloseDocument();
95
96 // Prompts for saving if about to close a modified document. Returns TRUE
97 // if ok to close the document (may have saved in the meantime, or set
98 // modified to FALSE)
99 virtual bool OnSaveModified();
100
101 // Called by framework if created automatically by the default document
102 // manager: gives document a chance to initialise and (usually) create a
103 // view
104 virtual bool OnCreate(const wxString& path, long flags);
105
106 // By default, creates a base wxCommandProcessor.
107 virtual wxCommandProcessor *OnCreateCommandProcessor();
108 virtual wxCommandProcessor *GetCommandProcessor() const { return m_commandProcessor; }
109 virtual void SetCommandProcessor(wxCommandProcessor *proc) { m_commandProcessor = proc; }
110
111 // Called after a view is added or removed. The default implementation
112 // deletes the document if this is there are no more views.
113 virtual void OnChangedViewList();
114
115 virtual bool DeleteContents();
116
117 virtual bool Draw(wxDC&);
118 virtual bool IsModified() const { return m_documentModified; }
119 virtual void Modify(bool mod) { m_documentModified = mod; }
120
121 virtual bool AddView(wxView *view);
122 virtual bool RemoveView(wxView *view);
123 wxList& GetViews() const { return (wxList&) m_documentViews; }
124 wxView *GetFirstView() const;
125
126 virtual void UpdateAllViews(wxView *sender = (wxView *) NULL, wxObject *hint = (wxObject *) NULL);
127
128 // Remove all views (because we're closing the document)
129 virtual bool DeleteAllViews();
130
131 // Other stuff
132 virtual wxDocManager *GetDocumentManager() const;
133 virtual wxDocTemplate *GetDocumentTemplate() const { return m_documentTemplate; }
134 virtual void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
135
136 // Get title, or filename if no title, else [unnamed]
137 virtual bool GetPrintableName(wxString& buf) const;
138
139 // Returns a window that can be used as a parent for document-related
140 // dialogs. Override if necessary.
141 virtual wxWindow *GetDocumentWindow() const;
142
143protected:
144 wxList m_documentViews;
145 wxString m_documentFile;
146 wxString m_documentTitle;
147 wxString m_documentTypeName;
148 wxDocTemplate* m_documentTemplate;
149 bool m_documentModified;
150 wxDocument* m_documentParent;
151 wxCommandProcessor* m_commandProcessor;
152 bool m_savedYet;
c801d85f
KB
153};
154
155class WXDLLEXPORT wxView: public wxEvtHandler
156{
caf0debf 157 DECLARE_ABSTRACT_CLASS(wxView)
c801d85f 158
caf0debf
VZ
159public:
160 // wxView(wxDocument *doc = (wxDocument *) NULL);
161 wxView();
162 ~wxView();
c801d85f 163
caf0debf
VZ
164 wxDocument *GetDocument() const { return m_viewDocument; }
165 void SetDocument(wxDocument *doc);
c801d85f 166
caf0debf
VZ
167 wxString GetViewName() const { return m_viewTypeName; }
168 void SetViewName(const wxString& name) { m_viewTypeName = name; };
c801d85f 169
caf0debf
VZ
170 wxFrame *GetFrame() const { return m_viewFrame ; }
171 void SetFrame(wxFrame *frame) { m_viewFrame = frame; }
c801d85f 172
caf0debf
VZ
173 virtual void OnActivateView(bool activate, wxView *activeView, wxView *deactiveView);
174 virtual void OnDraw(wxDC *dc) = 0;
175 virtual void OnPrint(wxDC *dc, wxObject *info);
176 virtual void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
177 virtual void OnChangeFilename();
c801d85f 178
caf0debf
VZ
179 // Called by framework if created automatically by the default document
180 // manager class: gives view a chance to initialise
181 virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags)) { return TRUE; };
c801d85f 182
caf0debf
VZ
183 // Checks if the view is the last one for the document; if so, asks user
184 // to confirm save data (if modified). If ok, deletes itself and returns
185 // TRUE.
186 virtual bool Close(bool deleteWindow = TRUE);
187
188 // Override to do cleanup/veto close
189 virtual bool OnClose(bool deleteWindow);
2b854a32 190
e3065973 191#if WXWIN_COMPATIBILITY
caf0debf
VZ
192 // Defeat compiler warning
193 bool OnClose() { return wxEvtHandler::OnClose(); }
2b854a32 194#endif
c801d85f 195
caf0debf
VZ
196 // Extend event processing to search the document's event table
197 virtual bool ProcessEvent(wxEvent& event);
c801d85f 198
caf0debf
VZ
199 // A view's window can call this to notify the view it is (in)active.
200 // The function then notifies the document manager.
201 virtual void Activate(bool activate);
c801d85f 202
caf0debf
VZ
203 wxDocManager *GetDocumentManager() const
204 { return m_viewDocument->GetDocumentManager(); }
c801d85f 205
47d67540 206#if wxUSE_PRINTING_ARCHITECTURE
caf0debf 207 virtual wxPrintout *OnCreatePrintout();
c801d85f
KB
208#endif
209
caf0debf
VZ
210protected:
211 wxDocument* m_viewDocument;
212 wxString m_viewTypeName;
213 wxFrame* m_viewFrame;
c801d85f
KB
214};
215
216// Represents user interface (and other) properties of documents and views
217class WXDLLEXPORT wxDocTemplate: public wxObject
218{
caf0debf
VZ
219DECLARE_CLASS(wxDocTemplate)
220
221friend class WXDLLEXPORT wxDocManager;
222
223public:
224 // Associate document and view types. They're for identifying what view is
225 // associated with what template/document type
226 wxDocTemplate(wxDocManager *manager,
227 const wxString& descr,
228 const wxString& filter,
229 const wxString& dir,
230 const wxString& ext,
231 const wxString& docTypeName,
232 const wxString& viewTypeName,
233 wxClassInfo *docClassInfo = (wxClassInfo *) NULL,
234 wxClassInfo *viewClassInfo = (wxClassInfo *)NULL,
235 long flags = wxDEFAULT_TEMPLATE_FLAGS);
236
237 ~wxDocTemplate();
238
239 // By default, these two member functions dynamically creates document and
240 // view using dynamic instance construction. Override these if you need a
241 // different method of construction.
242 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
243 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
244
245 wxString GetDefaultExtension() const { return m_defaultExt; };
246 wxString GetDescription() const { return m_description; }
247 wxString GetDirectory() const { return m_directory; };
248 wxDocManager *GetDocumentManager() const { return m_documentManager; }
249 void SetDocumentManager(wxDocManager *manager) { m_documentManager = manager; }
250 wxString GetFileFilter() const { return m_fileFilter; };
251 long GetFlags() const { return m_flags; };
252 virtual wxString GetViewName() const { return m_viewTypeName; }
253 virtual wxString GetDocumentName() const { return m_docTypeName; }
254
255 void SetFileFilter(const wxString& filter) { m_fileFilter = filter; };
256 void SetDirectory(const wxString& dir) { m_directory = dir; };
257 void SetDescription(const wxString& descr) { m_description = descr; };
258 void SetDefaultExtension(const wxString& ext) { m_defaultExt = ext; };
259 void SetFlags(long flags) { m_flags = flags; };
260
261 bool IsVisible() const { return ((m_flags & wxTEMPLATE_VISIBLE) == wxTEMPLATE_VISIBLE); }
262
263 virtual bool FileMatchesTemplate(const wxString& path);
264
265protected:
266 long m_flags;
267 wxString m_fileFilter;
268 wxString m_directory;
269 wxString m_description;
270 wxString m_defaultExt;
271 wxString m_docTypeName;
272 wxString m_viewTypeName;
273 wxDocManager* m_documentManager;
274
275 // For dynamic creation of appropriate instances.
276 wxClassInfo* m_docClassInfo;
277 wxClassInfo* m_viewClassInfo;
c801d85f
KB
278};
279
caf0debf
VZ
280// One object of this class may be created in an application, to manage all
281// the templates and documents.
c801d85f
KB
282class WXDLLEXPORT wxDocManager: public wxEvtHandler
283{
caf0debf
VZ
284 DECLARE_DYNAMIC_CLASS(wxDocManager)
285
286public:
287 wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS, bool initialize = TRUE);
288 ~wxDocManager();
289
290 virtual bool Initialize();
291
292 // Handlers for common user commands
293 void OnFileClose(wxCommandEvent& event);
294 void OnFileNew(wxCommandEvent& event);
295 void OnFileOpen(wxCommandEvent& event);
296 void OnFileRevert(wxCommandEvent& event);
297 void OnFileSave(wxCommandEvent& event);
298 void OnFileSaveAs(wxCommandEvent& event);
299 void OnPrint(wxCommandEvent& event);
300 void OnPrintSetup(wxCommandEvent& event);
301 void OnPreview(wxCommandEvent& event);
302 void OnUndo(wxCommandEvent& event);
303 void OnRedo(wxCommandEvent& event);
304
305 // Extend event processing to search the view's event table
306 virtual bool ProcessEvent(wxEvent& event);
307
308 virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
309 virtual wxView *CreateView(wxDocument *doc, long flags = 0);
310 virtual void DeleteTemplate(wxDocTemplate *temp, long flags = 0);
311 virtual bool FlushDoc(wxDocument *doc);
312 virtual wxDocTemplate *MatchTemplate(const wxString& path);
313 virtual wxDocTemplate *SelectDocumentPath(wxDocTemplate **templates,
314 int noTemplates, wxString& path, long flags, bool save = FALSE);
315 virtual wxDocTemplate *SelectDocumentType(wxDocTemplate **templates,
316 int noTemplates);
317 virtual wxDocTemplate *SelectViewType(wxDocTemplate **templates,
318 int noTemplates);
319 virtual wxDocTemplate *FindTemplateForPath(const wxString& path);
320
321 void AssociateTemplate(wxDocTemplate *temp);
322 void DisassociateTemplate(wxDocTemplate *temp);
323
324 wxDocument *GetCurrentDocument() const;
325
326 void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
327 int GetMaxDocsOpen() const { return m_maxDocsOpen; }
328
329 // Add and remove a document from the manager's list
330 void AddDocument(wxDocument *doc);
331 void RemoveDocument(wxDocument *doc);
332
333 // Clear remaining documents and templates
334 bool Clear(bool force = TRUE);
335
336 // Views or windows should inform the document manager
337 // when a view is going in or out of focus
338 virtual void ActivateView(wxView *view, bool activate = TRUE, bool deleting = FALSE);
339 virtual wxView *GetCurrentView() const;
340
341 virtual wxList& GetDocuments() const { return (wxList&) m_docs; }
342
343 // Make a default document name
344 virtual bool MakeDefaultName(wxString& buf);
345
346 virtual wxFileHistory *OnCreateFileHistory();
347 virtual wxFileHistory *GetFileHistory() const { return m_fileHistory; }
348
349 // File history management
350 virtual void AddFileToHistory(const wxString& file);
351 virtual int GetNoHistoryFiles() const;
352 virtual wxString GetHistoryFile(int i) const;
353 virtual void FileHistoryUseMenu(wxMenu *menu);
354 virtual void FileHistoryRemoveMenu(wxMenu *menu);
702ca7c0 355#if wxUSE_CONFIG
caf0debf
VZ
356 virtual void FileHistoryLoad(wxConfigBase& config);
357 virtual void FileHistorySave(wxConfigBase& config);
358#endif // wxUSE_CONFIG
359
360 virtual void FileHistoryAddFilesToMenu();
361 virtual void FileHistoryAddFilesToMenu(wxMenu* menu);
362
363protected:
364 long m_flags;
365 int m_defaultDocumentNameCounter;
366 int m_maxDocsOpen;
367 wxList m_docs;
368 wxList m_templates;
369 wxView* m_currentView;
370 wxFileHistory* m_fileHistory;
371
372 DECLARE_EVENT_TABLE()
c801d85f
KB
373};
374
caf0debf
VZ
375// ----------------------------------------------------------------------------
376// A default child frame
377// ----------------------------------------------------------------------------
c801d85f 378
caf0debf 379class WXDLLEXPORT wxDocChildFrame : public wxFrame
c801d85f 380{
caf0debf
VZ
381 DECLARE_CLASS(wxDocChildFrame)
382
383public:
384 wxDocChildFrame(wxDocument *doc,
385 wxView *view,
386 wxFrame *frame,
387 wxWindowID id,
388 const wxString& title,
389 const wxPoint& pos = wxDefaultPosition,
390 const wxSize& size = wxDefaultSize,
391 long type = wxDEFAULT_FRAME_STYLE,
392 const wxString& name = "frame");
393 ~wxDocChildFrame();
394
395 // Extend event processing to search the view's event table
396 virtual bool ProcessEvent(wxEvent& event);
397
398 void OnActivate(wxActivateEvent& event);
399 void OnCloseWindow(wxCloseEvent& event);
400
401 wxDocument *GetDocument() const { return m_childDocument; }
402 wxView *GetView() const { return m_childView; }
403 void SetDocument(wxDocument *doc) { m_childDocument = doc; }
404 void SetView(wxView *view) { m_childView = view; }
405
406protected:
407 wxDocument* m_childDocument;
408 wxView* m_childView;
409
410 DECLARE_EVENT_TABLE()
411};
c801d85f 412
caf0debf
VZ
413// ----------------------------------------------------------------------------
414// A default parent frame
415// ----------------------------------------------------------------------------
c801d85f 416
caf0debf
VZ
417class WXDLLEXPORT wxDocParentFrame : public wxFrame
418{
419 DECLARE_CLASS(wxDocParentFrame)
c801d85f 420
caf0debf
VZ
421public:
422 wxDocParentFrame(wxDocManager *manager,
423 wxFrame *frame,
424 wxWindowID id,
425 const wxString& title,
426 const wxPoint& pos = wxDefaultPosition,
427 const wxSize& size = wxDefaultSize,
428 long type = wxDEFAULT_FRAME_STYLE,
429 const wxString& name = "frame");
c801d85f 430
caf0debf
VZ
431 // Extend event processing to search the document manager's event table
432 virtual bool ProcessEvent(wxEvent& event);
c801d85f 433
caf0debf 434 wxDocManager *GetDocumentManager() const { return m_docManager; }
c801d85f 435
caf0debf
VZ
436 void OnExit(wxCommandEvent& event);
437 void OnMRUFile(wxCommandEvent& event);
438 void OnCloseWindow(wxCloseEvent& event);
c801d85f 439
caf0debf
VZ
440protected:
441 wxDocManager *m_docManager;
442
443 DECLARE_EVENT_TABLE()
444};
c801d85f 445
caf0debf
VZ
446// ----------------------------------------------------------------------------
447// Provide simple default printing facilities
448// ----------------------------------------------------------------------------
c801d85f 449
caf0debf
VZ
450#if wxUSE_PRINTING_ARCHITECTURE
451class WXDLLEXPORT wxDocPrintout : public wxPrintout
452{
453 DECLARE_DYNAMIC_CLASS(wxDocPrintout)
c801d85f 454
caf0debf
VZ
455public:
456 wxDocPrintout(wxView *view = (wxView *) NULL, const wxString& title = "Printout");
457 bool OnPrintPage(int page);
458 bool HasPage(int page);
459 bool OnBeginDocument(int startPage, int endPage);
460 void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
c801d85f 461
caf0debf 462 virtual wxView *GetView() { return m_printoutView; }
c801d85f 463
caf0debf
VZ
464protected:
465 wxView* m_printoutView;
c801d85f 466};
caf0debf 467#endif // wxUSE_PRINTING_ARCHITECTURE
c801d85f 468
caf0debf
VZ
469// ----------------------------------------------------------------------------
470// Command processing framework
471// ----------------------------------------------------------------------------
c801d85f 472
caf0debf 473class WXDLLEXPORT wxCommand : public wxObject
c801d85f 474{
caf0debf 475 DECLARE_CLASS(wxCommand)
c801d85f 476
caf0debf
VZ
477public:
478 wxCommand(bool canUndoIt = FALSE, const wxString& name = "");
479 ~wxCommand();
c801d85f 480
caf0debf
VZ
481 // Override this to perform a command
482 virtual bool Do() = 0;
483
484 // Override this to undo a command
485 virtual bool Undo() = 0;
486
487 virtual bool CanUndo() const { return m_canUndo; }
488 virtual wxString GetName() const { return m_commandName; }
489
490protected:
491 bool m_canUndo;
492 wxString m_commandName;
c801d85f
KB
493};
494
caf0debf 495class WXDLLEXPORT wxCommandProcessor : public wxObject
c801d85f 496{
caf0debf
VZ
497 DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
498
499public:
500 wxCommandProcessor(int maxCommands = 100);
501 ~wxCommandProcessor();
502
503 // Pass a command to the processor. The processor calls Do(); if
504 // successful, is appended to the command history unless storeIt is FALSE.
505 virtual bool Submit(wxCommand *command, bool storeIt = TRUE);
506 virtual bool Undo();
507 virtual bool Redo();
508 virtual bool CanUndo() const;
509 virtual bool CanRedo() const;
510
511 // Call this to manage an edit menu.
512 void SetEditMenu(wxMenu *menu) { m_commandEditMenu = menu; }
513 wxMenu *GetEditMenu() const { return m_commandEditMenu; }
514 virtual void SetMenuStrings();
515 virtual void Initialize();
516
517 wxList& GetCommands() const { return (wxList&) m_commands; }
518 int GetMaxCommands() const { return m_maxNoCommands; }
519 virtual void ClearCommands();
520
521protected:
522 int m_maxNoCommands;
523 wxList m_commands;
524 wxNode* m_currentCommand;
525 wxMenu* m_commandEditMenu;
c801d85f
KB
526};
527
caf0debf 528// ----------------------------------------------------------------------------
7f555861 529// File history management
caf0debf 530// ----------------------------------------------------------------------------
7f555861 531
caf0debf 532class WXDLLEXPORT wxFileHistory : public wxObject
c801d85f 533{
caf0debf 534 DECLARE_DYNAMIC_CLASS(wxFileHistory)
c801d85f 535
caf0debf
VZ
536public:
537 wxFileHistory(int maxFiles = 9);
538 ~wxFileHistory();
7f555861 539
caf0debf
VZ
540 // Operations
541 virtual void AddFileToHistory(const wxString& file);
542 virtual int GetMaxFiles() const { return m_fileMaxFiles; }
543 virtual void UseMenu(wxMenu *menu);
7f555861 544
caf0debf
VZ
545 // Remove menu from the list (MDI child may be closing)
546 virtual void RemoveMenu(wxMenu *menu);
7f555861 547
caf0debf
VZ
548#if wxUSE_CONFIG
549 virtual void Load(wxConfigBase& config);
550 virtual void Save(wxConfigBase& config);
551#endif // wxUSE_CONFIG
552
553 virtual void AddFilesToMenu();
554 virtual void AddFilesToMenu(wxMenu* menu); // Single menu
555
556 // Accessors
557 virtual wxString GetHistoryFile(int i) const;
558
559 // A synonym for GetNoHistoryFiles
560 virtual int GetCount() const { return m_fileHistoryN; }
561 int GetNoHistoryFiles() const { return m_fileHistoryN; }
562
563 wxList& GetMenus() const { return (wxList&) m_fileMenus; }
564
565protected:
566 // Last n files
567 wxChar** m_fileHistory;
568 // Number of files saved
569 int m_fileHistoryN;
570 // Menus to maintain (may need several for an MDI app)
571 wxList m_fileMenus;
572 // Max files to maintain
573 int m_fileMaxFiles;
c801d85f
KB
574};
575
576// For compatibility with existing file formats:
577// converts from/to a stream to/from a temporary file.
578bool WXDLLEXPORT wxTransferFileToStream(const wxString& filename, ostream& stream);
579bool WXDLLEXPORT wxTransferStreamToFile(istream& stream, const wxString& filename);
580
caf0debf 581#endif // _WX_DOCH__