2 * \file FormCharacter.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
21 #include "ControlCharacter.h"
22 #include "FormCharacter.h"
23 #include "forms/form_character.h"
26 #include "helper_funcs.h"
27 #include "xforms_helpers.h"
28 #include FORMS_H_LOCATION
30 #include "frnt_lang.h"
32 #include "support/lstrings.h"
39 typedef FormCB<ControlCharacter, FormDB<FD_character> > base_class;
41 FormCharacter::FormCharacter()
42 : base_class(_("Character Layout"), false)
46 void FormCharacter::ComboInputCB(int, void * v, Combox *)
48 FormCharacter * pre = static_cast<FormCharacter*>(v);
49 // must use input() directly, to avoid treating the Combox
50 // as an FL_OBJECT, leading to a crash (bug 406)
51 pre->bc().input(pre->input(0, 0));
54 void FormCharacter::build()
56 dialog_.reset(build_character(this));
58 vector<FamilyPair> const family = getFamilyData();
59 vector<SeriesPair> const series = getSeriesData();
60 vector<ShapePair> const shape = getShapeData();
61 vector<SizePair> const size = getSizeData();
62 vector<BarPair> const bar = getBarData();
63 vector<ColorPair> const color = getColorData();
64 vector<LanguagePair> const langs = getLanguageData(true);
66 // Store the identifiers for later
67 family_ = getSecond(family);
68 series_ = getSecond(series);
69 shape_ = getSecond(shape);
70 size_ = getSecond(size);
71 bar_ = getSecond(bar);
72 color_ = getSecond(color);
73 lang_ = getSecond(langs);
75 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
76 // with which to initialise the xforms choice object.
77 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
78 fl_addto_choice(dialog_->choice_family, choice.c_str());
80 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
81 fl_addto_choice(dialog_->choice_series, choice.c_str());
83 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
84 fl_addto_choice(dialog_->choice_shape, choice.c_str());
86 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
87 fl_addto_choice(dialog_->choice_size, choice.c_str());
89 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
90 fl_addto_choice(dialog_->choice_bar, choice.c_str());
92 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
93 fl_addto_choice(dialog_->choice_color, choice.c_str());
95 // xforms appears to need this to prevent a crash...
96 fl_addto_choice(dialog_->choice_language, "prevent crash");
98 // insert default language box manually
99 fl_addto_form(dialog_->form);
100 FL_OBJECT * ob = dialog_->choice_language;
101 fl_hide_object(dialog_->choice_language);
103 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
104 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
105 combo_language2_->shortcut("#L", 1);
106 combo_language2_->setcallback(ComboInputCB, this);
109 // build up the combox entries
110 vector<LanguagePair>::const_iterator it = langs.begin();
111 vector<LanguagePair>::const_iterator end = langs.end();
112 for (; it != end; ++it) {
113 combo_language2_->addto(it->first);
115 combo_language2_->select(1);
117 // Manage the ok, apply and cancel/close buttons
118 bc().setApply(dialog_->button_apply);
119 bc().setCancel(dialog_->button_close);
120 bc().addReadOnly(dialog_->check_toggle_all);
124 void FormCharacter::apply()
128 int pos = fl_get_choice(dialog_->choice_family);
129 controller().setFamily(family_[pos - 1]);
131 pos = fl_get_choice(dialog_->choice_series);
132 controller().setSeries(series_[pos - 1]);
134 pos = fl_get_choice(dialog_->choice_shape);
135 controller().setShape(shape_[pos - 1]);
137 pos = fl_get_choice(dialog_->choice_size);
138 controller().setSize(size_[pos - 1]);
140 pos = fl_get_choice(dialog_->choice_bar);
141 controller().setBar(bar_[pos - 1]);
143 pos = fl_get_choice(dialog_->choice_color);
144 controller().setColor(color_[pos - 1]);
146 pos = combo_language2_->get();
147 controller().setLanguage(lang_[pos - 1]);
149 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
150 controller().setToggleAll(toggleall);
154 void FormCharacter::update()
156 int pos = int(findPos(family_, controller().getFamily()));
157 fl_set_choice(dialog_->choice_family, pos+1);
159 pos = int(findPos(series_, controller().getSeries()));
160 fl_set_choice(dialog_->choice_series, pos+1);
162 pos = int(findPos(shape_, controller().getShape()));
163 fl_set_choice(dialog_->choice_shape, pos+1);
165 pos = int(findPos(size_, controller().getSize()));
166 fl_set_choice(dialog_->choice_size, pos+1);
168 pos = int(findPos(bar_, controller().getBar()));
169 fl_set_choice(dialog_->choice_bar, pos+1);
171 pos = int(findPos(color_, controller().getColor()));
172 fl_set_choice(dialog_->choice_color, pos+1);
174 pos = int(findPos(lang_, controller().getLanguage()));
175 combo_language2_->select(pos+1);
177 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
181 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
183 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
185 int pos = fl_get_choice(dialog_->choice_family);
186 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
187 activate = ButtonPolicy::SMI_VALID;
189 pos = fl_get_choice(dialog_->choice_series);
190 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
191 activate = ButtonPolicy::SMI_VALID;
193 pos = fl_get_choice(dialog_->choice_shape);
194 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
195 activate = ButtonPolicy::SMI_VALID;
197 pos = fl_get_choice(dialog_->choice_size);
198 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
199 activate = ButtonPolicy::SMI_VALID;
201 pos = fl_get_choice(dialog_->choice_bar);
202 if (bar_[pos - 1] != frnt::IGNORE)
203 activate = ButtonPolicy::SMI_VALID;
205 pos = fl_get_choice(dialog_->choice_color);
206 if (color_[pos - 1] != LColor::ignore)
207 activate = ButtonPolicy::SMI_VALID;
209 pos = combo_language2_->get();
210 if (lang_[pos - 1] != "No change")
211 activate = ButtonPolicy::SMI_VALID;