2 * Copyright (C) 2009 by Aiwota Programmer
3 * aiwotaprog@tetteke.tk
5 * This file is part of Dialektos.
7 * Dialektos is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * Dialektos is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Dialektos. If not, see <http://www.gnu.org/licenses/>.
21 #include "text_view_scrollable.hxx"
23 #include <gtkmm/drawingarea.h>
24 #include <sigc++/functors/mem_fun.h>
33 Scrollable::Scrollable(): adjustment_(0, 0, 0) {
34 adjustment_.signal_value_changed().connect(
35 sigc::mem_fun(*this, &Scrollable::on_adjustment_value_changed));
36 adjustment_.signal_changed().connect(
37 sigc::mem_fun(*this, &Scrollable::on_adjustment_changed));
40 Scrollable::~Scrollable() {}
42 void Scrollable::on_adjustment_changed() {
43 const gdouble value = adjustment_.get_value();
44 const gdouble lower = adjustment_.get_lower();
45 const gdouble upper = adjustment_.get_upper();
46 const gdouble page_size = adjustment_.get_page_size();
47 adjustment_.set_value(std::min(upper-page_size, std::max(value, lower)));
50 void Scrollable::on_adjustment_value_changed() {
51 const gdouble value = adjustment_.get_value();
52 const gdouble lower = adjustment_.get_lower();
53 const gdouble upper = adjustment_.get_upper();
54 const gdouble page_size = adjustment_.get_page_size();
55 adjustment_.set_value(std::min(upper-page_size, std::max(value, lower)));
59 bool Scrollable::on_configure_event(GdkEventConfigure* event) {
60 const int height = event->height;
61 adjustment_.set_page_size(height);
62 adjustment_.set_page_increment(height);
63 adjustment_.set_step_increment(height*0.1);
64 return Gtk::DrawingArea::on_configure_event(event);
69 } // namespace text_view
71 } // namespace dialektos