applied an extended version of patch 685795: clean up view [de]activation
[wxWidgets.git] / src / common / docview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/docview.cpp
3 // Purpose: Document/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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "docview.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_DOC_VIEW_ARCHITECTURE
32
33 #ifndef WX_PRECOMP
34 #include "wx/string.h"
35 #include "wx/utils.h"
36 #include "wx/app.h"
37 #include "wx/dc.h"
38 #include "wx/dialog.h"
39 #include "wx/menu.h"
40 #include "wx/list.h"
41 #include "wx/filedlg.h"
42 #include "wx/intl.h"
43 #include "wx/log.h"
44 #endif
45
46 #include "wx/ffile.h"
47
48 #ifdef __WXMAC__
49 #include "wx/filename.h"
50 #endif
51
52 #ifdef __WXGTK__
53 #include "wx/mdi.h"
54 #endif
55
56 #if wxUSE_PRINTING_ARCHITECTURE
57 #include "wx/prntbase.h"
58 #include "wx/printdlg.h"
59 #endif
60
61 #include "wx/msgdlg.h"
62 #include "wx/choicdlg.h"
63 #include "wx/docview.h"
64 #include "wx/confbase.h"
65 #include "wx/file.h"
66 #include "wx/cmdproc.h"
67
68 #include <stdio.h>
69 #include <string.h>
70
71 #if wxUSE_STD_IOSTREAM
72 #include "wx/ioswrap.h"
73 #if wxUSE_IOSTREAMH
74 #include <fstream.h>
75 #else
76 #include <fstream>
77 #endif
78 #else
79 #include "wx/wfstream.h"
80 #endif
81
82 // ----------------------------------------------------------------------------
83 // wxWindows macros
84 // ----------------------------------------------------------------------------
85
86 IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
87 IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
88 IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
89 IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler)
90 IMPLEMENT_CLASS(wxDocChildFrame, wxFrame)
91 IMPLEMENT_CLASS(wxDocParentFrame, wxFrame)
92
93 #if wxUSE_PRINTING_ARCHITECTURE
94 IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout)
95 #endif
96
97 IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
98
99 // ----------------------------------------------------------------------------
100 // function prototypes
101 // ----------------------------------------------------------------------------
102
103 static inline wxString FindExtension(const wxChar *path);
104 static wxWindow* wxFindSuitableParent(void);
105
106 // ----------------------------------------------------------------------------
107 // local constants
108 // ----------------------------------------------------------------------------
109
110 static const wxChar *s_MRUEntryFormat = wxT("&%d %s");
111
112 // ============================================================================
113 // implementation
114 // ============================================================================
115
116 // ----------------------------------------------------------------------------
117 // local functions
118 // ----------------------------------------------------------------------------
119
120 static wxString FindExtension(const wxChar *path)
121 {
122 wxString ext;
123 wxSplitPath(path, NULL, NULL, &ext);
124
125 // VZ: extensions are considered not case sensitive - is this really a good
126 // idea?
127 return ext.MakeLower();
128 }
129
130 // ----------------------------------------------------------------------------
131 // Definition of wxDocument
132 // ----------------------------------------------------------------------------
133
134 wxDocument::wxDocument(wxDocument *parent)
135 {
136 m_documentModified = FALSE;
137 m_documentParent = parent;
138 m_documentTemplate = (wxDocTemplate *) NULL;
139 m_commandProcessor = (wxCommandProcessor*) NULL;
140 m_savedYet = FALSE;
141 }
142
143 bool wxDocument::DeleteContents()
144 {
145 return TRUE;
146 }
147
148 wxDocument::~wxDocument()
149 {
150 DeleteContents();
151
152 if (m_commandProcessor)
153 delete m_commandProcessor;
154
155 if (GetDocumentManager())
156 GetDocumentManager()->RemoveDocument(this);
157
158 // Not safe to do here, since it'll invoke virtual view functions
159 // expecting to see valid derived objects: and by the time we get here,
160 // we've called destructors higher up.
161 //DeleteAllViews();
162 }
163
164 bool wxDocument::Close()
165 {
166 if (OnSaveModified())
167 return OnCloseDocument();
168 else
169 return FALSE;
170 }
171
172 bool wxDocument::OnCloseDocument()
173 {
174 // Tell all views that we're about to close
175 NotifyClosing();
176 DeleteContents();
177 Modify(FALSE);
178 return TRUE;
179 }
180
181 // Note that this implicitly deletes the document when the last view is
182 // deleted.
183 bool wxDocument::DeleteAllViews()
184 {
185 wxDocManager* manager = GetDocumentManager();
186
187 wxNode *node = m_documentViews.GetFirst();
188 while (node)
189 {
190 wxView *view = (wxView *)node->GetData();
191 if (!view->Close())
192 return FALSE;
193
194 wxNode *next = node->GetNext();
195
196 delete view; // Deletes node implicitly
197 node = next;
198 }
199 // If we haven't yet deleted the document (for example
200 // if there were no views) then delete it.
201 if (manager && manager->GetDocuments().Member(this))
202 delete this;
203
204 return TRUE;
205 }
206
207 wxView *wxDocument::GetFirstView() const
208 {
209 if (m_documentViews.GetCount() == 0)
210 return (wxView *) NULL;
211 return (wxView *)m_documentViews.GetFirst()->GetData();
212 }
213
214 wxDocManager *wxDocument::GetDocumentManager() const
215 {
216 return (m_documentTemplate ? m_documentTemplate->GetDocumentManager() : (wxDocManager*) NULL);
217 }
218
219 bool wxDocument::OnNewDocument()
220 {
221 if (!OnSaveModified())
222 return FALSE;
223
224 if (OnCloseDocument()==FALSE) return FALSE;
225 DeleteContents();
226 Modify(FALSE);
227 SetDocumentSaved(FALSE);
228
229 wxString name;
230 GetDocumentManager()->MakeDefaultName(name);
231 SetTitle(name);
232 SetFilename(name, TRUE);
233
234 return TRUE;
235 }
236
237 bool wxDocument::Save()
238 {
239 if (!IsModified() && m_savedYet)
240 return TRUE;
241
242 if ( m_documentFile.empty() || !m_savedYet )
243 return SaveAs();
244
245 return OnSaveDocument(m_documentFile);
246 }
247
248 bool wxDocument::SaveAs()
249 {
250 wxDocTemplate *docTemplate = GetDocumentTemplate();
251 if (!docTemplate)
252 return FALSE;
253
254 wxString tmp = wxFileSelector(_("Save as"),
255 docTemplate->GetDirectory(),
256 wxFileNameFromPath(GetFilename()),
257 docTemplate->GetDefaultExtension(),
258 docTemplate->GetFileFilter(),
259 wxSAVE | wxOVERWRITE_PROMPT,
260 GetDocumentWindow());
261
262 if (tmp.IsEmpty())
263 return FALSE;
264
265 wxString fileName(tmp);
266 wxString path, name, ext;
267 wxSplitPath(fileName, & path, & name, & ext);
268
269 if (ext.IsEmpty() || ext == wxT(""))
270 {
271 fileName += wxT(".");
272 fileName += docTemplate->GetDefaultExtension();
273 }
274
275 SetFilename(fileName);
276 SetTitle(wxFileNameFromPath(fileName));
277
278 // Notify the views that the filename has changed
279 wxNode *node = m_documentViews.GetFirst();
280 while (node)
281 {
282 wxView *view = (wxView *)node->GetData();
283 view->OnChangeFilename();
284 node = node->GetNext();
285 }
286
287 // Files that were not saved correctly are not added to the FileHistory.
288 if (!OnSaveDocument(m_documentFile))
289 return FALSE;
290
291 // A file that doesn't use the default extension of its document template cannot be opened
292 // via the FileHistory, so we do not add it.
293 if (docTemplate->FileMatchesTemplate(fileName))
294 {
295 GetDocumentManager()->AddFileToHistory(fileName);
296 }
297 else
298 {
299 // The user will probably not be able to open the file again, so
300 // we could warn about the wrong file-extension here.
301 }
302 return TRUE;
303 }
304
305 bool wxDocument::OnSaveDocument(const wxString& file)
306 {
307 if ( !file )
308 return FALSE;
309
310 wxString msgTitle;
311 if (wxTheApp->GetAppName() != wxT(""))
312 msgTitle = wxTheApp->GetAppName();
313 else
314 msgTitle = wxString(_("File error"));
315
316 #if wxUSE_STD_IOSTREAM
317 wxSTD ofstream store(file.mb_str());
318 if (store.fail() || store.bad())
319 #else
320 wxFileOutputStream store(file);
321 if (store.GetLastError() != wxSTREAM_NO_ERROR)
322 #endif
323 {
324 (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
325 GetDocumentWindow());
326 // Saving error
327 return FALSE;
328 }
329 if (!SaveObject(store))
330 {
331 (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
332 GetDocumentWindow());
333 // Saving error
334 return FALSE;
335 }
336 Modify(FALSE);
337 SetFilename(file);
338 SetDocumentSaved(TRUE);
339 #ifdef __WXMAC__
340 wxFileName fn(file) ;
341 fn.MacSetDefaultTypeAndCreator() ;
342 #endif
343 return TRUE;
344 }
345
346 bool wxDocument::OnOpenDocument(const wxString& file)
347 {
348 if (!OnSaveModified())
349 return FALSE;
350
351 wxString msgTitle;
352 if (wxTheApp->GetAppName() != wxT(""))
353 msgTitle = wxTheApp->GetAppName();
354 else
355 msgTitle = wxString(_("File error"));
356
357 #if wxUSE_STD_IOSTREAM
358 wxSTD ifstream store(file.mb_str());
359 if (store.fail() || store.bad())
360 #else
361 wxFileInputStream store(file);
362 if (store.GetLastError() != wxSTREAM_NO_ERROR)
363 #endif
364 {
365 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
366 GetDocumentWindow());
367 return FALSE;
368 }
369 #if wxUSE_STD_IOSTREAM
370 LoadObject(store);
371 if ( !store && !store.eof() )
372 #else
373 int res = LoadObject(store).GetLastError();
374 if ((res != wxSTREAM_NO_ERROR) &&
375 (res != wxSTREAM_EOF))
376 #endif
377 {
378 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
379 GetDocumentWindow());
380 return FALSE;
381 }
382 SetFilename(file, TRUE);
383 Modify(FALSE);
384 m_savedYet = TRUE;
385
386 UpdateAllViews();
387
388 return TRUE;
389 }
390
391 #if wxUSE_STD_IOSTREAM
392 wxSTD istream& wxDocument::LoadObject(wxSTD istream& stream)
393 #else
394 wxInputStream& wxDocument::LoadObject(wxInputStream& stream)
395 #endif
396 {
397 return stream;
398 }
399
400 #if wxUSE_STD_IOSTREAM
401 wxSTD ostream& wxDocument::SaveObject(wxSTD ostream& stream)
402 #else
403 wxOutputStream& wxDocument::SaveObject(wxOutputStream& stream)
404 #endif
405 {
406 return stream;
407 }
408
409 bool wxDocument::Revert()
410 {
411 return FALSE;
412 }
413
414
415 // Get title, or filename if no title, else unnamed
416 bool wxDocument::GetPrintableName(wxString& buf) const
417 {
418 if (m_documentTitle != wxT(""))
419 {
420 buf = m_documentTitle;
421 return TRUE;
422 }
423 else if (m_documentFile != wxT(""))
424 {
425 buf = wxFileNameFromPath(m_documentFile);
426 return TRUE;
427 }
428 else
429 {
430 buf = _("unnamed");
431 return TRUE;
432 }
433 }
434
435 wxWindow *wxDocument::GetDocumentWindow() const
436 {
437 wxView *view = GetFirstView();
438 if (view)
439 return view->GetFrame();
440 else
441 return wxTheApp->GetTopWindow();
442 }
443
444 wxCommandProcessor *wxDocument::OnCreateCommandProcessor()
445 {
446 return new wxCommandProcessor;
447 }
448
449 // TRUE if safe to close
450 bool wxDocument::OnSaveModified()
451 {
452 if (IsModified())
453 {
454 wxString title;
455 GetPrintableName(title);
456
457 wxString msgTitle;
458 if (wxTheApp->GetAppName() != wxT(""))
459 msgTitle = wxTheApp->GetAppName();
460 else
461 msgTitle = wxString(_("Warning"));
462
463 wxString prompt;
464 prompt.Printf(_("Do you want to save changes to document %s?"),
465 (const wxChar *)title);
466 int res = wxMessageBox(prompt, msgTitle,
467 wxYES_NO|wxCANCEL|wxICON_QUESTION,
468 GetDocumentWindow());
469 if (res == wxNO)
470 {
471 Modify(FALSE);
472 return TRUE;
473 }
474 else if (res == wxYES)
475 return Save();
476 else if (res == wxCANCEL)
477 return FALSE;
478 }
479 return TRUE;
480 }
481
482 bool wxDocument::Draw(wxDC& WXUNUSED(context))
483 {
484 return TRUE;
485 }
486
487 bool wxDocument::AddView(wxView *view)
488 {
489 if (!m_documentViews.Member(view))
490 {
491 m_documentViews.Append(view);
492 OnChangedViewList();
493 }
494 return TRUE;
495 }
496
497 bool wxDocument::RemoveView(wxView *view)
498 {
499 (void)m_documentViews.DeleteObject(view);
500 OnChangedViewList();
501 return TRUE;
502 }
503
504 bool wxDocument::OnCreate(const wxString& WXUNUSED(path), long flags)
505 {
506 if (GetDocumentTemplate()->CreateView(this, flags))
507 return TRUE;
508 else
509 return FALSE;
510 }
511
512 // Called after a view is added or removed.
513 // The default implementation deletes the document if
514 // there are no more views.
515 void wxDocument::OnChangedViewList()
516 {
517 if (m_documentViews.GetCount() == 0)
518 {
519 if (OnSaveModified())
520 {
521 delete this;
522 }
523 }
524 }
525
526 void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint)
527 {
528 wxNode *node = m_documentViews.GetFirst();
529 while (node)
530 {
531 wxView *view = (wxView *)node->GetData();
532 if (view != sender)
533 view->OnUpdate(sender, hint);
534 node = node->GetNext();
535 }
536 }
537
538 void wxDocument::NotifyClosing()
539 {
540 wxNode *node = m_documentViews.GetFirst();
541 while (node)
542 {
543 wxView *view = (wxView *)node->GetData();
544 view->OnClosingDocument();
545 node = node->GetNext();
546 }
547 }
548
549 void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
550 {
551 m_documentFile = filename;
552 if ( notifyViews )
553 {
554 // Notify the views that the filename has changed
555 wxNode *node = m_documentViews.GetFirst();
556 while (node)
557 {
558 wxView *view = (wxView *)node->GetData();
559 view->OnChangeFilename();
560 node = node->GetNext();
561 }
562 }
563 }
564
565 // ----------------------------------------------------------------------------
566 // Document view
567 // ----------------------------------------------------------------------------
568
569 wxView::wxView()
570 {
571 m_viewDocument = (wxDocument*) NULL;
572
573 m_viewFrame = (wxFrame *) NULL;
574 }
575
576 wxView::~wxView()
577 {
578 GetDocumentManager()->ActivateView(this, FALSE);
579 m_viewDocument->RemoveView(this);
580 }
581
582 // Extend event processing to search the document's event table
583 bool wxView::ProcessEvent(wxEvent& event)
584 {
585 if ( !GetDocument() || !GetDocument()->ProcessEvent(event) )
586 return wxEvtHandler::ProcessEvent(event);
587
588 return TRUE;
589 }
590
591 void wxView::OnActivateView(bool WXUNUSED(activate), wxView *WXUNUSED(activeView), wxView *WXUNUSED(deactiveView))
592 {
593 }
594
595 void wxView::OnPrint(wxDC *dc, wxObject *WXUNUSED(info))
596 {
597 OnDraw(dc);
598 }
599
600 void wxView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
601 {
602 }
603
604 void wxView::OnChangeFilename()
605 {
606 if (GetFrame() && GetDocument())
607 {
608 wxString title;
609
610 GetDocument()->GetPrintableName(title);
611
612 GetFrame()->SetTitle(title);
613 }
614 }
615
616 void wxView::SetDocument(wxDocument *doc)
617 {
618 m_viewDocument = doc;
619 if (doc)
620 doc->AddView(this);
621 }
622
623 bool wxView::Close(bool deleteWindow)
624 {
625 if (OnClose(deleteWindow))
626 return TRUE;
627 else
628 return FALSE;
629 }
630
631 void wxView::Activate(bool activate)
632 {
633 if (GetDocument() && GetDocumentManager())
634 {
635 OnActivateView(activate, this, GetDocumentManager()->GetCurrentView());
636 GetDocumentManager()->ActivateView(this, activate);
637 }
638 }
639
640 bool wxView::OnClose(bool WXUNUSED(deleteWindow))
641 {
642 return GetDocument() ? GetDocument()->Close() : TRUE;
643 }
644
645 #if wxUSE_PRINTING_ARCHITECTURE
646 wxPrintout *wxView::OnCreatePrintout()
647 {
648 return new wxDocPrintout(this);
649 }
650 #endif // wxUSE_PRINTING_ARCHITECTURE
651
652 // ----------------------------------------------------------------------------
653 // wxDocTemplate
654 // ----------------------------------------------------------------------------
655
656 wxDocTemplate::wxDocTemplate(wxDocManager *manager,
657 const wxString& descr,
658 const wxString& filter,
659 const wxString& dir,
660 const wxString& ext,
661 const wxString& docTypeName,
662 const wxString& viewTypeName,
663 wxClassInfo *docClassInfo,
664 wxClassInfo *viewClassInfo,
665 long flags)
666 {
667 m_documentManager = manager;
668 m_description = descr;
669 m_directory = dir;
670 m_defaultExt = ext;
671 m_fileFilter = filter;
672 m_flags = flags;
673 m_docTypeName = docTypeName;
674 m_viewTypeName = viewTypeName;
675 m_documentManager->AssociateTemplate(this);
676
677 m_docClassInfo = docClassInfo;
678 m_viewClassInfo = viewClassInfo;
679 }
680
681 wxDocTemplate::~wxDocTemplate()
682 {
683 m_documentManager->DisassociateTemplate(this);
684 }
685
686 // Tries to dynamically construct an object of the right class.
687 wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
688 {
689 if (!m_docClassInfo)
690 return (wxDocument *) NULL;
691 wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject();
692 doc->SetFilename(path);
693 doc->SetDocumentTemplate(this);
694 GetDocumentManager()->AddDocument(doc);
695 doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
696
697 if (doc->OnCreate(path, flags))
698 return doc;
699 else
700 {
701 if (GetDocumentManager()->GetDocuments().Member(doc))
702 doc->DeleteAllViews();
703 return (wxDocument *) NULL;
704 }
705 }
706
707 wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
708 {
709 if (!m_viewClassInfo)
710 return (wxView *) NULL;
711 wxView *view = (wxView *)m_viewClassInfo->CreateObject();
712 view->SetDocument(doc);
713 if (view->OnCreate(doc, flags))
714 {
715 return view;
716 }
717 else
718 {
719 delete view;
720 return (wxView *) NULL;
721 }
722 }
723
724 // The default (very primitive) format detection: check is the extension is
725 // that of the template
726 bool wxDocTemplate::FileMatchesTemplate(const wxString& path)
727 {
728 return GetDefaultExtension().IsSameAs(FindExtension(path));
729 }
730
731 // ----------------------------------------------------------------------------
732 // wxDocManager
733 // ----------------------------------------------------------------------------
734
735 BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
736 EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen)
737 EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose)
738 EVT_MENU(wxID_CLOSE_ALL, wxDocManager::OnFileCloseAll)
739 EVT_MENU(wxID_REVERT, wxDocManager::OnFileRevert)
740 EVT_MENU(wxID_NEW, wxDocManager::OnFileNew)
741 EVT_MENU(wxID_SAVE, wxDocManager::OnFileSave)
742 EVT_MENU(wxID_SAVEAS, wxDocManager::OnFileSaveAs)
743 EVT_MENU(wxID_UNDO, wxDocManager::OnUndo)
744 EVT_MENU(wxID_REDO, wxDocManager::OnRedo)
745
746 EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
747 EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose)
748 EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateFileClose)
749 EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert)
750 EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
751 EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
752 EVT_UPDATE_UI(wxID_SAVEAS, wxDocManager::OnUpdateFileSaveAs)
753 EVT_UPDATE_UI(wxID_UNDO, wxDocManager::OnUpdateUndo)
754 EVT_UPDATE_UI(wxID_REDO, wxDocManager::OnUpdateRedo)
755
756 #if wxUSE_PRINTING_ARCHITECTURE
757 EVT_MENU(wxID_PRINT, wxDocManager::OnPrint)
758 EVT_MENU(wxID_PRINT_SETUP, wxDocManager::OnPrintSetup)
759 EVT_MENU(wxID_PREVIEW, wxDocManager::OnPreview)
760
761 EVT_UPDATE_UI(wxID_PRINT, wxDocManager::OnUpdatePrint)
762 EVT_UPDATE_UI(wxID_PRINT_SETUP, wxDocManager::OnUpdatePrintSetup)
763 EVT_UPDATE_UI(wxID_PREVIEW, wxDocManager::OnUpdatePreview)
764 #endif
765 END_EVENT_TABLE()
766
767 wxDocManager* wxDocManager::sm_docManager = (wxDocManager*) NULL;
768
769 wxDocManager::wxDocManager(long flags, bool initialize)
770 {
771 m_defaultDocumentNameCounter = 1;
772 m_flags = flags;
773 m_currentView = (wxView *) NULL;
774 m_maxDocsOpen = 10000;
775 m_fileHistory = (wxFileHistory *) NULL;
776 if (initialize)
777 Initialize();
778 sm_docManager = this;
779 }
780
781 wxDocManager::~wxDocManager()
782 {
783 Clear();
784 if (m_fileHistory)
785 delete m_fileHistory;
786 sm_docManager = (wxDocManager*) NULL;
787 }
788
789 // closes the specified document
790 bool wxDocManager::CloseDocument(wxDocument* doc, bool force)
791 {
792 if (doc->Close() || force)
793 {
794 // Implicitly deletes the document when
795 // the last view is deleted
796 doc->DeleteAllViews();
797
798 // Check we're really deleted
799 if (m_docs.Member(doc))
800 delete doc;
801
802 return TRUE;
803 }
804 return FALSE;
805 }
806
807 bool wxDocManager::CloseDocuments(bool force)
808 {
809 wxNode *node = m_docs.GetFirst();
810 while (node)
811 {
812 wxDocument *doc = (wxDocument *)node->GetData();
813 wxNode *next = node->GetNext();
814
815 if (!CloseDocument(doc, force))
816 return FALSE;
817
818 // This assumes that documents are not connected in
819 // any way, i.e. deleting one document does NOT
820 // delete another.
821 node = next;
822 }
823 return TRUE;
824 }
825
826 bool wxDocManager::Clear(bool force)
827 {
828 if (!CloseDocuments(force))
829 return FALSE;
830
831 wxNode *node = m_templates.GetFirst();
832 while (node)
833 {
834 wxDocTemplate *templ = (wxDocTemplate*) node->GetData();
835 wxNode* next = node->GetNext();
836 delete templ;
837 node = next;
838 }
839 return TRUE;
840 }
841
842 bool wxDocManager::Initialize()
843 {
844 m_fileHistory = OnCreateFileHistory();
845 return TRUE;
846 }
847
848 wxFileHistory *wxDocManager::OnCreateFileHistory()
849 {
850 return new wxFileHistory;
851 }
852
853 void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event))
854 {
855 wxDocument *doc = GetCurrentDocument();
856 if (!doc)
857 return;
858 if (doc->Close())
859 {
860 doc->DeleteAllViews();
861 if (m_docs.Member(doc))
862 delete doc;
863 }
864 }
865
866 void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event))
867 {
868 CloseDocuments(FALSE);
869 }
870
871 void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event))
872 {
873 CreateDocument( wxT(""), wxDOC_NEW );
874 }
875
876 void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event))
877 {
878 if ( !CreateDocument( wxT(""), 0) )
879 {
880 OnOpenFileFailure();
881 }
882 }
883
884 void wxDocManager::OnFileRevert(wxCommandEvent& WXUNUSED(event))
885 {
886 wxDocument *doc = GetCurrentDocument();
887 if (!doc)
888 return;
889 doc->Revert();
890 }
891
892 void wxDocManager::OnFileSave(wxCommandEvent& WXUNUSED(event))
893 {
894 wxDocument *doc = GetCurrentDocument();
895 if (!doc)
896 return;
897 doc->Save();
898 }
899
900 void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))
901 {
902 wxDocument *doc = GetCurrentDocument();
903 if (!doc)
904 return;
905 doc->SaveAs();
906 }
907
908 void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
909 {
910 #if wxUSE_PRINTING_ARCHITECTURE
911 wxView *view = GetCurrentView();
912 if (!view)
913 return;
914
915 wxPrintout *printout = view->OnCreatePrintout();
916 if (printout)
917 {
918 wxPrinter printer;
919 printer.Print(view->GetFrame(), printout, TRUE);
920
921 delete printout;
922 }
923 #endif // wxUSE_PRINTING_ARCHITECTURE
924 }
925
926 void wxDocManager::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
927 {
928 #if wxUSE_PRINTING_ARCHITECTURE
929 wxWindow *parentWin = wxTheApp->GetTopWindow();
930 wxView *view = GetCurrentView();
931 if (view)
932 parentWin = view->GetFrame();
933
934 wxPrintDialogData data;
935
936 wxPrintDialog printerDialog(parentWin, &data);
937 printerDialog.GetPrintDialogData().SetSetupDialog(TRUE);
938 printerDialog.ShowModal();
939 #endif // wxUSE_PRINTING_ARCHITECTURE
940 }
941
942 void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
943 {
944 #if wxUSE_PRINTING_ARCHITECTURE
945 wxView *view = GetCurrentView();
946 if (!view)
947 return;
948
949 wxPrintout *printout = view->OnCreatePrintout();
950 if (printout)
951 {
952 // Pass two printout objects: for preview, and possible printing.
953 wxPrintPreviewBase *preview = (wxPrintPreviewBase *) NULL;
954 preview = new wxPrintPreview(printout, view->OnCreatePrintout());
955
956 wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"),
957 wxPoint(100, 100), wxSize(600, 650));
958 frame->Centre(wxBOTH);
959 frame->Initialize();
960 frame->Show(TRUE);
961 }
962 #endif // wxUSE_PRINTING_ARCHITECTURE
963 }
964
965 void wxDocManager::OnUndo(wxCommandEvent& event)
966 {
967 wxDocument *doc = GetCurrentDocument();
968 if (!doc)
969 return;
970 if (doc->GetCommandProcessor())
971 doc->GetCommandProcessor()->Undo();
972 else
973 event.Skip();
974 }
975
976 void wxDocManager::OnRedo(wxCommandEvent& event)
977 {
978 wxDocument *doc = GetCurrentDocument();
979 if (!doc)
980 return;
981 if (doc->GetCommandProcessor())
982 doc->GetCommandProcessor()->Redo();
983 else
984 event.Skip();
985 }
986
987 // Handlers for UI update commands
988
989 void wxDocManager::OnUpdateFileOpen(wxUpdateUIEvent& event)
990 {
991 event.Enable( TRUE );
992 }
993
994 void wxDocManager::OnUpdateFileClose(wxUpdateUIEvent& event)
995 {
996 wxDocument *doc = GetCurrentDocument();
997 event.Enable( (doc != (wxDocument*) NULL) );
998 }
999
1000 void wxDocManager::OnUpdateFileRevert(wxUpdateUIEvent& event)
1001 {
1002 wxDocument *doc = GetCurrentDocument();
1003 event.Enable( (doc != (wxDocument*) NULL) );
1004 }
1005
1006 void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
1007 {
1008 event.Enable( TRUE );
1009 }
1010
1011 void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
1012 {
1013 wxDocument *doc = GetCurrentDocument();
1014 event.Enable( doc && doc->IsModified() );
1015 }
1016
1017 void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event)
1018 {
1019 wxDocument *doc = GetCurrentDocument();
1020 event.Enable( (doc != (wxDocument*) NULL) );
1021 }
1022
1023 void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event)
1024 {
1025 wxDocument *doc = GetCurrentDocument();
1026 if (!doc)
1027 event.Enable(FALSE);
1028 else if (!doc->GetCommandProcessor())
1029 event.Skip();
1030 else
1031 {
1032 event.Enable( doc->GetCommandProcessor()->CanUndo() );
1033 doc->GetCommandProcessor()->SetMenuStrings();
1034 }
1035 }
1036
1037 void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
1038 {
1039 wxDocument *doc = GetCurrentDocument();
1040 if (!doc)
1041 event.Enable(FALSE);
1042 else if (!doc->GetCommandProcessor())
1043 event.Skip();
1044 else
1045 {
1046 event.Enable( doc->GetCommandProcessor()->CanRedo() );
1047 doc->GetCommandProcessor()->SetMenuStrings();
1048 }
1049 }
1050
1051 void wxDocManager::OnUpdatePrint(wxUpdateUIEvent& event)
1052 {
1053 wxDocument *doc = GetCurrentDocument();
1054 event.Enable( (doc != (wxDocument*) NULL) );
1055 }
1056
1057 void wxDocManager::OnUpdatePrintSetup(wxUpdateUIEvent& event)
1058 {
1059 event.Enable( TRUE );
1060 }
1061
1062 void wxDocManager::OnUpdatePreview(wxUpdateUIEvent& event)
1063 {
1064 wxDocument *doc = GetCurrentDocument();
1065 event.Enable( (doc != (wxDocument*) NULL) );
1066 }
1067
1068 wxView *wxDocManager::GetCurrentView() const
1069 {
1070 if (m_currentView)
1071 return m_currentView;
1072 if (m_docs.GetCount() == 1)
1073 {
1074 wxDocument* doc = (wxDocument*) m_docs.GetFirst()->GetData();
1075 return doc->GetFirstView();
1076 }
1077 return (wxView *) NULL;
1078 }
1079
1080 // Extend event processing to search the view's event table
1081 bool wxDocManager::ProcessEvent(wxEvent& event)
1082 {
1083 wxView* view = GetCurrentView();
1084 if (view)
1085 {
1086 if (view->ProcessEvent(event))
1087 return TRUE;
1088 }
1089 return wxEvtHandler::ProcessEvent(event);
1090 }
1091
1092 wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
1093 {
1094 wxDocTemplate **templates = new wxDocTemplate *[m_templates.GetCount()];
1095 int n = 0;
1096
1097 for (size_t i = 0; i < m_templates.GetCount(); i++)
1098 {
1099 wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Item(i)->GetData());
1100 if (temp->IsVisible())
1101 {
1102 templates[n] = temp;
1103 n ++;
1104 }
1105 }
1106 if (n == 0)
1107 {
1108 delete[] templates;
1109 return (wxDocument *) NULL;
1110 }
1111
1112 wxDocument* docToClose = NULL;
1113
1114 // If we've reached the max number of docs, close the
1115 // first one.
1116 if ( (int)GetDocuments().GetCount() >= m_maxDocsOpen )
1117 {
1118 wxDocument *doc = (wxDocument *)GetDocuments().GetFirst()->GetData();
1119 docToClose = doc;
1120 }
1121
1122 // New document: user chooses a template, unless there's only one.
1123 if (flags & wxDOC_NEW)
1124 {
1125 if (n == 1)
1126 {
1127 if (docToClose)
1128 {
1129 if (!CloseDocument(docToClose, FALSE))
1130 {
1131 delete[] templates;
1132 return NULL;
1133 }
1134 }
1135
1136 wxDocTemplate *temp = templates[0];
1137 delete[] templates;
1138 wxDocument *newDoc = temp->CreateDocument(path, flags);
1139
1140 if (newDoc)
1141 {
1142 newDoc->SetDocumentName(temp->GetDocumentName());
1143 newDoc->SetDocumentTemplate(temp);
1144 newDoc->OnNewDocument();
1145 }
1146 return newDoc;
1147 }
1148
1149 wxDocTemplate *temp = SelectDocumentType(templates, n);
1150 delete[] templates;
1151 if (temp)
1152 {
1153 if (docToClose)
1154 {
1155 if (!CloseDocument(docToClose, FALSE))
1156 {
1157 return NULL;
1158 }
1159 }
1160
1161 wxDocument *newDoc = temp->CreateDocument(path, flags);
1162
1163 if (newDoc)
1164 {
1165 newDoc->SetDocumentName(temp->GetDocumentName());
1166 newDoc->SetDocumentTemplate(temp);
1167 newDoc->OnNewDocument();
1168 }
1169 return newDoc;
1170 }
1171 else
1172 return (wxDocument *) NULL;
1173 }
1174
1175 // Existing document
1176 wxDocTemplate *temp = (wxDocTemplate *) NULL;
1177
1178 wxString path2(wxT(""));
1179 if (path != wxT(""))
1180 path2 = path;
1181
1182 if (flags & wxDOC_SILENT)
1183 {
1184 temp = FindTemplateForPath(path2);
1185 if (!temp)
1186 {
1187 // Since we do not add files with non-default extensions to the FileHistory this
1188 // can only happen if the application changes the allowed templates in runtime.
1189 (void)wxMessageBox(_("Sorry, the format for this file is unknown."),
1190 _("Open File"),
1191 wxOK | wxICON_EXCLAMATION, wxFindSuitableParent());
1192 }
1193 }
1194 else
1195 temp = SelectDocumentPath(templates, n, path2, flags);
1196
1197 delete[] templates;
1198
1199 if (temp)
1200 {
1201 if (docToClose)
1202 {
1203 if (!CloseDocument(docToClose, FALSE))
1204 {
1205 return NULL;
1206 }
1207 }
1208
1209 wxDocument *newDoc = temp->CreateDocument(path2, flags);
1210 if (newDoc)
1211 {
1212 newDoc->SetDocumentName(temp->GetDocumentName());
1213 newDoc->SetDocumentTemplate(temp);
1214 if (!newDoc->OnOpenDocument(path2))
1215 {
1216 newDoc->DeleteAllViews();
1217 // delete newDoc; // Implicitly deleted by DeleteAllViews
1218 return (wxDocument *) NULL;
1219 }
1220 // A file that doesn't use the default extension of its document
1221 // template cannot be opened via the FileHistory, so we do not
1222 // add it.
1223 if (temp->FileMatchesTemplate(path2))
1224 AddFileToHistory(path2);
1225 }
1226 return newDoc;
1227 }
1228
1229 return (wxDocument *) NULL;
1230 }
1231
1232 wxView *wxDocManager::CreateView(wxDocument *doc, long flags)
1233 {
1234 wxDocTemplate **templates = new wxDocTemplate *[m_templates.GetCount()];
1235 int n =0;
1236
1237 for (size_t i = 0; i < m_templates.GetCount(); i++)
1238 {
1239 wxDocTemplate *temp = (wxDocTemplate *)(m_templates.Item(i)->GetData());
1240 if (temp->IsVisible())
1241 {
1242 if (temp->GetDocumentName() == doc->GetDocumentName())
1243 {
1244 templates[n] = temp;
1245 n ++;
1246 }
1247 }
1248 }
1249 if (n == 0)
1250 {
1251 delete[] templates;
1252 return (wxView *) NULL;
1253 }
1254 if (n == 1)
1255 {
1256 wxDocTemplate *temp = templates[0];
1257 delete[] templates;
1258 wxView *view = temp->CreateView(doc, flags);
1259 if (view)
1260 view->SetViewName(temp->GetViewName());
1261 return view;
1262 }
1263
1264 wxDocTemplate *temp = SelectViewType(templates, n);
1265 delete[] templates;
1266 if (temp)
1267 {
1268 wxView *view = temp->CreateView(doc, flags);
1269 if (view)
1270 view->SetViewName(temp->GetViewName());
1271 return view;
1272 }
1273 else
1274 return (wxView *) NULL;
1275 }
1276
1277 // Not yet implemented
1278 void wxDocManager::DeleteTemplate(wxDocTemplate *WXUNUSED(temp), long WXUNUSED(flags))
1279 {
1280 }
1281
1282 // Not yet implemented
1283 bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
1284 {
1285 return FALSE;
1286 }
1287
1288 wxDocument *wxDocManager::GetCurrentDocument() const
1289 {
1290 wxView *view = GetCurrentView();
1291 if (view)
1292 return view->GetDocument();
1293 else
1294 return (wxDocument *) NULL;
1295 }
1296
1297 // Make a default document name
1298 bool wxDocManager::MakeDefaultName(wxString& name)
1299 {
1300 name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
1301 m_defaultDocumentNameCounter++;
1302
1303 return TRUE;
1304 }
1305
1306 // Make a frame title (override this to do something different)
1307 // If docName is empty, a document is not currently active.
1308 wxString wxDocManager::MakeFrameTitle(wxDocument* doc)
1309 {
1310 wxString appName = wxTheApp->GetAppName();
1311 wxString title;
1312 if (!doc)
1313 title = appName;
1314 else
1315 {
1316 wxString docName;
1317 doc->GetPrintableName(docName);
1318 title = docName + wxString(_(" - ")) + appName;
1319 }
1320 return title;
1321 }
1322
1323
1324 // Not yet implemented
1325 wxDocTemplate *wxDocManager::MatchTemplate(const wxString& WXUNUSED(path))
1326 {
1327 return (wxDocTemplate *) NULL;
1328 }
1329
1330 // File history management
1331 void wxDocManager::AddFileToHistory(const wxString& file)
1332 {
1333 if (m_fileHistory)
1334 m_fileHistory->AddFileToHistory(file);
1335 }
1336
1337 void wxDocManager::RemoveFileFromHistory(size_t i)
1338 {
1339 if (m_fileHistory)
1340 m_fileHistory->RemoveFileFromHistory(i);
1341 }
1342
1343 wxString wxDocManager::GetHistoryFile(size_t i) const
1344 {
1345 wxString histFile;
1346
1347 if (m_fileHistory)
1348 histFile = m_fileHistory->GetHistoryFile(i);
1349
1350 return histFile;
1351 }
1352
1353 void wxDocManager::FileHistoryUseMenu(wxMenu *menu)
1354 {
1355 if (m_fileHistory)
1356 m_fileHistory->UseMenu(menu);
1357 }
1358
1359 void wxDocManager::FileHistoryRemoveMenu(wxMenu *menu)
1360 {
1361 if (m_fileHistory)
1362 m_fileHistory->RemoveMenu(menu);
1363 }
1364
1365 #if wxUSE_CONFIG
1366 void wxDocManager::FileHistoryLoad(wxConfigBase& config)
1367 {
1368 if (m_fileHistory)
1369 m_fileHistory->Load(config);
1370 }
1371
1372 void wxDocManager::FileHistorySave(wxConfigBase& config)
1373 {
1374 if (m_fileHistory)
1375 m_fileHistory->Save(config);
1376 }
1377 #endif
1378
1379 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu* menu)
1380 {
1381 if (m_fileHistory)
1382 m_fileHistory->AddFilesToMenu(menu);
1383 }
1384
1385 void wxDocManager::FileHistoryAddFilesToMenu()
1386 {
1387 if (m_fileHistory)
1388 m_fileHistory->AddFilesToMenu();
1389 }
1390
1391 size_t wxDocManager::GetHistoryFilesCount() const
1392 {
1393 return m_fileHistory ? m_fileHistory->GetCount() : 0;
1394 }
1395
1396
1397 // Find out the document template via matching in the document file format
1398 // against that of the template
1399 wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
1400 {
1401 wxDocTemplate *theTemplate = (wxDocTemplate *) NULL;
1402
1403 // Find the template which this extension corresponds to
1404 for (size_t i = 0; i < m_templates.GetCount(); i++)
1405 {
1406 wxDocTemplate *temp = (wxDocTemplate *)m_templates.Item(i)->GetData();
1407 if ( temp->FileMatchesTemplate(path) )
1408 {
1409 theTemplate = temp;
1410 break;
1411 }
1412 }
1413 return theTemplate;
1414 }
1415
1416 // Try to get a more suitable parent frame than the top window,
1417 // for selection dialogs. Otherwise you may get an unexpected
1418 // window being activated when a dialog is shown.
1419 static wxWindow* wxFindSuitableParent()
1420 {
1421 wxWindow* parent = wxTheApp->GetTopWindow();
1422
1423 wxWindow* focusWindow = wxWindow::FindFocus();
1424 if (focusWindow)
1425 {
1426 while (focusWindow &&
1427 !focusWindow->IsKindOf(CLASSINFO(wxDialog)) &&
1428 !focusWindow->IsKindOf(CLASSINFO(wxFrame)))
1429
1430 focusWindow = focusWindow->GetParent();
1431
1432 if (focusWindow)
1433 parent = focusWindow;
1434 }
1435 return parent;
1436 }
1437
1438 // Prompts user to open a file, using file specs in templates.
1439 // Must extend the file selector dialog or implement own; OR
1440 // match the extension to the template extension.
1441
1442 wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
1443 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
1444 int noTemplates,
1445 #else
1446 int WXUNUSED(noTemplates),
1447 #endif
1448 wxString& path,
1449 long WXUNUSED(flags),
1450 bool WXUNUSED(save))
1451 {
1452 // We can only have multiple filters in Windows and GTK
1453 #if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__)
1454 wxString descrBuf;
1455
1456 int i;
1457 for (i = 0; i < noTemplates; i++)
1458 {
1459 if (templates[i]->IsVisible())
1460 {
1461 // add a '|' to separate this filter from the previous one
1462 if ( !descrBuf.IsEmpty() )
1463 descrBuf << wxT('|');
1464
1465 descrBuf << templates[i]->GetDescription()
1466 << wxT(" (") << templates[i]->GetFileFilter() << wxT(") |")
1467 << templates[i]->GetFileFilter();
1468 }
1469 }
1470 #else
1471 wxString descrBuf = wxT("*.*");
1472 #endif
1473
1474 int FilterIndex = -1;
1475
1476 wxWindow* parent = wxFindSuitableParent();
1477
1478 wxString pathTmp = wxFileSelectorEx(_("Select a file"),
1479 m_lastDirectory,
1480 wxT(""),
1481 &FilterIndex,
1482 descrBuf,
1483 0,
1484 parent);
1485
1486 wxDocTemplate *theTemplate = (wxDocTemplate *)NULL;
1487 if (!pathTmp.IsEmpty())
1488 {
1489 if (!wxFileExists(pathTmp))
1490 {
1491 wxString msgTitle;
1492 if (!wxTheApp->GetAppName().IsEmpty())
1493 msgTitle = wxTheApp->GetAppName();
1494 else
1495 msgTitle = wxString(_("File error"));
1496
1497 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
1498 parent);
1499
1500 path = wxT("");
1501 return (wxDocTemplate *) NULL;
1502 }
1503 m_lastDirectory = wxPathOnly(pathTmp);
1504
1505 path = pathTmp;
1506
1507 // first choose the template using the extension, if this fails (i.e.
1508 // wxFileSelectorEx() didn't fill it), then use the path
1509 if ( FilterIndex != -1 )
1510 theTemplate = templates[FilterIndex];
1511 if ( !theTemplate )
1512 theTemplate = FindTemplateForPath(path);
1513 if ( !theTemplate )
1514 {
1515 // Since we do not add files with non-default extensions to the FileHistory this
1516 // can only happen if the application changes the allowed templates in runtime.
1517 (void)wxMessageBox(_("Sorry, the format for this file is unknown."),
1518 _("Open File"),
1519 wxOK | wxICON_EXCLAMATION, wxFindSuitableParent());
1520 }
1521 }
1522 else
1523 {
1524 path = wxT("");
1525 }
1526
1527 return theTemplate;
1528 }
1529
1530 wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
1531 int noTemplates, bool sort)
1532 {
1533 wxArrayString strings(sort);
1534 wxDocTemplate **data = new wxDocTemplate *[noTemplates];
1535 int i;
1536 int n = 0;
1537
1538 for (i = 0; i < noTemplates; i++)
1539 {
1540 if (templates[i]->IsVisible())
1541 {
1542 int j;
1543 bool want = TRUE;
1544 for (j = 0; j < n; j++)
1545 {
1546 //filter out NOT unique documents + view combinations
1547 if ( templates[i]->m_docTypeName == data[j]->m_docTypeName &&
1548 templates[i]->m_viewTypeName == data[j]->m_viewTypeName
1549 )
1550 want = FALSE;
1551 }
1552
1553 if ( want )
1554 {
1555 strings.Add(templates[i]->m_description);
1556
1557 data[n] = templates[i];
1558 n ++;
1559 }
1560 }
1561 } // for
1562
1563 if (sort)
1564 {
1565 // Yes, this will be slow, but template lists
1566 // are typically short.
1567 int j;
1568 n = strings.Count();
1569 for (i = 0; i < n; i++)
1570 {
1571 for (j = 0; j < noTemplates; j++)
1572 {
1573 if (strings[i] == templates[j]->m_description)
1574 data[i] = templates[j];
1575 }
1576 }
1577 }
1578
1579 wxDocTemplate *theTemplate;
1580
1581 switch ( n )
1582 {
1583 case 0:
1584 // no visible templates, hence nothing to choose from
1585 theTemplate = NULL;
1586 break;
1587
1588 case 1:
1589 // don't propose the user to choose if he heas no choice
1590 theTemplate = data[0];
1591 break;
1592
1593 default:
1594 // propose the user to choose one of several
1595 theTemplate = (wxDocTemplate *)wxGetSingleChoiceData
1596 (
1597 _("Select a document template"),
1598 _("Templates"),
1599 strings,
1600 (void **)data,
1601 wxFindSuitableParent()
1602 );
1603 }
1604
1605 delete[] data;
1606
1607 return theTemplate;
1608 }
1609
1610 wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
1611 int noTemplates, bool sort)
1612 {
1613 wxArrayString strings(sort);
1614 wxDocTemplate **data = new wxDocTemplate *[noTemplates];
1615 int i;
1616 int n = 0;
1617
1618 for (i = 0; i < noTemplates; i++)
1619 {
1620 wxDocTemplate *templ = templates[i];
1621 if ( templ->IsVisible() && !templ->GetViewName().empty() )
1622 {
1623 int j;
1624 bool want = TRUE;
1625 for (j = 0; j < n; j++)
1626 {
1627 //filter out NOT unique views
1628 if ( templates[i]->m_viewTypeName == data[j]->m_viewTypeName )
1629 want = FALSE;
1630 }
1631
1632 if ( want )
1633 {
1634 strings.Add(templ->m_viewTypeName);
1635 data[n] = templ;
1636 n ++;
1637 }
1638 }
1639 }
1640
1641 if (sort)
1642 {
1643 // Yes, this will be slow, but template lists
1644 // are typically short.
1645 int j;
1646 n = strings.Count();
1647 for (i = 0; i < n; i++)
1648 {
1649 for (j = 0; j < noTemplates; j++)
1650 {
1651 if (strings[i] == templates[j]->m_viewTypeName)
1652 data[i] = templates[j];
1653 }
1654 }
1655 }
1656
1657 wxDocTemplate *theTemplate;
1658
1659 // the same logic as above
1660 switch ( n )
1661 {
1662 case 0:
1663 theTemplate = (wxDocTemplate *)NULL;
1664 break;
1665
1666 case 1:
1667 theTemplate = data[0];
1668 break;
1669
1670 default:
1671 theTemplate = (wxDocTemplate *)wxGetSingleChoiceData
1672 (
1673 _("Select a document view"),
1674 _("Views"),
1675 strings,
1676 (void **)data,
1677 wxFindSuitableParent()
1678 );
1679
1680 }
1681
1682 delete[] data;
1683 return theTemplate;
1684 }
1685
1686 void wxDocManager::AssociateTemplate(wxDocTemplate *temp)
1687 {
1688 if (!m_templates.Member(temp))
1689 m_templates.Append(temp);
1690 }
1691
1692 void wxDocManager::DisassociateTemplate(wxDocTemplate *temp)
1693 {
1694 m_templates.DeleteObject(temp);
1695 }
1696
1697 // Add and remove a document from the manager's list
1698 void wxDocManager::AddDocument(wxDocument *doc)
1699 {
1700 if (!m_docs.Member(doc))
1701 m_docs.Append(doc);
1702 }
1703
1704 void wxDocManager::RemoveDocument(wxDocument *doc)
1705 {
1706 m_docs.DeleteObject(doc);
1707 }
1708
1709 // Views or windows should inform the document manager
1710 // when a view is going in or out of focus
1711 void wxDocManager::ActivateView(wxView *view, bool activate)
1712 {
1713 if ( activate )
1714 {
1715 m_currentView = view;
1716 }
1717 else // deactivate
1718 {
1719 if ( m_currentView == view )
1720 {
1721 // don't keep stale pointer
1722 m_currentView = (wxView *) NULL;
1723 }
1724 }
1725 }
1726
1727 // ----------------------------------------------------------------------------
1728 // Default document child frame
1729 // ----------------------------------------------------------------------------
1730
1731 BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame)
1732 EVT_ACTIVATE(wxDocChildFrame::OnActivate)
1733 EVT_CLOSE(wxDocChildFrame::OnCloseWindow)
1734 END_EVENT_TABLE()
1735
1736 wxDocChildFrame::wxDocChildFrame(wxDocument *doc,
1737 wxView *view,
1738 wxFrame *frame,
1739 wxWindowID id,
1740 const wxString& title,
1741 const wxPoint& pos,
1742 const wxSize& size,
1743 long style,
1744 const wxString& name)
1745 : wxFrame(frame, id, title, pos, size, style, name)
1746 {
1747 m_childDocument = doc;
1748 m_childView = view;
1749 if (view)
1750 view->SetFrame(this);
1751 }
1752
1753 wxDocChildFrame::~wxDocChildFrame()
1754 {
1755 }
1756
1757 // Extend event processing to search the view's event table
1758 bool wxDocChildFrame::ProcessEvent(wxEvent& event)
1759 {
1760 if (m_childView)
1761 m_childView->Activate(TRUE);
1762
1763 if ( !m_childView || ! m_childView->ProcessEvent(event) )
1764 {
1765 // Only hand up to the parent if it's a menu command
1766 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
1767 return wxEvtHandler::ProcessEvent(event);
1768 else
1769 return TRUE;
1770 }
1771 else
1772 return TRUE;
1773 }
1774
1775 void wxDocChildFrame::OnActivate(wxActivateEvent& event)
1776 {
1777 wxFrame::OnActivate(event);
1778
1779 if (m_childView)
1780 m_childView->Activate(event.GetActive());
1781 }
1782
1783 void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event)
1784 {
1785 if (m_childView)
1786 {
1787 bool ans = FALSE;
1788 if (!event.CanVeto())
1789 ans = TRUE; // Must delete.
1790 else
1791 ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
1792
1793 if (ans)
1794 {
1795 m_childView->Activate(FALSE);
1796 delete m_childView;
1797 m_childView = (wxView *) NULL;
1798 m_childDocument = (wxDocument *) NULL;
1799
1800 this->Destroy();
1801 }
1802 else
1803 event.Veto();
1804 }
1805 else
1806 event.Veto();
1807 }
1808
1809 // ----------------------------------------------------------------------------
1810 // Default parent frame
1811 // ----------------------------------------------------------------------------
1812
1813 BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
1814 EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit)
1815 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocParentFrame::OnMRUFile)
1816 EVT_CLOSE(wxDocParentFrame::OnCloseWindow)
1817 END_EVENT_TABLE()
1818
1819 wxDocParentFrame::wxDocParentFrame(wxDocManager *manager,
1820 wxFrame *frame,
1821 wxWindowID id,
1822 const wxString& title,
1823 const wxPoint& pos,
1824 const wxSize& size,
1825 long style,
1826 const wxString& name)
1827 : wxFrame(frame, id, title, pos, size, style, name)
1828 {
1829 m_docManager = manager;
1830 }
1831
1832 void wxDocParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
1833 {
1834 Close();
1835 }
1836
1837 void wxDocParentFrame::OnMRUFile(wxCommandEvent& event)
1838 {
1839 int n = event.GetId() - wxID_FILE1; // the index in MRU list
1840 wxString filename(m_docManager->GetHistoryFile(n));
1841 if ( !filename.IsEmpty() )
1842 {
1843 // verify that the file exists before doing anything else
1844 if ( wxFile::Exists(filename) )
1845 {
1846 // try to open it
1847 if (!m_docManager->CreateDocument(filename, wxDOC_SILENT))
1848 {
1849 // remove the file from the MRU list. The user should already be notified.
1850 m_docManager->RemoveFileFromHistory(n);
1851
1852 wxLogError(_("The file '%s' couldn't be opened.\nIt has been removed from the most recently used files list."),
1853 filename.c_str());
1854 }
1855 }
1856 else
1857 {
1858 // remove the bogus filename from the MRU list and notify the user
1859 // about it
1860 m_docManager->RemoveFileFromHistory(n);
1861
1862 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list."),
1863 filename.c_str());
1864 }
1865 }
1866 }
1867
1868 // Extend event processing to search the view's event table
1869 bool wxDocParentFrame::ProcessEvent(wxEvent& event)
1870 {
1871 // Try the document manager, then do default processing
1872 if (!m_docManager || !m_docManager->ProcessEvent(event))
1873 return wxEvtHandler::ProcessEvent(event);
1874 else
1875 return TRUE;
1876 }
1877
1878 // Define the behaviour for the frame closing
1879 // - must delete all frames except for the main one.
1880 void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
1881 {
1882 if (m_docManager->Clear(!event.CanVeto()))
1883 {
1884 this->Destroy();
1885 }
1886 else
1887 event.Veto();
1888 }
1889
1890 #if wxUSE_PRINTING_ARCHITECTURE
1891
1892 wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title)
1893 : wxPrintout(title)
1894 {
1895 m_printoutView = view;
1896 }
1897
1898 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page))
1899 {
1900 wxDC *dc = GetDC();
1901
1902 // Get the logical pixels per inch of screen and printer
1903 int ppiScreenX, ppiScreenY;
1904 GetPPIScreen(&ppiScreenX, &ppiScreenY);
1905 int ppiPrinterX, ppiPrinterY;
1906 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
1907
1908 // This scales the DC so that the printout roughly represents the
1909 // the screen scaling. The text point size _should_ be the right size
1910 // but in fact is too small for some reason. This is a detail that will
1911 // need to be addressed at some point but can be fudged for the
1912 // moment.
1913 float scale = (float)((float)ppiPrinterX/(float)ppiScreenX);
1914
1915 // Now we have to check in case our real page size is reduced
1916 // (e.g. because we're drawing to a print preview memory DC)
1917 int pageWidth, pageHeight;
1918 int w, h;
1919 dc->GetSize(&w, &h);
1920 GetPageSizePixels(&pageWidth, &pageHeight);
1921
1922 // If printer pageWidth == current DC width, then this doesn't
1923 // change. But w might be the preview bitmap width, so scale down.
1924 float overallScale = scale * (float)(w/(float)pageWidth);
1925 dc->SetUserScale(overallScale, overallScale);
1926
1927 if (m_printoutView)
1928 {
1929 m_printoutView->OnDraw(dc);
1930 }
1931 return TRUE;
1932 }
1933
1934 bool wxDocPrintout::HasPage(int pageNum)
1935 {
1936 return (pageNum == 1);
1937 }
1938
1939 bool wxDocPrintout::OnBeginDocument(int startPage, int endPage)
1940 {
1941 if (!wxPrintout::OnBeginDocument(startPage, endPage))
1942 return FALSE;
1943
1944 return TRUE;
1945 }
1946
1947 void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
1948 {
1949 *minPage = 1;
1950 *maxPage = 1;
1951 *selPageFrom = 1;
1952 *selPageTo = 1;
1953 }
1954
1955 #endif // wxUSE_PRINTING_ARCHITECTURE
1956
1957 // ----------------------------------------------------------------------------
1958 // File history processor
1959 // ----------------------------------------------------------------------------
1960
1961 static inline wxChar* MYcopystring(const wxString& s)
1962 {
1963 wxChar* copy = new wxChar[s.length() + 1];
1964 return wxStrcpy(copy, s.c_str());
1965 }
1966
1967 static inline wxChar* MYcopystring(const wxChar* s)
1968 {
1969 wxChar* copy = new wxChar[wxStrlen(s) + 1];
1970 return wxStrcpy(copy, s);
1971 }
1972
1973 wxFileHistory::wxFileHistory(size_t maxFiles, wxWindowID idBase)
1974 {
1975 m_fileMaxFiles = maxFiles;
1976 m_idBase = idBase;
1977 m_fileHistoryN = 0;
1978 m_fileHistory = new wxChar *[m_fileMaxFiles];
1979 }
1980
1981 wxFileHistory::~wxFileHistory()
1982 {
1983 size_t i;
1984 for (i = 0; i < m_fileHistoryN; i++)
1985 delete[] m_fileHistory[i];
1986 delete[] m_fileHistory;
1987 }
1988
1989 // File history management
1990 void wxFileHistory::AddFileToHistory(const wxString& file)
1991 {
1992 size_t i;
1993
1994 // Check we don't already have this file
1995 for (i = 0; i < m_fileHistoryN; i++)
1996 {
1997 #if defined( __WXMSW__ ) // Add any other OSes with case insensitive file names
1998 wxString testString;
1999 if ( m_fileHistory[i] )
2000 testString = m_fileHistory[i];
2001 if ( m_fileHistory[i] && ( file.Lower() == testString.Lower() ) )
2002 #else
2003 if ( m_fileHistory[i] && ( file == m_fileHistory[i] ) )
2004 #endif
2005 {
2006 // we do have it, move it to the top of the history
2007 RemoveFileFromHistory (i);
2008 AddFileToHistory (file);
2009 return;
2010 }
2011 }
2012
2013 // if we already have a full history, delete the one at the end
2014 if ( m_fileMaxFiles == m_fileHistoryN )
2015 {
2016 RemoveFileFromHistory (m_fileHistoryN - 1);
2017 AddFileToHistory (file);
2018 return;
2019 }
2020
2021 // Add to the project file history:
2022 // Move existing files (if any) down so we can insert file at beginning.
2023 if (m_fileHistoryN < m_fileMaxFiles)
2024 {
2025 wxNode* node = m_fileMenus.GetFirst();
2026 while (node)
2027 {
2028 wxMenu* menu = (wxMenu*) node->GetData();
2029 if ( m_fileHistoryN == 0 && menu->GetMenuItemCount() )
2030 {
2031 menu->AppendSeparator();
2032 }
2033 menu->Append(m_idBase+m_fileHistoryN, _("[EMPTY]"));
2034 node = node->GetNext();
2035 }
2036 m_fileHistoryN ++;
2037 }
2038 // Shuffle filenames down
2039 for (i = (m_fileHistoryN-1); i > 0; i--)
2040 {
2041 m_fileHistory[i] = m_fileHistory[i-1];
2042 }
2043 m_fileHistory[0] = MYcopystring(file);
2044
2045 // this is the directory of the last opened file
2046 wxString pathCurrent;
2047 wxSplitPath( m_fileHistory[0], &pathCurrent, NULL, NULL );
2048 for (i = 0; i < m_fileHistoryN; i++)
2049 {
2050 if ( m_fileHistory[i] )
2051 {
2052 // if in same directory just show the filename; otherwise the full
2053 // path
2054 wxString pathInMenu, path, filename, ext;
2055 wxSplitPath( m_fileHistory[i], &path, &filename, &ext );
2056 if ( path == pathCurrent )
2057 {
2058 pathInMenu = filename;
2059 if ( !ext.empty() )
2060 pathInMenu = pathInMenu + wxFILE_SEP_EXT + ext;
2061 }
2062 else
2063 {
2064 // absolute path; could also set relative path
2065 pathInMenu = m_fileHistory[i];
2066 }
2067
2068 wxString buf;
2069 buf.Printf(s_MRUEntryFormat, i + 1, pathInMenu.c_str());
2070 wxNode* node = m_fileMenus.GetFirst();
2071 while (node)
2072 {
2073 wxMenu* menu = (wxMenu*) node->GetData();
2074 menu->SetLabel(m_idBase + i, buf);
2075 node = node->GetNext();
2076 }
2077 }
2078 }
2079 }
2080
2081 void wxFileHistory::RemoveFileFromHistory(size_t i)
2082 {
2083 wxCHECK_RET( i < m_fileHistoryN,
2084 wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
2085
2086 // delete the element from the array (could use memmove() too...)
2087 delete [] m_fileHistory[i];
2088
2089 size_t j;
2090 for ( j = i; j < m_fileHistoryN - 1; j++ )
2091 {
2092 m_fileHistory[j] = m_fileHistory[j + 1];
2093 }
2094
2095 wxNode* node = m_fileMenus.GetFirst();
2096 while ( node )
2097 {
2098 wxMenu* menu = (wxMenu*) node->GetData();
2099
2100 // shuffle filenames up
2101 wxString buf;
2102 for ( j = i; j < m_fileHistoryN - 1; j++ )
2103 {
2104 buf.Printf(s_MRUEntryFormat, j + 1, m_fileHistory[j]);
2105 menu->SetLabel(m_idBase + j, buf);
2106 }
2107
2108 node = node->GetNext();
2109
2110 // delete the last menu item which is unused now
2111 wxWindowID lastItemId = m_idBase + m_fileHistoryN - 1;
2112 if (menu->FindItem(lastItemId))
2113 {
2114 menu->Delete(lastItemId);
2115 }
2116
2117 // delete the last separator too if no more files are left
2118 if ( m_fileHistoryN == 1 )
2119 {
2120 wxMenuItemList::Node *node = menu->GetMenuItems().GetLast();
2121 if ( node )
2122 {
2123 wxMenuItem *menuItem = node->GetData();
2124 if ( menuItem->IsSeparator() )
2125 {
2126 menu->Delete(menuItem);
2127 }
2128 //else: should we search backwards for the last separator?
2129 }
2130 //else: menu is empty somehow
2131 }
2132 }
2133
2134 m_fileHistoryN--;
2135 }
2136
2137 wxString wxFileHistory::GetHistoryFile(size_t i) const
2138 {
2139 wxString s;
2140 if ( i < m_fileHistoryN )
2141 {
2142 s = m_fileHistory[i];
2143 }
2144 else
2145 {
2146 wxFAIL_MSG( wxT("bad index in wxFileHistory::GetHistoryFile") );
2147 }
2148
2149 return s;
2150 }
2151
2152 void wxFileHistory::UseMenu(wxMenu *menu)
2153 {
2154 if (!m_fileMenus.Member(menu))
2155 m_fileMenus.Append(menu);
2156 }
2157
2158 void wxFileHistory::RemoveMenu(wxMenu *menu)
2159 {
2160 m_fileMenus.DeleteObject(menu);
2161 }
2162
2163 #if wxUSE_CONFIG
2164 void wxFileHistory::Load(wxConfigBase& config)
2165 {
2166 m_fileHistoryN = 0;
2167 wxString buf;
2168 buf.Printf(wxT("file%d"), (int)m_fileHistoryN+1);
2169 wxString historyFile;
2170 while ((m_fileHistoryN < m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != wxT("")))
2171 {
2172 m_fileHistory[m_fileHistoryN] = MYcopystring((const wxChar*) historyFile);
2173 m_fileHistoryN ++;
2174 buf.Printf(wxT("file%d"), (int)m_fileHistoryN+1);
2175 historyFile = wxT("");
2176 }
2177 AddFilesToMenu();
2178 }
2179
2180 void wxFileHistory::Save(wxConfigBase& config)
2181 {
2182 size_t i;
2183 for (i = 0; i < m_fileMaxFiles; i++)
2184 {
2185 wxString buf;
2186 buf.Printf(wxT("file%d"), (int)i+1);
2187 if (i < m_fileHistoryN)
2188 config.Write(buf, wxString(m_fileHistory[i]));
2189 else
2190 config.Write(buf, wxEmptyString);
2191 }
2192 }
2193 #endif // wxUSE_CONFIG
2194
2195 void wxFileHistory::AddFilesToMenu()
2196 {
2197 if (m_fileHistoryN > 0)
2198 {
2199 wxNode* node = m_fileMenus.GetFirst();
2200 while (node)
2201 {
2202 wxMenu* menu = (wxMenu*) node->GetData();
2203 if (menu->GetMenuItemCount())
2204 {
2205 menu->AppendSeparator();
2206 }
2207
2208 size_t i;
2209 for (i = 0; i < m_fileHistoryN; i++)
2210 {
2211 if (m_fileHistory[i])
2212 {
2213 wxString buf;
2214 buf.Printf(s_MRUEntryFormat, i+1, m_fileHistory[i]);
2215 menu->Append(m_idBase+i, buf);
2216 }
2217 }
2218 node = node->GetNext();
2219 }
2220 }
2221 }
2222
2223 void wxFileHistory::AddFilesToMenu(wxMenu* menu)
2224 {
2225 if (m_fileHistoryN > 0)
2226 {
2227 if (menu->GetMenuItemCount())
2228 {
2229 menu->AppendSeparator();
2230 }
2231
2232 size_t i;
2233 for (i = 0; i < m_fileHistoryN; i++)
2234 {
2235 if (m_fileHistory[i])
2236 {
2237 wxString buf;
2238 buf.Printf(s_MRUEntryFormat, i+1, m_fileHistory[i]);
2239 menu->Append(m_idBase+i, buf);
2240 }
2241 }
2242 }
2243 }
2244
2245 // ----------------------------------------------------------------------------
2246 // Permits compatibility with existing file formats and functions that
2247 // manipulate files directly
2248 // ----------------------------------------------------------------------------
2249
2250 #if wxUSE_STD_IOSTREAM
2251
2252 bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
2253 {
2254 wxFFile file(filename, _T("rb"));
2255 if ( !file.IsOpened() )
2256 return FALSE;
2257
2258 char buf[4096];
2259
2260 size_t nRead;
2261 do
2262 {
2263 nRead = file.Read(buf, WXSIZEOF(buf));
2264 if ( file.Error() )
2265 return FALSE;
2266
2267 stream.write(buf, nRead);
2268 if ( !stream )
2269 return FALSE;
2270 }
2271 while ( !file.Eof() );
2272
2273 return TRUE;
2274 }
2275
2276 bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
2277 {
2278 wxFFile file(filename, _T("wb"));
2279 if ( !file.IsOpened() )
2280 return FALSE;
2281
2282 char buf[4096];
2283 do
2284 {
2285 stream.read(buf, WXSIZEOF(buf));
2286 if ( !stream.bad() ) // fail may be set on EOF, don't use operator!()
2287 {
2288 if ( !file.Write(buf, stream.gcount()) )
2289 return FALSE;
2290 }
2291 }
2292 while ( !stream.eof() );
2293
2294 return TRUE;
2295 }
2296
2297 #else // !wxUSE_STD_IOSTREAM
2298
2299 bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
2300 {
2301 wxFFile file(filename, _T("rb"));
2302 if ( !file.IsOpened() )
2303 return FALSE;
2304
2305 char buf[4096];
2306
2307 size_t nRead;
2308 do
2309 {
2310 nRead = file.Read(buf, WXSIZEOF(buf));
2311 if ( file.Error() )
2312 return FALSE;
2313
2314 stream.Write(buf, nRead);
2315 if ( !stream )
2316 return FALSE;
2317 }
2318 while ( !file.Eof() );
2319
2320 return TRUE;
2321 }
2322
2323 bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
2324 {
2325 wxFFile file(filename, _T("wb"));
2326 if ( !file.IsOpened() )
2327 return FALSE;
2328
2329 char buf[4096];
2330 do
2331 {
2332 stream.Read(buf, WXSIZEOF(buf));
2333
2334 const size_t nRead = stream.LastRead();
2335 if ( !nRead || !file.Write(buf, nRead) )
2336 return FALSE;
2337 }
2338 while ( !stream.Eof() );
2339
2340 return TRUE;
2341 }
2342
2343 #endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
2344
2345 #endif // wxUSE_DOC_VIEW_ARCHITECTURE
2346