Added wxChoice renderer to wxDataViewCtrl
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -882,6 +882,33 @@ private:
|
|||||||
long m_min,m_max;
|
long m_min,m_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// wxDataViewChoiceRenderer
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDataViewChoiceRenderer( const wxArrayString &choices,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
|
||||||
|
int alignment = wxDVR_DEFAULT_ALIGNMENT );
|
||||||
|
virtual bool HasEditorCtrl() { return true; }
|
||||||
|
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
|
||||||
|
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
|
||||||
|
virtual bool Render( wxRect rect, wxDC *dc, int state );
|
||||||
|
virtual wxSize GetSize() const;
|
||||||
|
virtual bool SetValue( const wxVariant &value );
|
||||||
|
virtual bool GetValue( wxVariant &value ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxArrayString m_choices;
|
||||||
|
wxString m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -263,6 +263,27 @@ protected:
|
|||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// wxDataViewChoiceRenderer
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDataViewChoiceRenderer( const wxArrayString &choices,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
|
||||||
|
int alignment = wxDVR_DEFAULT_ALIGNMENT );
|
||||||
|
virtual bool Render( wxRect rect, wxDC *dc, int state );
|
||||||
|
virtual wxSize GetSize() const;
|
||||||
|
virtual bool SetValue( const wxVariant &value );
|
||||||
|
virtual bool GetValue( wxVariant &value ) const;
|
||||||
|
|
||||||
|
void SetAlignment( int align );
|
||||||
|
private:
|
||||||
|
wxArrayString m_choices;
|
||||||
|
wxString m_data;
|
||||||
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// wxDataViewColumn
|
// wxDataViewColumn
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
@@ -74,15 +74,15 @@ static const char *small1_xpm[] = {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Implement this data model
|
Implement this data model
|
||||||
Title Artist Year
|
Title Artist Year Judgement
|
||||||
-------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
1: My Music:
|
1: My Music:
|
||||||
2: Pop music
|
2: Pop music
|
||||||
3: You are not alone Michael Jackson 1995
|
3: You are not alone Michael Jackson 1995 good
|
||||||
4: Take a bow Madonna 1994
|
4: Take a bow Madonna 1994 good
|
||||||
5: Classical music
|
5: Classical music
|
||||||
6: Ninth Symphony Ludwig v. Beethoven 1824
|
6: Ninth Symphony Ludwig v. Beethoven 1824 good
|
||||||
7: German Requiem Johannes Brahms 1868
|
7: German Requiem Johannes Brahms 1868 good
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -100,6 +100,7 @@ public:
|
|||||||
m_title = title;
|
m_title = title;
|
||||||
m_artist = artist;
|
m_artist = artist;
|
||||||
m_year = year;
|
m_year = year;
|
||||||
|
m_quality = "good";
|
||||||
m_isContainer = false;
|
m_isContainer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +137,7 @@ public:
|
|||||||
wxString m_title;
|
wxString m_title;
|
||||||
wxString m_artist;
|
wxString m_artist;
|
||||||
int m_year;
|
int m_year;
|
||||||
|
wxString m_quality;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MyMusicModelNode *m_parent;
|
MyMusicModelNode *m_parent;
|
||||||
@@ -255,7 +257,7 @@ public:
|
|||||||
|
|
||||||
virtual unsigned int GetColumnCount() const
|
virtual unsigned int GetColumnCount() const
|
||||||
{
|
{
|
||||||
return 5;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual wxString GetColumnType( unsigned int col ) const
|
virtual wxString GetColumnType( unsigned int col ) const
|
||||||
@@ -275,14 +277,15 @@ public:
|
|||||||
case 0: variant = node->m_title; break;
|
case 0: variant = node->m_title; break;
|
||||||
case 1: variant = node->m_artist; break;
|
case 1: variant = node->m_artist; break;
|
||||||
case 2: variant = (long) node->m_year; break;
|
case 2: variant = (long) node->m_year; break;
|
||||||
case 3:
|
case 3: variant = node->m_quality; break;
|
||||||
|
case 4:
|
||||||
// wxMac doesn't conceal the popularity progress renderer, return 0 for containers
|
// wxMac doesn't conceal the popularity progress renderer, return 0 for containers
|
||||||
if (IsContainer(item))
|
if (IsContainer(item))
|
||||||
variant = (long) 0;
|
variant = (long) 0;
|
||||||
else
|
else
|
||||||
variant = (long) 80; // all music is very 80% popular
|
variant = (long) 80; // all music is very 80% popular
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
// Make size of red square depend on year
|
// Make size of red square depend on year
|
||||||
if (GetYear(item) < 1900)
|
if (GetYear(item) < 1900)
|
||||||
variant = (long) 35;
|
variant = (long) 35;
|
||||||
@@ -313,6 +316,7 @@ public:
|
|||||||
case 0: node->m_title = variant.GetString(); return true;
|
case 0: node->m_title = variant.GetString(); return true;
|
||||||
case 1: node->m_artist = variant.GetString(); return true;
|
case 1: node->m_artist = variant.GetString(); return true;
|
||||||
case 2: node->m_year = variant.GetLong(); return true;
|
case 2: node->m_year = variant.GetLong(); return true;
|
||||||
|
case 3: node->m_quality = variant.GetString(); return true;
|
||||||
default: wxLogError( wxT("MyMusicModel::SetValue: wrong column") );
|
default: wxLogError( wxT("MyMusicModel::SetValue: wrong column") );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -626,7 +630,8 @@ public:
|
|||||||
|
|
||||||
virtual wxSize GetSize() const
|
virtual wxSize GetSize() const
|
||||||
{
|
{
|
||||||
return wxSize(60,m_height);
|
//return wxSize(60,m_height);
|
||||||
|
return wxSize(60,20);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool SetValue( const wxVariant &value )
|
virtual bool SetValue( const wxVariant &value )
|
||||||
@@ -844,19 +849,26 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
||||||
m_musicCtrl->AppendColumn( column1 );
|
m_musicCtrl->AppendColumn( column1 );
|
||||||
|
|
||||||
#if 1
|
|
||||||
wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
|
wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
|
||||||
wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 80, wxALIGN_LEFT,
|
wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 100, wxALIGN_LEFT,
|
||||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
||||||
m_musicCtrl->AppendColumn( column2 );
|
m_musicCtrl->AppendColumn( column2 );
|
||||||
|
|
||||||
m_musicCtrl->AppendProgressColumn( wxT("popularity"), 3, wxDATAVIEW_CELL_INERT, 80 );
|
wxArrayString choices;
|
||||||
|
choices.Add( "good" );
|
||||||
|
choices.Add( "bad" );
|
||||||
|
choices.Add( "lousy" );
|
||||||
|
wxDataViewChoiceRenderer *c = new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
|
||||||
|
wxDataViewColumn *column3 = new wxDataViewColumn( wxT("rating"), c, 3, 100, wxALIGN_LEFT,
|
||||||
|
wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
m_musicCtrl->AppendColumn( column3 );
|
||||||
|
|
||||||
|
m_musicCtrl->AppendProgressColumn( wxT("popularity"), 4, wxDATAVIEW_CELL_INERT, 80 );
|
||||||
|
|
||||||
MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
|
MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
|
||||||
wxDataViewColumn *column3 = new wxDataViewColumn( wxT("custom"), cr, 4, -1, wxALIGN_LEFT,
|
wxDataViewColumn *column4 = new wxDataViewColumn( wxT("custom"), cr, 5, -1, wxALIGN_LEFT,
|
||||||
wxDATAVIEW_COL_RESIZABLE );
|
wxDATAVIEW_COL_RESIZABLE );
|
||||||
m_musicCtrl->AppendColumn( column3 );
|
m_musicCtrl->AppendColumn( column4 );
|
||||||
#endif
|
|
||||||
|
|
||||||
data_sizer->Add( m_musicCtrl, 3, wxGROW );
|
data_sizer->Add( m_musicCtrl, 3, wxGROW );
|
||||||
|
|
||||||
@@ -877,8 +889,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
|
wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
|
||||||
wxDataViewColumn *column4 = new wxDataViewColumn(wxT("attributes"), ra, 2 );
|
wxDataViewColumn *column5 = new wxDataViewColumn(wxT("attributes"), ra, 2 );
|
||||||
m_listCtrl->AppendColumn( column4 );
|
m_listCtrl->AppendColumn( column5 );
|
||||||
|
|
||||||
data_sizer->Add( m_listCtrl, 2, wxGROW );
|
data_sizer->Add( m_listCtrl, 2, wxGROW );
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "wx/dataview.h"
|
#include "wx/dataview.h"
|
||||||
#include "wx/spinctrl.h"
|
#include "wx/spinctrl.h"
|
||||||
|
#include "wx/choice.h"
|
||||||
|
|
||||||
#include "wx/weakref.h"
|
#include "wx/weakref.h"
|
||||||
|
|
||||||
@@ -1316,6 +1317,64 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// wxDataViewChoiceRenderer
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
#ifndef __WXGTK20__
|
||||||
|
|
||||||
|
wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
|
||||||
|
wxDataViewCustomRenderer(wxT("string"), mode, alignment )
|
||||||
|
{
|
||||||
|
m_choices = choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxControl* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
|
||||||
|
{
|
||||||
|
wxString s = value;
|
||||||
|
wxSize size = labelRect.GetSize();
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
size = wxSize( wxMax(70,labelRect.width ), -1 );
|
||||||
|
#endif
|
||||||
|
wxChoice *c = new wxChoice( parent, wxID_ANY, labelRect.GetTopLeft(), size, m_choices );
|
||||||
|
c->SetStringSelection( value.GetString() );
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
|
||||||
|
{
|
||||||
|
wxChoice *c = (wxChoice*) editor;
|
||||||
|
wxString s = c->GetStringSelection();
|
||||||
|
value = s;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
|
||||||
|
{
|
||||||
|
RenderText( m_data, 0, rect, dc, state );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxDataViewChoiceRenderer::GetSize() const
|
||||||
|
{
|
||||||
|
return wxSize(80,16);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
|
||||||
|
{
|
||||||
|
m_data = value.GetString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
|
||||||
|
{
|
||||||
|
value = m_data;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -1541,7 +1541,7 @@ static void wxGtkTextRendererEditedCallback( GtkCellRendererText *renderer,
|
|||||||
static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer),
|
static void wxGtkTextRendererEditedCallback( GtkCellRendererText *WXUNUSED(renderer),
|
||||||
gchar *arg1, gchar *arg2, gpointer user_data )
|
gchar *arg1, gchar *arg2, gpointer user_data )
|
||||||
{
|
{
|
||||||
wxDataViewTextRenderer *cell = (wxDataViewTextRenderer*) user_data;
|
wxDataViewRenderer *cell = (wxDataViewRenderer*) user_data;
|
||||||
|
|
||||||
wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont());
|
wxString tmp = wxGTK_CONV_BACK_FONT(arg2, cell->GetOwner()->GetOwner()->GetFont());
|
||||||
wxVariant value = tmp;
|
wxVariant value = tmp;
|
||||||
@@ -2021,6 +2021,120 @@ wxSize wxDataViewProgressRenderer::GetSize() const
|
|||||||
return wxSize(40,12);
|
return wxSize(40,12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
// wxDataViewChoiceRenderer
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices,
|
||||||
|
wxDataViewCellMode mode, int alignment ) :
|
||||||
|
wxDataViewCustomRenderer( "string", mode, alignment, true )
|
||||||
|
{
|
||||||
|
m_choices = choices;
|
||||||
|
|
||||||
|
#ifdef __WXGTK26__
|
||||||
|
if (!gtk_check_version(2,6,0))
|
||||||
|
{
|
||||||
|
m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new();
|
||||||
|
|
||||||
|
GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING );
|
||||||
|
size_t n;
|
||||||
|
for (n = 0; n < m_choices.GetCount(); n++)
|
||||||
|
gtk_list_store_insert_with_values( store, NULL, n, 0, m_choices[n].utf8_str(), -1 );
|
||||||
|
|
||||||
|
g_object_set (m_renderer,
|
||||||
|
"model", store,
|
||||||
|
"text-column", 0,
|
||||||
|
"has-entry", FALSE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
bool editable = (mode & wxDATAVIEW_CELL_EDITABLE);
|
||||||
|
g_object_set (m_renderer, "editable", editable, NULL);
|
||||||
|
|
||||||
|
SetAlignment(alignment);
|
||||||
|
|
||||||
|
g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
|
||||||
|
|
||||||
|
GtkInitHandlers();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// Use custom cell code
|
||||||
|
wxDataViewCustomRenderer::Init(mode, alignment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
|
||||||
|
{
|
||||||
|
RenderText( m_data, 0, rect, dc, state );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxDataViewChoiceRenderer::GetSize() const
|
||||||
|
{
|
||||||
|
return wxSize(70,20);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef __WXGTK26__
|
||||||
|
if (!gtk_check_version(2,6,0))
|
||||||
|
{
|
||||||
|
GValue gvalue = { 0, };
|
||||||
|
g_value_init( &gvalue, G_TYPE_STRING );
|
||||||
|
g_value_set_string( &gvalue, wxGTK_CONV_FONT( value.GetString(), GetOwner()->GetOwner()->GetFont() ) );
|
||||||
|
g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
|
||||||
|
g_value_unset( &gvalue );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
m_data = value.GetString();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
|
||||||
|
{
|
||||||
|
#ifdef __WXGTK26__
|
||||||
|
if (!gtk_check_version(2,6,0))
|
||||||
|
{
|
||||||
|
GValue gvalue = { 0, };
|
||||||
|
g_value_init( &gvalue, G_TYPE_STRING );
|
||||||
|
g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
|
||||||
|
wxString temp = wxGTK_CONV_BACK_FONT( g_value_get_string( &gvalue ), const_cast<wxDataViewTextRenderer*>(this)->GetOwner()->GetOwner()->GetFont() );
|
||||||
|
g_value_unset( &gvalue );
|
||||||
|
value = temp;
|
||||||
|
wxPrintf( "temp %s\n", temp );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
value = m_data;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewChoiceRenderer::SetAlignment( int align )
|
||||||
|
{
|
||||||
|
wxDataViewCustomRenderer::SetAlignment(align);
|
||||||
|
|
||||||
|
if (gtk_check_version(2,10,0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// horizontal alignment:
|
||||||
|
PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
|
||||||
|
if (align & wxALIGN_RIGHT)
|
||||||
|
pangoAlign = PANGO_ALIGN_RIGHT;
|
||||||
|
else if (align & wxALIGN_CENTER_HORIZONTAL)
|
||||||
|
pangoAlign = PANGO_ALIGN_CENTER;
|
||||||
|
|
||||||
|
GValue gvalue = { 0, };
|
||||||
|
g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
|
||||||
|
g_value_set_enum( &gvalue, pangoAlign );
|
||||||
|
g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
|
||||||
|
g_value_unset( &gvalue );
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// wxDataViewDateRenderer
|
// wxDataViewDateRenderer
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user