r1028@localhost: muntyan | 2005-11-25 22:35:45 -0600

MooToolItemFlags for MooAction::create_tool_item()
This commit is contained in:
Yevgen Muntyan 2005-11-26 12:48:40 +00:00
parent e4e820440e
commit 16ae989619
5 changed files with 111 additions and 15 deletions

View File

@ -245,6 +245,15 @@
) )
) )
(define-flags ToolItemFlags
(in-module "Moo")
(c-name "MooToolItemFlags")
(gtype-id "MOO_TYPE_TOOL_ITEM_FLAGS")
(values
'("menu" "MOO_TOOL_ITEM_MENU")
)
)
;; From ../mooutils/moocombo.h ;; From ../mooutils/moocombo.h
@ -2293,6 +2302,7 @@
(parameters (parameters
'("GtkWidget*" "toolbar") '("GtkWidget*" "toolbar")
'("int" "position") '("int" "position")
'("MooToolItemFlags" "flags")
) )
) )

View File

@ -59,7 +59,8 @@ static void moo_action_set_visible_real (MooAction *action,
static GtkWidget *moo_action_create_menu_item_real (MooAction *action); static GtkWidget *moo_action_create_menu_item_real (MooAction *action);
static GtkWidget *moo_action_create_tool_item_real (MooAction *action, static GtkWidget *moo_action_create_tool_item_real (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position); int position,
MooToolItemFlags flags);
static void moo_action_add_proxy (MooAction *action, static void moo_action_add_proxy (MooAction *action,
GtkWidget *proxy); GtkWidget *proxy);
@ -619,7 +620,8 @@ moo_action_create_menu_item (MooAction *action)
GtkWidget* GtkWidget*
moo_action_create_tool_item (MooAction *action, moo_action_create_tool_item (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position) int position,
MooToolItemFlags flags)
{ {
MooActionClass *klass; MooActionClass *klass;
@ -628,7 +630,7 @@ moo_action_create_tool_item (MooAction *action,
klass = MOO_ACTION_GET_CLASS (action); klass = MOO_ACTION_GET_CLASS (action);
g_return_val_if_fail (klass != NULL && klass->create_tool_item != NULL, FALSE); g_return_val_if_fail (klass != NULL && klass->create_tool_item != NULL, FALSE);
return klass->create_tool_item (action, toolbar, position); return klass->create_tool_item (action, toolbar, position, flags);
} }
@ -717,14 +719,18 @@ moo_action_create_menu_item_real (MooAction *action)
static GtkWidget* static GtkWidget*
moo_action_create_tool_item_real (MooAction *action, moo_action_create_tool_item_real (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position) int position,
MooToolItemFlags flags)
{ {
#if GTK_MINOR_VERSION >= 4 #if GTK_MINOR_VERSION >= 4
GtkToolItem *item = NULL; GtkToolItem *item = NULL;
if (action->stock_id) if (action->stock_id)
{ {
item = gtk_tool_button_new_from_stock (action->stock_id); if (flags & MOO_TOOL_ITEM_MENU)
item = gtk_menu_tool_button_new_from_stock (action->stock_id);
else
item = gtk_tool_button_new_from_stock (action->stock_id);
} }
else else
{ {
@ -741,7 +747,11 @@ moo_action_create_tool_item_real (MooAction *action,
gtk_widget_show (icon); gtk_widget_show (icon);
} }
item = gtk_tool_button_new (icon, action->label); if (flags & MOO_TOOL_ITEM_MENU)
item = gtk_menu_tool_button_new (icon, action->label);
else
item = gtk_tool_button_new (icon, action->label);
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE); gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE);
} }
@ -945,3 +955,22 @@ _moo_action_get_accel (MooAction *action)
g_return_val_if_fail (action->accel_path != NULL, ""); g_return_val_if_fail (action->accel_path != NULL, "");
return moo_get_accel (action->accel_path); return moo_get_accel (action->accel_path);
} }
GType
moo_tool_item_flags_get_type (void)
{
static GType type = 0;
if (!type)
{
static const GFlagsValue values[] = {
{ MOO_TOOL_ITEM_MENU, (char*) "MOO_TOOL_ITEM_MENU", (char*) "menu" },
{ 0, NULL, NULL }
};
type = g_flags_register_static ("MooToolItemFlags", values);
}
return type;
}

View File

