mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 22:30:22 +00:00
testgtk: Stop using ::button-press-event
This one example can just as well use a gesture.
This commit is contained in:
parent
1818e7bed2
commit
33e2f31de4
@ -3756,16 +3756,20 @@ cursor_model (void)
|
|||||||
return (GtkTreeModel *)store;
|
return (GtkTreeModel *)store;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static void
|
||||||
cursor_event (GtkWidget *widget,
|
cursor_pressed_cb (GtkGesture *gesture,
|
||||||
GdkEvent *event,
|
int n_pressed,
|
||||||
GtkWidget *entry)
|
double x,
|
||||||
|
double y,
|
||||||
|
GtkWidget *entry)
|
||||||
{
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gint i;
|
gint i;
|
||||||
const gint n = G_N_ELEMENTS (cursor_names);
|
const gint n = G_N_ELEMENTS (cursor_names);
|
||||||
GdkEventType type;
|
int button;
|
||||||
guint button;
|
|
||||||
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
||||||
|
|
||||||
name = (const gchar *)g_object_get_data (G_OBJECT (widget), "name");
|
name = (const gchar *)g_object_get_data (G_OBJECT (widget), "name");
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
@ -3777,23 +3781,13 @@ cursor_event (GtkWidget *widget,
|
|||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
type = gdk_event_get_event_type (event);
|
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
||||||
gdk_event_get_button (event, &button);
|
if (button == GDK_BUTTON_PRIMARY)
|
||||||
if (type == GDK_BUTTON_PRESS &&
|
i = (i + 1) % n;
|
||||||
(button == GDK_BUTTON_PRIMARY ||
|
else
|
||||||
button == GDK_BUTTON_SECONDARY))
|
i = (i + n - 1) % n;
|
||||||
{
|
|
||||||
if (button == GDK_BUTTON_PRIMARY)
|
|
||||||
i = (i + 1) % n;
|
|
||||||
else
|
|
||||||
i = (i + n - 1) % n;
|
|
||||||
|
|
||||||
gtk_entry_set_text (GTK_ENTRY (entry), cursor_names[i]);
|
gtk_entry_set_text (GTK_ENTRY (entry), cursor_names[i]);
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3862,6 +3856,7 @@ create_cursors (GtkWidget *widget)
|
|||||||
GtkEntryCompletion *completion;
|
GtkEntryCompletion *completion;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
gboolean cursor_demo = FALSE;
|
gboolean cursor_demo = FALSE;
|
||||||
|
GtkGesture *gesture;
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
@ -3950,8 +3945,10 @@ create_cursors (GtkWidget *widget)
|
|||||||
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (darea), 80);
|
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (darea), 80);
|
||||||
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), cursor_draw, NULL, NULL);
|
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), cursor_draw, NULL, NULL);
|
||||||
gtk_container_add (GTK_CONTAINER (frame), darea);
|
gtk_container_add (GTK_CONTAINER (frame), darea);
|
||||||
g_signal_connect (darea, "button_press_event",
|
gesture = gtk_gesture_multi_press_new (darea);
|
||||||
G_CALLBACK (cursor_event), entry);
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
|
||||||
|
g_signal_connect (gesture, "pressed", G_CALLBACK (cursor_pressed_cb), entry);
|
||||||
|
g_object_set_data_full (G_OBJECT (darea), "gesture", gesture, g_object_unref);
|
||||||
gtk_widget_show (darea);
|
gtk_widget_show (darea);
|
||||||
|
|
||||||
g_signal_connect (entry, "changed",
|
g_signal_connect (entry, "changed",
|
||||||
|
Loading…
Reference in New Issue
Block a user