diff options
author | Timm Bäder <tbaeder@redhat.com> | 2019-01-23 07:29:36 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2019-01-23 17:14:32 +0100 |
commit | 0694b9b204ed4ede7cdd56d690da9cb1c3438080 (patch) | |
tree | fba801de48c93b7a4ae1c199ebeb82699fbe9464 | |
parent | 4047fa34bbeabfd3c9ee12fc5df795b05dbe2531 (diff) | |
download | gtk+-wip/baedert/widgetview.tar.gz |
Inspector: add & use GtkWidgetViewwip/baedert/widgetview
Use it to show a visual representation of the focus widget in a toplevel
-rw-r--r-- | gtk/inspector/init.c | 2 | ||||
-rw-r--r-- | gtk/inspector/meson.build | 1 | ||||
-rw-r--r-- | gtk/inspector/misc-info.c | 18 | ||||
-rw-r--r-- | gtk/inspector/misc-info.ui | 4 | ||||
-rw-r--r-- | gtk/inspector/widgetview.c | 93 | ||||
-rw-r--r-- | gtk/inspector/widgetview.h | 39 |
6 files changed, 141 insertions, 16 deletions
diff --git a/gtk/inspector/init.c b/gtk/inspector/init.c index 049126f401..eb00c10785 100644 --- a/gtk/inspector/init.c +++ b/gtk/inspector/init.c @@ -48,6 +48,7 @@ #include "visual.h" #include "window.h" #include "gtkstackcombo.h" +#include "widgetview.h" #include "gtkmagnifierprivate.h" @@ -85,6 +86,7 @@ gtk_inspector_init (void) g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL); g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW); g_type_ensure (GTK_TYPE_STACK_COMBO); + g_type_ensure (GTK_TYPE_WIDGET_VIEW); if (extension_point == NULL) { diff --git a/gtk/inspector/meson.build b/gtk/inspector/meson.build index a134f8f278..ae0fac76dd 100644 --- a/gtk/inspector/meson.build +++ b/gtk/inspector/meson.build @@ -37,5 +37,6 @@ inspector_sources = files( 'treewalk.c', 'updatesoverlay.c', 'visual.c', + 'widgetview.c', 'window.c', ) diff --git a/gtk/inspector/misc-info.c b/gtk/inspector/misc-info.c index fc522ea6b1..262457a987 100644 --- a/gtk/inspector/misc-info.c +++ b/gtk/inspector/misc-info.c @@ -29,6 +29,7 @@ #include "gtkframe.h" #include "gtkbutton.h" #include "gtkwidgetprivate.h" +#include "widgetview.h" struct _GtkInspectorMiscInfoPrivate { @@ -223,19 +224,10 @@ update_focus_widget (GtkInspectorMiscInfo *sl) GtkWidget *widget; widget = gtk_window_get_focus (GTK_WINDOW (sl->priv->object)); - if (widget) - { - gchar *tmp; - tmp = g_strdup_printf ("%p", widget); - gtk_label_set_label (GTK_LABEL (sl->priv->focus_widget), tmp); - g_free (tmp); - gtk_widget_set_sensitive (sl->priv->focus_widget_button, TRUE); - } - else - { - gtk_label_set_label (GTK_LABEL (sl->priv->focus_widget), "NULL"); - gtk_widget_set_sensitive (sl->priv->focus_widget_button, FALSE); - } + + gtk_widget_view_set_inspected_widget (GTK_WIDGET_VIEW (sl->priv->focus_widget), + widget); + gtk_widget_set_sensitive (sl->priv->focus_widget_button, widget != NULL); } static void diff --git a/gtk/inspector/misc-info.ui b/gtk/inspector/misc-info.ui index d82b73f272..96c62db5a3 100644 --- a/gtk/inspector/misc-info.ui +++ b/gtk/inspector/misc-info.ui @@ -176,11 +176,9 @@ </object> </child> <child> - <object class="GtkLabel" id="focus_widget"> - <property name="selectable">1</property> + <object class="GtkWidgetView" id="focus_widget"> <property name="halign">end</property> <property name="valign">baseline</property> - <property name="ellipsize">end</property> </object> </child> <child> diff --git a/gtk/inspector/widgetview.c b/gtk/inspector/widgetview.c new file mode 100644 index 0000000000..484577d8ac --- /dev/null +++ b/gtk/inspector/widgetview.c @@ -0,0 +1,93 @@ + +#include "widgetview.h" +#include "gtklabel.h" +#include "gtkpicture.h" +#include "gtkbox.h" + +G_DEFINE_TYPE (GtkWidgetView, gtk_widget_view, GTK_TYPE_WIDGET); + +static void +gtk_widget_view_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) +{ + GtkWidgetView *self = GTK_WIDGET_VIEW (widget); + + gtk_widget_measure (self->box, orientation, for_size, + minimum, natural, minimum_baseline, natural_baseline); +} + +static void +gtk_widget_view_size_allocate (GtkWidget *widget, + int width, + int height, + int baseline) +{ + GtkWidgetView *self = GTK_WIDGET_VIEW (widget); + + gtk_widget_size_allocate (self->box, + &(GtkAllocation) { + 0, 0, + width, height + }, -1); +} + +static void +gtk_widget_view_class_init (GtkWidgetViewClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->measure = gtk_widget_view_measure; + widget_class->size_allocate = gtk_widget_view_size_allocate; +} + + +static void +gtk_widget_view_init (GtkWidgetView *self) +{ + gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE); + + self->typename_label = gtk_label_new (""); + self->paintable_picture = gtk_picture_new (); + self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); + + gtk_container_add (GTK_CONTAINER (self->box), self->typename_label); + gtk_container_add (GTK_CONTAINER (self->box), self->paintable_picture); + + gtk_widget_set_parent (self->box, GTK_WIDGET (self)); +} + + +GtkWidget * +gtk_widget_view_new (void) +{ + return (GtkWidget *) g_object_new (GTK_TYPE_WIDGET_VIEW, NULL); +} + +void +gtk_widget_view_set_inspected_widget (GtkWidgetView *self, + GtkWidget *inspected) +{ + char typename_buffer[512]; + GdkPaintable *paintable; + + g_set_object (&self->inspected, inspected); + + if (!self->inspected) + { + gtk_label_set_label (GTK_LABEL (self->typename_label), "NULL"); + return; + } + + g_snprintf (typename_buffer, sizeof (typename_buffer), + "%s", G_OBJECT_TYPE_NAME (inspected)); + gtk_label_set_label (GTK_LABEL (self->typename_label), typename_buffer); + + paintable = gtk_widget_paintable_new (inspected); + gtk_picture_set_paintable (GTK_PICTURE (self->paintable_picture), paintable); + g_object_unref (paintable); +} diff --git a/gtk/inspector/widgetview.h b/gtk/inspector/widgetview.h new file mode 100644 index 0000000000..6a3b89e033 --- /dev/null +++ b/gtk/inspector/widgetview.h @@ -0,0 +1,39 @@ + +#ifndef __GTK_WIDGET_VIEW_H__ +#define __GTK_WIDGET_VIEW_H__ + +#include "gtkwidget.h" +#include "gtkwidgetpaintable.h" + +#define GTK_TYPE_WIDGET_VIEW (gtk_widget_view_get_type ()) +#define GTK_WIDGET_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WIDGET_VIEW, GtkWidgetView)) +#define GTK_WIDGET_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WIDGET_VIEW, GtkWidgetViewClass)) +#define GTK_IS_WIDGET_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WIDGET_VIEW)) +#define GTK_IS_WIDGET_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WIDGET_VIEW)) +#define GTK_WIDGET_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WIDGET_VIEW, GtkWidgetViewClass)) + +typedef struct _GtkWidgetView GtkWidgetView; +typedef struct _GtkWidgetViewClass GtkWidgetViewClass; + +struct _GtkWidgetView +{ + GtkWidget parent_instance; + + GtkWidget *box; + GtkWidget *typename_label; + GtkWidget *paintable_picture; + + GtkWidget *inspected; +}; + +struct _GtkWidgetViewClass +{ + GtkWidgetClass parent_class; +}; + +GType gtk_widget_view_get_type (void) G_GNUC_CONST; +GtkWidget * gtk_widget_view_new (void); +void gtk_widget_view_set_inspected_widget (GtkWidgetView *self, + GtkWidget *inspected); + +#endif |