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 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
)
94 // ----------------------------------------------------------------------------
95 // function prototypes
96 // ----------------------------------------------------------------------------
98 static inline wxString
FindExtension(const wxChar
*path
);
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 static const wxChar
*s_MRUEntryFormat
= wxT("&%d %s");
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 static wxString
FindExtension(const wxChar
*path
)
117 wxSplitPath(path
, NULL
, NULL
, &ext
);
119 // VZ: extensions are considered not case sensitive - is this really a good
121 return ext
.MakeLower();
124 // ----------------------------------------------------------------------------
125 // Definition of wxDocument
126 // ----------------------------------------------------------------------------
128 wxDocument::wxDocument(wxDocument
*parent
)
130 m_documentModified
= FALSE
;
131 m_documentParent
= parent
;
132 m_documentTemplate
= (wxDocTemplate
*) NULL
;
136 bool wxDocument::DeleteContents()
141 wxDocument::~wxDocument()
145 if (m_commandProcessor
)
146 delete m_commandProcessor
;
148 GetDocumentManager()->RemoveDocument(this);
150 // Not safe to do here, since it'll invoke virtual view functions
151 // expecting to see valid derived objects: and by the time we get here,
152 // we've called destructors higher up.
156 bool wxDocument::Close()
158 if (OnSaveModified())
159 return OnCloseDocument();
164 bool wxDocument::OnCloseDocument()
171 // Note that this implicitly deletes the document when the last view is
173 bool wxDocument::DeleteAllViews()
175 wxNode
*node
= m_documentViews
.First();
178 wxView
*view
= (wxView
*)node
->Data();
182 wxNode
*next
= node
->Next();
184 delete view
; // Deletes node implicitly
190 wxView
*wxDocument::GetFirstView() const
192 if (m_documentViews
.Number() == 0)
193 return (wxView
*) NULL
;
194 return (wxView
*)m_documentViews
.First()->Data();
197 wxDocManager
*wxDocument::GetDocumentManager() const
199 return m_documentTemplate
->GetDocumentManager();
202 bool wxDocument::OnNewDocument()
204 if (!OnSaveModified())
207 if (OnCloseDocument()==FALSE
) return FALSE
;
210 SetDocumentSaved(FALSE
);
213 GetDocumentManager()->MakeDefaultName(name
);
215 SetFilename(name
, TRUE
);
220 bool wxDocument::Save()
224 if (!IsModified()) return TRUE
;
225 if (m_documentFile
== wxT("") || !m_savedYet
)
228 ret
= OnSaveDocument(m_documentFile
);
230 SetDocumentSaved(TRUE
);
234 bool wxDocument::SaveAs()
236 wxDocTemplate
*docTemplate
= GetDocumentTemplate();
240 wxString tmp
= wxFileSelector(_("Save as"),
241 docTemplate
->GetDirectory(),
243 docTemplate
->GetDefaultExtension(),
244 docTemplate
->GetFileFilter(),
245 wxSAVE
| wxOVERWRITE_PROMPT
,
246 GetDocumentWindow());
251 wxString
fileName(tmp
);
252 wxString path
, name
, ext
;
253 wxSplitPath(fileName
, & path
, & name
, & ext
);
255 if (ext
.IsEmpty() || ext
== wxT(""))
258 fileName
+= docTemplate
->GetDefaultExtension();
261 SetFilename(fileName
);
262 SetTitle(wxFileNameFromPath(fileName
));
264 GetDocumentManager()->AddFileToHistory(fileName
);
266 // Notify the views that the filename has changed
267 wxNode
*node
= m_documentViews
.First();
270 wxView
*view
= (wxView
*)node
->Data();
271 view
->OnChangeFilename();
275 return OnSaveDocument(m_documentFile
);
278 bool wxDocument::OnSaveDocument(const wxString
& file
)
284 if (wxTheApp
->GetAppName() != wxT(""))
285 msgTitle
= wxTheApp
->GetAppName();
287 msgTitle
= wxString(_("File error"));
289 #if wxUSE_STD_IOSTREAM
290 ofstream
store(wxString(file
.fn_str()));
291 if (store
.fail() || store
.bad())
293 wxFileOutputStream
store(wxString(file
.fn_str()));
294 if (store
.LastError() != wxSTREAM_NOERROR
)
297 (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
298 GetDocumentWindow());
302 if (!SaveObject(store
))
304 (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle
, wxOK
| wxICON_EXCLAMATION
,
305 GetDocumentWindow());
314 bool wxDocument::OnOpenDocument(const wxString
& file
)
316 if (!OnSaveModified())
320 if (wxTheApp
->GetAppName() != wxT(""))
321 msgTitle
= wxTheApp
->GetAppName();
323 msgTitle
= wxString(_("File error"));
325 #if wxUSE_STD_IOSTREAM
326 ifstream
store(wxString(file
.fn_str()));
327 if (store
.fail() || store
.bad())
329 wxFileInputStream
store(wxString(file
.fn_str()));
330 if (store
.LastError() != wxSTREAM_NOERROR
)
333 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
334 GetDocumentWindow());
337 #if wxUSE_STD_IOSTREAM
338 if (!LoadObject(store
))
340 int res
= LoadObject(store
).LastError();
341 if ((res
!= wxSTREAM_NOERROR
) &&
342 (res
!= wxSTREAM_EOF
))
345 (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle
, wxOK
|wxICON_EXCLAMATION
,
346 GetDocumentWindow());
349 SetFilename(file
, TRUE
);
358 #if wxUSE_STD_IOSTREAM
359 istream
& wxDocument::LoadObject(istream
& stream
)
361 wxInputStream
& wxDocument::LoadObject(wxInputStream
& stream
)
367 #if wxUSE_STD_IOSTREAM
368 ostream
& wxDocument::SaveObject(ostream
& stream
)
370 wxOutputStream
& wxDocument::SaveObject(wxOutputStream
& stream
)
376 bool wxDocument::Revert()
382 // Get title, or filename if no title, else unnamed
383 bool wxDocument::GetPrintableName(wxString
& buf
) const
385 if (m_documentTitle
!= wxT(""))
387 buf
= m_documentTitle
;
390 else if (m_documentFile
!= wxT(""))
392 buf
= wxFileNameFromPath(m_documentFile
);
402 wxWindow
*wxDocument::GetDocumentWindow() const
404 wxView
*view
= GetFirstView();
406 return view
->GetFrame();
408 return wxTheApp
->GetTopWindow();
411 wxCommandProcessor
*wxDocument::OnCreateCommandProcessor()
413 return new wxCommandProcessor
;
416 // TRUE if safe to close
417 bool wxDocument::OnSaveModified()
422 GetPrintableName(title
);
425 if (wxTheApp
->GetAppName() != wxT(""))
426 msgTitle
= wxTheApp
->GetAppName();
428 msgTitle
= wxString(_("Warning"));
431 prompt
.Printf(_("Do you want to save changes to document %s?"),
432 (const wxChar
*)title
);
433 int res
= wxMessageBox(prompt
, msgTitle
,
434 wxYES_NO
|wxCANCEL
|wxICON_QUESTION
,
435 GetDocumentWindow());
441 else if (res
== wxYES
)
443 else if (res
== wxCANCEL
)
449 bool wxDocument::Draw(wxDC
& WXUNUSED(context
))
454 bool wxDocument::AddView(wxView
*view
)
456 if (!m_documentViews
.Member(view
))
458 m_documentViews
.Append(view
);
464 bool wxDocument::RemoveView(wxView
*view
)
466 (void)m_documentViews
.DeleteObject(view
);
471 bool wxDocument::OnCreate(const wxString
& WXUNUSED(path
), long flags
)
473 if (GetDocumentTemplate()->CreateView(this, flags
))
479 // Called after a view is added or removed.
480 // The default implementation deletes the document if
481 // there are no more views.
482 void wxDocument::OnChangedViewList()
484 if (m_documentViews
.Number() == 0)
486 if (OnSaveModified())
493 void wxDocument::UpdateAllViews(wxView
*sender
, wxObject
*hint
)
495 wxNode
*node
= m_documentViews
.First();
498 wxView
*view
= (wxView
*)node
->Data();
499 view
->OnUpdate(sender
, hint
);
504 void wxDocument::SetFilename(const wxString
& filename
, bool notifyViews
)
506 m_documentFile
= filename
;
509 // Notify the views that the filename has changed
510 wxNode
*node
= m_documentViews
.First();
513 wxView
*view
= (wxView
*)node
->Data();
514 view
->OnChangeFilename();
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
527 m_viewDocument
= (wxDocument
*) NULL
;
529 m_viewTypeName
= wxT("");
530 m_viewFrame
= (wxFrame
*) NULL
;
535 // GetDocumentManager()->ActivateView(this, FALSE, TRUE);
536 m_viewDocument
->RemoveView(this);
539 // Extend event processing to search the document's event table
540 bool wxView::ProcessEvent(wxEvent
& event
)
542 if ( !GetDocument() || !GetDocument()->ProcessEvent(event
) )
543 return wxEvtHandler::ProcessEvent(event
);
548 void wxView::OnActivateView(bool WXUNUSED(activate
), wxView
*WXUNUSED(activeView
), wxView
*WXUNUSED(deactiveView
))
552 void wxView::OnPrint(wxDC
*dc
, wxObject
*WXUNUSED(info
))
557 void wxView::OnUpdate(wxView
*WXUNUSED(sender
), wxObject
*WXUNUSED(hint
))
561 void wxView::OnChangeFilename()
563 if (GetFrame() && GetDocument())
566 GetDocument()->GetPrintableName(name
);
568 GetFrame()->SetTitle(name
);
572 void wxView::SetDocument(wxDocument
*doc
)
574 m_viewDocument
= doc
;
579 bool wxView::Close(bool deleteWindow
)
581 if (OnClose(deleteWindow
))
587 void wxView::Activate(bool activate
)
589 if (GetDocumentManager())
591 OnActivateView(activate
, this, GetDocumentManager()->GetCurrentView());
592 GetDocumentManager()->ActivateView(this, activate
);
596 bool wxView::OnClose(bool WXUNUSED(deleteWindow
))
598 return GetDocument() ? GetDocument()->Close() : TRUE
;
601 #if wxUSE_PRINTING_ARCHITECTURE
602 wxPrintout
*wxView::OnCreatePrintout()
604 return new wxDocPrintout(this);
606 #endif // wxUSE_PRINTING_ARCHITECTURE
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
612 wxDocTemplate::wxDocTemplate(wxDocManager
*manager
,
613 const wxString
& descr
,
614 const wxString
& filter
,
617 const wxString
& docTypeName
,
618 const wxString
& viewTypeName
,
619 wxClassInfo
*docClassInfo
,
620 wxClassInfo
*viewClassInfo
,
623 m_documentManager
= manager
;
624 m_description
= descr
;
627 m_fileFilter
= filter
;
629 m_docTypeName
= docTypeName
;
630 m_viewTypeName
= viewTypeName
;
631 m_documentManager
->AssociateTemplate(this);
633 m_docClassInfo
= docClassInfo
;
634 m_viewClassInfo
= viewClassInfo
;
637 wxDocTemplate::~wxDocTemplate()
639 m_documentManager
->DisassociateTemplate(this);
642 // Tries to dynamically construct an object of the right class.
643 wxDocument
*wxDocTemplate::CreateDocument(const wxString
& path
, long flags
)
646 return (wxDocument
*) NULL
;
647 wxDocument
*doc
= (wxDocument
*)m_docClassInfo
->CreateObject();
648 doc
->SetFilename(path
);
649 doc
->SetDocumentTemplate(this);
650 GetDocumentManager()->AddDocument(doc
);
651 doc
->SetCommandProcessor(doc
->OnCreateCommandProcessor());
653 if (doc
->OnCreate(path
, flags
))
658 return (wxDocument
*) NULL
;
662 wxView
*wxDocTemplate::CreateView(wxDocument
*doc
, long flags
)
664 if (!m_viewClassInfo
)
665 return (wxView
*) NULL
;
666 wxView
*view
= (wxView
*)m_viewClassInfo
->CreateObject();
667 view
->SetDocument(doc
);
668 if (view
->OnCreate(doc
, flags
))
675 return (wxView
*) NULL
;
679 // The default (very primitive) format detection: check is the extension is
680 // that of the template
681 bool wxDocTemplate::FileMatchesTemplate(const wxString
& path
)
683 return GetDefaultExtension().IsSameAs(FindExtension(path
));
686 // ----------------------------------------------------------------------------
688 // ----------------------------------------------------------------------------
690 BEGIN_EVENT_TABLE(wxDocManager
, wxEvtHandler
)
691 EVT_MENU(wxID_OPEN
, wxDocManager::OnFileOpen
)
692 EVT_MENU(wxID_CLOSE
, wxDocManager::OnFileClose
)
693 EVT_MENU(wxID_REVERT
, wxDocManager::OnFileRevert
)
694 EVT_MENU(wxID_NEW
, wxDocManager::OnFileNew
)
695 EVT_MENU(wxID_SAVE
, wxDocManager::OnFileSave
)
696 EVT_MENU(wxID_SAVEAS
, wxDocManager::OnFileSaveAs
)
697 EVT_MENU(wxID_UNDO
, wxDocManager::OnUndo
)
698 EVT_MENU(wxID_REDO
, wxDocManager::OnRedo
)
699 #if wxUSE_PRINTING_ARCHITECTURE
700 EVT_MENU(wxID_PRINT
, wxDocManager::OnPrint
)
701 EVT_MENU(wxID_PRINT_SETUP
, wxDocManager::OnPrintSetup
)
702 EVT_MENU(wxID_PREVIEW
, wxDocManager::OnPreview
)
706 wxDocManager::wxDocManager(long flags
, bool initialize
)
708 m_defaultDocumentNameCounter
= 1;
710 m_currentView
= (wxView
*) NULL
;
711 m_maxDocsOpen
= 10000;
712 m_fileHistory
= (wxFileHistory
*) NULL
;
717 wxDocManager::~wxDocManager()
721 delete m_fileHistory
;
724 bool wxDocManager::Clear(bool force
)
726 wxNode
*node
= m_docs
.First();
729 wxDocument
*doc
= (wxDocument
*)node
->Data();
730 wxNode
*next
= node
->Next();
732 if (!doc
->Close() && !force
)
735 // Implicitly deletes the document when the last
736 // view is removed (deleted)
737 doc
->DeleteAllViews();
739 // Check document is deleted
740 if (m_docs
.Member(doc
))
743 // This assumes that documents are not connected in
744 // any way, i.e. deleting one document does NOT
748 node
= m_templates
.First();
751 wxDocTemplate
*templ
= (wxDocTemplate
*) node
->Data();
752 wxNode
* next
= node
->Next();
759 bool wxDocManager::Initialize()
761 m_fileHistory
= OnCreateFileHistory();
765 wxFileHistory
*wxDocManager::OnCreateFileHistory()
767 return new wxFileHistory
;
770 void wxDocManager::OnFileClose(wxCommandEvent
& WXUNUSED(event
))
772 wxDocument
*doc
= GetCurrentDocument();
777 doc
->DeleteAllViews();
778 if (m_docs
.Member(doc
))
783 void wxDocManager::OnFileNew(wxCommandEvent
& WXUNUSED(event
))
785 CreateDocument(wxString(""), wxDOC_NEW
);
788 void wxDocManager::OnFileOpen(wxCommandEvent
& WXUNUSED(event
))
790 CreateDocument(wxString(""), 0);
793 void wxDocManager::OnFileRevert(wxCommandEvent
& WXUNUSED(event
))
795 wxDocument
*doc
= GetCurrentDocument();
801 void wxDocManager::OnFileSave(wxCommandEvent
& WXUNUSED(event
))
803 wxDocument
*doc
= GetCurrentDocument();
809 void wxDocManager::OnFileSaveAs(wxCommandEvent
& WXUNUSED(event
))
811 wxDocument
*doc
= GetCurrentDocument();
817 void wxDocManager::OnPrint(wxCommandEvent
& WXUNUSED(event
))
819 #if wxUSE_PRINTING_ARCHITECTURE
820 wxView
*view
= GetCurrentView();
824 wxPrintout
*printout
= view
->OnCreatePrintout();
828 printer
.Print(view
->GetFrame(), printout
, TRUE
);
832 #endif // wxUSE_PRINTING_ARCHITECTURE
835 void wxDocManager::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
837 #if wxUSE_PRINTING_ARCHITECTURE
838 wxWindow
*parentWin
= wxTheApp
->GetTopWindow();
839 wxView
*view
= GetCurrentView();
841 parentWin
= view
->GetFrame();
843 wxPrintDialogData data
;
845 wxPrintDialog
printerDialog(parentWin
, &data
);
846 printerDialog
.GetPrintDialogData().SetSetupDialog(TRUE
);
847 printerDialog
.ShowModal();
848 #endif // wxUSE_PRINTING_ARCHITECTURE
851 void wxDocManager::OnPreview(wxCommandEvent
& WXUNUSED(event
))
853 #if wxUSE_PRINTING_ARCHITECTURE
854 wxView
*view
= GetCurrentView();
858 wxPrintout
*printout
= view
->OnCreatePrintout();
861 // Pass two printout objects: for preview, and possible printing.
862 wxPrintPreviewBase
*preview
= (wxPrintPreviewBase
*) NULL
;
863 preview
= new wxPrintPreview(printout
, view
->OnCreatePrintout());
865 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, (wxFrame
*)wxTheApp
->GetTopWindow(), _("Print Preview"),
866 wxPoint(100, 100), wxSize(600, 650));
867 frame
->Centre(wxBOTH
);
871 #endif // wxUSE_PRINTING_ARCHITECTURE
874 void wxDocManager::OnUndo(wxCommandEvent
& WXUNUSED(event
))
876 wxDocument
*doc
= GetCurrentDocument();
879 if (doc
->GetCommandProcessor())
880 doc
->GetCommandProcessor()->Undo();
883 void wxDocManager::OnRedo(wxCommandEvent
& WXUNUSED(event
))
885 wxDocument
*doc
= GetCurrentDocument();
888 if (doc
->GetCommandProcessor())
889 doc
->GetCommandProcessor()->Redo();
892 wxView
*wxDocManager::GetCurrentView() const
895 return m_currentView
;
896 if (m_docs
.Number() == 1)
898 wxDocument
* doc
= (wxDocument
*) m_docs
.First()->Data();
899 return doc
->GetFirstView();
901 return (wxView
*) NULL
;
904 // Extend event processing to search the view's event table
905 bool wxDocManager::ProcessEvent(wxEvent
& event
)
907 wxView
* view
= GetCurrentView();
910 if (view
->ProcessEvent(event
))
913 return wxEvtHandler::ProcessEvent(event
);
916 wxDocument
*wxDocManager::CreateDocument(const wxString
& path
, long flags
)
918 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
921 for (i
= 0; i
< m_templates
.Number(); i
++)
923 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
924 if (temp
->IsVisible())
933 return (wxDocument
*) NULL
;
936 // If we've reached the max number of docs, close the
938 if (GetDocuments().Number() >= m_maxDocsOpen
)
940 wxDocument
*doc
= (wxDocument
*)GetDocuments().First()->Data();
943 // Implicitly deletes the document when
944 // the last view is deleted
945 doc
->DeleteAllViews();
947 // Check we're really deleted
948 if (m_docs
.Member(doc
))
952 return (wxDocument
*) NULL
;
955 // New document: user chooses a template, unless there's only one.
956 if (flags
& wxDOC_NEW
)
960 wxDocTemplate
*temp
= templates
[0];
962 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
965 newDoc
->SetDocumentName(temp
->GetDocumentName());
966 newDoc
->SetDocumentTemplate(temp
);
967 newDoc
->OnNewDocument();
972 wxDocTemplate
*temp
= SelectDocumentType(templates
, n
);
976 wxDocument
*newDoc
= temp
->CreateDocument(path
, flags
);
979 newDoc
->SetDocumentName(temp
->GetDocumentName());
980 newDoc
->SetDocumentTemplate(temp
);
981 newDoc
->OnNewDocument();
986 return (wxDocument
*) NULL
;
990 wxDocTemplate
*temp
= (wxDocTemplate
*) NULL
;
992 wxString
path2(wxT(""));
996 if (flags
& wxDOC_SILENT
)
997 temp
= FindTemplateForPath(path2
);
999 temp
= SelectDocumentPath(templates
, n
, path2
, flags
);
1005 wxDocument
*newDoc
= temp
->CreateDocument(path2
, flags
);
1008 newDoc
->SetDocumentName(temp
->GetDocumentName());
1009 newDoc
->SetDocumentTemplate(temp
);
1010 if (!newDoc
->OnOpenDocument(path2
))
1013 return (wxDocument
*) NULL
;
1015 AddFileToHistory(path2
);
1020 return (wxDocument
*) NULL
;
1023 wxView
*wxDocManager::CreateView(wxDocument
*doc
, long flags
)
1025 wxDocTemplate
**templates
= new wxDocTemplate
*[m_templates
.Number()];
1028 for (i
= 0; i
< m_templates
.Number(); i
++)
1030 wxDocTemplate
*temp
= (wxDocTemplate
*)(m_templates
.Nth(i
)->Data());
1031 if (temp
->IsVisible())
1033 if (temp
->GetDocumentName() == doc
->GetDocumentName())
1035 templates
[n
] = temp
;
1043 return (wxView
*) NULL
;
1047 wxDocTemplate
*temp
= templates
[0];
1049 wxView
*view
= temp
->CreateView(doc
, flags
);
1051 view
->SetViewName(temp
->GetViewName());
1055 wxDocTemplate
*temp
= SelectViewType(templates
, n
);
1059 wxView
*view
= temp
->CreateView(doc
, flags
);
1061 view
->SetViewName(temp
->GetViewName());
1065 return (wxView
*) NULL
;
1068 // Not yet implemented
1069 void wxDocManager::DeleteTemplate(wxDocTemplate
*WXUNUSED(temp
), long WXUNUSED(flags
))
1073 // Not yet implemented
1074 bool wxDocManager::FlushDoc(wxDocument
*WXUNUSED(doc
))
1079 wxDocument
*wxDocManager::GetCurrentDocument() const
1082 return m_currentView
->GetDocument();
1084 return (wxDocument
*) NULL
;
1087 // Make a default document name
1088 bool wxDocManager::MakeDefaultName(wxString
& name
)
1090 name
.Printf(_("unnamed%d"), m_defaultDocumentNameCounter
);
1091 m_defaultDocumentNameCounter
++;
1096 // Not yet implemented
1097 wxDocTemplate
*wxDocManager::MatchTemplate(const wxString
& WXUNUSED(path
))
1099 return (wxDocTemplate
*) NULL
;
1102 // File history management
1103 void wxDocManager::AddFileToHistory(const wxString
& file
)
1106 m_fileHistory
->AddFileToHistory(file
);
1109 void wxDocManager::RemoveFileFromHistory(int i
)
1112 m_fileHistory
->RemoveFileFromHistory(i
);
1115 wxString
wxDocManager::GetHistoryFile(int i
) const
1120 histFile
= m_fileHistory
->GetHistoryFile(i
);
1125 void wxDocManager::FileHistoryUseMenu(wxMenu
*menu
)
1128 m_fileHistory
->UseMenu(menu
);
1131 void wxDocManager::FileHistoryRemoveMenu(wxMenu
*menu
)
1134 m_fileHistory
->RemoveMenu(menu
);
1138 void wxDocManager::FileHistoryLoad(wxConfigBase
& config
)
1141 m_fileHistory
->Load(config
);
1144 void wxDocManager::FileHistorySave(wxConfigBase
& config
)
1147 m_fileHistory
->Save(config
);
1151 void wxDocManager::FileHistoryAddFilesToMenu(wxMenu
* menu
)
1154 m_fileHistory
->AddFilesToMenu(menu
);
1157 void wxDocManager::FileHistoryAddFilesToMenu()
1160 m_fileHistory
->AddFilesToMenu();
1163 int wxDocManager::GetNoHistoryFiles() const
1166 return m_fileHistory
->GetNoHistoryFiles();
1172 // Find out the document template via matching in the document file format
1173 // against that of the template
1174 wxDocTemplate
*wxDocManager::FindTemplateForPath(const wxString
& path
)
1176 wxDocTemplate
*theTemplate
= (wxDocTemplate
*) NULL
;
1178 // Find the template which this extension corresponds to
1180 for (i
= 0; i
< m_templates
.Number(); i
++)
1182 wxDocTemplate
*temp
= (wxDocTemplate
*)m_templates
.Nth(i
)->Data();
1183 if ( temp
->FileMatchesTemplate(path
) )
1192 // Prompts user to open a file, using file specs in templates.
1193 // How to implement in wxWindows? Must extend the file selector
1194 // dialog or implement own; OR match the extension to the
1195 // template extension.
1197 wxDocTemplate
*wxDocManager::SelectDocumentPath(wxDocTemplate
**templates
,
1198 #if defined(__WXMSW__) || defined(__WXGTK__)
1201 int WXUNUSED(noTemplates
),
1204 long WXUNUSED(flags
),
1205 bool WXUNUSED(save
))
1207 // We can only have multiple filters in Windows and GTK
1208 #if defined(__WXMSW__) || defined(__WXGTK__)
1212 for (i
= 0; i
< noTemplates
; i
++)
1214 if (templates
[i
]->IsVisible())
1216 // add a '|' to separate this filter from the previous one
1217 if ( !descrBuf
.IsEmpty() )
1218 descrBuf
<< wxT('|');
1220 descrBuf
<< templates
[i
]->GetDescription()
1221 << wxT(" (") << templates
[i
]->GetFileFilter() << wxT(") |")
1222 << templates
[i
]->GetFileFilter();
1226 wxString descrBuf
= wxT("*.*");
1229 int FilterIndex
= 0;
1230 wxString pathTmp
= wxFileSelectorEx(_("Select a file"),
1236 wxTheApp
->GetTopWindow());
1238 if (!pathTmp
.IsEmpty())
1240 m_lastDirectory
= wxPathOnly(pathTmp
);
1243 wxString theExt
= FindExtension(path
);
1245 return (wxDocTemplate
*) NULL
;
1247 // This is dodgy in that we're selecting the template on the
1248 // basis of the file extension, which may not be a standard
1249 // one. We really want to know exactly which template was
1250 // chosen by using a more advanced file selector.
1251 wxDocTemplate
*theTemplate
= FindTemplateForPath(path
);
1253 theTemplate
= templates
[FilterIndex
];
1260 return (wxDocTemplate
*) NULL
;
1263 // In all other windowing systems, until we have more advanced
1264 // file selectors, we must select the document type (template) first, and
1265 // _then_ pop up the file selector.
1266 wxDocTemplate
*temp
= SelectDocumentType(templates
, noTemplates
);
1268 return (wxDocTemplate
*) NULL
;
1270 wxChar
*pathTmp
= wxFileSelector(_("Select a file"), wxT(""), wxT(""),
1271 temp
->GetDefaultExtension(),
1272 temp
->GetFileFilter(),
1273 0, wxTheApp
->GetTopWindow());
1281 return (wxDocTemplate
*) NULL
;
1285 wxDocTemplate
*wxDocManager::SelectDocumentType(wxDocTemplate
**templates
,
1288 wxChar
**strings
= new wxChar
*[noTemplates
];
1289 wxChar
**data
= new wxChar
*[noTemplates
];
1292 for (i
= 0; i
< noTemplates
; i
++)
1294 if (templates
[i
]->IsVisible())
1296 strings
[n
] = (wxChar
*)templates
[i
]->m_description
.c_str();
1297 data
[n
] = (wxChar
*)templates
[i
];
1305 return (wxDocTemplate
*) NULL
;
1309 wxDocTemplate
*temp
= (wxDocTemplate
*)data
[0];
1315 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n
,
1316 strings
, (void **)data
);
1322 wxDocTemplate
*wxDocManager::SelectViewType(wxDocTemplate
**templates
,
1325 wxChar
**strings
= new wxChar
*[noTemplates
];
1326 wxChar
**data
= new wxChar
*[noTemplates
];
1329 for (i
= 0; i
< noTemplates
; i
++)
1331 if (templates
[i
]->IsVisible() && (templates
[i
]->GetViewName() != wxT("")))
1333 strings
[n
] = (wxChar
*)templates
[i
]->m_viewTypeName
.c_str();
1334 data
[n
] = (wxChar
*)templates
[i
];
1338 wxDocTemplate
*theTemplate
= (wxDocTemplate
*)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n
,
1339 strings
, (void **)data
);
1345 void wxDocManager::AssociateTemplate(wxDocTemplate
*temp
)
1347 if (!m_templates
.Member(temp
))
1348 m_templates
.Append(temp
);
1351 void wxDocManager::DisassociateTemplate(wxDocTemplate
*temp
)
1353 m_templates
.DeleteObject(temp
);
1356 // Add and remove a document from the manager's list
1357 void wxDocManager::AddDocument(wxDocument
*doc
)
1359 if (!m_docs
.Member(doc
))
1363 void wxDocManager::RemoveDocument(wxDocument
*doc
)
1365 m_docs
.DeleteObject(doc
);
1368 // Views or windows should inform the document manager
1369 // when a view is going in or out of focus
1370 void wxDocManager::ActivateView(wxView
*view
, bool activate
, bool WXUNUSED(deleting
))
1372 // If we're deactiving, and if we're not actually deleting the view, then
1373 // don't reset the current view because we may be going to
1374 // a window without a view.
1375 // WHAT DID I MEAN BY THAT EXACTLY?
1379 if (m_currentView == view)
1380 m_currentView = NULL;
1386 m_currentView
= view
;
1388 m_currentView
= (wxView
*) NULL
;
1392 // ----------------------------------------------------------------------------
1393 // Default document child frame
1394 // ----------------------------------------------------------------------------
1396 BEGIN_EVENT_TABLE(wxDocChildFrame
, wxFrame
)
1397 EVT_ACTIVATE(wxDocChildFrame::OnActivate
)
1398 EVT_CLOSE(wxDocChildFrame::OnCloseWindow
)
1401 wxDocChildFrame::wxDocChildFrame(wxDocument
*doc
,
1405 const wxString
& title
,
1409 const wxString
& name
)
1410 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1412 m_childDocument
= doc
;
1415 view
->SetFrame(this);
1418 wxDocChildFrame::~wxDocChildFrame()
1422 // Extend event processing to search the view's event table
1423 bool wxDocChildFrame::ProcessEvent(wxEvent
& event
)
1426 m_childView
->Activate(TRUE
);
1428 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
1430 // Only hand up to the parent if it's a menu command
1431 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
1432 return wxEvtHandler::ProcessEvent(event
);
1440 void wxDocChildFrame::OnActivate(wxActivateEvent
& event
)
1442 wxFrame::OnActivate(event
);
1445 m_childView
->Activate(event
.GetActive());
1448 void wxDocChildFrame::OnCloseWindow(wxCloseEvent
& event
)
1453 if (!event
.CanVeto())
1454 ans
= TRUE
; // Must delete.
1456 ans
= m_childView
->Close(FALSE
); // FALSE means don't delete associated window
1460 m_childView
->Activate(FALSE
);
1462 m_childView
= (wxView
*) NULL
;
1463 m_childDocument
= (wxDocument
*) NULL
;
1474 // ----------------------------------------------------------------------------
1475 // Default parent frame
1476 // ----------------------------------------------------------------------------
1478 BEGIN_EVENT_TABLE(wxDocParentFrame
, wxFrame
)
1479 EVT_MENU(wxID_EXIT
, wxDocParentFrame::OnExit
)
1480 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocParentFrame::OnMRUFile
)
1481 EVT_CLOSE(wxDocParentFrame::OnCloseWindow
)
1484 wxDocParentFrame::wxDocParentFrame(wxDocManager
*manager
,
1487 const wxString
& title
,
1491 const wxString
& name
)
1492 : wxFrame(frame
, id
, title
, pos
, size
, style
, name
)
1494 m_docManager
= manager
;
1497 void wxDocParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
1502 void wxDocParentFrame::OnMRUFile(wxCommandEvent
& event
)
1504 int n
= event
.GetSelection() - wxID_FILE1
; // the index in MRU list
1505 wxString
filename(m_docManager
->GetHistoryFile(n
));
1506 if ( !filename
.IsEmpty() )
1508 // verify that the file exists before doing anything else
1509 if ( wxFile::Exists(filename
) )
1512 (void)m_docManager
->CreateDocument(filename
, wxDOC_SILENT
);
1516 // remove the bogus filename from the MRU list and notify the user
1518 m_docManager
->RemoveFileFromHistory(n
);
1520 wxLogError(_("The file '%s' doesn't exist and couldn't be opened.\n"
1521 "It has been also removed from the MRU files list."),
1527 // Extend event processing to search the view's event table
1528 bool wxDocParentFrame::ProcessEvent(wxEvent
& event
)
1530 // Try the document manager, then do default processing
1531 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
1532 return wxEvtHandler::ProcessEvent(event
);
1537 // Define the behaviour for the frame closing
1538 // - must delete all frames except for the main one.
1539 void wxDocParentFrame::OnCloseWindow(wxCloseEvent
& event
)
1541 if (m_docManager
->Clear(!event
.CanVeto()))
1549 #if wxUSE_PRINTING_ARCHITECTURE
1551 wxDocPrintout::wxDocPrintout(wxView
*view
, const wxString
& title
)
1554 m_printoutView
= view
;
1557 bool wxDocPrintout::OnPrintPage(int WXUNUSED(page
))
1561 // Get the logical pixels per inch of screen and printer
1562 int ppiScreenX
, ppiScreenY
;
1563 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
1564 int ppiPrinterX
, ppiPrinterY
;
1565 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
1567 // This scales the DC so that the printout roughly represents the
1568 // the screen scaling. The text point size _should_ be the right size
1569 // but in fact is too small for some reason. This is a detail that will
1570 // need to be addressed at some point but can be fudged for the
1572 float scale
= (float)((float)ppiPrinterX
/(float)ppiScreenX
);
1574 // Now we have to check in case our real page size is reduced
1575 // (e.g. because we're drawing to a print preview memory DC)
1576 int pageWidth
, pageHeight
;
1578 dc
->GetSize(&w
, &h
);
1579 GetPageSizePixels(&pageWidth
, &pageHeight
);
1581 // If printer pageWidth == current DC width, then this doesn't
1582 // change. But w might be the preview bitmap width, so scale down.
1583 float overallScale
= scale
* (float)(w
/(float)pageWidth
);
1584 dc
->SetUserScale(overallScale
, overallScale
);
1588 m_printoutView
->OnDraw(dc
);
1593 bool wxDocPrintout::HasPage(int pageNum
)
1595 return (pageNum
== 1);
1598 bool wxDocPrintout::OnBeginDocument(int startPage
, int endPage
)
1600 if (!wxPrintout::OnBeginDocument(startPage
, endPage
))
1606 void wxDocPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
1614 #endif // wxUSE_PRINTING_ARCHITECTURE
1616 // ----------------------------------------------------------------------------
1617 // Command processing framework
1618 // ----------------------------------------------------------------------------
1620 wxCommand::wxCommand(bool canUndoIt
, const wxString
& name
)
1622 m_canUndo
= canUndoIt
;
1623 m_commandName
= name
;
1626 wxCommand::~wxCommand()
1630 // Command processor
1631 wxCommandProcessor::wxCommandProcessor(int maxCommands
)
1633 m_maxNoCommands
= maxCommands
;
1634 m_currentCommand
= (wxNode
*) NULL
;
1635 m_commandEditMenu
= (wxMenu
*) NULL
;
1638 wxCommandProcessor::~wxCommandProcessor()
1643 // Pass a command to the processor. The processor calls Do();
1644 // if successful, is appended to the command history unless
1645 // storeIt is FALSE.
1646 bool wxCommandProcessor::Submit(wxCommand
*command
, bool storeIt
)
1648 bool success
= command
->Do();
1649 if (success
&& storeIt
)
1651 if (m_commands
.Number() == m_maxNoCommands
)
1653 wxNode
*firstNode
= m_commands
.First();
1654 wxCommand
*firstCommand
= (wxCommand
*)firstNode
->Data();
1655 delete firstCommand
;
1659 // Correct a bug: we must chop off the current 'branch'
1660 // so that we're at the end of the command list.
1661 if (!m_currentCommand
)
1665 wxNode
*node
= m_currentCommand
->Next();
1668 wxNode
*next
= node
->Next();
1669 delete (wxCommand
*)node
->Data();
1675 m_commands
.Append(command
);
1676 m_currentCommand
= m_commands
.Last();
1682 bool wxCommandProcessor::Undo()
1684 if (m_currentCommand
)
1686 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1687 if (command
->CanUndo())
1689 bool success
= command
->Undo();
1692 m_currentCommand
= m_currentCommand
->Previous();
1701 bool wxCommandProcessor::Redo()
1703 wxCommand
*redoCommand
= (wxCommand
*) NULL
;
1704 wxNode
*redoNode
= (wxNode
*) NULL
;
1705 if (m_currentCommand
&& m_currentCommand
->Next())
1707 redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1708 redoNode
= m_currentCommand
->Next();
1712 if (m_commands
.Number() > 0)
1714 redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1715 redoNode
= m_commands
.First();
1721 bool success
= redoCommand
->Do();
1724 m_currentCommand
= redoNode
;
1732 bool wxCommandProcessor::CanUndo() const
1734 if (m_currentCommand
)
1735 return ((wxCommand
*)m_currentCommand
->Data())->CanUndo();
1739 bool wxCommandProcessor::CanRedo() const
1741 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() == (wxNode
*) NULL
))
1744 if ((m_currentCommand
!= (wxNode
*) NULL
) && (m_currentCommand
->Next() != (wxNode
*) NULL
))
1747 if ((m_currentCommand
== (wxNode
*) NULL
) && (m_commands
.Number() > 0))
1753 void wxCommandProcessor::Initialize()
1755 m_currentCommand
= m_commands
.Last();
1759 void wxCommandProcessor::SetMenuStrings()
1761 if (m_commandEditMenu
)
1764 if (m_currentCommand
)
1766 wxCommand
*command
= (wxCommand
*)m_currentCommand
->Data();
1767 wxString
commandName(command
->GetName());
1768 if (commandName
== wxT("")) commandName
= _("Unnamed command");
1769 bool canUndo
= command
->CanUndo();
1771 buf
= wxString(_("&Undo ")) + commandName
;
1773 buf
= wxString(_("Can't &Undo ")) + commandName
;
1775 m_commandEditMenu
->SetLabel(wxID_UNDO
, buf
);
1776 m_commandEditMenu
->Enable(wxID_UNDO
, canUndo
);
1778 // We can redo, if we're not at the end of the history.
1779 if (m_currentCommand
->Next())
1781 wxCommand
*redoCommand
= (wxCommand
*)m_currentCommand
->Next()->Data();
1782 wxString
redoCommandName(redoCommand
->GetName());
1783 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1784 buf
= wxString(_("&Redo ")) + redoCommandName
;
1785 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1786 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1790 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1791 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1796 m_commandEditMenu
->SetLabel(wxID_UNDO
, _("&Undo"));
1797 m_commandEditMenu
->Enable(wxID_UNDO
, FALSE
);
1799 if (m_commands
.Number() == 0)
1801 m_commandEditMenu
->SetLabel(wxID_REDO
, _("&Redo"));
1802 m_commandEditMenu
->Enable(wxID_REDO
, FALSE
);
1806 // currentCommand is NULL but there are commands: this means that
1807 // we've undone to the start of the list, but can redo the first.
1808 wxCommand
*redoCommand
= (wxCommand
*)m_commands
.First()->Data();
1809 wxString
redoCommandName(redoCommand
->GetName());
1810 if (redoCommandName
== wxT("")) redoCommandName
= _("Unnamed command");
1811 buf
= wxString(_("&Redo ")) + redoCommandName
;
1812 m_commandEditMenu
->SetLabel(wxID_REDO
, buf
);
1813 m_commandEditMenu
->Enable(wxID_REDO
, TRUE
);
1819 void wxCommandProcessor::ClearCommands()
1821 wxNode
*node
= m_commands
.First();
1824 wxCommand
*command
= (wxCommand
*)node
->Data();
1827 node
= m_commands
.First();
1829 m_currentCommand
= (wxNode
*) NULL
;
1832 // ----------------------------------------------------------------------------
1833 // File history processor
1834 // ----------------------------------------------------------------------------
1836 wxFileHistory::wxFileHistory(int maxFiles
)
1838 m_fileMaxFiles
= maxFiles
;
1840 m_fileHistory
= new wxChar
*[m_fileMaxFiles
];
1843 wxFileHistory::~wxFileHistory()
1846 for (i
= 0; i
< m_fileHistoryN
; i
++)
1847 delete[] m_fileHistory
[i
];
1848 delete[] m_fileHistory
;
1851 // File history management
1852 void wxFileHistory::AddFileToHistory(const wxString
& file
)
1855 // Check we don't already have this file
1856 for (i
= 0; i
< m_fileHistoryN
; i
++)
1858 if (m_fileHistory
[i
] && wxString(m_fileHistory
[i
]) == file
)
1862 // Add to the project file history:
1863 // Move existing files (if any) down so we can insert file at beginning.
1865 // First delete filename that has popped off the end of the array (if any)
1866 if (m_fileHistoryN
== m_fileMaxFiles
)
1868 delete[] m_fileHistory
[m_fileMaxFiles
-1];
1869 m_fileHistory
[m_fileMaxFiles
-1] = (wxChar
*) NULL
;
1871 if (m_fileHistoryN
< m_fileMaxFiles
)
1873 wxNode
* node
= m_fileMenus
.First();
1876 wxMenu
* menu
= (wxMenu
*) node
->Data();
1877 if (m_fileHistoryN
== 0)
1878 menu
->AppendSeparator();
1879 menu
->Append(wxID_FILE1
+m_fileHistoryN
, _("[EMPTY]"));
1880 node
= node
->Next();
1884 // Shuffle filenames down
1885 for (i
= (m_fileHistoryN
-1); i
> 0; i
--)
1887 m_fileHistory
[i
] = m_fileHistory
[i
-1];
1889 m_fileHistory
[0] = copystring(file
);
1891 for (i
= 0; i
< m_fileHistoryN
; i
++)
1892 if (m_fileHistory
[i
])
1895 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
1896 wxNode
* node
= m_fileMenus
.First();
1899 wxMenu
* menu
= (wxMenu
*) node
->Data();
1900 menu
->SetLabel(wxID_FILE1
+i
, buf
);
1901 node
= node
->Next();
1906 void wxFileHistory::RemoveFileFromHistory(int i
)
1908 wxCHECK_RET( i
< m_fileHistoryN
,
1909 wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
1911 wxNode
* node
= m_fileMenus
.First();
1914 wxMenu
* menu
= (wxMenu
*) node
->Data();
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 node
= node
->Next();
1935 // delete the last menu item which is unused now
1936 menu
->Delete(wxID_FILE1
+ m_fileHistoryN
- 1);
1938 // delete the last separator too if no more files are left
1939 if ( m_fileHistoryN
== 1 )
1941 wxMenuItemList::Node
*node
= menu
->GetMenuItems().GetLast();
1944 wxMenuItem
*menuItem
= node
->GetData();
1945 if ( menuItem
->IsSeparator() )
1947 menu
->Delete(menuItem
);
1949 //else: should we search backwards for the last separator?
1951 //else: menu is empty somehow
1958 wxString
wxFileHistory::GetHistoryFile(int i
) const
1961 if ( i
< m_fileHistoryN
)
1963 s
= m_fileHistory
[i
];
1967 wxFAIL_MSG( wxT("bad index in wxFileHistory::GetHistoryFile") );
1973 void wxFileHistory::UseMenu(wxMenu
*menu
)
1975 if (!m_fileMenus
.Member(menu
))
1976 m_fileMenus
.Append(menu
);
1979 void wxFileHistory::RemoveMenu(wxMenu
*menu
)
1981 m_fileMenus
.DeleteObject(menu
);
1985 void wxFileHistory::Load(wxConfigBase
& config
)
1989 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1990 wxString historyFile
;
1991 while ((m_fileHistoryN
<= m_fileMaxFiles
) && config
.Read(buf
, &historyFile
) && (historyFile
!= wxT("")))
1993 m_fileHistory
[m_fileHistoryN
] = copystring((const wxChar
*) historyFile
);
1995 buf
.Printf(wxT("file%d"), m_fileHistoryN
+1);
1996 historyFile
= wxT("");
2001 void wxFileHistory::Save(wxConfigBase
& config
)
2004 for (i
= 0; i
< m_fileHistoryN
; i
++)
2007 buf
.Printf(wxT("file%d"), i
+1);
2008 config
.Write(buf
, wxString(m_fileHistory
[i
]));
2011 #endif // wxUSE_CONFIG
2013 void wxFileHistory::AddFilesToMenu()
2015 if (m_fileHistoryN
> 0)
2017 wxNode
* node
= m_fileMenus
.First();
2020 wxMenu
* menu
= (wxMenu
*) node
->Data();
2021 menu
->AppendSeparator();
2023 for (i
= 0; i
< m_fileHistoryN
; i
++)
2025 if (m_fileHistory
[i
])
2028 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2029 menu
->Append(wxID_FILE1
+i
, buf
);
2032 node
= node
->Next();
2037 void wxFileHistory::AddFilesToMenu(wxMenu
* menu
)
2039 if (m_fileHistoryN
> 0)
2041 menu
->AppendSeparator();
2043 for (i
= 0; i
< m_fileHistoryN
; i
++)
2045 if (m_fileHistory
[i
])
2048 buf
.Printf(s_MRUEntryFormat
, i
+1, m_fileHistory
[i
]);
2049 menu
->Append(wxID_FILE1
+i
, buf
);
2055 // ----------------------------------------------------------------------------
2056 // Permits compatibility with existing file formats and functions that
2057 // manipulate files directly
2058 // ----------------------------------------------------------------------------
2060 #if wxUSE_STD_IOSTREAM
2061 bool wxTransferFileToStream(const wxString
& filename
, ostream
& stream
)
2066 if ((fd1
= fopen (filename
.fn_str(), "rb")) == NULL
)
2069 while ((ch
= getc (fd1
)) != EOF
)
2070 stream
<< (unsigned char)ch
;
2076 bool wxTransferStreamToFile(istream
& stream
, const wxString
& filename
)
2081 if ((fd1
= fopen (filename
.fn_str(), "wb")) == NULL
)
2086 while (!stream
.eof())
2097 #endif // wxUSE_DOC_VIEW_ARCHITECTURE