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