[gtranslator] Update from gedit.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Update from gedit.
- Date: Wed, 23 Jun 2010 20:29:42 +0000 (UTC)
commit ec9a21530a044cf8dd3129917759754fb95b3b41
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Jun 23 22:29:27 2010 +0200
Update from gedit.
src/gtr-status-combo-box.c | 105 ++++++++++++++++++++++++++++++++++++--------
src/gtr-status-combo-box.h | 8 +++-
2 files changed, 93 insertions(+), 20 deletions(-)
---
diff --git a/src/gtr-status-combo-box.c b/src/gtr-status-combo-box.c
index 29a6fde..8195e7f 100644
--- a/src/gtr-status-combo-box.c
+++ b/src/gtr-status-combo-box.c
@@ -22,6 +22,8 @@
#include "gtr-status-combo-box.h"
+#include <gdk/gdkkeysyms.h>
+
#define COMBO_BOX_TEXT_DATA "GtrStatusComboBoxTextData"
#define GTR_STATUS_COMBO_BOX_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GTR_TYPE_STATUS_COMBO_BOX, GtrStatusComboBoxPrivate))
@@ -155,7 +157,7 @@ gtr_status_combo_box_class_init (GtrStatusComboBoxClass *klass)
"}\n"
"widget \"*.gtr-status-combo-button\" style \"gtr-status-combo-button-style\"");
- g_type_class_add_private (object_class, sizeof(GtrStatusComboBoxPrivate));
+ g_type_class_add_private (object_class, sizeof (GtrStatusComboBoxPrivate));
}
static void
@@ -173,18 +175,20 @@ menu_position_func (GtkMenu *menu,
GtrStatusComboBox *combo)
{
GtkRequisition request;
+ GtkAllocation allocation;
*push_in = FALSE;
gtk_widget_size_request (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request);
/* get the origin... */
- gdk_window_get_origin (GTK_WIDGET (combo)->window, x, y);
+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
/* make the menu as wide as the widget */
- if (request.width < GTK_WIDGET (combo)->allocation.width)
+ gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
+ if (request.width < allocation.width)
{
- gtk_widget_set_size_request (GTK_WIDGET (menu), GTK_WIDGET (combo)->allocation.width, -1);
+ gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
}
/* position it above the widget */
@@ -192,17 +196,19 @@ menu_position_func (GtkMenu *menu,
}
static void
-button_press_event (GtkWidget *widget,
- GdkEventButton *event,
- GtrStatusComboBox *combo)
+show_menu (GtrStatusComboBox *combo,
+ guint button,
+ guint32 time)
{
GtkRequisition request;
gint max_height;
+ GtkAllocation allocation;
gtk_widget_size_request (combo->priv->menu, &request);
/* do something relative to our own height here, maybe we can do better */
- max_height = GTK_WIDGET (combo)->allocation.height * 20;
+ gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
+ max_height = allocation.height * 20;
if (request.height > max_height)
{
@@ -210,13 +216,13 @@ button_press_event (GtkWidget *widget,
gtk_widget_set_size_request (gtk_widget_get_toplevel (combo->priv->menu), -1, max_height);
}
- gtk_menu_popup (GTK_MENU (combo->priv->menu),
- NULL,
- NULL,
- (GtkMenuPositionFunc)menu_position_func,
- combo,
- event->button,
- event->time);
+ gtk_menu_popup (GTK_MENU (combo->priv->menu),
+ NULL,
+ NULL,
+ (GtkMenuPositionFunc)menu_position_func,
+ combo,
+ button,
+ time);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), TRUE);
@@ -227,6 +233,36 @@ button_press_event (GtkWidget *widget,
}
}
+static gboolean
+button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ GtrStatusComboBox *combo)
+{
+ if (event->type == GDK_BUTTON_PRESS && event->button == 1)
+ {
+ show_menu (combo, event->button,event->time);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+key_press_event (GtkWidget *widget,
+ GdkEventKey *event,
+ GtrStatusComboBox *combo)
+{
+ if (event->keyval == GDK_Return || event->keyval == GDK_ISO_Enter ||
+ event->keyval == GDK_KP_Enter || event->keyval == GDK_space ||
+ event->keyval == GDK_KP_Space)
+ {
+ show_menu (combo, 0, event->time);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
set_shadow_type (GtrStatusComboBox *combo)
{
@@ -292,9 +328,13 @@ gtr_status_combo_box_init (GtrStatusComboBox *self)
self->priv->menu = gtk_menu_new ();
g_object_ref_sink (self->priv->menu);
- g_signal_connect (self->priv->button,
- "button-press-event",
- G_CALLBACK (button_press_event),
+ g_signal_connect (self->priv->button,
+ "button-press-event",
+ G_CALLBACK (button_press_event),
+ self);
+ g_signal_connect (self->priv->button,
+ "key-press-event",
+ G_CALLBACK (key_press_event),
self);
g_signal_connect (self->priv->menu,
"deactivate",
@@ -303,12 +343,22 @@ gtr_status_combo_box_init (GtrStatusComboBox *self)
}
/* public functions */
+
+/**
+ * gtr_status_combo_box_new:
+ * @label: (allow-none):
+ */
GtkWidget *
gtr_status_combo_box_new (const gchar *label)
{
return g_object_new (GTR_TYPE_STATUS_COMBO_BOX, "label", label, NULL);
}
+/**
+ * gtr_status_combo_box_set_label:
+ * @combo:
+ * @label: (allow-none):
+ */
void
gtr_status_combo_box_set_label (GtrStatusComboBox *combo,
const gchar *label)
@@ -337,6 +387,12 @@ item_activated (GtkMenuItem *item,
gtr_status_combo_box_set_item (combo, item);
}
+/**
+ * gtr_status_combo_box_add_item:
+ * @combo:
+ * @item:
+ * @text: (allow-none):
+ */
void
gtr_status_combo_box_add_item (GtrStatusComboBox *combo,
GtkMenuItem *item,
@@ -362,6 +418,12 @@ gtr_status_combo_box_remove_item (GtrStatusComboBox *combo,
GTK_WIDGET (item));
}
+/**
+ * gtr_status_combo_box_get_items:
+ * @combo:
+ *
+ * Returns: (element-type Gtk.Widget) (transfer container):
+ */
GList *
gtr_status_combo_box_get_items (GtrStatusComboBox *combo)
{
@@ -384,6 +446,12 @@ gtr_status_combo_box_get_item_text (GtrStatusComboBox *combo,
return ret;
}
+/**
+ * gtr_status_combo_box_set_item_text:
+ * @combo:
+ * @item:
+ * @text: (allow-none):
+ */
void
gtr_status_combo_box_set_item_text (GtrStatusComboBox *combo,
GtkMenuItem *item,
@@ -416,3 +484,4 @@ gtr_status_combo_box_get_item_label (GtrStatusComboBox *combo)
return GTK_LABEL (combo->priv->item);
}
+/* ex:ts=8:noet: */
diff --git a/src/gtr-status-combo-box.h b/src/gtr-status-combo-box.h
index 257866d..0446d2c 100644
--- a/src/gtr-status-combo-box.h
+++ b/src/gtr-status-combo-box.h
@@ -39,13 +39,15 @@ typedef struct _GtrStatusComboBox GtrStatusComboBox;
typedef struct _GtrStatusComboBoxClass GtrStatusComboBoxClass;
typedef struct _GtrStatusComboBoxPrivate GtrStatusComboBoxPrivate;
-struct _GtrStatusComboBox {
+struct _GtrStatusComboBox
+{
GtkEventBox parent;
GtrStatusComboBoxPrivate *priv;
};
-struct _GtrStatusComboBoxClass {
+struct _GtrStatusComboBoxClass
+{
GtkEventBoxClass parent_class;
void (*changed) (GtrStatusComboBox *combo,
@@ -80,3 +82,5 @@ GtkLabel *gtr_status_combo_box_get_item_label (GtrStatusComboBox *combo);
G_END_DECLS
#endif /* __GTR_STATUS_COMBO_BOX_H__ */
+
+/* ex:ts=8:noet: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]