]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GCharacter.C
fix math fonts with LyX/Mac
[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 #include "GCharacter.h"
14 #include "ghelpers.h"
15 #include "LColor.h"
16
17 #include "controllers/frnt_lang.h"
18 #include "controllers/helper_funcs.h"
19
20 #include "support/lstrings.h"
21
22 #include <libglademm.h>
23
24 using std::vector;
25 using std::string;
26
27 namespace lyx {
28 namespace frontend {
29
30
31 GCharacter::GCharacter(Dialog & parent)
32         : GViewCB<ControlCharacter, GViewGladeB>(parent, _("Text Style"), false)
33 {}
34
35
36 void GCharacter::PopulateComboBox(Gtk::ComboBox * combo,
37                                   vector<string> const & strings)
38 {
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;
44
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);
49 }
50
51
52 void GCharacter::doBuild()
53 {
54         string const gladeName = findGladeFile("character");
55         xml_ = Gnome::Glade::Xml::create(gladeName);
56         Gtk::Button * button;
57
58         // Manage the ok, apply and cancel/close buttons
59         xml_->get_widget("Ok", button);
60         setOK(button);
61         xml_->get_widget("Apply", button);
62         setApply(button);
63         xml_->get_widget("Cancel", button);
64         setCancel(button);
65
66         xml_->get_widget("ToggleAll", toggleallcheck_);
67
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_);
76
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_);
86
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);
95
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);
104
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));
115
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);
121
122         // We have to update *before* the signals are connected
123         update();
124
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));
139 }
140
141
142 void GCharacter::apply()
143 {
144         int pos = familycombo_->get_active_row_number();
145         controller().setFamily(family_[pos]);
146
147         pos = seriescombo_->get_active_row_number();
148         controller().setSeries(series_[pos]);
149
150         pos = shapecombo_->get_active_row_number();
151         controller().setShape(shape_[pos]);
152
153         pos = sizecombo_->get_active_row_number();
154         controller().setSize(size_[pos]);
155
156         pos = misccombo_->get_active_row_number();
157         controller().setBar(bar_[pos]);
158
159         pos = colorcombo_->get_active_row_number();
160         controller().setColor(color_[pos]);
161
162         pos = languagecombo_->get_active_row_number();
163         controller().setLanguage(lang_[pos]);
164
165         bool const toggleall = toggleallcheck_->get_active();
166         controller().setToggleAll(toggleall);
167 }
168
169
170 void GCharacter::update()
171 {
172         int pos = int(findPos(family_, controller().getFamily()));
173         familycombo_->set_active(pos);
174
175         pos = int(findPos(series_, controller().getSeries()));
176         seriescombo_->set_active(pos);
177
178         pos = int(findPos(shape_, controller().getShape()));
179         shapecombo_->set_active(pos);
180
181         pos = int(findPos(size_, controller().getSize()));
182         sizecombo_->set_active(pos);
183
184         pos = int(findPos(bar_, controller().getBar()));
185         misccombo_->set_active(pos);
186
187         pos = int(findPos(color_, controller().getColor()));
188         colorcombo_->set_active(pos);
189
190         pos = int(findPos(lang_, controller().getLanguage()));
191         languagecombo_->set_active(pos);
192
193         toggleallcheck_->set_active(controller().getToggleAll());
194 }
195
196
197 void GCharacter::onChange()
198 {
199         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
200
201         int pos = familycombo_->get_active_row_number();
202         if (family_[pos] != LyXFont::IGNORE_FAMILY)
203                 activate = ButtonPolicy::SMI_VALID;
204
205         pos = seriescombo_->get_active_row_number();
206         if (series_[pos] != LyXFont::IGNORE_SERIES)
207                 activate = ButtonPolicy::SMI_VALID;
208
209         pos = shapecombo_->get_active_row_number();
210         if (shape_[pos] != LyXFont::IGNORE_SHAPE)
211                 activate = ButtonPolicy::SMI_VALID;
212
213         pos = sizecombo_->get_active_row_number();
214         if (size_[pos] != LyXFont::IGNORE_SIZE)
215                 activate = ButtonPolicy::SMI_VALID;
216
217         pos =  misccombo_->get_active_row_number();
218         if (bar_[pos] != IGNORE)
219                 activate = ButtonPolicy::SMI_VALID;
220
221         pos = colorcombo_->get_active_row_number();
222         if (color_[pos] != LColor::ignore)
223                 activate = ButtonPolicy::SMI_VALID;
224
225         pos = languagecombo_->get_active_row_number();
226         if (lang_[pos] != "No change")
227                 activate = ButtonPolicy::SMI_VALID;
228
229         bc().input(activate);
230 }
231
232 } // namespace frontend
233 } // namespace lyx