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-05-16 23:44:43 +00:00
|
|
|
|
2019-11-08 23:43:41 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2019-12-14 03:33:13 +00:00
|
|
|
#include "gtkdropdown.h"
|
2020-07-07 04:53:55 +00:00
|
|
|
#include "gtkbox.h"
|
2019-11-08 23:43:41 +00:00
|
|
|
#include "gtkcustomsorter.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkgesture.h"
|
|
|
|
#include "gtklabel.h"
|
2018-09-11 02:41:52 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtksortlistmodel.h"
|
2019-04-02 23:24:57 +00:00
|
|
|
#include "gtkstack.h"
|
2019-11-08 23:43:41 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-07-06 20:53:54 +00:00
|
|
|
#include "window.h"
|
2021-01-20 23:51:01 +00:00
|
|
|
#include "gtksignallistitemfactory.h"
|
|
|
|
#include "gtkcolumnview.h"
|
|
|
|
#include "gtkcolumnviewcolumn.h"
|
|
|
|
#include "gtklistitem.h"
|
|
|
|
#include "gtknoselection.h"
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2019-11-08 23:36:59 +00:00
|
|
|
struct _GtkInspectorControllers
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2019-11-08 23:43:41 +00:00
|
|
|
GtkWidget parent_instance;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkWidget *view;
|
2014-05-16 23:44:43 +00:00
|
|
|
};
|
|
|
|
|
2019-11-08 23:36:59 +00:00
|
|
|
struct _GtkInspectorControllersClass
|
|
|
|
{
|
2019-11-08 23:43:41 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2019-11-08 23:36:59 +00:00
|
|
|
};
|
|
|
|
|
2019-11-08 23:43:41 +00:00
|
|
|
G_DEFINE_TYPE (GtkInspectorControllers, gtk_inspector_controllers, GTK_TYPE_WIDGET)
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2018-09-10 23:56:42 +00:00
|
|
|
static void
|
2021-01-20 23:51:01 +00:00
|
|
|
row_activated (GtkColumnView *view,
|
|
|
|
guint position,
|
2019-11-08 23:36:59 +00:00
|
|
|
GtkInspectorControllers *self)
|
2018-09-10 23:56:42 +00:00
|
|
|
{
|
2020-07-06 20:53:54 +00:00
|
|
|
GtkInspectorWindow *iw;
|
2021-01-20 23:51:01 +00:00
|
|
|
GListModel *model;
|
2018-09-11 00:25:37 +00:00
|
|
|
GObject *controller;
|
2020-07-06 20:53:54 +00:00
|
|
|
|
|
|
|
iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_INSPECTOR_WINDOW));
|
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
model = G_LIST_MODEL (gtk_column_view_get_model (view));
|
|
|
|
controller = g_list_model_get_item (model, position);
|
2020-07-06 20:53:54 +00:00
|
|
|
gtk_inspector_window_push_object (iw, controller, CHILD_KIND_CONTROLLER, 0);
|
2021-01-20 23:51:01 +00:00
|
|
|
g_object_unref (controller);
|
2018-09-10 23:56:42 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
static void
|
2021-01-20 23:51:01 +00:00
|
|
|
setup_row (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkWidget *label;
|
2018-09-10 23:56:42 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
label = gtk_label_new ("");
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
|
|
|
}
|
2018-09-11 02:41:52 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
static void
|
|
|
|
bind_type (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkEventController *controller;
|
2018-09-11 02:41:52 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
controller = gtk_list_item_get_item (list_item);
|
2018-09-10 23:56:42 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (label), G_OBJECT_TYPE_NAME (controller));
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-20 23:51:01 +00:00
|
|
|
bind_name (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkWidget *label;
|
2018-09-10 23:56:42 +00:00
|
|
|
GtkEventController *controller;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
controller = gtk_list_item_get_item (list_item);
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), gtk_event_controller_get_name (controller));
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
static void
|
|
|
|
bind_phase (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
controller = gtk_list_item_get_item (list_item);
|
|
|
|
|
|
|
|
switch (gtk_event_controller_get_propagation_phase (controller))
|
|
|
|
{
|
|
|
|
case GTK_PHASE_NONE:
|
|
|
|
name = C_("event phase", "None");
|
|
|
|
break;
|
|
|
|
case GTK_PHASE_CAPTURE:
|
|
|
|
name = C_("event phase", "Capture");
|
|
|
|
break;
|
|
|
|
case GTK_PHASE_BUBBLE:
|
|
|
|
name = C_("event phase", "Bubble");
|
|
|
|
break;
|
|
|
|
case GTK_PHASE_TARGET:
|
|
|
|
name = C_("event phase", "Target");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), name);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
static void
|
|
|
|
bind_limit (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item,
|
|
|
|
gpointer data)
|
2018-09-11 02:41:52 +00:00
|
|
|
{
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
GtkEventController *controller;
|
|
|
|
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
controller = gtk_list_item_get_item (list_item);
|
|
|
|
|
|
|
|
if (gtk_event_controller_get_propagation_limit (controller) == GTK_LIMIT_SAME_NATIVE)
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), C_("propagation limit", "Native"));
|
|
|
|
else
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_controllers_init (GtkInspectorControllers *self)
|
|
|
|
{
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkListItemFactory *factory;
|
|
|
|
GtkColumnViewColumn *column;
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new ();
|
|
|
|
|
|
|
|
self->view = gtk_column_view_new (NULL);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_type), NULL);
|
|
|
|
|
|
|
|
column = gtk_column_view_column_new ("Type", factory);
|
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_name), NULL);
|
|
|
|
|
|
|
|
column = gtk_column_view_column_new ("Name", factory);
|
2021-10-24 17:23:26 +00:00
|
|
|
gtk_column_view_column_set_expand (column, TRUE);
|
2021-01-20 23:51:01 +00:00
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_phase), NULL);
|
|
|
|
|
|
|
|
column = gtk_column_view_column_new ("Phase", factory);
|
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
|
|
|
|
|
|
|
factory = gtk_signal_list_item_factory_new ();
|
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK (setup_row), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK (bind_limit), NULL);
|
|
|
|
|
|
|
|
column = gtk_column_view_column_new ("Limit", factory);
|
|
|
|
gtk_column_view_append_column (GTK_COLUMN_VIEW (self->view), column);
|
|
|
|
g_object_unref (column);
|
|
|
|
|
|
|
|
g_signal_connect (self->view, "activate", G_CALLBACK (row_activated), self);
|
|
|
|
|
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), self->view);
|
|
|
|
|
|
|
|
gtk_widget_set_parent (sw, GTK_WIDGET (self));
|
2018-09-11 02:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-11-08 23:36:59 +00:00
|
|
|
gtk_inspector_controllers_set_object (GtkInspectorControllers *self,
|
2018-09-11 00:25:37 +00:00
|
|
|
GObject *object)
|
2014-05-16 23:44:43 +00:00
|
|
|
{
|
2019-04-02 23:24:57 +00:00
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
2021-01-20 23:51:01 +00:00
|
|
|
GListModel *model;
|
2018-09-11 02:41:52 +00:00
|
|
|
GtkSortListModel *sort_model;
|
2019-12-03 04:44:22 +00:00
|
|
|
GtkSorter *sorter;
|
2021-01-20 23:51:01 +00:00
|
|
|
GtkNoSelection *no_selection;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2019-11-08 23:36:59 +00:00
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (self));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (self));
|
2019-04-02 23:24:57 +00:00
|
|
|
|
2014-11-09 02:29:51 +00:00
|
|
|
if (!GTK_IS_WIDGET (object))
|
2019-04-02 23:24:57 +00:00
|
|
|
{
|
2021-01-20 23:51:01 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), NULL);
|
2019-04-02 23:24:57 +00:00
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
2014-11-09 02:29:51 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
model = gtk_widget_observe_controllers (GTK_WIDGET (object));
|
2020-08-03 19:54:42 +00:00
|
|
|
sorter = GTK_SORTER (gtk_custom_sorter_new (compare_controllers, NULL, NULL));
|
2021-01-20 23:51:01 +00:00
|
|
|
sort_model = gtk_sort_list_model_new (model, sorter);
|
|
|
|
no_selection = gtk_no_selection_new (G_LIST_MODEL (sort_model));
|
2018-09-11 02:41:52 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (self->view), GTK_SELECTION_MODEL (no_selection));
|
2018-09-11 02:41:52 +00:00
|
|
|
|
2021-01-20 23:51:01 +00:00
|
|
|
g_object_unref (no_selection);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 23:43:41 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_controllers_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorControllers *self = GTK_INSPECTOR_CONTROLLERS (object);
|
|
|
|
|
|
|
|
gtk_widget_unparent (gtk_widget_get_first_child (GTK_WIDGET (self)));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_inspector_controllers_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2014-05-16 23:44:43 +00:00
|
|
|
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
|
|
|
{
|
2019-11-08 23:43:41 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-05-16 23:44:43 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2020-09-01 16:56:51 +00:00
|
|
|
object_class->dispose = gtk_inspector_controllers_dispose;
|
2014-05-16 23:44:43 +00:00
|
|
|
|
2019-11-08 23:43:41 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2014-05-16 23:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|