1/*
2 * Copyright (c) 2021 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "config.h"
19#include <glib/gi18n-lib.h>
20
21#include "recorderrow.h"
22
23#include <gtk/gtkbinlayout.h>
24
25/* This is a minimal widget whose purpose it is to compare the event sequence
26 * of its row in the recordings list with the event sequence of the selected
27 * row, and highlight itself if they match.
28 */
29
30struct _GtkInspectorRecorderRow
31{
32 GtkWidget parent;
33
34 gpointer sequence;
35 gpointer match_sequence;
36};
37
38enum {
39 PROP_SEQUENCE = 1,
40 PROP_MATCH_SEQUENCE,
41 LAST_PROP
42};
43
44static GParamSpec *props[LAST_PROP] = { NULL, };
45
46G_DEFINE_TYPE (GtkInspectorRecorderRow, gtk_inspector_recorder_row, GTK_TYPE_WIDGET)
47
48static void
49gtk_inspector_recorder_row_init (GtkInspectorRecorderRow *self)
50{
51}
52
53static void
54dispose (GObject *object)
55{
56 GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (ptr: object);
57
58 gtk_widget_unparent (widget: gtk_widget_get_first_child (GTK_WIDGET (self)));
59
60 G_OBJECT_CLASS (gtk_inspector_recorder_row_parent_class)->dispose (object);
61}
62
63static void
64update_style (GtkInspectorRecorderRow *self)
65{
66 if (self->sequence == self->match_sequence && self->sequence != NULL)
67 gtk_widget_add_css_class (GTK_WIDGET (self), css_class: "highlight");
68 else
69 gtk_widget_remove_css_class (GTK_WIDGET (self), css_class: "highlight");
70}
71
72static void
73gtk_inspector_recorder_row_get_property (GObject *object,
74 guint param_id,
75 GValue *value,
76 GParamSpec *pspec)
77{
78 GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (ptr: object);
79
80 switch (param_id)
81 {
82 case PROP_SEQUENCE:
83 g_value_set_pointer (value, v_pointer: self->sequence);
84 break;
85
86 case PROP_MATCH_SEQUENCE:
87 g_value_set_pointer (value, v_pointer: self->match_sequence);
88 break;
89
90 default:
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
92 break;
93 }
94}
95
96static void
97gtk_inspector_recorder_row_set_property (GObject *object,
98 guint param_id,
99 const GValue *value,
100 GParamSpec *pspec)
101{
102 GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (ptr: object);
103
104 switch (param_id)
105 {
106 case PROP_SEQUENCE:
107 self->sequence = g_value_get_pointer (value);
108 update_style (self);
109 break;
110
111 case PROP_MATCH_SEQUENCE:
112 self->match_sequence = g_value_get_pointer (value);
113 update_style (self);
114 break;
115
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
118 break;
119 }
120}
121
122static void
123gtk_inspector_recorder_row_class_init (GtkInspectorRecorderRowClass *klass)
124{
125 GObjectClass *object_class = G_OBJECT_CLASS (klass);
126 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
127
128 object_class->dispose = dispose;
129 object_class->set_property = gtk_inspector_recorder_row_set_property;
130 object_class->get_property = gtk_inspector_recorder_row_get_property;
131
132 props[PROP_SEQUENCE] = g_param_spec_pointer (name: "sequence", nick: "", blurb: "", flags: G_PARAM_READWRITE);
133 props[PROP_MATCH_SEQUENCE] = g_param_spec_pointer (name: "match-sequence", nick: "", blurb: "", flags: G_PARAM_READWRITE);
134
135 g_object_class_install_properties (oclass: object_class, n_pspecs: LAST_PROP, pspecs: props);
136
137 gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
138}
139

source code of gtk/gtk/inspector/recorderrow.c