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 #include "GCharacter.h"
17 #include "controllers/frnt_lang.h"
18 #include "controllers/helper_funcs.h"
20 #include "support/lstrings.h"
22 #include <libglademm.h>
31 GCharacter::GCharacter(Dialog & parent)
32 : GViewCB<ControlCharacter, GViewGladeB>(parent, _("Text Style"), false)
36 void GCharacter::PopulateComboBox(Gtk::ComboBox * combo,
37 vector<string> const & strings)
39 Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
40 vector<string>::const_iterator it = strings.begin();
41 vector<string>::const_iterator end = strings.end();
42 for(; it != end; ++it)
43 (*model->append())[stringcol_] = *it;
45 combo->set_model(model);
46 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
47 combo->pack_start(*cell, true);
48 combo->add_attribute(*cell,"text",0);
52 void GCharacter::doBuild()
54 string const gladeName = findGladeFile("character");
55 xml_ = Gnome::Glade::Xml::create(gladeName);
58 // Manage the ok, apply and cancel/close buttons
59 xml_->get_widget("Ok", button);
61 xml_->get_widget("Apply", button);
63 xml_->get_widget("Cancel", button);
66 xml_->get_widget("ToggleAll", toggleallcheck_);
68 // Get combobox addresses
69 xml_->get_widget("Family", familycombo_);
70 xml_->get_widget("Series", seriescombo_);
71 xml_->get_widget("Shape", shapecombo_);
72 xml_->get_widget("Color", colorcombo_);
73 xml_->get_widget("Language", languagecombo_);
74 xml_->get_widget("Size", sizecombo_);
75 xml_->get_widget("Misc", misccombo_);
77 // Don't let the user change anything for read only documents
78 bcview().addReadOnly(familycombo_);
79 bcview().addReadOnly(seriescombo_);
80 bcview().addReadOnly(shapecombo_);
81 bcview().addReadOnly(colorcombo_);
82 bcview().addReadOnly(languagecombo_);
83 bcview().addReadOnly(sizecombo_);
84 bcview().addReadOnly(misccombo_);
85 bcview().addReadOnly(toggleallcheck_);
87 // Caption/identifier pairs for the parameters
88 vector<FamilyPair> const family = getFamilyData();
89 vector<SeriesPair> const series = getSeriesData();
90 vector<ShapePair> const shape = getShapeData();
91 vector<SizePair> const size = getSizeData();
92 vector<BarPair> const bar = getBarData();
93 vector<ColorPair> const color = getColorData();
94 vector<LanguagePair> const language = getLanguageData(true);
96 // Store the identifiers for later
97 family_ = getSecond(family);
98 series_ = getSecond(series);
99 shape_ = getSecond(shape);
100 size_ = getSecond(size);
101 bar_ = getSecond(bar);
102 color_ = getSecond(color);
103 lang_ = getSecond(language);
105 // Setup the columnrecord we use for all combos
106 cols_.add(stringcol_);
107 // Load the captions into the comboboxes
108 PopulateComboBox(familycombo_, getFirst(family));
109 PopulateComboBox(seriescombo_, getFirst(series));
110 PopulateComboBox(shapecombo_, getFirst(shape));
111 PopulateComboBox(sizecombo_, getFirst(size));
112 PopulateComboBox(misccombo_, getFirst(bar));
113 PopulateComboBox(colorcombo_, getFirst(color));
114 PopulateComboBox(languagecombo_, getFirst(language));
116 /* We use a table so that people with decent size screens don't
117 * have to scroll. However, this risks the popup being too wide
118 * for people with small screens, and it doesn't scroll horizontally.
119 * Hopefully this is not too wide */
120 languagecombo_->set_wrap_width(3);
122 // We have to update *before* the signals are connected
125 familycombo_->signal_changed().connect(
126 sigc::mem_fun(*this, &GCharacter::onChange));
127 seriescombo_->signal_changed().connect(
128 sigc::mem_fun(*this, &GCharacter::onChange));
129 shapecombo_->signal_changed().connect(
130 sigc::mem_fun(*this, &GCharacter::onChange));
131 sizecombo_->signal_changed().connect(
132 sigc::mem_fun(*this, &GCharacter::onChange));
133 misccombo_->signal_changed().connect(
134 sigc::mem_fun(*this, &GCharacter::onChange));
135 colorcombo_->signal_changed().connect(
136 sigc::mem_fun(*this, &GCharacter::onChange));
137 languagecombo_->signal_changed().connect(
138 sigc::mem_fun(*this, &GCharacter::onChange));
142 void GCharacter::apply()
144 int pos = familycombo_->get_active_row_number();
145 controller().setFamily(family_[pos]);
147 pos = seriescombo_->get_active_row_number();
148 controller().setSeries(series_[pos]);
150 pos = shapecombo_->get_active_row_number();
151 controller().setShape(shape_[pos]);
153 pos = sizecombo_->get_active_row_number();
154 controller().setSize(size_[pos]);
156 pos = misccombo_->get_active_row_number();
157 controller().setBar(bar_[pos]);
159 pos = colorcombo_->get_active_row_number();
160 controller().setColor(color_[pos]);
162 pos = languagecombo_->get_active_row_number();
163 controller().setLanguage(lang_[pos]);
165 bool const toggleall = toggleallcheck_->get_active();
166 controller().setToggleAll(toggleall);
170 void GCharacter::update()
172 int pos = int(findPos(family_, controller().getFamily()));
173 familycombo_->set_active(pos);
175 pos = int(findPos(series_, controller().getSeries()));
176 seriescombo_->set_active(pos);
178 pos = int(findPos(shape_, controller().getShape()));
179 shapecombo_->set_active(pos);
181 pos = int(findPos(size_, controller().getSize()));
182 sizecombo_->set_active(pos);
184 pos = int(findPos(bar_, controller().getBar()));
185 misccombo_->set_active(pos);
187 pos = int(findPos(color_, controller().getColor()));
188 colorcombo_->set_active(pos);
190 pos = int(findPos(lang_, controller().getLanguage()));
191 languagecombo_->set_active(pos);
193 toggleallcheck_->set_active(controller().getToggleAll());
197 void GCharacter::onChange()
199 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
201 int pos = familycombo_->get_active_row_number();
202 if (family_[pos] != LyXFont::IGNORE_FAMILY)
203 activate = ButtonPolicy::SMI_VALID;
205 pos = seriescombo_->get_active_row_number();
206 if (series_[pos] != LyXFont::IGNORE_SERIES)
207 activate = ButtonPolicy::SMI_VALID;
209 pos = shapecombo_->get_active_row_number();
210 if (shape_[pos] != LyXFont::IGNORE_SHAPE)
211 activate = ButtonPolicy::SMI_VALID;
213 pos = sizecombo_->get_active_row_number();
214 if (size_[pos] != LyXFont::IGNORE_SIZE)
215 activate = ButtonPolicy::SMI_VALID;
217 pos = misccombo_->get_active_row_number();
218 if (bar_[pos] != IGNORE)
219 activate = ButtonPolicy::SMI_VALID;
221 pos = colorcombo_->get_active_row_number();
222 if (color_[pos] != LColor::ignore)
223 activate = ButtonPolicy::SMI_VALID;
225 pos = languagecombo_->get_active_row_number();
226 if (lang_[pos] != "No change")
227 activate = ButtonPolicy::SMI_VALID;
229 bc().input(activate);
232 } // namespace frontend