예제 #1
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_spin_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  gfloat climb_rate;
  gint digits, policy_value = GTK_UPDATE_ALWAYS, i;
  gchar *policy;
  gboolean numeric, snap, wrap;
  GtkAdjustment *adj;

  climb_rate = gb_widget_input_float (data, ClimbRate);
  /* No set function for this */
  if (data->apply)
    GTK_SPIN_BUTTON (widget)->climb_rate = climb_rate;

  digits = gb_widget_input_int (data, Digits);
  if (data->apply)
    gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), digits);

  numeric = gb_widget_input_bool (data, Numeric);
  if (data->apply)
    gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (widget), numeric);

  snap = gb_widget_input_bool (data, Snap);
  if (data->apply)
    gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (widget), snap);

  policy = gb_widget_input_choice (data, Policy);
  for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++)
    {
      if (!strcmp (policy, GbPolicyChoices[i])
	  || !strcmp (policy, GbPolicySymbols[i]))
	{
	  policy_value = GbPolicyValues[i];
	  break;
	}
    }
  if (data->apply)
    gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (widget), policy_value);

  wrap = gb_widget_input_bool (data, Wrap);
  if (data->apply)
    gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), wrap);

  adj = GTK_SPIN_BUTTON (widget)->adjustment;
  if (gb_widget_input_adjustment (data, Values, adj, "adjustment"))
    {
      gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed");
    }
}
예제 #2
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_bonobo_control_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  Bonobo_PropertyBag pb = control_get_pb (widget);
  char *moniker = gtk_object_get_data (GTK_OBJECT (widget), Moniker);
  GList *key_list, *names;

  g_assert (moniker);

  if (!pb)
    return;

  key_list = bonobo_pbclient_get_keys (pb, NULL);
  for (names = key_list; names; names = names->next) {
    CORBA_TypeCode tc;
    char          *prop = create_prop_name (moniker, names->data);

#if 0
    g_print ("Checking property: %s\n", prop);
#endif

    tc  = bonobo_pbclient_get_type (pb, names->data, NULL);
    switch (tc->kind) {
    case CORBA_tk_boolean:
    {
      gboolean val;

      val = gb_widget_input_bool (data, prop);
      if (data->apply)
        bonobo_pbclient_set_boolean (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_string:
    {
      const char *str;

      str = gb_widget_input_string (data, prop);
      if (data->apply)
        bonobo_pbclient_set_string (pb, names->data, str, NULL);

      break;
    }
    case CORBA_tk_float:
    {
      gfloat val;

      val = gb_widget_input_float (data, prop);
      if (data->apply)
        bonobo_pbclient_set_float (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_double:
    {
      gdouble val;

      val = gb_widget_input_float (data, prop);
      if (data->apply)
        bonobo_pbclient_set_double (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_long:
    {
      glong val;

      val = gb_widget_input_int (data, prop);
      if (data->apply)
        bonobo_pbclient_set_long (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_ulong:
    {
      glong val;

      val = gb_widget_input_int (data, prop);
      if (data->apply)
        bonobo_pbclient_set_ulong (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_short:
    {
      glong val;

      val = gb_widget_input_int (data, prop);
      if (data->apply)
        bonobo_pbclient_set_short (pb, names->data, val, NULL);
      break;
    }
    case CORBA_tk_ushort:
    {
      glong val;

      val = gb_widget_input_int (data, prop);
      if (data->apply)
        bonobo_pbclient_set_ushort (pb, names->data, val, NULL);
      break;
    }
    default:
      g_warning ("Unhandled type %d", tc->kind);
      break;
    }
    g_free (prop);
  }
  bonobo_pbclient_free_keys (key_list);
}
예제 #3
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
void
gb_label_set_standard_properties (GtkWidget * widget,
				  GbWidgetSetArgData * data,
				  const char *label_p,
				  const char *use_underline_p,
				  const char *use_markup_p,
				  const char *justify_p,
				  const char *wrap_p,
				  const char *selectable_p,
				  const char *xalign_p,
				  const char *yalign_p,
				  const char *xpad_p,
				  const char *ypad_p,
				  const char *focus_target_p)
{
  gchar *label, *justify, *accel_target;
  const gchar *label_text;
  gfloat xalign, yalign;
  gint xpad, ypad, i;
  gboolean wrap, selectable, set_alignment = FALSE, set_padding = FALSE;
  gboolean use_underline, use_markup;
  gboolean set_label = FALSE;

  use_underline = gb_widget_input_bool (data, use_underline_p);
  if (data->apply)
    gtk_label_set_use_underline (GTK_LABEL (widget), use_underline);

  use_markup = gb_widget_input_bool (data, use_markup_p);
  if (data->apply)
    {
      set_label = TRUE;
      gtk_object_set_data (GTK_OBJECT (widget), use_markup_p,
			   GINT_TO_POINTER (use_markup));
    }

  label = gb_widget_input_text (data, label_p);
  if (data->apply)
    {
      set_label = TRUE;
      label_text = label;
    }
  else
    {
      label_text = gtk_label_get_label (GTK_LABEL (widget));
    }

  if (set_label)
    {
      gboolean prev_use_markup;

      use_markup = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
							 use_markup_p));

      /* We try to parse the markup here, and if it isn't valid, we will
	 turn use_markup off and show it as plain text. */
      if (use_markup)
	{
	  GError *error = NULL;
	  gunichar accel_marker = 0;
	  PangoAttrList *attrs = NULL;
	  gunichar accel_char = 0;
	  gchar *text = NULL;

	  if (gtk_label_get_use_underline (GTK_LABEL (widget)))
	    accel_marker = '_';

	  /* We check it is valid markup. If it isn't we will set "use_markup"
	     to FALSE. Note that we don't need attrs, text, or accel_char but
	     it seems to crash otherwise. */
	  if (!pango_parse_markup (label_text, -1, accel_marker, &attrs, &text,
				   &accel_char, &error))
	    {
	      use_markup = FALSE;
	      g_error_free (error);
	    }
	  else
	    {
	      if (attrs)
		pango_attr_list_unref (attrs);
	      g_free (text);
	    }
	}

      /* If we are turning use_markup off, we want to do that before setting
	 the text. If we are turning it on, we want to do it after. */
      prev_use_markup = gtk_label_get_use_markup (GTK_LABEL (widget));
      if (!use_markup && prev_use_markup)
	gtk_label_set_use_markup (GTK_LABEL (widget), use_markup);

      gtk_label_set_label (GTK_LABEL (widget), label_text);

      if (use_markup && !prev_use_markup)
	gtk_label_set_use_markup (GTK_LABEL (widget), use_markup);
    }

  if (data->action == GB_APPLYING)
    g_free (label);

  justify = gb_widget_input_choice (data, justify_p);
  if (data->apply)
    {
      for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]);
	   i++)
	{
	  if (!strcmp (justify, GbJustifyChoices[i])
	      || !strcmp (justify, GbJustifySymbols[i]))
	    {
	      gtk_label_set_justify (GTK_LABEL (widget), GbJustifyValues[i]);
	      break;
	    }
	}
    }

  wrap = gb_widget_input_bool (data, wrap_p);
  if (data->apply)
    gtk_label_set_line_wrap (GTK_LABEL (widget), wrap);

  selectable = gb_widget_input_bool (data, selectable_p);
  if (data->apply)
    gtk_label_set_selectable (GTK_LABEL (widget), selectable);

  xalign = gb_widget_input_float (data, xalign_p);
  if (data->apply)
    set_alignment = TRUE;
  else
    xalign = GTK_MISC (widget)->xalign;

  yalign = gb_widget_input_float (data, yalign_p);
  if (data->apply)
    set_alignment = TRUE;
  else
    yalign = GTK_MISC (widget)->yalign;

  if (set_alignment)
    gtk_misc_set_alignment (GTK_MISC (widget), xalign, yalign);

  xpad = gb_widget_input_int (data, xpad_p);
  if (data->apply)
    set_padding = TRUE;
  else
    xpad = GTK_MISC (widget)->xpad;

  ypad = gb_widget_input_int (data, ypad_p);
  if (data->apply)
    set_padding = TRUE;
  else
    ypad = GTK_MISC (widget)->ypad;

  if (set_padding)
    gtk_misc_set_padding (GTK_MISC (widget), xpad, ypad);

  /* Labels not in buttons may have a focus target widget. */
  accel_target = gb_widget_input_combo (data, focus_target_p);
  if (data->apply)
    {
      if (!gb_label_find_mnemonic_widget (widget))
	{
	  if (!strcmp (accel_target, _("Auto")))
	    accel_target = NULL;

	  gtk_object_set_data_full (GTK_OBJECT (widget), focus_target_p,
				    g_strdup (accel_target),
				    accel_target ? g_free : NULL);
	}
    }
}
예제 #4
0
파일: gbimage.c 프로젝트: jubalh/deadbeef
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_image_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  gfloat xalign, yalign;
  gint xpad, ypad, i, pixel_size;
  gboolean set_alignment = FALSE, set_padding = FALSE, apply_icon_size;
  GtkIconSize icon_size = GTK_ICON_SIZE_BUTTON;
  gchar *icon_size_string, *icon, *icon_name;

  icon_size = GTK_IMAGE (widget)->icon_size;

  if (data->action == GB_APPLYING)
    {
      icon_size_string = gb_widget_input_choice (data, IconSize);
      apply_icon_size = data->apply;
      if (data->apply)
	{
	  for (i = 0; i < GladeIconSizeChoicesSize; i++)
	    {
	      if (!strcmp (icon_size_string, GladeIconSizeChoices[i])
		  || !strcmp (icon_size_string, GladeIconSizeSymbols[i]))
		{
		  icon_size = GladeIconSizeValues[i];
		  break;
		}
	    }
	}
    }
  else
    {
      /* We have to save the size as an integer, which sucks a bit.
	 The integer is the GtkIconSize enum value, not the actual size.*/
      int new_size = gb_widget_input_int (data, IconSize);
      apply_icon_size = data->apply;
      if (data->apply)
	icon_size = new_size;
    }

  /* When loading we use different names. */
  if (data->action == GB_LOADING)
    {
      icon = gb_widget_input_icon (data, "stock");
      if (!data->apply)
	icon = gb_widget_input_icon (data, "pixbuf");
    }
  else
    {
      icon = gb_widget_input_icon (data, Icon);
    }

  if (data->apply)
    {
      gboolean is_stock_icon = glade_util_check_is_stock_id (icon);

      /* Remove the old icon stored in the widget data, and remove the
	 pixmap from the project, if necessary. */
      gb_image_clear_pixmap (widget, data->project);

      gtk_object_set_data_full (GTK_OBJECT (widget), GladeIconKey,
				g_strdup (icon), icon ? g_free : NULL);

      if (is_stock_icon)
	{
	  GtkIconSize new_icon_size;

	  new_icon_size = check_icon_size (icon, icon_size);

	  /* If we are showing this widget's properties, we need to update
	     the sizes option menu. */
	  if (property_get_widget () == widget)
	    {
	      /* We set it sensitive before changing the value, so the child
		 menu item is changed from insensitive to sensitive if needed.
		 Otherwise it may remain insensitive. */
	      property_set_sensitive (IconSize, TRUE);
	      property_set_sensitive (PixelSize, FALSE);

	      property_set_auto_apply (FALSE);

	      check_visible_sizes (icon, FALSE);

	      /* Check the icon size is valid for the stock item, and if not
		 pick the first valid size. */
	      for (i = 0; i < GladeIconSizeChoicesSize; i++)
		{
		  if (GladeIconSizeValues[i] == new_icon_size)
		    {
		      property_set_choice (IconSize, i);
		    }
		}

	      property_set_named_icon (IconName, NULL);

	      property_set_auto_apply (TRUE);
	    }

	  gtk_image_set_from_stock (GTK_IMAGE (widget), icon,
				    new_icon_size);
	}
      else
	{
	  /* If an icon filename is set, use that, otherwise use the icon
	     we use for the palette. */
	  if (icon)
	    {
	      gtk_image_set_from_file (GTK_IMAGE (widget), icon);
	      glade_project_add_pixmap (data->project, icon);
	    }
	  else
	    {
	      gtk_image_set_from_pixmap (GTK_IMAGE (widget),
					 gbwidget.gdkpixmap, gbwidget.mask);
	    }

	  if (property_get_widget () == widget)
	    {
	      /* The icon size isn't relevant to non-stock icons. */
	      property_set_sensitive (IconSize, FALSE);
	      property_set_sensitive (PixelSize, FALSE);

	      property_set_auto_apply (FALSE);
	      property_set_named_icon (IconName, NULL);
	      property_set_auto_apply (TRUE);
	    }
	}

      /* We've recreated the icon with the new size above, so we don't need
	 to apply the size again. */
      apply_icon_size = FALSE;
    }

  /* This is for the named/themed icon. */
  icon_name = gb_widget_input_named_icon (data, IconName);
  if (data->apply)
    {
      /* Clear any stock icon or icon from a file. */
      gb_image_clear_pixmap (widget, data->project);

      gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name,
				    icon_size);

      if (property_get_widget () == widget)
	{
	  property_set_sensitive (IconSize, TRUE);
	  property_set_sensitive (PixelSize, TRUE);

	  /* Clear the Icon property. */
	  property_set_auto_apply (FALSE);
	  property_set_icon (Icon, NULL);
	  property_set_auto_apply (TRUE);
	}

      /* We've recreated the icon with the new size above, so we don't need
	 to apply the size again. */
      apply_icon_size = FALSE;
    }

  /* When we set the icon size, we reset the pixel size to -1, otherwise it
     overrides the icon size. */
  if (apply_icon_size)
    {
      gtk_image_set_pixel_size (GTK_IMAGE (widget), -1);
      g_object_set (widget, "icon_size", icon_size, NULL);

      if (property_get_widget () == widget)
	{
	  property_set_auto_apply (FALSE);
	  property_set_int (PixelSize, -1);
	  property_set_auto_apply (TRUE);
	}
    }

  /* GtkImage doesn't like a pixel size of 0 so we just skip that. */
  pixel_size = gb_widget_input_int (data, PixelSize);
  if (data->apply && pixel_size != 0)
    gtk_image_set_pixel_size (GTK_IMAGE (widget), pixel_size);

  xalign = gb_widget_input_float (data, XAlign);
  if (data->apply)
    set_alignment = TRUE;
  else
    xalign = GTK_MISC (widget)->xalign;

  yalign = gb_widget_input_float (data, YAlign);
  if (data->apply)
    set_alignment = TRUE;
  else
    yalign = GTK_MISC (widget)->yalign;

  if (set_alignment)
    gtk_misc_set_alignment (GTK_MISC (widget), xalign, yalign);

  xpad = gb_widget_input_int (data, XPad);
  if (data->apply)
    set_padding = TRUE;
  else
    xpad = GTK_MISC (widget)->xpad;

  ypad = gb_widget_input_int (data, YPad);
  if (data->apply)
    set_padding = TRUE;
  else
    ypad = GTK_MISC (widget)->ypad;

  if (set_padding)
    gtk_misc_set_padding (GTK_MISC (widget), xpad, ypad);
}