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
= 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() != 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() != 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() != 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
!= wxT(""))
383 buf
= m_documentTitle
;
386 else if (m_documentFile
!= wxT(""))
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() != wxT(""))
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
;
709 m_lastDirectory
= wxT("") ;
714 wxDocManager::~wxDocManager()
718 delete m_fileHistory
;
721 bool wxDocManager::Clear(bool force
)
723 wxNode
*node
= m_docs
.First();
726 wxDocument
*doc
= (wxDocument
*)node
->Data();
727 wxNode
*next
= node
->Next();
729 if (!doc
->Close() && !force
)
732 // Implicitly deletes the document when the last
733 // view is removed (deleted)
734 doc
->DeleteAllViews();
736 // Check document is deleted
737 if (m_docs
.Member(doc
))
740 // This assumes that documents are not connected in
741 // any way, i.e. deleting one document does NOT
745 node
= m_templates
.First();
748 wxDocTemplate
*templ
= (wxDocTemplate
*) node
->Data();
749 wxNode
* next
= node
->Next();
756 bool wxDocManager::Initialize()
758 m_fileHistory
= OnCreateFileHistory();
762 wxFileHistory
*wxDocManager::OnCreateFileHistory()
764 return new wxFileHistory
;
767 void wxDocManager::OnFileClose(wxCommandEvent
& WXUNUSED(event
))
769 wxDocument
*doc
= GetCurrentDocument();
774 doc
->DeleteAllViews();
775 if (m_docs
.Member(doc
))
780 void wxDocManager::OnFileNew(wxCommandEvent
& WXUNUSED(event
))
782 CreateDocument(wxString(""), wxDOC_NEW
);
785 void wxDocManager::OnFileOpen(wxCommandEvent
& WXUNUSED(event
))
787 CreateDocument(wxString(""), 0);
790 void wxDocManager::OnFileRevert(wxCommandEvent
& WXUNUSED(event
))
792 wxDocument
*doc
= GetCurrentDocument();
798 void wxDocManager::OnFileSave(wxCommandEvent
& WXUNUSED(event
))
800 wxDocument
*doc
= GetCurrentDocument();
806 void wxDocManager::OnFileSaveAs(wxCommandEvent
& WXUNUSED(event
))
808 wxDocument
*doc
= GetCurrentDocument();
814 void wxDocManager::OnPrint(wxCommandEvent
& WXUNUSED(event
))
816 #if wxUSE_PRINTING_ARCHITECTURE
817 wxView
*view
= GetCurrentView();
821 wxPrintout
*printout
= view
->OnCreatePrintout();
825 printer
.Print(view
->GetFrame(), printout
, TRUE
);
829 #endif // wxUSE_PRINTING_ARCHITECTURE
832 void wxDocManager::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
834 #if wxUSE_PRINTING_ARCHITECTURE
835 wxWindow
*parentWin
= wxTheApp
->GetTopWindow();
836 wxView
*view
= GetCurrentView();
838 parentWin
= view
->GetFrame();
840 wxPrintDialogData data
;
842 wxPrintDialog
printerDialog(parentWin
, &data
);
843 printerDialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
844 printerDialog
.ShowModal();
845 #endif // wxUSE_PRINTING_ARCHITECTURE
848 void wxDocManager::OnPreview(wxCommandEvent
& WXUNUSED(event
))
850 #if wxUSE_PRINTING_ARCHITECTURE
851 wxView
*view
= GetCurrentView();
855 wxPrintout
*printout
= view
->OnCreatePrintout();
858 // Pass two printout objects: for preview, and possible printing.
859 wxPrintPreviewBase
*preview
= (wxPrintPreviewBase
*) NULL
;
860 preview
= new wxPrintPreview(printout
, view
->OnCreatePrintout());
862 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, (wxFrame
*)wxTheApp
->GetTopWindow(), _("Print Preview"),
863 wxPoint(100, 100), wxSize(600, 650));
864 frame
->Centre(wxBOTH
);
868 #endif // wxUSE_PRINTING_ARCHITECTURE
871 void wxDocManager::OnUndo(wxCommandEvent
& WXUNUSED(event
))
873 wxDocument
*doc
= GetCurrentDocument();
876 if (doc
->GetCommandProcessor())
877 doc
->GetCommandProcessor()->Undo();
880 void wxDocManager::OnRedo(wxCommandEvent
& WXUNUSED(event
))
882 wxDocument
*doc
= GetCurrentDocument();
885 if (doc
->GetCommandProcessor())
886 doc
->GetCommandProcessor()->Redo();
889 wxView
*wxDocManager::GetCurrentView() const
892 return m_currentView
;
893 if (m_docs
.Number() == 1)
895 wxDocument
* doc
= (wxDocument
*) m_docs
.First()->Data();
896 return doc
->GetFirstView();
898 return (wxView
*) NULL
;
901 // Extend event processing to search the view's event table
902 bool wxDocManager::ProcessEvent(wxEvent
& event
)
904 wxView
* view
= GetCurrentView();
907 if (view
->ProcessEvent(event
))
910 return wxEvtHandler::ProcessEvent(event
);
913 wxDocument
*wxDocManager::CreateDocument(const wxString
& path
, long flags
)
915 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
918 for (i
= 0; i
< m_templates
.Number(); i
++)
920 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
921 if (temp
->IsVisible())
930 return (wxDocument
*) NULL
;
933 // If we've reached the max number of docs, close the
935 if (GetDocuments().Number() >= m_maxDocsOpen
)
937 wxDocument
*doc
= (wxDocument
*)GetDocuments().First()->Data();
940 // Implicitly deletes the document when
941 // the last view is deleted
942 doc
->DeleteAllViews();
944 // Check we're really deleted
945 if (m_docs
.Member(doc
))
949 return (wxDocument
*) NULL
;
952 // New document: user chooses a template, unless there's only one.
953 if (flags
& wxDOC_NEW
)
957 wxDocTemplate
*temp
= templates
[0];
959 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
962 newDoc
->SetDocumentName(temp
->GetDocumentName());
963 newDoc
->SetDocumentTemplate(temp
);
964 newDoc
->OnNewDocument();
969 wxDocTemplate
*temp
= SelectDocumentType(templates
, n
);
973 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
976 newDoc
->SetDocumentName(temp
->GetDocumentName());
977 newDoc
->SetDocumentTemplate(temp
);
978 newDoc
->OnNewDocument();
983 return (wxDocument
*) NULL
;
987 wxDocTemplate
*temp
= (wxDocTemplate
*) NULL
;
989 wxString
path2(wxT(""));
993 if (flags
& wxDOC_SILENT
)
994 temp
= FindTemplateForPath(path2
);
996 temp
= SelectDocumentPath(templates
, n
, path2
, flags
);
1002 wxDocument
*newDoc
= temp
->CreateDocument(path2
, flags
);
1005 newDoc
->SetDocumentName(temp
->GetDocumentName());
1006 newDoc
->SetDocumentTemplate(temp
);
1007 if (!newDoc
->OnOpenDocument(path2
))
1010 return (wxDocument
*) NULL
;
1012 AddFileToHistory(path2
);
1017 return (wxDocument
*) NULL
;
1020 wxView
*wxDocManager::CreateView(wxDocument
*doc
, long flags
)
1022 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
1025 for (i
= 0; i
< m_templates
.Number(); i
++)
1027 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
1028 if (temp
->IsVisible())
1030 if (temp
->GetDocumentName() == doc
->GetDocumentName())
1032 templates
[n
] = temp
;
1040 return (wxView
*) NULL
;
1044 wxDocTemplate
*temp
= templates
[0];
1046 wxView
*view
= temp
->CreateView(doc
, flags
);
1048 view
->SetViewName(temp
->GetViewName());
1052 wxDocTemplate
*temp
= SelectViewType(templates
, n
);
1056 wxView
*view
= temp
->CreateView(doc
, flags
);
1058 view
->SetViewName(temp
->GetViewName());
1062 return (wxView
*) NULL
;
1065 // Not yet implemented
1066 void wxDocManager::DeleteTemplate(wxDocTemplate
*WXUNUSED(temp
), long WXUNUSED(flags
))
1070 // Not yet implemented
1071 bool wxDocManager::FlushDoc(wxDocument
*WXUNUSED(doc
))
1076 wxDocument
*wxDocManager::GetCurrentDocument() const
1079 return m_currentView
->GetDocument();
1081 return (wxDocument
*) NULL
;
1084 // Make a default document name
1085 bool wxDocManager::MakeDefaultName(wxString
& name
)
1087 name
.Printf(_("unnamed%d"), m_defaultDocumentNameCounter
);
1088 m_defaultDocumentNameCounter
++;
1093 // Not yet implemented
1094 wxDocTemplate
*wxDocManager::MatchTemplate(const wxString
& WXUNUSED(path
))
1096 return (wxDocTemplate
*) NULL
;
1099 // File history management
1100 void wxDocManager::AddFileToHistory(const wxString
& file
)
1103 m_fileHistory
->AddFileToHistory(file
);
1106 void wxDocManager::RemoveFileFromHistory(int i
)
1109 m_fileHistory
->RemoveFileFromHistory(i
);
1112 wxString
wxDocManager::GetHistoryFile(int i
) const
1117 histFile
= m_fileHistory
->GetHistoryFile(i
);
1122 void wxDocManager::FileHistoryUseMenu(wxMenu
*menu
)
1125 m_fileHistory
->UseMenu(menu
);
1128 void wxDocManager::FileHistoryRemoveMenu(wxMenu
*menu
)
1131 m_fileHistory
->RemoveMenu(menu
);
1135 void wxDocManager::FileHistoryLoad(wxConfigBase
& config
)
1138 m_fileHistory
->Load(config
);
1141 void wxDocManager::FileHistorySave(wxConfigBase
& config
)
1144 m_fileHistory
->Save(config
);
1148 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu
* menu
)
1151 m_fileHistory
->AddFilesToMenu(menu
);
1154 void wxDocManager::FileHistoryAddFilesToMenu()
1157 m_fileHistory
->AddFilesToMenu();
1160 int wxDocManager::GetNoHistoryFiles() const
1163 return m_fileHistory
->GetNoHistoryFiles();
1169 // Find out the document template via matching in the document file format
1170 // against that of the template
1171 wxDocTemplate
*wxDocManager::FindTemplateForPath(const wxString
& path
)
1173 wxDocTemplate
*theTemplate
= (wxDocTemplate
*) NULL
;
1175 // Find the template which this extension corresponds to
1177 for (i
= 0; i
< m_templates
.Number(); i
++)
1179 wxDocTemplate
*temp
= (wxDocTemplate
*)m_templates
.Nth(i
)->Data();
1180 if ( temp
->FileMatchesTemplate(path
) )
1189 // Prompts user to open a file, using file specs in templates.
1190 // How to implement in wxWindows? Must extend the file selector
1191 // dialog or implement own; OR match the extension to the
1192 // template extension.
1194 wxDocTemplate
*wxDocManager::SelectDocumentPath(wxDocTemplate
**templates
,
1198 int WXUNUSED(noTemplates
),
1201 long WXUNUSED(flags
),
1202 bool WXUNUSED(save
))
1204 // We can only have multiple filters in Windows
1209 for (i
= 0; i
< noTemplates
; i
++)
1211 if (templates
[i
]->IsVisible())
1213 // add a '|' to separate this filter from the previous one
1214 if ( !descrBuf
.IsEmpty() )
1215 descrBuf
<< wxT('|');
1217 descrBuf
<< templates
[i
]->GetDescription()
1218 << wxT(" (") << templates
[i
]->GetFileFilter() << wxT(") |")
1219 << templates
[i
]->GetFileFilter();
1223 wxString descrBuf
= wxT("*.*");
1226 int FilterIndex
= 0;
1227 wxString pathTmp
= wxFileSelectorEx(_("Select a file"),
1233 wxTheApp
->GetTopWindow());
1235 if (!pathTmp
.IsEmpty())
1237 m_lastDirectory
= wxPathOnly(pathTmp
);
1240 wxString theExt
= FindExtension(path
);
1242 return (wxDocTemplate
*) NULL
;
1244 // This is dodgy in that we're selecting the template on the
1245 // basis of the file extension, which may not be a standard
1246 // one. We really want to know exactly which template was
1247 // chosen by using a more advanced file selector.
1248 wxDocTemplate
*theTemplate
= FindTemplateForPath(path
);
1250 theTemplate
= templates
[FilterIndex
];
1257 return (wxDocTemplate
*) NULL
;
1260 // In all other windowing systems, until we have more advanced
1261 // file selectors, we must select the document type (template) first, and
1262 // _then_ pop up the file selector.
1263 wxDocTemplate
*temp
= SelectDocumentType(templates
, noTemplates
);
1265 return (wxDocTemplate
*) NULL
;
1267 wxChar
*pathTmp
= wxFileSelector(_("Select a file"), wxT(""), wxT(""),
1268 temp
->GetDefaultExtension(),
1269 temp
->GetFileFilter(),
1270 0, wxTheApp
->GetTopWindow());
1278 return (wxDocTemplate
*) NULL
;
1282 wxDocTemplate
*wxDocManager::SelectDocumentType(wxDocTemplate
**templates
,
1285 wxChar
**strings
= new wxChar
*[noTemplates
];
1286 wxChar
**data
= new wxChar
*[noTemplates
];
1289 for (i
= 0; i
< noTemplates
; i
++)
1291 if (templates
[i
]->IsVisible())
1293 strings
[n
] = (wxChar
*)templates
[i
]->m_description
.c_str();
1294 data
[n
] = (wxChar
*)templates
[i
];
1302 return (wxDocTemplate
*) NULL
;
1306 wxDocTemplate
*temp
= (wxDocTemplate
*)data
[0];
1312 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n
,
1313 strings
, (char **)data
);
1319 wxDocTemplate
*wxDocManager::SelectViewType(wxDocTemplate
**templates
,
1322 wxChar
**strings
= new wxChar
*[noTemplates
];
1323 wxChar
**data
= new wxChar
*[noTemplates
];
1326 for (i
= 0; i
< noTemplates
; i
++)
1328 if (templates
[i
]->IsVisible() && (templates
[i
]->GetViewName() != wxT("")))
1330 strings
[n
] = (wxChar
*)templates
[i
]->m_viewTypeName
.c_str();
1331 data
[n
] = (wxChar
*)templates
[i
];
1335 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n
,
1336 strings
, (char **)data
);
1342 void wxDocManager::AssociateTemplate(wxDocTemplate
*temp
)
1344 if (!m_templates
.Member(temp
))
1345 m_templates
.Append(temp
);
1348 void wxDocManager::DisassociateTemplate(wxDocTemplate
*temp
)
1350 m_templates
.DeleteObject(temp
);
1353 // Add and remove a document from the manager's list
1354 void wxDocManager::AddDocument(wxDocument
*doc
)
1356 if (!m_docs
.Member(doc
))
1360 void wxDocManager::RemoveDocument(wxDocument
*doc
)
1362 m_docs
.DeleteObject(doc
);
1365 // Views or windows should inform the document manager
1366 // when a view is going in or out of focus
1367 void wxDocManager::ActivateView(wxView
*view
, bool activate
, bool WXUNUSED(deleting
))
1369 // If we're deactiving, and if we're not actually deleting the view, then
1370 // don't reset the current view because we may be going to
1371 // a window without a view.
1372 // WHAT DID I MEAN BY THAT EXACTLY?
1376 if (m_currentView == view)
1377 m_currentView = NULL;
1383 m_currentView
= view
;
1385 m_currentView
= (wxView
*) NULL
;
1389 // ----------------------------------------------------------------------------
1390 // Default document child frame
1391 // ----------------------------------------------------------------------------
1393 BEGIN_EVENT_TABLE(wxDocChildFrame
, wxFrame
)
1394 EVT_ACTIVATE(wxDocChildFrame::OnActivate
)
1395 EVT_CLOSE(wxDocChildFrame::OnCloseWindow
)
1398 wxDocChildFrame::wxDocChildFrame(wxDocument
*doc
,
1402 const wxString
& title
,
1406 const wxString
& name
)
1407 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1409 m_childDocument
= doc
;
1412 view
->SetFrame(this);
1415 wxDocChildFrame::~wxDocChildFrame()
1419 // Extend event processing to search the view's event table
1420 bool wxDocChildFrame::ProcessEvent(wxEvent
& event
)
1423 m_childView
->Activate(TRUE
);
1425 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
1427 // Only hand up to the parent if it's a menu command
1428 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
1429 return wxEvtHandler::ProcessEvent(event
);
1437 void wxDocChildFrame::OnActivate(wxActivateEvent
& event
)
1439 wxFrame::OnActivate(event
);
1442 m_childView
->Activate(event
.GetActive());
1445 void wxDocChildFrame::OnCloseWindow(wxCloseEvent
& event
)
1450 if (!event
.CanVeto())
1451 ans
= TRUE
; // Must delete.
1453 ans
= m_childView
->Close(FALSE
); // FALSE means don't delete associated window
1457 m_childView
->Activate(FALSE
);
1459 m_childView
= (wxView
*) NULL
;
1460 m_childDocument
= (wxDocument
*) NULL
;
1471 // ----------------------------------------------------------------------------
1472 // Default parent frame
1473 // ----------------------------------------------------------------------------
1475 BEGIN_EVENT_TABLE(wxDocParentFrame
, wxFrame
)
1476 EVT_MENU(wxID_EXIT
, wxDocParentFrame::OnExit
)
1477 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocParentFrame::OnMRUFile
)
1478 EVT_CLOSE(wxDocParentFrame::OnCloseWindow
)
1481 wxDocParentFrame::wxDocParentFrame(wxDocManager
*manager
,
1484 const wxString
& title
,
1488 const wxString
& name
)
1489 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1491 m_docManager
= manager
;
1494 void wxDocParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
1499 void wxDocParentFrame::OnMRUFile(wxCommandEvent
& event
)
1501 int n
= event
.GetSelection() - wxID_FILE1
; // the index in MRU list
1502 wxString
filename(m_docManager
->GetHistoryFile(n
));
1503 if ( !filename
.IsEmpty() )
1505 // verify that the file exists before doing anything else
1506 if ( wxFile::Exists(filename
) )
1509 (void)m_docManager
->CreateDocument(filename
, wxDOC_SILENT
);
1513 // remove the bogus filename from the MRU list and notify the user
1515 m_docManager
->RemoveFileFromHistory(n
);
1517 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\n"
1518 "It has been also removed from the MRU files list."),
1524 // Extend event processing to search the view's event table
1525 bool wxDocParentFrame::ProcessEvent(wxEvent
& event
)
1527 // Try the document manager, then do default processing
1528 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
1529 return wxEvtHandler::ProcessEvent(event
);
1534 // Define the behaviour for the frame closing
1535 // - must delete all frames except for the main one.
1536 void wxDocParentFrame::OnCloseWindow(wxCloseEvent
& event
)
1538 if (m_docManager
->Clear(!event
.CanVeto()))
1546 #if wxUSE_PRINTING_ARCHITECTURE
1548 wxDocPrintout::wxDocPrintout(wxView
*view
, const wxString
& title
)
1551 m_printoutView
= view
;
1554 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page
))
1558 // Get the logical pixels per inch of screen and printer
1559 int ppiScreenX
, ppiScreenY
;
1560 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
1561 int ppiPrinterX
, ppiPrinterY
;
1562 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
1564 // This scales the DC so that the printout roughly represents the
1565 // the screen scaling. The text point size _should_ be the right size
1566 // but in fact is too small for some reason. This is a detail that will
1567 // need to be addressed at some point but can be fudged for the
1569 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
1571 // Now we have to check in case our real page size is reduced
1572 // (e.g. because we're drawing to a print preview memory DC)
1573 int pageWidth
, pageHeight
;
1575 dc
->GetSize(&w
, &h
);
1576 GetPageSizePixels(&pageWidth
, &pageHeight
);
1578 // If printer pageWidth == current DC width, then this doesn't
1579 // change. But w might be the preview bitmap width, so scale down.
1580 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
1581 dc
->SetUserScale(overallScale
, overallScale
);
1585 m_printoutView
->OnDraw(dc
);
1590 bool wxDocPrintout::HasPage(int pageNum
)
1592 return (pageNum
== 1);
1595 bool wxDocPrintout::OnBeginDocument(int startPage
, int endPage
)
1597 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
1603 void wxDocPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
1611 #endif // wxUSE_PRINTING_ARCHITECTURE
1613 // ----------------------------------------------------------------------------
1614 // Command processing framework
1615 // ----------------------------------------------------------------------------
1617 wxCommand::wxCommand(bool canUndoIt
, const wxString
& name
)
1619 m_canUndo
= canUndoIt
;
1620 m_commandName
= name
;
1623 wxCommand::~wxCommand()
1627 // Command processor
1628 wxCommandProcessor::wxCommandProcessor(int maxCommands
)
1630 m_maxNoCommands
= maxCommands
;
1631 m_currentCommand
= (wxNode
*) NULL
;
1632 m_commandEditMenu
= (wxMenu
*) NULL
;
1635 wxCommandProcessor::~wxCommandProcessor()
1640 // Pass a command to the processor. The processor calls Do();
1641 // if successful, is appended to the command history unless
1642 // storeIt is FALSE.
1643 bool wxCommandProcessor::Submit(wxCommand
*command
, bool storeIt
)
1645 bool success
= command
->Do();
1646 if (success
&& storeIt
)
1648 if (m_commands
.Number() == m_maxNoCommands
)
1650 wxNode
*firstNode
= m_commands
.First();
1651 wxCommand
*firstCommand
= (wxCommand
*)firstNode
->Data();
1652 delete firstCommand
;
1656 // Correct a bug: we must chop off the current 'branch'
1657 // so that we're at the end of the command list.
1658 if (!m_currentCommand
)
1662 wxNode
*node
= m_currentCommand
->Next();
1665 wxNode
*next
= node
->Next();
1666 delete (wxCommand
*)node
->Data();
1672 m_commands
.Append(command
);
1673 m_currentCommand
= m_commands
.Last();
1679 bool wxCommandProcessor::Undo()
1681 if (m_currentCommand
)
1683 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1684 if (command
->CanUndo())
1686 bool success
= command
->Undo();
1689 m_currentCommand
= m_currentCommand
->Previous();
1698 bool wxCommandProcessor::Redo()
1700 wxCommand
*redoCommand
= (wxCommand
*) NULL
;
1701 wxNode
*redoNode
= (wxNode
*) NULL
;
1702 if (m_currentCommand
&& m_currentCommand
->Next())
1704 redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1705 redoNode
= m_currentCommand
->Next();
1709 if (m_commands
.Number() > 0)
1711 redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1712 redoNode
= m_commands
.First();
1718 bool success
= redoCommand
->Do();
1721 m_currentCommand
= redoNode
;
1729 bool wxCommandProcessor::CanUndo() const
1731 if (m_currentCommand
)
1732 return ((wxCommand
*)m_currentCommand
->Data())->CanUndo();
1736 bool wxCommandProcessor::CanRedo() const
1738 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() == (wxNode
*) NULL
))
1741 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() != (wxNode
*) NULL
))
1744 if ((m_currentCommand
== (wxNode
*) NULL
) && (m_commands
.Number() > 0))
1750 void wxCommandProcessor::Initialize()
1752 m_currentCommand
= m_commands
.Last();
1756 void wxCommandProcessor::SetMenuStrings()
1758 if (m_commandEditMenu
)
1761 if (m_currentCommand
)
1763 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1764 wxString
commandName(command
->GetName());
1765 if (commandName
== wxT("")) commandName
= _("Unnamed command");
1766 bool canUndo
= command
->CanUndo();
1768 buf
= wxString(_("&Undo ")) + commandName
;
1770 buf
= wxString(_("Can't &Undo ")) + commandName
;
1772 m_commandEditMenu
->SetLabel(wxID_UNDO
, buf
);
1773 m_commandEditMenu
->Enable(wxID_UNDO
, canUndo
);
1775 // We can redo, if we're not at the end of the history.
1776 if (m_currentCommand
->Next())
1778 wxCommand
*redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1779 wxString
redoCommandName(redoCommand
->GetName());
1780 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1781 buf
= wxString(_("&Redo ")) + redoCommandName
;
1782 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1783 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1787 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1788 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1793 m_commandEditMenu
->SetLabel(wxID_UNDO
, _("&Undo"));
1794 m_commandEditMenu
->Enable(wxID_UNDO
, FALSE
);
1796 if (m_commands
.Number() == 0)
1798 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1799 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1803 // currentCommand is NULL but there are commands: this means that
1804 // we've undone to the start of the list, but can redo the first.
1805 wxCommand
*redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1806 wxString
redoCommandName(redoCommand
->GetName());
1807 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1808 buf
= wxString(_("&Redo ")) + redoCommandName
;
1809 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1810 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1816 void wxCommandProcessor::ClearCommands()
1818 wxNode
*node
= m_commands
.First();
1821 wxCommand
*command
= (wxCommand
*)node
->Data();
1824 node
= m_commands
.First();
1826 m_currentCommand
= (wxNode
*) NULL
;
1829 // ----------------------------------------------------------------------------
1830 // File history processor
1831 // ----------------------------------------------------------------------------
1833 wxFileHistory::wxFileHistory(int maxFiles
)
1835 m_fileMaxFiles
= maxFiles
;
1837 m_fileHistory
= new wxChar
*[m_fileMaxFiles
];
1840 wxFileHistory::~wxFileHistory()
1843 for (i
= 0; i
< m_fileHistoryN
; i
++)
1844 delete[] m_fileHistory
[i
];
1845 delete[] m_fileHistory
;
1848 // File history management
1849 void wxFileHistory::AddFileToHistory(const wxString
& file
)
1852 // Check we don't already have this file
1853 for (i
= 0; i
< m_fileHistoryN
; i
++)
1855 if (m_fileHistory
[i
] && wxString(m_fileHistory
[i
]) == file
)
1859 // Add to the project file history:
1860 // Move existing files (if any) down so we can insert file at beginning.
1862 // First delete filename that has popped off the end of the array (if any)
1863 if (m_fileHistoryN
== m_fileMaxFiles
)
1865 delete[] m_fileHistory
[m_fileMaxFiles
-1];
1866 m_fileHistory
[m_fileMaxFiles
-1] = (wxChar
*) NULL
;
1868 if (m_fileHistoryN
< m_fileMaxFiles
)
1870 wxNode
* node
= m_fileMenus
.First();
1873 wxMenu
* menu
= (wxMenu
*) node
->Data();
1874 if (m_fileHistoryN
== 0)
1875 menu
->AppendSeparator();
1876 menu
->Append(wxID_FILE1
+m_fileHistoryN
, _("[EMPTY]"));
1877 node
= node
->Next();
1881 // Shuffle filenames down
1882 for (i
= (m_fileHistoryN
-1); i
> 0; i
--)
1884 m_fileHistory
[i
] = m_fileHistory
[i
-1];
1886 m_fileHistory
[0] = copystring(file
);
1888 for (i
= 0; i
< m_fileHistoryN
; i
++)
1889 if (m_fileHistory
[i
])
1892 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
1893 wxNode
* node
= m_fileMenus
.First();
1896 wxMenu
* menu
= (wxMenu
*) node
->Data();
1897 menu
->SetLabel(wxID_FILE1
+i
, buf
);
1898 node
= node
->Next();
1903 void wxFileHistory::RemoveFileFromHistory(int i
)
1905 wxCHECK_RET( i
< m_fileHistoryN
,
1906 wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
1908 wxNode
* node
= m_fileMenus
.First();
1911 wxMenu
* menu
= (wxMenu
*) node
->Data();
1913 // wxMenu::Delete() is missing from wxGTK, so this can't be done :-(
1915 // delete the menu items
1916 menu
->Delete(wxID_FILE1
+ i
);
1919 // delete the element from the array (could use memmove() too...)
1920 delete [] m_fileHistory
[i
];
1923 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1925 m_fileHistory
[j
] = m_fileHistory
[j
+ 1];
1928 // shuffle filenames up
1930 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1932 buf
.Printf(s_MRUEntryFormat
, j
+ 1, m_fileHistory
[j
]);
1933 menu
->SetLabel(wxID_FILE1
+ j
, buf
);
1936 // to be removed as soon as wxMenu::Delete() is implemented
1938 menu
->SetLabel(wxID_FILE1
+ m_fileHistoryN
- 1, wxT(""));
1941 node
= node
->Next();
1946 wxString
wxFileHistory::GetHistoryFile(int i
) const
1948 if (i
< m_fileHistoryN
)
1949 return wxString(m_fileHistory
[i
]);
1951 return wxString("");
1954 void wxFileHistory::UseMenu(wxMenu
*menu
)
1956 if (!m_fileMenus
.Member(menu
))
1957 m_fileMenus
.Append(menu
);
1960 void wxFileHistory::RemoveMenu(wxMenu
*menu
)
1962 m_fileMenus
.DeleteObject(menu
);
1966 void wxFileHistory::Load(wxConfigBase
& config
)
1970 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1971 wxString historyFile
;
1972 while ((m_fileHistoryN
<= m_fileMaxFiles
) && config
.Read(buf
, &historyFile
) && (historyFile
!= wxT("")))
1974 m_fileHistory
[m_fileHistoryN
] = copystring((const wxChar
*) historyFile
);
1976 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1982 void wxFileHistory::Save(wxConfigBase
& config
)
1985 for (i
= 0; i
< m_fileHistoryN
; i
++)
1988 buf
.Printf(wxT("file%d"), i
+1);
1989 config
.Write(buf
, wxString(m_fileHistory
[i
]));
1992 #endif // wxUSE_CONFIG
1994 void wxFileHistory::AddFilesToMenu()
1996 if (m_fileHistoryN
> 0)
1998 wxNode
* node
= m_fileMenus
.First();
2001 wxMenu
* menu
= (wxMenu
*) node
->Data();
2002 menu
->AppendSeparator();
2004 for (i
= 0; i
< m_fileHistoryN
; i
++)
2006 if (m_fileHistory
[i
])
2009 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2010 menu
->Append(wxID_FILE1
+i
, buf
);
2013 node
= node
->Next();
2018 void wxFileHistory::AddFilesToMenu(wxMenu
* menu
)
2020 if (m_fileHistoryN
> 0)
2022 menu
->AppendSeparator();
2024 for (i
= 0; i
< m_fileHistoryN
; i
++)
2026 if (m_fileHistory
[i
])
2029 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2030 menu
->Append(wxID_FILE1
+i
, buf
);
2036 // ----------------------------------------------------------------------------
2037 // Permits compatibility with existing file formats and functions that
2038 // manipulate files directly
2039 // ----------------------------------------------------------------------------
2041 #if wxUSE_STD_IOSTREAM
2042 bool wxTransferFileToStream(const wxString
& filename
, ostream
& stream
)
2047 if ((fd1
= fopen (filename
.fn_str(), "rb")) == NULL
)
2050 while ((ch
= getc (fd1
)) != EOF
)
2051 stream
<< (unsigned char)ch
;
2057 bool wxTransferStreamToFile(istream
& stream
, const wxString
& filename
)
2062 if ((fd1
= fopen (filename
.fn_str(), "wb")) == NULL
)
2067 while (!stream
.eof())
2078 #endif // wxUSE_DOC_VIEW_ARCHITECTURE