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