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