Ejemplo n.º 1
0
/**
 * gimp_option_menu_set_history:
 * @option_menu: A #GtkOptionMenu as returned by gimp_option_menu_new() or
 *               gimp_option_menu_new2().
 * @item_data:   The @item_data of the menu item you want to select.
 *
 * Iterates over all entries in a #GtkOptionMenu and selects the one
 * with the matching @item_data. Probably only makes sense to use with
 * a #GtkOptionMenu that was created using gimp_option_menu_new() or
 * gimp_option_menu_new2().
 **/
void
gimp_option_menu_set_history (GtkOptionMenu *option_menu,
                              gpointer       item_data)
{
  GList *list;
  gint   history = 0;

  g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));

  for (list = GTK_MENU_SHELL (option_menu->menu)->children;
       list;
       list = g_list_next (list))
    {
      GtkWidget *menu_item = GTK_WIDGET (list->data);

      if (GTK_IS_LABEL (gtk_bin_get_child (GTK_BIN (menu_item))) &&
          g_object_get_data (G_OBJECT (menu_item),
                             "gimp-item-data") == item_data)
        {
          break;
        }

      history++;
    }

  if (list)
    gtk_option_menu_set_history (option_menu, history);
}
Ejemplo n.º 2
0
/**
 * gimp_int_option_menu_set_sensitive:
 * @option_menu: a #GtkOptionMenu as returned by gimp_option_menu_new() or
 *            gimp_option_menu_new2().
 * @callback: a function called for each item in the menu to determine the
 *            the sensitivity state.
 * @callback_data: data to pass to the @callback function.
 *
 * Calls the given @callback for each item in the menu and passes it the
 * item_data and the @callback_data. The menu item's sensitivity is set
 * according to the return value of this function. This function does the
 * same thing as gimp_option_menu_set_sensitive(), but takes integers as
 * @item_data instead of pointers.
 **/
void
gimp_int_option_menu_set_sensitive (GtkOptionMenu                        *option_menu,
                                    GimpIntOptionMenuSensitivityCallback  callback,
                                    gpointer                              callback_data)
{
  GList *list;

  g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
  g_return_if_fail (callback != NULL);

  for (list = GTK_MENU_SHELL (option_menu->menu)->children;
       list;
       list = g_list_next (list))
    {
      GtkWidget *menu_item = GTK_WIDGET (list->data);

      if (GTK_IS_LABEL (gtk_bin_get_child (GTK_BIN (menu_item))))
        {
          gint     item_data;
          gboolean sensitive;

          item_data = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item),
                                                          "gimp-item-data"));
          sensitive = callback (item_data, callback_data);
          gtk_widget_set_sensitive (menu_item, sensitive);
        }
    }
}
Ejemplo n.º 3
0
/**
 * gimp_option_menu_set_sensitive:
 * @option_menu: a #GtkOptionMenu as returned by gimp_option_menu_new() or
 *            gimp_option_menu_new2().
 * @callback: a function called for each item in the menu to determine the
 *            the sensitivity state.
 * @callback_data: data to pass to the @callback function.
 *
 * Calls the given @callback for each item in the menu and passes it the
 * item_data and the @callback_data. The menu item's sensitivity is set
 * according to the return value of this function.
 **/
