2014-05-16 23:44:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
#include "gestures.h"
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtksizegroup.h"
|
|
|
|
#include "gtkcomboboxtext.h"
|
|
|
|
#include "gtklistbox.h"
|
|
|
|
#include "gtkgesture.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkframe.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2014-05-16 23:44:43 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-10-11 01:40:53 +00:00
|
|
|
PROP_OBJECT_TREE
|
2014-05-16 23:44:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkInspectorGesturesPrivate
|
|
|
|
{
|
|
|
|
GtkSizeGroup *sizegroup;
|
|
|
|
GObject *object;
|
2014-11-22 18:12:41 +00:00
|
|
|
GtkInspectorObjectTree *object_tree;
|
2014-05-16 23:44:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorGestures, gtk_inspector_gestures, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_gestures_init (GtkInspectorGestures *sl)
|
|
|
|
{
|
|
|
|
sl->priv = gtk_inspector_gestures_get_instance_private (sl);
|
|
|
|
sl->priv->sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
|
|
|
g_object_set (sl,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
2014-11-22 18:12:41 +00:00
|
|
|
"margin-start", 60,
|
|
|
|
"margin-end", 60,
|
|
|
|
"margin-bottom", 60,
|
2014-05-16 23:44:43 +00:00
|
|
|
"spacing", 10,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_all (GtkInspectorGestures *sl)
|
|
|
|
{
|
|
|
|
GList *children, *l;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (sl));
|
|
|
|
for (l = children; l; l = l->next)
|
|
|
|
{
|
|
|
|
child = l->data;
|
|
|
|
gtk_container_remove (GTK_CONTAINER (sl), child);
|
|
|
|
}
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
phase_changed_cb (GtkComboBox *combo, GtkInspectorGestures *sl)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
GtkPropagationPhase phase;
|
|
|
|
GtkGesture *gesture;
|
|
|
|
|
|
|
|
phase = gtk_combo_box_get_active (combo);
|
|
|
|
row = gtk_widget_get_ancestor (GTK_WIDGET (combo), GTK_TYPE_LIST_BOX_ROW);
|
|
|
|
gesture = GTK_GESTURE (g_object_get_data (G_OBJECT (row), "gesture"));
|
2014-05-26 10:08:55 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), phase);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_activated (GtkListBox *box,
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
GtkInspectorGestures *sl)
|
|
|
|
{
|
|
|
|
GObject *gesture;
|
|
|
|
|
|
|
|
gesture = G_OBJECT (g_object_get_data (G_OBJECT (row), "gesture"));
|
2014-11-22 18:12:41 +00:00
|
|
|
gtk_inspector_object_tree_select_object (sl->priv->object_tree, gesture);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_gesture (GtkInspectorGestures *sl,
|
|
|
|
GObject *object,
|
|
|
|
GtkWidget *listbox,
|
|
|
|
GtkGesture *gesture,
|
|
|
|
GtkPropagationPhase phase)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *combo;
|
|
|
|
|
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (listbox), row);
|
|
|
|
gtk_widget_show (row);
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 40);
|
|
|
|
gtk_container_add (GTK_CONTAINER (row), box);
|
|
|
|
g_object_set (box, "margin", 10, NULL);
|
|
|
|
gtk_widget_show (box);
|
|
|
|
label = gtk_label_new (g_type_name_from_instance ((GTypeInstance*)gesture));
|
|
|
|
g_object_set (label, "xalign", 0.0, NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), label);
|
|
|
|
gtk_size_group_add_widget (sl->priv->sizegroup, label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_NONE, _("None"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_CAPTURE, _("Capture"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_BUBBLE, _("Bubble"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_TARGET, _("Target"));
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), phase);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), combo);
|
|
|
|
gtk_widget_show (combo);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (row), "gesture", gesture);
|
|
|
|
g_signal_connect (combo, "changed", G_CALLBACK (phase_changed_cb), sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_gesture_group (GtkInspectorGestures *sl,
|
|
|
|
GObject *object,
|
|
|
|
GtkGesture *gesture,
|
|
|
|
GHashTable *hash)
|
|
|
|
{
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *listbox;
|
|
|
|
GList *list, *l;
|
|
|
|
GtkGesture *g;
|
|
|
|
GtkPropagationPhase phase;
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
gtk_widget_set_halign (frame, GTK_ALIGN_CENTER);
|
|
|
|
|
|
|
|
listbox = gtk_list_box_new ();
|
|
|
|
g_signal_connect (listbox, "row-activated", G_CALLBACK (row_activated), sl);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), listbox);
|
|
|
|
gtk_widget_show (listbox);
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (listbox), GTK_SELECTION_NONE);
|
|
|
|
|
|
|
|
list = gtk_gesture_get_group (gesture);
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
g = l->data;
|
|
|
|
phase = GPOINTER_TO_INT (g_hash_table_lookup (hash, g));
|
|
|
|
add_gesture (sl, object, listbox, g, phase);
|
|
|
|
g_hash_table_remove (hash, g);
|
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sl), frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_gestures_set_object (GtkInspectorGestures *sl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2014-11-09 02:29:51 +00:00
|
|
|
GHashTable *hash;
|
|
|
|
GHashTableIter iter;
|
|
|
|
GList *list, *l;
|
|
|
|
gint phase;
|
2014-11-22 18:12:41 +00:00
|
|
|
const gchar *title;
|
|
|
|
GtkWidget *label;
|
2014-11-09 02:29:51 +00:00
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
clear_all (sl);
|
2014-11-09 02:29:51 +00:00
|
|
|
gtk_widget_hide (GTK_WIDGET (sl));
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2014-11-09 02:29:51 +00:00
|
|
|
if (!GTK_IS_WIDGET (object))
|
|
|
|
return;
|
|
|
|
|
2014-11-22 18:12:41 +00:00
|
|
|
title = (const gchar *)g_object_get_data (object, "gtk-inspector-object-title");
|
|
|
|
label = gtk_label_new (title);
|
|
|
|
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_margin_top (label, 12);
|
|
|
|
gtk_widget_set_margin_bottom (label, 30);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (sl), label);
|
|
|
|
|
2014-11-09 02:29:51 +00:00
|
|
|
hash = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
|
|
for (phase = GTK_PHASE_NONE; phase <= GTK_PHASE_TARGET; phase++)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2014-11-09 02:29:51 +00:00
|
|
|
list = _gtk_widget_list_controllers (GTK_WIDGET (object), phase);
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
g_hash_table_insert (hash, l->data, GINT_TO_POINTER (phase));
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2014-11-09 02:29:51 +00:00
|
|
|
if (g_hash_table_size (hash))
|
|
|
|
gtk_widget_show (GTK_WIDGET (sl));
|
|
|
|
|
|
|
|
while (g_hash_table_size (hash) > 0)
|
|
|
|
{
|
|
|
|
gpointer key, value;
|
|
|
|
GtkGesture *gesture;
|
|
|
|
g_hash_table_iter_init (&iter, hash);
|
2015-07-17 19:55:18 +00:00
|
|
|
(void)g_hash_table_iter_next (&iter, &key, &value);
|
2014-11-09 02:29:51 +00:00
|
|
|
gesture = key;
|
|
|
|
add_gesture_group (sl, object, gesture, hash);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
2014-11-09 02:29:51 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (hash);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorGestures *sl = GTK_INSPECTOR_GESTURES (object);
|
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
case PROP_OBJECT_TREE:
|
|
|
|
g_value_take_object (value, sl->priv->object_tree);
|
2014-05-16 23:44:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorGestures *sl = GTK_INSPECTOR_GESTURES (object);
|
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
case PROP_OBJECT_TREE:
|
|
|
|
sl->priv->object_tree = g_value_get_object (value);
|
2014-05-16 23:44:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_gestures_class_init (GtkInspectorGesturesClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_OBJECT_TREE,
|
|
|
|
g_param_spec_object ("object-tree", "Widget Tree", "Widget tree",
|
2014-05-16 23:44:43 +00:00
|
|
|
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|