~blue-shell-next/carbon-gtk/master

« back to all changes in this revision

Viewing changes to src/animations/oxygenscrollbardata.cpp

  • Committer: David Edmundson
  • Date: 2015-02-11 15:48:54 UTC
  • Revision ID: git-v1:ed61428ce6f52c8b8551e5efd0cdc4f2ad956719
RenameĀ files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* this file is part of the oxygen gtk engine
3
 
* Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
4
 
*
5
 
* This  library is free  software; you can  redistribute it and/or
6
 
* modify it  under  the terms  of the  GNU Lesser  General  Public
7
 
* License  as published  by the Free  Software  Foundation; either
8
 
* version 2 of the License, or(at your option ) any later version.
9
 
*
10
 
* This library is distributed  in the hope that it will be useful,
11
 
* but  WITHOUT ANY WARRANTY; without even  the implied warranty of
12
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 
* Lesser General Public License for more details.
14
 
*
15
 
* You should have received a copy of the GNU Lesser General Public
16
 
* License  along  with  this library;  if not,  write to  the Free
17
 
* Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
18
 
* MA 02110-1301, USA.
19
 
*/
20
 
 
21
 
#include "oxygenscrollbardata.h"
22
 
#include "../oxygengtkutils.h"
23
 
 
24
 
#include <gtk/gtk.h>
25
 
 
26
 
namespace Oxygen
27
 
{
28
 
 
29
 
    //________________________________________________________________________________
30
 
    void ScrollBarData::connect( GtkWidget* widget )
31
 
    {
32
 
        _target = widget;
33
 
        _locked = false;
34
 
        _valueChangedId.connect( G_OBJECT(widget), "value-changed", G_CALLBACK( valueChanged ), this );
35
 
    }
36
 
 
37
 
    //________________________________________________________________________________
38
 
    void ScrollBarData::disconnect( GtkWidget* )
39
 
    {
40
 
        _target = 0L;
41
 
 
42
 
        // reset timeout and locked flag
43
 
        _timer.stop();
44
 
        _locked = false;
45
 
 
46
 
        _valueChangedId.disconnect();
47
 
    }
48
 
 
49
 
    //________________________________________________________________________________
50
 
    void ScrollBarData::valueChanged( GtkRange* widget, gpointer pointer )
51
 
    {
52
 
 
53
 
        ScrollBarData& data( *static_cast<ScrollBarData*>( pointer ) );
54
 
        if( data._updatesDelayed )
55
 
        {
56
 
 
57
 
            // schedule delayed timeOut
58
 
            if( !data._timer.isRunning() )
59
 
            {
60
 
 
61
 
                data._timer.start( data._delay, (GSourceFunc)delayedUpdate, &data );
62
 
                data._locked = false;
63
 
 
64
 
            } else data._locked = true;
65
 
 
66
 
 
67
 
        } else if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( GTK_WIDGET( widget ) ) ) {
68
 
 
69
 
            gtk_widget_queue_draw( parent );
70
 
 
71
 
        }
72
 
 
73
 
        return;
74
 
    }
75
 
 
76
 
    //________________________________________________________________________________
77
 
    gboolean ScrollBarData::delayedUpdate( gpointer pointer )
78
 
    {
79
 
 
80
 
        ScrollBarData& data( *static_cast<ScrollBarData*>(pointer) );
81
 
 
82
 
        if( !data._target )
83
 
        {
84
 
 
85
 
            // if target is invalid, reset timeout and return
86
 
            data._locked = false;
87
 
            return FALSE;
88
 
 
89
 
        } else if( data._locked ) {
90
 
 
91
 
            // if locked, reset the flag and re-run timer
92
 
            data._locked = false;
93
 
            return TRUE;
94
 
 
95
 
        } else if( GtkWidget* parent = Gtk::gtk_parent_scrolled_window( GTK_WIDGET( data._target ) ) ) {
96
 
 
97
 
            // otherwise, trigger update
98
 
            gtk_widget_queue_draw( parent );
99
 
            return FALSE;
100
 
 
101
 
        }
102
 
 
103
 
        // if everything fails, unlock and do nothing
104
 
        data._locked = false;
105
 
        return FALSE;
106
 
 
107
 
    }
108
 
 
109
 
}