void
gimp_option_menu_set_sensitive (GtkOptionMenu                     *option_menu,
                                GimpOptionMenuSensitivityCallback  callback,
                                gpointer                           callback_data)
{
  GList *children;
  GList *list;

  g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
  g_return_if_fail (callback != NULL);

  children = gtk_container_get_children (GTK_CONTAINER (option_menu->menu));

  for (list = children; list; list = g_list_next (list))
    {
      GtkWidget *menu_item = GTK_WIDGET (list->data);

      if (GTK_IS_LABEL (gtk_bin_get_child (GTK_BIN (menu_item))))
        {
          gpointer item_data;
          gboolean sensitive;

          item_data = g_object_get_data (G_OBJECT (menu_item),
                                         "gimp-item-data");
          sensitive = callback (item_data, callback_data);
          gtk_widget_set_sensitive (menu_item, sensitive);
        }
    }

  g_list_free (children);
}
Ejemplo n.º 4
0
/**
 * gimp_int_option_menu_set_history:
 * @option_menu: A #GtkOptionMenu as returned by gimp_int_option_menu_new().
 * @item_data:   The @item_data of the menu item you want to select.
 *
 * Iterates over all entries in a #GtkOptionMenu and selects the one with the
 * matching @item_data. Probably only makes sense to use with a #GtkOptionMenu
 * that was created using gimp_int_option_menu_new(). This function does the
 * same thing as gimp_option_menu_set_history(), but takes integers as
 * @item_data instead of pointers.
 **/
void
gimp_int_option_menu_set_history (GtkOptionMenu *option_menu,
                                  gint           item_data)
{
  g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));

  gimp_option_menu_set_history (option_menu, GINT_TO_POINTER (item_data));
}
Ejemplo n.º 5
0
/**
 * Fetches the data set associated with the selected menu item in
 * the GtkOptionMenu m.
 */
gpointer
option_menu_get_selected_data(GtkOptionMenu *option_menu)
{
    GtkWidget *menu;

    g_assert(GTK_IS_OPTION_MENU(option_menu));

    menu = gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(option_menu)));
    return menu ? gtk_object_get_user_data(GTK_OBJECT(menu)) : NULL;
}
Ejemplo n.º 6
0
static void
check_visible_sizes (const gchar *stock_id, gboolean show_all)
{
  GtkIconSet *icon_set;
  GtkIconSize *sizes;
  gint n_sizes, i, j;
  GtkWidget *option_menu, *menu;
  gboolean item_visible[G_N_ELEMENTS(GladeIconSizeValues)];
  GList *children;

  for (j = 0; j < GladeIconSizeChoicesSize; j++)
    item_visible[j] = show_all;

  if (!show_all)
    {
      icon_set = gtk_icon_factory_lookup_default (stock_id);
      if (icon_set)
	{
	  gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes);
	  /* Figure out which of our choices should be visible. */
	  for (i = 0; i < n_sizes; i++)
	    {
	      for (j = 0; j < GladeIconSizeChoicesSize; j++)
		{
		  if (sizes[i] == GladeIconSizeValues[j])
		    item_visible[j] = TRUE;
		}
	    }
	  g_free (sizes);
	}
    }

  /* Show or Hide the items as appropriate. */
  option_menu = property_get_value_widget (IconSize);
  g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));

  menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
  g_return_if_fail (GTK_IS_MENU (menu));

  children = GTK_MENU_SHELL (menu)->children;
  for (j = 0; j < GladeIconSizeChoicesSize; j++)
    {
      GtkWidget *item;

      item = children->data;

      if (item_visible[j])
	gtk_widget_show (item);
      else
	gtk_widget_hide (item);

      children = children->next;
    }
}
Ejemplo n.º 7
0
static void
set_menu (GladeMenuEditor *menued, GtkOptionMenu *option)
{
  int history;

  g_return_if_fail (GLADE_IS_MENU_EDITOR (menued));
  g_return_if_fail (GTK_IS_OPTION_MENU (option));
  
  history = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (option), History));
  gtk_option_menu_set_menu (option, GTK_WIDGET (menued->menu));	
  gtk_option_menu_set_history (option, history);
}
Ejemplo n.º 8
0
/**
 * Select the menu item which has given data attached to it.
 */
