Added ability to disable images in wxRTC for performance or image corruption reasons

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75881 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2014-02-13 12:32:46 +00:00
parent 5e989e67fc
commit f95ee1bade
8 changed files with 112 additions and 9 deletions

View File

@ -165,6 +165,7 @@ ALL_GUI_DIST: ALL_DIST
mkdir $(DISTDIR)/include/wx/generic/private mkdir $(DISTDIR)/include/wx/generic/private
mkdir $(DISTDIR)/include/wx/html mkdir $(DISTDIR)/include/wx/html
mkdir $(DISTDIR)/include/wx/richtext mkdir $(DISTDIR)/include/wx/richtext
mkdir $(DISTDIR)/include/wx/richtext/bitmaps
mkdir $(DISTDIR)/include/wx/aui mkdir $(DISTDIR)/include/wx/aui
mkdir $(DISTDIR)/include/wx/ribbon mkdir $(DISTDIR)/include/wx/ribbon
mkdir $(DISTDIR)/include/wx/persist 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/generic/private/*.h $(DISTDIR)/include/wx/generic/private
$(CP_P) $(INCDIR)/wx/html/*.h $(DISTDIR)/include/wx/html $(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/*.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/aui/*.h $(DISTDIR)/include/wx/aui
$(CP_P) $(INCDIR)/wx/ribbon/*.h $(DISTDIR)/include/wx/ribbon $(CP_P) $(INCDIR)/wx/ribbon/*.h $(DISTDIR)/include/wx/ribbon
$(CP_P) $(INCDIR)/wx/persist/*.h $(DISTDIR)/include/wx/persist $(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/msw
mkdir $(DISTDIR)/include/wx/html mkdir $(DISTDIR)/include/wx/html
mkdir $(DISTDIR)/include/wx/richtext mkdir $(DISTDIR)/include/wx/richtext
mkdir $(DISTDIR)/include/wx/richtext/bitmaps
mkdir $(DISTDIR)/include/wx/aui mkdir $(DISTDIR)/include/wx/aui
mkdir $(DISTDIR)/include/wx/ribbon mkdir $(DISTDIR)/include/wx/ribbon
mkdir $(DISTDIR)/include/wx/persist mkdir $(DISTDIR)/include/wx/persist

View File

@ -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 */
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... ",
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
" ...... ......",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... ",
"...... ...... "
};

View File

@ -2211,7 +2211,7 @@ public:
*/ */
wxRichTextDrawingContext(wxRichTextBuffer* buffer); 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? Does this object have virtual attributes?
@ -2269,8 +2269,21 @@ public:
bool GetVirtualAttributesEnabled() const { return m_enableVirtualAttributes; } 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; wxRichTextBuffer* m_buffer;
bool m_enableVirtualAttributes; bool m_enableVirtualAttributes;
bool m_enableImages;
}; };
/** /**
@ -4810,7 +4823,7 @@ public:
/** /**
Creates a cached image at the required size. 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. Gets the original image size.

View File

@ -2122,6 +2122,18 @@ public:
*/ */
wxPoint GetFirstVisiblePoint() const; 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 #ifdef DOXYGEN
/** /**
Returns the content of the entire control as a string. Returns the content of the entire control as a string.
@ -2321,6 +2333,9 @@ protected:
wxSize m_lastWindowSize; wxSize m_lastWindowSize;
int m_setupScrollbarsCount; int m_setupScrollbarsCount;
int m_setupScrollbarsCountInOnSize; int m_setupScrollbarsCountInOnSize;
/// Whether images are enabled for this control
bool m_enableImages;
}; };
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP

View File

@ -2111,7 +2111,21 @@ public:
bool GetVirtualAttributesEnabled() const; 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; wxRichTextBuffer* m_buffer;
bool m_enableVirtualAttributes;
bool m_enableImages;
}; };
/** /**
@ -4642,7 +4656,7 @@ public:
/** /**
Creates a cached image at the required size. 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: protected:
wxRichTextImageBlock m_imageBlock; wxRichTextImageBlock m_imageBlock;

View File

@ -2032,6 +2032,18 @@ public:
*/ */
long GetFirstVisiblePosition() const; 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 Returns the caret position since the default formatting was changed. As
soon as this position changes, we no longer reflect the default style soon as this position changes, we no longer reflect the default style

View File

@ -42,6 +42,7 @@
#include "wx/richtext/richtextimagedlg.h" #include "wx/richtext/richtextimagedlg.h"
#include "wx/richtext/richtextsizepage.h" #include "wx/richtext/richtextsizepage.h"
#include "wx/richtext/richtextxml.h" #include "wx/richtext/richtextxml.h"
#include "wx/richtext/bitmaps/image_placeholder24x24.xpm"
#include "wx/listimpl.cpp" #include "wx/listimpl.cpp"
#include "wx/arrimpl.cpp" #include "wx/arrimpl.cpp"
@ -12100,11 +12101,21 @@ void wxRichTextImage::Init()
} }
/// Create a cached image at the required size /// 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()) if (!m_imageBlock.IsOk())
return false; 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 // 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 // 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. // 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()) if (!IsShown())
return true; return true;
// Don't need cached size AFAIK if (!LoadImageCache(dc, context))
// wxSize size = GetCachedSize();
if (!LoadImageCache(dc))
return false; return false;
wxRichTextAttr attr(GetAttributes()); wxRichTextAttr attr(GetAttributes());
@ -12298,7 +12307,7 @@ bool wxRichTextImage::Draw(wxDC& dc, wxRichTextDrawingContext& context, const wx
/// Lay the item out /// Lay the item out
bool wxRichTextImage::Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& WXUNUSED(parentRect), int WXUNUSED(style)) 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; return false;
wxSize imageSize(m_imageCache.GetWidth(), m_imageCache.GetHeight()); 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())) if (!range.IsWithin(GetRange()))
return false; return false;
if (!((wxRichTextImage*)this)->LoadImageCache(dc, false, parentSize)) if (!((wxRichTextImage*)this)->LoadImageCache(dc, context, false, parentSize))
{ {
size.x = 0; size.y = 0; size.x = 0; size.y = 0;
if (partialExtents) if (partialExtents)
@ -14869,7 +14878,10 @@ wxRichTextDrawingContext::wxRichTextDrawingContext(wxRichTextBuffer* buffer)
Init(); Init();
m_buffer = buffer; m_buffer = buffer;
if (m_buffer && m_buffer->GetRichTextCtrl()) if (m_buffer && m_buffer->GetRichTextCtrl())
{
EnableVirtualAttributes(m_buffer->GetRichTextCtrl()->GetVirtualAttributesEnabled()); EnableVirtualAttributes(m_buffer->GetRichTextCtrl()->GetVirtualAttributesEnabled());
m_enableImages = m_buffer->GetRichTextCtrl()->GetImagesEnabled();
}
} }
bool wxRichTextDrawingContext::HasVirtualAttributes(wxRichTextObject* obj) const bool wxRichTextDrawingContext::HasVirtualAttributes(wxRichTextObject* obj) const

View File

@ -380,6 +380,8 @@ void wxRichTextCtrl::Init()
// Scrollbar hysteresis detection // Scrollbar hysteresis detection
m_setupScrollbarsCount = 0; m_setupScrollbarsCount = 0;
m_setupScrollbarsCountInOnSize = 0; m_setupScrollbarsCountInOnSize = 0;
m_enableImages = true;
} }
void wxRichTextCtrl::DoThaw() void wxRichTextCtrl::DoThaw()