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
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
#include "controllers.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"
|
2018-09-11 02:41:52 +00:00
|
|
|
#include "gtkflattenlistmodel.h"
|
|
|
|
#include "gtkframe.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkgesture.h"
|
|
|
|
#include "gtklabel.h"
|
2018-09-11 02:41:52 +00:00
|
|
|
#include "gtklistbox.h"
|
|
|
|
#include "gtkmaplistmodel.h"
|
|
|
|
#include "gtkpropertylookuplistmodelprivate.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtksortlistmodel.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#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
|
|
|
};
|
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
struct _GtkInspectorControllersPrivate
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2018-09-10 23:56:42 +00:00
|
|
|
GtkWidget *listbox;
|
2018-09-11 02:41:52 +00:00
|
|
|
GtkPropertyLookupListModel *model;
|
2014-05-16 23:44:43 +00:00
|
|
|
GtkSizeGroup *sizegroup;
|
2014-11-22 18:12:41 +00:00
|
|
|
GtkInspectorObjectTree *object_tree;
|
2014-05-16 23:44:43 +00:00
|
|
|
};
|
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorControllers, gtk_inspector_controllers, GTK_TYPE_BOX)
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2018-09-10 23:56:42 +00:00
|
|
|
static void
|
2018-09-11 00:25:37 +00:00
|
|
|
row_activated (GtkListBox *box,
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
GtkInspectorControllers *sl)
|
2018-09-10 23:56:42 +00:00
|
|
|
{
|
2018-09-11 00:25:37 +00:00
|
|
|
GObject *controller;
|
2018-09-10 23:56:42 +00:00
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
controller = G_OBJECT (g_object_get_data (G_OBJECT (row), "controller"));
|
|
|
|
gtk_inspector_object_tree_select_object (sl->priv->object_tree, controller);
|
2018-09-10 23:56:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
static void
|
2018-09-11 00:25:37 +00:00
|
|
|
gtk_inspector_controllers_init (GtkInspectorControllers *sl)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2018-09-11 02:41:52 +00:00
|
|
|
GtkWidget *sw, *box;
|
2018-09-10 23:56:42 +00:00
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
sl->priv = gtk_inspector_controllers_get_instance_private (sl);
|
2014-05-16 23:44:43 +00:00
|
|
|
sl->priv->sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
2018-09-11 02:41:52 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
|
|
|
g_object_set (box,
|
2014-11-22 18:12:41 +00:00
|
|
|
"margin-start", 60,
|
|
|
|
"margin-end", 60,
|
2016-03-07 01:41:28 +00:00
|
|
|
"margin-top", 60,
|
|
|
|
"margin-bottom", 30,
|
2014-05-16 23:44:43 +00:00
|
|
|
NULL);
|
2018-09-11 02:41:52 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (sw), box);
|
|
|
|
gtk_widget_set_hexpand (box, TRUE);
|
|
|
|
gtk_widget_set_vexpand (box, TRUE);
|
2018-09-10 23:56:42 +00:00
|
|
|
|
|
|
|
sl->priv->listbox = gtk_list_box_new ();
|
2018-09-11 02:41:52 +00:00
|
|
|
gtk_widget_set_halign (sl->priv->listbox, GTK_ALIGN_CENTER);
|
2018-09-10 23:56:42 +00:00
|
|
|
g_signal_connect (sl->priv->listbox, "row-activated", G_CALLBACK (row_activated), sl);
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (sl->priv->listbox), GTK_SELECTION_NONE);
|
2018-09-11 02:41:52 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), sl->priv->listbox);
|
2018-09-10 23:56:42 +00:00
|
|
|
|
2018-09-11 02:41:52 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (sl), sw);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-09-11 00:25:37 +00:00
|
|
|
phase_changed_cb (GtkComboBox *combo,
|
|
|
|
GtkInspectorControllers *sl)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
GtkPropagationPhase phase;
|
2018-09-10 23:56:42 +00:00
|
|
|
GtkEventController *controller;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
|
|
|
phase = gtk_combo_box_get_active (combo);
|
|
|
|
row = gtk_widget_get_ancestor (GTK_WIDGET (combo), GTK_TYPE_LIST_BOX_ROW);
|
2018-09-11 00:25:37 +00:00
|
|
|
controller = GTK_EVENT_CONTROLLER (g_object_get_data (G_OBJECT (row), "controller"));
|
2018-09-10 23:56:42 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (controller, phase);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 02:19:06 +00:00
|
|
|
static GtkWidget *
|
|
|
|
create_controller_widget (gpointer item,
|
|
|
|
gpointer user_data)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2018-09-11 02:19:06 +00:00
|
|
|
GtkEventController *controller = item;
|
|
|
|
GtkInspectorControllers *sl = user_data;
|
2014-05-16 23:44:43 +00:00
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *combo;
|
|
|
|
|
|
|
|
row = gtk_list_box_row_new ();
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 40);
|
|
|
|
gtk_container_add (GTK_CONTAINER (row), box);
|
|
|
|
g_object_set (box, "margin", 10, NULL);
|
2018-09-10 23:56:42 +00:00
|
|
|
label = gtk_label_new (G_OBJECT_TYPE_NAME (controller));
|
2014-05-16 23:44:43 +00:00
|
|
|
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_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
2016-02-16 23:33:16 +00:00
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_NONE, C_("event phase", "None"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_CAPTURE, C_("event phase", "Capture"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_BUBBLE, C_("event phase", "Bubble"));
|
|
|
|
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combo), GTK_PHASE_TARGET, C_("event phase", "Target"));
|
2018-09-10 23:56:42 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), gtk_event_controller_get_propagation_phase (controller));
|
2014-05-16 23:44:43 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), combo);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
|
|
|
|
2018-09-11 00:25:37 +00:00
|
|
|
g_object_set_data (G_OBJECT (row), "controller", controller);
|
2014-05-16 23:44:43 +00:00
|
|
|
g_signal_connect (combo, "changed", G_CALLBACK (phase_changed_cb), sl);
|
2018-09-11 02:19:06 +00:00
|
|
|
|
|
|
|
return row;
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 02:41:52 +00:00
|
|
|
static gpointer
|
|
|
|
map_to_controllers (gpointer widget,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
gpointer result = gtk_widget_observe_controllers (widget);
|
|
|
|
g_object_unref (widget);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_phases (GtkPropagationPhase first,
|
|
|
|
GtkPropagationPhase second)
|
|
|
|
{
|
|
|
|
int priorities[] = {
|
|
|
|
[GTK_PHASE_NONE] = 0,
|
|
|
|
[GTK_PHASE_CAPTURE] = 1,
|
|
|
|
[GTK_PHASE_BUBBLE] = 3,
|
|
|
|
[GTK_PHASE_TARGET] = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
return priorities[first] - priorities[second];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_controllers (gconstpointer _first,
|
|
|
|
gconstpointer _second,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
GtkEventController *first = GTK_EVENT_CONTROLLER (_first);
|
|
|
|
GtkEventController *second = GTK_EVENT_CONTROLLER (_second);
|
|
|
|
GtkPropagationPhase first_phase, second_phase;
|
|
|
|
GtkWidget *first_widget, *second_widget;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
|
|
first_phase = gtk_event_controller_get_propagation_phase (first);
|
|
|
|
second_phase = gtk_event_controller_get_propagation_phase (second);
|
|
|
|
result = compare_phases (first_phase, second_phase);
|
|
|
|
if (result != 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
first_widget = gtk_event_controller_get_widget (first);
|
|
|
|
second_widget = gtk_event_controller_get_widget (second);
|
|
|
|
if (first_widget == second_widget)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (gtk_widget_is_ancestor (first_widget, second_widget))
|
|
|
|
result = -1;
|
|
|
|
else
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
if (first_phase == GTK_PHASE_BUBBLE)
|
|
|
|
result = -result;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
void
|
2018-09-11 00:25:37 +00:00
|
|
|
gtk_inspector_controllers_set_object (GtkInspectorControllers *sl,
|
|
|
|
GObject *object)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2018-09-11 02:19:06 +00:00
|
|
|
GtkInspectorControllersPrivate *priv = sl->priv;
|
2018-09-11 02:41:52 +00:00
|
|
|
GtkMapListModel *map_model;
|
|
|
|
GtkFlattenListModel *flatten_model;
|
|
|
|
GtkSortListModel *sort_model;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2014-11-09 02:29:51 +00:00
|
|
|
if (!GTK_IS_WIDGET (object))
|
|
|
|
return;
|
|
|
|
|
2018-09-11 02:41:52 +00:00
|
|
|
priv->model = gtk_property_lookup_list_model_new (GTK_TYPE_WIDGET, "parent");
|
|
|
|
gtk_property_lookup_list_model_set_object (priv->model, object);
|
|
|
|
|
|
|
|
map_model = gtk_map_list_model_new (G_TYPE_LIST_MODEL, G_LIST_MODEL (priv->model), map_to_controllers, NULL, NULL);
|
|
|
|
g_object_unref (priv->model);
|
|
|
|
|
|
|
|
flatten_model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, G_LIST_MODEL (map_model));
|
|
|
|
|
|
|
|
sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model),
|
|
|
|
compare_controllers,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2018-09-11 02:19:06 +00:00
|
|
|
gtk_list_box_bind_model (GTK_LIST_BOX (priv->listbox),
|
2018-09-11 02:41:52 +00:00
|
|
|
G_LIST_MODEL (sort_model),
|
2018-09-11 02:19:06 +00:00
|
|
|
create_controller_widget,
|
|
|
|
sl,
|
|
|
|
NULL);
|
2018-09-11 02:41:52 +00:00
|
|
|
|
|
|
|
g_object_unref (sort_model);
|
|
|
|
g_object_unref (flatten_model);
|
|
|
|
g_object_unref (map_model);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2018-09-11 00:25:37 +00:00
|
|
|
GtkInspectorControllers *sl = GTK_INSPECTOR_CONTROLLERS (object);
|
2014-05-16 23:44:43 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-09-11 00:25:37 +00:00
|
|
|
GtkInspectorControllers *sl = GTK_INSPECTOR_CONTROLLERS (object);
|
2014-05-16 23:44:43 +00:00
|
|
|
|
|
|
|
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
|
2018-09-11 00:25:37 +00:00
|
|
|
gtk_inspector_controllers_class_init (GtkInspectorControllersClass *klass)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
|
|
|
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:
|