diff options
author | Ettore Perazzoli <ettore@src.gnome.org> | 2002-01-24 06:21:24 +0800 |
---|---|---|
committer | Ettore Perazzoli <ettore@src.gnome.org> | 2002-01-24 06:21:24 +0800 |
commit | 4eb4ae3be83fcc187ac0ca3bd104a14ceeb0786f (patch) | |
tree | df41d34e0a3fe0f77831e21bdc9f116470f9fc8c /widgets | |
parent | 8cdf205496519e8b5a436ed5747494b29777a73f (diff) | |
download | gsoc2013-evolution-4eb4ae3be83fcc187ac0ca3bd104a14ceeb0786f.tar.gz gsoc2013-evolution-4eb4ae3be83fcc187ac0ca3bd104a14ceeb0786f.tar.zst gsoc2013-evolution-4eb4ae3be83fcc187ac0ca3bd104a14ceeb0786f.zip |
[Implement an Outlook-style "New" dropdown button. It is basically
done but it needs pretty icons so I am leaving it disabled for now.]
* e-combo-button.c: Remove member `separator' from
`EComboButtonPrivate'. New members `icon', `label'.
(init): There shall be no separator no more. Init `icon' and
`label' to %NULL.
(e_combo_button_construct): Set no relief.
(e_combo_button_new): Don't get a @menu arg anymore.
(e_combo_button_construct): Likewise.
(e_combo_button_set_icon): New.
(e_combo_button_set_label): New.
(e_combo_button_set_menu): New.
(impl_clicked): New, overriding the "clicked" method for
GtkButton.
(class_init): Install.
(impl_button_release_event): Removed.
(class_init): No need to override ::release_event with this
anymore.
(impl_released): New, override for the GtkButton::released method.
(class_init): Install.
* e-shell-user-creatable-items-handler.c: New member `id' in
struct `Component'. New member `icon' in struct `MenuItem'.
(component_free): Free ->id.
(component_new): Renamed from `component_new_from_client'. Get an
@id arg and set ->id accordingly.
(e_shell_user_creatable_items_handler_add_component): New arg @id.
Pass it to `component_new'.
(e_shell_user_creatable_items_handler_setup_menus): New arg
@current_component_id.
(e_shell_user_creatable_items_handler_update_menus): New.
(set_current_component): New helper function.
(get_component_by_id): New helper function.
(add_verbs): Renamed from `add_verbs_to_ui_component()'. Get a
@shell_view instead of a @ui_component. Set the SHELL_VIEW_KEY on
the ui_component of the shell_view to point to the shell_view
itself.
(ensure_menu_items): Set item->icon to NULL.
(free_menu_items): Unref item->icon.
(ensure_menu_xml): Set the icon as well.
(get_default_action_for_view): New helper function.
(find_menu_item_for_verb): New helper function.
(shell_view_view_changed_callback): New callback, set up the label
on the "New" button depending on the current component.
(e_shell_user_creatable_items_handler_attach_menus): New. For
now, do not display the toolbar button yet.
(execute_verb): New helper function, splitting out code from
`verb_fn'.
(verb_fn): Use `execute_verb'.
(combo_button_activate_default_callback): Callback for the
"activate_default" signal on the EComboButton.
(setup_toolbar_button): Connect.
* evolution-shell-component.c: New member `icon' in
`UserCreatableItemType'.
(impl__get_userCreatableItemTypes): Put the ->icon in the
corba_type as well.
(user_creatable_item_type_new): Get a new @icon argument.
(evolution_shell_component_add_user_creatable_item): New arg
@icon.
* Evolution-ShellComponent.idl: New member `icon' in struct
`UserCreatableItemType'.
* evolution-test-component.c (register_component): Pass a NULL
@icon to `evolution_shell_component_add_user_creatable_item()'.
* e-shell-view.c (class_init): Add the signal to the class.
(e_shell_view_display_uri): Emit "view_changed".
(e_shell_view_get_current_component_id): New.
* evolution-shell-component-client.c: New member `id' in
EvolutionShellComponentClientPrivate.
(init): Init to NULL.
(impl_destroy): Free.
(evolution_shell_component_client_new_for_objref): Removed.
(evolution_shell_component_client_construct): New arg @id.
Initialize ->id from it.
(evolution_shell_component_client_get_id): New.
* e-shell-view.h: New signal "view_changed".
* evolution-activity-client.c (create_icon_from_pixbuf): Removed.
(create_corba_animated_icon_from_pixbuf_array): Removed.
(evolution_activity_client_construct): Use
`e_new_corba_animated_icon_from_pixbuf_array()' instead.
svn path=/trunk/; revision=15438
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/ChangeLog | 21 | ||||
-rw-r--r-- | widgets/misc/e-combo-button.c | 322 | ||||
-rw-r--r-- | widgets/misc/e-combo-button.h | 14 |
3 files changed, 247 insertions, 110 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 5fd0471bb5..f59af32bcf 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,24 @@ +2002-01-23 Ettore Perazzoli <ettore@ximian.com> + + * e-combo-button.c: Remove member `separator' from + `EComboButtonPrivate'. New members `icon', `label'. + (init): There shall be no separator no more. Init `icon' and + `label' to %NULL. + (e_combo_button_construct): Set no relief. + (e_combo_button_new): Don't get a @menu arg anymore. + (e_combo_button_construct): Likewise. + (e_combo_button_set_icon): New. + (e_combo_button_set_label): New. + (e_combo_button_set_menu): New. + (impl_clicked): New, overriding the "clicked" method for + GtkButton. + (class_init): Install. + (impl_button_release_event): Removed. + (class_init): No need to override ::release_event with this + anymore. + (impl_released): New, override for the GtkButton::released method. + (class_init): Install. + 2002-01-04 Jeffrey Stedfast <fejj@ximian.com> * e-charset-picker.c: Added iso-8859-8 (Hebrew; Visual) to the diff --git a/widgets/misc/e-combo-button.c b/widgets/misc/e-combo-button.c index 9f5a536ff2..c037586fc6 100644 --- a/widgets/misc/e-combo-button.c +++ b/widgets/misc/e-combo-button.c @@ -26,7 +26,6 @@ #include "e-combo-button.h" -#include <gtk/gtkvseparator.h> #include <gtk/gtkhbox.h> #include <gtk/gtklabel.h> #include <gtk/gtkmain.h> @@ -36,17 +35,13 @@ #include <gal/util/e-util.h> -enum { - ACTIVATE_DEFAULT, - LAST_SIGNAL -}; - - struct _EComboButtonPrivate { + GdkPixbuf *icon; + + GtkWidget *icon_pixmap; + GtkWidget *label; GtkWidget *arrow_pixmap; GtkWidget *hbox; - GtkWidget *separator; - GtkWidget *label_hbox; GtkMenu *menu; @@ -56,7 +51,7 @@ struct _EComboButtonPrivate { #define SPACING 2 -static char *arrow_xpm[] = { +static const char *arrow_xpm[] = { "11 5 2 1", " c none", ". c #000000000000", @@ -70,7 +65,82 @@ static char *arrow_xpm[] = { #define PARENT_TYPE gtk_button_get_type () static GtkButtonClass *parent_class = NULL; -static guint combo_button_signals[LAST_SIGNAL] = { 0 }; + +enum { + ACTIVATE_DEFAULT, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + + +/* Utility functions. */ + +static GtkWidget * +create_pixmap_widget_from_pixbuf (GdkPixbuf *pixbuf) +{ + GtkWidget *pixmap_widget; + GdkPixmap *pixmap; + GdkBitmap *mask; + + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 128); + + pixmap_widget = gtk_pixmap_new (pixmap, mask); + + gdk_pixmap_unref (pixmap); + gdk_bitmap_unref (mask); + + return pixmap_widget; +} + +static GtkWidget * +create_empty_pixmap_widget (void) +{ + GtkWidget *pixmap_widget; + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); + + pixmap_widget = create_pixmap_widget_from_pixbuf (pixbuf); + + gdk_pixbuf_unref (pixbuf); + + return pixmap_widget; +} + +static GtkWidget * +create_arrow_pixmap_widget (void) +{ + GtkWidget *pixmap_widget; + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_xpm_data (arrow_xpm); + + pixmap_widget = create_pixmap_widget_from_pixbuf (pixbuf); + + gdk_pixbuf_unref (pixbuf); + + return pixmap_widget; +} + +static void +set_icon (EComboButton *combo_button, + GdkPixbuf *pixbuf) +{ + EComboButtonPrivate *priv; + GdkPixmap *pixmap; + GdkBitmap *mask; + + priv = combo_button->priv; + + priv->icon = gdk_pixbuf_ref (pixbuf); + + gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 128); + gtk_pixmap_set (GTK_PIXMAP (priv->icon_pixmap), pixmap, mask); + + gdk_pixmap_unref (pixmap); + gdk_pixmap_unref (mask); +} /* Callbacks for the associated menu. */ @@ -140,6 +210,11 @@ impl_destroy (GtkObject *object) priv->arrow_pixmap = NULL; } + if (priv->icon != NULL) { + gdk_pixbuf_unref (priv->icon); + priv->icon = NULL; + } + g_free (priv); (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); @@ -148,48 +223,6 @@ impl_destroy (GtkObject *object) /* GtkWidget methods. */ -static void -impl_realize (GtkWidget *widget) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - GdkPixmap *arrow_gdk_pixmap; - GdkBitmap *arrow_gdk_mask; - - combo_button = E_COMBO_BUTTON (widget); - priv = combo_button->priv; - - (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); - - g_assert (priv->arrow_pixmap == NULL); - - arrow_gdk_pixmap = gdk_pixmap_create_from_xpm_d (widget->window, &arrow_gdk_mask, NULL, arrow_xpm); - priv->arrow_pixmap = gtk_pixmap_new (arrow_gdk_pixmap, arrow_gdk_mask); - gtk_widget_show (priv->arrow_pixmap); - - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->arrow_pixmap, FALSE, TRUE, SPACING); - - gdk_pixmap_unref (arrow_gdk_pixmap); - gdk_bitmap_unref (arrow_gdk_mask); -} - -static void -impl_unrealize (GtkWidget *widget) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (widget); - priv = combo_button->priv; - - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); - - if (priv->arrow_pixmap != NULL) { - gtk_widget_destroy (priv->arrow_pixmap); - priv->arrow_pixmap = NULL; - } -} - static int impl_button_press_event (GtkWidget *widget, GdkEventButton *event) @@ -203,7 +236,7 @@ impl_button_press_event (GtkWidget *widget, if (event->type == GDK_BUTTON_PRESS && event->button == 1) { GTK_BUTTON (widget)->button_down = TRUE; - if (event->x >= priv->separator->allocation.x) { + if (event->x >= priv->arrow_pixmap->allocation.x) { /* User clicked on the right side: pop up the menu. */ gtk_button_pressed (GTK_BUTTON (widget)); @@ -223,18 +256,6 @@ impl_button_press_event (GtkWidget *widget, } static int -impl_button_release_event (GtkWidget *widget, - GdkEventButton *event) -{ - if (event->button == 1) { - gtk_grab_remove (widget); - gtk_button_released (GTK_BUTTON (widget)); - } - - return TRUE; -} - -static int impl_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event) { @@ -255,38 +276,77 @@ impl_leave_notify_event (GtkWidget *widget, } +/* GtkButton methods. */ + +static void +impl_released (GtkButton *button) +{ + EComboButton *combo_button; + EComboButtonPrivate *priv; + + combo_button = E_COMBO_BUTTON (button); + priv = combo_button->priv; + + /* Massive cut & paste from GtkButton here... The only change in + behavior here is that we want to emit ::activate_default when not + the menu hasn't been popped up. */ + + if (button->button_down) { + int new_state; + + button->button_down = FALSE; + + if (button->in_button) { + gtk_button_clicked (button); + + if (! priv->menu_popped_up) + gtk_signal_emit (GTK_OBJECT (button), signals[ACTIVATE_DEFAULT]); + } + + new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL); + + if (GTK_WIDGET_STATE (button) != new_state) { + gtk_widget_set_state (GTK_WIDGET (button), new_state); + + /* We _draw () instead of queue_draw so that if the + operation blocks, the label doesn't vanish. */ + gtk_widget_draw (GTK_WIDGET (button), NULL); + } + } +} + + static void class_init (GtkObjectClass *object_class) { GtkWidgetClass *widget_class; + GtkButtonClass *button_class; parent_class = gtk_type_class (PARENT_TYPE); object_class->destroy = impl_destroy; widget_class = GTK_WIDGET_CLASS (object_class); - widget_class->realize = impl_realize; - widget_class->unrealize = impl_unrealize; - widget_class->button_press_event = impl_button_press_event; - widget_class->button_release_event = impl_button_release_event; - widget_class->leave_notify_event = impl_leave_notify_event; - - combo_button_signals[ACTIVATE_DEFAULT] = - gtk_signal_new ("activate_default", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (EComboButtonClass, activate_default), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, combo_button_signals, LAST_SIGNAL); + widget_class->button_press_event = impl_button_press_event; + widget_class->leave_notify_event = impl_leave_notify_event; + + button_class = GTK_BUTTON_CLASS (object_class); + button_class->released = impl_released; + + signals[ACTIVATE_DEFAULT] = gtk_signal_new ("activate_default", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EComboButtonClass, activate_default), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } static void init (EComboButton *combo_button) { EComboButtonPrivate *priv; - GtkWidget *label; priv = g_new (EComboButtonPrivate, 1); combo_button->priv = priv; @@ -295,58 +355,106 @@ init (EComboButton *combo_button) gtk_container_add (GTK_CONTAINER (combo_button), priv->hbox); gtk_widget_show (priv->hbox); - priv->label_hbox = gtk_hbox_new (FALSE, SPACING); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label_hbox, TRUE, TRUE, 0); - gtk_widget_show (priv->label_hbox); + priv->icon_pixmap = create_empty_pixmap_widget (); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->icon_pixmap, TRUE, TRUE, 0); + gtk_widget_show (priv->icon_pixmap); - priv->separator = gtk_vseparator_new (); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->separator, FALSE, TRUE, SPACING); - gtk_widget_show (priv->separator); + priv->label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label, TRUE, TRUE, 0); + gtk_widget_show (priv->label); - label = gtk_label_new ("TEST!!!"); - gtk_container_add (GTK_CONTAINER (priv->label_hbox), label); - gtk_widget_show (label); + priv->arrow_pixmap = create_arrow_pixmap_widget (); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->arrow_pixmap, TRUE, TRUE, 0); + gtk_widget_show (priv->arrow_pixmap); - priv->arrow_pixmap = NULL; + priv->icon = NULL; priv->menu = NULL; priv->menu_popped_up = FALSE; } void -e_combo_button_construct (EComboButton *combo_button, - GtkMenu *menu) +e_combo_button_construct (EComboButton *combo_button) { EComboButtonPrivate *priv; g_return_if_fail (combo_button != NULL); g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); priv = combo_button->priv; g_return_if_fail (priv->menu == NULL); - priv->menu = menu; - gtk_menu_attach_to_widget (menu, GTK_WIDGET (combo_button), menu_detacher); - - gtk_signal_connect (GTK_OBJECT (menu), "deactivate", - GTK_SIGNAL_FUNC (menu_deactivate_callback), - combo_button); - GTK_WIDGET_UNSET_FLAGS (combo_button, GTK_CAN_FOCUS); + + gtk_button_set_relief (GTK_BUTTON (combo_button), GTK_RELIEF_NONE); } GtkWidget * -e_combo_button_new (GtkMenu *menu) +e_combo_button_new (void) { - GtkWidget *new; + EComboButton *new; new = gtk_type_new (e_combo_button_get_type ()); + e_combo_button_construct (new); - e_combo_button_construct (E_COMBO_BUTTON (new), menu); + return GTK_WIDGET (new); +} + + +void +e_combo_button_set_icon (EComboButton *combo_button, + GdkPixbuf *pixbuf) +{ + g_return_if_fail (combo_button != NULL); + g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); + g_return_if_fail (pixbuf != NULL); + + set_icon (combo_button, pixbuf); +} + +void +e_combo_button_set_label (EComboButton *combo_button, + const char *label) +{ + EComboButtonPrivate *priv; + + g_return_if_fail (combo_button != NULL); + g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); + g_return_if_fail (label != NULL); + + priv = combo_button->priv; + + if (label == NULL) + label = ""; + + gtk_label_parse_uline (GTK_LABEL (priv->label), label); +} + +void +e_combo_button_set_menu (EComboButton *combo_button, + GtkMenu *menu) +{ + EComboButtonPrivate *priv; + + g_return_if_fail (combo_button != NULL); + g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); + g_return_if_fail (menu != NULL); + g_return_if_fail (GTK_IS_MENU (menu)); - return new; + priv = combo_button->priv; + + if (priv->menu != NULL) + gtk_menu_detach (priv->menu); + + priv->menu = menu; + if (menu == NULL) + return; + + gtk_menu_attach_to_widget (menu, GTK_WIDGET (combo_button), menu_detacher); + + gtk_signal_connect (GTK_OBJECT (menu), "deactivate", + GTK_SIGNAL_FUNC (menu_deactivate_callback), + combo_button); } diff --git a/widgets/misc/e-combo-button.h b/widgets/misc/e-combo-button.h index 7634194427..a0ad8af8f6 100644 --- a/widgets/misc/e-combo-button.h +++ b/widgets/misc/e-combo-button.h @@ -30,6 +30,8 @@ #include <gtk/gtkbutton.h> #include <gtk/gtkmenu.h> +#include <gdk-pixbuf/gdk-pixbuf.h> + #ifdef __cplusplus extern "C" { #pragma } @@ -60,10 +62,16 @@ struct _EComboButtonClass { }; -GtkType e_combo_button_get_type (void); -void e_combo_button_construct (EComboButton *combo_button, +GtkType e_combo_button_get_type (void); +void e_combo_button_construct (EComboButton *combo_button); +GtkWidget *e_combo_button_new (void); + +void e_combo_button_set_icon (EComboButton *combo_button, + GdkPixbuf *pixbuf); +void e_combo_button_set_label (EComboButton *combo_button, + const char *label); +void e_combo_button_set_menu (EComboButton *combo_button, GtkMenu *menu); -GtkWidget *e_combo_button_new (GtkMenu *menu); #ifdef __cplusplus } |