Implement basic MVC logic (change an item in one
view and all views update themselves) and made wxDataViewToggleCell react to mouse clicks as a test for that (generic code). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38298 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
acd8510fd2
commit
0fdc2321bc
@ -220,6 +220,7 @@ public:
|
|||||||
virtual bool Validate( wxVariant &value ) { return true; }
|
virtual bool Validate( wxVariant &value ) { return true; }
|
||||||
|
|
||||||
wxString GetVariantType() { return m_variantType; }
|
wxString GetVariantType() { return m_variantType; }
|
||||||
|
wxDataViewCellMode GetMode() { return m_mode; }
|
||||||
|
|
||||||
void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
|
void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
|
||||||
wxDataViewColumn* GetOwner() { return m_owner; }
|
wxDataViewColumn* GetOwner() { return m_owner; }
|
||||||
|
@ -112,6 +112,7 @@ public:
|
|||||||
bool GetValue( wxVariant &value );
|
bool GetValue( wxVariant &value );
|
||||||
|
|
||||||
bool Render( wxRect cell, wxDC *dc, int state );
|
bool Render( wxRect cell, wxDC *dc, int state );
|
||||||
|
bool Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row );
|
||||||
wxSize GetSize();
|
wxSize GetSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -376,7 +376,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
|||||||
dataview_right->AppendColumn( column );
|
dataview_right->AppendColumn( column );
|
||||||
dataview_right->AppendTextColumn( wxT("first"), 0 );
|
dataview_right->AppendTextColumn( wxT("first"), 0 );
|
||||||
dataview_right->AppendTextColumn( wxT("second"), 1 );
|
dataview_right->AppendTextColumn( wxT("second"), 1 );
|
||||||
wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_EDITABLE );
|
wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE );
|
||||||
column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3 );
|
column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3 );
|
||||||
dataview_right->AppendColumn( column );
|
dataview_right->AppendColumn( column );
|
||||||
|
|
||||||
|
@ -252,7 +252,10 @@ bool wxDataViewToggleCell::Render( wxRect cell, wxDC *dc, int state )
|
|||||||
{
|
{
|
||||||
// User wxRenderer here
|
// User wxRenderer here
|
||||||
|
|
||||||
|
if (GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)
|
||||||
dc->SetPen( *wxBLACK_PEN );
|
dc->SetPen( *wxBLACK_PEN );
|
||||||
|
else
|
||||||
|
dc->SetPen( *wxGREY_PEN );
|
||||||
dc->SetBrush( *wxTRANSPARENT_BRUSH );
|
dc->SetBrush( *wxTRANSPARENT_BRUSH );
|
||||||
wxRect rect;
|
wxRect rect;
|
||||||
rect.x = cell.x + cell.width/2 - 10;
|
rect.x = cell.x + cell.width/2 - 10;
|
||||||
@ -273,6 +276,15 @@ bool wxDataViewToggleCell::Render( wxRect cell, wxDC *dc, int state )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxDataViewToggleCell::Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row )
|
||||||
|
{
|
||||||
|
bool value = !m_toggle;
|
||||||
|
wxVariant variant = value;
|
||||||
|
model->SetValue( variant, col, row );
|
||||||
|
model->ValueChanged( col, row );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
wxSize wxDataViewToggleCell::GetSize()
|
wxSize wxDataViewToggleCell::GetSize()
|
||||||
{
|
{
|
||||||
return wxSize(20,20);
|
return wxSize(20,20);
|
||||||
@ -595,7 +607,11 @@ bool wxDataViewMainWindow::RowChanged( size_t row )
|
|||||||
|
|
||||||
bool wxDataViewMainWindow::ValueChanged( size_t col, size_t row )
|
bool wxDataViewMainWindow::ValueChanged( size_t col, size_t row )
|
||||||
{
|
{
|
||||||
return false;
|
wxRect rect( 0, row*m_lineHeight, 10000, m_lineHeight );
|
||||||
|
m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
|
||||||
|
Refresh( true, &rect );
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDataViewMainWindow::RowsReordered( size_t *new_order )
|
bool wxDataViewMainWindow::RowsReordered( size_t *new_order )
|
||||||
@ -699,6 +715,47 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &event )
|
|||||||
|
|
||||||
void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
||||||
{
|
{
|
||||||
|
int x = event.GetX();
|
||||||
|
int y = event.GetY();
|
||||||
|
m_owner->CalcUnscrolledPosition( x, y, &x, &y );
|
||||||
|
|
||||||
|
wxDataViewColumn *col = NULL;
|
||||||
|
|
||||||
|
int xpos = 0;
|
||||||
|
size_t cols = GetOwner()->GetNumberOfColumns();
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < cols; i++)
|
||||||
|
{
|
||||||
|
wxDataViewColumn *c = GetOwner()->GetColumn( i );
|
||||||
|
if (x < xpos + c->GetWidth())
|
||||||
|
{
|
||||||
|
col = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xpos += c->GetWidth();
|
||||||
|
}
|
||||||
|
if (!col)
|
||||||
|
return;
|
||||||
|
wxDataViewCell *cell = col->GetCell();
|
||||||
|
|
||||||
|
size_t row = y / m_lineHeight;
|
||||||
|
|
||||||
|
wxDataViewListModel *model = GetOwner()->GetModel();
|
||||||
|
|
||||||
|
if (event.LeftDClick())
|
||||||
|
{
|
||||||
|
if (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)
|
||||||
|
{
|
||||||
|
wxVariant value;
|
||||||
|
model->GetValue( value, col->GetModelColumn(), row );
|
||||||
|
cell->SetValue( value );
|
||||||
|
wxRect cell_rect( xpos, row * m_lineHeight, col->GetWidth(), m_lineHeight );
|
||||||
|
cell->Activate( cell_rect, model, col->GetModelColumn(), row );
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -997,7 +997,7 @@ wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype,
|
|||||||
{
|
{
|
||||||
m_renderer = (void*) gtk_cell_renderer_toggle_new();
|
m_renderer = (void*) gtk_cell_renderer_toggle_new();
|
||||||
|
|
||||||
if (m_mode & wxDATAVIEW_CELL_EDITABLE)
|
if (m_mode & wxDATAVIEW_CELL_ACTIVATABLE)
|
||||||
{
|
{
|
||||||
g_signal_connect_after( m_renderer, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
|
g_signal_connect_after( m_renderer, "toggled", G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user