X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f555861b7e50f335c7b929bb76be38e9ebd69c5..fc9ef629ac8733c4f0b844356782cca80ae09c4b:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index b54ea6d75b..01f8ebe21a 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -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,21 +46,19 @@ #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 -#include +#include "wx/ioswrap.h" + +#if wxUSE_IOSTREAMH + #include #else -#include + #include #endif -#include "fstream.h" - #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler) IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler) @@ -68,7 +66,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) @@ -193,18 +191,21 @@ bool wxDocument::Save(void) bool wxDocument::SaveAs(void) { - wxDocTemplate *docTemplate = GetDocumentTemplate(); - if (!docTemplate) - return FALSE; - - char *tmp = wxFileSelector(_("Save as"), docTemplate->GetDirectory(), GetFilename(), - docTemplate->GetDefaultExtension(), docTemplate->GetFileFilter(), - wxSAVE|wxOVERWRITE_PROMPT, GetDocumentWindow()); + wxDocTemplate *docTemplate = GetDocumentTemplate(); + if (!docTemplate) + return FALSE; - if (!tmp) - return FALSE; - else - { + wxString tmp = wxFileSelector(_("Save as"), + docTemplate->GetDirectory(), + GetFilename(), + docTemplate->GetDefaultExtension(), + docTemplate->GetFileFilter(), + wxSAVE | wxOVERWRITE_PROMPT, + GetDocumentWindow()); + + if (tmp.IsEmpty()) + return FALSE; + wxString fileName(tmp); wxString path(""); wxString name(""); @@ -230,8 +231,8 @@ bool wxDocument::SaveAs(void) view->OnChangeFilename(); node = node->Next(); } - } - return OnSaveDocument(m_documentFile); + + return OnSaveDocument(m_documentFile); } bool wxDocument::OnSaveDocument(const wxString& file) @@ -357,7 +358,6 @@ bool wxDocument::OnSaveModified(void) { if (IsModified()) { - char buf[400]; wxString title; GetPrintableName(title); @@ -367,9 +367,12 @@ bool wxDocument::OnSaveModified(void) else msgTitle = wxString(_("Warning")); - 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()); + wxString prompt; + prompt.Printf(_("Do you want to save changes to document %s?"), + (const char *)title); + int res = wxMessageBox(prompt, msgTitle, + wxYES_NO|wxCANCEL|wxICON_QUESTION, + GetDocumentWindow()); if (res == wxNO) { Modify(FALSE); @@ -459,9 +462,10 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews) * Document view */ -wxView::wxView(wxDocument *doc) +wxView::wxView() { - SetDocument(doc); +// SetDocument(doc); + m_viewDocument = (wxDocument*) NULL; m_viewTypeName = ""; m_viewFrame = (wxFrame *) NULL; @@ -535,7 +539,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); @@ -744,20 +748,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; } @@ -772,20 +764,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)) @@ -799,12 +780,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)); @@ -1030,10 +1006,9 @@ wxDocument *wxDocManager::GetCurrentDocument(void) const // Make a default document name bool wxDocManager::MakeDefaultName(wxString& name) { - char buf[256]; - sprintf(buf, _("unnamed%d"), m_defaultDocumentNameCounter); - m_defaultDocumentNameCounter ++; - name = buf; + name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter); + m_defaultDocumentNameCounter++; + return TRUE; } @@ -1070,6 +1045,7 @@ void wxDocManager::FileHistoryRemoveMenu(wxMenu *menu) m_fileHistory->RemoveMenu(menu); } +#if wxUSE_CONFIG void wxDocManager::FileHistoryLoad(wxConfigBase& config) { if (m_fileHistory) @@ -1081,6 +1057,7 @@ void wxDocManager::FileHistorySave(wxConfigBase& config) if (m_fileHistory) m_fileHistory->Save(config); } +#endif void wxDocManager::FileHistoryAddFilesToMenu(wxMenu* menu) { @@ -1157,35 +1134,41 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) // How to implement in wxWindows? Must extend the file selector // dialog or implement own; OR match the extension to the // template extension. + +#ifdef __WXMSW__ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, int noTemplates, wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) +#else +wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templates), + int WXUNUSED(noTemplates), wxString& path, long WXUNUSED(flags), bool WXUNUSED(save)) +#endif { // We can only have multiple filters in Windows #ifdef __WXMSW__ - char *descrBuf = new char[1000]; - descrBuf[0] = 0; - int i; - for (i = 0; i < noTemplates; i++) - { - if (templates[i]->IsVisible()) + wxString descrBuf; + + int i; + for (i = 0; i < noTemplates; i++) { - strcat(descrBuf, templates[i]->GetDescription()); - strcat(descrBuf, " ("); - strcat(descrBuf, templates[i]->GetFileFilter()); - strcat(descrBuf, ") "); - strcat(descrBuf, "|"); - strcat(descrBuf, templates[i]->GetFileFilter()); - strcat(descrBuf, "|"); + if (templates[i]->IsVisible()) + { + // add a '|' to separate this filter from the previous one + if ( !descrBuf.IsEmpty() ) + descrBuf << '|'; + + descrBuf << templates[i]->GetDescription() + << " (" << templates[i]->GetFileFilter() << ") |" + << templates[i]->GetFileFilter(); + } } - } - int len = strlen(descrBuf); - if (len > 0) - // Omit final "|" - descrBuf[len-1] = 0; +#else + wxString descrBuf = "*.*"; +#endif - char *pathTmp = wxFileSelector(_("Select a file"), "", "", "", descrBuf, 0, wxTheApp->GetTopWindow()); - delete[] descrBuf; - if (pathTmp) + wxString pathTmp = wxFileSelector(_("Select a file"), "", "", "", + descrBuf, 0, wxTheApp->GetTopWindow()); + + if (!pathTmp.IsEmpty()) { path = pathTmp; char *theExt = FindExtension((char *)(const char *)path); @@ -1204,7 +1187,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, path = ""; return (wxDocTemplate *) NULL; } -#else +#if 0 // In all other windowing systems, until we have more advanced // file selectors, we must select the document type (template) first, and // _then_ pop up the file selector. @@ -1273,7 +1256,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, int n = 0; for (i = 0; i < noTemplates; i++) { - if (templates[i]->IsVisible() && templates[i]->GetViewName()) + if (templates[i]->IsVisible() && (templates[i]->GetViewName() != "")) { strings[n] = WXSTRINGCAST templates[i]->m_viewTypeName; data[n] = (char *)templates[i]; @@ -1340,6 +1323,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, @@ -1382,24 +1366,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(); } /* @@ -1409,6 +1399,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, @@ -1442,12 +1433,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) @@ -1639,7 +1635,16 @@ bool wxCommandProcessor::CanUndo(void) const bool wxCommandProcessor::CanRedo(void) const { - return ((m_currentCommand && m_currentCommand->Next())); + 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) @@ -1699,7 +1704,7 @@ 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"); + if (redoCommandName == "") redoCommandName = _("Unnamed command"); buf = wxString(_("&Redo ")) + redoCommandName; m_commandEditMenu->SetLabel(wxID_REDO, buf); m_commandEditMenu->Enable(wxID_REDO, TRUE); @@ -1784,8 +1789,8 @@ void wxFileHistory::AddFileToHistory(const wxString& file) for (i = 0; i < m_fileHistoryN; i++) if (m_fileHistory[i]) { - char buf[400]; - sprintf(buf, "&%d %s", i+1, m_fileHistory[i]); + wxString buf; + buf.Printf("&%d %s", i+1, m_fileHistory[i]); wxNode* node = m_fileMenus.First(); while (node) { @@ -1815,17 +1820,18 @@ void wxFileHistory::RemoveMenu(wxMenu *menu) m_fileMenus.DeleteObject(menu); } +#if wxUSE_CONFIG void wxFileHistory::Load(wxConfigBase& config) { m_fileHistoryN = 0; - char buf[400]; - sprintf(buf, "file%d", m_fileHistoryN+1); - wxString historyFile(""); + wxString buf; + buf.Printf("file%d", m_fileHistoryN+1); + wxString historyFile; while ((m_fileHistoryN <= m_fileMaxFiles) && config.Read(buf, &historyFile) && (historyFile != "")) { m_fileHistory[m_fileHistoryN] = copystring((const char*) historyFile); m_fileHistoryN ++; - sprintf(buf, "file%d", m_fileHistoryN+1); + buf.Printf("file%d", m_fileHistoryN+1); historyFile = ""; } AddFilesToMenu(); @@ -1841,6 +1847,7 @@ void wxFileHistory::Save(wxConfigBase& config) config.Write(buf, wxString(m_fileHistory[i])); } } +#endif void wxFileHistory::AddFilesToMenu() { @@ -1940,4 +1947,4 @@ bool wxTransferStreamToFile(istream& stream, const wxString& filename) } #endif - // End USE_DOC_VIEW_ARCHITECTURE + // End wxUSE_DOC_VIEW_ARCHITECTURE