/** * gimp_unit_menu_get_pixel_digits: * @menu: a #GimpUnitMenu * * Retrieve the number of digits for a pixel size as set by * gimp_unit_menu_set_pixel_digits(). * * Return value: the configured number of digits for a pixel size **/ gint gimp_unit_menu_get_pixel_digits (GimpUnitMenu *menu) { g_return_val_if_fail (GIMP_IS_UNIT_MENU (menu), 0); return menu->pixel_digits; }
/** * gimp_unit_menu_get_unit: * @menu: The unit menu you want to know the unit of. * * Returns the #GimpUnit the user has selected from the #GimpUnitMenu. * * Returns: The unit the user has selected. **/ GimpUnit gimp_unit_menu_get_unit (GimpUnitMenu *menu) { g_return_val_if_fail (GIMP_IS_UNIT_MENU (menu), GIMP_UNIT_INCH); return menu->unit; }
/** * gimp_unit_menu_set_pixel_digits: * @menu: a #GimpUnitMenu * @digits: the number of digits to display for a pixel size * * A GimpUnitMenu can be setup to control the number of digits shown * by attached spinbuttons. Please refer to the documentation of * gimp_unit_menu_update() to see how this is done. * * This function allows to specify the number of digits shown for a * size in pixels. Usually this is 0 (only full pixels). If you want * to allow the user to specify sub-pixel sizes using the attached * spinbuttons, specify the number of digits after the decimal point * here. You should do this after attaching your spinbuttons. **/ void gimp_unit_menu_set_pixel_digits (GimpUnitMenu *menu, gint digits) { GimpUnit unit; g_return_if_fail (GIMP_IS_UNIT_MENU (menu)); menu->pixel_digits = digits; gimp_unit_menu_update (GTK_WIDGET (menu), &unit); }
static void gimp_unit_menu_destroy (GtkObject *object) { GimpUnitMenu *gum; g_return_if_fail (object != NULL); g_return_if_fail (GIMP_IS_UNIT_MENU (object)); gum = GIMP_UNIT_MENU (object); if (gum->format) g_free (gum->format); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); }
/** * gimp_unit_menu_set_unit: * @menu: The unit menu you want to set the unit for. * @unit: The new unit. * * Sets a new #GimpUnit for the specified #GimpUnitMenu. **/ void gimp_unit_menu_set_unit (GimpUnitMenu *menu, GimpUnit unit) { GtkWidget *menuitem = NULL; GList *items; gint user_unit; g_return_if_fail (GIMP_IS_UNIT_MENU (menu)); g_return_if_fail (((unit >= GIMP_UNIT_PIXEL) && ((unit > GIMP_UNIT_PIXEL) || menu->show_pixels) && (unit < gimp_unit_get_number_of_units ())) || ((unit == GIMP_UNIT_PERCENT) && menu->show_percent)); if (unit == menu->unit) return; items = GTK_MENU_SHELL (GTK_OPTION_MENU (menu)->menu)->children; user_unit = (GIMP_UNIT_END + (((menu->show_pixels || menu->show_percent) ? 2 : 0) + ((menu->show_pixels && menu->show_percent) ? 1 : 0))); if ((unit >= GIMP_UNIT_END) && (unit != GIMP_UNIT_PERCENT)) { gchar *string; if ((g_list_length (items) - 3) >= user_unit) { gtk_widget_destroy (GTK_WIDGET (g_list_nth_data (items, user_unit - 1))); gtk_widget_destroy (GTK_WIDGET (g_list_nth_data (items, user_unit - 1))); } menuitem = gtk_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (GTK_OPTION_MENU (menu)->menu), menuitem); gtk_widget_set_sensitive (menuitem, FALSE); gtk_menu_reorder_child (GTK_MENU (GTK_OPTION_MENU (menu)->menu), menuitem, user_unit - 1); gtk_widget_show (menuitem); string = gimp_unit_format_string (menu->format, unit); menuitem = gtk_menu_item_new_with_label (string); g_free (string); gtk_menu_shell_append (GTK_MENU_SHELL (GTK_OPTION_MENU (menu)->menu), menuitem); g_object_set_data (G_OBJECT (menuitem), "gimp_unit_menu", GINT_TO_POINTER (unit)); gtk_menu_reorder_child (GTK_MENU (GTK_OPTION_MENU (menu)->menu), menuitem, user_unit); gtk_widget_show (menuitem); g_signal_connect (menuitem, "activate", G_CALLBACK (gimp_unit_menu_callback), menu); } menu->unit = unit; gtk_option_menu_set_history (GTK_OPTION_MENU (menu), (unit == GIMP_UNIT_PIXEL) ? 0 : ((unit == GIMP_UNIT_PERCENT) ? (menu->show_pixels ? 1 : 0) : (((menu->show_pixels || menu->show_percent) ? 2 : 0) + ((menu->show_pixels && menu->show_percent) ? 1 : 0) + ((unit < GIMP_UNIT_END) ? (unit - 1) : GIMP_UNIT_END)))); g_signal_emit (menu, gimp_unit_menu_signals[UNIT_CHANGED], 0); }