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"
25 #include "frnt_lang.h"
27 #include "support/lstrings.h"
34 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
36 FormCharacter::FormCharacter(ControlCharacter & c)
37 : base_class(c, _("Character Layout"), false)
41 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
43 FormCharacter * pre = static_cast<FormCharacter*>(v);
44 pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
47 void FormCharacter::build()
49 dialog_.reset(build_character());
51 vector<FamilyPair> const family = getFamilyData();
52 vector<SeriesPair> const series = getSeriesData();
53 vector<ShapePair> const shape = getShapeData();
54 vector<SizePair> const size = getSizeData();
55 vector<BarPair> const bar = getBarData();
56 vector<ColorPair> const color = getColorData();
57 vector<LanguagePair> const langs = getLanguageData(true);
59 // Store the identifiers for later
60 family_ = getSecond(family);
61 series_ = getSecond(series);
62 shape_ = getSecond(shape);
63 size_ = getSecond(size);
64 bar_ = getSecond(bar);
65 color_ = getSecond(color);
66 lang_ = getSecond(langs);
68 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
69 // with which to initialise the xforms choice object.
70 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
71 fl_addto_choice(dialog_->choice_family, choice.c_str());
73 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
74 fl_addto_choice(dialog_->choice_series, choice.c_str());
76 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
77 fl_addto_choice(dialog_->choice_shape, choice.c_str());
79 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
80 fl_addto_choice(dialog_->choice_size, choice.c_str());
82 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
83 fl_addto_choice(dialog_->choice_bar, choice.c_str());
85 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
86 fl_addto_choice(dialog_->choice_color, choice.c_str());
88 // xforms appears to need this to prevent a crash...
89 fl_addto_choice(dialog_->choice_language, "prevent crash");
91 // insert default language box manually
92 fl_addto_form(dialog_->form);
93 FL_OBJECT * ob = dialog_->choice_language;
94 fl_hide_object(dialog_->choice_language);
96 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
97 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
98 combo_language2_->shortcut("#L", 1);
99 combo_language2_->setcallback(ComboInputCB, this);
102 // build up the combox entries
103 vector<LanguagePair>::const_iterator it = langs.begin();
104 vector<LanguagePair>::const_iterator end = langs.end();
105 for (; it != end; ++it) {
106 combo_language2_->addto(it->first);
108 combo_language2_->select(1);
110 // Manage the ok, apply and cancel/close buttons
111 bc().setApply(dialog_->button_apply);
112 bc().setCancel(dialog_->button_close);
113 bc().addReadOnly(dialog_->check_toggle_all);
117 void FormCharacter::apply()
121 int pos = fl_get_choice(dialog_->choice_family);
122 controller().setFamily(family_[pos-1]);
124 pos = fl_get_choice(dialog_->choice_series);
125 controller().setSeries(series_[pos-1]);
127 pos = fl_get_choice(dialog_->choice_shape);
128 controller().setShape(shape_[pos-1]);
130 pos = fl_get_choice(dialog_->choice_size);
131 controller().setSize(size_[pos-1]);
133 pos = fl_get_choice(dialog_->choice_bar);
134 controller().setBar(bar_[pos-1]);
136 pos = fl_get_choice(dialog_->choice_color);
137 controller().setColor(color_[pos-1]);
139 pos = combo_language2_->get();
140 controller().setLanguage(lang_[pos-1]);
142 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
143 controller().setToggleAll(toggleall);
150 typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
152 typename vector<A>::const_iterator it =
153 find(vec.begin(), vec.end(), val);
156 return it - vec.begin();
162 void FormCharacter::update()
164 int pos = int(findPos(family_, controller().getFamily()));
165 fl_set_choice(dialog_->choice_family, pos+1);
167 pos = int(findPos(series_, controller().getSeries()));
168 fl_set_choice(dialog_->choice_series, pos+1);
170 pos = int(findPos(shape_, controller().getShape()));
171 fl_set_choice(dialog_->choice_shape, pos+1);
173 pos = int(findPos(size_, controller().getSize()));
174 fl_set_choice(dialog_->choice_size, pos+1);
176 pos = int(findPos(bar_, controller().getBar()));
177 fl_set_choice(dialog_->choice_bar, pos+1);
179 pos = int(findPos(color_, controller().getColor()));
180 fl_set_choice(dialog_->choice_color, pos+1);
182 pos = int(findPos(lang_, controller().getLanguage()));
183 combo_language2_->select(pos+1);
185 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
189 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
191 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
193 int pos = fl_get_choice(dialog_->choice_family);
194 if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
195 activate = ButtonPolicy::SMI_VALID;
197 pos = fl_get_choice(dialog_->choice_series);
198 if (series_[pos-1] != LyXFont::IGNORE_SERIES)
199 activate = ButtonPolicy::SMI_VALID;
201 pos = fl_get_choice(dialog_->choice_shape);
202 if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
203 activate = ButtonPolicy::SMI_VALID;
205 pos = fl_get_choice(dialog_->choice_size);
206 if (size_[pos-1] != LyXFont::IGNORE_SIZE)
207 activate = ButtonPolicy::SMI_VALID;
209 pos = fl_get_choice(dialog_->choice_bar);
210 if (bar_[pos-1] != frnt::IGNORE)
211 activate = ButtonPolicy::SMI_VALID;
213 pos = fl_get_choice(dialog_->choice_color);
214 if (color_[pos-1] != LColor::ignore)
215 activate = ButtonPolicy::SMI_VALID;
217 pos = combo_language2_->get();
218 if (lang_[pos-1] != "No change")
219 activate = ButtonPolicy::SMI_VALID;