From 7e81e3a796eec142428ca04b44015956031eeb0f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Jul 2013 21:55:06 +0000 Subject: [PATCH 1/1] Fix build with wxUSE_FFILE=0. Add the missing "#if wxUSE_FFILE" checks and add fallbacks to wxFile if it's available. Closes #15353. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74596 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 +++ include/wx/richtext/richtextbuffer.h | 24 +++++++++++++-- include/wx/richtext/richtextctrl.h | 4 +++ include/wx/richtext/richtextprint.h | 4 +++ src/common/debugrpt.cpp | 44 +++++++++++++++++++++++----- src/common/textcmn.cpp | 4 +++ src/generic/dbgrptg.cpp | 13 ++++++-- src/richtext/richtextbuffer.cpp | 4 +++ src/richtext/richtextctrl.cpp | 3 +- src/richtext/richtextprint.cpp | 4 +++ src/stc/stc.cpp | 2 +- 11 files changed, 95 insertions(+), 15 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 903cfcbf7f..5185e0139f 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -560,6 +560,10 @@ Major new features in this release 3.0: (released 2013-09-??) -------------------------- +All: + +- Fix build with wxUSE_FFILE==0 (jroemmler). + All (GUI): - Fix crash in wxHTML on mal-formed elements (LukasK). diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 8a3343a9b2..6fc97b1395 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -4842,23 +4842,41 @@ public: */ virtual void ResetAndClearCommands(); +#if wxUSE_FFILE && wxUSE_STREAMS //@{ /** - Loads content from a stream or file. + Loads content from a file. Not all handlers will implement file loading. */ virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); - virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); //@} //@{ /** - Saves content to a stream or file. + Saves content to a file. Not all handlers will implement file saving. */ virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); + //@} +#endif // wxUSE_FFILE + +#if wxUSE_STREAMS + //@{ + /** + Loads content from a stream. + Not all handlers will implement loading from a stream. + */ + virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); + //@} + + //@{ + /** + Saves content to a stream. + Not all handlers will implement saving to a stream. + */ virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); //@} +#endif // wxUSE_STREAMS /** Sets the handler flags, controlling loading and saving. diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index 88c6f66387..b115490172 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -573,6 +573,7 @@ public: int type = wxRICHTEXT_TYPE_ANY); #endif +#if wxUSE_FFILE && wxUSE_STREAMS /** Helper function for LoadFile(). Loads content into the control's buffer using the given type. @@ -582,6 +583,7 @@ public: This function looks for a suitable wxRichTextFileHandler object. */ virtual bool DoLoadFile(const wxString& file, int fileType); +#endif // wxUSE_FFILE && wxUSE_STREAMS #ifdef DOXYGEN /** @@ -596,6 +598,7 @@ public: int type = wxRICHTEXT_TYPE_ANY); #endif +#if wxUSE_FFILE && wxUSE_STREAMS /** Helper function for SaveFile(). Saves the buffer content using the given type. @@ -606,6 +609,7 @@ public: */ virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY); +#endif // wxUSE_FFILE && wxUSE_STREAMS /** Sets flags that change the behaviour of loading or saving. diff --git a/include/wx/richtext/richtextprint.h b/include/wx/richtext/richtextprint.h index 8ca2e80bb3..4c41043210 100644 --- a/include/wx/richtext/richtextprint.h +++ b/include/wx/richtext/richtextprint.h @@ -165,11 +165,15 @@ public: virtual ~wxRichTextPrinting(); /// Preview the file or buffer +#if wxUSE_FFILE && wxUSE_STREAMS bool PreviewFile(const wxString& richTextFile); +#endif bool PreviewBuffer(const wxRichTextBuffer& buffer); /// Print the file or buffer +#if wxUSE_FFILE && wxUSE_STREAMS bool PrintFile(const wxString& richTextFile, bool showPrintDialog = true); +#endif bool PrintBuffer(const wxRichTextBuffer& buffer, bool showPrintDialog = true); /// Shows page setup dialog diff --git a/src/common/debugrpt.cpp b/src/common/debugrpt.cpp index 3d4f505412..d13e1194a4 100644 --- a/src/common/debugrpt.cpp +++ b/src/common/debugrpt.cpp @@ -33,8 +33,12 @@ #if wxUSE_DEBUGREPORT && wxUSE_XML #include "wx/debugrpt.h" +#if wxUSE_FFILE + #include "wx/ffile.h" +#elif wxUSE_FILE + #include "wx/file.h" +#endif -#include "wx/ffile.h" #include "wx/filename.h" #include "wx/dir.h" #include "wx/dynlib.h" @@ -288,17 +292,25 @@ wxDebugReport::AddText(const wxString& filename, const wxString& text, const wxString& description) { +#if wxUSE_FFILE || wxUSE_FILE wxASSERT_MSG( !wxFileName(filename).IsAbsolute(), wxT("filename should be relative to debug report directory") ); - wxFileName fn(GetDirectory(), filename); - wxFFile file(fn.GetFullPath(), wxT("w")); - if ( !file.IsOpened() || !file.Write(text) ) + const wxString fullPath = wxFileName(GetDirectory(), filename).GetFullPath(); +#if wxUSE_FFILE + wxFFile file(fullPath, wxT("w")); +#elif wxUSE_FILE + wxFile file(fullPath, wxFile::write); +#endif + if ( !file.IsOpened() || !file.Write(text, wxConvAuto()) ) return false; AddFile(filename, description); return true; +#else // !wxUSE_FFILE && !wxUSE_FILE + return false; +#endif } void wxDebugReport::RemoveFile(const wxString& name) @@ -614,6 +626,8 @@ void wxDebugReportCompress::SetCompressedFileBaseName(const wxString& name) bool wxDebugReportCompress::DoProcess() { +#define HAS_FILE_STREAMS (wxUSE_STREAMS && (wxUSE_FILE || wxUSE_FFILE)) +#if HAS_FILE_STREAMS const size_t count = GetFilesCount(); if ( !count ) return false; @@ -630,7 +644,14 @@ bool wxDebugReportCompress::DoProcess() fn.SetExt("zip"); // create the streams - wxFFileOutputStream os(fn.GetFullPath(), wxT("wb")); + const wxString ofullPath = fn.GetFullPath(); +#if wxUSE_FFILE + wxFFileOutputStream os(ofullPath, wxT("wb")); +#elif wxUSE_FILE + wxFileOutputStream os(ofullPath); +#endif + if ( !os.IsOk() ) + return false; wxZipOutputStream zos(os, 9); // add all files to the ZIP one @@ -645,8 +666,12 @@ bool wxDebugReportCompress::DoProcess() if ( !zos.PutNextEntry(ze) ) return false; - const wxFileName filename(GetDirectory(), name); - wxFFileInputStream is(filename.GetFullPath()); + const wxString ifullPath = wxFileName(GetDirectory(), name).GetFullPath(); +#if wxUSE_FFILE + wxFFileInputStream is(ifullPath); +#elif wxUSE_FILE + wxFileInputStream is(ifullPath); +#endif if ( !is.IsOk() || !zos.Write(is).IsOk() ) return false; } @@ -654,9 +679,12 @@ bool wxDebugReportCompress::DoProcess() if ( !zos.Close() ) return false; - m_zipfile = fn.GetFullPath(); + m_zipfile = ofullPath; return true; +#else + return false; +#endif // HAS_FILE_STREAMS } // ---------------------------------------------------------------------------- diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp index 46847431f1..120c878474 100644 --- a/src/common/textcmn.cpp +++ b/src/common/textcmn.cpp @@ -915,6 +915,8 @@ bool wxTextAreaBase::DoLoadFile(const wxString& filename, int WXUNUSED(fileType) return true; } } +#else + (void)filename; // avoid compiler warning about unreferenced parameter #endif // wxUSE_FFILE wxLogError(_("File couldn't be loaded.")); @@ -936,6 +938,8 @@ bool wxTextAreaBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType) return true; } +#else + (void)filename; // avoid compiler warning about unreferenced parameter #endif // wxUSE_FFILE return false; diff --git a/src/generic/dbgrptg.cpp b/src/generic/dbgrptg.cpp index a6b5561a4b..accea20e70 100644 --- a/src/generic/dbgrptg.cpp +++ b/src/generic/dbgrptg.cpp @@ -39,7 +39,11 @@ #endif // WX_PRECOMP #include "wx/filename.h" -#include "wx/ffile.h" +#ifdef wxUSE_FFILE + #include "wx/ffile.h" +#else + #include "wx/file.h" +#endif #include "wx/mimetype.h" #include "wx/statline.h" @@ -432,7 +436,12 @@ void wxDebugReportDialog::OnView(wxCommandEvent& ) wxFileName fn(m_dbgrpt.GetDirectory(), m_files[sel]); wxString str; - wxFFile file(fn.GetFullPath()); + const wxString& fullPath = fn.GetFullPath(); +#if wxUSE_FFILE + wxFFile file(fullPath); +#elif wxUSE_FILE + wxFile file(fullPath); +#endif if ( file.IsOpened() && file.ReadAll(&str) ) { wxDumpPreviewDlg dlg(this, m_files[sel], str); diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 86c41cfb5a..1fbbd22999 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -8317,6 +8317,7 @@ wxString wxRichTextBuffer::GetExtWildcard(bool combine, bool save, wxArrayInt* t return wildcard; } +#if wxUSE_FFILE && wxUSE_STREAMS /// Load a file bool wxRichTextBuffer::LoadFile(const wxString& filename, wxRichTextFileType type) { @@ -8345,7 +8346,9 @@ bool wxRichTextBuffer::SaveFile(const wxString& filename, wxRichTextFileType typ else return false; } +#endif // wxUSE_FFILE && wxUSE_STREAMS +#if wxUSE_STREAMS /// Load from a stream bool wxRichTextBuffer::LoadFile(wxInputStream& stream, wxRichTextFileType type) { @@ -8374,6 +8377,7 @@ bool wxRichTextBuffer::SaveFile(wxOutputStream& stream, wxRichTextFileType type) else return false; } +#endif // wxUSE_STREAMS /// Copy the range to the clipboard bool wxRichTextBuffer::CopyToClipboard(const wxRichTextRange& range) diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 7657356d35..119a8a9d92 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -2665,7 +2665,7 @@ bool wxRichTextCtrl::RecreateBuffer(const wxSize& size) // ---------------------------------------------------------------------------- // file IO functions // ---------------------------------------------------------------------------- - +#if wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType) { SetFocusObject(& GetBuffer(), true); @@ -2707,6 +2707,7 @@ bool wxRichTextCtrl::DoSaveFile(const wxString& filename, int fileType) return false; } +#endif // wxUSE_FFILE && wxUSE_STREAMS // ---------------------------------------------------------------------------- // wxRichTextCtrl specific functionality diff --git a/src/richtext/richtextprint.cpp b/src/richtext/richtextprint.cpp index 59c331d02f..7de085df91 100644 --- a/src/richtext/richtextprint.cpp +++ b/src/richtext/richtextprint.cpp @@ -506,6 +506,7 @@ void wxRichTextPrinting::SetRichTextBufferPreview(wxRichTextBuffer* buf) m_richTextBufferPreview = buf; } +#if wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PreviewFile(const wxString& richTextFile) { SetRichTextBufferPreview(new wxRichTextBuffer); @@ -525,6 +526,7 @@ bool wxRichTextPrinting::PreviewFile(const wxString& richTextFile) p2->SetRichTextBuffer(m_richTextBufferPrinting); return DoPreview(p1, p2); } +#endif // wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) { @@ -540,6 +542,7 @@ bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) return DoPreview(p1, p2); } +#if wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PrintFile(const wxString& richTextFile, bool showPrintDialog) { SetRichTextBufferPrinting(new wxRichTextBuffer); @@ -557,6 +560,7 @@ bool wxRichTextPrinting::PrintFile(const wxString& richTextFile, bool showPrintD delete p; return ret; } +#endif // wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer& buffer, bool showPrintDialog) { diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 1dc93c27de..5577bb37fd 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -50,7 +50,7 @@ #if wxUSE_FFILE #include "wx/ffile.h" #elif wxUSE_FILE - #include "wx/ffile.h" + #include "wx/file.h" #endif #ifdef __WXGTK__ -- 2.45.2