1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document/view classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "docview.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_DOC_VIEW_ARCHITECTURE
34 #include "wx/string.h"
38 #include "wx/dialog.h"
41 #include "wx/filedlg.h"
50 #if wxUSE_PRINTING_ARCHITECTURE
51 #include "wx/prntbase.h"
52 #include "wx/printdlg.h"
55 #include "wx/msgdlg.h"
56 #include "wx/choicdlg.h"
57 #include "wx/docview.h"
58 #include "wx/confbase.h"
64 #if wxUSE_STD_IOSTREAM
65 #include "wx/ioswrap.h"
72 #include "wx/wfstream.h"
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 #if !USE_SHARED_LIBRARY
80 IMPLEMENT_ABSTRACT_CLASS(wxDocument
, wxEvtHandler
)
81 IMPLEMENT_ABSTRACT_CLASS(wxView
, wxEvtHandler
)
82 IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate
, wxObject
)
83 IMPLEMENT_DYNAMIC_CLASS(wxDocManager
, wxEvtHandler
)
84 IMPLEMENT_CLASS(wxDocChildFrame
, wxFrame
)
85 IMPLEMENT_CLASS(wxDocParentFrame
, wxFrame
)
87 #if wxUSE_PRINTING_ARCHITECTURE
88 IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout
, wxPrintout
)
91 IMPLEMENT_CLASS(wxCommand
, wxObject
)
92 IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor
, wxObject
)
93 IMPLEMENT_DYNAMIC_CLASS(wxFileHistory
, wxObject
)
96 // ----------------------------------------------------------------------------
97 // function prototypes
98 // ----------------------------------------------------------------------------
100 static inline wxString
FindExtension(const wxChar
*path
);
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 static const wxChar
*s_MRUEntryFormat
= wxT("&%d %s");
108 // ============================================================================
110 // ============================================================================
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 static wxString
FindExtension(const wxChar
*path
)
119 wxSplitPath(path
, NULL
, NULL
, &ext
);
121 // VZ: extensions are considered not case sensitive - is this really a good
123 return ext
.MakeLower();
126 // ----------------------------------------------------------------------------
127 // Definition of wxDocument
128 // ----------------------------------------------------------------------------
130 wxDocument::wxDocument(wxDocument
*parent
)
132 m_documentModified
= FALSE
;
133 m_documentParent
= parent
;
134 m_documentTemplate
= (wxDocTemplate
*) NULL
;
138 bool wxDocument::DeleteContents()
143 wxDocument::~wxDocument()
147 if (m_commandProcessor
)
148 delete m_commandProcessor
;
150 GetDocumentManager()->RemoveDocument(this);
152 // Not safe to do here, since it'll invoke virtual view functions
153 // expecting to see valid derived objects: and by the time we get here,
154 // we've called destructors higher up.
158 bool wxDocument::Close()
160 if (OnSaveModified())
161 return OnCloseDocument();
166 bool wxDocument::OnCloseDocument()
173 // Note that this implicitly deletes the document when the last view is
175 bool wxDocument::DeleteAllViews()
177 wxNode
*node
= m_documentViews
.First();
180 wxView
*view
= (wxView
*)node
->Data();
184 wxNode
*next
= node
->Next();
186 delete view
; // Deletes node implicitly
192 wxView
*wxDocument::GetFirstView() const
194 if (m_documentViews
.Number() == 0)
195 return (wxView
*) NULL
;
196 return (wxView
*)m_documentViews
.First()->Data();
199 wxDocManager
*wxDocument::GetDocumentManager() const
201 return m_documentTemplate
->GetDocumentManager();
204 bool wxDocument::OnNewDocument()
206 if (!OnSaveModified())
209 if (OnCloseDocument()==FALSE
) return FALSE
;
212 SetDocumentSaved(FALSE
);
215 GetDocumentManager()->MakeDefaultName(name
);
217 SetFilename(name
, TRUE
);
222 bool wxDocument::Save()
226 if (!IsModified()) return TRUE
;
227 if (m_documentFile
== wxT("") || !m_savedYet
)
230 ret
= OnSaveDocument(m_documentFile
);
232 SetDocumentSaved(TRUE
);
236 bool wxDocument::SaveAs()
238 wxDocTemplate
*docTemplate
= GetDocumentTemplate();
242 wxString tmp
= wxFileSelector(_("Save as"),
243 docTemplate
->GetDirectory(),
245 docTemplate
->GetDefaultExtension(),
246 docTemplate
->GetFileFilter(),
247 wxSAVE
| wxOVERWRITE_PROMPT
,
248 GetDocumentWindow());
253 wxString
fileName(tmp
);
254 wxString path
, name
, ext
;
255 wxSplitPath(fileName
, & path
, & name
, & ext
);
257 if (ext
.IsEmpty() || ext
== wxT(""))
260 fileName
+= docTemplate
->GetDefaultExtension();
263 SetFilename(fileName
);
264 SetTitle(wxFileNameFromPath(fileName
));
266 GetDocumentManager()->AddFileToHistory(fileName
);
268 // Notify the views that the filename has changed
269 wxNode
*node
= m_documentViews
.First();
272 wxView
*view
= (wxView
*)node
->Data();
273 view
->OnChangeFilename();
277 return OnSaveDocument(m_documentFile
);
280 bool wxDocument::OnSaveDocument(const wxString
& file
)
286 if (wxTheApp
->GetAppName() != wxT(""))
287 msgTitle
= wxTheApp
->GetAppName();
289 msgTitle
= wxString(_("File error"));
291 #if wxUSE_STD_IOSTREAM
292 ofstream
store(wxString(file
.fn_str()));
293 if (store
.fail() || store
.bad())
295 wxFileOutputStream
store(wxString(file
.fn_str()));
296 if (store
.LastError() != wxSTREAM_NOERROR
)
299 (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
300 GetDocumentWindow());
304 if (!SaveObject(store
))
306 (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
307 GetDocumentWindow());
316 bool wxDocument::OnOpenDocument(const wxString
& file
)
318 if (!OnSaveModified())
322 if (wxTheApp
->GetAppName() != wxT(""))
323 msgTitle
= wxTheApp
->GetAppName();
325 msgTitle
= wxString(_("File error"));
327 #if wxUSE_STD_IOSTREAM
328 ifstream
store(wxString(file
.fn_str()));
329 if (store
.fail() || store
.bad())
331 wxFileInputStream
store(wxString(file
.fn_str()));
332 if (store
.LastError() != wxSTREAM_NOERROR
)
335 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
336 GetDocumentWindow());
339 #if wxUSE_STD_IOSTREAM
340 if (!LoadObject(store
))
342 int res
= LoadObject(store
).LastError();
343 if ((res
!= wxSTREAM_NOERROR
) &&
344 (res
!= wxSTREAM_EOF
))
347 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
348 GetDocumentWindow());
351 SetFilename(file
, TRUE
);
360 #if wxUSE_STD_IOSTREAM
361 istream
& wxDocument::LoadObject(istream
& stream
)
363 wxInputStream
& wxDocument::LoadObject(wxInputStream
& stream
)
369 #if wxUSE_STD_IOSTREAM
370 ostream
& wxDocument::SaveObject(ostream
& stream
)
372 wxOutputStream
& wxDocument::SaveObject(wxOutputStream
& stream
)
378 bool wxDocument::Revert()
384 // Get title, or filename if no title, else unnamed
385 bool wxDocument::GetPrintableName(wxString
& buf
) const
387 if (m_documentTitle
!= wxT(""))
389 buf
= m_documentTitle
;
392 else if (m_documentFile
!= wxT(""))
394 buf
= wxFileNameFromPath(m_documentFile
);
404 wxWindow
*wxDocument::GetDocumentWindow() const
406 wxView
*view
= GetFirstView();
408 return view
->GetFrame();
410 return wxTheApp
->GetTopWindow();
413 wxCommandProcessor
*wxDocument::OnCreateCommandProcessor()
415 return new wxCommandProcessor
;
418 // TRUE if safe to close
419 bool wxDocument::OnSaveModified()
424 GetPrintableName(title
);
427 if (wxTheApp
->GetAppName() != wxT(""))
428 msgTitle
= wxTheApp
->GetAppName();
430 msgTitle
= wxString(_("Warning"));
433 prompt
.Printf(_("Do you want to save changes to document %s?"),
434 (const wxChar
*)title
);
435 int res
= wxMessageBox(prompt
, msgTitle
,
436 wxYES_NO
|wxCANCEL
|wxICON_QUESTION
,
437 GetDocumentWindow());
443 else if (res
== wxYES
)
445 else if (res
== wxCANCEL
)
451 bool wxDocument::Draw(wxDC
& WXUNUSED(context
))
456 bool wxDocument::AddView(wxView
*view
)
458 if (!m_documentViews
.Member(view
))
460 m_documentViews
.Append(view
);
466 bool wxDocument::RemoveView(wxView
*view
)
468 (void)m_documentViews
.DeleteObject(view
);
473 bool wxDocument::OnCreate(const wxString
& WXUNUSED(path
), long flags
)
475 if (GetDocumentTemplate()->CreateView(this, flags
))
481 // Called after a view is added or removed.
482 // The default implementation deletes the document if
483 // there are no more views.
484 void wxDocument::OnChangedViewList()
486 if (m_documentViews
.Number() == 0)
488 if (OnSaveModified())
495 void wxDocument::UpdateAllViews(wxView
*sender
, wxObject
*hint
)
497 wxNode
*node
= m_documentViews
.First();
500 wxView
*view
= (wxView
*)node
->Data();
501 view
->OnUpdate(sender
, hint
);
506 void wxDocument::SetFilename(const wxString
& filename
, bool notifyViews
)
508 m_documentFile
= filename
;
511 // Notify the views that the filename has changed
512 wxNode
*node
= m_documentViews
.First();
515 wxView
*view
= (wxView
*)node
->Data();
516 view
->OnChangeFilename();
522 // ----------------------------------------------------------------------------
524 // ----------------------------------------------------------------------------
529 m_viewDocument
= (wxDocument
*) NULL
;
531 m_viewTypeName
= wxT("");
532 m_viewFrame
= (wxFrame
*) NULL
;
537 // GetDocumentManager()->ActivateView(this, FALSE, TRUE);
538 m_viewDocument
->RemoveView(this);
541 // Extend event processing to search the document's event table
542 bool wxView::ProcessEvent(wxEvent
& event
)
544 if ( !GetDocument() || !GetDocument()->ProcessEvent(event
) )
545 return wxEvtHandler::ProcessEvent(event
);
550 void wxView::OnActivateView(bool WXUNUSED(activate
), wxView
*WXUNUSED(activeView
), wxView
*WXUNUSED(deactiveView
))
554 void wxView::OnPrint(wxDC
*dc
, wxObject
*WXUNUSED(info
))
559 void wxView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*WXUNUSED(hint
))
563 void wxView::OnChangeFilename()
565 if (GetFrame() && GetDocument())
568 GetDocument()->GetPrintableName(name
);
570 GetFrame()->SetTitle(name
);
574 void wxView::SetDocument(wxDocument
*doc
)
576 m_viewDocument
= doc
;
581 bool wxView::Close(bool deleteWindow
)
583 if (OnClose(deleteWindow
))
589 void wxView::Activate(bool activate
)
591 if (GetDocumentManager())
593 OnActivateView(activate
, this, GetDocumentManager()->GetCurrentView());
594 GetDocumentManager()->ActivateView(this, activate
);
598 bool wxView::OnClose(bool WXUNUSED(deleteWindow
))
600 return GetDocument() ? GetDocument()->Close() : TRUE
;
603 #if wxUSE_PRINTING_ARCHITECTURE
604 wxPrintout
*wxView::OnCreatePrintout()
606 return new wxDocPrintout(this);
608 #endif // wxUSE_PRINTING_ARCHITECTURE
610 // ----------------------------------------------------------------------------
612 // ----------------------------------------------------------------------------
614 wxDocTemplate::wxDocTemplate(wxDocManager
*manager
,
615 const wxString
& descr
,
616 const wxString
& filter
,
619 const wxString
& docTypeName
,
620 const wxString
& viewTypeName
,
621 wxClassInfo
*docClassInfo
,
622 wxClassInfo
*viewClassInfo
,
625 m_documentManager
= manager
;
626 m_description
= descr
;
629 m_fileFilter
= filter
;
631 m_docTypeName
= docTypeName
;
632 m_viewTypeName
= viewTypeName
;
633 m_documentManager
->AssociateTemplate(this);
635 m_docClassInfo
= docClassInfo
;
636 m_viewClassInfo
= viewClassInfo
;
639 wxDocTemplate::~wxDocTemplate()
641 m_documentManager
->DisassociateTemplate(this);
644 // Tries to dynamically construct an object of the right class.
645 wxDocument
*wxDocTemplate::CreateDocument(const wxString
& path
, long flags
)
648 return (wxDocument
*) NULL
;
649 wxDocument
*doc
= (wxDocument
*)m_docClassInfo
->CreateObject();
650 doc
->SetFilename(path
);
651 doc
->SetDocumentTemplate(this);
652 GetDocumentManager()->AddDocument(doc
);
653 doc
->SetCommandProcessor(doc
->OnCreateCommandProcessor());
655 if (doc
->OnCreate(path
, flags
))
660 return (wxDocument
*) NULL
;
664 wxView
*wxDocTemplate::CreateView(wxDocument
*doc
, long flags
)
666 if (!m_viewClassInfo
)
667 return (wxView
*) NULL
;
668 wxView
*view
= (wxView
*)m_viewClassInfo
->CreateObject();
669 view
->SetDocument(doc
);
670 if (view
->OnCreate(doc
, flags
))
677 return (wxView
*) NULL
;
681 // The default (very primitive) format detection: check is the extension is
682 // that of the template
683 bool wxDocTemplate::FileMatchesTemplate(const wxString
& path
)
685 return GetDefaultExtension().IsSameAs(FindExtension(path
));
688 // ----------------------------------------------------------------------------
690 // ----------------------------------------------------------------------------
692 BEGIN_EVENT_TABLE(wxDocManager
, wxEvtHandler
)
693 EVT_MENU(wxID_OPEN
, wxDocManager::OnFileOpen
)
694 EVT_MENU(wxID_CLOSE
, wxDocManager::OnFileClose
)
695 EVT_MENU(wxID_REVERT
, wxDocManager::OnFileRevert
)
696 EVT_MENU(wxID_NEW
, wxDocManager::OnFileNew
)
697 EVT_MENU(wxID_SAVE
, wxDocManager::OnFileSave
)
698 EVT_MENU(wxID_SAVEAS
, wxDocManager::OnFileSaveAs
)
699 EVT_MENU(wxID_UNDO
, wxDocManager::OnUndo
)
700 EVT_MENU(wxID_REDO
, wxDocManager::OnRedo
)
701 #if wxUSE_PRINTING_ARCHITECTURE
702 EVT_MENU(wxID_PRINT
, wxDocManager::OnPrint
)
703 EVT_MENU(wxID_PRINT_SETUP
, wxDocManager::OnPrintSetup
)
704 EVT_MENU(wxID_PREVIEW
, wxDocManager::OnPreview
)
708 wxDocManager::wxDocManager(long flags
, bool initialize
)
710 m_defaultDocumentNameCounter
= 1;
712 m_currentView
= (wxView
*) NULL
;
713 m_maxDocsOpen
= 10000;
714 m_fileHistory
= (wxFileHistory
*) NULL
;
719 wxDocManager::~wxDocManager()
723 delete m_fileHistory
;
726 bool wxDocManager::Clear(bool force
)
728 wxNode
*node
= m_docs
.First();
731 wxDocument
*doc
= (wxDocument
*)node
->Data();
732 wxNode
*next
= node
->Next();
734 if (!doc
->Close() && !force
)
737 // Implicitly deletes the document when the last
738 // view is removed (deleted)
739 doc
->DeleteAllViews();
741 // Check document is deleted
742 if (m_docs
.Member(doc
))
745 // This assumes that documents are not connected in
746 // any way, i.e. deleting one document does NOT
750 node
= m_templates
.First();
753 wxDocTemplate
*templ
= (wxDocTemplate
*) node
->Data();
754 wxNode
* next
= node
->Next();
761 bool wxDocManager::Initialize()
763 m_fileHistory
= OnCreateFileHistory();
767 wxFileHistory
*wxDocManager::OnCreateFileHistory()
769 return new wxFileHistory
;
772 void wxDocManager::OnFileClose(wxCommandEvent
& WXUNUSED(event
))
774 wxDocument
*doc
= GetCurrentDocument();
779 doc
->DeleteAllViews();
780 if (m_docs
.Member(doc
))
785 void wxDocManager::OnFileNew(wxCommandEvent
& WXUNUSED(event
))
787 CreateDocument(wxString(""), wxDOC_NEW
);
790 void wxDocManager::OnFileOpen(wxCommandEvent
& WXUNUSED(event
))
792 CreateDocument(wxString(""), 0);
795 void wxDocManager::OnFileRevert(wxCommandEvent
& WXUNUSED(event
))
797 wxDocument
*doc
= GetCurrentDocument();
803 void wxDocManager::OnFileSave(wxCommandEvent
& WXUNUSED(event
))
805 wxDocument
*doc
= GetCurrentDocument();
811 void wxDocManager::OnFileSaveAs(wxCommandEvent
& WXUNUSED(event
))
813 wxDocument
*doc
= GetCurrentDocument();
819 void wxDocManager::OnPrint(wxCommandEvent
& WXUNUSED(event
))
821 #if wxUSE_PRINTING_ARCHITECTURE
822 wxView
*view
= GetCurrentView();
826 wxPrintout
*printout
= view
->OnCreatePrintout();
830 printer
.Print(view
->GetFrame(), printout
, TRUE
);
834 #endif // wxUSE_PRINTING_ARCHITECTURE
837 void wxDocManager::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
839 #if wxUSE_PRINTING_ARCHITECTURE
840 wxWindow
*parentWin
= wxTheApp
->GetTopWindow();
841 wxView
*view
= GetCurrentView();
843 parentWin
= view
->GetFrame();
845 wxPrintDialogData data
;
847 wxPrintDialog
printerDialog(parentWin
, &data
);
848 printerDialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
849 printerDialog
.ShowModal();
850 #endif // wxUSE_PRINTING_ARCHITECTURE
853 void wxDocManager::OnPreview(wxCommandEvent
& WXUNUSED(event
))
855 #if wxUSE_PRINTING_ARCHITECTURE
856 wxView
*view
= GetCurrentView();
860 wxPrintout
*printout
= view
->OnCreatePrintout();
863 // Pass two printout objects: for preview, and possible printing.
864 wxPrintPreviewBase
*preview
= (wxPrintPreviewBase
*) NULL
;
865 preview
= new wxPrintPreview(printout
, view
->OnCreatePrintout());
867 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, (wxFrame
*)wxTheApp
->GetTopWindow(), _("Print Preview"),
868 wxPoint(100, 100), wxSize(600, 650));
869 frame
->Centre(wxBOTH
);
873 #endif // wxUSE_PRINTING_ARCHITECTURE
876 void wxDocManager::OnUndo(wxCommandEvent
& WXUNUSED(event
))
878 wxDocument
*doc
= GetCurrentDocument();
881 if (doc
->GetCommandProcessor())
882 doc
->GetCommandProcessor()->Undo();
885 void wxDocManager::OnRedo(wxCommandEvent
& WXUNUSED(event
))
887 wxDocument
*doc
= GetCurrentDocument();
890 if (doc
->GetCommandProcessor())
891 doc
->GetCommandProcessor()->Redo();
894 wxView
*wxDocManager::GetCurrentView() const
897 return m_currentView
;
898 if (m_docs
.Number() == 1)
900 wxDocument
* doc
= (wxDocument
*) m_docs
.First()->Data();
901 return doc
->GetFirstView();
903 return (wxView
*) NULL
;
906 // Extend event processing to search the view's event table
907 bool wxDocManager::ProcessEvent(wxEvent
& event
)
909 wxView
* view
= GetCurrentView();
912 if (view
->ProcessEvent(event
))
915 return wxEvtHandler::ProcessEvent(event
);
918 wxDocument
*wxDocManager::CreateDocument(const wxString
& path
, long flags
)
920 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
923 for (i
= 0; i
< m_templates
.Number(); i
++)
925 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
926 if (temp
->IsVisible())
935 return (wxDocument
*) NULL
;
938 // If we've reached the max number of docs, close the
940 if (GetDocuments().Number() >= m_maxDocsOpen
)
942 wxDocument
*doc
= (wxDocument
*)GetDocuments().First()->Data();
945 // Implicitly deletes the document when
946 // the last view is deleted
947 doc
->DeleteAllViews();
949 // Check we're really deleted
950 if (m_docs
.Member(doc
))
954 return (wxDocument
*) NULL
;
957 // New document: user chooses a template, unless there's only one.
958 if (flags
& wxDOC_NEW
)
962 wxDocTemplate
*temp
= templates
[0];
964 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
967 newDoc
->SetDocumentName(temp
->GetDocumentName());
968 newDoc
->SetDocumentTemplate(temp
);
969 newDoc
->OnNewDocument();
974 wxDocTemplate
*temp
= SelectDocumentType(templates
, n
);
978 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
981 newDoc
->SetDocumentName(temp
->GetDocumentName());
982 newDoc
->SetDocumentTemplate(temp
);
983 newDoc
->OnNewDocument();
988 return (wxDocument
*) NULL
;
992 wxDocTemplate
*temp
= (wxDocTemplate
*) NULL
;
994 wxString
path2(wxT(""));
998 if (flags
& wxDOC_SILENT
)
999 temp
= FindTemplateForPath(path2
);
1001 temp
= SelectDocumentPath(templates
, n
, path2
, flags
);
1007 wxDocument
*newDoc
= temp
->CreateDocument(path2
, flags
);
1010 newDoc
->SetDocumentName(temp
->GetDocumentName());
1011 newDoc
->SetDocumentTemplate(temp
);
1012 if (!newDoc
->OnOpenDocument(path2
))
1015 return (wxDocument
*) NULL
;
1017 AddFileToHistory(path2
);
1022 return (wxDocument
*) NULL
;
1025 wxView
*wxDocManager::CreateView(wxDocument
*doc
, long flags
)
1027 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
1030 for (i
= 0; i
< m_templates
.Number(); i
++)
1032 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
1033 if (temp
->IsVisible())
1035 if (temp
->GetDocumentName() == doc
->GetDocumentName())
1037 templates
[n
] = temp
;
1045 return (wxView
*) NULL
;
1049 wxDocTemplate
*temp
= templates
[0];
1051 wxView
*view
= temp
->CreateView(doc
, flags
);
1053 view
->SetViewName(temp
->GetViewName());
1057 wxDocTemplate
*temp
= SelectViewType(templates
, n
);
1061 wxView
*view
= temp
->CreateView(doc
, flags
);
1063 view
->SetViewName(temp
->GetViewName());
1067 return (wxView
*) NULL
;
1070 // Not yet implemented
1071 void wxDocManager::DeleteTemplate(wxDocTemplate
*WXUNUSED(temp
), long WXUNUSED(flags
))
1075 // Not yet implemented
1076 bool wxDocManager::FlushDoc(wxDocument
*WXUNUSED(doc
))
1081 wxDocument
*wxDocManager::GetCurrentDocument() const
1084 return m_currentView
->GetDocument();
1086 return (wxDocument
*) NULL
;
1089 // Make a default document name
1090 bool wxDocManager::MakeDefaultName(wxString
& name
)
1092 name
.Printf(_("unnamed%d"), m_defaultDocumentNameCounter
);
1093 m_defaultDocumentNameCounter
++;
1098 // Not yet implemented
1099 wxDocTemplate
*wxDocManager::MatchTemplate(const wxString
& WXUNUSED(path
))
1101 return (wxDocTemplate
*) NULL
;
1104 // File history management
1105 void wxDocManager::AddFileToHistory(const wxString
& file
)
1108 m_fileHistory
->AddFileToHistory(file
);
1111 void wxDocManager::RemoveFileFromHistory(int i
)
1114 m_fileHistory
->RemoveFileFromHistory(i
);
1117 wxString
wxDocManager::GetHistoryFile(int i
) const
1122 histFile
= m_fileHistory
->GetHistoryFile(i
);
1127 void wxDocManager::FileHistoryUseMenu(wxMenu
*menu
)
1130 m_fileHistory
->UseMenu(menu
);
1133 void wxDocManager::FileHistoryRemoveMenu(wxMenu
*menu
)
1136 m_fileHistory
->RemoveMenu(menu
);
1140 void wxDocManager::FileHistoryLoad(wxConfigBase
& config
)
1143 m_fileHistory
->Load(config
);
1146 void wxDocManager::FileHistorySave(wxConfigBase
& config
)
1149 m_fileHistory
->Save(config
);
1153 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu
* menu
)
1156 m_fileHistory
->AddFilesToMenu(menu
);
1159 void wxDocManager::FileHistoryAddFilesToMenu()
1162 m_fileHistory
->AddFilesToMenu();
1165 int wxDocManager::GetNoHistoryFiles() const
1168 return m_fileHistory
->GetNoHistoryFiles();
1174 // Find out the document template via matching in the document file format
1175 // against that of the template
1176 wxDocTemplate
*wxDocManager::FindTemplateForPath(const wxString
& path
)
1178 wxDocTemplate
*theTemplate
= (wxDocTemplate
*) NULL
;
1180 // Find the template which this extension corresponds to
1182 for (i
= 0; i
< m_templates
.Number(); i
++)
1184 wxDocTemplate
*temp
= (wxDocTemplate
*)m_templates
.Nth(i
)->Data();
1185 if ( temp
->FileMatchesTemplate(path
) )
1194 // Prompts user to open a file, using file specs in templates.
1195 // How to implement in wxWindows? Must extend the file selector
1196 // dialog or implement own; OR match the extension to the
1197 // template extension.
1199 wxDocTemplate
*wxDocManager::SelectDocumentPath(wxDocTemplate
**templates
,
1200 #if defined(__WXMSW__) || defined(__WXGTK__)
1203 int WXUNUSED(noTemplates
),
1206 long WXUNUSED(flags
),
1207 bool WXUNUSED(save
))
1209 // We can only have multiple filters in Windows and GTK
1210 #if defined(__WXMSW__) || defined(__WXGTK__)
1214 for (i
= 0; i
< noTemplates
; i
++)
1216 if (templates
[i
]->IsVisible())
1218 // add a '|' to separate this filter from the previous one
1219 if ( !descrBuf
.IsEmpty() )
1220 descrBuf
<< wxT('|');
1222 descrBuf
<< templates
[i
]->GetDescription()
1223 << wxT(" (") << templates
[i
]->GetFileFilter() << wxT(") |")
1224 << templates
[i
]->GetFileFilter();
1228 wxString descrBuf
= wxT("*.*");
1231 int FilterIndex
= 0;
1232 wxString pathTmp
= wxFileSelectorEx(_("Select a file"),
1238 wxTheApp
->GetTopWindow());
1240 if (!pathTmp
.IsEmpty())
1242 m_lastDirectory
= wxPathOnly(pathTmp
);
1245 wxString theExt
= FindExtension(path
);
1247 return (wxDocTemplate
*) NULL
;
1249 // This is dodgy in that we're selecting the template on the
1250 // basis of the file extension, which may not be a standard
1251 // one. We really want to know exactly which template was
1252 // chosen by using a more advanced file selector.
1253 wxDocTemplate
*theTemplate
= FindTemplateForPath(path
);
1255 theTemplate
= templates
[FilterIndex
];
1262 return (wxDocTemplate
*) NULL
;
1265 // In all other windowing systems, until we have more advanced
1266 // file selectors, we must select the document type (template) first, and
1267 // _then_ pop up the file selector.
1268 wxDocTemplate
*temp
= SelectDocumentType(templates
, noTemplates
);
1270 return (wxDocTemplate
*) NULL
;
1272 wxChar
*pathTmp
= wxFileSelector(_("Select a file"), wxT(""), wxT(""),
1273 temp
->GetDefaultExtension(),
1274 temp
->GetFileFilter(),
1275 0, wxTheApp
->GetTopWindow());
1283 return (wxDocTemplate
*) NULL
;
1287 wxDocTemplate
*wxDocManager::SelectDocumentType(wxDocTemplate
**templates
,
1290 wxChar
**strings
= new wxChar
*[noTemplates
];
1291 wxChar
**data
= new wxChar
*[noTemplates
];
1294 for (i
= 0; i
< noTemplates
; i
++)
1296 if (templates
[i
]->IsVisible())
1298 strings
[n
] = (wxChar
*)templates
[i
]->m_description
.c_str();
1299 data
[n
] = (wxChar
*)templates
[i
];
1307 return (wxDocTemplate
*) NULL
;
1311 wxDocTemplate
*temp
= (wxDocTemplate
*)data
[0];
1317 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n
,
1318 strings
, (void **)data
);
1324 wxDocTemplate
*wxDocManager::SelectViewType(wxDocTemplate
**templates
,
1327 wxChar
**strings
= new wxChar
*[noTemplates
];
1328 wxChar
**data
= new wxChar
*[noTemplates
];
1331 for (i
= 0; i
< noTemplates
; i
++)
1333 if (templates
[i
]->IsVisible() && (templates
[i
]->GetViewName() != wxT("")))
1335 strings
[n
] = (wxChar
*)templates
[i
]->m_viewTypeName
.c_str();
1336 data
[n
] = (wxChar
*)templates
[i
];
1340 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n
,
1341 strings
, (void **)data
);
1347 void wxDocManager::AssociateTemplate(wxDocTemplate
*temp
)
1349 if (!m_templates
.Member(temp
))
1350 m_templates
.Append(temp
);
1353 void wxDocManager::DisassociateTemplate(wxDocTemplate
*temp
)
1355 m_templates
.DeleteObject(temp
);
1358 // Add and remove a document from the manager's list
1359 void wxDocManager::AddDocument(wxDocument
*doc
)
1361 if (!m_docs
.Member(doc
))
1365 void wxDocManager::RemoveDocument(wxDocument
*doc
)
1367 m_docs
.DeleteObject(doc
);
1370 // Views or windows should inform the document manager
1371 // when a view is going in or out of focus
1372 void wxDocManager::ActivateView(wxView
*view
, bool activate
, bool WXUNUSED(deleting
))
1374 // If we're deactiving, and if we're not actually deleting the view, then
1375 // don't reset the current view because we may be going to
1376 // a window without a view.
1377 // WHAT DID I MEAN BY THAT EXACTLY?
1381 if (m_currentView == view)
1382 m_currentView = NULL;
1388 m_currentView
= view
;
1390 m_currentView
= (wxView
*) NULL
;
1394 // ----------------------------------------------------------------------------
1395 // Default document child frame
1396 // ----------------------------------------------------------------------------
1398 BEGIN_EVENT_TABLE(wxDocChildFrame
, wxFrame
)
1399 EVT_ACTIVATE(wxDocChildFrame::OnActivate
)
1400 EVT_CLOSE(wxDocChildFrame::OnCloseWindow
)
1403 wxDocChildFrame::wxDocChildFrame(wxDocument
*doc
,
1407 const wxString
& title
,
1411 const wxString
& name
)
1412 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1414 m_childDocument
= doc
;
1417 view
->SetFrame(this);
1420 wxDocChildFrame::~wxDocChildFrame()
1424 // Extend event processing to search the view's event table
1425 bool wxDocChildFrame::ProcessEvent(wxEvent
& event
)
1428 m_childView
->Activate(TRUE
);
1430 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
1432 // Only hand up to the parent if it's a menu command
1433 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
1434 return wxEvtHandler::ProcessEvent(event
);
1442 void wxDocChildFrame::OnActivate(wxActivateEvent
& event
)
1444 wxFrame::OnActivate(event
);
1447 m_childView
->Activate(event
.GetActive());
1450 void wxDocChildFrame::OnCloseWindow(wxCloseEvent
& event
)
1455 if (!event
.CanVeto())
1456 ans
= TRUE
; // Must delete.
1458 ans
= m_childView
->Close(FALSE
); // FALSE means don't delete associated window
1462 m_childView
->Activate(FALSE
);
1464 m_childView
= (wxView
*) NULL
;
1465 m_childDocument
= (wxDocument
*) NULL
;
1476 // ----------------------------------------------------------------------------
1477 // Default parent frame
1478 // ----------------------------------------------------------------------------
1480 BEGIN_EVENT_TABLE(wxDocParentFrame
, wxFrame
)
1481 EVT_MENU(wxID_EXIT
, wxDocParentFrame::OnExit
)
1482 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocParentFrame::OnMRUFile
)
1483 EVT_CLOSE(wxDocParentFrame::OnCloseWindow
)
1486 wxDocParentFrame::wxDocParentFrame(wxDocManager
*manager
,
1489 const wxString
& title
,
1493 const wxString
& name
)
1494 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1496 m_docManager
= manager
;
1499 void wxDocParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
1504 void wxDocParentFrame::OnMRUFile(wxCommandEvent
& event
)
1506 int n
= event
.GetSelection() - wxID_FILE1
; // the index in MRU list
1507 wxString
filename(m_docManager
->GetHistoryFile(n
));
1508 if ( !filename
.IsEmpty() )
1510 // verify that the file exists before doing anything else
1511 if ( wxFile::Exists(filename
) )
1514 (void)m_docManager
->CreateDocument(filename
, wxDOC_SILENT
);
1518 // remove the bogus filename from the MRU list and notify the user
1520 m_docManager
->RemoveFileFromHistory(n
);
1522 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\n"
1523 "It has been also removed from the MRU files list."),
1529 // Extend event processing to search the view's event table
1530 bool wxDocParentFrame::ProcessEvent(wxEvent
& event
)
1532 // Try the document manager, then do default processing
1533 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
1534 return wxEvtHandler::ProcessEvent(event
);
1539 // Define the behaviour for the frame closing
1540 // - must delete all frames except for the main one.
1541 void wxDocParentFrame::OnCloseWindow(wxCloseEvent
& event
)
1543 if (m_docManager
->Clear(!event
.CanVeto()))
1551 #if wxUSE_PRINTING_ARCHITECTURE
1553 wxDocPrintout::wxDocPrintout(wxView
*view
, const wxString
& title
)
1556 m_printoutView
= view
;
1559 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page
))
1563 // Get the logical pixels per inch of screen and printer
1564 int ppiScreenX
, ppiScreenY
;
1565 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
1566 int ppiPrinterX
, ppiPrinterY
;
1567 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
1569 // This scales the DC so that the printout roughly represents the
1570 // the screen scaling. The text point size _should_ be the right size
1571 // but in fact is too small for some reason. This is a detail that will
1572 // need to be addressed at some point but can be fudged for the
1574 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
1576 // Now we have to check in case our real page size is reduced
1577 // (e.g. because we're drawing to a print preview memory DC)
1578 int pageWidth
, pageHeight
;
1580 dc
->GetSize(&w
, &h
);
1581 GetPageSizePixels(&pageWidth
, &pageHeight
);
1583 // If printer pageWidth == current DC width, then this doesn't
1584 // change. But w might be the preview bitmap width, so scale down.
1585 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
1586 dc
->SetUserScale(overallScale
, overallScale
);
1590 m_printoutView
->OnDraw(dc
);
1595 bool wxDocPrintout::HasPage(int pageNum
)
1597 return (pageNum
== 1);
1600 bool wxDocPrintout::OnBeginDocument(int startPage
, int endPage
)
1602 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
1608 void wxDocPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
1616 #endif // wxUSE_PRINTING_ARCHITECTURE
1618 // ----------------------------------------------------------------------------
1619 // Command processing framework
1620 // ----------------------------------------------------------------------------
1622 wxCommand::wxCommand(bool canUndoIt
, const wxString
& name
)
1624 m_canUndo
= canUndoIt
;
1625 m_commandName
= name
;
1628 wxCommand::~wxCommand()
1632 // Command processor
1633 wxCommandProcessor::wxCommandProcessor(int maxCommands
)
1635 m_maxNoCommands
= maxCommands
;
1636 m_currentCommand
= (wxNode
*) NULL
;
1637 m_commandEditMenu
= (wxMenu
*) NULL
;
1640 wxCommandProcessor::~wxCommandProcessor()
1645 // Pass a command to the processor. The processor calls Do();
1646 // if successful, is appended to the command history unless
1647 // storeIt is FALSE.
1648 bool wxCommandProcessor::Submit(wxCommand
*command
, bool storeIt
)
1650 bool success
= command
->Do();
1651 if (success
&& storeIt
)
1653 if (m_commands
.Number() == m_maxNoCommands
)
1655 wxNode
*firstNode
= m_commands
.First();
1656 wxCommand
*firstCommand
= (wxCommand
*)firstNode
->Data();
1657 delete firstCommand
;
1661 // Correct a bug: we must chop off the current 'branch'
1662 // so that we're at the end of the command list.
1663 if (!m_currentCommand
)
1667 wxNode
*node
= m_currentCommand
->Next();
1670 wxNode
*next
= node
->Next();
1671 delete (wxCommand
*)node
->Data();
1677 m_commands
.Append(command
);
1678 m_currentCommand
= m_commands
.Last();
1684 bool wxCommandProcessor::Undo()
1686 if (m_currentCommand
)
1688 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1689 if (command
->CanUndo())
1691 bool success
= command
->Undo();
1694 m_currentCommand
= m_currentCommand
->Previous();
1703 bool wxCommandProcessor::Redo()
1705 wxCommand
*redoCommand
= (wxCommand
*) NULL
;
1706 wxNode
*redoNode
= (wxNode
*) NULL
;
1707 if (m_currentCommand
&& m_currentCommand
->Next())
1709 redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1710 redoNode
= m_currentCommand
->Next();
1714 if (m_commands
.Number() > 0)
1716 redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1717 redoNode
= m_commands
.First();
1723 bool success
= redoCommand
->Do();
1726 m_currentCommand
= redoNode
;
1734 bool wxCommandProcessor::CanUndo() const
1736 if (m_currentCommand
)
1737 return ((wxCommand
*)m_currentCommand
->Data())->CanUndo();
1741 bool wxCommandProcessor::CanRedo() const
1743 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() == (wxNode
*) NULL
))
1746 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() != (wxNode
*) NULL
))
1749 if ((m_currentCommand
== (wxNode
*) NULL
) && (m_commands
.Number() > 0))
1755 void wxCommandProcessor::Initialize()
1757 m_currentCommand
= m_commands
.Last();
1761 void wxCommandProcessor::SetMenuStrings()
1763 if (m_commandEditMenu
)
1766 if (m_currentCommand
)
1768 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1769 wxString
commandName(command
->GetName());
1770 if (commandName
== wxT("")) commandName
= _("Unnamed command");
1771 bool canUndo
= command
->CanUndo();
1773 buf
= wxString(_("&Undo ")) + commandName
;
1775 buf
= wxString(_("Can't &Undo ")) + commandName
;
1777 m_commandEditMenu
->SetLabel(wxID_UNDO
, buf
);
1778 m_commandEditMenu
->Enable(wxID_UNDO
, canUndo
);
1780 // We can redo, if we're not at the end of the history.
1781 if (m_currentCommand
->Next())
1783 wxCommand
*redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1784 wxString
redoCommandName(redoCommand
->GetName());
1785 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1786 buf
= wxString(_("&Redo ")) + redoCommandName
;
1787 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1788 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1792 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1793 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1798 m_commandEditMenu
->SetLabel(wxID_UNDO
, _("&Undo"));
1799 m_commandEditMenu
->Enable(wxID_UNDO
, FALSE
);
1801 if (m_commands
.Number() == 0)
1803 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1804 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1808 // currentCommand is NULL but there are commands: this means that
1809 // we've undone to the start of the list, but can redo the first.
1810 wxCommand
*redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1811 wxString
redoCommandName(redoCommand
->GetName());
1812 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1813 buf
= wxString(_("&Redo ")) + redoCommandName
;
1814 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1815 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1821 void wxCommandProcessor::ClearCommands()
1823 wxNode
*node
= m_commands
.First();
1826 wxCommand
*command
= (wxCommand
*)node
->Data();
1829 node
= m_commands
.First();
1831 m_currentCommand
= (wxNode
*) NULL
;
1834 // ----------------------------------------------------------------------------
1835 // File history processor
1836 // ----------------------------------------------------------------------------
1838 wxFileHistory::wxFileHistory(int maxFiles
)
1840 m_fileMaxFiles
= maxFiles
;
1842 m_fileHistory
= new wxChar
*[m_fileMaxFiles
];
1845 wxFileHistory::~wxFileHistory()
1848 for (i
= 0; i
< m_fileHistoryN
; i
++)
1849 delete[] m_fileHistory
[i
];
1850 delete[] m_fileHistory
;
1853 // File history management
1854 void wxFileHistory::AddFileToHistory(const wxString
& file
)
1857 // Check we don't already have this file
1858 for (i
= 0; i
< m_fileHistoryN
; i
++)
1860 if (m_fileHistory
[i
] && wxString(m_fileHistory
[i
]) == file
)
1864 // Add to the project file history:
1865 // Move existing files (if any) down so we can insert file at beginning.
1867 // First delete filename that has popped off the end of the array (if any)
1868 if (m_fileHistoryN
== m_fileMaxFiles
)
1870 delete[] m_fileHistory
[m_fileMaxFiles
-1];
1871 m_fileHistory
[m_fileMaxFiles
-1] = (wxChar
*) NULL
;
1873 if (m_fileHistoryN
< m_fileMaxFiles
)
1875 wxNode
* node
= m_fileMenus
.First();
1878 wxMenu
* menu
= (wxMenu
*) node
->Data();
1879 if (m_fileHistoryN
== 0)
1880 menu
->AppendSeparator();
1881 menu
->Append(wxID_FILE1
+m_fileHistoryN
, _("[EMPTY]"));
1882 node
= node
->Next();
1886 // Shuffle filenames down
1887 for (i
= (m_fileHistoryN
-1); i
> 0; i
--)
1889 m_fileHistory
[i
] = m_fileHistory
[i
-1];
1891 m_fileHistory
[0] = copystring(file
);
1893 for (i
= 0; i
< m_fileHistoryN
; i
++)
1894 if (m_fileHistory
[i
])
1897 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
1898 wxNode
* node
= m_fileMenus
.First();
1901 wxMenu
* menu
= (wxMenu
*) node
->Data();
1902 menu
->SetLabel(wxID_FILE1
+i
, buf
);
1903 node
= node
->Next();
1908 void wxFileHistory::RemoveFileFromHistory(int i
)
1910 wxCHECK_RET( i
< m_fileHistoryN
,
1911 wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
1913 wxNode
* node
= m_fileMenus
.First();
1916 wxMenu
* menu
= (wxMenu
*) node
->Data();
1918 // delete the element from the array (could use memmove() too...)
1919 delete [] m_fileHistory
[i
];
1922 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1924 m_fileHistory
[j
] = m_fileHistory
[j
+ 1];
1927 // shuffle filenames up
1929 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1931 buf
.Printf(s_MRUEntryFormat
, j
+ 1, m_fileHistory
[j
]);
1932 menu
->SetLabel(wxID_FILE1
+ j
, buf
);
1935 node
= node
->Next();
1937 // delete the last menu item which is unused now
1938 menu
->Delete(wxID_FILE1
+ m_fileHistoryN
- 1);
1940 // delete the last separator too if no more files are left
1941 if ( m_fileHistoryN
== 1 )
1943 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetLast();
1946 wxMenuItem
*menuItem
= node
->GetData();
1947 if ( menuItem
->IsSeparator() )
1949 menu
->Delete(menuItem
);
1951 //else: should we search backwards for the last separator?
1953 //else: menu is empty somehow
1960 wxString
wxFileHistory::GetHistoryFile(int i
) const
1963 if ( i
< m_fileHistoryN
)
1965 s
= m_fileHistory
[i
];
1969 wxFAIL_MSG( wxT("bad index in wxFileHistory::GetHistoryFile") );
1975 void wxFileHistory::UseMenu(wxMenu
*menu
)
1977 if (!m_fileMenus
.Member(menu
))
1978 m_fileMenus
.Append(menu
);
1981 void wxFileHistory::RemoveMenu(wxMenu
*menu
)
1983 m_fileMenus
.DeleteObject(menu
);
1987 void wxFileHistory::Load(wxConfigBase
& config
)
1991 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1992 wxString historyFile
;
1993 while ((m_fileHistoryN
<= m_fileMaxFiles
) && config
.Read(buf
, &historyFile
) && (historyFile
!= wxT("")))
1995 m_fileHistory
[m_fileHistoryN
] = copystring((const wxChar
*) historyFile
);
1997 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1998 historyFile
= wxT("");
2003 void wxFileHistory::Save(wxConfigBase
& config
)
2006 for (i
= 0; i
< m_fileHistoryN
; i
++)
2009 buf
.Printf(wxT("file%d"), i
+1);
2010 config
.Write(buf
, wxString(m_fileHistory
[i
]));
2013 #endif // wxUSE_CONFIG
2015 void wxFileHistory::AddFilesToMenu()
2017 if (m_fileHistoryN
> 0)
2019 wxNode
* node
= m_fileMenus
.First();
2022 wxMenu
* menu
= (wxMenu
*) node
->Data();
2023 menu
->AppendSeparator();
2025 for (i
= 0; i
< m_fileHistoryN
; i
++)
2027 if (m_fileHistory
[i
])
2030 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2031 menu
->Append(wxID_FILE1
+i
, buf
);
2034 node
= node
->Next();
2039 void wxFileHistory::AddFilesToMenu(wxMenu
* menu
)
2041 if (m_fileHistoryN
> 0)
2043 menu
->AppendSeparator();
2045 for (i
= 0; i
< m_fileHistoryN
; i
++)
2047 if (m_fileHistory
[i
])
2050 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2051 menu
->Append(wxID_FILE1
+i
, buf
);
2057 // ----------------------------------------------------------------------------
2058 // Permits compatibility with existing file formats and functions that
2059 // manipulate files directly
2060 // ----------------------------------------------------------------------------
2062 #if wxUSE_STD_IOSTREAM
2063 bool wxTransferFileToStream(const wxString
& filename
, ostream
& stream
)
2068 if ((fd1
= fopen (filename
.fn_str(), "rb")) == NULL
)
2071 while ((ch
= getc (fd1
)) != EOF
)
2072 stream
<< (unsigned char)ch
;
2078 bool wxTransferStreamToFile(istream
& stream
, const wxString
& filename
)
2083 if ((fd1
= fopen (filename
.fn_str(), "wb")) == NULL
)
2088 while (!stream
.eof())
2099 #endif // wxUSE_DOC_VIEW_ARCHITECTURE