diff --git a/build/bakefiles/make_dist.mk b/build/bakefiles/make_dist.mk index 77522841f0..f0fdf624b6 100644 --- a/build/bakefiles/make_dist.mk +++ b/build/bakefiles/make_dist.mk @@ -165,6 +165,7 @@ ALL_GUI_DIST: ALL_DIST mkdir $(DISTDIR)/include/wx/generic/private mkdir $(DISTDIR)/include/wx/html mkdir $(DISTDIR)/include/wx/richtext + mkdir $(DISTDIR)/include/wx/richtext/bitmaps mkdir $(DISTDIR)/include/wx/aui mkdir $(DISTDIR)/include/wx/ribbon mkdir $(DISTDIR)/include/wx/persist @@ -182,6 +183,7 @@ ALL_GUI_DIST: ALL_DIST $(CP_P) $(INCDIR)/wx/generic/private/*.h $(DISTDIR)/include/wx/generic/private $(CP_P) $(INCDIR)/wx/html/*.h $(DISTDIR)/include/wx/html $(CP_P) $(INCDIR)/wx/richtext/*.h $(DISTDIR)/include/wx/richtext + $(CP_P) $(INCDIR)/wx/richtext/bitmaps/*.xpm $(DISTDIR)/include/wx/richtext/bitmaps $(CP_P) $(INCDIR)/wx/aui/*.h $(DISTDIR)/include/wx/aui $(CP_P) $(INCDIR)/wx/ribbon/*.h $(DISTDIR)/include/wx/ribbon $(CP_P) $(INCDIR)/wx/persist/*.h $(DISTDIR)/include/wx/persist @@ -292,6 +294,7 @@ BASE_DIST: ALL_DIST INTL_DIST mkdir $(DISTDIR)/include/wx/msw mkdir $(DISTDIR)/include/wx/html mkdir $(DISTDIR)/include/wx/richtext + mkdir $(DISTDIR)/include/wx/richtext/bitmaps mkdir $(DISTDIR)/include/wx/aui mkdir $(DISTDIR)/include/wx/ribbon mkdir $(DISTDIR)/include/wx/persist diff --git a/include/wx/richtext/bitmaps/image_placeholder24x24.xpm b/include/wx/richtext/bitmaps/image_placeholder24x24.xpm new file mode 100644 index 0000000000..9d1cdec489 --- /dev/null +++ b/include/wx/richtext/bitmaps/image_placeholder24x24.xpm @@ -0,0 +1,32 @@ +/* XPM */ +static char *image_placeholder24x24_xpm[] = { +/* columns rows colors chars-per-pixel */ +"24 24 2 1", +" c #7E97A9", +". c #EBEBFF", +/* pixels */ +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... ", +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +" ...... ......", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... ", +"...... ...... " +}; diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 94e1240836..32bb8a2076 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -2211,7 +2211,7 @@ public: */ wxRichTextDrawingContext(wxRichTextBuffer* buffer); - void Init() { m_buffer = NULL; m_enableVirtualAttributes = true; } + void Init() { m_buffer = NULL; m_enableVirtualAttributes = true; m_enableImages = true; } /** Does this object have virtual attributes? @@ -2269,8 +2269,21 @@ public: bool GetVirtualAttributesEnabled() const { return m_enableVirtualAttributes; } + /** + Enable or disable images + */ + + void EnableImages(bool b) { m_enableImages = b; } + + /** + Returns @true if images are enabled. + */ + + bool GetImagesEnabled() const { return m_enableImages; } + wxRichTextBuffer* m_buffer; bool m_enableVirtualAttributes; + bool m_enableImages; }; /** @@ -4810,7 +4823,7 @@ public: /** Creates a cached image at the required size. */ - virtual bool LoadImageCache(wxDC& dc, bool resetCache = false, const wxSize& parentSize = wxDefaultSize); + virtual bool LoadImageCache(wxDC& dc, wxRichTextDrawingContext& context, bool resetCache = false, const wxSize& parentSize = wxDefaultSize); /** Gets the original image size. diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index 74e060aa34..3f3ef8bda2 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -2122,6 +2122,18 @@ public: */ wxPoint GetFirstVisiblePoint() const; + /** + Enable or disable images + */ + + void EnableImages(bool b) { m_enableImages = b; } + + /** + Returns @true if images are enabled. + */ + + bool GetImagesEnabled() const { return m_enableImages; } + #ifdef DOXYGEN /** Returns the content of the entire control as a string. @@ -2321,6 +2333,9 @@ protected: wxSize m_lastWindowSize; int m_setupScrollbarsCount; int m_setupScrollbarsCountInOnSize; + + /// Whether images are enabled for this control + bool m_enableImages; }; #if wxUSE_DRAG_AND_DROP diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index 38834746fa..eebde53142 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -2111,7 +2111,21 @@ public: bool GetVirtualAttributesEnabled() const; + /** + Enable or disable images + */ + + void EnableImages(bool b) { m_enableImages = b; } + + /** + Returns @true if images are enabled. + */ + + bool GetImagesEnabled() const { return m_enableImages; } + wxRichTextBuffer* m_buffer; + bool m_enableVirtualAttributes; + bool m_enableImages; }; /** @@ -4642,7 +4656,7 @@ public: /** Creates a cached image at the required size. */ - virtual bool LoadImageCache(wxDC& dc, bool resetCache = false, const wxSize& parentSize = wxDefaultSize); + virtual bool LoadImageCache(wxDC& dc, wxRichTextDrawingContext& context, bool resetCache = false, const wxSize& parentSize = wxDefaultSize); protected: wxRichTextImageBlock m_imageBlock; diff --git a/interface/wx/richtext/richtextctrl.h b/interface/wx/richtext/richtextctrl.h index c8dab6f3e3..4c6bca1e5f 100644 --- a/interface/wx/richtext/richtextctrl.h +++ b/interface/wx/richtext/richtextctrl.h @@ -2032,6 +2032,18 @@ public: */ long GetFirstVisiblePosition() const; + /** + Enable or disable images + */ + + void EnableImages(bool b); + + /** + Returns @true if images are enabled. + */ + + bool GetImagesEnabled() const; + /** Returns the caret position since the default formatting was changed. As soon as this position changes, we no longer reflect the default style diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 92b77bfa1d..7b46f44496 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -42,6 +42,7 @@ #include "wx/richtext/richtextimagedlg.h" #include "wx/richtext/richtextsizepage.h" #include "wx/richtext/richtextxml.h" +#include "wx/richtext/bitmaps/image_placeholder24x24.xpm" #include "wx/listimpl.cpp" #include "wx/arrimpl.cpp" @@ -12100,11 +12101,21 @@ void wxRichTextImage::Init() } /// Create a cached image at the required size -bool wxRichTextImage::LoadImageCache(wxDC& dc, bool resetCache, const wxSize& parentSize) +bool wxRichTextImage::LoadImageCache(wxDC& dc, wxRichTextDrawingContext& context, bool resetCache, const wxSize& parentSize) { if (!m_imageBlock.IsOk()) return false; + if (!context.GetImagesEnabled()) + { + if (resetCache || !m_imageCache.IsOk()) + { + wxBitmap bitmap(image_placeholder24x24_xpm); + m_imageCache = bitmap; + } + return true; + } + // If we have an original image size, use that to compute the cached bitmap size // instead of loading the image each time. This way we can avoid loading // the image so long as the new cached bitmap size hasn't changed. @@ -12266,9 +12277,7 @@ bool wxRichTextImage::Draw(wxDC& dc, wxRichTextDrawingContext& context, const wx if (!IsShown()) return true; - // Don't need cached size AFAIK - // wxSize size = GetCachedSize(); - if (!LoadImageCache(dc)) + if (!LoadImageCache(dc, context)) return false; wxRichTextAttr attr(GetAttributes()); @@ -12298,7 +12307,7 @@ bool wxRichTextImage::Draw(wxDC& dc, wxRichTextDrawingContext& context, const wx /// Lay the item out bool wxRichTextImage::Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& WXUNUSED(parentRect), int WXUNUSED(style)) { - if (!LoadImageCache(dc)) + if (!LoadImageCache(dc, context)) return false; wxSize imageSize(m_imageCache.GetWidth(), m_imageCache.GetHeight()); @@ -12327,7 +12336,7 @@ bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, i if (!range.IsWithin(GetRange())) return false; - if (!((wxRichTextImage*)this)->LoadImageCache(dc, false, parentSize)) + if (!((wxRichTextImage*)this)->LoadImageCache(dc, context, false, parentSize)) { size.x = 0; size.y = 0; if (partialExtents) @@ -14869,7 +14878,10 @@ wxRichTextDrawingContext::wxRichTextDrawingContext(wxRichTextBuffer* buffer) Init(); m_buffer = buffer; if (m_buffer && m_buffer->GetRichTextCtrl()) + { EnableVirtualAttributes(m_buffer->GetRichTextCtrl()->GetVirtualAttributesEnabled()); + m_enableImages = m_buffer->GetRichTextCtrl()->GetImagesEnabled(); + } } bool wxRichTextDrawingContext::HasVirtualAttributes(wxRichTextObject* obj) const diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 6aee0626f7..2cb5e7b505 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -380,6 +380,8 @@ void wxRichTextCtrl::Init() // Scrollbar hysteresis detection m_setupScrollbarsCount = 0; m_setupScrollbarsCountInOnSize = 0; + + m_enableImages = true; } void wxRichTextCtrl::DoThaw()