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"
63 #if wxUSE_STD_IOSTREAM
64 #include "wx/ioswrap.h"
71 #include "wx/wfstream.h"
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 #if !USE_SHARED_LIBRARY
79 IMPLEMENT_ABSTRACT_CLASS(wxDocument
, wxEvtHandler
)
80 IMPLEMENT_ABSTRACT_CLASS(wxView
, wxEvtHandler
)
81 IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate
, wxObject
)
82 IMPLEMENT_DYNAMIC_CLASS(wxDocManager
, wxEvtHandler
)
83 IMPLEMENT_CLASS(wxDocChildFrame
, wxFrame
)
84 IMPLEMENT_CLASS(wxDocParentFrame
, wxFrame
)
86 #if wxUSE_PRINTING_ARCHITECTURE
87 IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout
, wxPrintout
)
90 IMPLEMENT_CLASS(wxCommand
, wxObject
)
91 IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor
, wxObject
)
92 IMPLEMENT_DYNAMIC_CLASS(wxFileHistory
, wxObject
)
95 // ----------------------------------------------------------------------------
96 // function prototypes
97 // ----------------------------------------------------------------------------
99 static inline wxString
FindExtension(const wxChar
*path
);
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 static const char *s_MRUEntryFormat
= _T("&%d %s");
107 // ============================================================================
109 // ============================================================================
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 static wxString
FindExtension(const wxChar
*path
)
118 wxSplitPath(path
, NULL
, NULL
, &ext
);
120 // VZ: extensions are considered not case sensitive - is this really a good
122 return ext
.MakeLower();
125 // ----------------------------------------------------------------------------
126 // Definition of wxDocument
127 // ----------------------------------------------------------------------------
129 wxDocument::wxDocument(wxDocument
*parent
)
131 m_documentModified
= FALSE
;
132 m_documentParent
= parent
;
133 m_documentTemplate
= (wxDocTemplate
*) NULL
;
137 bool wxDocument::DeleteContents()
142 wxDocument::~wxDocument()
146 if (m_commandProcessor
)
147 delete m_commandProcessor
;
149 GetDocumentManager()->RemoveDocument(this);
151 // Not safe to do here, since it'll invoke virtual view functions
152 // expecting to see valid derived objects: and by the time we get here,
153 // we've called destructors higher up.
157 bool wxDocument::Close()
159 if (OnSaveModified())
160 return OnCloseDocument();
165 bool wxDocument::OnCloseDocument()
172 // Note that this implicitly deletes the document when the last view is
174 bool wxDocument::DeleteAllViews()
176 wxNode
*node
= m_documentViews
.First();
179 wxView
*view
= (wxView
*)node
->Data();
183 wxNode
*next
= node
->Next();
185 delete view
; // Deletes node implicitly
191 wxView
*wxDocument::GetFirstView() const
193 if (m_documentViews
.Number() == 0)
194 return (wxView
*) NULL
;
195 return (wxView
*)m_documentViews
.First()->Data();
198 wxDocManager
*wxDocument::GetDocumentManager() const
200 return m_documentTemplate
->GetDocumentManager();
203 bool wxDocument::OnNewDocument()
205 if (!OnSaveModified())
208 if (OnCloseDocument()==FALSE
) return FALSE
;
211 SetDocumentSaved(FALSE
);
214 GetDocumentManager()->MakeDefaultName(name
);
216 SetFilename(name
, TRUE
);
221 bool wxDocument::Save()
225 if (!IsModified()) return TRUE
;
226 if (m_documentFile
== _T("") || !m_savedYet
)
229 ret
= OnSaveDocument(m_documentFile
);
231 SetDocumentSaved(TRUE
);
235 bool wxDocument::SaveAs()
237 wxDocTemplate
*docTemplate
= GetDocumentTemplate();
241 wxString tmp
= wxFileSelector(_("Save as"),
242 docTemplate
->GetDirectory(),
244 docTemplate
->GetDefaultExtension(),
245 docTemplate
->GetFileFilter(),
246 wxSAVE
| wxOVERWRITE_PROMPT
,
247 GetDocumentWindow());
252 wxString
fileName(tmp
);
253 wxString path
, name
, ext
;
254 wxSplitPath(fileName
, & path
, & name
, & ext
);
256 if (ext
.IsEmpty() || ext
== _T(""))
259 fileName
+= docTemplate
->GetDefaultExtension();
262 SetFilename(fileName
);
263 SetTitle(wxFileNameFromPath(fileName
));
265 GetDocumentManager()->AddFileToHistory(fileName
);
267 // Notify the views that the filename has changed
268 wxNode
*node
= m_documentViews
.First();
271 wxView
*view
= (wxView
*)node
->Data();
272 view
->OnChangeFilename();
276 return OnSaveDocument(m_documentFile
);
279 bool wxDocument::OnSaveDocument(const wxString
& file
)
285 if (wxTheApp
->GetAppName() != _T(""))
286 msgTitle
= wxTheApp
->GetAppName();
288 msgTitle
= wxString(_("File error"));
290 #if wxUSE_STD_IOSTREAM
291 ofstream
store(wxString(file
.fn_str()));
292 if (store
.fail() || store
.bad())
294 wxFileOutputStream
store(wxString(file
.fn_str()));
295 if (store
.LastError() != 0)
298 (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
299 GetDocumentWindow());
303 if (!SaveObject(store
))
305 (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
306 GetDocumentWindow());
315 bool wxDocument::OnOpenDocument(const wxString
& file
)
317 if (!OnSaveModified())
321 if (wxTheApp
->GetAppName() != _T(""))
322 msgTitle
= wxTheApp
->GetAppName();
324 msgTitle
= wxString(_("File error"));
326 #if wxUSE_STD_IOSTREAM
327 ifstream
store(wxString(file
.fn_str()));
328 if (store
.fail() || store
.bad())
330 wxFileInputStream
store(wxString(file
.fn_str()));
331 if (store
.LastError() != 0)
334 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
335 GetDocumentWindow());
338 if (!LoadObject(store
))
340 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
341 GetDocumentWindow());
344 SetFilename(file
, TRUE
);
353 #if wxUSE_STD_IOSTREAM
354 istream
& wxDocument::LoadObject(istream
& stream
)
356 wxInputStream
& wxDocument::LoadObject(wxInputStream
& stream
)
362 #if wxUSE_STD_IOSTREAM
363 ostream
& wxDocument::SaveObject(ostream
& stream
)
365 wxOutputStream
& wxDocument::SaveObject(wxOutputStream
& stream
)
371 bool wxDocument::Revert()
377 // Get title, or filename if no title, else unnamed
378 bool wxDocument::GetPrintableName(wxString
& buf
) const
380 if (m_documentTitle
!= _T(""))
382 buf
= m_documentTitle
;
385 else if (m_documentFile
!= _T(""))
387 buf
= wxFileNameFromPath(m_documentFile
);
397 wxWindow
*wxDocument::GetDocumentWindow() const
399 wxView
*view
= GetFirstView();
401 return view
->GetFrame();
403 return wxTheApp
->GetTopWindow();
406 wxCommandProcessor
*wxDocument::OnCreateCommandProcessor()
408 return new wxCommandProcessor
;
411 // TRUE if safe to close
412 bool wxDocument::OnSaveModified()
417 GetPrintableName(title
);
420 if (wxTheApp
->GetAppName() != _T(""))
421 msgTitle
= wxTheApp
->GetAppName();
423 msgTitle
= wxString(_("Warning"));
426 prompt
.Printf(_("Do you want to save changes to document %s?"),
427 (const wxChar
*)title
);
428 int res
= wxMessageBox(prompt
, msgTitle
,
429 wxYES_NO
|wxCANCEL
|wxICON_QUESTION
,
430 GetDocumentWindow());
436 else if (res
== wxYES
)
438 else if (res
== wxCANCEL
)
444 bool wxDocument::Draw(wxDC
& WXUNUSED(context
))
449 bool wxDocument::AddView(wxView
*view
)
451 if (!m_documentViews
.Member(view
))
453 m_documentViews
.Append(view
);
459 bool wxDocument::RemoveView(wxView
*view
)
461 (void)m_documentViews
.DeleteObject(view
);
466 bool wxDocument::OnCreate(const wxString
& WXUNUSED(path
), long flags
)
468 if (GetDocumentTemplate()->CreateView(this, flags
))
474 // Called after a view is added or removed.
475 // The default implementation deletes the document if
476 // there are no more views.
477 void wxDocument::OnChangedViewList()
479 if (m_documentViews
.Number() == 0)
481 if (OnSaveModified())
488 void wxDocument::UpdateAllViews(wxView
*sender
, wxObject
*hint
)
490 wxNode
*node
= m_documentViews
.First();
493 wxView
*view
= (wxView
*)node
->Data();
494 view
->OnUpdate(sender
, hint
);
499 void wxDocument::SetFilename(const wxString
& filename
, bool notifyViews
)
501 m_documentFile
= filename
;
504 // Notify the views that the filename has changed
505 wxNode
*node
= m_documentViews
.First();
508 wxView
*view
= (wxView
*)node
->Data();
509 view
->OnChangeFilename();
515 // ----------------------------------------------------------------------------
517 // ----------------------------------------------------------------------------
522 m_viewDocument
= (wxDocument
*) NULL
;
525 m_viewFrame
= (wxFrame
*) NULL
;
530 GetDocumentManager()->ActivateView(this, FALSE
, TRUE
);
531 m_viewDocument
->RemoveView(this);
534 // Extend event processing to search the document's event table
535 bool wxView::ProcessEvent(wxEvent
& event
)
537 if ( !GetDocument() || !GetDocument()->ProcessEvent(event
) )
538 return wxEvtHandler::ProcessEvent(event
);
543 void wxView::OnActivateView(bool WXUNUSED(activate
), wxView
*WXUNUSED(activeView
), wxView
*WXUNUSED(deactiveView
))
547 void wxView::OnPrint(wxDC
*dc
, wxObject
*WXUNUSED(info
))
552 void wxView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*WXUNUSED(hint
))
556 void wxView::OnChangeFilename()
558 if (GetFrame() && GetDocument())
561 GetDocument()->GetPrintableName(name
);
563 GetFrame()->SetTitle(name
);
567 void wxView::SetDocument(wxDocument
*doc
)
569 m_viewDocument
= doc
;
574 bool wxView::Close(bool deleteWindow
)
576 if (OnClose(deleteWindow
))
582 void wxView::Activate(bool activate
)
584 if (GetDocumentManager())
586 OnActivateView(activate
, this, GetDocumentManager()->GetCurrentView());
587 GetDocumentManager()->ActivateView(this, activate
);
591 bool wxView::OnClose(bool WXUNUSED(deleteWindow
))
593 return GetDocument() ? GetDocument()->Close() : TRUE
;
596 #if wxUSE_PRINTING_ARCHITECTURE
597 wxPrintout
*wxView::OnCreatePrintout()
599 return new wxDocPrintout(this);
601 #endif // wxUSE_PRINTING_ARCHITECTURE
603 // ----------------------------------------------------------------------------
605 // ----------------------------------------------------------------------------
607 wxDocTemplate::wxDocTemplate(wxDocManager
*manager
,
608 const wxString
& descr
,
609 const wxString
& filter
,
612 const wxString
& docTypeName
,
613 const wxString
& viewTypeName
,
614 wxClassInfo
*docClassInfo
,
615 wxClassInfo
*viewClassInfo
,
618 m_documentManager
= manager
;
619 m_description
= descr
;
622 m_fileFilter
= filter
;
624 m_docTypeName
= docTypeName
;
625 m_viewTypeName
= viewTypeName
;
626 m_documentManager
->AssociateTemplate(this);
628 m_docClassInfo
= docClassInfo
;
629 m_viewClassInfo
= viewClassInfo
;
632 wxDocTemplate::~wxDocTemplate()
634 m_documentManager
->DisassociateTemplate(this);
637 // Tries to dynamically construct an object of the right class.
638 wxDocument
*wxDocTemplate::CreateDocument(const wxString
& path
, long flags
)
641 return (wxDocument
*) NULL
;
642 wxDocument
*doc
= (wxDocument
*)m_docClassInfo
->CreateObject();
643 doc
->SetFilename(path
);
644 doc
->SetDocumentTemplate(this);
645 GetDocumentManager()->AddDocument(doc
);
646 doc
->SetCommandProcessor(doc
->OnCreateCommandProcessor());
648 if (doc
->OnCreate(path
, flags
))
653 return (wxDocument
*) NULL
;
657 wxView
*wxDocTemplate::CreateView(wxDocument
*doc
, long flags
)
659 if (!m_viewClassInfo
)
660 return (wxView
*) NULL
;
661 wxView
*view
= (wxView
*)m_viewClassInfo
->CreateObject();
662 view
->SetDocument(doc
);
663 if (view
->OnCreate(doc
, flags
))
670 return (wxView
*) NULL
;
674 // The default (very primitive) format detection: check is the extension is
675 // that of the template
676 bool wxDocTemplate::FileMatchesTemplate(const wxString
& path
)
678 return GetDefaultExtension().IsSameAs(FindExtension(path
));
681 // ----------------------------------------------------------------------------
683 // ----------------------------------------------------------------------------
685 BEGIN_EVENT_TABLE(wxDocManager
, wxEvtHandler
)
686 EVT_MENU(wxID_OPEN
, wxDocManager::OnFileOpen
)
687 EVT_MENU(wxID_CLOSE
, wxDocManager::OnFileClose
)
688 EVT_MENU(wxID_REVERT
, wxDocManager::OnFileRevert
)
689 EVT_MENU(wxID_NEW
, wxDocManager::OnFileNew
)
690 EVT_MENU(wxID_SAVE
, wxDocManager::OnFileSave
)
691 EVT_MENU(wxID_SAVEAS
, wxDocManager::OnFileSaveAs
)
692 EVT_MENU(wxID_UNDO
, wxDocManager::OnUndo
)
693 EVT_MENU(wxID_REDO
, wxDocManager::OnRedo
)
694 #if wxUSE_PRINTING_ARCHITECTURE
695 EVT_MENU(wxID_PRINT
, wxDocManager::OnPrint
)
696 EVT_MENU(wxID_PRINT_SETUP
, wxDocManager::OnPrintSetup
)
697 EVT_MENU(wxID_PREVIEW
, wxDocManager::OnPreview
)
701 wxDocManager::wxDocManager(long flags
, bool initialize
)
703 m_defaultDocumentNameCounter
= 1;
705 m_currentView
= (wxView
*) NULL
;
706 m_maxDocsOpen
= 10000;
707 m_fileHistory
= (wxFileHistory
*) NULL
;
712 wxDocManager::~wxDocManager()
716 delete m_fileHistory
;
719 bool wxDocManager::Clear(bool force
)
721 wxNode
*node
= m_docs
.First();
724 wxDocument
*doc
= (wxDocument
*)node
->Data();
725 wxNode
*next
= node
->Next();
727 if (!doc
->Close() && !force
)
730 // Implicitly deletes the document when the last
731 // view is removed (deleted)
732 doc
->DeleteAllViews();
734 // Check document is deleted
735 if (m_docs
.Member(doc
))
738 // This assumes that documents are not connected in
739 // any way, i.e. deleting one document does NOT
743 node
= m_templates
.First();
746 wxDocTemplate
*templ
= (wxDocTemplate
*) node
->Data();
747 wxNode
* next
= node
->Next();
754 bool wxDocManager::Initialize()
756 m_fileHistory
= OnCreateFileHistory();
760 wxFileHistory
*wxDocManager::OnCreateFileHistory()
762 return new wxFileHistory
;
765 void wxDocManager::OnFileClose(wxCommandEvent
& WXUNUSED(event
))
767 wxDocument
*doc
= GetCurrentDocument();
772 doc
->DeleteAllViews();
773 if (m_docs
.Member(doc
))
778 void wxDocManager::OnFileNew(wxCommandEvent
& WXUNUSED(event
))
780 CreateDocument(wxString(""), wxDOC_NEW
);
783 void wxDocManager::OnFileOpen(wxCommandEvent
& WXUNUSED(event
))
785 CreateDocument(wxString(""), 0);
788 void wxDocManager::OnFileRevert(wxCommandEvent
& WXUNUSED(event
))
790 wxDocument
*doc
= GetCurrentDocument();
796 void wxDocManager::OnFileSave(wxCommandEvent
& WXUNUSED(event
))
798 wxDocument
*doc
= GetCurrentDocument();
804 void wxDocManager::OnFileSaveAs(wxCommandEvent
& WXUNUSED(event
))
806 wxDocument
*doc
= GetCurrentDocument();
812 void wxDocManager::OnPrint(wxCommandEvent
& WXUNUSED(event
))
814 #if wxUSE_PRINTING_ARCHITECTURE
815 wxView
*view
= GetCurrentView();
819 wxPrintout
*printout
= view
->OnCreatePrintout();
823 printer
.Print(view
->GetFrame(), printout
, TRUE
);
827 #endif // wxUSE_PRINTING_ARCHITECTURE
830 void wxDocManager::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
832 #if wxUSE_PRINTING_ARCHITECTURE
833 wxWindow
*parentWin
= wxTheApp
->GetTopWindow();
834 wxView
*view
= GetCurrentView();
836 parentWin
= view
->GetFrame();
838 wxPrintDialogData data
;
840 wxPrintDialog
printerDialog(parentWin
, &data
);
841 printerDialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
842 printerDialog
.ShowModal();
843 #endif // wxUSE_PRINTING_ARCHITECTURE
846 void wxDocManager::OnPreview(wxCommandEvent
& WXUNUSED(event
))
848 #if wxUSE_PRINTING_ARCHITECTURE
849 wxView
*view
= GetCurrentView();
853 wxPrintout
*printout
= view
->OnCreatePrintout();
856 // Pass two printout objects: for preview, and possible printing.
857 wxPrintPreviewBase
*preview
= (wxPrintPreviewBase
*) NULL
;
858 preview
= new wxPrintPreview(printout
, view
->OnCreatePrintout());
860 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, (wxFrame
*)wxTheApp
->GetTopWindow(), _("Print Preview"),
861 wxPoint(100, 100), wxSize(600, 650));
862 frame
->Centre(wxBOTH
);
866 #endif // wxUSE_PRINTING_ARCHITECTURE
869 void wxDocManager::OnUndo(wxCommandEvent
& WXUNUSED(event
))
871 wxDocument
*doc
= GetCurrentDocument();
874 if (doc
->GetCommandProcessor())
875 doc
->GetCommandProcessor()->Undo();
878 void wxDocManager::OnRedo(wxCommandEvent
& WXUNUSED(event
))
880 wxDocument
*doc
= GetCurrentDocument();
883 if (doc
->GetCommandProcessor())
884 doc
->GetCommandProcessor()->Redo();
887 wxView
*wxDocManager::GetCurrentView() const
890 return m_currentView
;
891 if (m_docs
.Number() == 1)
893 wxDocument
* doc
= (wxDocument
*) m_docs
.First()->Data();
894 return doc
->GetFirstView();
896 return (wxView
*) NULL
;
899 // Extend event processing to search the view's event table
900 bool wxDocManager::ProcessEvent(wxEvent
& event
)
902 wxView
* view
= GetCurrentView();
905 if (view
->ProcessEvent(event
))
908 return wxEvtHandler::ProcessEvent(event
);
911 wxDocument
*wxDocManager::CreateDocument(const wxString
& path
, long flags
)
913 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
916 for (i
= 0; i
< m_templates
.Number(); i
++)
918 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
919 if (temp
->IsVisible())
928 return (wxDocument
*) NULL
;
931 // If we've reached the max number of docs, close the
933 if (GetDocuments().Number() >= m_maxDocsOpen
)
935 wxDocument
*doc
= (wxDocument
*)GetDocuments().First()->Data();
938 // Implicitly deletes the document when
939 // the last view is deleted
940 doc
->DeleteAllViews();
942 // Check we're really deleted
943 if (m_docs
.Member(doc
))
947 return (wxDocument
*) NULL
;
950 // New document: user chooses a template, unless there's only one.
951 if (flags
& wxDOC_NEW
)
955 wxDocTemplate
*temp
= templates
[0];
957 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
960 newDoc
->SetDocumentName(temp
->GetDocumentName());
961 newDoc
->SetDocumentTemplate(temp
);
962 newDoc
->OnNewDocument();
967 wxDocTemplate
*temp
= SelectDocumentType(templates
, n
);
971 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
974 newDoc
->SetDocumentName(temp
->GetDocumentName());
975 newDoc
->SetDocumentTemplate(temp
);
976 newDoc
->OnNewDocument();
981 return (wxDocument
*) NULL
;
985 wxDocTemplate
*temp
= (wxDocTemplate
*) NULL
;
987 wxString
path2(_T(""));
991 if (flags
& wxDOC_SILENT
)
992 temp
= FindTemplateForPath(path2
);
994 temp
= SelectDocumentPath(templates
, n
, path2
, flags
);
1000 wxDocument
*newDoc
= temp
->CreateDocument(path2
, flags
);
1003 newDoc
->SetDocumentName(temp
->GetDocumentName());
1004 newDoc
->SetDocumentTemplate(temp
);
1005 if (!newDoc
->OnOpenDocument(path2
))
1008 return (wxDocument
*) NULL
;
1010 AddFileToHistory(path2
);
1015 return (wxDocument
*) NULL
;
1018 wxView
*wxDocManager::CreateView(wxDocument
*doc
, long flags
)
1020 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
1023 for (i
= 0; i
< m_templates
.Number(); i
++)
1025 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
1026 if (temp
->IsVisible())
1028 if (temp
->GetDocumentName() == doc
->GetDocumentName())
1030 templates
[n
] = temp
;
1038 return (wxView
*) NULL
;
1042 wxDocTemplate
*temp
= templates
[0];
1044 wxView
*view
= temp
->CreateView(doc
, flags
);
1046 view
->SetViewName(temp
->GetViewName());
1050 wxDocTemplate
*temp
= SelectViewType(templates
, n
);
1054 wxView
*view
= temp
->CreateView(doc
, flags
);
1056 view
->SetViewName(temp
->GetViewName());
1060 return (wxView
*) NULL
;
1063 // Not yet implemented
1064 void wxDocManager::DeleteTemplate(wxDocTemplate
*WXUNUSED(temp
), long WXUNUSED(flags
))
1068 // Not yet implemented
1069 bool wxDocManager::FlushDoc(wxDocument
*WXUNUSED(doc
))
1074 wxDocument
*wxDocManager::GetCurrentDocument() const
1077 return m_currentView
->GetDocument();
1079 return (wxDocument
*) NULL
;
1082 // Make a default document name
1083 bool wxDocManager::MakeDefaultName(wxString
& name
)
1085 name
.Printf(_("unnamed%d"), m_defaultDocumentNameCounter
);
1086 m_defaultDocumentNameCounter
++;
1091 // Not yet implemented
1092 wxDocTemplate
*wxDocManager::MatchTemplate(const wxString
& WXUNUSED(path
))
1094 return (wxDocTemplate
*) NULL
;
1097 // File history management
1098 void wxDocManager::AddFileToHistory(const wxString
& file
)
1101 m_fileHistory
->AddFileToHistory(file
);
1104 void wxDocManager::RemoveFileFromHistory(int i
)
1107 m_fileHistory
->RemoveFileFromHistory(i
);
1110 wxString
wxDocManager::GetHistoryFile(int i
) const
1115 histFile
= m_fileHistory
->GetHistoryFile(i
);
1120 void wxDocManager::FileHistoryUseMenu(wxMenu
*menu
)
1123 m_fileHistory
->UseMenu(menu
);
1126 void wxDocManager::FileHistoryRemoveMenu(wxMenu
*menu
)
1129 m_fileHistory
->RemoveMenu(menu
);
1133 void wxDocManager::FileHistoryLoad(wxConfigBase
& config
)
1136 m_fileHistory
->Load(config
);
1139 void wxDocManager::FileHistorySave(wxConfigBase
& config
)
1142 m_fileHistory
->Save(config
);
1146 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu
* menu
)
1149 m_fileHistory
->AddFilesToMenu(menu
);
1152 void wxDocManager::FileHistoryAddFilesToMenu()
1155 m_fileHistory
->AddFilesToMenu();
1158 int wxDocManager::GetNoHistoryFiles() const
1161 return m_fileHistory
->GetNoHistoryFiles();
1167 // Find out the document template via matching in the document file format
1168 // against that of the template
1169 wxDocTemplate
*wxDocManager::FindTemplateForPath(const wxString
& path
)
1171 wxDocTemplate
*theTemplate
= (wxDocTemplate
*) NULL
;
1173 // Find the template which this extension corresponds to
1175 for (i
= 0; i
< m_templates
.Number(); i
++)
1177 wxDocTemplate
*temp
= (wxDocTemplate
*)m_templates
.Nth(i
)->Data();
1178 if ( temp
->FileMatchesTemplate(path
) )
1187 // Prompts user to open a file, using file specs in templates.
1188 // How to implement in wxWindows? Must extend the file selector
1189 // dialog or implement own; OR match the extension to the
1190 // template extension.
1192 wxDocTemplate
*wxDocManager::SelectDocumentPath(wxDocTemplate
**templates
,
1196 int WXUNUSED(noTemplates
),
1199 long WXUNUSED(flags
),
1200 bool WXUNUSED(save
))
1202 // We can only have multiple filters in Windows
1207 for (i
= 0; i
< noTemplates
; i
++)
1209 if (templates
[i
]->IsVisible())
1211 // add a '|' to separate this filter from the previous one
1212 if ( !descrBuf
.IsEmpty() )
1213 descrBuf
<< _T('|');
1215 descrBuf
<< templates
[i
]->GetDescription()
1216 << _T(" (") << templates
[i
]->GetFileFilter() << _T(") |")
1217 << templates
[i
]->GetFileFilter();
1221 wxString descrBuf
= _T("*.*");
1224 int FilterIndex
= 0;
1225 wxString pathTmp
= wxFileSelectorEx(_("Select a file"),
1231 wxTheApp
->GetTopWindow());
1233 if (!pathTmp
.IsEmpty())
1236 wxString theExt
= FindExtension(path
);
1238 return (wxDocTemplate
*) NULL
;
1240 // This is dodgy in that we're selecting the template on the
1241 // basis of the file extension, which may not be a standard
1242 // one. We really want to know exactly which template was
1243 // chosen by using a more advanced file selector.
1244 wxDocTemplate
*theTemplate
= FindTemplateForPath(path
);
1246 theTemplate
= templates
[FilterIndex
];
1253 return (wxDocTemplate
*) NULL
;
1256 // In all other windowing systems, until we have more advanced
1257 // file selectors, we must select the document type (template) first, and
1258 // _then_ pop up the file selector.
1259 wxDocTemplate
*temp
= SelectDocumentType(templates
, noTemplates
);
1261 return (wxDocTemplate
*) NULL
;
1263 wxChar
*pathTmp
= wxFileSelector(_("Select a file"), _T(""), _T(""),
1264 temp
->GetDefaultExtension(),
1265 temp
->GetFileFilter(),
1266 0, wxTheApp
->GetTopWindow());
1274 return (wxDocTemplate
*) NULL
;
1278 wxDocTemplate
*wxDocManager::SelectDocumentType(wxDocTemplate
**templates
,
1281 wxChar
**strings
= new wxChar
*[noTemplates
];
1282 wxChar
**data
= new wxChar
*[noTemplates
];
1285 for (i
= 0; i
< noTemplates
; i
++)
1287 if (templates
[i
]->IsVisible())
1289 strings
[n
] = WXSTRINGCAST templates
[i
]->m_description
;
1290 data
[n
] = (wxChar
*)templates
[i
];
1298 return (wxDocTemplate
*) NULL
;
1302 wxDocTemplate
*temp
= (wxDocTemplate
*)data
[0];
1308 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n
,
1309 strings
, (char **)data
);
1315 wxDocTemplate
*wxDocManager::SelectViewType(wxDocTemplate
**templates
,
1318 wxChar
**strings
= new wxChar
*[noTemplates
];
1319 wxChar
**data
= new wxChar
*[noTemplates
];
1322 for (i
= 0; i
< noTemplates
; i
++)
1324 if (templates
[i
]->IsVisible() && (templates
[i
]->GetViewName() != _T("")))
1326 strings
[n
] = WXSTRINGCAST templates
[i
]->m_viewTypeName
;
1327 data
[n
] = (wxChar
*)templates
[i
];
1331 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n
,
1332 strings
, (char **)data
);
1338 void wxDocManager::AssociateTemplate(wxDocTemplate
*temp
)
1340 if (!m_templates
.Member(temp
))
1341 m_templates
.Append(temp
);
1344 void wxDocManager::DisassociateTemplate(wxDocTemplate
*temp
)
1346 m_templates
.DeleteObject(temp
);
1349 // Add and remove a document from the manager's list
1350 void wxDocManager::AddDocument(wxDocument
*doc
)
1352 if (!m_docs
.Member(doc
))
1356 void wxDocManager::RemoveDocument(wxDocument
*doc
)
1358 m_docs
.DeleteObject(doc
);
1361 // Views or windows should inform the document manager
1362 // when a view is going in or out of focus
1363 void wxDocManager::ActivateView(wxView
*view
, bool activate
, bool WXUNUSED(deleting
))
1365 // If we're deactiving, and if we're not actually deleting the view, then
1366 // don't reset the current view because we may be going to
1367 // a window without a view.
1368 // WHAT DID I MEAN BY THAT EXACTLY?
1372 if (m_currentView == view)
1373 m_currentView = NULL;
1379 m_currentView
= view
;
1381 m_currentView
= (wxView
*) NULL
;
1385 // ----------------------------------------------------------------------------
1386 // Default document child frame
1387 // ----------------------------------------------------------------------------
1389 BEGIN_EVENT_TABLE(wxDocChildFrame
, wxFrame
)
1390 EVT_ACTIVATE(wxDocChildFrame::OnActivate
)
1391 EVT_CLOSE(wxDocChildFrame::OnCloseWindow
)
1394 wxDocChildFrame::wxDocChildFrame(wxDocument
*doc
,
1398 const wxString
& title
,
1402 const wxString
& name
)
1403 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1405 m_childDocument
= doc
;
1408 view
->SetFrame(this);
1411 wxDocChildFrame::~wxDocChildFrame()
1415 // Extend event processing to search the view's event table
1416 bool wxDocChildFrame::ProcessEvent(wxEvent
& event
)
1419 m_childView
->Activate(TRUE
);
1421 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
1423 // Only hand up to the parent if it's a menu command
1424 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
1425 return wxEvtHandler::ProcessEvent(event
);
1433 void wxDocChildFrame::OnActivate(wxActivateEvent
& event
)
1435 wxFrame::OnActivate(event
);
1438 m_childView
->Activate(event
.GetActive());
1441 void wxDocChildFrame::OnCloseWindow(wxCloseEvent
& event
)
1446 if (!event
.CanVeto())
1447 ans
= TRUE
; // Must delete.
1449 ans
= m_childView
->Close(FALSE
); // FALSE means don't delete associated window
1453 m_childView
->Activate(FALSE
);
1455 m_childView
= (wxView
*) NULL
;
1456 m_childDocument
= (wxDocument
*) NULL
;
1467 // ----------------------------------------------------------------------------
1468 // Default parent frame
1469 // ----------------------------------------------------------------------------
1471 BEGIN_EVENT_TABLE(wxDocParentFrame
, wxFrame
)
1472 EVT_MENU(wxID_EXIT
, wxDocParentFrame::OnExit
)
1473 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocParentFrame::OnMRUFile
)
1474 EVT_CLOSE(wxDocParentFrame::OnCloseWindow
)
1477 wxDocParentFrame::wxDocParentFrame(wxDocManager
*manager
,
1480 const wxString
& title
,
1484 const wxString
& name
)
1485 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1487 m_docManager
= manager
;
1490 void wxDocParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
1495 void wxDocParentFrame::OnMRUFile(wxCommandEvent
& event
)
1497 int n
= event
.GetSelection() - wxID_FILE1
; // the index in MRU list
1498 wxString
filename(m_docManager
->GetHistoryFile(n
));
1499 if ( !filename
.IsEmpty() )
1501 // verify that the file exists before doing anything else
1502 if ( wxFile::Exists(filename
) )
1505 (void)m_docManager
->CreateDocument(filename
, wxDOC_SILENT
);
1509 // remove the bogus filename from the MRU list and notify the user
1511 m_docManager
->RemoveFileFromHistory(n
);
1513 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\n"
1514 "It has been also removed from the MRU files list."),
1520 // Extend event processing to search the view's event table
1521 bool wxDocParentFrame::ProcessEvent(wxEvent
& event
)
1523 // Try the document manager, then do default processing
1524 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
1525 return wxEvtHandler::ProcessEvent(event
);
1530 // Define the behaviour for the frame closing
1531 // - must delete all frames except for the main one.
1532 void wxDocParentFrame::OnCloseWindow(wxCloseEvent
& event
)
1534 if (m_docManager
->Clear(!event
.CanVeto()))
1542 #if wxUSE_PRINTING_ARCHITECTURE
1544 wxDocPrintout::wxDocPrintout(wxView
*view
, const wxString
& title
)
1545 : wxPrintout(WXSTRINGCAST title
)
1547 m_printoutView
= view
;
1550 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page
))
1554 // Get the logical pixels per inch of screen and printer
1555 int ppiScreenX
, ppiScreenY
;
1556 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
1557 int ppiPrinterX
, ppiPrinterY
;
1558 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
1560 // This scales the DC so that the printout roughly represents the
1561 // the screen scaling. The text point size _should_ be the right size
1562 // but in fact is too small for some reason. This is a detail that will
1563 // need to be addressed at some point but can be fudged for the
1565 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
1567 // Now we have to check in case our real page size is reduced
1568 // (e.g. because we're drawing to a print preview memory DC)
1569 int pageWidth
, pageHeight
;
1571 dc
->GetSize(&w
, &h
);
1572 GetPageSizePixels(&pageWidth
, &pageHeight
);
1574 // If printer pageWidth == current DC width, then this doesn't
1575 // change. But w might be the preview bitmap width, so scale down.
1576 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
1577 dc
->SetUserScale(overallScale
, overallScale
);
1581 m_printoutView
->OnDraw(dc
);
1586 bool wxDocPrintout::HasPage(int pageNum
)
1588 return (pageNum
== 1);
1591 bool wxDocPrintout::OnBeginDocument(int startPage
, int endPage
)
1593 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
1599 void wxDocPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
1607 #endif // wxUSE_PRINTING_ARCHITECTURE
1609 // ----------------------------------------------------------------------------
1610 // Command processing framework
1611 // ----------------------------------------------------------------------------
1613 wxCommand::wxCommand(bool canUndoIt
, const wxString
& name
)
1615 m_canUndo
= canUndoIt
;
1616 m_commandName
= name
;
1619 wxCommand::~wxCommand()
1623 // Command processor
1624 wxCommandProcessor::wxCommandProcessor(int maxCommands
)
1626 m_maxNoCommands
= maxCommands
;
1627 m_currentCommand
= (wxNode
*) NULL
;
1628 m_commandEditMenu
= (wxMenu
*) NULL
;
1631 wxCommandProcessor::~wxCommandProcessor()
1636 // Pass a command to the processor. The processor calls Do();
1637 // if successful, is appended to the command history unless
1638 // storeIt is FALSE.
1639 bool wxCommandProcessor::Submit(wxCommand
*command
, bool storeIt
)
1641 bool success
= command
->Do();
1642 if (success
&& storeIt
)
1644 if (m_commands
.Number() == m_maxNoCommands
)
1646 wxNode
*firstNode
= m_commands
.First();
1647 wxCommand
*firstCommand
= (wxCommand
*)firstNode
->Data();
1648 delete firstCommand
;
1652 // Correct a bug: we must chop off the current 'branch'
1653 // so that we're at the end of the command list.
1654 if (!m_currentCommand
)
1658 wxNode
*node
= m_currentCommand
->Next();
1661 wxNode
*next
= node
->Next();
1662 delete (wxCommand
*)node
->Data();
1668 m_commands
.Append(command
);
1669 m_currentCommand
= m_commands
.Last();
1675 bool wxCommandProcessor::Undo()
1677 if (m_currentCommand
)
1679 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1680 if (command
->CanUndo())
1682 bool success
= command
->Undo();
1685 m_currentCommand
= m_currentCommand
->Previous();
1694 bool wxCommandProcessor::Redo()
1696 wxCommand
*redoCommand
= (wxCommand
*) NULL
;
1697 wxNode
*redoNode
= (wxNode
*) NULL
;
1698 if (m_currentCommand
&& m_currentCommand
->Next())
1700 redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1701 redoNode
= m_currentCommand
->Next();
1705 if (m_commands
.Number() > 0)
1707 redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1708 redoNode
= m_commands
.First();
1714 bool success
= redoCommand
->Do();
1717 m_currentCommand
= redoNode
;
1725 bool wxCommandProcessor::CanUndo() const
1727 if (m_currentCommand
)
1728 return ((wxCommand
*)m_currentCommand
->Data())->CanUndo();
1732 bool wxCommandProcessor::CanRedo() const
1734 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() == (wxNode
*) NULL
))
1737 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() != (wxNode
*) NULL
))
1740 if ((m_currentCommand
== (wxNode
*) NULL
) && (m_commands
.Number() > 0))
1746 void wxCommandProcessor::Initialize()
1748 m_currentCommand
= m_commands
.Last();
1752 void wxCommandProcessor::SetMenuStrings()
1754 if (m_commandEditMenu
)
1757 if (m_currentCommand
)
1759 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1760 wxString
commandName(command
->GetName());
1761 if (commandName
== _T("")) commandName
= _("Unnamed command");
1762 bool canUndo
= command
->CanUndo();
1764 buf
= wxString(_("&Undo ")) + commandName
;
1766 buf
= wxString(_("Can't &Undo ")) + commandName
;
1768 m_commandEditMenu
->SetLabel(wxID_UNDO
, buf
);
1769 m_commandEditMenu
->Enable(wxID_UNDO
, canUndo
);
1771 // We can redo, if we're not at the end of the history.
1772 if (m_currentCommand
->Next())
1774 wxCommand
*redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1775 wxString
redoCommandName(redoCommand
->GetName());
1776 if (redoCommandName
== _T("")) redoCommandName
= _("Unnamed command");
1777 buf
= wxString(_("&Redo ")) + redoCommandName
;
1778 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1779 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1783 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1784 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1789 m_commandEditMenu
->SetLabel(wxID_UNDO
, _("&Undo"));
1790 m_commandEditMenu
->Enable(wxID_UNDO
, FALSE
);
1792 if (m_commands
.Number() == 0)
1794 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1795 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1799 // currentCommand is NULL but there are commands: this means that
1800 // we've undone to the start of the list, but can redo the first.
1801 wxCommand
*redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1802 wxString
redoCommandName(redoCommand
->GetName());
1803 if (redoCommandName
== _T("")) redoCommandName
= _("Unnamed command");
1804 buf
= wxString(_("&Redo ")) + redoCommandName
;
1805 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1806 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1812 void wxCommandProcessor::ClearCommands()
1814 wxNode
*node
= m_commands
.First();
1817 wxCommand
*command
= (wxCommand
*)node
->Data();
1820 node
= m_commands
.First();
1822 m_currentCommand
= (wxNode
*) NULL
;
1825 // ----------------------------------------------------------------------------
1826 // File history processor
1827 // ----------------------------------------------------------------------------
1829 wxFileHistory::wxFileHistory(int maxFiles
)
1831 m_fileMaxFiles
= maxFiles
;
1833 m_fileHistory
= new wxChar
*[m_fileMaxFiles
];
1836 wxFileHistory::~wxFileHistory()
1839 for (i
= 0; i
< m_fileHistoryN
; i
++)
1840 delete[] m_fileHistory
[i
];
1841 delete[] m_fileHistory
;
1844 // File history management
1845 void wxFileHistory::AddFileToHistory(const wxString
& file
)
1848 // Check we don't already have this file
1849 for (i
= 0; i
< m_fileHistoryN
; i
++)
1851 if (m_fileHistory
[i
] && wxString(m_fileHistory
[i
]) == file
)
1855 // Add to the project file history:
1856 // Move existing files (if any) down so we can insert file at beginning.
1858 // First delete filename that has popped off the end of the array (if any)
1859 if (m_fileHistoryN
== m_fileMaxFiles
)
1861 delete[] m_fileHistory
[m_fileMaxFiles
-1];
1862 m_fileHistory
[m_fileMaxFiles
-1] = (wxChar
*) NULL
;
1864 if (m_fileHistoryN
< m_fileMaxFiles
)
1866 wxNode
* node
= m_fileMenus
.First();
1869 wxMenu
* menu
= (wxMenu
*) node
->Data();
1870 if (m_fileHistoryN
== 0)
1871 menu
->AppendSeparator();
1872 menu
->Append(wxID_FILE1
+m_fileHistoryN
, _("[EMPTY]"));
1873 node
= node
->Next();
1877 // Shuffle filenames down
1878 for (i
= (m_fileHistoryN
-1); i
> 0; i
--)
1880 m_fileHistory
[i
] = m_fileHistory
[i
-1];
1882 m_fileHistory
[0] = copystring(file
);
1884 for (i
= 0; i
< m_fileHistoryN
; i
++)
1885 if (m_fileHistory
[i
])
1888 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
1889 wxNode
* node
= m_fileMenus
.First();
1892 wxMenu
* menu
= (wxMenu
*) node
->Data();
1893 menu
->SetLabel(wxID_FILE1
+i
, buf
);
1894 node
= node
->Next();
1899 void wxFileHistory::RemoveFileFromHistory(int i
)
1901 wxCHECK_RET( i
< m_fileHistoryN
,
1902 _T("invalid index in wxFileHistory::RemoveFileFromHistory") );
1904 wxNode
* node
= m_fileMenus
.First();
1907 wxMenu
* menu
= (wxMenu
*) node
->Data();
1909 // wxMenu::Delete() is missing from wxGTK, so this can't be done :-(
1911 // delete the menu items
1912 menu
->Delete(wxID_FILE1
+ i
);
1915 // delete the element from the array (could use memmove() too...)
1916 delete [] m_fileHistory
[i
];
1919 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1921 m_fileHistory
[j
] = m_fileHistory
[j
+ 1];
1924 // shuffle filenames up
1926 for ( j
= i
; j
< m_fileHistoryN
- 1; j
++ )
1928 buf
.Printf(s_MRUEntryFormat
, j
+ 1, m_fileHistory
[j
]);
1929 menu
->SetLabel(wxID_FILE1
+ j
, buf
);
1932 // to be removed as soon as wxMenu::Delete() is implemented
1934 menu
->SetLabel(wxID_FILE1
+ m_fileHistoryN
- 1, _T(""));
1937 node
= node
->Next();
1942 wxString
wxFileHistory::GetHistoryFile(int i
) const
1944 if (i
< m_fileHistoryN
)
1945 return wxString(m_fileHistory
[i
]);
1947 return wxString("");
1950 void wxFileHistory::UseMenu(wxMenu
*menu
)
1952 if (!m_fileMenus
.Member(menu
))
1953 m_fileMenus
.Append(menu
);
1956 void wxFileHistory::RemoveMenu(wxMenu
*menu
)
1958 m_fileMenus
.DeleteObject(menu
);
1962 void wxFileHistory::Load(wxConfigBase
& config
)
1966 buf
.Printf(_T("file%d"), m_fileHistoryN
+1);
1967 wxString historyFile
;
1968 while ((m_fileHistoryN
<= m_fileMaxFiles
) && config
.Read(buf
, &historyFile
) && (historyFile
!= _T("")))
1970 m_fileHistory
[m_fileHistoryN
] = copystring((const wxChar
*) historyFile
);
1972 buf
.Printf(_T("file%d"), m_fileHistoryN
+1);
1978 void wxFileHistory::Save(wxConfigBase
& config
)
1981 for (i
= 0; i
< m_fileHistoryN
; i
++)
1984 buf
.Printf(_T("file%d"), i
+1);
1985 config
.Write(buf
, wxString(m_fileHistory
[i
]));
1988 #endif // wxUSE_CONFIG
1990 void wxFileHistory::AddFilesToMenu()
1992 if (m_fileHistoryN
> 0)
1994 wxNode
* node
= m_fileMenus
.First();
1997 wxMenu
* menu
= (wxMenu
*) node
->Data();
1998 menu
->AppendSeparator();
2000 for (i
= 0; i
< m_fileHistoryN
; i
++)
2002 if (m_fileHistory
[i
])
2005 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2006 menu
->Append(wxID_FILE1
+i
, buf
);
2009 node
= node
->Next();
2014 void wxFileHistory::AddFilesToMenu(wxMenu
* menu
)
2016 if (m_fileHistoryN
> 0)
2018 menu
->AppendSeparator();
2020 for (i
= 0; i
< m_fileHistoryN
; i
++)
2022 if (m_fileHistory
[i
])
2025 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2026 menu
->Append(wxID_FILE1
+i
, buf
);
2032 // ----------------------------------------------------------------------------
2033 // Permits compatibility with existing file formats and functions that
2034 // manipulate files directly
2035 // ----------------------------------------------------------------------------
2037 #if wxUSE_STD_IOSTREAM
2038 bool wxTransferFileToStream(const wxString
& filename
, ostream
& stream
)
2043 if ((fd1
= fopen (filename
.fn_str(), "rb")) == NULL
)
2046 while ((ch
= getc (fd1
)) != EOF
)
2047 stream
<< (unsigned char)ch
;
2053 bool wxTransferStreamToFile(istream
& stream
, const wxString
& filename
)
2058 if ((fd1
= fopen (filename
.fn_str(), "wb")) == NULL
)
2063 while (!stream
.eof())
2074 #endif // wxUSE_DOC_VIEW_ARCHITECTURE