GtkComboBox GtkComboBoxEntry CellRenderers



Hi,
  I'd like to ensure that the width of the items in my combo box are always
at least the size of the combobox or comboboxentry.  So, far I have this working
for combobox because I can get a pointer to the cellrenderer for the content of
the combobox.  I'm running into problems with comboboxentry because when i try to
create my own cellrenderer and also set the text-column. I end up getting two columns
in the dropdown box.

Here's a snip of what i'm trying to accomplish:

static void ensure_width( GtkCellLayout *cell_layout,
                          GtkCellRenderer *cell,
                          GtkTreeModel *tree_model,
                          GtkTreeIter *iter,
                          gpointer data )
{
  gint widget_width = GTK_WIDGET( cell_layout )->allocation.width;
  gint width;
  gtk_cell_renderer_get_fixed_size( cell, &width, NULL );
  if( width < ( widget_width - 10 ) ){
    gtk_cell_renderer_set_fixed_size( cell, widget_width - 10, -1 );
  }
}
void construct_combo_box( ... )
{
  GTypes
  for( guint i = 0; i < columns, ++i ){

        ...

  GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
  gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo_box ), renderer, TRUE );
  gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combo_box ), renderer, "text", i, NULL );
  gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( combo_box ),
                                      renderer, (GtkCellLayoutDataFunc)ensure_width,
                                      NULL, NULL );

        ...
  }

  GtkListStore *store = gtk_list_store_newv( widget->data_values->len, types );
  gtk_combo_box_set_model( GTK_COMBO_BOX( widget->widget ), GTK_TREE_MODEL( store ) );
  gtk_combo_box_set_wrap_width( GTK_COMBO_BOX( widget->widget ), 1 );

  if( type == gtk_combo_box_entry_get_type() ){
    GtkEntryCompletion *completion = gtk_entry_completion_new();
    g_object_set( G_OBJECT( combo_box ), "text-column", text_column, NULL );
//    gtk_combo_box_entry_set_text_column( GTK_COMBO_BOX_ENTRY( widget->widget ), text_column );
    gtk_entry_set_completion( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( widget->widget ) ) ), completion );
    g_object_unref( completion );
    gtk_entry_completion_set_model( completion, GTK_TREE_MODEL( store ) );
    gtk_entry_completion_set_text_column( completion, text_column );
  }
}

thanks,
todd



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]