@ -27,11 +27,17 @@ G_BEGIN_DECLS
#define MOO_IS_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_ACTION)) #define MOO_IS_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_ACTION))
#define MOO_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_ACTION, MooActionClass)) #define MOO_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_ACTION, MooActionClass))
#define MOO_TYPE_TOOL_ITEM_FLAGS (moo_tool_item_flags_get_type ())
typedef struct _MooAction MooAction; typedef struct _MooAction MooAction;
typedef struct _MooActionPrivate MooActionPrivate; typedef struct _MooActionPrivate MooActionPrivate;
typedef struct _MooActionClass MooActionClass; typedef struct _MooActionClass MooActionClass;
typedef enum {
MOO_TOOL_ITEM_MENU = 1 << 0
} MooToolItemFlags;
struct _MooAction struct _MooAction
{ {
GObject object; GObject object;
@ -66,7 +72,8 @@ struct _MooActionClass
GtkWidget *(*create_menu_item) (MooAction *action); GtkWidget *(*create_menu_item) (MooAction *action);
GtkWidget *(*create_tool_item) (MooAction *action, GtkWidget *(*create_tool_item) (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position); int position,
MooToolItemFlags flags);
void (*add_proxy) (MooAction *action, void (*add_proxy) (MooAction *action,
GtkWidget *widget); GtkWidget *widget);
@ -81,6 +88,7 @@ struct _MooActionClass
GType moo_action_get_type (void) G_GNUC_CONST; GType moo_action_get_type (void) G_GNUC_CONST;
GType moo_tool_item_flags_get_type (void) G_GNUC_CONST;
void moo_action_activate (MooAction *action); void moo_action_activate (MooAction *action);
@ -95,7 +103,8 @@ gboolean moo_action_get_no_accel (MooAction *action);
GtkWidget *moo_action_create_menu_item (MooAction *action); GtkWidget *moo_action_create_menu_item (MooAction *action);
GtkWidget *moo_action_create_tool_item (MooAction *action, GtkWidget *moo_action_create_tool_item (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position); int position,
MooToolItemFlags flags);
void moo_action_set_sensitive (MooAction *action, void moo_action_set_sensitive (MooAction *action,
gboolean sensitive); gboolean sensitive);

View File

@ -38,7 +38,8 @@ static void moo_toggle_action_finalize (GObject *object)
static GtkWidget *create_menu_item (MooAction *action); static GtkWidget *create_menu_item (MooAction *action);
static GtkWidget *create_tool_item (MooAction *action, static GtkWidget *create_tool_item (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position); int position,
MooToolItemFlags flags);
static void moo_toggle_action_toggled (MooToggleAction *action, static void moo_toggle_action_toggled (MooToggleAction *action,
gboolean active); gboolean active);
@ -279,7 +280,8 @@ create_menu_item (MooAction *action)
static GtkWidget* static GtkWidget*
create_tool_item (MooAction *action, create_tool_item (MooAction *action,
GtkWidget *toolbar, GtkWidget *toolbar,
int position) int position,
G_GNUC_UNUSED MooToolItemFlags flags)
{ {
#if GTK_CHECK_VERSION(2,4,0) #if GTK_CHECK_VERSION(2,4,0)
GtkToolItem *item = NULL; GtkToolItem *item = NULL;

View File

@ -1921,6 +1921,34 @@ create_tool_separator (MooUIXML *xml,
} }
#define IS_MENU_TOOL_BUTTON(wid) (GTK_IS_MENU_TOOL_BUTTON (wid) || \
MOO_IS_MENU_TOOL_BUTTON (wid))
static void
menu_tool_button_set_menu (GtkWidget *button,
GtkWidget *menu)
{
if (GTK_IS_MENU_TOOL_BUTTON (button))
gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (button), menu);
else if (MOO_IS_MENU_TOOL_BUTTON (button))
moo_menu_tool_button_set_menu (MOO_MENU_TOOL_BUTTON (button), menu);
else
g_return_if_reached ();
}
static GtkWidget*
menu_tool_button_get_menu (GtkWidget *button)
{
if (GTK_IS_MENU_TOOL_BUTTON (button))
return gtk_menu_tool_button_get_menu (GTK_MENU_TOOL_BUTTON (button));
else if (MOO_IS_MENU_TOOL_BUTTON (button))
return moo_menu_tool_button_get_menu (MOO_MENU_TOOL_BUTTON (button));
else
g_return_val_if_reached (NULL);
}
static gboolean static gboolean
create_tool_item (MooUIXML *xml, create_tool_item (MooUIXML *xml,
Toplevel *toplevel, Toplevel *toplevel,
@ -1947,7 +1975,25 @@ create_tool_item (MooUIXML *xml,
if (action->dead) if (action->dead)
return TRUE; return TRUE;
tool_item = moo_action_create_tool_item (action, GTK_WIDGET (toolbar), index); tool_item = moo_action_create_tool_item (action, GTK_WIDGET (toolbar), index,
node->children ? MOO_TOOL_ITEM_MENU : 0);
if (node->children)
{
if (!IS_MENU_TOOL_BUTTON (tool_item))
{
g_critical ("%s: oops", G_STRLOC);
}
else
{
GtkWidget *menu = gtk_menu_new ();
/* XXX empty menu */
gtk_widget_show (menu);
menu_tool_button_set_menu (tool_item, menu);
fill_menu_shell (xml, toplevel, node, GTK_MENU_SHELL (menu));
}
}
} }
else else
{ {
@ -1975,7 +2021,7 @@ create_tool_item (MooUIXML *xml,
menu = gtk_menu_new (); menu = gtk_menu_new ();
/* XXX empty menu */ /* XXX empty menu */
gtk_widget_show (menu); gtk_widget_show (menu);
moo_menu_tool_button_set_menu (MOO_MENU_TOOL_BUTTON (tool_item), menu); menu_tool_button_set_menu (tool_item, menu);
fill_menu_shell (xml, toplevel, node, GTK_MENU_SHELL (menu)); fill_menu_shell (xml, toplevel, node, GTK_MENU_SHELL (menu));
} }
@ -2190,17 +2236,17 @@ toplevel_add_node (MooUIXML *xml,
update_separators (parent, toplevel); update_separators (parent, toplevel);
} }
else if (MOO_IS_MENU_TOOL_BUTTON (parent_widget)) else if (IS_MENU_TOOL_BUTTON (parent_widget))
{ {
GtkWidget *menu; GtkWidget *menu;
menu = moo_menu_tool_button_get_menu (MOO_MENU_TOOL_BUTTON (parent_widget)); menu = menu_tool_button_get_menu (parent_widget);
if (!menu) if (!menu)
{ {
menu = gtk_menu_new (); menu = gtk_menu_new ();
gtk_widget_show (menu); gtk_widget_show (menu);
moo_menu_tool_button_set_menu (MOO_MENU_TOOL_BUTTON (parent_widget), menu); menu_tool_button_set_menu (parent_widget, menu);
} }
switch (node->type) switch (node->type)