Corrected/added support for column headers with icon and text
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53147 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -325,6 +325,10 @@ private:
|
|||||||
// holds the GTK handle
|
// holds the GTK handle
|
||||||
GtkWidget *m_column;
|
GtkWidget *m_column;
|
||||||
|
|
||||||
|
// holds GTK handles for title/bitmap in the header
|
||||||
|
GtkWidget *m_image;
|
||||||
|
GtkWidget *m_label;
|
||||||
|
|
||||||
// delayed connection to mouse events
|
// delayed connection to mouse events
|
||||||
friend class wxDataViewCtrl;
|
friend class wxDataViewCtrl;
|
||||||
void OnInternalIdle();
|
void OnInternalIdle();
|
||||||
|
@@ -785,7 +785,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
m_music_model = new MyMusicModel;
|
m_music_model = new MyMusicModel;
|
||||||
m_musicCtrl->AssociateModel( m_music_model.get() );
|
m_musicCtrl->AssociateModel( m_music_model.get() );
|
||||||
|
|
||||||
wxDataViewTextRenderer *tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT, wxALIGN_RIGHT );
|
wxDataViewTextRenderer *tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT );
|
||||||
wxDataViewColumn *column0 = new wxDataViewColumn( wxT("title"), tr, 0, 200, wxALIGN_LEFT,
|
wxDataViewColumn *column0 = new wxDataViewColumn( wxT("title"), tr, 0, 200, wxALIGN_LEFT,
|
||||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
|
||||||
m_musicCtrl->AppendColumn( column0 );
|
m_musicCtrl->AppendColumn( column0 );
|
||||||
@@ -824,7 +824,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120, wxALIGN_RIGHT );
|
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120, wxALIGN_RIGHT );
|
||||||
m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT, 60 );
|
m_listCtrl->AppendIconTextColumn(wxIcon(small1_xpm), 1, wxDATAVIEW_CELL_INERT )->SetTitle( wxT("icon") );
|
||||||
#else
|
#else
|
||||||
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE );
|
m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE );
|
||||||
m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT );
|
m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT );
|
||||||
|
@@ -2440,6 +2440,16 @@ void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
|
|||||||
|
|
||||||
SetWidth( width );
|
SetWidth( width );
|
||||||
|
|
||||||
|
// Create container for icon and label
|
||||||
|
GtkWidget *box = gtk_hbox_new( FALSE, 1 );
|
||||||
|
gtk_widget_show( box );
|
||||||
|
// gtk_container_set_border_width((GtkContainer*)box, 2);
|
||||||
|
m_image = gtk_image_new();
|
||||||
|
gtk_box_pack_start(GTK_BOX(box), m_image, FALSE, FALSE, 1);
|
||||||
|
m_label = gtk_label_new("");
|
||||||
|
gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 );
|
||||||
|
gtk_tree_view_column_set_widget( column, box );
|
||||||
|
|
||||||
gtk_tree_view_column_pack_end( column, renderer, TRUE );
|
gtk_tree_view_column_pack_end( column, renderer, TRUE );
|
||||||
|
|
||||||
gtk_tree_view_column_set_cell_data_func( column, renderer,
|
gtk_tree_view_column_set_cell_data_func( column, renderer,
|
||||||
@@ -2479,39 +2489,27 @@ void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
|
|||||||
|
|
||||||
void wxDataViewColumn::SetTitle( const wxString &title )
|
void wxDataViewColumn::SetTitle( const wxString &title )
|
||||||
{
|
{
|
||||||
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
|
|
||||||
|
|
||||||
if (m_isConnected)
|
|
||||||
{
|
|
||||||
// disconnect before column->button gets recreated
|
|
||||||
g_signal_handlers_disconnect_by_func( column->button,
|
|
||||||
(GtkWidget*) gtk_dataview_header_button_press_callback, this);
|
|
||||||
|
|
||||||
m_isConnected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: can it really happen that we don't have the owner here??
|
|
||||||
wxDataViewCtrl *ctrl = GetOwner();
|
wxDataViewCtrl *ctrl = GetOwner();
|
||||||
gtk_tree_view_column_set_title( column, ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
|
gtk_label_set_text( GTK_LABEL(m_label), ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
|
||||||
: wxGTK_CONV_SYS(title) );
|
: wxGTK_CONV_SYS(title) );
|
||||||
|
if (title.empty())
|
||||||
gtk_tree_view_column_set_widget( column, NULL );
|
gtk_widget_hide( m_label );
|
||||||
|
else
|
||||||
|
gtk_widget_show( m_label );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxDataViewColumn::GetTitle() const
|
wxString wxDataViewColumn::GetTitle() const
|
||||||
{
|
{
|
||||||
const gchar *str = gtk_tree_view_column_get_title( GTK_TREE_VIEW_COLUMN(m_column) );
|
return wxGTK_CONV_BACK( gtk_label_get_text( GTK_LABEL(m_label) ) );
|
||||||
return wxConvFileName->cMB2WX(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
|
void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
|
||||||
{
|
{
|
||||||
wxDataViewColumnBase::SetBitmap( bitmap );
|
wxDataViewColumnBase::SetBitmap( bitmap );
|
||||||
|
|
||||||
GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
|
|
||||||
if (bitmap.Ok())
|
if (bitmap.Ok())
|
||||||
{
|
{
|
||||||
GtkImage *gtk_image = GTK_IMAGE( gtk_image_new() );
|
GtkImage *gtk_image = GTK_IMAGE(m_image);
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = (GdkBitmap *) NULL;
|
||||||
if (bitmap.GetMask())
|
if (bitmap.GetMask())
|
||||||
@@ -2527,13 +2525,11 @@ void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
|
|||||||
gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image),
|
gtk_image_set_from_pixmap(GTK_IMAGE(gtk_image),
|
||||||
bitmap.GetPixmap(), mask);
|
bitmap.GetPixmap(), mask);
|
||||||
}
|
}
|
||||||
gtk_widget_show( GTK_WIDGET(gtk_image) );
|
gtk_widget_show( m_image );
|
||||||
|
|
||||||
gtk_tree_view_column_set_widget( column, GTK_WIDGET(gtk_image) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_tree_view_column_set_widget( column, NULL );
|
gtk_widget_hide( m_image );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -174,13 +174,23 @@ static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDes
|
|||||||
} /* switch */
|
} /* switch */
|
||||||
columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
|
columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
|
||||||
columnDescription.headerBtnDesc.btnFontStyle.style = normal;
|
columnDescription.headerBtnDesc.btnFontStyle.style = normal;
|
||||||
|
if (columnPtr->GetBitmap().IsOk())
|
||||||
|
{
|
||||||
columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
|
columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
|
||||||
if (columnPtr->GetBitmap().Ok())
|
|
||||||
#if wxCHECK_VERSION(2,9,0)
|
#if wxCHECK_VERSION(2,9,0)
|
||||||
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
|
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
|
||||||
#else
|
#else
|
||||||
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetBitmapData()->GetIconRef();
|
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetBitmapData()->GetIconRef();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// not text only as we otherwise could not add a bitmap later
|
||||||
|
// columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
|
||||||
|
columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
|
||||||
|
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// done:
|
// done:
|
||||||
return true;
|
return true;
|
||||||
} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
|
} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
|
||||||
|
Reference in New Issue
Block a user