Added on-demand image loading option to wxRTC.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2014-03-10 11:08:42 +00:00
parent 3772880ce6
commit cd3fc53163
7 changed files with 420 additions and 21 deletions

View File

@@ -2211,7 +2211,8 @@ public:
*/
wxRichTextDrawingContext(wxRichTextBuffer* buffer);
void Init() { m_buffer = NULL; m_enableVirtualAttributes = true; m_enableImages = true; m_layingOut = false; }
void Init()
{ m_buffer = NULL; m_enableVirtualAttributes = true; m_enableImages = true; m_layingOut = false; m_enableDelayedImageLoading = false; }
/**
Does this object have virtual attributes?
@@ -2293,9 +2294,22 @@ public:
bool GetLayingOut() const { return m_layingOut; }
/**
Enable or disable delayed image loading
*/
void EnableDelayedImageLoading(bool b) { m_enableDelayedImageLoading = b; }
/**
Returns @true if delayed image loading is enabled.
*/
bool GetDelayedImageLoading() const { return m_enableDelayedImageLoading; }
wxRichTextBuffer* m_buffer;
bool m_enableVirtualAttributes;
bool m_enableImages;
bool m_enableDelayedImageLoading;
bool m_layingOut;
};
@@ -2428,7 +2442,6 @@ public:
virtual bool Merge(wxRichTextObject* WXUNUSED(object), wxRichTextDrawingContext& WXUNUSED(context)) { return false; }
/**
JACS
Returns @true if this object can potentially be split, by virtue of having
different virtual attributes for individual sub-objects.
*/
@@ -4742,6 +4755,8 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
{
DECLARE_DYNAMIC_CLASS(wxRichTextImage)
public:
enum { ImageState_Unloaded, ImageState_Loaded, ImageState_Bad };
// Constructors
/**
@@ -4824,12 +4839,12 @@ public:
/**
Sets the image cache.
*/
void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; m_originalImageSize = wxSize(bitmap.GetWidth(), bitmap.GetHeight()); }
void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; m_originalImageSize = wxSize(bitmap.GetWidth(), bitmap.GetHeight()); m_imageState = ImageState_Loaded; }
/**
Resets the image cache.
*/
void ResetImageCache() { m_imageCache = wxNullBitmap; m_originalImageSize = wxSize(-1, -1); }
void ResetImageCache() { m_imageCache = wxNullBitmap; m_originalImageSize = wxSize(-1, -1); m_imageState = ImageState_Unloaded; }
/**
Returns the image block containing the raw data.
@@ -4851,7 +4866,12 @@ public:
/**
Creates a cached image at the required size.
*/
virtual bool LoadImageCache(wxDC& dc, wxRichTextDrawingContext& context, bool resetCache = false, const wxSize& parentSize = wxDefaultSize);
virtual bool LoadImageCache(wxDC& dc, wxRichTextDrawingContext& context, wxSize& retImageSize, bool resetCache = false, const wxSize& parentSize = wxDefaultSize);
/**
Do the loading and scaling
*/
virtual bool LoadAndScaleImageCache(wxImage& image, const wxSize& sz, bool delayLoading, bool& changed);
/**
Gets the original image size.
@@ -4863,10 +4883,21 @@ public:
*/
void SetOriginalImageSize(const wxSize& sz) { m_originalImageSize = sz; }
/**
Gets the image state.
*/
int GetImageState() const { return m_imageState; }
/**
Sets the image state.
*/
void SetImageState(int state) { m_imageState = state; }
protected:
wxRichTextImageBlock m_imageBlock;
wxBitmap m_imageCache;
wxSize m_originalImageSize;
int m_imageState;
};
class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand;

View File

@@ -17,7 +17,7 @@
#include "wx/scrolwin.h"
#include "wx/caret.h"
#include "wx/timer.h"
#include "wx/textctrl.h"
#if wxUSE_DRAG_AND_DROP
@@ -79,6 +79,8 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition;
#define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
// Milliseconds before layout occurs after resize
#define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
// Milliseconds before delayed image processing occurs
#define wxRICHTEXT_DEFAULT_DELAYED_IMAGE_PROCESSING_INTERVAL 200
/* Identifiers
*/
@@ -1980,6 +1982,12 @@ public:
*/
bool RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection);
/**
Overrides standard refresh in order to provoke delayed image loading.
*/
virtual void Refresh( bool eraseBackground = true,
const wxRect *rect = (const wxRect *) NULL );
/**
Sets the caret position.
@@ -2134,6 +2142,38 @@ public:
bool GetImagesEnabled() const { return m_enableImages; }
/**
Enable or disable delayed image loading
*/
void EnableDelayedImageLoading(bool b) { m_enableDelayedImageLoading = b; }
/**
Returns @true if delayed image loading is enabled.
*/
bool GetDelayedImageLoading() const { return m_enableDelayedImageLoading; }
/**
Gets the flag indicating that delayed image processing is required.
*/
bool GetDelayedImageProcessingRequired() const { return m_delayedImageProcessingRequired; }
/**
Sets the flag indicating that delayed image processing is required.
*/
void SetDelayedImageProcessingRequired(bool b) { m_delayedImageProcessingRequired = b; }
/**
Returns the last time delayed image processing was performed.
*/
wxLongLong GetDelayedImageProcessingTime() const { return m_delayedImageProcessingTime; }
/**
Sets the last time delayed image processing was performed.
*/
void SetDelayedImageProcessingTime(wxLongLong t) { m_delayedImageProcessingTime = t; }
#ifdef DOXYGEN
/**
Returns the content of the entire control as a string.
@@ -2209,6 +2249,22 @@ public:
// implement wxTextEntry methods
virtual wxString DoGetValue() const;
/**
Do delayed image loading and garbage-collect other images
*/
bool ProcessDelayedImageLoading(bool refresh);
bool ProcessDelayedImageLoading(const wxRect& screenRect, wxRichTextParagraphLayoutBox* box, int& loadCount);
/**
Request delayed image processing.
*/
void RequestDelayedImageProcessing();
/**
Respond to timer events.
*/
void OnTimer(wxTimerEvent& event);
protected:
// implement the wxTextEntry pure virtual method
virtual wxWindow *GetEditableWindow() { return this; }
@@ -2336,6 +2392,12 @@ protected:
/// Whether images are enabled for this control
bool m_enableImages;
/// Whether delayed image loading is enabled for this control
bool m_enableDelayedImageLoading;
bool m_delayedImageProcessingRequired;
wxLongLong m_delayedImageProcessingTime;
wxTimer m_delayedImageProcessingTimer;
};
#if wxUSE_DRAG_AND_DROP