X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fege-adjustment-action.cpp;h=17e11db2d5c5e30f44cb0c54b4dfc52091d852ed;hb=8a2e76b7021b9b960d7c30801a1a14461d9b5939;hp=5e4fcefa3ce7f2508ad0c768eeb45c88cb619b7e;hpb=7a1e6c8525b097c6cbad0d9fcedd7e99b91e1c53;p=inkscape.git diff --git a/src/ege-adjustment-action.cpp b/src/ege-adjustment-action.cpp index 5e4fcefa3..17e11db2d 100644 --- a/src/ege-adjustment-action.cpp +++ b/src/ege-adjustment-action.cpp @@ -41,11 +41,18 @@ /* Note: this file should be kept compilable as both .cpp and .c */ +#include #include #include +#include #include -#include +#include +#include +#if GTK_CHECK_VERSION(2,12,0) +#include +#include +#endif /* GTK_CHECK_VERSION(2,12,0) */ #include #include #include @@ -53,6 +60,8 @@ #include #include +#include "widgets/icon.h" +#include "icon-size.h" #include "ege-adjustment-action.h" @@ -80,6 +89,25 @@ static void egeAct_free_all_descriptions( EgeAdjustmentAction* action ); static GtkActionClass* gParentClass = 0; static GQuark gDataName = 0; +enum { + APPEARANCE_UNKNOWN = -1, + APPEARANCE_NONE = 0, + 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 +}; + +#if GTK_CHECK_VERSION(2,12,0) +/* TODO need to have appropriate icons setup for these: */ +static const gchar *floogles[] = { + GTK_STOCK_REMOVE, + GTK_STOCK_ADD, + GTK_STOCK_GO_DOWN, + GTK_STOCK_ABOUT, + GTK_STOCK_GO_UP, + 0}; +#endif /* GTK_CHECK_VERSION(2,12,0) */ + typedef struct _EgeAdjustmentDescr EgeAdjustmentDescr; struct _EgeAdjustmentDescr @@ -102,8 +130,12 @@ struct _EgeAdjustmentActionPrivate gdouble lastVal; gdouble step; gdouble page; + gint appearanceMode; gboolean transferFocus; GList* descriptions; + gchar* appearance; + gchar* iconId; + Inkscape::IconSize iconSize; }; #define EGE_ADJUSTMENT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentActionPrivate ) ) @@ -114,7 +146,10 @@ enum { PROP_CLIMB_RATE, PROP_DIGITS, PROP_SELFID, - PROP_TOOL_POST + PROP_TOOL_POST, + PROP_APPEARANCE, + PROP_ICON_ID, + PROP_ICON_SIZE }; enum { @@ -216,6 +251,32 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass ) "Function for final adjustments", (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_object_class_install_property( objClass, + PROP_APPEARANCE, + g_param_spec_string( "appearance", + "Appearance hint", + "A hint for how to display", + "", + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_object_class_install_property( objClass, + PROP_ICON_ID, + g_param_spec_string( "iconId", + "Icon ID", + "The id for the icon", + "", + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_object_class_install_property( objClass, + PROP_ICON_SIZE, + g_param_spec_int( "iconSize", + "Icon Size", + "The size the icon", + (int)Inkscape::ICON_SIZE_MENU, + (int)Inkscape::ICON_SIZE_DECORATION, + (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + g_type_class_add_private( klass, sizeof(EgeAdjustmentActionClass) ); } } @@ -235,8 +296,12 @@ static void ege_adjustment_action_init( EgeAdjustmentAction* action ) action->private_data->lastVal = 0.0; action->private_data->step = 0.0; action->private_data->page = 0.0; + action->private_data->appearanceMode = APPEARANCE_NONE; action->private_data->transferFocus = FALSE; action->private_data->descriptions = 0; + action->private_data->appearance = 0; + action->private_data->iconId = 0; + action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; } static void ege_adjustment_action_finalize( GObject* object ) @@ -310,6 +375,18 @@ static void ege_adjustment_action_get_property( GObject* obj, guint propId, GVal g_value_set_pointer( value, (void*)action->private_data->toolPost ); break; + case PROP_APPEARANCE: + g_value_set_string( value, action->private_data->appearance ); + break; + + case PROP_ICON_ID: + g_value_set_string( value, action->private_data->iconId ); + break; + + case PROP_ICON_SIZE: + g_value_set_int( value, action->private_data->iconSize ); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); } @@ -376,6 +453,41 @@ void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValu } break; + case PROP_APPEARANCE: + { + gchar* tmp = action->private_data->appearance; + gchar* newVal = g_value_dup_string( value ); + action->private_data->appearance = newVal; + g_free( tmp ); + + if ( !action->private_data->appearance || (strcmp("", newVal) == 0) ) { + action->private_data->appearanceMode = APPEARANCE_NONE; + } else if ( strcmp("full", newVal) == 0 ) { + action->private_data->appearanceMode = APPEARANCE_FULL; + } else if ( strcmp("compact", newVal) == 0 ) { + action->private_data->appearanceMode = APPEARANCE_COMPACT; + } else if ( strcmp("minimal", newVal) == 0 ) { + action->private_data->appearanceMode = APPEARANCE_MINIMAL; + } else { + action->private_data->appearanceMode = APPEARANCE_UNKNOWN; + } + } + break; + + case PROP_ICON_ID: + { + gchar* tmp = action->private_data->iconId; + action->private_data->iconId = g_value_dup_string( value ); + g_free( tmp ); + } + break; + + case PROP_ICON_SIZE: + { + action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); + } + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); } @@ -460,6 +572,11 @@ void ege_adjustment_action_set_descriptions( EgeAdjustmentAction* action, gchar } } +void ege_adjustment_action_set_appearance( EgeAdjustmentAction* action, gchar const* val ) +{ + g_object_set( G_OBJECT(action), "appearance", val, NULL ); +} + static void process_menu_action( GtkWidget* obj, gpointer data ) { GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(obj); @@ -538,7 +655,9 @@ static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* men cur = g_list_next( cur ); } - str = g_strdup_printf( act->private_data->format, num, (marker?" ":""), ( (marker && marker->descr) ? marker->descr:"") ); + str = g_strdup_printf( act->private_data->format, num, + ((marker && marker->descr) ? ": " : ""), + ((marker && marker->descr) ? marker->descr : "")); *dst = gtk_radio_menu_item_new_with_label( *group, str ); if ( !*group) { @@ -697,23 +816,46 @@ static gboolean event_cb( EgeAdjustmentAction* act, GdkEvent* evt ) return handled; } +static gchar* +slider_format_falue (GtkScale* scale, gdouble value, gchar *label) +{ + (void)scale; + return g_strdup_printf("%s %d", label, (int) round(value)); +} + static GtkWidget* create_tool_item( GtkAction* action ) { GtkWidget* item = 0; if ( IS_EGE_ADJUSTMENT_ACTION(action) ) { EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action ); - GtkWidget* spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); + GtkWidget* spinbutton = 0; GtkWidget* hb = gtk_hbox_new( FALSE, 5 ); - GValue value; - - item = GTK_WIDGET( gtk_tool_item_new() ); + GValue value; memset( &value, 0, sizeof(value) ); g_value_init( &value, G_TYPE_STRING ); - g_object_get_property( G_OBJECT(action), "label", &value ); + g_object_get_property( G_OBJECT(action), "short_label", &value ); const gchar* sss = g_value_get_string( &value ); - GtkWidget* lbl = gtk_label_new( sss ? sss : "wwww" ); + + if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { + // Slider + spinbutton = gtk_hscale_new( act->private_data->adj); + gtk_widget_set_size_request(spinbutton, 100, -1); + gtk_scale_set_digits (GTK_SCALE(spinbutton), 0); + gtk_signal_connect(GTK_OBJECT(spinbutton), "format-value", GTK_SIGNAL_FUNC(slider_format_falue), (void *) sss); + +#if GTK_CHECK_VERSION(2,12,0) + } else if ( act->private_data->appearanceMode == APPEARANCE_MINIMAL ) { + spinbutton = gtk_scale_button_new( GTK_ICON_SIZE_MENU, 0, 100, 2, 0 ); + gtk_scale_button_set_adjustment( GTK_SCALE_BUTTON(spinbutton), act->private_data->adj ); + gtk_scale_button_set_icons( GTK_SCALE_BUTTON(spinbutton), floogles ); +#endif /* GTK_CHECK_VERSION(2,12,0) */ + } else { + spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits ); + } + + item = GTK_WIDGET( gtk_tool_item_new() ); { GValue tooltip; @@ -729,10 +871,27 @@ static GtkWidget* create_tool_item( GtkAction* action ) } } - gtk_misc_set_alignment( GTK_MISC(lbl), 1.0, 0.5 ); + if ( act->private_data->appearanceMode != APPEARANCE_FULL ) { + GtkWidget* filler1 = gtk_label_new(" "); + gtk_box_pack_start( GTK_BOX(hb), filler1, FALSE, FALSE, 0 ); + + // Use an icon if available or use short-label + if ( act->private_data->iconId && strcmp( act->private_data->iconId, "" ) != 0 ) { + GtkWidget* icon = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); + gtk_box_pack_start( GTK_BOX(hb), icon, FALSE, FALSE, 0 ); + } else { + GtkWidget* lbl = gtk_label_new( sss ? sss : "wwww" ); + gtk_misc_set_alignment( GTK_MISC(lbl), 1.0, 0.5 ); + gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 ); + } + } + + if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { + gtk_box_pack_start( GTK_BOX(hb), spinbutton, TRUE, TRUE, 0 ); + } else { + gtk_box_pack_start( GTK_BOX(hb), spinbutton, FALSE, FALSE, 0 ); + } - gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 ); - gtk_box_pack_end( GTK_BOX(hb), spinbutton, FALSE, FALSE, 0 ); gtk_container_add( GTK_CONTAINER(item), hb ); if ( act->private_data->selfId ) { @@ -746,7 +905,15 @@ static GtkWidget* create_tool_item( GtkAction* action ) g_signal_connect( G_OBJECT(spinbutton), "value-changed", G_CALLBACK(value_changed_cb), action ); g_signal_connect_swapped( G_OBJECT(spinbutton), "event", G_CALLBACK(event_cb), action ); - gtk_entry_set_width_chars( GTK_ENTRY(spinbutton), act->private_data->digits + 3 ); + if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { + /* */ +#if GTK_CHECK_VERSION(2,12,0) + } else if ( act->private_data->appearanceMode == APPEARANCE_MINIMAL ) { + /* */ +#endif /* GTK_CHECK_VERSION(2,12,0) */ + } else { + gtk_entry_set_width_chars( GTK_ENTRY(spinbutton), act->private_data->digits + 3 ); + } gtk_widget_show_all( item ); @@ -785,7 +952,15 @@ gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data ) (void)event; if ( IS_EGE_ADJUSTMENT_ACTION(data) ) { EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data ); - action->private_data->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); + if ( GTK_IS_SPIN_BUTTON(widget) ) { + action->private_data->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) ); +#if GTK_CHECK_VERSION(2,12,0) + } else if ( GTK_IS_SCALE_BUTTON(widget) ) { + action->private_data->lastVal = gtk_scale_button_get_value( GTK_SCALE_BUTTON(widget) ); +#endif /* GTK_CHECK_VERSION(2,12,0) */ + } else if (GTK_IS_RANGE(widget) ) { + action->private_data->lastVal = gtk_range_get_value( GTK_RANGE(widget) ); + } action->private_data->transferFocus = TRUE; }