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 char *s_MRUEntryFormat
= T("&%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
== T("") || !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
== T(""))
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() != T(""))
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() != 0)
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() != T(""))
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() != 0)
335 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
336 GetDocumentWindow());
339 if (!LoadObject(store
))
341 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
342 GetDocumentWindow());
345 SetFilename(file
, TRUE
);
354 #if wxUSE_STD_IOSTREAM
355 istream
& wxDocument::LoadObject(istream
& stream
)
357 wxInputStream
& wxDocument::LoadObject(wxInputStream
& stream
)
363 #if wxUSE_STD_IOSTREAM
364 ostream
& wxDocument::SaveObject(ostream
& stream
)
366 wxOutputStream
& wxDocument::SaveObject(wxOutputStream
& stream
)
372 bool wxDocument::Revert()
378 // Get title, or filename if no title, else unnamed
379 bool wxDocument::GetPrintableName(wxString
& buf
) const
381 if (m_documentTitle
!= T(""))
383 buf
= m_documentTitle
;
386 else if (m_documentFile
!= T(""))
388 buf
= wxFileNameFromPath(m_documentFile
);
398 wxWindow
*wxDocument::GetDocumentWindow() const
400 wxView
*view
= GetFirstView();
402 return view
->GetFrame();
404 return wxTheApp
->GetTopWindow();
407 wxCommandProcessor
*wxDocument::OnCreateCommandProcessor()
409 return new wxCommandProcessor
;
412 // TRUE if safe to close
413 bool wxDocument::OnSaveModified()
418 GetPrintableName(title
);
421 if (wxTheApp
->GetAppName() != T(""))
422 msgTitle
= wxTheApp
->GetAppName();
424 msgTitle
= wxString(_("Warning"));
427 prompt
.Printf(_("Do you want to save changes to document %s?"),
428 (const wxChar
*)title
);
429 int res
= wxMessageBox(prompt
, msgTitle
,
430 wxYES_NO
|wxCANCEL
|wxICON_QUESTION
,
431 GetDocumentWindow());
437 else if (res
== wxYES
)
439 else if (res
== wxCANCEL
)
445 bool wxDocument::Draw(wxDC
& WXUNUSED(context
))
450 bool wxDocument::AddView(wxView
*view
)
452 if (!m_documentViews
.Member(view
))
454 m_documentViews
.Append(view
);
460 bool wxDocument::RemoveView(wxView
*view
)
462 (void)m_documentViews
.DeleteObject(view
);
467 bool wxDocument::OnCreate(const wxString
& WXUNUSED(path
), long flags
)
469 if (GetDocumentTemplate()->CreateView(this, flags
))
475 // Called after a view is added or removed.
476 // The default implementation deletes the document if
477 // there are no more views.
478 void wxDocument::OnChangedViewList()
480 if (m_documentViews
.Number() == 0)
482 if (OnSaveModified())
489 void wxDocument::UpdateAllViews(wxView
*sender
, wxObject
*hint
)
491 wxNode
*node
= m_documentViews
.First();
494 wxView
*view
= (wxView
*)node
->Data();
495 view
->OnUpdate(sender
, hint
);
500 void wxDocument::SetFilename(const wxString
& filename
, bool notifyViews
)
502 m_documentFile
= filename
;
505 // Notify the views that the filename has changed
506 wxNode
*node
= m_documentViews
.First();
509 wxView
*view
= (wxView
*)node
->Data();
510 view
->OnChangeFilename();
516 // ----------------------------------------------------------------------------
518 // ----------------------------------------------------------------------------
523 m_viewDocument
= (wxDocument
*) NULL
;
526 m_viewFrame
= (wxFrame
*) NULL
;
531 GetDocumentManager()->ActivateView(this, FALSE
, TRUE
);
532 m_viewDocument
->RemoveView(this);
535 // Extend event processing to search the document's event table
536 bool wxView::ProcessEvent(wxEvent
& event
)
538 if ( !GetDocument() || !GetDocument()->ProcessEvent(event
) )
539 return wxEvtHandler::ProcessEvent(event
);
544 void wxView::OnActivateView(bool WXUNUSED(activate
), wxView
*WXUNUSED(activeView
), wxView
*WXUNUSED(deactiveView
))
548 void wxView::OnPrint(wxDC
*dc
, wxObject
*WXUNUSED(info
))
553 void wxView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*WXUNUSED(hint
))
557 void wxView::OnChangeFilename()
559 if (GetFrame() && GetDocument())
562 GetDocument()->GetPrintableName(name
);
564 GetFrame()->SetTitle(name
);
568 void wxView::SetDocument(wxDocument
*doc
)
570 m_viewDocument
= doc
;
575 bool wxView::Close(bool deleteWindow
)
577 if (OnClose(deleteWindow
))
583 void wxView::Activate(bool activate
)
585 if (GetDocumentManager())
587 OnActivateView(activate
, this, GetDocumentManager()->GetCurrentView());
588 GetDocumentManager()->ActivateView(this, activate
);
592 bool wxView::OnClose(bool WXUNUSED(deleteWindow
))
594 return GetDocument() ? GetDocument()->Close() : TRUE
;
597 #if wxUSE_PRINTING_ARCHITECTURE
598 wxPrintout
*wxView::OnCreatePrintout()
600 return new wxDocPrintout(this);
602 #endif // wxUSE_PRINTING_ARCHITECTURE
604 // ----------------------------------------------------------------------------
606 // ----------------------------------------------------------------------------
608 wxDocTemplate::wxDocTemplate(wxDocManager
*manager
,
609 const wxString
& descr
,
610 const wxString
& filter
,
613 const wxString
& docTypeName
,
614 const wxString
& viewTypeName
,
615 wxClassInfo
*docClassInfo
,
616 wxClassInfo
*viewClassInfo
,
619 m_documentManager
= manager
;
620 m_description
= descr
;
623 m_fileFilter
= filter
;
625 m_docTypeName
= docTypeName
;
626 m_viewTypeName
= viewTypeName
;
627 m_documentManager
->AssociateTemplate(this);
629 m_docClassInfo
= docClassInfo
;
630 m_viewClassInfo
= viewClassInfo
;
633 wxDocTemplate::~wxDocTemplate()
635 m_documentManager
->DisassociateTemplate(this);
638 // Tries to dynamically construct an object of the right class.
639 wxDocument
*wxDocTemplate::CreateDocument(const wxString
& path
, long flags
)
642 return (wxDocument
*) NULL
;
643 wxDocument
*doc
= (wxDocument
*)m_docClassInfo
->CreateObject();
644 doc
->SetFilename(path
);
645 doc
->SetDocumentTemplate(this);
646 GetDocumentManager()->AddDocument(doc
);
647 doc
->SetCommandProcessor(doc
->OnCreateCommandProcessor());
649 if (doc
->OnCreate(path
, flags
))
654 return (wxDocument
*) NULL
;
658 wxView
*wxDocTemplate::CreateView(wxDocument
*doc
, long flags
)
660 if (!m_viewClassInfo
)
661 return (wxView
*) NULL
;
662 wxView
*view
= (wxView
*)m_viewClassInfo
->CreateObject();
663 view
->SetDocument(doc
);
664 if (view
->OnCreate(doc
, flags
))
671 return (wxView
*) NULL
;
675 // The default (very primitive) format detection: check is the extension is
676 // that of the template
677 bool wxDocTemplate::FileMatchesTemplate(const wxString
& path
)
679 return GetDefaultExtension().IsSameAs(FindExtension(path
));
682 // ----------------------------------------------------------------------------
684 // ----------------------------------------------------------------------------
686 BEGIN_EVENT_TABLE(wxDocManager
, wxEvtHandler
)
687 EVT_MENU(wxID_OPEN
, wxDocManager::OnFileOpen
)
688 EVT_MENU(wxID_CLOSE
, wxDocManager::OnFileClose
)
689 EVT_MENU(wxID_REVERT
, wxDocManager::OnFileRevert
)
690 EVT_MENU(wxID_NEW
, wxDocManager::OnFileNew
)
691 EVT_MENU(wxID_SAVE
, wxDocManager::OnFileSave
)
692 EVT_MENU(wxID_SAVEAS
, wxDocManager::OnFileSaveAs
)
693 EVT_MENU(wxID_UNDO
, wxDocManager::OnUndo
)
694 EVT_MENU(wxID_REDO
, wxDocManager::OnRedo
)
695 #if wxUSE_PRINTING_ARCHITECTURE
696 EVT_MENU(wxID_PRINT
, wxDocManager::OnPrint
)
697 EVT_MENU(wxID_PRINT_SETUP
, wxDocManager::OnPrintSetup
)
698 EVT_MENU(wxID_PREVIEW
, wxDocManager::OnPreview
)
702 wxDocManager::wxDocManager(long flags
, bool initialize
)
704 m_defaultDocumentNameCounter
= 1;
706 m_currentView
= (wxView
*) NULL
;
707 m_maxDocsOpen
= 10000;
708 m_fileHistory
= (wxFileHistory
*) NULL
;
713 wxDocManager::~wxDocManager()
717 delete m_fileHistory
;
720 bool wxDocManager::Clear(bool force
)
722 wxNode
*node
= m_docs
.First();
725 wxDocument
*doc
= (wxDocument
*)node
->Data();
726 wxNode
*next
= node
->Next();
728 if (!doc
->Close() && !force
)
731 // Implicitly deletes the document when the last
732 // view is removed (deleted)
733 doc
->DeleteAllViews();
735 // Check document is deleted
736 if (m_docs
.Member(doc
))
739 // This assumes that documents are not connected in
740 // any way, i.e. deleting one document does NOT
744 node
= m_templates
.First();
747 wxDocTemplate
*templ
= (wxDocTemplate
*) node
->Data();
748 wxNode
* next
= node
->Next();
755 bool wxDocManager::Initialize()
757 m_fileHistory
= OnCreateFileHistory();
761 wxFileHistory
*wxDocManager::OnCreateFileHistory()
763 return new wxFileHistory
;
766 void wxDocManager::OnFileClose(wxCommandEvent
& WXUNUSED(event
))
768 wxDocument
*doc
= GetCurrentDocument();
773 doc
->DeleteAllViews();
774 if (m_docs
.Member(doc
))
779 void wxDocManager::OnFileNew(wxCommandEvent
& WXUNUSED(event
))
781 CreateDocument(wxString(""), wxDOC_NEW
);
784 void wxDocManager::OnFileOpen(wxCommandEvent
& WXUNUSED(event
))
786 CreateDocument(wxString(""), 0);
789 void wxDocManager::OnFileRevert(wxCommandEvent
& WXUNUSED(event
))
791 wxDocument
*doc
= GetCurrentDocument();
797 void wxDocManager::OnFileSave(wxCommandEvent
& WXUNUSED(event
))
799 wxDocument
*doc
= GetCurrentDocument();
805 void wxDocManager::OnFileSaveAs(wxCommandEvent
& WXUNUSED(event
))
807 wxDocument
*doc
= GetCurrentDocument();
813 void wxDocManager::OnPrint(wxCommandEvent
& WXUNUSED(event
))
815 #if wxUSE_PRINTING_ARCHITECTURE
816 wxView
*view
= GetCurrentView();
820 wxPrintout
*printout
= view
->OnCreatePrintout();
824 printer
.Print(view
->GetFrame(), printout
, TRUE
);
828 #endif // wxUSE_PRINTING_ARCHITECTURE
831 void wxDocManager::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
833 #if wxUSE_PRINTING_ARCHITECTURE
834 wxWindow
*parentWin
= wxTheApp
->GetTopWindow();
835 wxView
*view
= GetCurrentView();
837 parentWin
= view
->GetFrame();
839 wxPrintDialogData data
;
841 wxPrintDialog
printerDialog(parentWin
, &data
);
842 printerDialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
843 printerDialog
.ShowModal();
844 #endif // wxUSE_PRINTING_ARCHITECTURE
847 void wxDocManager::OnPreview(wxCommandEvent
& WXUNUSED(event
))
849 #if wxUSE_PRINTING_ARCHITECTURE
850 wxView
*view
= GetCurrentView();
854 wxPrintout
*printout
= view
->OnCreatePrintout();
857 // Pass two printout objects: for preview, and possible printing.
858 wxPrintPreviewBase
*preview
= (wxPrintPreviewBase
*) NULL
;
859 preview
= new wxPrintPreview(printout
, view
->OnCreatePrintout());
861 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, (wxFrame
*)wxTheApp
->GetTopWindow(), _("Print Preview"),
862 wxPoint(100, 100), wxSize(600, 650));
863 frame
->Centre(wxBOTH
);
867 #endif // wxUSE_PRINTING_ARCHITECTURE
870 void wxDocManager::OnUndo(wxCommandEvent
& WXUNUSED(event
))
872 wxDocument
*doc
= GetCurrentDocument();
875 if (doc
->GetCommandProcessor())
876 doc
->GetCommandProcessor()->Undo();
879 void wxDocManager::OnRedo(wxCommandEvent
& WXUNUSED(event
))
881 wxDocument
*doc
= GetCurrentDocument();
884 if (doc
->GetCommandProcessor())
885 doc
->GetCommandProcessor()->Redo();
888 wxView
*wxDocManager::GetCurrentView() const
891 return m_currentView
;
892 if (m_docs
.Number() == 1)
894 wxDocument
* doc
= (wxDocument
*) m_docs
.First()->Data();
895 return doc
->GetFirstView();
897 return (wxView
*) NULL
;
900 // Extend event processing to search the view's event table
901 bool wxDocManager::ProcessEvent(wxEvent
& event
)
903 wxView
* view
= GetCurrentView();
906 if (view
->ProcessEvent(event
))
909 return wxEvtHandler::ProcessEvent(event
);
912 wxDocument
*wxDocManager::CreateDocument(const wxString
& path
, long flags
)
914 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
917 for (i
= 0; i
< m_templates
.Number(); i
++)
919 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
920 if (temp
->IsVisible())
929 return (wxDocument
*) NULL
;
932 // If we've reached the max number of docs, close the
934 if (GetDocuments().Number() >= m_maxDocsOpen
)
936 wxDocument
*doc
= (wxDocument
*)GetDocuments().First()->Data();
939 // Implicitly deletes the document when
940 // the last view is deleted
941 doc
->DeleteAllViews();
943 // Check we're really deleted
944 if (m_docs
.Member(doc
))
948 return (wxDocument
*) NULL
;
951 // New document: user chooses a template, unless there's only one.
952 if (flags
& wxDOC_NEW
)
956 wxDocTemplate
*temp
= templates
[0];
958 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
961 newDoc
->SetDocumentName(temp
->GetDocumentName());
962 newDoc
->SetDocumentTemplate(temp
);
963 newDoc
->OnNewDocument();
968 wxDocTemplate
*temp
= SelectDocumentType(templates
, n
);
972 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
975 newDoc
->SetDocumentName(temp
->GetDocumentName());
976 newDoc
->SetDocumentTemplate(temp
);
977 newDoc
->OnNewDocument();
982 return (wxDocument
*) NULL
;
986 wxDocTemplate
*temp
= (wxDocTemplate
*) NULL
;
988 wxString
path2(T(""));
992 if (flags
& wxDOC_SILENT
)
993 temp
= FindTemplateForPath(path2
);
995 temp
= SelectDocumentPath(templates
, n
, path2
, flags
);
1001 wxDocument
*newDoc
= temp
->CreateDocument(path2
, flags
);
1004 newDoc
->SetDocumentName(temp
->GetDocumentName());
1005 newDoc
->SetDocumentTemplate(temp
);
1006 if (!newDoc
->OnOpenDocument(path2
))
1009 return (wxDocument
*) NULL
;
1011 AddFileToHistory(path2
);
1016 return (wxDocument
*) NULL
;
1019 wxView
*wxDocManager::CreateView(wxDocument
*doc
, long flags
)
1021 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
1024 for (i
= 0; i
< m_templates
.Number(); i
++)
1026 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
1027 if (temp
->IsVisible())
1029 if (temp
->GetDocumentName() == doc
->GetDocumentName())
1031 templates
[n
] = temp
;
1039 return (wxView
*) NULL
;
1043 wxDocTemplate
*temp
= templates
[0];
1045 wxView
*view
= temp
->CreateView(doc
, flags
);
1047 view
->SetViewName(temp
->GetViewName());
1051 wxDocTemplate
*temp
= SelectViewType(templates
, n
);
1055 wxView
*view
= temp
->CreateView(doc
, flags
);
1057 view
->SetViewName(temp
->GetViewName());
1061 return (wxView
*) NULL
;
1064 // Not yet implemented
1065 void wxDocManager::DeleteTemplate(wxDocTemplate
*WXUNUSED(temp
), long WXUNUSED(flags
))
1069 // Not yet implemented
1070 bool wxDocManager::FlushDoc(wxDocument
*WXUNUSED(doc
))
1075 wxDocument
*wxDocManager::GetCurrentDocument() const
1078 return m_currentView
->GetDocument();
1080 return (wxDocument
*) NULL
;
1083 // Make a default document name
1084 bool wxDocManager::MakeDefaultName(wxString
& name
)
1086 name
.Printf(_("unnamed%d"), m_defaultDocumentNameCounter
);
1087 m_defaultDocumentNameCounter
++;
1092 // Not yet implemented
1093 wxDocTemplate
*wxDocManager::MatchTemplate(const wxString
& WXUNUSED(path
))
1095 return (wxDocTemplate
*) NULL
;
1098 // File history management
1099 void wxDocManager::AddFileToHistory(const wxString
& file
)
1102 m_fileHistory
->AddFileToHistory(file
);
1105 void wxDocManager::RemoveFileFromHistory(int i
)
1108 m_fileHistory
->RemoveFileFromHistory(i
);
1111 wxString
wxDocManager::GetHistoryFile(int i
) const
1116 histFile
= m_fileHistory
->GetHistoryFile(i
);
1121 void wxDocManager::FileHistoryUseMenu(wxMenu
*menu
)
1124 m_fileHistory
->UseMenu(menu
);
1127 void wxDocManager::FileHistoryRemoveMenu(wxMenu
*menu
)
1130 m_fileHistory
->RemoveMenu(menu
);
1134 void wxDocManager::FileHistoryLoad(wxConfigBase
& config
)
1137 m_fileHistory
->Load(config
);
1140 void wxDocManager::FileHistorySave(wxConfigBase
& config
)
1143 m_fileHistory
->Save(config
);
1147 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu
* menu
)
1150 m_fileHistory
->AddFilesToMenu(menu
);
1153 void wxDocManager::FileHistoryAddFilesToMenu()
1156 m_fileHistory
->AddFilesToMenu();
1159 int wxDocManager::GetNoHistoryFiles() const
1162 return m_fileHistory
->GetNoHistoryFiles();
1168 // Find out the document template via matching in the document file format
1169 // against that of the template
1170 wxDocTemplate
*wxDocManager::FindTemplateForPath(const wxString
& path
)
1172 wxDocTemplate
*theTemplate
= (wxDocTemplate
*) NULL
;
1174 // Find the template which this extension corresponds to
1176 for (i
= 0; i
< m_templates
.Number(); i
++)
1178 wxDocTemplate
*temp
= (wxDocTemplate
*)m_templates
.Nth(i
)->Data();
1179 if ( temp
->FileMatchesTemplate(path
) )
1188 // Prompts user to open a file, using file specs in templates.
1189 // How to implement in wxWindows? Must extend the file selector
1190 // dialog or implement own; OR match the extension to the
1191 // template extension.
1193 wxDocTemplate
*wxDocManager::SelectDocumentPath(wxDocTemplate
**templates
,
1197 int WXUNUSED(noTemplates
),
1200 long WXUNUSED(flags
),
1201 bool WXUNUSED(save
))
1203 // We can only have multiple filters in Windows
1208 for (i
= 0; i
< noTemplates
; i
++)
1210 if (templates
[i
]->IsVisible())
1212 // add a '|' to separate this filter from the previous one
1213 if ( !descrBuf
.IsEmpty() )
1216 descrBuf
<< templates
[i
]->GetDescription()
1217 << T(" (") << templates
[i
]->GetFileFilter() << T(") |")
1218 << templates
[i
]->GetFileFilter();
1222 wxString descrBuf
= T("*.*");
1225 int FilterIndex
= 0;
1226 wxString pathTmp
= wxFileSelectorEx(_("Select a file"),
1232 wxTheApp
->GetTopWindow());
1234 if (!pathTmp
.IsEmpty())
1237 wxString theExt
= FindExtension(path
);
1239 return (wxDocTemplate
*) NULL
;
1241 // This is dodgy in that we're selecting the template on the
1242 // basis of the file extension, which may not be a standard
1243 // one. We really want to know exactly which template was
1244 // chosen by using a more advanced file selector.
1245 wxDocTemplate
*theTemplate
= FindTemplateForPath(path
);
1247 theTemplate
= templates
[FilterIndex
];
1254 return (wxDocTemplate
*) NULL
;
1257 // In all other windowing systems, until we have more advanced
1258 // file selectors, we must select the document type (template) first, and
1259 // _then_ pop up the file selector.
1260 wxDocTemplate
*temp
= SelectDocumentType(templates
, noTemplates
);
1262 return (wxDocTemplate
*) NULL
;
1264 wxChar
*pathTmp
= wxFileSelector(_("Select a file"), T(""), T(""),
1265 temp
->GetDefaultExtension(),
1266 temp
->GetFileFilter(),
1267 0, wxTheApp
->GetTopWindow());
1275 return (wxDocTemplate
*) NULL
;
1279 wxDocTemplate
*wxDocManager::SelectDocumentType(wxDocTemplate
**templates
,
1282 wxChar
**strings
= new wxChar
*[noTemplates
];
1283 wxChar
**data
= new wxChar
*[noTemplates
];
1286 for (i
= 0; i
< noTemplates
; i
++)
1288 if (templates
[i
]->IsVisible())
1290 strings
[n
] = (wxChar
*)templates
[i
]->m_description
.c_str();
1291 data
[n
] = (wxChar
*)templates
[i
];
1299 return (wxDocTemplate
*) NULL
;
1303 wxDocTemplate
*temp
= (wxDocTemplate
*)data
[0];
1309 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n
,
1310 strings
, (char **)data
);
1316 wxDocTemplate
*wxDocManager::SelectViewType(wxDocTemplate
**templates
,
1319 wxChar
**strings
= new wxChar
*[noTemplates
];
1320 wxChar
**data
= new wxChar
*[noTemplates
];
1323 for (i
= 0; i
< noTemplates
; i
++)
1325 if (templates
[i
]->IsVisible() && (templates
[i
]->GetViewName() != T("")))
1327 strings
[n
] = (wxChar
*)templates
[i
]->m_viewTypeName
.c_str();
1328 data
[n
] = (wxChar
*)templates
[i
];
1332 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n
,
1333 strings
, (char **)data
);
1339 void wxDocManager::AssociateTemplate(wxDocTemplate
*temp
)
1341 if (!m_templates
.Member(temp
))
1342 m_templates
.Append(temp
);
1345 void wxDocManager::DisassociateTemplate(wxDocTemplate
*temp
)
1347 m_templates
.DeleteObject(temp
);
1350 // Add and remove a document from the manager's list
1351 void wxDocManager::AddDocument(wxDocument
*doc
)
1353 if (!m_docs
.Member(doc
))
1357 void wxDocManager::RemoveDocument(wxDocument
*doc
)
1359 m_docs
.DeleteObject(doc
);
1362 // Views or windows should inform the document manager
1363 // when a view is going in or out of focus
1364 void wxDocManager::ActivateView(wxView
*view
, bool activate
, bool WXUNUSED(deleting
))
1366 // If we're deactiving, and if we're not actually deleting the view, then
1367 // don't reset the current view because we may be going to
1368 // a window without a view.
1369 // WHAT DID I MEAN BY THAT EXACTLY?
1373 if (m_currentView == view)
1374 m_currentView = NULL;
1380 m_currentView
= view
;
1382 m_currentView
= (wxView
*) NULL
;
1386 // ----------------------------------------------------------------------------
1387 // Default document child frame
1388 // ----------------------------------------------------------------------------
1390 BEGIN_EVENT_TABLE(wxDocChildFrame
, wxFrame
)
1391 EVT_ACTIVATE(wxDocChildFrame::OnActivate
)
1392 EVT_CLOSE(wxDocChildFrame::OnCloseWindow
)
1395 wxDocChildFrame::wxDocChildFrame(wxDocument
*doc
,
1399 const wxString
& title
,
1403 const wxString
& name
)
1404 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1406 m_childDocument
= doc
;
1409 view
->SetFrame(this);
1412 wxDocChildFrame::~wxDocChildFrame()
1416 // Extend event processing to search the view's event table
1417 bool wxDocChildFrame::ProcessEvent(wxEvent
& event
)
1420 m_childView
->Activate(TRUE
);
1422 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
1424 // Only hand up to the parent if it's a menu command
1425 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
1426 return wxEvtHandler::ProcessEvent(event
);
1434 void wxDocChildFrame::OnActivate(wxActivateEvent
& event
)
1436 wxFrame::OnActivate(event
);
1439 m_childView
->Activate(event
.GetActive());
1442 void wxDocChildFrame::OnCloseWindow(wxCloseEvent
& event
)
1447 if (!event
.CanVeto())
1448 ans
= TRUE
; // Must delete.
1450 ans
= m_childView
->Close(FALSE
); // FALSE means don't delete associated window
1454 m_childView
->Activate(FALSE
);
1456 m_childView
= (wxView
*) NULL
;
1457 m_childDocument
= (wxDocument
*) NULL
;
1468 // ----------------------------------------------------------------------------
1469 // Default parent frame
1470 // ----------------------------------------------------------------------------
1472 BEGIN_EVENT_TABLE(wxDocParentFrame
, wxFrame
)
1473 EVT_MENU(wxID_EXIT
, wxDocParentFrame::OnExit
)
1474 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocParentFrame::OnMRUFile
)
1475 EVT_CLOSE(wxDocParentFrame::OnCloseWindow
)
1478 wxDocParentFrame::wxDocParentFrame(wxDocManager
*manager
,
1481 const wxString
& title
,
1485 const wxString
& name
)
1486 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1488 m_docManager
= manager
;
1491 void wxDocParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
1496 void wxDocParentFrame::OnMRUFile(wxCommandEvent
& event
)
1498 int n
= event
.GetSelection() - wxID_FILE1
; // the index in MRU list
1499 wxString
filename(m_docManager
->GetHistoryFile(n
));
1500 if ( !filename
.IsEmpty() )
1502 // verify that the file exists before doing anything else
1503 if ( wxFile::Exists(filename
) )
1506 (void)m_docManager
->CreateDocument(filename
, wxDOC_SILENT
);
1510 // remove the bogus filename from the MRU list and notify the user
1512 m_docManager
->RemoveFileFromHistory(n
);
1514 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\n"
1515 "It has been also removed from the MRU files list."),
1521 // Extend event processing to search the view's event table
1522 bool wxDocParentFrame::ProcessEvent(wxEvent
& event
)
1524 // Try the document manager, then do default processing
1525 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
1526 return wxEvtHandler::ProcessEvent(event
);
1531 // Define the behaviour for the frame closing
1532 // - must delete all frames except for the main one.
1533 void wxDocParentFrame::OnCloseWindow(wxCloseEvent
& event
)
1535 if (m_docManager
->Clear(!event
.CanVeto()))
1543 #if wxUSE_PRINTING_ARCHITECTURE
1545 wxDocPrintout::wxDocPrintout(wxView
*view
, const wxString
& title
)
1548 m_printoutView
= view
;
1551 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page
))
1555 // Get the logical pixels per inch of screen and printer
1556 int ppiScreenX
, ppiScreenY
;
1557 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
1558 int ppiPrinterX
, ppiPrinterY
;
1559 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
1561 // This scales the DC so that the printout roughly represents the
1562 // the screen scaling. The text point size _should_ be the right size
1563 // but in fact is too small for some reason. This is a detail that will
1564 // need to be addressed at some point but can be fudged for the
1566 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
1568 // Now we have to check in case our real page size is reduced
1569 // (e.g. because we're drawing to a print preview memory DC)
1570 int pageWidth
, pageHeight
;
1572 dc
->GetSize(&w
, &h
);
1573 GetPageSizePixels(&pageWidth
, &pageHeight
);
1575 // If printer pageWidth == current DC width, then this doesn't
1576 // change. But w might be the preview bitmap width, so scale down.
1577 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
1578 dc
->SetUserScale(overallScale
, overallScale
);
1582 m_printoutView
->OnDraw(dc
);
1587 bool wxDocPrintout::HasPage(int pageNum
)
1589 return (pageNum
== 1);
1592 bool wxDocPrintout::OnBeginDocument(int startPage
, int endPage
)
1594 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
1600 void wxDocPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
1608 #endif // wxUSE_PRINTING_ARCHITECTURE
1610 // ----------------------------------------------------------------------------
1611 // Command processing framework
1612 // ----------------------------------------------------------------------------
1614 wxCommand::wxCommand(bool canUndoIt
, const wxString
& name
)
1616 m_canUndo
= canUndoIt
;
1617 m_commandName
= name
;
1620 wxCommand::~wxCommand()
1624 // Command processor
1625 wxCommandProcessor::wxCommandProcessor(int maxCommands
)
1627 m_maxNoCommands
= maxCommands
;
1628 m_currentCommand
= (wxNode
*) NULL
;
1629 m_commandEditMenu
= (wxMenu
*) NULL
;
1632 wxCommandProcessor::~wxCommandProcessor()
1637 // Pass a command to the processor. The processor calls Do();
1638 // if successful, is appended to the command history unless
1639 // storeIt is FALSE.
1640 bool wxCommandProcessor::Submit(wxCommand
*command
, bool storeIt
)
1642 bool success
= command
->Do();
1643 if (success
&& storeIt
)
1645 if (m_commands
.Number() == m_maxNoCommands
)
1647 wxNode
*firstNode
= m_commands
.First();
1648 wxCommand
*firstCommand
= (wxCommand
*)firstNode
->Data();
1649 delete firstCommand
;
1653 // Correct a bug: we must chop off the current 'branch'
1654 // so that we're at the end of the command list.
1655 if (!m_currentCommand
)
1659 wxNode
*node
= m_currentCommand
->Next();
1662 wxNode
*next
= node
->Next();
1663 delete (wxCommand
*)node
->Data();
1669 m_commands
.Append(command
);
1670 m_currentCommand
= m_commands
.Last();
1676 bool wxCommandProcessor::Undo()
1678 if (m_currentCommand
)
1680 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1681 if (command
->CanUndo())
1683 bool success
= command
->Undo();
1686 m_currentCommand
= m_currentCommand
->Previous();
1695 bool wxCommandProcessor::Redo()
1697 wxCommand
*redoCommand
= (wxCommand
*) NULL
;
1698 wxNode
*redoNode
= (wxNode
*) NULL
;
1699 if (m_currentCommand
&& m_currentCommand
->Next())
1701 redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1702 redoNode
= m_currentCommand
->Next();
1706 if (m_commands
.Number() > 0)
1708 redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1709 redoNode
= m_commands
.First();
1715 bool success
= redoCommand
->Do();
1718 m_currentCommand
= redoNode
;
1726 bool wxCommandProcessor::CanUndo() const
1728 if (m_currentCommand
)
1729 return ((wxCommand
*)m_currentCommand
->Data())->CanUndo();
1733 bool wxCommandProcessor::CanRedo() const
1735 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() == (wxNode
*) NULL
))
1738 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() != (wxNode
*) NULL
))
1741 if ((m_currentCommand
== (wxNode
*) NULL
) && (m_commands
.Number() > 0))
1747 void wxCommandProcessor::Initialize()
1749 m_currentCommand
= m_commands
.Last();
1753 void wxCommandProcessor::SetMenuStrings()
1755 if (m_commandEditMenu
)
1758 if (m_currentCommand
)
1760 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1761 wxString
commandName(command
->GetName());
1762 if (commandName
== T("")) commandName
= _("Unnamed command");
1763 bool canUndo
= command
->CanUndo();
1765 buf
= wxString(_("&Undo ")) + commandName
;
1767 buf
= wxString(_("Can't &Undo ")) + commandName
;
1769 m_commandEditMenu
->SetLabel(wxID_UNDO
, buf
);
1770 m_commandEditMenu
->Enable(wxID_UNDO
, canUndo
);
1772 // We can redo, if we're not at the end of the history.
1773 if (m_currentCommand
->Next())
1775 wxCommand
*redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1776 wxString
redoCommandName(redoCommand
->GetName());
1777 if (redoCommandName
== T("")) redoCommandName
= _("Unnamed command");
1778 buf
= wxString(_("&Redo ")) + redoCommandName
;
1779 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1780 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1784 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1785 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1790 m_commandEditMenu
->SetLabel(wxID_UNDO
, _("&Undo"));
1791 m_commandEditMenu
->Enable(wxID_UNDO
, FALSE
);
1793 if (m_commands
.Number() == 0)
1795 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1796 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1800 // currentCommand is NULL but there are commands: this means that
1801 // we've undone to the start of the list, but can redo the first.
1802 wxCommand
*redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1803 wxString
redoCommandName(redoCommand
->GetName());
1804 if (redoCommandName
== T("")) redoCommandName
= _("Unnamed command");
1805 buf
= wxString(_("&Redo ")) + redoCommandName
;
1806 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1807 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1813 void wxCommandProcessor::ClearCommands()
1815 wxNode
*node
= m_commands
.First();
1818 wxCommand
*command
= (wxCommand
*)node
->Data();
1821 node
= m_commands
.First();
1823 m_currentCommand
= (wxNode
*) NULL
;
1826 // ----------------------------------------------------------------------------
1827 // File history processor
1828 // ----------------------------------------------------------------------------
1830 wxFileHistory::wxFileHistory(int maxFiles
)
1832 m_fileMaxFiles
= maxFiles
;
1834 m_fileHistory
= new wxChar
*[m_fileMaxFiles
];
1837 wxFileHistory::~wxFileHistory()
1840 for (i
= 0; i
< m_fileHistoryN
; i
++)
1841 delete[] m_fileHistory
[i
];
1842 delete[] m_fileHistory
;
1845 // File history management
1846 void wxFileHistory::AddFileToHistory(const wxString
& file
)
1849 // Check we don't already have this file
1850 for (i
= 0; i
< m_fileHistoryN
; i
++)
1852 if (m_fileHistory
[i
] && wxString(m_fileHistory
[i
]) == file
)
1856 // Add to the project file history:
1857 // Move existing files (if any) down so we can insert file at beginning.
1859 // First delete filename that has popped off the end of the array (if any)
1860 if (m_fileHistoryN
== m_fileMaxFiles
)
1862 delete[] m_fileHistory
[m_fileMaxFiles
-1];
1863 m_fileHistory
[m_fileMaxFiles
-1] = (wxChar
*) NULL
;
1865 if (m_fileHistoryN
< m_fileMaxFiles
)
1867 wxNode
* node
= m_fileMenus
.First();
1870 wxMenu
* menu
= (wxMenu
*) node
->Data();
1871 if (m_fileHistoryN
== 0)
1872 menu
->AppendSeparator();
1873 menu
->Append(wxID_FILE1
+m_fileHistoryN
, _("[EMPTY]"));
1874 node
= node
->Next();
1878 // Shuffle filenames down
1879 for (i
= (m_fileHistoryN
-1); i
> 0; i
--)
1881 m_fileHistory
[i
] = m_fileHistory
[i
-1];
1883 m_fileHistory
[0] = copystring(file
);
1885 for (i
= 0; i
< m_fileHistoryN
; i
++)
1886 if (m_fileHistory
[i
])
1889 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
1890 wxNode
* node
= m_fileMenus
.First();
1893 wxMenu
* menu
= (wxMenu
*) node
->Data();
1894 menu
->SetLabel(wxID_FILE1
+i
, buf
);
1895 node
= node
->Next();
1900 void wxFileHistory::RemoveFileFromHistory(int i
)
1902 wxCHECK_RET( i
< m_fileHistoryN
,
1903 T("invalid index in wxFileHistory::RemoveFileFromHistory") );
1905 wxNode
* node
= m_fileMenus
.First();
1908 wxMenu
* menu
= (wxMenu
*) node
->Data();
1910 // wxMenu::Delete() is missing from wxGTK, so this can't be done :-(
1912 // delete the menu items
1913 menu
->Delete(wxID_FILE1
+ i
);
1916 // delete the element from the array (could use memmove() too...)
1917 delete [] m_fileHistory
[i
];
1920 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1922 m_fileHistory
[j
] = m_fileHistory
[j
+ 1];
1925 // shuffle filenames up
1927 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1929 buf
.Printf(s_MRUEntryFormat
, j
+ 1, m_fileHistory
[j
]);
1930 menu
->SetLabel(wxID_FILE1
+ j
, buf
);
1933 // to be removed as soon as wxMenu::Delete() is implemented
1935 menu
->SetLabel(wxID_FILE1
+ m_fileHistoryN
- 1, T(""));
1938 node
= node
->Next();
1943 wxString
wxFileHistory::GetHistoryFile(int i
) const
1945 if (i
< m_fileHistoryN
)
1946 return wxString(m_fileHistory
[i
]);
1948 return wxString("");
1951 void wxFileHistory::UseMenu(wxMenu
*menu
)
1953 if (!m_fileMenus
.Member(menu
))
1954 m_fileMenus
.Append(menu
);
1957 void wxFileHistory::RemoveMenu(wxMenu
*menu
)
1959 m_fileMenus
.DeleteObject(menu
);
1963 void wxFileHistory::Load(wxConfigBase
& config
)
1967 buf
.Printf(T("file%d"), m_fileHistoryN
+1);
1968 wxString historyFile
;
1969 while ((m_fileHistoryN
<= m_fileMaxFiles
) && config
.Read(buf
, &historyFile
) && (historyFile
!= T("")))
1971 m_fileHistory
[m_fileHistoryN
] = copystring((const wxChar
*) historyFile
);
1973 buf
.Printf(T("file%d"), m_fileHistoryN
+1);
1979 void wxFileHistory::Save(wxConfigBase
& config
)
1982 for (i
= 0; i
< m_fileHistoryN
; i
++)
1985 buf
.Printf(T("file%d"), i
+1);
1986 config
.Write(buf
, wxString(m_fileHistory
[i
]));
1989 #endif // wxUSE_CONFIG
1991 void wxFileHistory::AddFilesToMenu()
1993 if (m_fileHistoryN
> 0)
1995 wxNode
* node
= m_fileMenus
.First();
1998 wxMenu
* menu
= (wxMenu
*) node
->Data();
1999 menu
->AppendSeparator();
2001 for (i
= 0; i
< m_fileHistoryN
; i
++)
2003 if (m_fileHistory
[i
])
2006 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2007 menu
->Append(wxID_FILE1
+i
, buf
);
2010 node
= node
->Next();
2015 void wxFileHistory::AddFilesToMenu(wxMenu
* menu
)
2017 if (m_fileHistoryN
> 0)
2019 menu
->AppendSeparator();
2021 for (i
= 0; i
< m_fileHistoryN
; i
++)
2023 if (m_fileHistory
[i
])
2026 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2027 menu
->Append(wxID_FILE1
+i
, buf
);
2033 // ----------------------------------------------------------------------------
2034 // Permits compatibility with existing file formats and functions that
2035 // manipulate files directly
2036 // ----------------------------------------------------------------------------
2038 #if wxUSE_STD_IOSTREAM
2039 bool wxTransferFileToStream(const wxString
& filename
, ostream
& stream
)
2044 if ((fd1
= fopen (filename
.fn_str(), "rb")) == NULL
)
2047 while ((ch
= getc (fd1
)) != EOF
)
2048 stream
<< (unsigned char)ch
;
2054 bool wxTransferStreamToFile(istream
& stream
, const wxString
& filename
)
2059 if ((fd1
= fopen (filename
.fn_str(), "wb")) == NULL
)
2064 while (!stream
.eof())
2075 #endif // wxUSE_DOC_VIEW_ARCHITECTURE