Make wxDataViewCtrl::GetColumnPosition() return the index under MSW as per GTK and the docs (fixes #12129), give immediate visual feedback after calling e.g. wxDataViewColumn::SetHidden(true) under MSW, also per GTK+ and as I'd expect. Make GTK+ control emit header click events also for non-reorderable columns. Add a few tests for wxDataViewColumn::SetHidden() and wxDataViewCtrl::GetColumnPosition()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64549 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
dca0afc73c
commit
5d9e160561
@ -52,38 +52,35 @@ public:
|
||||
}
|
||||
|
||||
// implement wxHeaderColumnBase methods
|
||||
virtual void SetTitle(const wxString& title) { m_title = title; }
|
||||
virtual void SetTitle(const wxString& title) { m_title = title; UpdateDisplay(); }
|
||||
virtual wxString GetTitle() const { return m_title; }
|
||||
|
||||
virtual void SetWidth(int width) { m_width = width; }
|
||||
virtual void SetWidth(int width) { m_width = width; UpdateDisplay(); }
|
||||
virtual int GetWidth() const { return m_width; }
|
||||
|
||||
virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
|
||||
virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; UpdateDisplay(); }
|
||||
virtual int GetMinWidth() const { return m_minWidth; }
|
||||
|
||||
virtual void SetAlignment(wxAlignment align) { m_align = align; }
|
||||
virtual void SetAlignment(wxAlignment align) { m_align = align; UpdateDisplay(); }
|
||||
virtual wxAlignment GetAlignment() const { return m_align; }
|
||||
|
||||
virtual void SetFlags(int flags) { m_flags = flags; }
|
||||
virtual void SetFlags(int flags) { m_flags = flags; UpdateDisplay(); }
|
||||
virtual int GetFlags() const { return m_flags; }
|
||||
|
||||
virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
|
||||
virtual void SetAsSortKey(bool sort = true) { m_sort = sort; UpdateDisplay(); }
|
||||
virtual bool IsSortKey() const { return m_sort; }
|
||||
|
||||
virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
|
||||
virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; UpdateDisplay(); }
|
||||
virtual bool IsSortOrderAscending() const { return m_sortAscending; }
|
||||
|
||||
virtual void SetBitmap( const wxBitmap& bitmap ) { wxDataViewColumnBase::SetBitmap(bitmap); UpdateDisplay(); }
|
||||
|
||||
|
||||
private:
|
||||
// common part of all ctors
|
||||
void Init(int width, wxAlignment align, int flags)
|
||||
{
|
||||
m_width = width == wxCOL_WIDTH_DEFAULT ? wxDVC_DEFAULT_WIDTH : width;
|
||||
m_minWidth = 0;
|
||||
m_align = align;
|
||||
m_flags = flags;
|
||||
m_sort = false;
|
||||
m_sortAscending = true;
|
||||
}
|
||||
void Init(int width, wxAlignment align, int flags);
|
||||
|
||||
void UpdateDisplay();
|
||||
|
||||
wxString m_title;
|
||||
int m_width,
|
||||
|
@ -111,6 +111,7 @@ public: // event handlers
|
||||
void OnEditingDone( wxDataViewEvent &event );
|
||||
|
||||
void OnHeaderClick( wxDataViewEvent &event );
|
||||
void OnAttrHeaderClick( wxDataViewEvent &event );
|
||||
void OnHeaderRightClick( wxDataViewEvent &event );
|
||||
void OnSorted( wxDataViewEvent &event );
|
||||
|
||||
@ -119,6 +120,8 @@ public: // event handlers
|
||||
void OnRightClick( wxMouseEvent &event );
|
||||
void OnGoto( wxCommandEvent &event);
|
||||
void OnAddMany( wxCommandEvent &event);
|
||||
void OnHideAttributes( wxCommandEvent &event);
|
||||
void OnShowAttributes( wxCommandEvent &event);
|
||||
|
||||
void OnBeginDrag( wxDataViewEvent &event );
|
||||
void OnDropPossible( wxDataViewEvent &event );
|
||||
@ -139,6 +142,7 @@ private:
|
||||
// other data:
|
||||
|
||||
wxDataViewColumn* m_col;
|
||||
wxDataViewColumn* m_attributes;
|
||||
|
||||
wxTextCtrl* m_log;
|
||||
wxLog *m_logOld;
|
||||
@ -264,6 +268,7 @@ enum
|
||||
// control IDs
|
||||
|
||||
ID_MUSIC_CTRL = 50,
|
||||
ID_ATTR_CTRL = 51,
|
||||
|
||||
ID_ADD_MOZART = 100,
|
||||
ID_DELETE_MUSIC = 101,
|
||||
@ -276,6 +281,9 @@ enum
|
||||
ID_DELETE_LIST = 201,
|
||||
ID_GOTO = 202,
|
||||
ID_ADD_MANY = 203,
|
||||
ID_HIDE_ATTRIBUTES = 204,
|
||||
ID_SHOW_ATTRIBUTES = 205,
|
||||
|
||||
// Fourth page.
|
||||
ID_DELETE_TREE_ITEM = 400,
|
||||
ID_DELETE_ALL_TREE_ITEMS = 401,
|
||||
@ -305,6 +313,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
|
||||
EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
|
||||
EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany)
|
||||
EVT_BUTTON( ID_HIDE_ATTRIBUTES, MyFrame::OnHideAttributes)
|
||||
EVT_BUTTON( ID_SHOW_ATTRIBUTES, MyFrame::OnShowAttributes)
|
||||
// Fourth page.
|
||||
EVT_BUTTON( ID_DELETE_TREE_ITEM, MyFrame::OnDeleteTreeItem )
|
||||
EVT_BUTTON( ID_DELETE_ALL_TREE_ITEMS, MyFrame::OnDeleteAllTreeItems )
|
||||
@ -335,6 +345,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL, MyFrame::OnDrop )
|
||||
|
||||
EVT_RIGHT_UP(MyFrame::OnRightClick)
|
||||
|
||||
EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_ATTR_CTRL, MyFrame::OnAttrHeaderClick)
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h):
|
||||
@ -415,10 +428,12 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
||||
BuildDataViewCtrl(secondPanel, 1); // sets m_ctrl[1]
|
||||
|
||||
wxBoxSizer *button_sizer2 = new wxBoxSizer( wxHORIZONTAL );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_PREPEND_LIST,"Prepend"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_ADD_MANY, "Add 1000"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_PREPEND_LIST,"Prepend"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_ADD_MANY, "Add 1000"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_HIDE_ATTRIBUTES, "Hide attributes"), 0, wxALL, 10 );
|
||||
button_sizer2->Add( new wxButton( secondPanel, ID_SHOW_ATTRIBUTES, "Show attributes"), 0, wxALL, 10 );
|
||||
|
||||
wxSizer *secondPanelSz = new wxBoxSizer( wxVERTICAL );
|
||||
secondPanelSz->Add(m_ctrl[1], 1, wxGROW|wxALL, 5);
|
||||
@ -569,7 +584,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
||||
case 1:
|
||||
{
|
||||
wxASSERT(!m_ctrl[1] && !m_list_model);
|
||||
m_ctrl[1] = new wxDataViewCtrl( parent, wxID_ANY, wxDefaultPosition,
|
||||
m_ctrl[1] = new wxDataViewCtrl( parent, ID_ATTR_CTRL, wxDefaultPosition,
|
||||
wxDefaultSize, style );
|
||||
|
||||
m_list_model = new MyListModel;
|
||||
@ -582,11 +597,15 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
||||
m_ctrl[1]->AppendIconTextColumn("icon",
|
||||
MyListModel::Col_IconText,
|
||||
wxDATAVIEW_CELL_EDITABLE);
|
||||
m_ctrl[1]->AppendColumn(
|
||||
|
||||
m_attributes =
|
||||
new wxDataViewColumn("attributes",
|
||||
new wxDataViewTextRenderer,
|
||||
MyListModel::Col_TextWithAttr)
|
||||
);
|
||||
MyListModel::Col_TextWithAttr,
|
||||
80,
|
||||
wxALIGN_RIGHT,
|
||||
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
||||
m_ctrl[1]->AppendColumn( m_attributes );
|
||||
|
||||
m_ctrl[1]->AppendColumn(
|
||||
new wxDataViewColumn("custom renderer",
|
||||
@ -995,6 +1014,21 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event )
|
||||
m_ctrl[0]->PopupMenu(&menu);
|
||||
}
|
||||
|
||||
void MyFrame::OnAttrHeaderClick( wxDataViewEvent &event )
|
||||
{
|
||||
// we need to skip the event to let the default behaviour of sorting by
|
||||
// this column when it is clicked to take place
|
||||
event.Skip();
|
||||
|
||||
if (!m_log)
|
||||
return;
|
||||
|
||||
int pos = m_ctrl[1]->GetColumnPosition( event.GetDataViewColumn() );
|
||||
|
||||
wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
|
||||
wxLogMessage( "Column title: %s Column width: %d", event.GetDataViewColumn()->GetTitle(), event.GetDataViewColumn()->GetWidth() );
|
||||
}
|
||||
|
||||
void MyFrame::OnHeaderClick( wxDataViewEvent &event )
|
||||
{
|
||||
// we need to skip the event to let the default behaviour of sorting by
|
||||
@ -1068,6 +1102,16 @@ void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event))
|
||||
m_list_model->AddMany();
|
||||
}
|
||||
|
||||
void MyFrame::OnHideAttributes(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_attributes->SetHidden(true);
|
||||
}
|
||||
|
||||
void MyFrame::OnShowAttributes(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
m_attributes->SetHidden(false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MyFrame - event handlers for the fourth page
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -53,8 +53,14 @@
|
||||
// classes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxDataViewColumn;
|
||||
class wxDataViewHeaderWindow;
|
||||
class wxDataViewCtrl;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// classes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static const int SCROLL_UNIT_X = 15;
|
||||
|
||||
// the cell padding on the left/right
|
||||
@ -76,6 +82,29 @@ static wxDataViewModel* g_model;
|
||||
static int g_column = -2;
|
||||
static bool g_asending = true;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewColumn
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void wxDataViewColumn::Init(int width, wxAlignment align, int flags)
|
||||
{
|
||||
m_width = width == wxCOL_WIDTH_DEFAULT ? wxDVC_DEFAULT_WIDTH : width;
|
||||
m_minWidth = 0;
|
||||
m_align = align;
|
||||
m_flags = flags;
|
||||
m_sort = false;
|
||||
m_sortAscending = true;
|
||||
}
|
||||
|
||||
void wxDataViewColumn::UpdateDisplay()
|
||||
{
|
||||
if (m_owner)
|
||||
{
|
||||
int idx = m_owner->GetColumnIndex( this );
|
||||
m_owner->OnColumnChange( idx );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewHeaderWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -4046,6 +4075,18 @@ bool wxDataViewCtrl::ClearColumns()
|
||||
|
||||
int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
|
||||
{
|
||||
#if 1
|
||||
unsigned int len = GetColumnCount();
|
||||
for ( unsigned int i = 0; i < len; i++ )
|
||||
{
|
||||
wxDataViewColumn * col = GetColumnAt(i);
|
||||
if (column==col)
|
||||
return i;
|
||||
}
|
||||
|
||||
return wxNOT_FOUND;
|
||||
#else
|
||||
// This returns the position in pixels which is not what we want.
|
||||
int ret = 0,
|
||||
dummy = 0;
|
||||
unsigned int len = GetColumnCount();
|
||||
@ -4062,6 +4103,7 @@ int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
|
||||
|
@ -2842,7 +2842,7 @@ void wxDataViewColumn::OnInternalIdle()
|
||||
{
|
||||
if (m_isConnected)
|
||||
return;
|
||||
|
||||
|
||||
if (GTK_WIDGET_REALIZED(GetOwner()->m_treeview))
|
||||
{
|
||||
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
|
||||
@ -2851,6 +2851,9 @@ void wxDataViewColumn::OnInternalIdle()
|
||||
g_signal_connect(column->button, "button_press_event",
|
||||
G_CALLBACK (gtk_dataview_header_button_press_callback), this);
|
||||
|
||||
// otherwise the event will be blocked by GTK+
|
||||
gtk_tree_view_column_set_clickable( column, TRUE );
|
||||
|
||||
m_isConnected = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user