]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GCharacter.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / GCharacter.C
1 /**
2  * \file GCharacter.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 _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GCharacter.h"
22 #include "ghelpers.h"
23 #include "LColor.h"
24
25 #include "controllers/frnt_lang.h"
26 #include "controllers/helper_funcs.h"
27
28 #include "support/lstrings.h"
29
30 #include <libglademm.h>
31
32 using std::vector;
33 using std::string;
34
35 namespace lyx {
36 namespace frontend {
37
38
39 GCharacter::GCharacter(Dialog & parent)
40         : GViewCB<ControlCharacter, GViewGladeB>(parent, _("Text Style"), false)
41 {}
42
43
44 void GCharacter::PopulateComboBox(Gtk::ComboBox * combo,
45                                   vector<string> const & strings)
46 {
47         Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
48         vector<string>::const_iterator it = strings.begin();
49         vector<string>::const_iterator end = strings.end();
50         for(; it != end; ++it)
51                 (*model->append())[stringcol_] = *it;
52
53         combo->set_model(model);
54         Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
55         combo->pack_start(*cell, true);
56         combo->add_attribute(*cell,"text",0);
57 }
58
59
60 void GCharacter::doBuild()
61 {
62         string const gladeName = findGladeFile("character");
63         xml_ = Gnome::Glade::Xml::create(gladeName);
64         Gtk::Button * button;
65
66         // Manage the ok, apply and cancel/close buttons
67         xml_->get_widget("Ok", button);
68         setOK(button);
69         xml_->get_widget("Apply", button);
70         setApply(button);
71         xml_->get_widget("Cancel", button);
72         setCancel(button);
73
74         xml_->get_widget("ToggleAll", toggleallcheck_);
75
76         // Get combobox addresses
77         xml_->get_widget("Family", familycombo_);
78         xml_->get_widget("Series", seriescombo_);
79         xml_->get_widget("Shape", shapecombo_);
80         xml_->get_widget("Color", colorcombo_);
81         xml_->get_widget("Language", languagecombo_);
82         xml_->get_widget("Size", sizecombo_);
83         xml_->get_widget("Misc", misccombo_);
84
85         // Don't let the user change anything for read only documents
86         bcview().addReadOnly(familycombo_);
87         bcview().addReadOnly(seriescombo_);
88         bcview().addReadOnly(shapecombo_);
89         bcview().addReadOnly(colorcombo_);
90         bcview().addReadOnly(languagecombo_);
91         bcview().addReadOnly(sizecombo_);
92         bcview().addReadOnly(misccombo_);
93         bcview().addReadOnly(toggleallcheck_);
94
95         // Caption/identifier pairs for the parameters
96         vector<FamilyPair>   const family = getFamilyData();
97         vector<SeriesPair>   const series = getSeriesData();
98         vector<ShapePair>    const shape  = getShapeData();
99         vector<SizePair>     const size   = getSizeData();
100         vector<BarPair>      const bar    = getBarData();
101         vector<ColorPair>    const color  = getColorData();
102         vector<LanguagePair> const language  = getLanguageData(true);
103
104         // Store the identifiers for later
105         family_ = getSecond(family);
106         series_ = getSecond(series);
107         shape_  = getSecond(shape);
108         size_   = getSecond(size);
109         bar_    = getSecond(bar);
110         color_  = getSecond(color);
111         lang_   = getSecond(language);
112
113         // Setup the columnrecord we use for all combos
114         cols_.add(stringcol_);
115         // Load the captions into the comboboxes
116         PopulateComboBox(familycombo_, getFirst(family));
117         PopulateComboBox(seriescombo_, getFirst(series));
118         PopulateComboBox(shapecombo_, getFirst(shape));
119         PopulateComboBox(sizecombo_, getFirst(size));
120         PopulateComboBox(misccombo_, getFirst(bar));
121         PopulateComboBox(colorcombo_, getFirst(color));
122         PopulateComboBox(languagecombo_, getFirst(language));
123
124         /* We use a table so that people with decent size screens don't
125         * have to scroll.  However, this risks the popup being too wide
126         * for people with small screens, and it doesn't scroll horizontally.
127         * Hopefully this is not too wide */
128         languagecombo_->set_wrap_width(3);
129
130         // We have to update *before* the signals are connected
131         update();
132
133         familycombo_->signal_changed().connect(
134                 sigc::mem_fun(*this, &GCharacter::onChange));
135         seriescombo_->signal_changed().connect(
136                 sigc::mem_fun(*this, &GCharacter::onChange));
137         shapecombo_->signal_changed().connect(
138                 sigc::mem_fun(*this, &GCharacter::onChange));
139         sizecombo_->signal_changed().connect(
140                 sigc::mem_fun(*this, &GCharacter::onChange));
141         misccombo_->signal_changed().connect(
142                 sigc::mem_fun(*this, &GCharacter::onChange));
143         colorcombo_->signal_changed().connect(
144                 sigc::mem_fun(*this, &GCharacter::onChange));
145         languagecombo_->signal_changed().connect(
146                 sigc::mem_fun(*this, &GCharacter::onChange));
147 }
148
149
150 void GCharacter::apply()
151 {
152         int pos = familycombo_->get_active_row_number();
153         controller().setFamily(family_[pos]);
154
155         pos = seriescombo_->get_active_row_number();
156         controller().setSeries(series_[pos]);
157
158         pos = shapecombo_->get_active_row_number();
159         controller().setShape(shape_[pos]);
160
161         pos = sizecombo_->get_active_row_number();
162         controller().setSize(size_[pos]);
163
164         pos = misccombo_->get_active_row_number();
165         controller().setBar(bar_[pos]);
166
167         pos = colorcombo_->get_active_row_number();
168         controller().setColor(color_[pos]);
169
170         pos = languagecombo_->get_active_row_number();
171         controller().setLanguage(lang_[pos]);
172
173         bool const toggleall = toggleallcheck_->get_active();
174         controller().setToggleAll(toggleall);
175 }
176
177
178 void GCharacter::update()
179 {
180         int pos = int(findPos(family_, controller().getFamily()));
181         familycombo_->set_active(pos);
182
183         pos = int(findPos(series_, controller().getSeries()));
184         seriescombo_->set_active(pos);
185
186         pos = int(findPos(shape_, controller().getShape()));
187         shapecombo_->set_active(pos);
188
189         pos = int(findPos(size_, controller().getSize()));
190         sizecombo_->set_active(pos);
191
192         pos = int(findPos(bar_, controller().getBar()));
193         misccombo_->set_active(pos);
194
195         pos = int(findPos(color_, controller().getColor()));
196         colorcombo_->set_active(pos);
197
198         pos = int(findPos(lang_, controller().getLanguage()));
199         languagecombo_->set_active(pos);
200
201         toggleallcheck_->set_active(controller().getToggleAll());
202 }
203
204
205 void GCharacter::onChange()
206 {
207         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
208
209         int pos = familycombo_->get_active_row_number();
210         if (family_[pos] != LyXFont::IGNORE_FAMILY)
211                 activate = ButtonPolicy::SMI_VALID;
212
213         pos = seriescombo_->get_active_row_number();
214         if (series_[pos] != LyXFont::IGNORE_SERIES)
215                 activate = ButtonPolicy::SMI_VALID;
216
217         pos = shapecombo_->get_active_row_number();
218         if (shape_[pos] != LyXFont::IGNORE_SHAPE)
219                 activate = ButtonPolicy::SMI_VALID;
220
221         pos = sizecombo_->get_active_row_number();
222         if (size_[pos] != LyXFont::IGNORE_SIZE)
223                 activate = ButtonPolicy::SMI_VALID;
224
225         pos =  misccombo_->get_active_row_number();
226         if (bar_[pos] != IGNORE)
227                 activate = ButtonPolicy::SMI_VALID;
228
229         pos = colorcombo_->get_active_row_number();
230         if (color_[pos] != LColor::ignore)
231                 activate = ButtonPolicy::SMI_VALID;
232
233         pos = languagecombo_->get_active_row_number();
234         if (lang_[pos] != "No change")
235                 activate = ButtonPolicy::SMI_VALID;
236
237         bc().input(activate);
238 }
239
240 } // namespace frontend
241 } // namespace lyx