Initial attempt at i18n support using gettext
[synfig.git] / synfig-studio / trunk / 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         if(child)
91         {
92                 childchanged = child->signal_changed().connect(sigc::mem_fun(*this,&Adjust_Window::update_fromchild));
93
94                 update_child();
95         }
96 }
97
98 void Adjust_Window::on_changed()
99 {
100         update_child();
101 }
102
103 void Adjust_Window::on_value_changed()
104 {
105         update_child();
106 }
107
108 //SUB TIME FUNCTIONS
109 double Adjust_Window::get_sub_lower() const
110 {
111         return get_value();
112 }
113
114 double Adjust_Window::get_sub_upper() const
115 {
116         return get_value() + get_page_size();
117 }
118
119 //---- REFRESH FUNCTIONS -----
120 void Adjust_Window::update_child()
121 {
122         if(adj_child)
123         {
124                 bool childchanged = false;
125
126                 double v = get_value();
127                 double ve = v + get_page_size();
128
129                 //reset child's values if they need to be...
130                 if(abs(v - adj_child->get_lower()) > EPSILON)
131                 {
132                         adj_child->set_lower(v);
133                         childchanged = true;
134                 }
135
136                 if(abs(ve - adj_child->get_upper()) > EPSILON)
137                 {
138                         adj_child->set_upper(ve);
139                         childchanged = true;
140                 }
141
142                 if(childchanged)
143                 {
144                         adj_child->changed();
145                 }
146         }
147 }
148
149 void Adjust_Window::update_fromchild()
150 {
151         if(adj_child)
152         {
153                 double b = adj_child->get_lower();
154                 double dist = adj_child->get_upper() - b;
155
156                 //reset our values if they need to be...
157                 if(abs(get_value() - b) > EPSILON)
158                 {
159                         set_value(b);
160                         value_changed();
161                 }
162
163                 if(abs(get_page_size() - dist) > EPSILON)
164                 {
165                         set_page_size(dist);
166                         changed();
167                 }
168         }
169 }