~ubuntu-branches/ubuntu/trusty/gq/trusty

« back to all changes in this revision

Viewing changes to src/gq-change-bar.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2009-10-25 23:34:56 UTC
  • mfrom: (1.1.4 upstream) (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091025233456-i794n3yg2cff930j
Tags: 1.3.4-1
* QA upload.
  + Set maintainer to Debian QA Group <packages@qa.debian.org>.
* New upstream release. (Closes: #534705).
  + Does not segfault on amd64. (Closes: #444312).
  + Remove all existing patches and change patch system to quilt.
  + Replace dpatch build-dep with quilt.
* 01_desktop_file.diff - Remove encoding and bogus categories 
  from desktop file.
* Copy in config.{sub,guess} on configure, rm them on clean.
  + Add build-dep on autotools-dev.
* Make clean not ignore errors.
* Add copyright holders and version path to GPL (GPL-2).
* Update watch file to use SF redirector. (Closes: #449749).
* Bump debhelper build-dep and compat to 5.
* Bump Standards Version to 3.8.3.
  + Menu policy transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of GQ
 
2
 *
 
3
 * AUTHORS
 
4
 *     Sven Herzberg  <herzi@gnome-de.org>
 
5
 *
 
6
 * Copyright (C) 2006  Sven Herzberg
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License as
 
10
 * published by the Free Software Foundation; either version 2.1 of the
 
11
 * License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
21
 * USA
 
22
 */
 
23
 
 
24
#include "gq-change-bar.h"
 
25
 
 
26
#include <glib/gi18n.h>
 
27
 
 
28
struct GqChangeBarPrivate {
 
29
        GtkWidget   * comparison;
 
30
        GtkWidget   * input_form;
 
31
        GqDifference* difference;
 
32
};
 
33
#define P(i) (G_TYPE_INSTANCE_GET_PRIVATE((i), GQ_TYPE_CHANGE_BAR, struct GqChangeBarPrivate))
 
34
 
 
35
GtkWidget*
 
36
gq_change_bar_new(GqComparison* comparison,
 
37
                  GqInputForm * form)
 
38
{
 
39
        return g_object_new(GQ_TYPE_CHANGE_BAR,
 
40
                            "comparison", comparison,
 
41
                            "input-form", form,
 
42
                            NULL);
 
43
}
 
44
 
 
45
/* GType */
 
46
G_DEFINE_TYPE(GqChangeBar, gq_change_bar, GTK_TYPE_DRAWING_AREA);
 
47
 
 
48
enum {
 
49
        PROP_0,
 
50
        PROP_COMPARISON,
 
51
        PROP_INPUT_FORM
 
52
};
 
53
 
 
54
static void
 
55
gq_change_bar_init(GqChangeBar* self G_GNUC_UNUSED)
 
56
{}
 
57
 
 
58
static void
 
59
change_bar_dispose(GObject* object)
 
60
{
 
61
        if(P(object)->difference) {
 
62
                g_signal_handlers_disconnect_by_func(P(object)->difference, gtk_widget_queue_draw, object);
 
63
                g_object_unref(P(object)->difference);
 
64
                P(object)->difference = NULL;
 
65
        }
 
66
 
 
67
        if(P(object)->comparison) {
 
68
                g_object_unref(P(object)->comparison);
 
69
                P(object)->comparison = NULL;
 
70
        }
 
71
 
 
72
        if(P(object)->input_form) {
 
73
                g_object_unref(P(object)->input_form);
 
74
                P(object)->input_form = NULL;
 
75
        }
 
76
 
 
77
        G_OBJECT_CLASS(gq_change_bar_parent_class)->dispose(object);
 
78
}
 
79
 
 
80
static void
 
81
change_bar_get_property(GObject   * object,
 
82
                        guint       prop_id,
 
83
                        GValue    * value,
 
84
                        GParamSpec* pspec)
 
85
{
 
86
        switch(prop_id) {
 
87
        case PROP_COMPARISON:
 
88
                g_value_set_object(value, P(object)->comparison);
 
89
                break;
 
90
        case PROP_INPUT_FORM:
 
91
                g_value_set_object(value, P(object)->input_form);
 
92
                break;
 
93
        default:
 
94
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
95
                break;
 
96
        }
 
97
}
 
98
 
 
99
static void
 
100
change_bar_set_property(GObject     * object,
 
101
                        guint         prop_id,
 
102
                        GValue const* value,
 
103
                        GParamSpec  * pspec)
 
104
{
 
105
        switch(prop_id) {
 
106
        case PROP_COMPARISON:
 
107
                if(P(object)->comparison) {
 
108
                        g_signal_handlers_disconnect_by_func(P(object)->difference, gtk_widget_queue_draw, object);
 
109
                        g_object_unref(P(object)->difference);
 
110
                        P(object)->difference = NULL;
 
111
                        g_object_unref(P(object)->comparison);
 
112
                }
 
113
                P(object)->comparison = (GtkWidget*)g_value_dup_object(value);
 
114
                if(P(object)->comparison) {
 
115
                        P(object)->difference = g_object_ref(gq_comparison_get_difference(GQ_COMPARISON(P(object)->comparison)));
 
116
                        g_signal_connect_swapped(P(object)->difference, "updated",
 
117
                                                 G_CALLBACK(gtk_widget_queue_draw), object);
 
118
                }
 
119
                g_object_notify(object, "comparison");
 
120
                break;
 
121
        case PROP_INPUT_FORM:
 
122
                if(P(object)->input_form) {
 
123
                        g_object_unref(P(object)->input_form);
 
124
                }
 
125
                P(object)->input_form = (GtkWidget*)g_value_dup_object(value);
 
126
                g_object_notify(object, "input-form");
 
127
                break;
 
128
        default:
 
129
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
130
                break;
 
131
        }
 
132
}
 
133
 
 
134
static void
 
135
change_bar_display_change(GqFormfill* form1,
 
136
                          GqFormfill* form2,
 
137
                          gboolean     equal,
 
138
                          gpointer     user_data)
 
139
{
 
140
        gpointer * self_and_cr = user_data;
 
141
        GtkWidget* form = P(self_and_cr[0])->input_form;
 
142
        GtkWidget* comp1 = !form1 ? NULL : gtk_widget_get_parent(
 
143
                                        gtk_widget_get_parent(
 
144
                                                gtk_widget_get_parent(
 
145
                                                        gtk_widget_get_parent(
 
146
                                                        gtk_widget_get_parent(
 
147
                                                                gq_formfill_get_event_box(form1) // GtkEventBox
 
148
                                                                ) // should return GtkTable
 
149
                                                        ) // GtkVBox
 
150
                                                ) // should return GtkViewport
 
151
                                        ) // should return GtkScrolledWindow
 
152
                                ); // should return GqInputForm
 
153
        GtkWidget* comp2 = !form2 ? NULL : gtk_widget_get_parent(
 
154
                                        gtk_widget_get_parent(
 
155
                                                gtk_widget_get_parent(
 
156
                                                        gtk_widget_get_parent(
 
157
                                                        gtk_widget_get_parent(
 
158
                                                                gq_formfill_get_event_box(form2) // GtkEventBox
 
159
                                                                ) // should return GtkTable
 
160
                                                        ) // should return GtkVBox
 
161
                                                ) // should return GtkViewport
 
162
                                        ) // should return GtkScrolledWindow
 
163
                                ); // should return GqInputForm
 
164
 
 
165
        if(equal) {
 
166
                return;
 
167
        }
 
168
 
 
169
        if(comp1 == form || comp2 == form) {
 
170
                GtkWidget* reference = self_and_cr[1];
 
171
                GtkWidget* table;
 
172
                GtkWidget* ebox;
 
173
                cairo_t* cr = self_and_cr[2];
 
174
                cairo_set_line_width(cr, 1.0);
 
175
                if(comp1 == form) {
 
176
                        ebox = gq_formfill_get_event_box(form1);
 
177
                }
 
178
                else {
 
179
                        ebox = gq_formfill_get_event_box(form2);
 
180
                }
 
181
                table = gtk_widget_get_parent(ebox);
 
182
                cairo_rectangle(cr, 0.5, ((int)1.0*reference->allocation.height*(ebox->allocation.y+table->allocation.x)/(table->allocation.height+table->allocation.x))+0.5, 11.0, 3.0);
 
183
                if(form1 && form2) {
 
184
                        cairo_set_source_rgb(cr, 0.45, 0.62, 0.81);
 
185
                }
 
186
                else {
 
187
                        cairo_set_source_rgb(cr, 0.54, 0.88, 0.2);
 
188
                }
 
189
                cairo_fill_preserve(cr);
 
190
                if(form1 && form2) {
 
191
                        cairo_set_source_rgb(cr, 0.13, 0.29, 0.53);
 
192
                }
 
193
                else
 
194
                {
 
195
                        cairo_set_source_rgb(cr, 0.3, 0.6, 0.02);
 
196
                }
 
197
                cairo_stroke(cr);
 
198
        }
 
199
}
 
200
 
 
201
static gboolean
 
202
change_bar_expose_event(GtkWidget     * widget,
 
203
                        GdkEventExpose* event  G_GNUC_UNUSED)
 
204
{
 
205
        GtkWidget* reference = gtk_bin_get_child(GTK_BIN(gq_input_form_get_scrolled_window(GQ_INPUT_FORM(P(widget)->input_form))));
 
206
        cairo_t* cr = gdk_cairo_create(widget->window);
 
207
        gpointer self_ref_and_cr[3] = {widget, reference, cr};
 
208
        cairo_translate(cr, 0.0, reference->allocation.y - widget->allocation.y);
 
209
        gq_difference_foreach(P(widget)->difference, change_bar_display_change, self_ref_and_cr);
 
210
        cairo_destroy(cr);
 
211
        return FALSE;
 
212
}
 
213
 
 
214
static void
 
215
change_bar_size_request(GtkWidget     * widget G_GNUC_UNUSED,
 
216
                        GtkRequisition* requisition)
 
217
{
 
218
        requisition->width = 12;
 
219
}
 
220
 
 
221
static void
 
222
gq_change_bar_class_init(GqChangeBarClass* self_class)
 
223
{
 
224
        GObjectClass* object_class = G_OBJECT_CLASS(self_class);
 
225
        GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(self_class);
 
226
 
 
227
        /* GObjectClass */
 
228
        object_class->dispose      = change_bar_dispose;
 
229
        object_class->get_property = change_bar_get_property;
 
230
        object_class->set_property = change_bar_set_property;
 
231
 
 
232
        g_object_class_install_property(object_class, PROP_COMPARISON,
 
233
                                        g_param_spec_object("comparison",
 
234
                                                            _("Comparison"),
 
235
                                                            _("The compare widget"),
 
236
                                                            GQ_TYPE_COMPARISON,
 
237
                                                            G_PARAM_READWRITE));
 
238
        g_object_class_install_property(object_class, PROP_INPUT_FORM,
 
239
                                        g_param_spec_object("input-form",
 
240
                                                            _("Input Form"),
 
241
                                                            _("The input form of this change bar"),
 
242
                                                            GQ_TYPE_INPUT_FORM,
 
243
                                                            G_PARAM_READWRITE));
 
244
 
 
245
        /* GtkWidgetClass */
 
246
        widget_class->expose_event = change_bar_expose_event;
 
247
        widget_class->size_request = change_bar_size_request;
 
248
 
 
249
        /* GqChangeBarClass */
 
250
        g_type_class_add_private(self_class, sizeof(struct GqChangeBarPrivate));
 
251
}
 
252