UPDATE 1:
I find some workaround, it's kind of dirty. if you check the wxDataViewListCtrl documentation, you will find that it cannot detect mouse left button down event, especially for GTK.
So I just do everything in the custom button render
Code: Select all
#include <wx/dataview.h>
#include <wx/timer.h>
class wxDataViewMyButtonRenderer: public wxDataViewCustomRenderer, public wxTimer
{
public:
wxDataViewMyButtonRenderer( const wxString &varianttype = wxT("wxString"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect, wxDC*, int);
virtual wxSize GetSize() const;
virtual void Notify();
void SetParent(wxWindow*);
// Implementation only, don't use nor override
virtual bool ActivateCell(const wxRect& rect,
wxDataViewModel *model,
const wxDataViewItem& item,
unsigned int col,
const wxMouseEvent *mouseEvent);
private:
wxString m_value;
bool m_button_clicked;
wxRect m_button_rect;
wxDC* m_button_dc;
wxWindow* m_parent;
// wxTimer m_button_timer;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewMyButtonRenderer)
};
There is no mouse up event, so I have to hack, basically start a wxTimer when button clicked and draw the button up effect after about 1 second in Notify()
To draw the button up effect, I need ask the parent data view list to refresh itself, so that the button's Render() method has a chance to be called. That's why we need SetParent().
If anyone has better idea, please enlighten me.
UPDATE 2:
I added more tech details at my blog:
http://blog.binchen.org/?p=1118