X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fege-select-one-action.cpp;h=20967c9e7e5bcc8bbc34693490cb9557fa034dc8;hb=5d67bd380afd0885c8b4656cb3383aea24aedfcb;hp=636da6e4b684d02f6f06f50c36c29bd6af944403;hpb=6ed36be9f01f34d8701fde2cde599e369dc1c3fe;p=inkscape.git diff --git a/src/ege-select-one-action.cpp b/src/ege-select-one-action.cpp index 636da6e4b..20967c9e7 100644 --- a/src/ege-select-one-action.cpp +++ b/src/ege-select-one-action.cpp @@ -46,9 +46,11 @@ #include #include #include +#include #include #include #include +#include #include "ege-select-one-action.h" @@ -80,9 +82,9 @@ static GQuark gDataName = 0; enum { APPEARANCE_UNKNOWN = -1, APPEARANCE_NONE = 0, - APPEARANCE_FULL, - APPEARANCE_COMPACT, - APPEARANCE_MINIMAL, + APPEARANCE_FULL, // label, then all choices represented by separate buttons + APPEARANCE_COMPACT, // label, then choices in a drop-down menu + APPEARANCE_MINIMAL, // no label, just choices in a drop-down menu }; struct _EgeSelectOneActionPrivate @@ -92,6 +94,7 @@ struct _EgeSelectOneActionPrivate gint iconColumn; gint tooltipColumn; gint appearanceMode; + gint iconSize; GType radioActionType; GtkTreeModel* model; gchar* iconProperty; @@ -107,6 +110,7 @@ enum { PROP_ICON_COLUMN, PROP_TOOLTIP_COLUMN, PROP_ICON_PROP, + PROP_ICON_SIZE, PROP_APPEARANCE }; @@ -133,6 +137,9 @@ GType ege_select_one_action_get_type( void ) return myType; } +GtkTreeModel *ege_select_one_action_get_model(EgeSelectOneAction* action ){ + return GTK_TREE_MODEL(action->private_data->model); +} void ege_select_one_action_class_init( EgeSelectOneActionClass* klass ) { if ( klass ) { @@ -197,6 +204,14 @@ void ege_select_one_action_class_init( EgeSelectOneActionClass* klass ) "", (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, + PROP_ICON_SIZE, + g_param_spec_int( "icon-size", + "Icon Size", + "Target icon size", + -1, 20, -1, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, PROP_APPEARANCE, g_param_spec_string( "appearance", @@ -229,6 +244,7 @@ void ege_select_one_action_init( EgeSelectOneAction* action ) action->private_data->radioActionType = 0; action->private_data->model = 0; action->private_data->iconProperty = g_strdup("stock-id"); + action->private_data->iconSize = -1; action->private_data->appearance = 0; /* g_signal_connect( action, "notify", G_CALLBACK( fixup_labels ), NULL ); */ @@ -289,6 +305,17 @@ void ege_select_one_action_set_icon_column( EgeSelectOneAction* action, gint col g_object_set( G_OBJECT(action), "icon-column", col, NULL ); } +gint ege_select_one_action_get_icon_size( EgeSelectOneAction* action ) +{ + g_return_val_if_fail( IS_EGE_SELECT_ONE_ACTION(action), 0 ); + return action->private_data->iconSize; +} + +void ege_select_one_action_set_icon_size( EgeSelectOneAction* action, gint size ) +{ + g_object_set( G_OBJECT(action), "icon-size", size, NULL ); +} + gint ege_select_one_action_get_tooltip_column( EgeSelectOneAction* action ) { g_return_val_if_fail( IS_EGE_SELECT_ONE_ACTION(action), 0 ); @@ -333,6 +360,10 @@ void ege_select_one_action_get_property( GObject* obj, guint propId, GValue* val g_value_set_string( value, action->private_data->iconProperty ); break; + case PROP_ICON_SIZE: + g_value_set_int( value, action->private_data->iconSize ); + break; + case PROP_APPEARANCE: g_value_set_string( value, action->private_data->appearance ); break; @@ -385,6 +416,12 @@ void ege_select_one_action_set_property( GObject* obj, guint propId, const GValu } break; + case PROP_ICON_SIZE: + { + action->private_data->iconSize = g_value_get_int( value ); + } + break; + case PROP_APPEARANCE: { gchar* tmp = action->private_data->appearance; @@ -493,6 +530,14 @@ GtkWidget* create_tool_item( GtkAction* action ) gint index = 0; GtkTooltips* tooltips = gtk_tooltips_new(); + gchar* sss = 0; + g_object_get( G_OBJECT(action), "short_label", &sss, NULL ); + if (sss) { + GtkWidget* lbl; + lbl = gtk_label_new(sss); + gtk_box_pack_start( GTK_BOX(holder), lbl, FALSE, FALSE, 4 ); + } + valid = gtk_tree_model_get_iter_first( act->private_data->model, &iter ); while ( valid ) { gchar* str = 0; @@ -530,6 +575,13 @@ GtkWidget* create_tool_item( GtkAction* action ) g_object_set( G_OBJECT(obj), act->private_data->iconProperty, iconId, NULL ); } + if ( act->private_data->iconProperty >= 0 ) { + /* TODO get this string to be set instead of hardcoded */ + if ( act->private_data->iconSize >= 0 ) { + g_object_set( G_OBJECT(obj), "iconSize", act->private_data->iconSize, NULL ); + } + } + ract = GTK_RADIO_ACTION(obj); } else { ract = gtk_radio_action_new( "Name 1", str, tip, iconId, index ); @@ -562,17 +614,42 @@ GtkWidget* create_tool_item( GtkAction* action ) gtk_container_add( GTK_CONTAINER(item), holder ); } else { + GtkWidget* holder = gtk_hbox_new( FALSE, 4 ); GtkWidget* normal = gtk_combo_box_new_with_model( act->private_data->model ); - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); + GtkCellRenderer * renderer = 0; + + if ( act->private_data->iconColumn >= 0 ) { + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(normal), renderer, TRUE ); + + // "icon-name" + gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT(normal), renderer, "stock-id", act->private_data->iconColumn ); + } + + renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(normal), renderer, TRUE ); - gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(normal), renderer, "text", act->private_data->labelColumn, (gchar*)0); + gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT(normal), renderer, "text", act->private_data->labelColumn ); gtk_combo_box_set_active( GTK_COMBO_BOX(normal), act->private_data->active ); g_signal_connect( G_OBJECT(normal), "changed", G_CALLBACK(combo_changed_cb), action ); - gtk_container_add( GTK_CONTAINER(item), normal ); + g_object_set_data( G_OBJECT(holder), "ege-combo-box", normal ); + + if (act->private_data->appearanceMode == APPEARANCE_COMPACT) { + gchar* sss = 0; + g_object_get( G_OBJECT(action), "short_label", &sss, NULL ); + if (sss) { + GtkWidget* lbl; + lbl = gtk_label_new(sss); + gtk_box_pack_start( GTK_BOX(holder), lbl, FALSE, FALSE, 4 ); + } + } + + gtk_box_pack_start( GTK_BOX(holder), normal, FALSE, FALSE, 0 ); + + gtk_container_add( GTK_CONTAINER(item), holder ); } gtk_widget_show_all( item ); @@ -605,8 +682,9 @@ void resync_active( EgeSelectOneAction* act, gint active ) /* Search for the things we built up in create_tool_item() */ GList* children = gtk_container_get_children( GTK_CONTAINER(proxies->data) ); if ( children && children->data ) { - if ( GTK_IS_COMBO_BOX(children->data) ) { - GtkComboBox* combo = GTK_COMBO_BOX(children->data); + gpointer combodata = g_object_get_data( G_OBJECT(children->data), "ege-combo-box" ); + if ( GTK_IS_COMBO_BOX(combodata) ) { + GtkComboBox* combo = GTK_COMBO_BOX(combodata); if ( gtk_combo_box_get_active(combo) != active ) { gtk_combo_box_set_active( combo, active ); }