Support renderer::LeftClick() in generic code, removed unsupported RightClick(), corrected docs, added test to sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53020 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2008-04-05 12:09:15 +00:00
parent bfac616654
commit 0bdfa38835
5 changed files with 91 additions and 51 deletions

View File

@@ -150,9 +150,6 @@ public:
virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) ) wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
{ return false; } { return false; }
virtual bool RightClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
{ return false; }
virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) ) wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
{ return false; } { return false; }

View File

@@ -580,7 +580,8 @@ public:
~wxDataViewCustomRenderer(); ~wxDataViewCustomRenderer();
/** /**
Override this to react to double clicks or ENTER. Override this to react to double clicks or ENTER. This method will
only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
*/ */
virtual bool Activate( wxRect cell, virtual bool Activate( wxRect cell,
wxDataViewModel* model, wxDataViewModel* model,
@@ -621,7 +622,8 @@ public:
virtual bool HasEditorCtrl(); virtual bool HasEditorCtrl();
/** /**
Overrride this to react to a left click. Overrride this to react to a left click. This method will
only be called in wxDATAVIEW_CELL_ACTIVATABLE mode.
*/ */
virtual bool LeftClick( wxPoint cursor, virtual bool LeftClick( wxPoint cursor,
wxRect cell, wxRect cell,
@@ -646,16 +648,8 @@ public:
wxDC* dc, int state); wxDC* dc, int state);
/** /**
Overrride this to react to a right click. Overrride this to start a drag operation. Not yet
*/ supported
virtual bool RightClick(wxPoint cursor,
wxRect cell,
wxDataViewModel* model,
const wxDataViewItem & item,
unsigned int col);
/**
Overrride this to start a drag operation.
*/ */
virtual bool StartDrag(wxPoint cursor, wxRect cell, virtual bool StartDrag(wxPoint cursor, wxRect cell,
wxDataViewModel* model, wxDataViewModel* model,

View File

@@ -562,6 +562,50 @@ public:
int m_virtualItems; int m_virtualItems;
}; };
// -------------------------------------
// MyCustomRenderer
// -------------------------------------
class MyCustomRenderer: public wxDataViewCustomRenderer
{
public:
MyCustomRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
// MyCustomRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int alignment = wxDVR_DEFAULT_ALIGNMENT ) :
wxDataViewCustomRenderer( wxString("long"), mode, alignment ) { }
virtual bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
{
dc->SetBrush( *wxRED_BRUSH );
dc->SetPen( *wxTRANSPARENT_PEN );
dc->DrawRectangle( rect );
return true;
}
virtual bool Activate( wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
{
wxLogMessage( wxT("MyCustomRenderer Activate()") );
return false;
}
virtual bool LeftClick( wxPoint cursor, wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
{
wxLogMessage( wxT("MyCustomRenderer LeftClick( %d, %d )"), cursor.x, cursor.y );
return false;
}
virtual wxSize GetSize() const
{
return wxSize(40,20);
}
virtual bool SetValue( const wxVariant &WXUNUSED(value) ) { return true; }
virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
};
// ------------------------------------- // -------------------------------------
// MyApp // MyApp
// ------------------------------------- // -------------------------------------
@@ -645,7 +689,7 @@ bool MyApp::OnInit(void)
// build the first frame // build the first frame
MyFrame *frame = MyFrame *frame =
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 540); new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 1000, 540);
frame->Show(true); frame->Show(true);
SetTopWindow(frame); SetTopWindow(frame);
@@ -748,19 +792,26 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
#if 0 #if 0
// Call this and sorting is enabled // Call this and sorting is enabled
// immediatly upon start up. // immediatly upon start up.
wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, DEFAULT_ALIGN,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE); wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE);
col->SetSortOrder( true ); col->SetSortOrder( true );
#else #else
m_musicCtrl->AppendTextColumn(wxT("Title"),0,wxDATAVIEW_CELL_INERT,200,DEFAULT_ALIGN,wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE); m_musicCtrl->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT, 200, DEFAULT_ALIGN,
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE);
#endif #endif
m_musicCtrl->AppendTextColumn( wxT("Artist"), 1, wxDATAVIEW_CELL_EDITABLE, 150, m_musicCtrl->AppendTextColumn( wxT("Artist"), 1, wxDATAVIEW_CELL_EDITABLE, 150, DEFAULT_ALIGN,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE); wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE);
wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010 ); wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010 );
wxDataViewColumn *column = new wxDataViewColumn( wxT("year"), sr, 2, -1, wxALIGN_CENTRE, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE); wxDataViewColumn *column1 = new wxDataViewColumn( wxT("year"), sr, 2, -1, wxALIGN_CENTRE,
m_musicCtrl->AppendColumn( column ); wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
m_musicCtrl->AppendColumn( column1 );
MyCustomRenderer *cr = new MyCustomRenderer;
wxDataViewColumn *column2 = new wxDataViewColumn( wxT("custom"), cr, 2, -1, wxALIGN_CENTRE,
wxDATAVIEW_COL_RESIZABLE );
m_musicCtrl->AppendColumn( column2 );
data_sizer->Add( m_musicCtrl, 3, wxGROW ); data_sizer->Add( m_musicCtrl, 3, wxGROW );
@@ -778,8 +829,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT, 60 ); m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT, 60 );
wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr; wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
column = new wxDataViewColumn(wxT("attributes"), ra, 2 ); wxDataViewColumn *column3 = new wxDataViewColumn(wxT("attributes"), ra, 2 );
m_listCtrl->AppendColumn( column ); m_listCtrl->AppendColumn( column3 );
data_sizer->Add( m_listCtrl, 2, wxGROW ); data_sizer->Add( m_listCtrl, 2, wxGROW );
@@ -823,7 +874,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
treectrl->AssociateModel( store ); treectrl->AssociateModel( store );
store->DecRef(); store->DecRef();
treectrl->AppendIconTextColumn(wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1 ); treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0,
wxDATAVIEW_COL_RESIZABLE );
bottom_sizer->Add( treectrl, 1 ); bottom_sizer->Add( treectrl, 1 );
@@ -983,6 +1035,7 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event )
wxString title = m_music_model->GetTitle( event.GetItem() ); wxString title = m_music_model->GetTitle( event.GetItem() );
wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData()); wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData());
// wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),title.GetData(), event.GetValue().GetString());
} }
void MyFrame::OnHeaderClick( wxDataViewEvent &event ) void MyFrame::OnHeaderClick( wxDataViewEvent &event )

