X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fcustomentry.c;h=dc5848ec087b86e338d8c7b25b2487425c15e2ea;hb=36e1a0b66c81e1f2a8b5633c4fac259ffb046c98;hp=6282937016bac0abf6038e5750c7d307f1b9308c;hpb=573068f2bdcd3f8796e9646668fed910a90f890b;p=pspp
diff --git a/src/ui/gui/customentry.c b/src/ui/gui/customentry.c
index 6282937016..dc5848ec08 100644
--- a/src/ui/gui/customentry.c
+++ b/src/ui/gui/customentry.c
@@ -1,11 +1,9 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2005 Free Software Foundation
- Written by John Darrington
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2005, 2007, 2010, 2011, 2012 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -14,13 +12,10 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-*/
+ along with this program. If not, see . */
-/*
- This widget is a subclass of GtkEntry. It's an entry widget with a
+/*
+ This widget is a subclass of GtkEntry. It's an entry widget with a
button on the right hand side.
This code is heavily based upon the GtkSpinButton widget. Therefore
@@ -46,23 +41,23 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see
+ * .
*/
+
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include
-#include
-#include "customentry.h"
+#include
-#define P_(A) A
+#include
+#include "customentry.h"
+#include "helper.h"
static void psppire_custom_entry_class_init (PsppireCustomEntryClass *klass);
static void psppire_custom_entry_init (PsppireCustomEntry *ce);
@@ -100,7 +95,7 @@ psppire_custom_entry_get_type (void)
(GInstanceInitFunc) psppire_custom_entry_init,
};
- ce_type = g_type_register_static (GTK_TYPE_ENTRY, "PsppireCustomEntry",
+ ce_type = g_type_register_static (GTK_TYPE_ENTRY, "PsppireCustomEntry",
&ce_info, 0);
}
@@ -111,7 +106,7 @@ psppire_custom_entry_get_type (void)
static void
psppire_custom_entry_map (GtkWidget *widget)
{
- if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_MAPPED (widget))
+ if (gtk_widget_get_realized (widget) && !gtk_widget_get_mapped (widget))
{
GTK_WIDGET_CLASS (parent_class)->map (widget);
gdk_window_show (PSPPIRE_CUSTOM_ENTRY (widget)->panel);
@@ -121,7 +116,7 @@ psppire_custom_entry_map (GtkWidget *widget)
static void
psppire_custom_entry_unmap (GtkWidget *widget)
{
- if (GTK_WIDGET_MAPPED (widget))
+ if (gtk_widget_get_mapped (widget))
{
gdk_window_hide (PSPPIRE_CUSTOM_ENTRY (widget)->panel);
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
@@ -150,14 +145,14 @@ psppire_custom_entry_realize (GtkWidget *widget)
GTK_WIDGET_CLASS (parent_class)->realize (widget);
widget->allocation.width = real_width;
-
+
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
- | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK
+ attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK
| GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
@@ -169,8 +164,8 @@ psppire_custom_entry_realize (GtkWidget *widget)
widget->requisition.height) / 2;
attributes.width = button_size + 2 * widget->style->xthickness;
attributes.height = widget->requisition.height;
-
- custom_entry->panel = gdk_window_new (gtk_widget_get_parent_window (widget),
+
+ custom_entry->panel = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gdk_window_set_user_data (custom_entry->panel, widget);
@@ -186,7 +181,7 @@ psppire_custom_entry_realize (GtkWidget *widget)
static gint
psppire_custom_entry_get_button_width (PsppireCustomEntry *custom_entry)
{
- const gint size = pango_font_description_get_size
+ const gint size = pango_font_description_get_size
(GTK_WIDGET (custom_entry)->style->font_desc);
gint button_width = MAX (PANGO_PIXELS (size), MIN_BUTTON_WIDTH);
@@ -197,10 +192,10 @@ psppire_custom_entry_get_button_width (PsppireCustomEntry *custom_entry)
/**
* custom_entry_get_shadow_type:
* @custom_entry: a #PsppireCustomEntry
- *
+ *
* Convenience function to Get the shadow type from the underlying widget's
* style.
- *
+ *
* Return value: the #GtkShadowType
**/
static gint
@@ -237,7 +232,7 @@ psppire_custom_entry_redraw (PsppireCustomEntry *custom_entry)
widget = GTK_WIDGET (custom_entry);
- if (GTK_WIDGET_DRAWABLE (widget))
+ if (gtk_widget_is_drawable (widget))
{
gtk_widget_queue_draw (widget);
@@ -246,20 +241,21 @@ psppire_custom_entry_redraw (PsppireCustomEntry *custom_entry)
*/
gdk_window_invalidate_rect (custom_entry->panel, NULL, TRUE);
}
-}
+}
static gint
psppire_custom_entry_expose (GtkWidget *widget,
GdkEventExpose *event)
{
- PsppireCustomEntry *ce = PSPPIRE_CUSTOM_ENTRY(widget);
+ PsppireCustomEntry *ce = PSPPIRE_CUSTOM_ENTRY (widget);
g_return_val_if_fail (PSPPIRE_IS_CUSTOM_ENTRY (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
- if (GTK_WIDGET_DRAWABLE (widget))
+ if (gtk_widget_is_drawable (widget))
{
+ gboolean is_editable;
GtkShadowType shadow_type;
GdkRectangle rect;
@@ -271,19 +267,19 @@ psppire_custom_entry_expose (GtkWidget *widget,
gdk_drawable_get_size (ce->panel, &rect.width, &rect.height);
- gdk_window_begin_paint_rect (ce->panel, &rect);
+ gdk_window_begin_paint_rect (ce->panel, &rect);
shadow_type = psppire_custom_entry_get_shadow_type (ce);
-
- if (shadow_type != GTK_SHADOW_NONE)
- {
- gtk_paint_box (widget->style, ce->panel,
- GTK_STATE_NORMAL, shadow_type,
- NULL, widget, "customentry",
- rect.x, rect.y, rect.width, rect.height);
- }
+ g_object_get (widget, "editable", &is_editable, NULL);
+
+ gtk_paint_box (widget->style, ce->panel,
+ is_editable ? GTK_STATE_NORMAL: GTK_STATE_INSENSITIVE,
+ shadow_type,
+ NULL, widget, "customentry",
+ rect.x, rect.y, rect.width, rect.height);
+
gdk_window_end_paint (ce->panel);
}
@@ -308,12 +304,10 @@ psppire_custom_entry_class_init (PsppireCustomEntryClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class;
- GtkEntryClass *entry_class;
parent_class = g_type_class_peek_parent (klass);
widget_class = (GtkWidgetClass*) klass;
- entry_class = (GtkEntryClass*) klass;
widget_class->map = psppire_custom_entry_map;
widget_class->unmap = psppire_custom_entry_unmap;
@@ -327,24 +321,24 @@ psppire_custom_entry_class_init (PsppireCustomEntryClass *klass)
widget_class->size_allocate = psppire_custom_entry_size_allocate;
- gtk_widget_class_install_style_property_parser
+ gtk_widget_class_install_style_property_parser
(widget_class,
- g_param_spec_enum ("shadow_type",
- "Shadow Type",
- P_("Style of bevel around the custom entry button"),
+ g_param_spec_enum ("shadow_type",
+ "Shadow Type",
+ "Style of bevel around the custom entry button",
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_ETCHED_IN,
G_PARAM_READABLE),
gtk_rc_property_parse_enum);
- custom_entry_signals[CLICKED] =
+ custom_entry_signals[CLICKED] =
g_signal_new ("clicked",
- G_TYPE_FROM_CLASS(gobject_class),
+ G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
+ G_TYPE_NONE,
0);
@@ -371,10 +365,13 @@ psppire_custom_entry_button_press (GtkWidget *widget,
if (event->window == ce->panel)
{
- if (!GTK_WIDGET_HAS_FOCUS (widget))
+ gboolean is_editable ;
+ if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
- if ( event->button == 1)
+ g_object_get (ce, "editable", &is_editable, NULL);
+
+ if ( event->button == 1 && is_editable )
g_signal_emit (widget, custom_entry_signals[CLICKED], 0);
}
@@ -400,11 +397,11 @@ psppire_custom_entry_size_allocate (GtkWidget *widget,
g_return_if_fail (allocation != NULL);
ce = PSPPIRE_CUSTOM_ENTRY (widget);
- button_width = psppire_custom_entry_get_button_width(ce);
+ button_width = psppire_custom_entry_get_button_width (ce);
panel_width = button_width + 2 * widget->style->xthickness;
-
+
widget->allocation = *allocation;
-
+
entry_allocation = *allocation;
entry_allocation.width -= panel_width;
@@ -426,13 +423,13 @@ psppire_custom_entry_size_allocate (GtkWidget *widget,
GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, &entry_allocation);
- if (GTK_WIDGET_REALIZED (widget))
+ if (gtk_widget_get_realized (widget))
{
- gdk_window_move_resize (PSPPIRE_CUSTOM_ENTRY (widget)->panel,
+ gdk_window_move_resize (PSPPIRE_CUSTOM_ENTRY (widget)->panel,
panel_allocation.x,
panel_allocation.y,
panel_allocation.width,
- panel_allocation.height);
+ panel_allocation.height);
}
psppire_custom_entry_redraw (ce);