X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c67daf87774c71ae9f73af9969008af220e52a11..520e470fdd0daef09c77938db642e4583933c90d:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index cec8525fab..bbfdf9ab3f 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -24,7 +24,7 @@ #include "wx/defs.h" #endif -#if USE_DOC_VIEW_ARCHITECTURE +#if wxUSE_DOC_VIEW_ARCHITECTURE #ifndef WX_PRECOMP #include "wx/string.h" @@ -46,20 +46,22 @@ #include "wx/choicdlg.h" #include "wx/docview.h" #include "wx/printdlg.h" -#include "wx/generic/prntdlgg.h" -#include "wx/generic/printps.h" +#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) @@ -290,6 +292,7 @@ bool wxDocument::OnOpenDocument(const wxString& file) } SetFilename(file, TRUE); Modify(FALSE); + m_savedYet = TRUE; UpdateAllViews(); @@ -533,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); @@ -742,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; } @@ -770,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)) @@ -797,12 +777,7 @@ void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { // Pass two printout objects: for preview, and possible printing. wxPrintPreviewBase *preview = (wxPrintPreviewBase *) NULL; -#ifdef __WXMSW__ - if ( wxTheApp->GetPrintMode() == wxPRINT_WINDOWS ) - preview = new wxWindowsPrintPreview(printout, view->OnCreatePrintout()); - else -#endif - preview = new wxPostScriptPrintPreview(printout, view->OnCreatePrintout()); + preview = new wxPrintPreview(printout, view->OnCreatePrintout()); wxPreviewFrame *frame = new wxPreviewFrame(preview, (wxFrame *)wxTheApp->GetTopWindow(), _("Print Preview"), wxPoint(100, 100), wxSize(600, 650)); @@ -1059,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 @@ -1320,6 +1313,7 @@ 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, wxWindowID id, const wxString& title, @@ -1362,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 = (wxView *) NULL; m_childDocument = (wxDocument *) NULL; + + this->Destroy(); } - - return ans; + else + event.Veto(); } - else return TRUE; + else + event.Veto(); } /* @@ -1389,6 +1389,7 @@ bool wxDocChildFrame::OnClose(void) BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame) EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit) EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocParentFrame::OnMRUFile) + EVT_CLOSE(wxDocParentFrame::OnCloseWindow) END_EVENT_TABLE() wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, @@ -1422,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) @@ -1610,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(); @@ -1704,7 +1724,6 @@ void wxCommandProcessor::ClearCommands(void) wxFileHistory::wxFileHistory(int maxFiles) { m_fileMaxFiles = maxFiles; - m_fileMenu = (wxMenu *) NULL; m_fileHistoryN = 0; m_fileHistory = new char *[m_fileMaxFiles]; } @@ -1720,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. @@ -1743,9 +1758,15 @@ void wxFileHistory::AddFileToHistory(const wxString& file) } 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 @@ -1760,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(); + } } } @@ -1772,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 = (char *) 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 = (char *) 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 @@ -1864,4 +1935,4 @@ bool wxTransferStreamToFile(istream& stream, const wxString& filename) } #endif - // End USE_DOC_VIEW_ARCHITECTURE + // End wxUSE_DOC_VIEW_ARCHITECTURE