~ubuntu-branches/ubuntu/precise/gnome-control-center/precise-updates

« back to all changes in this revision

Viewing changes to libslab/double-click-detector.c

Tags: upstream-3.0.1.1
ImportĀ upstreamĀ versionĀ 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libslab.
3
 
 *
4
 
 * Copyright (c) 2006, 2007 Novell, Inc.
5
 
 *
6
 
 * Libslab is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "double-click-detector.h"
22
 
 
23
 
#include <gtk/gtk.h>
24
 
 
25
 
#include "libslab-utils.h"
26
 
 
27
 
G_DEFINE_TYPE (DoubleClickDetector, double_click_detector, G_TYPE_OBJECT);
28
 
 
29
 
static void
30
 
double_click_detector_class_init (DoubleClickDetectorClass * detector_class)
31
 
{
32
 
}
33
 
 
34
 
static void
35
 
double_click_detector_init (DoubleClickDetector * detector)
36
 
{
37
 
        GtkSettings *settings;
38
 
        gint click_interval;
39
 
 
40
 
        settings = gtk_settings_get_default ();
41
 
 
42
 
        g_object_get (G_OBJECT (settings), "gtk-double-click-time", &click_interval, NULL);
43
 
 
44
 
        detector->double_click_time = (guint32) click_interval;
45
 
        detector->last_click_time = 0;
46
 
}
47
 
 
48
 
DoubleClickDetector *
49
 
double_click_detector_new ()
50
 
{
51
 
        return g_object_new (DOUBLE_CLICK_DETECTOR_TYPE, NULL);
52
 
}
53
 
 
54
 
gboolean
55
 
double_click_detector_is_double_click (DoubleClickDetector *this, guint32 event_time,
56
 
                                       gboolean auto_update)
57
 
{
58
 
        gint32 delta;
59
 
 
60
 
        if (event_time <= 0)
61
 
                event_time = libslab_get_current_time_millis ();
62
 
 
63
 
        if (this->last_click_time <= 0) {
64
 
                if (auto_update)
65
 
                        double_click_detector_update_click_time (this, event_time);
66
 
 
67
 
                return FALSE;
68
 
        }
69
 
 
70
 
        delta = event_time - this->last_click_time;
71
 
 
72
 
        if (auto_update)
73
 
                double_click_detector_update_click_time (this, event_time);
74
 
 
75
 
        return delta < this->double_click_time;
76
 
}
77
 
 
78
 
void
79
 
double_click_detector_update_click_time (DoubleClickDetector *this, guint32 event_time)
80
 
{
81
 
        if (event_time <= 0)
82
 
                event_time = libslab_get_current_time_millis ();
83
 
 
84
 
        this->last_click_time = event_time;
85
 
}