OSDN Git Service

Session load and save.
[fukui-no-namari/dialektos.git] / src / text_view_scrollable.cxx
1 /*
2  * Copyright (C) 2009 by Aiwota Programmer
3  * aiwotaprog@tetteke.tk
4  *
5  * This file is part of Dialektos.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include "text_view_scrollable.hxx"
22
23 #include <gtkmm/drawingarea.h>
24 #include <sigc++/functors/mem_fun.h>
25
26
27 namespace dialektos {
28
29
30 namespace text_view {
31
32
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));
38 }
39
40 Scrollable::~Scrollable() {}
41
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)));
48 }
49
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)));
56   queue_draw();
57 }
58
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);
65 }
66
67
68
69 } // namespace text_view
70
71 } // namespace dialektos