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 <synfig/general.h>
33 
34 #include "adjust_window.h"
35 #include "app.h"
36 
37 #include <gui/localization.h>
38 
39 #endif
40 
41 /* === U S I N G =========================================================== */
42 
43 using namespace std;
44 //using namespace etl;
45 //using namespace synfig;
46 
47 using studio::Adjust_Window;
48 
49 /* === M A C R O S ========================================================= */
50 const double EPSILON = 1.0e-6;
51 
52 /* === G L O B A L S ======================================================= */
53 
54 /* === P R O C E D U R E S ================================================= */
55 
56 /* === M E T H O D S ======================================================= */
57 
58 /* === E N T R Y P O I N T ================================================= */
59 
Adjust_Window(double value,double lower,double upper,double stepinc,double pageinc,double pagesize,const Glib::RefPtr<Gtk::Adjustment> & adj)60 Adjust_Window::Adjust_Window(double value, double lower, double upper,
61 							 double stepinc, double pageinc, double pagesize,
62 							 const Glib::RefPtr<Gtk::Adjustment> &adj)
63 : Adjustment(value,lower,upper,stepinc,pageinc,pagesize),
64 	adj_child(0)
65 {
66 	if(adj) set_child_adjustment(adj);
67 }
68 
~Adjust_Window()69 Adjust_Window::~Adjust_Window()
70 {
71 	//connections should automatically be killed etc.
72 }
73 
74 //child interface functions
get_child_adjustment()75 Glib::RefPtr<Gtk::Adjustment> Adjust_Window::get_child_adjustment()
76 {
77 	return adj_child;
78 }
79 
get_child_adjustment() const80 Glib::RefPtr<const Gtk::Adjustment> Adjust_Window::get_child_adjustment() const
81 {
82 	return adj_child;
83 }
84 
set_child_adjustment(const Glib::RefPtr<Gtk::Adjustment> & child)85 void Adjust_Window::set_child_adjustment(const Glib::RefPtr<Gtk::Adjustment> &child)
86 {
87 	childchanged.disconnect();
88 
89 	adj_child = child;
90 
91 	// synfig::info("Adjust: connecting to child signals");
92 
93 	if(child)
94 	{
95 		childchanged = child->signal_changed().connect(sigc::mem_fun(*this,&Adjust_Window::update_fromchild));
96 
97 		update_child();
98 	}
99 }
100 
on_changed()101 void Adjust_Window::on_changed()
102 {
103 	if (getenv("SYNFIG_DEBUG_ON_CHANGED"))
104 		printf("%s:%d Adjust_Window::on_changed()\n", __FILE__, __LINE__);
105 
106 	update_child();
107 }
108 
on_value_changed()109 void Adjust_Window::on_value_changed()
110 {
111 	update_child();
112 }
113 
114 //SUB TIME FUNCTIONS
get_sub_lower() const115 double Adjust_Window::get_sub_lower() const
116 {
117 	return get_value();
118 }
119 
get_sub_upper() const120 double Adjust_Window::get_sub_upper() const
121 {
122 	return get_value() + get_page_size();
123 }
124 
125 //---- REFRESH FUNCTIONS -----
update_child()126 void Adjust_Window::update_child()
127 {
128 	if(adj_child)
129 	{
130 		bool childchanged = false;
131 
132 		double v = get_value();
133 		double ve = v + get_page_size();
134 
135 		//reset child's values if they need to be...
136 		if(abs(v - adj_child->get_lower()) > EPSILON)
137 		{
138 			adj_child->set_lower(v);
139 			childchanged = true;
140 		}
141 
142 		if(abs(ve - adj_child->get_upper()) > EPSILON)
143 		{
144 			adj_child->set_upper(ve);
145 			childchanged = true;
146 		}
147 
148 		if(childchanged)
149 		{
150 			adj_child->changed();
151 		}
152 	}
153 }
154 
update_fromchild()155 void Adjust_Window::update_fromchild()
156 {
157 	if(adj_child)
158 	{
159 		double b = adj_child->get_lower();
160 		double dist = adj_child->get_upper() - b;
161 
162 		//reset our values if they need to be...
163 		if(abs(get_value() - b) > EPSILON)
164 		{
165 			set_value(b);
166 			value_changed();
167 		}
168 
169 		if(abs(get_page_size() - dist) > EPSILON)
170 		{
171 			set_page_size(dist);
172 			changed();
173 		}
174 	}
175 }
176