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 "xforms_helpers.h"
26 #include "frnt_lang.h"
28 #include "support/lstrings.h"
35 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
37 FormCharacter::FormCharacter(ControlCharacter & c)
38 : base_class(c, _("Character Layout"), false)
42 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
44 FormCharacter * pre = static_cast<FormCharacter*>(v);
45 pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
48 void FormCharacter::build()
50 dialog_.reset(build_character());
52 vector<FamilyPair> const family = getFamilyData();
53 vector<SeriesPair> const series = getSeriesData();
54 vector<ShapePair> const shape = getShapeData();
55 vector<SizePair> const size = getSizeData();
56 vector<BarPair> const bar = getBarData();
57 vector<ColorPair> const color = getColorData();
58 vector<LanguagePair> const langs = getLanguageData(true);
60 // Store the identifiers for later
61 family_ = getSecond(family);
62 series_ = getSecond(series);
63 shape_ = getSecond(shape);
64 size_ = getSecond(size);
65 bar_ = getSecond(bar);
66 color_ = getSecond(color);
67 lang_ = getSecond(langs);
69 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
70 // with which to initialise the xforms choice object.
71 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
72 fl_addto_choice(dialog_->choice_family, choice.c_str());
74 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
75 fl_addto_choice(dialog_->choice_series, choice.c_str());
77 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
78 fl_addto_choice(dialog_->choice_shape, choice.c_str());
80 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
81 fl_addto_choice(dialog_->choice_size, choice.c_str());
83 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
84 fl_addto_choice(dialog_->choice_bar, choice.c_str());
86 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
87 fl_addto_choice(dialog_->choice_color, choice.c_str());
89 // xforms appears to need this to prevent a crash...
90 fl_addto_choice(dialog_->choice_language, "prevent crash");
92 // insert default language box manually
93 fl_addto_form(dialog_->form);
94 FL_OBJECT * ob = dialog_->choice_language;
95 fl_hide_object(dialog_->choice_language);
97 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
98 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
99 combo_language2_->shortcut("#L", 1);
100 combo_language2_->setcallback(ComboInputCB, this);
103 // build up the combox entries
104 vector<LanguagePair>::const_iterator it = langs.begin();
105 vector<LanguagePair>::const_iterator end = langs.end();
106 for (; it != end; ++it) {
107 combo_language2_->addto(it->first);
109 combo_language2_->select(1);
111 // Manage the ok, apply and cancel/close buttons
112 bc().setApply(dialog_->button_apply);
113 bc().setCancel(dialog_->button_close);
114 bc().addReadOnly(dialog_->check_toggle_all);
118 void FormCharacter::apply()
122 int pos = fl_get_choice(dialog_->choice_family);
123 controller().setFamily(family_[pos-1]);
125 pos = fl_get_choice(dialog_->choice_series);
126 controller().setSeries(series_[pos-1]);
128 pos = fl_get_choice(dialog_->choice_shape);
129 controller().setShape(shape_[pos-1]);
131 pos = fl_get_choice(dialog_->choice_size);
132 controller().setSize(size_[pos-1]);
134 pos = fl_get_choice(dialog_->choice_bar);
135 controller().setBar(bar_[pos-1]);
137 pos = fl_get_choice(dialog_->choice_color);
138 controller().setColor(color_[pos-1]);
140 pos = combo_language2_->get();
141 controller().setLanguage(lang_[pos-1]);
143 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
144 controller().setToggleAll(toggleall);
148 void FormCharacter::update()
150 int pos = int(findPos(family_, controller().getFamily()));
151 fl_set_choice(dialog_->choice_family, pos+1);
153 pos = int(findPos(series_, controller().getSeries()));
154 fl_set_choice(dialog_->choice_series, pos+1);
156 pos = int(findPos(shape_, controller().getShape()));
157 fl_set_choice(dialog_->choice_shape, pos+1);
159 pos = int(findPos(size_, controller().getSize()));
160 fl_set_choice(dialog_->choice_size, pos+1);
162 pos = int(findPos(bar_, controller().getBar()));
163 fl_set_choice(dialog_->choice_bar, pos+1);
165 pos = int(findPos(color_, controller().getColor()));
166 fl_set_choice(dialog_->choice_color, pos+1);
168 pos = int(findPos(lang_, controller().getLanguage()));
169 combo_language2_->select(pos+1);
171 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
175 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
177 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
179 int pos = fl_get_choice(dialog_->choice_family);
180 if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
181 activate = ButtonPolicy::SMI_VALID;
183 pos = fl_get_choice(dialog_->choice_series);
184 if (series_[pos-1] != LyXFont::IGNORE_SERIES)
185 activate = ButtonPolicy::SMI_VALID;
187 pos = fl_get_choice(dialog_->choice_shape);
188 if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
189 activate = ButtonPolicy::SMI_VALID;
191 pos = fl_get_choice(dialog_->choice_size);
192 if (size_[pos-1] != LyXFont::IGNORE_SIZE)
193 activate = ButtonPolicy::SMI_VALID;
195 pos = fl_get_choice(dialog_->choice_bar);
196 if (bar_[pos-1] != frnt::IGNORE)
197 activate = ButtonPolicy::SMI_VALID;
199 pos = fl_get_choice(dialog_->choice_color);
200 if (color_[pos-1] != LColor::ignore)
201 activate = ButtonPolicy::SMI_VALID;
203 pos = combo_language2_->get();
204 if (lang_[pos-1] != "No change")
205 activate = ButtonPolicy::SMI_VALID;