Beispiel #1
0
static gboolean
cb_tearable_button_release (GtkWidget *w, GdkEventButton *event,
			    GOComboBox *combo)
{
	GtkTearoffMenuItem *tearable;

	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (w), FALSE);

	tearable = GTK_TEAROFF_MENU_ITEM (w);
	tearable->torn_off = !tearable->torn_off;

	if (!combo->priv->torn_off) {
		gboolean need_connect;

		need_connect = (!combo->priv->tearoff_window);
		go_combo_set_tearoff_state (combo, TRUE);
		if (need_connect)
			g_signal_connect_swapped (combo->priv->tearoff_window,
				"delete_event",
				G_CALLBACK (cb_popup_delete), combo);
	} else
		go_combo_box_popup_hide_unconditional (combo);

	return TRUE;
}
Beispiel #2
0
static void
gail_menu_item_real_initialize (AtkObject *obj,
                                gpointer  data)
{
  GtkWidget *widget;
  GtkWidget *parent;

  ATK_OBJECT_CLASS (gail_menu_item_parent_class)->initialize (obj, data);

  g_signal_connect (data,
                    "select",
                    G_CALLBACK (menu_item_select),
                    NULL);
  g_signal_connect (data,
                    "deselect",
                    G_CALLBACK (menu_item_deselect),
                    NULL);
  widget = GTK_WIDGET (data);
  parent = gtk_widget_get_parent (widget);
  if (GTK_IS_MENU (parent))
    {
      GtkWidget *parent_widget;

      parent_widget =  gtk_menu_get_attach_widget (GTK_MENU (parent));

      if (!GTK_IS_MENU_ITEM (parent_widget))
        parent_widget = gtk_widget_get_parent (widget);
       if (parent_widget)
        {
          atk_object_set_parent (obj, gtk_widget_get_accessible (parent_widget));
        }
    }
  g_object_set_data (G_OBJECT (obj), "atk-component-layer",
                     GINT_TO_POINTER (ATK_LAYER_POPUP));

  if (GTK_IS_TEAROFF_MENU_ITEM (data))
    obj->role = ATK_ROLE_TEAR_OFF_MENU_ITEM;
  else if (GTK_IS_SEPARATOR_MENU_ITEM (data))
    obj->role = ATK_ROLE_SEPARATOR;
  else
    obj->role = ATK_ROLE_MENU_ITEM;
}
Beispiel #3
0
/**
 * Check if the menushell already has a taroff menuitem.
 */
