2014-05-21 01:44:48 +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-21 01:44:48 +00:00
|
|
|
#include "size-groups.h"
|
2018-04-04 10:38:09 +00:00
|
|
|
|
|
|
|
#include "highlightoverlay.h"
|
2014-05-21 01:44:48 +00:00
|
|
|
#include "window.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
|
|
|
#include "gtkcomboboxtext.h"
|
|
|
|
#include "gtkframe.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtklistbox.h"
|
|
|
|
#include "gtksizegroup.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
#include "gtkstylecontext.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtkswitch.h"
|
2014-05-21 01:44:48 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2019-04-02 23:24:57 +00:00
|
|
|
#include "gtkstack.h"
|
2014-05-21 01:44:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GtkListBoxRow parent;
|
2018-04-04 10:38:09 +00:00
|
|
|
GtkInspectorOverlay *highlight;
|
2014-05-21 01:44:48 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
} SizeGroupRow;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GtkListBoxRowClass parent;
|
|
|
|
} SizeGroupRowClass;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_WIDGET = 1,
|
|
|
|
LAST_PROPERTY
|
|
|
|
};
|
|
|
|
|
|
|
|
GParamSpec *properties[LAST_PROPERTY] = { NULL };
|
|
|
|
|
2014-09-06 00:52:03 +00:00
|
|
|
GType size_group_row_get_type (void);
|
|
|
|
|
2014-05-21 01:44:48 +00:00
|
|
|
G_DEFINE_TYPE (SizeGroupRow, size_group_row, GTK_TYPE_LIST_BOX_ROW)
|
|
|
|
|
|
|
|
static void
|
|
|
|
size_group_row_init (SizeGroupRow *row)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
size_group_row_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
SizeGroupRow *row = (SizeGroupRow*)object;
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_WIDGET:
|
|
|
|
g_value_set_pointer (value, row->widget);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:41:20 +00:00
|
|
|
static void
|
|
|
|
size_group_row_widget_destroyed (GtkWidget *widget, SizeGroupRow *row)
|
|
|
|
{
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (row));
|
|
|
|
if (parent)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (row));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_widget (SizeGroupRow *row, GtkWidget *widget)
|
|
|
|
{
|
|
|
|
if (row->widget)
|
|
|
|
g_signal_handlers_disconnect_by_func (row->widget,
|
|
|
|
size_group_row_widget_destroyed, row);
|
|
|
|
|
|
|
|
row->widget = widget;
|
|
|
|
|
|
|
|
if (row->widget)
|
|
|
|
g_signal_connect (row->widget, "destroy",
|
|
|
|
G_CALLBACK (size_group_row_widget_destroyed), row);
|
|
|
|
}
|
|
|
|
|
2014-05-21 01:44:48 +00:00
|
|
|
static void
|
|
|
|
size_group_row_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
SizeGroupRow *row = (SizeGroupRow*)object;
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_WIDGET:
|
2014-05-21 10:41:20 +00:00
|
|
|
set_widget (row, g_value_get_pointer (value));
|
2014-05-21 01:44:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
size_group_row_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
SizeGroupRow *row = (SizeGroupRow *)object;
|
|
|
|
|
2014-05-21 10:41:20 +00:00
|
|
|
set_widget (row, NULL);
|
2014-05-21 01:44:48 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (size_group_row_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
size_group_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags old_state)
|
|
|
|
{
|
|
|
|
SizeGroupRow *row = (SizeGroupRow*)widget;
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
|
|
|
if (!row->widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
state = gtk_widget_get_state_flags (widget);
|
|
|
|
if ((state & GTK_STATE_FLAG_PRELIGHT) != (old_state & GTK_STATE_FLAG_PRELIGHT))
|
|
|
|
{
|
2019-05-20 04:47:50 +00:00
|
|
|
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_root (widget));
|
2018-04-04 10:38:09 +00:00
|
|
|
|
2014-05-21 01:44:48 +00:00
|
|
|
if (state & GTK_STATE_FLAG_PRELIGHT)
|
2018-04-04 10:38:09 +00:00
|
|
|
{
|
|
|
|
row->highlight = gtk_highlight_overlay_new (row->widget);
|
|
|
|
gtk_inspector_window_add_overlay (iw, row->highlight);
|
|
|
|
}
|
2014-05-21 01:44:48 +00:00
|
|
|
else
|
2018-04-04 10:38:09 +00:00
|
|
|
{
|
|
|
|
gtk_inspector_window_remove_overlay (iw, row->highlight);
|
|
|
|
g_clear_object (&row->highlight);
|
|
|
|
}
|
2014-05-21 01:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
size_group_row_class_init (SizeGroupRowClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
|
|
|
object_class->finalize = size_group_row_finalize;
|
|
|
|
object_class->get_property = size_group_row_get_property;
|
|
|
|
object_class->set_property = size_group_row_set_property;
|
|
|
|
|
|
|
|
widget_class->state_flags_changed = size_group_state_flags_changed;
|
|
|
|
|
|
|
|
properties[PROP_WIDGET] =
|
|
|
|
g_param_spec_pointer ("widget", "Widget", "Widget", G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROPERTY, properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkInspectorSizeGroups, gtk_inspector_size_groups, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_view (GtkInspectorSizeGroups *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
|
|
|
|
add_widget (GtkInspectorSizeGroups *sl,
|
|
|
|
GtkListBox *listbox,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
row = g_object_new (size_group_row_get_type (), "widget", widget, NULL);
|
|
|
|
text = g_strdup_printf ("%p (%s)", widget, g_type_name_from_instance ((GTypeInstance*)widget));
|
|
|
|
label = gtk_label_new (text);
|
|
|
|
g_free (text);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (label, 10);
|
|
|
|
gtk_widget_set_margin_end (label, 10);
|
|
|
|
gtk_widget_set_margin_top (label, 10);
|
|
|
|
gtk_widget_set_margin_bottom (label, 10);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (row), label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (listbox), row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_size_group (GtkInspectorSizeGroups *sl,
|
|
|
|
GtkSizeGroup *group)
|
|
|
|
{
|
|
|
|
GtkWidget *frame, *box, *box2;
|
2016-10-09 13:53:22 +00:00
|
|
|
GtkWidget *label, *combo;
|
2014-05-21 01:44:48 +00:00
|
|
|
GSList *widgets, *l;
|
|
|
|
GtkWidget *listbox;
|
|
|
|
|
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (sl), frame);
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (box, GTK_STYLE_CLASS_VIEW);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), box);
|
|
|
|
|
|
|
|
box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), box2);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Mode"));
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (label, 10);
|
|
|
|
gtk_widget_set_margin_end (label, 10);
|
|
|
|
gtk_widget_set_margin_top (label, 10);
|
|
|
|
gtk_widget_set_margin_bottom (label, 10);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box2), label);
|
2014-05-21 01:44:48 +00:00
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (combo, 10);
|
|
|
|
gtk_widget_set_margin_end (combo, 10);
|
|
|
|
gtk_widget_set_margin_top (combo, 10);
|
|
|
|
gtk_widget_set_margin_bottom (combo, 10);
|
2014-05-21 01:44:48 +00:00
|
|
|
gtk_widget_set_halign (combo, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (combo, GTK_ALIGN_BASELINE);
|
2016-02-16 23:33:16 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("sizegroup mode", "None"));
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("sizegroup mode", "Horizontal"));
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("sizegroup mode", "Vertical"));
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("sizegroup mode", "Both"));
|
2014-05-21 01:44:48 +00:00
|
|
|
g_object_bind_property (group, "mode",
|
|
|
|
combo, "active",
|
|
|
|
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box2), combo);
|
2014-05-21 01:44:48 +00:00
|
|
|
|
|
|
|
listbox = gtk_list_box_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), listbox);
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (listbox), GTK_SELECTION_NONE);
|
|
|
|
|
|
|
|
widgets = gtk_size_group_get_widgets (group);
|
|
|
|
for (l = widgets; l; l = l->next)
|
|
|
|
add_widget (sl, GTK_LIST_BOX (listbox), GTK_WIDGET (l->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_inspector_size_groups_set_object (GtkInspectorSizeGroups *sl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
2014-07-16 09:58:20 +00:00
|
|
|
GSList *groups, *l;
|
2019-04-02 23:24:57 +00:00
|
|
|
GtkWidget *stack;
|
|
|
|
GtkStackPage *page;
|
|
|
|
|
|
|
|
stack = gtk_widget_get_parent (GTK_WIDGET (sl));
|
|
|
|
page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
|
|
|
|
|
|
|
|
g_object_set (page, "visible", FALSE, NULL);
|
2014-07-16 09:58:20 +00:00
|
|
|
|
2014-05-21 01:44:48 +00:00
|
|
|
clear_view (sl);
|
|
|
|
|
2014-07-12 12:59:59 +00:00
|
|
|
if (!GTK_IS_WIDGET (object))
|
2019-04-02 23:24:57 +00:00
|
|
|
return;
|
2014-07-12 12:59:59 +00:00
|
|
|
|
|
|
|
groups = _gtk_widget_get_sizegroups (GTK_WIDGET (object));
|
2014-11-09 02:30:12 +00:00
|
|
|
if (groups)
|
2019-04-02 23:24:57 +00:00
|
|
|
g_object_set (page, "visible", TRUE, NULL);
|
2014-07-12 12:59:59 +00:00
|
|
|
for (l = groups; l; l = l->next)
|
|
|
|
{
|
|
|
|
GtkSizeGroup *group = l->data;
|
|
|
|
add_size_group (sl, group);
|
2014-05-21 01:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_size_groups_init (GtkInspectorSizeGroups *sl)
|
|
|
|
{
|
|
|
|
g_object_set (sl,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
2014-11-23 01:56:49 +00:00
|
|
|
"margin-start", 60,
|
|
|
|
"margin-end", 60,
|
|
|
|
"margin-bottom", 60,
|
2016-03-07 01:41:28 +00:00
|
|
|
"margin-bottom", 30,
|
2014-11-23 01:56:49 +00:00
|
|
|
"spacing", 10,
|
2014-05-21 01:44:48 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_inspector_size_groups_class_init (GtkInspectorSizeGroupsClass *klass)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|