Added wxDataViewBitmapCell

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41473 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-09-26 22:17:00 +00:00
parent 2f62094615
commit cbc9145c04
3 changed files with 82 additions and 10 deletions

View File

@@ -58,6 +58,23 @@ protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextCell) DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextCell)
}; };
// ---------------------------------------------------------
// wxDataViewBitmapCell
// ---------------------------------------------------------
class wxDataViewBitmapCell: public wxDataViewCell
{
public:
wxDataViewBitmapCell( const wxString &varianttype = wxT("wxBitmap"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value );
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapCell)
};
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewToggleCell // wxDataViewToggleCell
// --------------------------------------------------------- // ---------------------------------------------------------

View File

@@ -26,6 +26,8 @@
#include "../sample.xpm" #include "../sample.xpm"
#endif #endif
#include "null.xpm"
#include "wx/dataview.h" #include "wx/dataview.h"
// ------------------------------------- // -------------------------------------
@@ -191,6 +193,8 @@ public:
m_list.Add( wxT("list") ); m_list.Add( wxT("list") );
m_list.Add( wxT("of") ); m_list.Add( wxT("of") );
m_list.Add( wxT("words.") ); m_list.Add( wxT("words.") );
m_bitmap = wxBitmap( null_xpm );
} }
virtual size_t GetNumberOfRows() { return m_list.GetCount(); } virtual size_t GetNumberOfRows() { return m_list.GetCount(); }
@@ -203,6 +207,11 @@ public:
variant = m_list[row]; variant = m_list[row];
return; return;
} }
if (col == 2)
{
variant = &m_bitmap;
return;
}
wxString tmp; wxString tmp;
tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
variant = tmp; variant = tmp;
@@ -243,6 +252,7 @@ public:
} }
wxArrayString m_list; wxArrayString m_list;
wxBitmap m_bitmap;
}; };
// ------------------------------------- // -------------------------------------
@@ -474,6 +484,7 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 0 ); wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 0 );
dataview_left->AppendColumn( column ); dataview_left->AppendColumn( column );
dataview_left->AppendTextColumn( wxT("second"), 1 ); dataview_left->AppendTextColumn( wxT("second"), 1 );
dataview_left->AppendColumn( new wxDataViewColumn( wxT("icon"), new wxDataViewBitmapCell, 2 ) );
// Right wxDataViewCtrl using the sorting model // Right wxDataViewCtrl using the sorting model
dataview_right = new wxDataViewCtrl( this, wxID_ANY ); dataview_right = new wxDataViewCtrl( this, wxID_ANY );
@@ -498,7 +509,7 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
left_sizer->Add( new wxButton( this, ID_APPEND_ROW_LEFT, wxT("Append") ), 0, wxALL, 5 ); left_sizer->Add( new wxButton( this, ID_APPEND_ROW_LEFT, wxT("Append") ), 0, wxALL, 5 );
left_sizer->Add( new wxButton( this, ID_PREPEND_ROW_LEFT, wxT("Prepend") ), 0, wxALL, 5 ); left_sizer->Add( new wxButton( this, ID_PREPEND_ROW_LEFT, wxT("Prepend") ), 0, wxALL, 5 );
left_sizer->Add( new wxButton( this, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 ); left_sizer->Add( new wxButton( this, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 );
left_sizer->Add( new wxButton( this, ID_DELETE_ROW_LEFT, wxT("Delete") ), 0, wxALL, 5 ); left_sizer->Add( new wxButton( this, ID_DELETE_ROW_LEFT, wxT("Delete second") ), 0, wxALL, 5 );
left_sizer->Add( new wxButton( this, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 ); left_sizer->Add( new wxButton( this, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 );
button_sizer->Add( left_sizer ); button_sizer->Add( left_sizer );
button_sizer->Add( 10, 10, 2 ); button_sizer->Add( 10, 10, 2 );
@@ -506,7 +517,7 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int
right_sizer->Add( new wxButton( this, ID_APPEND_ROW_RIGHT, wxT("Append") ), 0, wxALL, 5 ); right_sizer->Add( new wxButton( this, ID_APPEND_ROW_RIGHT, wxT("Append") ), 0, wxALL, 5 );
right_sizer->Add( new wxButton( this, ID_PREPEND_ROW_RIGHT, wxT("Prepend") ), 0, wxALL, 5 ); right_sizer->Add( new wxButton( this, ID_PREPEND_ROW_RIGHT, wxT("Prepend") ), 0, wxALL, 5 );
right_sizer->Add( new wxButton( this, ID_INSERT_ROW_RIGHT, wxT("Insert") ), 0, wxALL, 5 ); right_sizer->Add( new wxButton( this, ID_INSERT_ROW_RIGHT, wxT("Insert") ), 0, wxALL, 5 );
right_sizer->Add( new wxButton( this, ID_DELETE_ROW_RIGHT, wxT("Delete") ), 0, wxALL, 5 ); right_sizer->Add( new wxButton( this, ID_DELETE_ROW_RIGHT, wxT("Delete second") ), 0, wxALL, 5 );
right_sizer->Add( new wxButton( this, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 ); right_sizer->Add( new wxButton( this, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 );
button_sizer->Add( right_sizer ); button_sizer->Add( right_sizer );
button_sizer->Add( 10, 10, 1 ); button_sizer->Add( 10, 10, 1 );
@@ -555,7 +566,7 @@ void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event))
void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event)) void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event))
{ {
wxTextEntryDialog dialog( this, wxT("Enter text to insert at #2") ); wxTextEntryDialog dialog( this, wxT("Enter text to insert before second") );
if (dialog.ShowModal() == wxID_OK) if (dialog.ShowModal() == wxID_OK)
{ {
wxString value = dialog.GetValue(); wxString value = dialog.GetValue();

View File

@@ -919,7 +919,7 @@ static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
model->ValueChanged( model_col, model_row ); model->ValueChanged( model_col, model_row );
} }
IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCell) IMPLEMENT_CLASS(wxDataViewTextCell, wxDataViewCell)
wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) : wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) :
wxDataViewCell( varianttype, mode ) wxDataViewCell( varianttype, mode )
@@ -964,6 +964,48 @@ bool wxDataViewTextCell::GetValue( wxVariant &value )
return true; return true;
} }
// ---------------------------------------------------------
// wxDataViewBitmapCell
// ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewBitmapCell, wxDataViewCell)
wxDataViewBitmapCell::wxDataViewBitmapCell( const wxString &varianttype, wxDataViewCellMode mode ) :
wxDataViewCell( varianttype, mode )
{
m_renderer = (void*) gtk_cell_renderer_pixbuf_new();
}
bool wxDataViewBitmapCell::SetValue( const wxVariant &value )
{
if (value.GetType() == wxT("wxBitmap"))
{
// We could also use the type safe wxGetVariantCast here
const wxBitmap *bitmap = (const wxBitmap*) value.GetWxObjectPtr();
if (!bitmap)
return false;
// This may create a Pixbuf representation in the
// wxBitmap object (and it will stay there)
GdkPixbuf *pixbuf = bitmap->GetPixbuf();
GValue gvalue = { 0, };
g_value_init( &gvalue, G_TYPE_OBJECT );
g_value_set_object( &gvalue, pixbuf );
g_object_set_property( G_OBJECT(m_renderer), "pixbuf", &gvalue );
g_value_unset( &gvalue );
return true;
}
return false;
}
bool wxDataViewBitmapCell::GetValue( wxVariant &value )
{
return false;
}
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewToggleCell // wxDataViewToggleCell
// --------------------------------------------------------- // ---------------------------------------------------------
@@ -1003,7 +1045,7 @@ static void wxGtkToggleRendererToggledCallback( GtkCellRendererToggle *renderer,
model->ValueChanged( model_col, model_row ); model->ValueChanged( model_col, model_row );
} }
IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleCell, wxDataViewCell) IMPLEMENT_CLASS(wxDataViewToggleCell, wxDataViewCell)
wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype, wxDataViewToggleCell::wxDataViewToggleCell( const wxString &varianttype,
wxDataViewCellMode mode ) : wxDataViewCellMode mode ) :
@@ -1088,7 +1130,7 @@ public:
// wxDataViewCustomCell // wxDataViewCustomCell
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomCell, wxDataViewCell) IMPLEMENT_CLASS(wxDataViewCustomCell, wxDataViewCell)
wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype, wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype,
wxDataViewCellMode mode, bool no_init ) : wxDataViewCellMode mode, bool no_init ) :
@@ -1145,7 +1187,7 @@ wxDC *wxDataViewCustomCell::GetDC()
// wxDataViewProgressCell // wxDataViewProgressCell
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell) IMPLEMENT_CLASS(wxDataViewProgressCell, wxDataViewCustomCell)
wxDataViewProgressCell::wxDataViewProgressCell( const wxString &label, wxDataViewProgressCell::wxDataViewProgressCell( const wxString &label,
const wxString &varianttype, wxDataViewCellMode mode ) : const wxString &varianttype, wxDataViewCellMode mode ) :
@@ -1271,7 +1313,7 @@ void wxDataViewDateCellPopupTransient::OnCalendar( wxCalendarEvent &event )
DismissAndNotify(); DismissAndNotify();
} }
IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell, wxDataViewCustomCell) IMPLEMENT_CLASS(wxDataViewDateCell, wxDataViewCustomCell)
wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype, wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype,
wxDataViewCellMode mode ) : wxDataViewCellMode mode ) :
@@ -1350,12 +1392,14 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *column,
list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row ); list_store->model->GetValue( value, cell->GetOwner()->GetModelColumn(), model_row );
if (value.GetType() != cell->GetVariantType()) if (value.GetType() != cell->GetVariantType())
wxLogError( wxT("Wrong type\n") ); wxLogError( wxT("Wrong type, required: %s but: %s"),
value.GetType().c_str(),
cell->GetVariantType().c_str() );
cell->SetValue( value ); cell->SetValue( value );
} }
IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) IMPLEMENT_CLASS(wxDataViewColumn, wxDataViewColumnBase)
wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, size_t model_column, wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, size_t model_column,
int fixed_width, wxDataViewColumnSizing sizing, int flags ) : int fixed_width, wxDataViewColumnSizing sizing, int flags ) :