Use wxDataViewRenderer::PrepareForItem() in all ports
wxOSX and wxGTK previously used their own methods for handling the enabled state and the attributes of the items being rendered, change them to reuse the same methods as the generic implementation, i.e. SetEnabled() and SetAttr() and remove the port-specific GtkSetAttr(), OSXApplyAttr() and so on. This has the advantage of ensuring that the logic is the same for all platforms (e.g. item enabled status wasn't handled in the same way in wxGTK as in the other ports previously) and hopefully makes the code simpler by cutting down on the number of virtual methods. Notice that GtkSupportsAttrs() optimization was removed as it didn't seem to be worth the bother (we basically saved a call to a virtual model method at a price of a virtual renderer method call) and preserving it would have complicated things needlessly.
This commit is contained in:
@@ -115,10 +115,6 @@ public:
|
||||
virtual bool SetValue(const wxVariant& value) = 0;
|
||||
virtual bool GetValue(wxVariant& value) const = 0;
|
||||
|
||||
virtual void SetAttr(const wxDataViewItemAttr& WXUNUSED(attr)) { }
|
||||
|
||||
virtual void SetEnabled(bool WXUNUSED(enabled)) { }
|
||||
|
||||
wxString GetVariantType() const { return m_variantType; }
|
||||
|
||||
// Prepare for rendering the value of the corresponding item in the given
|
||||
@@ -128,22 +124,12 @@ public:
|
||||
// it is only passed to this method because the existing code already has
|
||||
// it and should probably be removed in the future.
|
||||
//
|
||||
// Returns false if the value is missing (or invalid, i.e. has a wrong type
|
||||
// differing from GetVariantType() of this renderer, in which case a debug
|
||||
// error is also logged as it indicates an error in the user code).
|
||||
bool PrepareValue(const wxDataViewModel* model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column);
|
||||
|
||||
// Prepare for rendering the given item by both calling PrepareValue() and
|
||||
// setting up the attributes.
|
||||
//
|
||||
// This is currently only used in the generic version but should really be
|
||||
// used everywhere, i.e. SetEnabled() and SetAttr() should be overridden in
|
||||
// the native versions instead of adding platform-specific equivalents for
|
||||
// them as it's done currently.
|
||||
void PrepareForItem(const wxDataViewModel *model,
|
||||
const wxDataViewItem& item, unsigned column);
|
||||
// Return true if this cell is non-empty or false otherwise (and also if
|
||||
// the model returned a value of the wrong, i.e. different from our
|
||||
// GetVariantType(), type, in which case a debug error is also logged).
|
||||
bool PrepareForItem(const wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column);
|
||||
|
||||
// renderer properties:
|
||||
virtual void SetMode( wxDataViewCellMode mode ) = 0;
|
||||
@@ -195,11 +181,17 @@ public:
|
||||
int GetEffectiveAlignment() const;
|
||||
|
||||
protected:
|
||||
// These methods are called from PrepareForItem() and should do whatever is
|
||||
// needed for the current platform to ensure that the item is rendered
|
||||
// using the given attributes and enabled/disabled state.
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) = 0;
|
||||
virtual void SetEnabled(bool enabled) = 0;
|
||||
|
||||
// Called from {Cancel,Finish}Editing() to cleanup m_editorCtrl
|
||||
void DestroyEditControl();
|
||||
|
||||
// Helper of PrepareValue() also used in StartEditing(): returns the value
|
||||
// checking that its type matches our GetVariantType().
|
||||
// Helper of PrepareForItem() also used in StartEditing(): returns the
|
||||
// value checking that its type matches our GetVariantType().
|
||||
wxVariant CheckedGetValue(const wxDataViewModel* model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column) const;
|
||||
@@ -318,7 +310,7 @@ public:
|
||||
|
||||
// Store the enabled state of the item so that it can be accessed from
|
||||
// Render() via GetEnabled() if needed.
|
||||
virtual void SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
virtual void SetEnabled(bool enabled);
|
||||
bool GetEnabled() const { return m_enabled; }
|
||||
|
||||
|
||||
|
@@ -55,37 +55,21 @@ public:
|
||||
void GtkInitHandlers();
|
||||
void GtkUpdateAlignment() { GtkApplyAlignment(m_renderer); }
|
||||
|
||||
// should be overridden to return true if the renderer supports properties
|
||||
// corresponding to wxDataViewItemAttr field, see wxGtkTreeCellDataFunc()
|
||||
// for details
|
||||
virtual bool GtkSupportsAttrs() const { return false; }
|
||||
|
||||
// if GtkSupportsAttrs() returns true, this function will be called to
|
||||
// effectively set the attribute to use for rendering the next item
|
||||
//
|
||||
// it should return true if the attribute had any non-default properties
|
||||
virtual bool GtkSetAttr(const wxDataViewItemAttr& WXUNUSED(attr))
|
||||
{ return false; }
|
||||
|
||||
|
||||
// these functions are only called if GtkSupportsAttrs() returns true and
|
||||
// are used to remember whether the renderer currently uses the default
|
||||
// attributes or if we changed (and not reset them)
|
||||
bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; }
|
||||
void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
|
||||
|
||||
// return the text renderer used by this renderer for setting text cell
|
||||
// specific attributes: can return NULL if this renderer doesn't render any
|
||||
// text
|
||||
virtual GtkCellRendererText *GtkGetTextRenderer() const { return NULL; }
|
||||
|
||||
|
||||
private:
|
||||
// Change the mode at GTK level without touching m_mode, this is useful for
|
||||
// temporarily making the renderer insensitive but does mean that GetMode()
|
||||
// may return a value different from the actual GTK renderer mode.
|
||||
void GtkSetMode(wxDataViewCellMode mode);
|
||||
|
||||
protected:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) wxOVERRIDE;
|
||||
virtual void SetEnabled(bool enabled) wxOVERRIDE;
|
||||
|
||||
virtual void GtkOnCellChanged(const wxVariant& value,
|
||||
const wxDataViewItem& item,
|
||||
unsigned col);
|
||||
|
@@ -49,12 +49,11 @@ public:
|
||||
|
||||
virtual void SetAlignment( int align );
|
||||
|
||||
virtual bool GtkSupportsAttrs() const { return true; }
|
||||
virtual bool GtkSetAttr(const wxDataViewItemAttr& attr);
|
||||
|
||||
virtual GtkCellRendererText *GtkGetTextRenderer() const;
|
||||
|
||||
protected:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) wxOVERRIDE;
|
||||
|
||||
// implementation of Set/GetValue()
|
||||
bool SetTextValue(const wxString& str);
|
||||
bool GetTextValue(wxString& str) const;
|
||||
@@ -137,16 +136,6 @@ public:
|
||||
m_renderParams = renderParams;
|
||||
}
|
||||
|
||||
// we may or not support attributes, as we don't know it, return true to
|
||||
// make it possible to use them
|
||||
virtual bool GtkSupportsAttrs() const { return true; }
|
||||
|
||||
virtual bool GtkSetAttr(const wxDataViewItemAttr& attr)
|
||||
{
|
||||
SetAttr(attr);
|
||||
return !attr.IsDefault();
|
||||
}
|
||||
|
||||
virtual GtkCellRendererText *GtkGetTextRenderer() const;
|
||||
|
||||
private:
|
||||
|
@@ -83,12 +83,9 @@ public:
|
||||
const wxDataViewItem& item,
|
||||
unsigned col);
|
||||
|
||||
// called to ensure that the given attribute will be used for rendering the
|
||||
// next cell (which had been already associated with this renderer before)
|
||||
virtual void OSXApplyAttr(const wxDataViewItemAttr& attr);
|
||||
|
||||
// called to set the state of the next cell to be rendered
|
||||
virtual void OSXApplyEnabled(bool enabled);
|
||||
protected:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) wxOVERRIDE;
|
||||
virtual void SetEnabled(bool enabled) wxOVERRIDE;
|
||||
#endif // Cocoa
|
||||
|
||||
private:
|
||||
|
@@ -31,10 +31,6 @@ public:
|
||||
|
||||
virtual bool MacRender();
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
virtual void OSXApplyAttr(const wxDataViewItemAttr& attr);
|
||||
#endif // Cocoa
|
||||
|
||||
virtual wxDC* GetDC(); // creates a device context and keeps it
|
||||
void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
|
||||
|
||||
|
Reference in New Issue
Block a user