X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/637f467a0639bf942ebeb466d056fa339bfdbdee..520e470fdd0daef09c77938db642e4583933c90d:/src/common/docview.cpp?ds=sidebyside diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 80ad3550d6..bbfdf9ab3f 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -24,9 +24,10 @@ #include "wx/defs.h" #endif -#if USE_DOC_VIEW_ARCHITECTURE +#if wxUSE_DOC_VIEW_ARCHITECTURE #ifndef WX_PRECOMP +#include "wx/string.h" #include "wx/utils.h" #include "wx/app.h" #include "wx/dc.h" @@ -34,32 +35,33 @@ #include "wx/menu.h" #include "wx/list.h" #include "wx/filedlg.h" +#include +#endif + +#ifdef __WXGTK__ +#include "wx/mdi.h" #endif #include "wx/msgdlg.h" #include "wx/choicdlg.h" #include "wx/docview.h" #include "wx/printdlg.h" -#include "wx/generic/prntdlgg.h" -#include "wx/generic/printps.h" - -/* -#ifdef __WXMSW__ -#include "wx/mdi.h" -#endif -*/ +#include "wx/confbase.h" #include #include -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include +#include #else #include +#include +# ifdef _MSC_VER + using namespace std; +# endif #endif -#include "fstream.h" - #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler) IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler) @@ -67,7 +69,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler) IMPLEMENT_CLASS(wxDocChildFrame, wxFrame) IMPLEMENT_CLASS(wxDocParentFrame, wxFrame) -#if USE_PRINTING_ARCHITECTURE +#if wxUSE_PRINTING_ARCHITECTURE IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout) #endif IMPLEMENT_CLASS(wxCommand, wxObject) @@ -86,7 +88,7 @@ wxDocument::wxDocument(wxDocument *parent) m_documentFile=""; m_documentTitle=""; m_documentParent=parent; - m_documentTemplate = NULL; + m_documentTemplate = (wxDocTemplate *) NULL; m_documentTypeName = ""; m_savedYet = FALSE; } @@ -149,7 +151,7 @@ bool wxDocument::DeleteAllViews(void) wxView *wxDocument::GetFirstView(void) const { if (m_documentViews.Number() == 0) - return NULL; + return (wxView *) NULL; return (wxView *)m_documentViews.First()->Data(); } @@ -196,18 +198,30 @@ bool wxDocument::SaveAs(void) if (!docTemplate) return FALSE; - char *tmp = wxFileSelector("Save as", docTemplate->GetDirectory(), GetFilename(), + char *tmp = wxFileSelector(_("Save as"), docTemplate->GetDirectory(), GetFilename(), docTemplate->GetDefaultExtension(), docTemplate->GetFileFilter(), - 0, GetDocumentWindow()); + wxSAVE|wxOVERWRITE_PROMPT, GetDocumentWindow()); if (!tmp) return FALSE; else { - SetFilename(tmp); - SetTitle(wxFileNameFromPath(tmp)); + wxString fileName(tmp); + wxString path(""); + wxString name(""); + wxString ext(""); + wxSplitPath(fileName, & path, & name, & ext); + + if (ext.IsEmpty() || ext == "") + { + fileName += "."; + fileName += docTemplate->GetDefaultExtension(); + } + + SetFilename(fileName); + SetTitle(wxFileNameFromPath(fileName)); - GetDocumentManager()->AddFileToHistory(tmp); + GetDocumentManager()->AddFileToHistory(fileName); // Notify the views that the filename has changed wxNode *node = m_documentViews.First(); @@ -230,19 +244,19 @@ bool wxDocument::OnSaveDocument(const wxString& file) if (wxTheApp->GetAppName() != "") msgTitle = wxTheApp->GetAppName(); else - msgTitle = wxString("File error"); + msgTitle = wxString(_("File error")); ofstream store(file); if (store.fail() || store.bad()) { - (void)wxMessageBox("Sorry, could not open this file for saving.", msgTitle, wxOK | wxICON_EXCLAMATION, + (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION, GetDocumentWindow()); // Saving error return FALSE; } if (SaveObject(store)==FALSE) { - (void)wxMessageBox("Sorry, could not save this file.", msgTitle, wxOK | wxICON_EXCLAMATION, + (void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION, GetDocumentWindow()); // Saving error return FALSE; @@ -261,23 +275,24 @@ bool wxDocument::OnOpenDocument(const wxString& file) if (wxTheApp->GetAppName() != "") msgTitle = wxTheApp->GetAppName(); else - msgTitle = wxString("File error"); + msgTitle = wxString(_("File error")); ifstream store(file); if (store.fail() || store.bad()) { - (void)wxMessageBox("Sorry, could not open this file.", msgTitle, wxOK|wxICON_EXCLAMATION, + (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, GetDocumentWindow()); return FALSE; } if (LoadObject(store)==FALSE) { - (void)wxMessageBox("Sorry, could not open this file.", msgTitle, wxOK|wxICON_EXCLAMATION, + (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, GetDocumentWindow()); return FALSE; } SetFilename(file, TRUE); Modify(FALSE); + m_savedYet = TRUE; UpdateAllViews(); @@ -319,7 +334,7 @@ bool wxDocument::GetPrintableName(wxString& buf) const } else { - buf = "unnamed"; + buf = _("unnamed"); return TRUE; } } @@ -351,9 +366,9 @@ bool wxDocument::OnSaveModified(void) if (wxTheApp->GetAppName() != "") msgTitle = wxTheApp->GetAppName(); else - msgTitle = wxString("Warning"); + msgTitle = wxString(_("Warning")); - sprintf(buf, "Do you want to save changes to document %s?", (const char *)title); + sprintf(buf, _("Do you want to save changes to document %s?"), (const char *)title); int res = wxMessageBox(buf, msgTitle, wxYES_NO|wxCANCEL|wxICON_QUESTION, GetDocumentWindow()); if (res == wxNO) @@ -450,7 +465,7 @@ wxView::wxView(wxDocument *doc) SetDocument(doc); m_viewTypeName = ""; - m_viewFrame = NULL; + m_viewFrame = (wxFrame *) NULL; } wxView::~wxView(void) @@ -488,28 +503,7 @@ void wxView::OnChangeFilename(void) wxString name; GetDocument()->GetPrintableName(name); - // If the frame is an MDI child, just set the title - // to the name. - // Otherwise, append the document name to the name of the application -#ifdef __WXMSW__ - if (GetFrame()->IsKindOf(CLASSINFO(wxMDIChildFrame))) -#else - if (FALSE) -#endif - { - GetFrame()->SetTitle(name); - } - else - { - if (wxTheApp->GetAppName() != "") - { - char buf[400]; - sprintf(buf, "%s - %s", (const char *)wxTheApp->GetAppName(), (const char *)name); - GetFrame()->SetTitle(buf); - } - else - GetFrame()->SetTitle(name); - } + GetFrame()->SetTitle(name); } } @@ -542,7 +536,7 @@ bool wxView::OnClose(bool WXUNUSED(deleteWindow)) return GetDocument() ? GetDocument()->Close() : TRUE; } -#if USE_PRINTING_ARCHITECTURE +#if wxUSE_PRINTING_ARCHITECTURE wxPrintout *wxView::OnCreatePrintout(void) { return new wxDocPrintout(this); @@ -584,7 +578,7 @@ wxDocTemplate::~wxDocTemplate(void) wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) { if (!m_docClassInfo) - return NULL; + return (wxDocument *) NULL; wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject(); doc->SetFilename(path); doc->SetDocumentTemplate(this); @@ -596,14 +590,14 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags) else { delete doc; - return NULL; + return (wxDocument *) NULL; } } wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) { if (!m_viewClassInfo) - return NULL; + return (wxView *) NULL; wxView *view = (wxView *)m_viewClassInfo->CreateObject(); view->SetDocument(doc); if (view->OnCreate(doc, flags)) @@ -613,7 +607,7 @@ wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags) else { delete view; - return NULL; + return (wxView *) NULL; } } @@ -635,9 +629,9 @@ wxDocManager::wxDocManager(long flags, bool initialize) { m_defaultDocumentNameCounter = 1; m_flags = flags; - m_currentView = NULL; + m_currentView = (wxView *) NULL; m_maxDocsOpen = 10000; - m_fileHistory = NULL; + m_fileHistory = (wxFileHistory *) NULL; if (initialize) Initialize(); } @@ -751,20 +745,8 @@ void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) wxPrintout *printout = view->OnCreatePrintout(); if (printout) { - // TODO: trouble about this is that it pulls in the postscript - // code unecessarily -#ifdef __WXMSW__ - if ( wxTheApp->GetPrintMode() == wxPRINT_WINDOWS ) - { - wxWindowsPrinter printer; - printer.Print(view->GetFrame(), printout, TRUE); - } - else -#endif - { - wxPostScriptPrinter printer; - printer.Print(view->GetFrame(), printout, TRUE); - } + wxPrinter printer; + printer.Print(view->GetFrame(), printout, TRUE); delete printout; } @@ -779,20 +761,9 @@ void wxDocManager::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) wxPrintData data; -#ifdef __WXMSW__ - if ( wxTheApp->GetPrintMode() == wxPRINT_WINDOWS ) - { - wxPrintDialog printerDialog(parentWin, & data); - printerDialog.GetPrintData().SetSetupDialog(TRUE); - printerDialog.ShowModal(); - } - else -#endif - { - wxGenericPrintDialog printerDialog(parentWin, & data); - printerDialog.GetPrintData().SetSetupDialog(TRUE); - printerDialog.ShowModal(); - } + wxPrintDialog printerDialog(parentWin, & data); + printerDialog.GetPrintData().SetSetupDialog(TRUE); + printerDialog.ShowModal(); } void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) @@ -805,15 +776,10 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) if (printout) { // Pass two printout objects: for preview, and possible printing. - wxPrintPreviewBase *preview = NULL; -#ifdef __WXMSW__ - if ( wxTheApp->GetPrintMode() == wxPRINT_WINDOWS ) - preview = new wxWindowsPrintPreview(printout, view->OnCreatePrintout()); - else -#endif - preview = new wxPostScriptPrintPreview(printout, view->OnCreatePrintout()); + wxPrintPreviewBase *preview = (wxPrintPreviewBase *) NULL; + preview = new wxPrintPreview(printout, view->OnCreatePrintout()); - wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), "Print Preview", + wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"), wxPoint(100, 100), wxSize(600, 650)); frame->Centre(wxBOTH); frame->Initialize(); @@ -848,7 +814,7 @@ wxView *wxDocManager::GetCurrentView(void) const wxDocument* doc = (wxDocument*) m_docs.First()->Data(); return doc->GetFirstView(); } - return NULL; + return (wxView *) NULL; } // Extend event processing to search the view's event table @@ -880,7 +846,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) if (n == 0) { delete[] templates; - return NULL; + return (wxDocument *) NULL; } // If we've reached the max number of docs, close the @@ -899,7 +865,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) delete doc; } else - return NULL; + return (wxDocument *) NULL; } // New document: user chooses a template, unless there's only one. @@ -933,11 +899,11 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) return newDoc; } else - return NULL; + return (wxDocument *) NULL; } // Existing document - wxDocTemplate *temp = NULL; + wxDocTemplate *temp = (wxDocTemplate *) NULL; wxString path2(""); if (path != "") @@ -960,14 +926,14 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags) if (!newDoc->OnOpenDocument(path2)) { delete newDoc; - return NULL; + return (wxDocument *) NULL; } AddFileToHistory(path2); } return newDoc; } else - return NULL; + return (wxDocument *) NULL; } wxView *wxDocManager::CreateView(wxDocument *doc, long flags) @@ -990,7 +956,7 @@ wxView *wxDocManager::CreateView(wxDocument *doc, long flags) if (n == 0) { delete[] templates; - return NULL; + return (wxView *) NULL; } if (n == 1) { @@ -1012,7 +978,7 @@ wxView *wxDocManager::CreateView(wxDocument *doc, long flags) return view; } else - return NULL; + return (wxView *) NULL; } // Not yet implemented @@ -1031,14 +997,14 @@ wxDocument *wxDocManager::GetCurrentDocument(void) const if (m_currentView) return m_currentView->GetDocument(); else - return NULL; + return (wxDocument *) NULL; } // Make a default document name bool wxDocManager::MakeDefaultName(wxString& name) { char buf[256]; - sprintf(buf, "unnamed%d", m_defaultDocumentNameCounter); + sprintf(buf, _("unnamed%d"), m_defaultDocumentNameCounter); m_defaultDocumentNameCounter ++; name = buf; return TRUE; @@ -1047,7 +1013,7 @@ bool wxDocManager::MakeDefaultName(wxString& name) // Not yet implemented wxDocTemplate *wxDocManager::MatchTemplate(const wxString& WXUNUSED(path)) { - return NULL; + return (wxDocTemplate *) NULL; } // File history management @@ -1068,19 +1034,37 @@ wxString wxDocManager::GetHistoryFile(int i) const void wxDocManager::FileHistoryUseMenu(wxMenu *menu) { if (m_fileHistory) - m_fileHistory->FileHistoryUseMenu(menu); + m_fileHistory->UseMenu(menu); +} + +void wxDocManager::FileHistoryRemoveMenu(wxMenu *menu) +{ + if (m_fileHistory) + m_fileHistory->RemoveMenu(menu); +} + +void wxDocManager::FileHistoryLoad(wxConfigBase& config) +{ + if (m_fileHistory) + m_fileHistory->Load(config); } -void wxDocManager::FileHistoryLoad(const wxString& resourceFile, const wxString& section) +void wxDocManager::FileHistorySave(wxConfigBase& config) { if (m_fileHistory) - m_fileHistory->FileHistoryLoad(resourceFile, section); + m_fileHistory->Save(config); } -void wxDocManager::FileHistorySave(const wxString& resourceFile, const wxString& section) +void wxDocManager::FileHistoryAddFilesToMenu(wxMenu* menu) { if (m_fileHistory) - m_fileHistory->FileHistorySave(resourceFile, section); + m_fileHistory->AddFilesToMenu(menu); +} + +void wxDocManager::FileHistoryAddFilesToMenu() +{ + if (m_fileHistory) + m_fileHistory->AddFilesToMenu(); } int wxDocManager::GetNoHistoryFiles(void) const @@ -1110,9 +1094,9 @@ static char *FindExtension(char *path) return ext; } else - return NULL; + return (char *) NULL; } - else return NULL; + else return (char *) NULL; } @@ -1122,8 +1106,8 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) { char *theExt = FindExtension((char *)(const char *)path); if (!theExt) - return NULL; - wxDocTemplate *theTemplate = NULL; + return (wxDocTemplate *) NULL; + wxDocTemplate *theTemplate = (wxDocTemplate *) NULL; if (m_templates.Number() == 1) return (wxDocTemplate *)m_templates.First()->Data(); @@ -1172,14 +1156,14 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, // Omit final "|" descrBuf[len-1] = 0; - char *pathTmp = wxFileSelector("Select a file", "", "", "", descrBuf, 0, wxTheApp->GetTopWindow()); + char *pathTmp = wxFileSelector(_("Select a file"), "", "", "", descrBuf, 0, wxTheApp->GetTopWindow()); delete[] descrBuf; if (pathTmp) { path = pathTmp; char *theExt = FindExtension((char *)(const char *)path); if (!theExt) - return NULL; + return (wxDocTemplate *) NULL; // This is dodgy in that we're selecting the template on the // basis of the file extension, which may not be a standard @@ -1191,7 +1175,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, else { path = ""; - return NULL; + return (wxDocTemplate *) NULL; } #else // In all other windowing systems, until we have more advanced @@ -1199,9 +1183,9 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, // _then_ pop up the file selector. wxDocTemplate *temp = SelectDocumentType(templates, noTemplates); if (!temp) - return NULL; + return (wxDocTemplate *) NULL; - char *pathTmp = wxFileSelector("Select a file", "", "", + char *pathTmp = wxFileSelector(_("Select a file"), "", "", temp->GetDefaultExtension(), temp->GetFileFilter(), 0, wxTheApp->GetTopWindow()); @@ -1212,7 +1196,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, return temp; } else - return NULL; + return (wxDocTemplate *) NULL; #endif } @@ -1236,7 +1220,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, { delete[] strings; delete[] data; - return NULL; + return (wxDocTemplate *) NULL; } else if (n == 1) { @@ -1246,7 +1230,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, return temp; } - wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData("Select a document template", "Templates", n, + wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document template"), _("Templates"), n, strings, data); delete[] strings; delete[] data; @@ -1269,7 +1253,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, n ++; } } - wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData("Select a document view", "Views", n, + wxDocTemplate *theTemplate = (wxDocTemplate *)wxGetSingleChoiceData(_("Select a document view"), _("Views"), n, strings, data); delete[] strings; delete[] data; @@ -1319,7 +1303,7 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet if (activate) m_currentView = view; else - m_currentView = NULL; + m_currentView = (wxView *) NULL; } } @@ -1329,11 +1313,12 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame) EVT_ACTIVATE(wxDocChildFrame::OnActivate) + EVT_CLOSE(wxDocChildFrame::OnCloseWindow) END_EVENT_TABLE() -wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, const wxString& title, +wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxFrame(frame, -1, title, pos, size, style, name) + wxFrame(frame, id, title, pos, size, style, name) { m_childDocument = doc; m_childView = view; @@ -1371,24 +1356,30 @@ void wxDocChildFrame::OnActivate(wxActivateEvent& event) m_childView->Activate(event.GetActive()); } -bool wxDocChildFrame::OnClose(void) +void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event) { - // Close view but don't delete the frame while doing so! - // ...since it will be deleted by wxWindows if we return TRUE. if (m_childView) { - bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window + bool ans = FALSE; + if (!event.CanVeto()) + ans = TRUE; // Must delete. + else + ans = m_childView->Close(FALSE); // FALSE means don't delete associated window + if (ans) { m_childView->Activate(FALSE); delete m_childView; - m_childView = NULL; - m_childDocument = NULL; + m_childView = (wxView *) NULL; + m_childDocument = (wxDocument *) NULL; + + this->Destroy(); } - - return ans; + else + event.Veto(); } - else return TRUE; + else + event.Veto(); } /* @@ -1397,12 +1388,13 @@ bool wxDocChildFrame::OnClose(void) BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame) EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit) - EVT_MENU_RANGE(wxID_FILE1, wxID_FILE2, wxDocParentFrame::OnMRUFile) + EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocParentFrame::OnMRUFile) + EVT_CLOSE(wxDocParentFrame::OnCloseWindow) END_EVENT_TABLE() -wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, +wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name): - wxFrame(frame, -1, title, pos, size, style, name) + wxFrame(frame, id, title, pos, size, style, name) { m_docManager = manager; } @@ -1431,12 +1423,17 @@ bool wxDocParentFrame::ProcessEvent(wxEvent& event) // Define the behaviour for the frame closing // - must delete all frames except for the main one. -bool wxDocParentFrame::OnClose(void) +void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event) { - return m_docManager->Clear(FALSE); + if (m_docManager->Clear(!event.CanVeto())) + { + this->Destroy(); + } + else + event.Veto(); } -#if USE_PRINTING_ARCHITECTURE +#if wxUSE_PRINTING_ARCHITECTURE wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title): wxPrintout(WXSTRINGCAST title) @@ -1521,8 +1518,8 @@ wxCommand::~wxCommand(void) wxCommandProcessor::wxCommandProcessor(int maxCommands) { m_maxNoCommands = maxCommands; - m_currentCommand = NULL; - m_commandEditMenu = NULL; + m_currentCommand = (wxNode *) NULL; + m_commandEditMenu = (wxMenu *) NULL; } wxCommandProcessor::~wxCommandProcessor(void) @@ -1590,8 +1587,8 @@ bool wxCommandProcessor::Undo(void) bool wxCommandProcessor::Redo(void) { - wxCommand *redoCommand = NULL; - wxNode *redoNode = NULL; + wxCommand *redoCommand = (wxCommand *) NULL; + wxNode *redoNode = (wxNode *) NULL; if (m_currentCommand && m_currentCommand->Next()) { redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); @@ -1619,13 +1616,27 @@ bool wxCommandProcessor::Redo(void) return FALSE; } -bool wxCommandProcessor::CanUndo(void) +bool wxCommandProcessor::CanUndo(void) const { if (m_currentCommand) return ((wxCommand *)m_currentCommand->Data())->CanUndo(); return FALSE; } +bool wxCommandProcessor::CanRedo(void) const +{ + if ((m_currentCommand != (wxNode*) NULL) && (m_currentCommand->Next() == (wxNode*) NULL)) + return FALSE; + + if ((m_currentCommand != (wxNode*) NULL) && (m_currentCommand->Next() != (wxNode*) NULL)) + return TRUE; + + if ((m_currentCommand == (wxNode*) NULL) && (m_commands.Number() > 0)) + return TRUE; + + return FALSE; +} + void wxCommandProcessor::Initialize(void) { m_currentCommand = m_commands.Last(); @@ -1641,12 +1652,12 @@ void wxCommandProcessor::SetMenuStrings(void) { wxCommand *command = (wxCommand *)m_currentCommand->Data(); wxString commandName(command->GetName()); - if (commandName == "") commandName = "Unnamed command"; + if (commandName == "") commandName = _("Unnamed command"); bool canUndo = command->CanUndo(); if (canUndo) - buf = wxString("&Undo ") + commandName; + buf = wxString(_("&Undo ")) + commandName; else - buf = wxString("Can't &Undo ") + commandName; + buf = wxString(_("Can't &Undo ")) + commandName; m_commandEditMenu->SetLabel(wxID_UNDO, buf); m_commandEditMenu->Enable(wxID_UNDO, canUndo); @@ -1656,25 +1667,25 @@ void wxCommandProcessor::SetMenuStrings(void) { wxCommand *redoCommand = (wxCommand *)m_currentCommand->Next()->Data(); wxString redoCommandName(redoCommand->GetName()); - if (redoCommandName == "") redoCommandName = "Unnamed command"; - buf = wxString("&Redo ") + redoCommandName; + if (redoCommandName == "") redoCommandName = _("Unnamed command"); + buf = wxString(_("&Redo ")) + redoCommandName; m_commandEditMenu->SetLabel(wxID_REDO, buf); m_commandEditMenu->Enable(wxID_REDO, TRUE); } else { - m_commandEditMenu->SetLabel(wxID_REDO, "&Redo"); + m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); m_commandEditMenu->Enable(wxID_REDO, FALSE); } } else { - m_commandEditMenu->SetLabel(wxID_UNDO, "&Undo"); + m_commandEditMenu->SetLabel(wxID_UNDO, _("&Undo")); m_commandEditMenu->Enable(wxID_UNDO, FALSE); if (m_commands.Number() == 0) { - m_commandEditMenu->SetLabel(wxID_REDO, "&Redo"); + m_commandEditMenu->SetLabel(wxID_REDO, _("&Redo")); m_commandEditMenu->Enable(wxID_REDO, FALSE); } else @@ -1683,8 +1694,8 @@ void wxCommandProcessor::SetMenuStrings(void) // we've undone to the start of the list, but can redo the first. wxCommand *redoCommand = (wxCommand *)m_commands.First()->Data(); wxString redoCommandName(redoCommand->GetName()); - if (!redoCommandName) redoCommandName = "Unnamed command"; - buf = wxString("&Redo ") + redoCommandName; + if (!redoCommandName) redoCommandName = _("Unnamed command"); + buf = wxString(_("&Redo ")) + redoCommandName; m_commandEditMenu->SetLabel(wxID_REDO, buf); m_commandEditMenu->Enable(wxID_REDO, TRUE); } @@ -1702,7 +1713,7 @@ void wxCommandProcessor::ClearCommands(void) delete node; node = m_commands.First(); } - m_currentCommand = NULL; + m_currentCommand = (wxNode *) NULL; } @@ -1713,7 +1724,6 @@ void wxCommandProcessor::ClearCommands(void) wxFileHistory::wxFileHistory(int maxFiles) { m_fileMaxFiles = maxFiles; - m_fileMenu = NULL; m_fileHistoryN = 0; m_fileHistory = new char *[m_fileMaxFiles]; } @@ -1729,18 +1739,14 @@ wxFileHistory::~wxFileHistory(void) // File history management void wxFileHistory::AddFileToHistory(const wxString& file) { - if (!m_fileMenu) - return; - int i; - // Check we don't already have this file for (i = 0; i < m_fileHistoryN; i++) { - if (m_fileHistory[i] && wxString(m_fileHistory[i]) == file) - return; + if (m_fileHistory[i] && wxString(m_fileHistory[i]) == file) + return; } - + // Add to the project file history: // Move existing files (if any) down so we can insert file at beginning. @@ -1748,13 +1754,19 @@ void wxFileHistory::AddFileToHistory(const wxString& file) if (m_fileHistoryN == m_fileMaxFiles) { delete[] m_fileHistory[m_fileMaxFiles-1]; - m_fileHistory[m_fileMaxFiles-1] = NULL; + m_fileHistory[m_fileMaxFiles-1] = (char *) NULL; } if (m_fileHistoryN < m_fileMaxFiles) { - if (m_fileHistoryN == 0) - m_fileMenu->AppendSeparator(); - m_fileMenu->Append(wxID_FILE1+m_fileHistoryN, "[EMPTY]"); + wxNode* node = m_fileMenus.First(); + while (node) + { + wxMenu* menu = (wxMenu*) node->Data(); + if (m_fileHistoryN == 0) + menu->AppendSeparator(); + menu->Append(wxID_FILE1+m_fileHistoryN, _("[EMPTY]")); + node = node->Next(); + } m_fileHistoryN ++; } // Shuffle filenames down @@ -1769,7 +1781,13 @@ void wxFileHistory::AddFileToHistory(const wxString& file) { char buf[400]; sprintf(buf, "&%d %s", i+1, m_fileHistory[i]); - m_fileMenu->SetLabel(wxID_FILE1+i, buf); + wxNode* node = m_fileMenus.First(); + while (node) + { + wxMenu* menu = (wxMenu*) node->Data(); + menu->SetLabel(wxID_FILE1+i, buf); + node = node->Next(); + } } } @@ -1781,40 +1799,84 @@ wxString wxFileHistory::GetHistoryFile(int i) const return wxString(""); } -void wxFileHistory::FileHistoryUseMenu(wxMenu *menu) +void wxFileHistory::UseMenu(wxMenu *menu) +{ + if (!m_fileMenus.Member(menu)) + m_fileMenus.Append(menu); +} + +void wxFileHistory::RemoveMenu(wxMenu *menu) { - m_fileMenu = menu; + m_fileMenus.DeleteObject(menu); } -void wxFileHistory::FileHistoryLoad(const wxString& resourceFile, const wxString& section) +void wxFileHistory::Load(wxConfigBase& config) { -#if USE_RESOURCES m_fileHistoryN = 0; char buf[400]; sprintf(buf, "file%d", m_fileHistoryN+1); - char *historyFile = NULL; - while ((m_fileHistoryN <= m_fileMaxFiles) && wxGetResource(section, buf, &historyFile, resourceFile) && historyFile) + wxString historyFile(""); + while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != "")) { - // wxGetResource allocates memory so this is o.k. - m_fileHistory[m_fileHistoryN] = historyFile; + m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile); m_fileHistoryN ++; sprintf(buf, "file%d", m_fileHistoryN+1); - historyFile = NULL; + historyFile = ""; } -#endif + AddFilesToMenu(); } -void wxFileHistory::FileHistorySave(const wxString& resourceFile, const wxString& section) +void wxFileHistory::Save(wxConfigBase& config) { -#if USE_RESOURCES - char buf[400]; int i; for (i = 0; i < m_fileHistoryN; i++) { - sprintf(buf, "file%d", i+1); - wxWriteResource(section, buf, m_fileHistory[i], resourceFile); + wxString buf; + buf.Printf("file%d", i+1); + config.Write(buf, wxString(m_fileHistory[i])); } -#endif +} + +void wxFileHistory::AddFilesToMenu() +{ + if (m_fileHistoryN > 0) + { + wxNode* node = m_fileMenus.First(); + while (node) + { + wxMenu* menu = (wxMenu*) node->Data(); + menu->AppendSeparator(); + int i; + for (i = 0; i < m_fileHistoryN; i++) + { + if (m_fileHistory[i]) + { + wxString buf; + buf.Printf("&%d %s", i+1, m_fileHistory[i]); + menu->Append(wxID_FILE1+i, buf); + } + } + node = node->Next(); + } + } +} + +void wxFileHistory::AddFilesToMenu(wxMenu* menu) +{ + if (m_fileHistoryN > 0) + { + menu->AppendSeparator(); + int i; + for (i = 0; i < m_fileHistoryN; i++) + { + if (m_fileHistory[i]) + { + wxString buf; + buf.Printf("&%d %s", i+1, m_fileHistory[i]); + menu->Append(wxID_FILE1+i, buf); + } + } + } } #if 0 @@ -1873,4 +1935,4 @@ bool wxTransferStreamToFile(istream& stream, const wxString& filename) } #endif - // End USE_DOC_VIEW_ARCHITECTURE + // End wxUSE_DOC_VIEW_ARCHITECTURE