3 * \file GtkLengthEntry.C
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCXX_CONCEPT_CHECKS
16 #undef _GLIBCXX_CONCEPT_CHECKS
18 #ifdef _GLIBCPP_CONCEPT_CHECKS
19 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "GtkLengthEntry.h"
37 string const getLengthFromWidgets(Gtk::Adjustment const & adj, Gtk::ComboBoxText const & combo)
39 std::ostringstream os;
40 os << adj.get_value();
41 os << combo.get_active_text();
46 void setWidgetsFromLength(Gtk::Adjustment & adj, Gtk::ComboBoxText & combo, LyXLength const & length)
48 adj.set_value(length.value());
50 string unit = stringFromUnit(length.unit());
52 unit = getDefaultUnit();
54 comboBoxTextSet(combo,unit);
58 void populateUnitCombo(Gtk::ComboBoxText & combo, bool const userelative)
60 vector<string> const units = buildLengthUnitList(userelative);
62 vector<string>::const_iterator it = units.begin();
63 vector<string>::const_iterator const end = units.end();
64 for(; it != end; ++it)
65 combo.append_text(*it);
72 GtkLengthEntry::GtkLengthEntry(
73 BaseObjectType* cobject,
74 const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
75 : Gtk::HBox(cobject), adj_(666.0, 0.0, 99999.0, 0.1, 1, 0.0), spin_(adj_, 0.1, 2)
77 populateUnitCombo (combo_, true);
81 pack_start (spin_, true, true, 0);
82 pack_start (combo_, false, false, 0);
84 spin_.signal_changed().connect(sigc::mem_fun(changedsignal_, &sigc::signal<void>::emit));
85 combo_.signal_changed().connect(sigc::mem_fun(changedsignal_, &sigc::signal<void>::emit));
89 sigc::signal< void >& GtkLengthEntry::signal_changed()
91 return changedsignal_;
95 void GtkLengthEntry::set_length(LyXLength const & length)
97 setWidgetsFromLength (*spin_.get_adjustment(), combo_, length);
101 void GtkLengthEntry::set_length(std::string const & length)
103 setWidgetsFromLength (*spin_.get_adjustment(), combo_, LyXLength(length));
107 LyXLength const GtkLengthEntry::get_length()
109 return LyXLength(getLengthFromWidgets(*spin_.get_adjustment(), combo_));
113 std::string const GtkLengthEntry::get_length_string()
115 return getLengthFromWidgets(*spin_.get_adjustment(), combo_);
119 void GtkLengthEntry::set_relative(bool rel)
122 if (rel != relative_) {
123 populateUnitCombo (combo_, rel);
129 } // namespace frontend