Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.09 / src / gtkmm / adjust_window.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file adjust_window.cpp
3 **      \brief Adjustment Window Implementation File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2004 Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "adjust_window.h"
33 #include "app.h"
34
35 #include "general.h"
36
37 #endif
38
39 /* === U S I N G =========================================================== */
40
41 using namespace std;
42 //using namespace etl;
43 //using namespace synfig;
44
45 using studio::Adjust_Window;
46
47 /* === M A C R O S ========================================================= */
48 const double EPSILON = 1.0e-6;
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 /* === E N T R Y P O I N T ================================================= */
57
58 Adjust_Window::Adjust_Window(double value, double lower, double upper,
59                                                         double stepinc, double pageinc, double pagesize,
60                                                         Gtk::Adjustment *adj)
61 : Adjustment(value,lower,upper,stepinc,pageinc,pagesize),
62         adj_child(0)
63 {
64         if(adj) set_child_adjustment(adj);
65 }
66
67 Adjust_Window::~Adjust_Window()
68 {
69         //connections should automatically be killed etc.
70 }
71
72 //child interface functions
73 Gtk::Adjustment *Adjust_Window::get_child_adjustment()
74 {
75         return adj_child;
76 }
77
78 const Gtk::Adjustment *Adjust_Window::get_child_adjustment() const
79 {
80         return adj_child;
81 }
82
83 void Adjust_Window::set_child_adjustment(Gtk::Adjustment *child)
84 {
85         childchanged.disconnect();
86
87         adj_child = child;
88
89         // synfig::info("Adjust: connecting to child signals");
90
91         if(child)
92         {
93                 childchanged = child->signal_changed().connect(sigc::mem_fun(*this,&Adjust_Window::update_fromchild));
94
95                 update_child();
96         }
97 }
98
99 void Adjust_Window::on_changed()
100 {
101         update_child();
102 }
103
104 void Adjust_Window::on_value_changed()
105 {
106         update_child();
107 }
108
109 //SUB TIME FUNCTIONS
110 double Adjust_Window::get_sub_lower() const
111 {
112         return get_value();
113 }
114
115 double Adjust_Window::get_sub_upper() const
116 {
117         return get_value() + get_page_size();
118 }
119
120 //---- REFRESH FUNCTIONS -----
121 void Adjust_Window::update_child()
122 {
123         if(adj_child)
124         {
125                 bool childchanged = false;
126
127                 double v = get_value();
128                 double ve = v + get_page_size();
129
130                 //reset child's values if they need to be...
131                 if(abs(v - adj_child->get_lower()) > EPSILON)
132                 {
133                         adj_child->set_lower(v);
134                         childchanged = true;
135                 }
136
137                 if(abs(ve - adj_child->get_upper()) > EPSILON)
138                 {
139                         adj_child->set_upper(ve);
140                         childchanged = true;
141                 }
142
143                 if(childchanged)
144                 {
145                         adj_child->changed();
146                 }
147         }
148 }
149
150 void Adjust_Window::update_fromchild()
151 {
152         if(adj_child)
153         {
154                 double b = adj_child->get_lower();
155                 double dist = adj_child->get_upper() - b;
156
157                 //reset our values if they need to be...
158                 if(abs(get_value() - b) > EPSILON)
159                 {
160                         set_value(b);
161                         value_changed();
162                 }
163
164                 if(abs(get_page_size() - dist) > EPSILON)
165                 {
166                         set_page_size(dist);
167                         changed();
168                 }
169         }
170 }