From: Robert Roebling Date: Sat, 30 Sep 2006 21:21:19 +0000 (+0000) Subject: Several wxBitmapDataCell changes. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2586d4a12176c79b2c34859c95db17cf45b54204?ds=inline Several wxBitmapDataCell changes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 5e37624e0f..70f83b67c9 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -24,7 +24,7 @@ #if defined(__WXGTK20__) // for testing -// #define wxUSE_GENERICDATAVIEWCTRL 1 + #define wxUSE_GENERICDATAVIEWCTRL 1 #elif defined(__WXMAC__) #define wxUSE_GENERICDATAVIEWCTRL 1 #else diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index bb5e2e7338..18a6bb0123 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -15,6 +15,7 @@ #include "wx/list.h" #include "wx/control.h" #include "wx/scrolwin.h" +#include "wx/icon.h" // --------------------------------------------------------- // classes @@ -109,6 +110,30 @@ protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextCell) }; +// --------------------------------------------------------- +// wxDataViewBitmapCell +// --------------------------------------------------------- + +class WXDLLIMPEXP_ADV wxDataViewBitmapCell: public wxDataViewCustomCell +{ +public: + wxDataViewBitmapCell( const wxString &varianttype = wxT("wxBitmap"), + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); + + bool SetValue( const wxVariant &value ); + bool GetValue( wxVariant &value ); + + bool Render( wxRect cell, wxDC *dc, int state ); + wxSize GetSize(); + +private: + wxIcon m_icon; + wxBitmap m_bitmap; + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapCell) +}; + // --------------------------------------------------------- // wxDataViewToggleCell // --------------------------------------------------------- diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 7d404f3e72..725dff04b7 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -35,6 +35,7 @@ #include "wx/calctrl.h" #include "wx/popupwin.h" #include "wx/renderer.h" +#include "wx/icon.h" //----------------------------------------------------------------------------- // classes @@ -298,7 +299,7 @@ wxDataViewCustomCell::wxDataViewCustomCell( const wxString &varianttype, // wxDataViewTextCell // --------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCustomCell) +IMPLEMENT_CLASS(wxDataViewTextCell, wxDataViewCustomCell) wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) : wxDataViewCustomCell( varianttype, mode ) @@ -329,6 +330,52 @@ wxSize wxDataViewTextCell::GetSize() return wxSize(80,20); } +// --------------------------------------------------------- +// wxDataViewBitmapCell +// --------------------------------------------------------- + +IMPLEMENT_CLASS(wxDataViewBitmapCell, wxDataViewCustomCell) + +wxDataViewBitmapCell::wxDataViewBitmapCell( const wxString &varianttype, wxDataViewCellMode mode ) : + wxDataViewCustomCell( varianttype, mode ) +{ +} + +bool wxDataViewBitmapCell::SetValue( const wxVariant &value ) +{ + if (value.GetType() == wxT("wxBitmap")) + m_bitmap << value; + if (value.GetType() == wxT("wxIcon")) + m_icon << value; + + return true; +} + +bool wxDataViewBitmapCell::GetValue( wxVariant& WXUNUSED(value) ) +{ + return false; +} + +bool wxDataViewBitmapCell::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) +{ + if (m_bitmap.Ok()) + dc->DrawBitmap( m_bitmap, cell.x, cell.y ); + else if (m_icon.Ok()) + dc->DrawIcon( m_icon, cell.x, cell.y ); + + return true; +} + +wxSize wxDataViewBitmapCell::GetSize() +{ + if (m_bitmap.Ok()) + return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ); + else if (m_icon.Ok()) + return wxSize( m_icon.GetWidth(), m_icon.GetHeight() ); + + return wxSize(16,16); +} + // --------------------------------------------------------- // wxDataViewToggleCell // --------------------------------------------------------- diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index f03d36bcdb..34f2ce3746 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -25,6 +25,8 @@ #include "wx/stockitem.h" #include "wx/calctrl.h" #include "wx/popupwin.h" +#include "wx/icon.h" + #include "wx/gtk/private.h" #include "wx/gtk/win_gtk.h" @@ -980,14 +982,30 @@ 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; + wxBitmap bitmap; + bitmap << value; + + // 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; + } + + if (value.GetType() == wxT("wxIcon")) + { + wxIcon bitmap; + bitmap << value; // This may create a Pixbuf representation in the // wxBitmap object (and it will stay there) - GdkPixbuf *pixbuf = bitmap->GetPixbuf(); + GdkPixbuf *pixbuf = bitmap.GetPixbuf(); GValue gvalue = { 0, }; g_value_init( &gvalue, G_TYPE_OBJECT );