Ejemplo n.º 1
0
void
gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
                                GimpUnit          unit)
{
  GtkTreeModel *model;
  GtkTreeIter   iter;
  gboolean      iter_valid;

  g_return_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo));

  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

  _gimp_unit_store_sync_units (GIMP_UNIT_STORE (model));

  for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
       iter_valid;
       iter_valid = gtk_tree_model_iter_next (model, &iter))
    {
      gint iter_unit;

      gtk_tree_model_get (model, &iter,
                          GIMP_UNIT_STORE_UNIT, &iter_unit,
                          -1);

      if (unit == (GimpUnit) iter_unit)
        {
          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
          break;
        }
    }
}
Ejemplo n.º 2
0
/**
 * gimp_resolution_entry_new:
 * @width_label:       Optional label for the width control.
 * @width:             Width of the item, specified in terms of @size_unit.
 * @height_label:      Optional label for the height control.
 * @height:            Height of the item, specified in terms of @size_unit.
 * @size_unit:         Unit used to specify the width and height.
 * @res_label:         Optional label for the resolution entry.
 * @initial_res:       The initial resolution.
 * @initial_unit:      The initial unit.
 *
 * Creates a new #GimpResolutionEntry widget.
 *
 * The #GimpResolutionEntry is derived from #GtkTable and will have
 * an empty border of one cell width on each side plus an empty column left
 * of the #GimpUnitMenu to allow the caller to add labels or other widgets.
 *
 * A #GimpChainButton is displayed if independent is set to %TRUE.
 *
 * Returns: A pointer to the new #GimpResolutionEntry widget.
 **/
GtkWidget *
gimp_resolution_entry_new (const gchar *width_label,
                           gdouble      width,
                           const gchar *height_label,
                           gdouble      height,
                           GimpUnit     size_unit,
                           const gchar *res_label,
                           gdouble      initial_res,
                           GimpUnit     initial_unit)
{
    GimpResolutionEntry *gre;
    GtkTreeModel        *model;

    gre = g_object_new (GIMP_TYPE_RESOLUTION_ENTRY, NULL);

    gre->unit = initial_unit;

    gtk_table_resize (GTK_TABLE (gre), 4, 4);

    gimp_resolution_entry_field_init (gre, &gre->x,
                                      &gre->width,
                                      X_CHANGED,
                                      initial_res, initial_unit,
                                      FALSE, 0);

    gtk_table_attach_defaults (GTK_TABLE (gre), gre->x.spinbutton,
                               1, 2,
                               3, 4);

    g_signal_connect (gre->x.adjustment, "value-changed",
                      G_CALLBACK (gimp_resolution_entry_value_callback),
                      &gre->x);

    gtk_widget_show (gre->x.spinbutton);

    gre->unitmenu = gimp_unit_combo_box_new ();
    model = gtk_combo_box_get_model (GTK_COMBO_BOX (gre->unitmenu));
    gimp_unit_store_set_has_pixels (GIMP_UNIT_STORE (model), FALSE);
    gimp_unit_store_set_has_percent (GIMP_UNIT_STORE (model), FALSE);
    gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (gre->unitmenu),
                                    initial_unit);

    gtk_table_attach (GTK_TABLE (gre), gre->unitmenu,
                      3, 4, 3, 4,
                      GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
    g_signal_connect (gre->unitmenu, "changed",
                      G_CALLBACK (gimp_resolution_entry_unit_callback),
                      gre);
    gtk_widget_show (gre->unitmenu);

    gimp_resolution_entry_field_init (gre, &gre->width,
                                      &gre->x,
                                      WIDTH_CHANGED,
                                      width, size_unit,
                                      TRUE, 0);

    gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.spinbutton,
                               1, 2,
                               1, 2);

    gtk_table_attach_defaults (GTK_TABLE (gre), gre->width.label,
                               3, 4,
                               1, 2);

    g_signal_connect (gre->width.adjustment, "value-changed",
                      G_CALLBACK (gimp_resolution_entry_value_callback),
                      &gre->width);

    gtk_widget_show (gre->width.spinbutton);
    gtk_widget_show (gre->width.label);

    gimp_resolution_entry_field_init (gre, &gre->height, &gre->x,
                                      HEIGHT_CHANGED,
                                      height, size_unit,
                                      TRUE, 0);

    gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.spinbutton,
                               1, 2, 2, 3);

    gtk_table_attach_defaults (GTK_TABLE (gre), gre->height.label,
                               3, 4, 2, 3);

    g_signal_connect (gre->height.adjustment, "value-changed",
                      G_CALLBACK (gimp_resolution_entry_value_callback),
                      &gre->height);

    gtk_widget_show (gre->height.spinbutton);
    gtk_widget_show (gre->height.label);

    if (width_label)
        gimp_resolution_entry_attach_label (gre, width_label,  1, 0, 0.0);

    if (height_label)
        gimp_resolution_entry_attach_label (gre, height_label, 2, 0, 0.0);

    if (res_label)
        gimp_resolution_entry_attach_label (gre, res_label,    3, 0, 0.0);

    return GTK_WIDGET (gre);
}