summaryrefslogtreecommitdiff
path: root/gtk/inspector/recorderrow.c
blob: a85e1e6d8ad435ea26a6ed5b5fd16fc9815183a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Copyright (c) 2021 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>

#include "recorderrow.h"

#include <gtk/gtkbinlayout.h>

/* This is a minimal widget whose purpose it is to compare the event sequence
 * of its row in the recordings list with the event sequence of the selected
 * row, and highlight itself if they match.
 */

struct _GtkInspectorRecorderRow
{
  GtkWidget parent;

  gpointer sequence;
  gpointer match_sequence;
};

enum {
  PROP_SEQUENCE = 1,
  PROP_MATCH_SEQUENCE,
  LAST_PROP
};

static GParamSpec *props[LAST_PROP] = { NULL, };

G_DEFINE_TYPE (GtkInspectorRecorderRow, gtk_inspector_recorder_row, GTK_TYPE_WIDGET)

static void
gtk_inspector_recorder_row_init (GtkInspectorRecorderRow *self)
{
}

static void
dispose (GObject *object)
{
  GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (object);

  gtk_widget_unparent (gtk_widget_get_first_child (GTK_WIDGET (self)));

  G_OBJECT_CLASS (gtk_inspector_recorder_row_parent_class)->dispose (object);
}

static void
update_style (GtkInspectorRecorderRow *self)
{
  if (self->sequence == self->match_sequence && self->sequence != NULL)
    gtk_widget_add_css_class (GTK_WIDGET (self), "highlight");
  else
    gtk_widget_remove_css_class (GTK_WIDGET (self), "highlight");
}

static void
gtk_inspector_recorder_row_get_property (GObject    *object,
                                         guint       param_id,
                                         GValue     *value,
                                         GParamSpec *pspec)
{
  GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (object);

  switch (param_id)
    {
    case PROP_SEQUENCE:
      g_value_set_pointer (value, self->sequence);
      break;

    case PROP_MATCH_SEQUENCE:
      g_value_set_pointer (value, self->match_sequence);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

static void
gtk_inspector_recorder_row_set_property (GObject      *object,
                                         guint         param_id,
                                         const GValue *value,
                                         GParamSpec   *pspec)
{
  GtkInspectorRecorderRow *self = GTK_INSPECTOR_RECORDER_ROW (object);

  switch (param_id)
    {
    case PROP_SEQUENCE:
      self->sequence = g_value_get_pointer (value);
      update_style (self);
      break;

    case PROP_MATCH_SEQUENCE:
      self->match_sequence = g_value_get_pointer (value);
      update_style (self);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

static void
gtk_inspector_recorder_row_class_init (GtkInspectorRecorderRowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  object_class->dispose = dispose;
  object_class->set_property = gtk_inspector_recorder_row_set_property;
  object_class->get_property = gtk_inspector_recorder_row_get_property;

  props[PROP_SEQUENCE] = g_param_spec_pointer ("sequence", NULL, NULL, G_PARAM_READWRITE);
  props[PROP_MATCH_SEQUENCE] = g_param_spec_pointer ("match-sequence", NULL, NULL, G_PARAM_READWRITE);

  g_object_class_install_properties (object_class, LAST_PROP, props);

  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
}