View File

@@ -3671,7 +3671,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
if (m_lastOnSame && !expander && !ignore_other_columns) if (m_lastOnSame && !expander && !ignore_other_columns)
{ {
if ((col == m_currentCol) && (current == m_currentRow) && if ((col == m_currentCol) && (current == m_currentRow) &&
(cell->GetMode() == wxDATAVIEW_CELL_EDITABLE) ) (cell->GetMode() & wxDATAVIEW_CELL_EDITABLE) )
{ {
m_renameTimer->Start( 100, true ); m_renameTimer->Start( 100, true );
} }
@@ -3704,28 +3704,18 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
SendSelectionChangedEvent(GetItemByRow( m_currentRow ) ); SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
} }
// notify cell about right click
wxVariant value; wxVariant value;
model->GetValue( value, item, col->GetModelColumn() ); model->GetValue( value, item, col->GetModelColumn() );
cell->SetValue( value ); wxWindow *parent = GetParent();
wxRect cell_rect( xpos, current * m_lineHeight, wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId());
col->GetWidth(), m_lineHeight ); le.SetItem( item );
if (!cell->RightClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn())) le.SetEventObject(parent);
{ le.SetModel(GetOwner()->GetModel());
wxWindow *parent = GetParent(); le.SetValue(value);
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, parent->GetId()); parent->GetEventHandler()->ProcessEvent(le);
le.SetItem( item );
le.SetEventObject(parent);
le.SetModel(GetOwner()->GetModel());
le.SetValue(value);
parent->GetEventHandler()->ProcessEvent(le);
}
} }
else if (event.MiddleDown()) else if (event.MiddleDown())
{ {
// notify cell about middle click
// cell->...
} }
if (event.LeftDown() || forceClick) if (event.LeftDown() || forceClick)
{ {
@@ -3783,7 +3773,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
wxFAIL_MSG( _T("how did we get here?") ); wxFAIL_MSG( _T("how did we get here?") );
} }
} }
if (m_currentRow != oldCurrentRow) if (m_currentRow != oldCurrentRow)
RefreshRow( oldCurrentRow ); RefreshRow( oldCurrentRow );
@@ -3794,6 +3784,18 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
m_lastOnSame = !forceClick && ((col == oldCurrentCol) && m_lastOnSame = !forceClick && ((col == oldCurrentCol) &&
(current == oldCurrentRow)) && oldWasSelected; (current == oldCurrentRow)) && oldWasSelected;
// Call LeftClick after everything else as under GTK+
if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
{
// notify cell about right click
wxVariant value;
model->GetValue( value, item, col->GetModelColumn() );
cell->SetValue( value );
wxRect cell_rect( xpos, current * m_lineHeight,
col->GetWidth(), m_lineHeight );
/* ignore ret */ cell->LeftClick( event.GetPosition(), cell_rect, model, item, col->GetModelColumn());
}
} }
} }

View File

@@ -1172,12 +1172,6 @@ gtk_wx_cell_renderer_activate(
if (cell->Activate( renderrect, model, item, model_col )) if (cell->Activate( renderrect, model, item, model_col ))
ret = true; ret = true;
} }
if (button_event->button == 3)
{
if (cell->RightClick( pt, renderrect, model, item, model_col ))
ret = true;
}
wxrenderer->last_click = button_event->time; wxrenderer->last_click = button_event->time;
return ret; return ret;