static gboolean 
gul_gui_menu_shell_has_tearoff (GtkMenuShell *ms)
{
	gboolean ret = FALSE;
	GList *children;
	GList *li;

	children = gtk_container_get_children (GTK_CONTAINER (ms));
	for (li = children; li; li = li->next)
	{
		if (GTK_IS_TEAROFF_MENU_ITEM (li->data))
		{
			ret = TRUE;
			break;
		}
	}
	g_list_free (children);

	return ret;
}
static gboolean
cb_tearable_button_release (GtkWidget *w, G_GNUC_UNUSED GdkEventButton *event,
			    GOComboBox *combo)
{
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (w), FALSE);

	/* FIXME: should we notify the parent menu? */

	if (!combo->priv->torn_off) {
		gboolean need_connect;

		need_connect = (!combo->priv->tearoff_window);
		go_combo_set_tearoff_state (combo, TRUE);
		if (need_connect)
			g_signal_connect_swapped (combo->priv->tearoff_window,
				"delete_event",
				G_CALLBACK (cb_popup_delete), combo);
	} else
		go_combo_box_popup_hide_unconditional (combo);

	return TRUE;
}
Beispiel #5
0
static void serializer_visit_menuitem (Serializer* self, GtkMenuItem* menuitem) {
    char* _tmp0_;
    gboolean _tmp2_ = FALSE;
    g_return_if_fail (self != NULL);
    g_return_if_fail (menuitem != NULL);
    if (GTK_IS_TEAROFF_MENU_ITEM (menuitem)) {
        return;
    }
    serializer_indent (self);
    g_string_append (self->priv->sb, "<item");
    g_string_append (self->priv->sb, _tmp0_ = g_markup_printf_escaped (" id=\"W%lu\"", (gulong) menuitem));
    _g_free0 (_tmp0_);
    if (self->priv->hybrid) {
        g_string_append (self->priv->sb, " client-side=\"1\"");
    }
    g_string_erase (self->priv->label_sb, (gssize) 0, (gssize) (-1));
    self->priv->last_item_empty = TRUE;
    self->priv->guessed_type = NULL;
    serializer_visit_container (self, (GtkContainer*) menuitem);
    if (self->priv->label_sb->len > 0) {
        char* _tmp1_;
        g_string_append (self->priv->sb, _tmp1_ = g_markup_printf_escaped (" label=\"%s\"", self->priv->label_sb->str));
        _g_free0 (_tmp1_);
        self->priv->last_item_empty = FALSE;
    }
    if (GTK_IS_SEPARATOR_MENU_ITEM (menuitem)) {
        _tmp2_ = TRUE;
    } else {
        _tmp2_ = gtk_bin_get_child ((GtkBin*) menuitem) == NULL;
    }
    if (_tmp2_) {
        self->priv->guessed_type = "s";
        self->priv->last_item_empty = FALSE;
    }
    if (GTK_IS_IMAGE_MENU_ITEM (menuitem)) {
        GtkMenuItem* _tmp3_;
        GtkWidget* _tmp4_;
        GtkImage* image;
        image = _g_object_ref0 ((_tmp4_ = gtk_image_menu_item_get_image ((_tmp3_ = menuitem, GTK_IS_IMAGE_MENU_ITEM (_tmp3_) ? ((GtkImageMenuItem*) _tmp3_) : NULL)), GTK_IS_IMAGE (_tmp4_) ? ((GtkImage*) _tmp4_) : NULL));
        if (image != NULL) {
            self->priv->guessed_type = "i";
            serializer_append_icon_attribute (self, image);
            self->priv->last_item_empty = FALSE;
        }
        _g_object_unref0 (image);
    }
    if (GTK_IS_CHECK_MENU_ITEM (menuitem)) {
        GtkMenuItem* _tmp5_;
        GtkCheckMenuItem* checkmenuitem;
        checkmenuitem = _g_object_ref0 ((_tmp5_ = menuitem, GTK_IS_CHECK_MENU_ITEM (_tmp5_) ? ((GtkCheckMenuItem*) _tmp5_) : NULL));
        if (gtk_check_menu_item_get_draw_as_radio (checkmenuitem)) {
            self->priv->guessed_type = "r";
        } else {
            self->priv->guessed_type = "c";
        }
        if (!gtk_check_menu_item_get_inconsistent (checkmenuitem)) {
            if (gtk_check_menu_item_get_active (checkmenuitem)) {
                g_string_append (self->priv->sb, " state=\"1\"");
            } else {
                g_string_append (self->priv->sb, " state=\"0\"");
            }
        }
        self->priv->last_item_empty = FALSE;
        _g_object_unref0 (checkmenuitem);
    }
    if (gtk_widget_get_visible ((GtkWidget*) menuitem) == FALSE) {
        g_string_append (self->priv->sb, " visible=\"0\"");
        self->priv->last_item_empty = FALSE;
    }
    if (gtk_widget_get_sensitive ((GtkWidget*) menuitem) == FALSE) {
        g_string_append (self->priv->sb, " sensitive=\"0\"");
    }
    if (self->priv->last_item_empty) {
        g_string_append (self->priv->sb, " visible=\"0\"");
    }
    if (self->priv->guessed_type != NULL) {
        g_string_append_printf (self->priv->sb, " type=\"%s\"", self->priv->guessed_type);
    }
    if (gtk_menu_item_get_submenu (menuitem) == NULL) {
        g_string_append (self->priv->sb, "/>");
        serializer_linebreak (self);
    } else {
        g_string_append_c (self->priv->sb, '>');
        serializer_linebreak (self);
        self->priv->level++;
        if (gtk_menu_item_get_submenu (menuitem) != NULL) {
            serializer_visit_menu (self, gtk_menu_item_get_submenu (menuitem));
        }
        self->priv->level--;
        serializer_indent (self);
        g_string_append (self->priv->sb, "</item>");
        serializer_linebreak (self);
    }
}
Beispiel #6
0
static void
sync_menu_shell (GtkMenuShell *menu_shell,
                 MenuRef       carbon_menu,
		 gboolean      toplevel,
		 gboolean      debug)
{
  GList         *children;
  GList         *l;
  MenuItemIndex  carbon_index = 1;

  if (debug)
    g_printerr ("%s: syncing shell %p\n", G_STRFUNC, menu_shell);

  carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu, toplevel);

  children = gtk_container_get_children (GTK_CONTAINER (menu_shell));

  for (l = children; l; l = l->next)
    {
      GtkWidget      *menu_item = l->data;
      CarbonMenuItem *carbon_item;

      if (GTK_IS_TEAROFF_MENU_ITEM (menu_item))
	continue;

      if (toplevel && g_object_get_data (G_OBJECT (menu_item),
					 "gtk-empty-menu-item"))
	continue;

      carbon_item = carbon_menu_item_get (menu_item);

      if (debug)
	g_printerr ("%s: carbon_item %d for menu_item %d (%s, %s)\n",
		    G_STRFUNC, carbon_item ? carbon_item->index : -1,
		    carbon_index, get_menu_label_text (menu_item, NULL),
		    g_type_name (G_TYPE_FROM_INSTANCE (menu_item)));

      if (carbon_item && carbon_item->index != carbon_index)
	{
	  if (debug)
	    g_printerr ("%s:   -> not matching, deleting\n", G_STRFUNC);

	  DeleteMenuItem (carbon_item->menu, carbon_index);
	  carbon_item = NULL;
	}

      if (!carbon_item)
	{
	  GtkWidget          *label      = NULL;
	  const gchar        *label_text;
	  CFStringRef         cfstr      = NULL;
	  MenuItemAttributes  attributes = 0;

	  if (debug)
	    g_printerr ("%s:   -> creating new\n", G_STRFUNC);

	  label_text = get_menu_label_text (menu_item, &label);
	  if (label_text)
	    cfstr = CFStringCreateWithCString (NULL, label_text,
					       kCFStringEncodingUTF8);

	  if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item))
	    attributes |= kMenuItemAttrSeparator;

	  if (!gtk_widget_is_sensitive (menu_item))
	    attributes |= kMenuItemAttrDisabled;

	  if (!gtk_widget_get_visible (menu_item))
	    attributes |= kMenuItemAttrHidden;

	  InsertMenuItemTextWithCFString (carbon_menu, cfstr,
					  carbon_index - 1,
					  attributes, 0);
	  SetMenuItemProperty (carbon_menu, carbon_index,
			       IGE_QUARTZ_MENU_CREATOR,
			       IGE_QUARTZ_ITEM_WIDGET,
			       sizeof (menu_item), &menu_item);

	  if (cfstr)
	    CFRelease (cfstr);

	  carbon_item = carbon_menu_item_connect (menu_item, label,
						  carbon_menu,
						  carbon_index);

	  if (GTK_IS_CHECK_MENU_ITEM (menu_item))
	    carbon_menu_item_update_active (carbon_item, menu_item);

	  carbon_menu_item_update_accel_closure (carbon_item, menu_item);

	  if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item)))
	    carbon_menu_item_update_submenu (carbon_item, menu_item);
	}

      carbon_index++;
    }

  g_list_free (children);
}
Beispiel #7
0
static void
sync_menu_shell (GtkMenuShell *menu_shell,
                 MenuRef       carbon_menu,
                 gboolean      toplevel)
{
    GList         *children;
    GList         *l;
    MenuItemIndex  carbon_index = 1;

    carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu);

    children = gtk_container_get_children (GTK_CONTAINER (menu_shell));

    UInt16 carbon_item_count = CountMenuItems(carbon_menu);

    for (l = children; l; l = l->next)
    {
        GtkWidget      *menu_item = l->data;
        CarbonMenuItem *carbon_item;

        if (GTK_IS_TEAROFF_MENU_ITEM (menu_item))
            continue;

        if (toplevel && g_object_get_data (G_OBJECT (menu_item),
                                           "gtk-empty-menu-item"))
            continue;

        GtkWidget *label = NULL;
        const gchar *label_text = NULL;

        label_text = get_menu_label_text (menu_item, &label);
        if (label_text && strcmp(label_text, "_SKIP_") == 0)
        {
            carbon_index++;
            continue;
        }
        else if (!label_text)
            label_text = "";

        MenuItemAttributes  attributes = 0;
        if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item))
            attributes |= kMenuItemAttrSeparator;
        if (!GTK_WIDGET_IS_SENSITIVE (menu_item))
            attributes |= kMenuItemAttrDisabled;
        if (!GTK_WIDGET_VISIBLE (menu_item))
            attributes |= kMenuItemAttrHidden;

        CFStringRef cfstr = CFStringCreateWithCString (NULL, label_text,
                                                       kCFStringEncodingUTF8);
        if (carbon_index > carbon_item_count)
            AppendMenuItemTextWithCFString(carbon_menu, cfstr, attributes, 0,
                                           NULL);
        else if (!toplevel && (carbon_index > carbon_item_count))
            InsertMenuItemTextWithCFString (carbon_menu, cfstr, 
                                            carbon_index, attributes, 0);
        else
            SetMenuItemTextWithCFString(carbon_menu, carbon_index, cfstr);
        CFRelease (cfstr);

        MenuItemAttributes c_attributes = kMenuItemAttrSectionHeader |
                                          kMenuItemAttrAutoDisable;
        if (!(attributes & kMenuItemAttrDisabled))
            c_attributes |= kMenuItemAttrDisabled;
        if (!(attributes & kMenuItemAttrSeparator))
            c_attributes |= kMenuItemAttrSeparator;
        if (!(attributes & kMenuItemAttrHidden))
            c_attributes |= kMenuItemAttrHidden;
        ChangeMenuItemAttributes(carbon_menu, carbon_index,
                                 attributes, c_attributes);
        SetMenuItemProperty (carbon_menu, carbon_index,
                             GTK_QUARTZ_MENU_CREATOR,
                             GTK_QUARTZ_ITEM_WIDGET,
                             sizeof (menu_item), &menu_item);

        carbon_item = carbon_menu_item_connect (menu_item, label,
                                                carbon_menu,
                                                carbon_index);

        if (GTK_IS_CHECK_MENU_ITEM (menu_item))
            carbon_menu_item_update_active (carbon_item, menu_item);

        carbon_menu_item_update_accel_closure (carbon_item, menu_item);
        
        if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item)))
            carbon_menu_item_update_submenu (carbon_item, menu_item);

        carbon_index++;
    }

    while (carbon_index <= carbon_item_count)
    {
        DeleteMenuItem (carbon_menu, carbon_index);
        carbon_index++;
    }

    g_list_free (children);
}