void
option_menu_select_item_by_data(GtkOptionMenu *option_menu, gconstpointer data)
{
    GList *iter;
    gint i;

    g_assert(option_menu);
    g_assert(GTK_IS_OPTION_MENU(option_menu));

    iter = GTK_MENU_SHELL(gtk_option_menu_get_menu(option_menu))->children;
    for (i = 0; iter != NULL; iter = g_list_next(iter), i++) {
        if (iter->data && gtk_object_get_user_data(iter->data) == data) {
			gtk_option_menu_set_history(option_menu, i);
			return;
        }
    }

	g_warning("option_menu_select_item_by_data: no item with data %p", data);
}
Ejemplo n.º 9
0
static void
gb_menu_bar_on_edit_menu (GtkWidget *button,
			  gpointer data)
{
  GtkWidget *option, *menued, *menu;

  option = property_get_widget ();
  g_return_if_fail (GTK_IS_OPTION_MENU (option));

  /* 
   * we need to remove the menu from the option menu otherwise there
   * will be a separator where the selected menu is
   */
  g_object_set_data (G_OBJECT (option), 
		     History,
		     GINT_TO_POINTER (gtk_option_menu_get_history (GTK_OPTION_MENU (option))));
  menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option));
  if (!menu)
    menu = gb_widget_new ("GtkMenu", option);
  g_object_ref (menu);

  gtk_option_menu_set_menu (GTK_OPTION_MENU (option), gtk_menu_new ());

  menued = glade_menu_editor_new (current_project, GTK_MENU_SHELL (menu));
  g_signal_connect (menued, "destroy", G_CALLBACK (set_menu), option);

  /* I think this was hidden as it doesn't call set_menu() to reset the
     history. */
  gtk_widget_hide (GLADE_MENU_EDITOR (menued)->apply_button);

  dialogize (menued, button);
  gtk_widget_show (GTK_WIDGET (menued));

  gtk_option_menu_set_menu (GTK_OPTION_MENU (option), menu);
  g_object_unref (menu);
}
Ejemplo n.º 10
0
static G_CONST_RETURN gchar*
gail_item_get_name (AtkObject *obj)
{
  G_CONST_RETURN gchar* name;

  g_return_val_if_fail (GAIL_IS_ITEM (obj), NULL);

  name = ATK_OBJECT_CLASS (parent_class)->get_name (obj);
  if (name == NULL)
    {
      /*
       * Get the label child
       */
      GtkWidget *widget;
      GtkWidget *label;

      widget = GTK_ACCESSIBLE (obj)->widget;
      if (widget == NULL)
        /*
         * State is defunct
         */
        return NULL;

      label = get_label_from_container (widget);
      if (GTK_IS_LABEL (label))
	return gtk_label_get_text (GTK_LABEL(label));
      /*
       * If we have a menu item in a menu attached to a GtkOptionMenu
       * the label of the selected item is detached from the menu item
       */
      else if (GTK_IS_MENU_ITEM (widget))
        {
          GtkWidget *parent;
          GtkWidget *attach;
          GList *list;
          AtkObject *parent_obj;
          gint index;

          parent = gtk_widget_get_parent (widget);
          if (GTK_IS_MENU (parent))
            {
              attach = gtk_menu_get_attach_widget (GTK_MENU (parent)); 

              if (GTK_IS_OPTION_MENU (attach))
                {
                  label = get_label_from_container (attach);
                  if (GTK_IS_LABEL (label))
	            return gtk_label_get_text (GTK_LABEL(label));
                }
              list = gtk_container_get_children (GTK_CONTAINER (parent));
              index = g_list_index (list, widget);

              if (index < 0 || index > g_list_length (list))
                {
                  g_list_free (list);
                  return NULL;
                }
              g_list_free (list);

              parent_obj = atk_object_get_parent (gtk_widget_get_accessible (parent));
              if (GTK_IS_ACCESSIBLE (parent_obj))
                {
                  parent = GTK_ACCESSIBLE (parent_obj)->widget;
                  if (GTK_IS_COMBO_BOX (parent))
                    {
                      GtkTreeModel *model;
                      GtkTreeIter iter;
                      GailItem *item;
                      gint n_columns, i;

                      model = gtk_combo_box_get_model (GTK_COMBO_BOX (parent));                       
                      item = GAIL_ITEM (obj);
                      if (gtk_tree_model_iter_nth_child (model, &iter, NULL, index))
                        {
                          n_columns = gtk_tree_model_get_n_columns (model);
                          for (i = 0; i < n_columns; i++)
                            {
                              GValue value = { 0, };

                               gtk_tree_model_get_value (model, &iter, i, &value);
                               if (G_VALUE_HOLDS_STRING (&value))
                                 {
				   g_free (item->text);
                                   item->text =  (gchar *) g_value_dup_string (&value);
                                   g_value_unset (&value);
                                   break;
                                 }
                            }
                        }
                      name = item->text;
                    }
                }
            }
        }
    }
  return name;
}
Ejemplo n.º 11
0
static void 
_check_object (AtkObject *obj)
{
  AtkRole role;
  static G_CONST_RETURN char *name = NULL;
  static gboolean first_time = TRUE;

  role = atk_object_get_role (obj);
  if (role == ATK_ROLE_PUSH_BUTTON)
  /*
   * Find the specified optionmenu item
   */
    {
      AtkRole valid_roles[NUM_VALID_ROLES];
      AtkObject *atk_option_menu;
      GtkWidget *widget;

      if (name == NULL)
      {
        name = g_getenv ("TEST_ACCESSIBLE_NAME");
        if (name == NULL)
          name = "foo";
      }
      valid_roles[0] = ATK_ROLE_PUSH_BUTTON;
      atk_option_menu = find_object_by_accessible_name_and_role (obj, name,
                               valid_roles, NUM_VALID_ROLES);

      if (atk_option_menu == NULL)
        {
          g_print ("Object not found for %s\n", name);
          return;
        }
      else
        {
          g_print ("Object found for %s\n", name);
        }


      g_assert (GTK_IS_ACCESSIBLE (atk_option_menu));
      widget = GTK_ACCESSIBLE (atk_option_menu)->widget;
      g_assert (GTK_IS_OPTION_MENU (widget));

      if (first_time)
        first_time = FALSE;
      else
        return;

      /*
       * This action opens the GtkOptionMenu whose name is "foo" or whatever
       * was specified in the environment variable TEST_ACCESSIBLE_NAME
       */
      atk_action_do_action (ATK_ACTION (atk_option_menu), 0);
    }
  else if ((role == ATK_ROLE_MENU_ITEM) ||
           (role == ATK_ROLE_CHECK_MENU_ITEM) ||
           (role == ATK_ROLE_RADIO_MENU_ITEM) ||
           (role == ATK_ROLE_TEAR_OFF_MENU_ITEM))
    {
      AtkObject *parent, *child;
      AtkRole parent_role;

      /*
       * If we receive focus while waiting for the menu to be closed
       * we return immediately
       */
      if (doing_action)
        return;

      parent = atk_object_get_parent (obj);
      parent_role = atk_object_get_role (parent);
      g_assert (parent_role == ATK_ROLE_MENU);
    
      child = atk_object_ref_accessible_child (parent, 1);
      doing_action = TRUE;
      gtk_timeout_add (5000, _do_menu_item_action, child);
    }
  else
    {
      G_CONST_RETURN char *accessible_name;

      accessible_name = atk_object_get_name (obj);
      if (accessible_name)
        {
          g_print ("Name: %s\n", accessible_name);
        } 
      else if (GTK_IS_ACCESSIBLE (obj))
        {
          GtkWidget *widget = GTK_ACCESSIBLE (obj)->widget;
          g_print ("Type: %s\n", g_type_name (G_OBJECT_TYPE (widget)));
        } 
      if (role == ATK_ROLE_TABLE)
        {
          gint n_cols, i;

          n_cols = atk_table_get_n_columns (ATK_TABLE (obj));
          g_print ("Number of Columns: %d\n", n_cols);

          for (i  = 0; i < n_cols; i++)
            {
              AtkObject *header;

              header = atk_table_get_column_header (ATK_TABLE (obj), i);
              g_print ("header: %s %s\n", 
                           g_type_name (G_OBJECT_TYPE (header)),
                           atk_object_get_name (header));
            }
        }
    }
}