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_popup.hxx"
23 #include <gdkmm/rectangle.h>
24 #include <gtkmm/window.h>
25 #include <boost/foreach.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include "text_element_id_map.hxx"
28 #include "text_element_res_num.hxx"
29 #include "text_line.hxx"
38 Popup::Popup(const LineListType& line_list,
39 const LineListType& original_line_list,
40 const text_element::Anchor& element,
41 boost::shared_ptr<text_element::IDMap> id_map,
42 boost::shared_ptr<text_element::ResNumMap> res_num_map):
43 Gtk::Window(Gtk::WINDOW_POPUP),
44 text_view_(original_line_list),
45 scrolled_(text_view_.get_adjustment()),
46 element_origin_(element) {
48 text_view_.set_id_map(id_map);
49 text_view_.set_res_num_map(res_num_map);
51 scrolled_.add(text_view_);
56 text_view_.size_allocate(Gdk::Rectangle(0, 0, 300, 200));
57 text_view_.get_adjustment().set_page_size(200);
59 BOOST_FOREACH(const TextLine& line, line_list) {
60 text_view_.add_line(new TextLine(line));
63 text_view_.relayout();
64 text_view_.queue_draw();
66 text_view_.size_allocate(Gdk::Rectangle(0, 0, 300,
67 std::min(200.0, std::ceil(text_view_.get_adjustment().get_upper()))));
68 set_default_size(300, text_view_.get_height());
72 bool Popup::is_same_origin(const text_element::Anchor& rhs) const {
73 return &element_origin_ == &rhs;
76 bool Popup::on_the_child() const {
77 return text_view_.is_pointer_on_the_popup();
81 } // namespace text_view
84 } // namespace dialektos