2 * \file FormCharacter.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Edwin Leuven, leuven@fee.uva.nl
7 * \author Angus Leeming, a.leeming@ic.ac.uk
13 #pragma implementation
19 #include "ControlCharacter.h"
20 #include "FormCharacter.h"
21 #include "form_character.h"
24 #include "helper_funcs.h"
26 #include "support/lstrings.h"
31 using namespace character;
33 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
35 FormCharacter::FormCharacter(ControlCharacter & c)
36 : base_class(c, _("Character Layout"), false)
40 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
42 FormCharacter * pre = static_cast<FormCharacter*>(v);
43 pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
46 void FormCharacter::build()
48 dialog_.reset(build_character());
50 vector<FamilyPair> const family = getFamilyData();
51 vector<SeriesPair> const series = getSeriesData();
52 vector<ShapePair> const shape = getShapeData();
53 vector<SizePair> const size = getSizeData();
54 vector<BarPair> const bar = getBarData();
55 vector<ColorPair> const color = getColorData();
56 vector<LanguagePair> const language = getLanguageData();
58 // Store the identifiers for later
59 family_ = getSecond(family);
60 series_ = getSecond(series);
61 shape_ = getSecond(shape);
62 size_ = getSecond(size);
63 bar_ = getSecond(bar);
64 color_ = getSecond(color);
65 lang_ = getSecond(language);
67 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
68 // with which to initialise the xforms choice object.
69 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
70 fl_addto_choice(dialog_->choice_family, choice.c_str());
72 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
73 fl_addto_choice(dialog_->choice_series, choice.c_str());
75 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
76 fl_addto_choice(dialog_->choice_shape, choice.c_str());
78 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
79 fl_addto_choice(dialog_->choice_size, choice.c_str());
81 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
82 fl_addto_choice(dialog_->choice_bar, choice.c_str());
84 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
85 fl_addto_choice(dialog_->choice_color, choice.c_str());
87 // xforms appears to need this to prevent a crash...
88 fl_addto_choice(dialog_->choice_language, "prevent crash");
90 // insert default language box manually
91 fl_addto_form(dialog_->form);
92 FL_OBJECT * ob = dialog_->choice_language;
93 fl_hide_object(dialog_->choice_language);
95 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
96 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
97 combo_language2_->shortcut("#L", 1);
98 combo_language2_->setcallback(ComboInputCB, this);
101 // build up the combox entries
102 for (vector<LanguagePair>::const_iterator cit = language.begin();
103 cit != language.end(); ++cit) {
104 combo_language2_->addto(_(cit->first));
106 combo_language2_->select(1);
108 // Manage the ok, apply and cancel/close buttons
109 bc().setApply(dialog_->button_apply);
110 bc().setCancel(dialog_->button_close);
111 bc().addReadOnly(dialog_->check_toggle_all);
115 void FormCharacter::apply()
119 int pos = fl_get_choice(dialog_->choice_family);
120 controller().setFamily(family_[pos-1]);
122 pos = fl_get_choice(dialog_->choice_series);
123 controller().setSeries(series_[pos-1]);
125 pos = fl_get_choice(dialog_->choice_shape);
126 controller().setShape(shape_[pos-1]);
128 pos = fl_get_choice(dialog_->choice_size);
129 controller().setSize(size_[pos-1]);
131 pos = fl_get_choice(dialog_->choice_bar);
132 controller().setBar(bar_[pos-1]);
134 pos = fl_get_choice(dialog_->choice_color);
135 controller().setColor(color_[pos-1]);
137 pos = combo_language2_->get();
138 controller().setLanguage(lang_[pos-1]);
140 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
141 controller().setToggleAll(toggleall);
148 typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
150 typename vector<A>::const_iterator it =
151 find(vec.begin(), vec.end(), val);
154 return it - vec.begin();
160 void FormCharacter::update()
162 int pos = int(findPos(family_, controller().getFamily()));
163 fl_set_choice(dialog_->choice_family, pos+1);
165 pos = int(findPos(series_, controller().getSeries()));
166 fl_set_choice(dialog_->choice_series, pos+1);
168 pos = int(findPos(shape_, controller().getShape()));
169 fl_set_choice(dialog_->choice_shape, pos+1);
171 pos = int(findPos(size_, controller().getSize()));
172 fl_set_choice(dialog_->choice_size, pos+1);
174 pos = int(findPos(bar_, controller().getBar()));
175 fl_set_choice(dialog_->choice_bar, pos+1);
177 pos = int(findPos(color_, controller().getColor()));
178 fl_set_choice(dialog_->choice_color, pos+1);
180 pos = int(findPos(lang_, controller().getLanguage()));
181 combo_language2_->select(pos+1);
183 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
187 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
189 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
191 int pos = fl_get_choice(dialog_->choice_family);
192 if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
193 activate = ButtonPolicy::SMI_VALID;
195 pos = fl_get_choice(dialog_->choice_series);
196 if (series_[pos-1] != LyXFont::IGNORE_SERIES)
197 activate = ButtonPolicy::SMI_VALID;
199 pos = fl_get_choice(dialog_->choice_shape);
200 if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
201 activate = ButtonPolicy::SMI_VALID;
203 pos = fl_get_choice(dialog_->choice_size);
204 if (size_[pos-1] != LyXFont::IGNORE_SIZE)
205 activate = ButtonPolicy::SMI_VALID;
207 pos = fl_get_choice(dialog_->choice_bar);
208 if (bar_[pos-1] != character::IGNORE)
209 activate = ButtonPolicy::SMI_VALID;
211 pos = fl_get_choice(dialog_->choice_color);
212 if (color_[pos-1] != LColor::ignore)
213 activate = ButtonPolicy::SMI_VALID;
215 pos = combo_language2_->get();
216 if (lang_[pos-1] != "No change")
217 activate = ButtonPolicy::SMI_VALID;