]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GVSpace.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / gtk / GVSpace.C
1 /**
2  * \file GVSpace.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
16 #endif
17
18 #include "GVSpace.h"
19 #include "ControlVSpace.h"
20 #include "ghelpers.h"
21
22 #include <libglademm.h>
23
24 using std::string;
25 using std::vector;
26
27 namespace lyx {
28 namespace frontend {
29
30 namespace {
31 string defaultUnit("cm");
32 } // namespace anon
33
34 GVSpace::GVSpace(Dialog & parent)
35         : GViewCB<ControlVSpace, GViewGladeB>(parent, _("VSpace Settings"), false)
36 {}
37
38
39 void GVSpace::doBuild()
40 {
41         string const gladeName = findGladeFile("vspace");
42         xml_ = Gnome::Glade::Xml::create(gladeName);
43
44         Gtk::Button * button;
45         xml_->get_widget("Cancel", button);
46         setCancel(button);
47         xml_->get_widget("Insert", button);
48         setOK(button);
49
50         xml_->get_widget("Spacing", spacingcombo_);
51         xml_->get_widget("Value", valuespin_);
52         xml_->get_widget("ValueUnits", valueunitscombo_);
53         xml_->get_widget("Protect", protectcheck_);
54
55         cols_.add(stringcol_);
56
57         PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList());
58
59         spacingcombo_->signal_changed().connect(
60                 sigc::mem_fun(*this, &GVSpace::onSpacingComboChanged));
61 }
62
63
64 void GVSpace::PopulateComboBox(Gtk::ComboBox * combo,
65                                   vector<string> const & strings)
66 {
67         Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
68         vector<string>::const_iterator it = strings.begin();
69         vector<string>::const_iterator end = strings.end();
70         for (int rowindex = 0; it != end; ++it, ++rowindex) {
71                 Gtk::TreeModel::iterator row = model->append();
72                 (*row)[stringcol_] = *it;
73         }
74
75         combo->set_model(model);
76         Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
77         combo->pack_start(*cell, true);
78         combo->add_attribute(*cell, "text", 0);
79 }
80
81
82 void GVSpace::update()
83 {
84         // set the right default unit
85         defaultUnit = getDefaultUnit();
86
87         VSpace const space = controller().params();
88
89         int pos = 0;
90         switch (space.kind()) {
91         case VSpace::DEFSKIP:
92                 pos = 0;
93                 break;
94         case VSpace::SMALLSKIP:
95                 pos = 1;
96                 break;
97         case VSpace::MEDSKIP:
98                 pos = 2;
99                 break;
100         case VSpace::BIGSKIP:
101                 pos = 3;
102                 break;
103         case VSpace::VFILL:
104                 pos = 4;
105                 break;
106         case VSpace::LENGTH:
107                 pos = 5;
108                 break;
109         }
110
111         spacingcombo_->set_active(pos);
112
113         protectcheck_->set_active(space.keep());
114
115         bool const custom_vspace = space.kind() == VSpace::LENGTH;
116         if (custom_vspace) {
117                 LyXLength length(space.length().asString());
118                 valuespin_->get_adjustment()->set_value(length.value());
119                 unitsComboFromLength(valueunitscombo_, stringcol_,
120                                      length, defaultUnit);
121         } else {
122                 valuespin_->get_adjustment()->set_value(0.0f);
123                 unitsComboFromLength(valueunitscombo_, stringcol_,
124                                      LyXLength(defaultUnit), defaultUnit);
125         }
126 }
127
128
129 void GVSpace::apply()
130 {
131         VSpace space;
132         switch (spacingcombo_->get_active_row_number()) {
133         case 0:
134                 space = VSpace(VSpace::DEFSKIP);
135                 break;
136         case 1:
137                 space = VSpace(VSpace::SMALLSKIP);
138                 break;
139         case 2:
140                 space = VSpace(VSpace::MEDSKIP);
141                 break;
142         case 3:
143                 space = VSpace(VSpace::BIGSKIP);
144                 break;
145         case 4:
146                 space = VSpace(VSpace::VFILL);
147                 break;
148         case 5:
149                 Glib::ustring const valueunit =
150                         (*valueunitscombo_->get_active())[stringcol_];
151                 space = VSpace(LyXGlueLength(valuespin_->get_text() + valueunit));
152                 break;
153         }
154
155         space.setKeep(protectcheck_->get_active());
156
157         controller().params() = space;
158 }
159
160
161 void GVSpace::onSpacingComboChanged()
162 {
163         bool const custom = spacingcombo_->get_active_row_number() == 5;
164         valueunitscombo_->set_sensitive(custom);
165         valuespin_->set_sensitive(custom);
166 }
167
168 } // namespace frontend
169 } // namespace lyx