2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Christian Hammond
|
|
|
|
* Copyright (c) 2008-2009 David Trowbridge
|
|
|
|
* Copyright (c) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2014-05-05 03:47:11 +00:00
|
|
|
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
#include "object-tree.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "prop-list.h"
|
|
|
|
|
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkbutton.h"
|
|
|
|
#include "gtkcelllayout.h"
|
2014-06-10 12:53:31 +00:00
|
|
|
#include "gtkcomboboxprivate.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkiconview.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmenuitem.h"
|
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtktextview.h"
|
2014-10-11 00:51:54 +00:00
|
|
|
#include "gtktreeview.h"
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtktreeselection.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktreestore.h"
|
2014-10-04 15:53:14 +00:00
|
|
|
#include "gtktreemodelsort.h"
|
|
|
|
#include "gtktreemodelfilter.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
OBJECT,
|
|
|
|
OBJECT_TYPE,
|
|
|
|
OBJECT_NAME,
|
2014-05-09 01:15:09 +00:00
|
|
|
OBJECT_LABEL,
|
2014-05-03 01:48:33 +00:00
|
|
|
OBJECT_ADDRESS,
|
2014-05-04 23:53:04 +00:00
|
|
|
SENSITIVE
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-10-11 02:34:32 +00:00
|
|
|
OBJECT_SELECTED,
|
|
|
|
OBJECT_ACTIVATED,
|
2014-05-03 01:48:33 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
struct _GtkInspectorObjectTreePrivate
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-10-11 00:51:54 +00:00
|
|
|
GtkTreeView *tree;
|
2014-05-03 01:48:33 +00:00
|
|
|
GtkTreeStore *model;
|
|
|
|
GHashTable *iters;
|
2014-05-21 02:38:38 +00:00
|
|
|
gulong map_hook;
|
|
|
|
gulong unmap_hook;
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorObjectTree, gtk_inspector_object_tree, GTK_TYPE_BOX)
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
static void
|
2014-10-11 02:34:32 +00:00
|
|
|
on_row_activated (GtkTreeView *tree,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *col,
|
|
|
|
GtkInspectorObjectTree *wt)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GObject *object;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (wt->priv->model), &iter, path);
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (wt->priv->model), &iter,
|
|
|
|
OBJECT, &object,
|
|
|
|
OBJECT_NAME, &name,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_signal_emit (wt, signals[OBJECT_ACTIVATED], 0, object, name);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_selection_changed (GtkTreeSelection *selection,
|
|
|
|
GtkInspectorObjectTree *wt)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-10-11 01:13:34 +00:00
|
|
|
GObject *object;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
GtkTreeModel *model;
|
2014-10-11 02:34:32 +00:00
|
|
|
|
|
|
|
object = NULL;
|
2014-10-11 01:13:34 +00:00
|
|
|
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (wt->priv->tree));
|
|
|
|
if (gtk_tree_selection_get_selected (sel, &model, &iter))
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
OBJECT, &object,
|
|
|
|
-1);
|
2014-10-11 02:34:32 +00:00
|
|
|
if (object)
|
|
|
|
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 02:34:32 +00:00
|
|
|
|
2014-05-09 00:13:34 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt;
|
2014-05-09 00:13:34 +00:00
|
|
|
GObject *object;
|
2014-05-09 02:58:43 +00:00
|
|
|
GtkTreeRowReference *row;
|
2014-05-09 00:13:34 +00:00
|
|
|
} ObjectData;
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
static void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_object_tree_remove_dead_object (gpointer data, GObject *dead_object)
|
2014-05-09 02:58:43 +00:00
|
|
|
{
|
|
|
|
ObjectData *od = data;
|
|
|
|
|
|
|
|
if (gtk_tree_row_reference_valid (od->row))
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
path = gtk_tree_row_reference_get_path (od->row);
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (od->wt->priv->model), &iter, path);
|
|
|
|
gtk_tree_store_remove (od->wt->priv->model, &iter);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
od->object = NULL;
|
|
|
|
g_hash_table_remove (od->wt->priv->iters, dead_object);
|
|
|
|
}
|
|
|
|
|
2014-05-09 00:13:34 +00:00
|
|
|
static void
|
|
|
|
object_data_free (gpointer data)
|
|
|
|
{
|
|
|
|
ObjectData *od = data;
|
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
gtk_tree_row_reference_free (od->row);
|
2014-05-09 00:13:34 +00:00
|
|
|
|
2014-05-09 02:58:43 +00:00
|
|
|
if (od->object)
|
2014-10-11 01:40:53 +00:00
|
|
|
g_object_weak_unref (od->object, gtk_object_tree_remove_dead_object, od);
|
2014-05-09 02:58:43 +00:00
|
|
|
|
2014-05-09 00:13:34 +00:00
|
|
|
g_free (od);
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-21 02:38:38 +00:00
|
|
|
static gboolean
|
|
|
|
map_or_unmap (GSignalInvocationHint *ihint,
|
|
|
|
guint n_params,
|
|
|
|
const GValue *params,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt = data;
|
2014-05-21 02:38:38 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
widget = g_value_get_object (params);
|
2014-10-11 01:40:53 +00:00
|
|
|
if (gtk_inspector_object_tree_find_object (wt, G_OBJECT (widget), &iter))
|
2014-05-21 02:38:38 +00:00
|
|
|
gtk_tree_store_set (wt->priv->model, &iter,
|
|
|
|
SENSITIVE, gtk_widget_get_mapped (widget),
|
|
|
|
-1);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_init (GtkInspectorObjectTree *wt)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-21 02:38:38 +00:00
|
|
|
guint signal_id;
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
wt->priv = gtk_inspector_object_tree_get_instance_private (wt);
|
2014-05-04 23:53:04 +00:00
|
|
|
wt->priv->iters = g_hash_table_new_full (g_direct_hash,
|
|
|
|
g_direct_equal,
|
|
|
|
NULL,
|
2014-05-09 00:13:34 +00:00
|
|
|
(GDestroyNotify) object_data_free);
|
2014-05-04 23:53:04 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (wt));
|
|
|
|
|
2014-05-21 02:38:38 +00:00
|
|
|
signal_id = g_signal_lookup ("map", GTK_TYPE_WIDGET);
|
|
|
|
wt->priv->map_hook = g_signal_add_emission_hook (signal_id, 0,
|
|
|
|
map_or_unmap, wt, NULL);
|
|
|
|
signal_id = g_signal_lookup ("unmap", GTK_TYPE_WIDGET);
|
|
|
|
wt->priv->unmap_hook = g_signal_add_emission_hook (signal_id, 0,
|
|
|
|
map_or_unmap, wt, NULL);
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (gtk_settings_get_default ()), NULL, NULL);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 02:38:38 +00:00
|
|
|
static void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_finalize (GObject *object)
|
2014-05-21 02:38:38 +00:00
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt = GTK_INSPECTOR_OBJECT_TREE (object);
|
2014-05-21 02:38:38 +00:00
|
|
|
guint signal_id;
|
|
|
|
|
2014-09-20 23:28:56 +00:00
|
|
|
g_hash_table_unref (wt->priv->iters);
|
|
|
|
|
2014-05-21 02:38:38 +00:00
|
|
|
signal_id = g_signal_lookup ("map", GTK_TYPE_WIDGET);
|
|
|
|
g_signal_remove_emission_hook (signal_id, wt->priv->map_hook);
|
|
|
|
signal_id = g_signal_lookup ("unmap", GTK_TYPE_WIDGET);
|
|
|
|
g_signal_remove_emission_hook (signal_id, wt->priv->unmap_hook);
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_object_tree_parent_class)->finalize (object);
|
2014-05-21 02:38:38 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_class_init (GtkInspectorObjectTreeClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-21 02:38:38 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-04 23:53:04 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
object_class->finalize = gtk_inspector_object_tree_finalize;
|
2014-05-21 02:38:38 +00:00
|
|
|
|
2014-10-11 02:34:32 +00:00
|
|
|
signals[OBJECT_ACTIVATED] =
|
|
|
|
g_signal_new ("object-activated",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
|
|
|
G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_activated),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_STRING);
|
|
|
|
|
|
|
|
signals[OBJECT_SELECTED] =
|
|
|
|
g_signal_new ("object-selected",
|
2014-10-11 01:13:34 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2014-05-04 23:53:04 +00:00
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
|
2014-10-11 02:34:32 +00:00
|
|
|
G_STRUCT_OFFSET (GtkInspectorObjectTreeClass, object_selected),
|
2014-05-04 23:53:04 +00:00
|
|
|
NULL, NULL,
|
2014-10-11 02:34:32 +00:00
|
|
|
NULL,
|
2014-10-11 01:13:34 +00:00
|
|
|
G_TYPE_NONE, 1, G_TYPE_OBJECT);
|
2014-05-04 23:53:04 +00:00
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/object-tree.ui");
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, model);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorObjectTree, tree);
|
2014-10-11 02:34:32 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_selection_changed);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_row_activated);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
typedef struct
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-10-11 01:40:53 +00:00
|
|
|
GtkInspectorObjectTree *wt;
|
2014-05-04 23:53:04 +00:00
|
|
|
GtkTreeIter *iter;
|
2014-05-10 02:28:45 +00:00
|
|
|
GObject *parent;
|
2014-05-04 23:53:04 +00:00
|
|
|
} FindAllData;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
static void
|
2014-05-13 18:43:19 +00:00
|
|
|
child_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2014-05-04 23:53:04 +00:00
|
|
|
{
|
|
|
|
FindAllData *d = data;
|
2014-05-13 18:43:19 +00:00
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (d->wt, G_OBJECT (widget), d->iter, NULL);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 02:28:45 +00:00
|
|
|
static gboolean
|
|
|
|
cell_callback (GtkCellRenderer *renderer,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
FindAllData *d = data;
|
2014-05-19 04:13:30 +00:00
|
|
|
gpointer cell_layout;
|
2014-05-10 02:28:45 +00:00
|
|
|
|
2014-05-19 04:13:30 +00:00
|
|
|
cell_layout = g_object_get_data (d->parent, "gtk-inspector-cell-layout");
|
|
|
|
g_object_set_data (G_OBJECT (renderer), "gtk-inspector-cell-layout", cell_layout);
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (d->wt, G_OBJECT (renderer), d->iter, NULL);
|
2014-05-10 02:28:45 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-13 18:43:19 +00:00
|
|
|
static void
|
|
|
|
tag_callback (GtkTextTag *tag,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
FindAllData *d = data;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
g_object_get (tag, "name", &name, NULL);
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (d->wt, G_OBJECT (tag), d->iter, name);
|
2014-05-13 18:43:19 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
|
2014-05-07 03:24:20 +00:00
|
|
|
GObject *object,
|
2014-05-08 05:26:17 +00:00
|
|
|
GtkTreeIter *parent_iter,
|
|
|
|
const gchar *name)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2014-05-09 02:58:43 +00:00
|
|
|
GtkTreePath *path;
|
2014-05-15 19:24:44 +00:00
|
|
|
const gchar *class_name;
|
2014-05-04 23:53:04 +00:00
|
|
|
gchar *address;
|
2014-05-03 01:48:33 +00:00
|
|
|
gboolean mapped;
|
2014-05-09 00:13:34 +00:00
|
|
|
ObjectData *od;
|
2014-05-09 01:15:09 +00:00
|
|
|
const gchar *label;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-15 19:24:44 +00:00
|
|
|
if (GTK_IS_WIDGET (object))
|
|
|
|
mapped = gtk_widget_get_mapped (GTK_WIDGET (object));
|
|
|
|
else
|
|
|
|
mapped = TRUE;
|
|
|
|
|
|
|
|
class_name = G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (object));
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-09 00:13:34 +00:00
|
|
|
if (GTK_IS_WIDGET (object))
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-15 19:24:44 +00:00
|
|
|
const gchar *id;
|
|
|
|
id = gtk_widget_get_name (GTK_WIDGET (object));
|
|
|
|
if (name == NULL && id != NULL && g_strcmp0 (id, class_name) != 0)
|
|
|
|
name = id;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 19:24:44 +00:00
|
|
|
if (GTK_IS_BUILDABLE (object))
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-15 19:24:44 +00:00
|
|
|
const gchar *id;
|
|
|
|
id = gtk_buildable_get_name (GTK_BUILDABLE (object));
|
|
|
|
if (name == NULL && id != NULL && !g_str_has_prefix (id, "___object_"))
|
|
|
|
name = id;
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 01:15:09 +00:00
|
|
|
if (name == NULL)
|
|
|
|
name = "";
|
|
|
|
|
|
|
|
if (GTK_IS_LABEL (object))
|
|
|
|
label = gtk_label_get_text (GTK_LABEL (object));
|
|
|
|
else if (GTK_IS_BUTTON (object))
|
|
|
|
label = gtk_button_get_label (GTK_BUTTON (object));
|
|
|
|
else if (GTK_IS_WINDOW (object))
|
|
|
|
label = gtk_window_get_title (GTK_WINDOW (object));
|
|
|
|
else if (GTK_IS_TREE_VIEW_COLUMN (object))
|
|
|
|
label = gtk_tree_view_column_get_title (GTK_TREE_VIEW_COLUMN (object));
|
|
|
|
else
|
|
|
|
label = "";
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
address = g_strdup_printf ("%p", object);
|
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
gtk_tree_store_append (wt->priv->model, &iter, parent_iter);
|
|
|
|
gtk_tree_store_set (wt->priv->model, &iter,
|
2014-05-03 01:48:33 +00:00
|
|
|
OBJECT, object,
|
|
|
|
OBJECT_TYPE, class_name,
|
|
|
|
OBJECT_NAME, name,
|
2014-05-09 01:15:09 +00:00
|
|
|
OBJECT_LABEL, label,
|
2014-05-03 01:48:33 +00:00
|
|
|
OBJECT_ADDRESS, address,
|
2014-05-15 19:24:44 +00:00
|
|
|
SENSITIVE, mapped,
|
2014-05-03 01:48:33 +00:00
|
|
|
-1);
|
2014-05-09 00:13:34 +00:00
|
|
|
|
|
|
|
od = g_new0 (ObjectData, 1);
|
2014-05-09 02:58:43 +00:00
|
|
|
od->wt = wt;
|
2014-05-09 00:13:34 +00:00
|
|
|
od->object = object;
|
2014-05-09 02:58:43 +00:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter);
|
|
|
|
od->row = gtk_tree_row_reference_new (GTK_TREE_MODEL (wt->priv->model), path);
|
|
|
|
gtk_tree_path_free (path);
|
2014-05-24 13:54:06 +00:00
|
|
|
|
|
|
|
g_hash_table_insert (wt->priv->iters, object, od);
|
2014-10-11 01:40:53 +00:00
|
|
|
g_object_weak_ref (object, gtk_object_tree_remove_dead_object, od);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-08 14:16:58 +00:00
|
|
|
g_free (address);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
|
|
|
if (GTK_IS_CONTAINER (object))
|
|
|
|
{
|
2014-05-04 23:53:04 +00:00
|
|
|
FindAllData data;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
data.wt = wt;
|
|
|
|
data.iter = &iter;
|
2014-05-10 02:28:45 +00:00
|
|
|
data.parent = object;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-13 18:43:19 +00:00
|
|
|
gtk_container_forall (GTK_CONTAINER (object), child_callback, &data);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
2014-05-08 05:38:52 +00:00
|
|
|
|
2014-05-13 18:43:19 +00:00
|
|
|
/* Below are special cases for dependent objects which are not
|
|
|
|
* children in the GtkContainer sense, but which we still want
|
|
|
|
* to show in the tree right away.
|
|
|
|
*/
|
2014-10-11 00:51:54 +00:00
|
|
|
if (GTK_IS_TREE_MODEL_SORT (object))
|
|
|
|
{
|
|
|
|
GObject *child = G_OBJECT (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "model");
|
2014-10-11 00:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_TREE_MODEL_FILTER (object))
|
|
|
|
{
|
|
|
|
GObject *child = G_OBJECT (gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "model");
|
2014-10-11 00:51:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 12:32:44 +00:00
|
|
|
if (GTK_IS_MENU_ITEM (object))
|
|
|
|
{
|
|
|
|
GtkWidget *submenu;
|
|
|
|
|
|
|
|
submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (object));
|
|
|
|
if (submenu)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (submenu), &iter, "submenu");
|
2014-06-10 12:32:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 12:53:31 +00:00
|
|
|
if (GTK_IS_COMBO_BOX (object))
|
|
|
|
{
|
|
|
|
GtkWidget *popup;
|
2014-10-04 15:43:50 +00:00
|
|
|
GObject *child;
|
2014-06-10 12:53:31 +00:00
|
|
|
|
|
|
|
popup = gtk_combo_box_get_popup (GTK_COMBO_BOX (object));
|
|
|
|
if (popup)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (popup), &iter, "popup");
|
2014-10-04 15:43:50 +00:00
|
|
|
|
|
|
|
child = G_OBJECT (gtk_combo_box_get_model (GTK_COMBO_BOX (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "model");
|
2014-06-10 12:53:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 05:38:52 +00:00
|
|
|
if (GTK_IS_TREE_VIEW (object))
|
|
|
|
{
|
|
|
|
gint n_columns, i;
|
2014-05-10 02:49:31 +00:00
|
|
|
GObject *child;
|
|
|
|
|
|
|
|
child = G_OBJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "model");
|
2014-05-08 05:38:52 +00:00
|
|
|
|
2014-08-02 23:28:23 +00:00
|
|
|
child = G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "selection");
|
2014-08-02 23:28:23 +00:00
|
|
|
|
2014-05-08 05:38:52 +00:00
|
|
|
n_columns = gtk_tree_view_get_n_columns (GTK_TREE_VIEW (object));
|
|
|
|
for (i = 0; i < n_columns; i++)
|
|
|
|
{
|
2014-05-10 02:49:31 +00:00
|
|
|
child = G_OBJECT (gtk_tree_view_get_column (GTK_TREE_VIEW (object), i));
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, NULL);
|
2014-05-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-10 02:49:31 +00:00
|
|
|
if (GTK_IS_ICON_VIEW (object))
|
|
|
|
{
|
|
|
|
GObject *child;
|
|
|
|
|
|
|
|
child = G_OBJECT (gtk_icon_view_get_model (GTK_ICON_VIEW (object)));
|
|
|
|
if (child)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, child, &iter, "model");
|
2014-05-10 02:49:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 02:28:45 +00:00
|
|
|
if (GTK_IS_CELL_AREA (object))
|
|
|
|
{
|
|
|
|
FindAllData data;
|
|
|
|
|
|
|
|
data.wt = wt;
|
|
|
|
data.iter = &iter;
|
|
|
|
data.parent = object;
|
|
|
|
|
|
|
|
gtk_cell_area_foreach (GTK_CELL_AREA (object), cell_callback, &data);
|
|
|
|
}
|
|
|
|
else if (GTK_IS_CELL_LAYOUT (object))
|
2014-05-08 05:38:52 +00:00
|
|
|
{
|
2014-05-08 14:16:58 +00:00
|
|
|
GtkCellArea *area;
|
2014-05-08 05:38:52 +00:00
|
|
|
|
2014-05-08 14:16:58 +00:00
|
|
|
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (object));
|
2014-05-19 04:13:30 +00:00
|
|
|
g_object_set_data (G_OBJECT (area), "gtk-inspector-cell-layout", object);
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (area), &iter, "cell-area");
|
2014-05-08 05:38:52 +00:00
|
|
|
}
|
2014-05-13 18:43:19 +00:00
|
|
|
|
|
|
|
if (GTK_IS_TEXT_VIEW (object))
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (object));
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (buffer), &iter, "buffer");
|
2014-05-13 18:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_TEXT_BUFFER (object))
|
|
|
|
{
|
|
|
|
GtkTextTagTable *tags;
|
|
|
|
|
|
|
|
tags = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (object));
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (tags), &iter, "tag-table");
|
2014-05-13 18:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_TEXT_TAG_TABLE (object))
|
|
|
|
{
|
|
|
|
FindAllData data;
|
|
|
|
|
|
|
|
data.wt = wt;
|
|
|
|
data.iter = &iter;
|
|
|
|
data.parent = object;
|
|
|
|
|
|
|
|
gtk_text_tag_table_foreach (GTK_TEXT_TAG_TABLE (object), tag_callback, &data);
|
|
|
|
}
|
2014-06-10 12:32:44 +00:00
|
|
|
|
|
|
|
if (GTK_IS_WIDGET (object))
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
GtkPropagationPhase phase;
|
|
|
|
const gchar *name;
|
|
|
|
} phases[] = {
|
|
|
|
{ GTK_PHASE_CAPTURE, "capture" },
|
|
|
|
{ GTK_PHASE_TARGET, "target" },
|
|
|
|
{ GTK_PHASE_BUBBLE, "bubble" },
|
|
|
|
{ GTK_PHASE_NONE, "" }
|
|
|
|
};
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (phases); i++)
|
|
|
|
{
|
|
|
|
GList *list, *l;
|
|
|
|
|
|
|
|
list = _gtk_widget_list_controllers (GTK_WIDGET (object), phases[i].phase);
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
GObject *controller = l->data;
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, controller, &iter, phases[i].name);
|
2014-06-10 12:32:44 +00:00
|
|
|
}
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
}
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_scan (GtkInspectorObjectTree *wt,
|
2014-05-07 03:24:20 +00:00
|
|
|
GtkWidget *window)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-09-12 11:46:05 +00:00
|
|
|
GtkWidget *inspector_win;
|
|
|
|
GList *toplevels, *l;
|
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
gtk_tree_store_clear (wt->priv->model);
|
|
|
|
g_hash_table_remove_all (wt->priv->iters);
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (gtk_settings_get_default ()), NULL, NULL);
|
2014-05-09 00:32:42 +00:00
|
|
|
if (g_application_get_default ())
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (g_application_get_default ()), NULL, NULL);
|
2014-09-12 11:46:05 +00:00
|
|
|
|
2014-09-26 13:49:47 +00:00
|
|
|
if (window)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (window), NULL, NULL);
|
2014-09-26 13:49:47 +00:00
|
|
|
|
2014-09-12 11:46:05 +00:00
|
|
|
inspector_win = gtk_widget_get_toplevel (GTK_WIDGET (wt));
|
|
|
|
toplevels = gtk_window_list_toplevels ();
|
|
|
|
for (l = toplevels; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WINDOW (l->data) &&
|
|
|
|
gtk_window_get_window_type (l->data) == GTK_WINDOW_TOPLEVEL &&
|
|
|
|
l->data != window &&
|
|
|
|
l->data != inspector_win)
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_append_object (wt, G_OBJECT (l->data), NULL, NULL);
|
2014-09-12 11:46:05 +00:00
|
|
|
}
|
|
|
|
g_list_free (toplevels);
|
|
|
|
|
2014-10-11 00:51:54 +00:00
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (wt->priv->tree));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_find_object (GtkInspectorObjectTree *wt,
|
2014-05-07 03:24:20 +00:00
|
|
|
GObject *object,
|
|
|
|
GtkTreeIter *iter)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-09 00:13:34 +00:00
|
|
|
ObjectData *od;
|
|
|
|
|
|
|
|
od = g_hash_table_lookup (wt->priv->iters, object);
|
2014-05-09 02:58:43 +00:00
|
|
|
if (od && gtk_tree_row_reference_valid (od->row))
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-09 02:58:43 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
path = gtk_tree_row_reference_get_path (od->row);
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (wt->priv->model), iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-11 01:40:53 +00:00
|
|
|
gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt,
|
2014-05-07 03:24:20 +00:00
|
|
|
GObject *object)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2014-10-11 01:40:53 +00:00
|
|
|
if (gtk_inspector_object_tree_find_object (wt, object, &iter))
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-10-11 02:34:32 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter);
|
2014-10-11 00:51:54 +00:00
|
|
|
gtk_tree_view_expand_to_path (GTK_TREE_VIEW (wt->priv->tree), path);
|
|
|
|
gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (wt->priv->tree)), &iter);
|
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (wt->priv->tree), path, NULL, FALSE, 0, 0);
|
2014-10-11 02:34:32 +00:00
|
|
|
gtk_tree_view_row_activated (GTK_TREE_VIEW (wt->priv->tree), path, NULL);
|
|
|
|
gtk_tree_path_free (path);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-04 23:53:04 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|