2 * \file GtkLengthEntry.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
21 #include "GtkLengthEntry.h"
36 string const getLengthFromWidgets(Gtk::Adjustment const & adj, Gtk::ComboBoxText const & combo)
38 std::ostringstream os;
39 os << adj.get_value();
40 os << combo.get_active_text();
45 void setWidgetsFromLength(Gtk::Adjustment & adj, Gtk::ComboBoxText & combo, LyXLength const & length)
47 adj.set_value(length.value());
49 string unit = stringFromUnit(length.unit());
51 unit = getDefaultUnit();
53 combo.set_active_text (unit);
57 void populateUnitCombo(Gtk::ComboBoxText & combo, bool const userelative)
59 vector<string> const units = buildLengthUnitList(userelative);
61 vector<string>::const_iterator it = units.begin();
62 vector<string>::const_iterator const end = units.end();
63 for(; it != end; ++it)
64 combo.append_text(*it);
71 GtkLengthEntry::GtkLengthEntry(
72 BaseObjectType* cobject,
73 const Glib::RefPtr<Gnome::Glade::Xml>& /*refGlade*/)
74 : Gtk::HBox(cobject), adj_(666.0, 0.0, 99999.0, 0.1, 1, 0.0), spin_(adj_, 0.1, 2)
76 populateUnitCombo (combo_, true);
80 pack_start (spin_, true, true, 0);
81 pack_start (combo_, false, false, 0);
83 spin_.signal_value_changed().connect(sigc::mem_fun(changedsignal_, &sigc::signal<void>::emit));
84 combo_.signal_changed().connect(sigc::mem_fun(changedsignal_, &sigc::signal<void>::emit));
88 sigc::signal< void >& GtkLengthEntry::signal_changed()
90 return changedsignal_;
94 void GtkLengthEntry::set_length(LyXLength const & length)
96 setWidgetsFromLength (*spin_.get_adjustment(), combo_, length);
100 void GtkLengthEntry::set_length(std::string const & length)
102 setWidgetsFromLength (*spin_.get_adjustment(), combo_, LyXLength(length));
106 LyXLength const GtkLengthEntry::get_length()
108 return LyXLength(getLengthFromWidgets(*spin_.get_adjustment(), combo_));
112 std::string const GtkLengthEntry::get_length_string()
114 return getLengthFromWidgets(*spin_.get_adjustment(), combo_);
118 void GtkLengthEntry::set_relative(bool rel)
121 if (rel != relative_) {
122 populateUnitCombo (combo_, rel);
128 Gtk::ComboBoxText *GtkLengthEntry::get_combo()
134 Gtk::SpinButton *GtkLengthEntry::get_spin()
139 Gtk::ComboBoxText const *const GtkLengthEntry::get_combo() const
145 Gtk::SpinButton const *const GtkLengthEntry::get_spin() const
151 } // namespace frontend