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 // must use input() directly, to avoid treating the Combox
46 // as an FL_OBJECT, leading to a crash (bug 406)
47 pre->bc().input(pre->input(0, 0));
50 void FormCharacter::build()
52 dialog_.reset(build_character());
54 vector<FamilyPair> const family = getFamilyData();
55 vector<SeriesPair> const series = getSeriesData();
56 vector<ShapePair> const shape = getShapeData();
57 vector<SizePair> const size = getSizeData();
58 vector<BarPair> const bar = getBarData();
59 vector<ColorPair> const color = getColorData();
60 vector<LanguagePair> const langs = getLanguageData(true);
62 // Store the identifiers for later
63 family_ = getSecond(family);
64 series_ = getSecond(series);
65 shape_ = getSecond(shape);
66 size_ = getSecond(size);
67 bar_ = getSecond(bar);
68 color_ = getSecond(color);
69 lang_ = getSecond(langs);
71 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
72 // with which to initialise the xforms choice object.
73 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
74 fl_addto_choice(dialog_->choice_family, choice.c_str());
76 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
77 fl_addto_choice(dialog_->choice_series, choice.c_str());
79 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
80 fl_addto_choice(dialog_->choice_shape, choice.c_str());
82 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
83 fl_addto_choice(dialog_->choice_size, choice.c_str());
85 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
86 fl_addto_choice(dialog_->choice_bar, choice.c_str());
88 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
89 fl_addto_choice(dialog_->choice_color, choice.c_str());
91 // xforms appears to need this to prevent a crash...
92 fl_addto_choice(dialog_->choice_language, "prevent crash");
94 // insert default language box manually
95 fl_addto_form(dialog_->form);
96 FL_OBJECT * ob = dialog_->choice_language;
97 fl_hide_object(dialog_->choice_language);
99 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
100 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
101 combo_language2_->shortcut("#L", 1);
102 combo_language2_->setcallback(ComboInputCB, this);
105 // build up the combox entries
106 vector<LanguagePair>::const_iterator it = langs.begin();
107 vector<LanguagePair>::const_iterator end = langs.end();
108 for (; it != end; ++it) {
109 combo_language2_->addto(it->first);
111 combo_language2_->select(1);
113 // Manage the ok, apply and cancel/close buttons
114 bc().setApply(dialog_->button_apply);
115 bc().setCancel(dialog_->button_close);
116 bc().addReadOnly(dialog_->check_toggle_all);
120 void FormCharacter::apply()
124 int pos = fl_get_choice(dialog_->choice_family);
125 controller().setFamily(family_[pos-1]);
127 pos = fl_get_choice(dialog_->choice_series);
128 controller().setSeries(series_[pos-1]);
130 pos = fl_get_choice(dialog_->choice_shape);
131 controller().setShape(shape_[pos-1]);
133 pos = fl_get_choice(dialog_->choice_size);
134 controller().setSize(size_[pos-1]);
136 pos = fl_get_choice(dialog_->choice_bar);
137 controller().setBar(bar_[pos-1]);
139 pos = fl_get_choice(dialog_->choice_color);
140 controller().setColor(color_[pos-1]);
142 pos = combo_language2_->get();
143 controller().setLanguage(lang_[pos-1]);
145 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
146 controller().setToggleAll(toggleall);
150 void FormCharacter::update()
152 int pos = int(findPos(family_, controller().getFamily()));
153 fl_set_choice(dialog_->choice_family, pos+1);
155 pos = int(findPos(series_, controller().getSeries()));
156 fl_set_choice(dialog_->choice_series, pos+1);
158 pos = int(findPos(shape_, controller().getShape()));
159 fl_set_choice(dialog_->choice_shape, pos+1);
161 pos = int(findPos(size_, controller().getSize()));
162 fl_set_choice(dialog_->choice_size, pos+1);
164 pos = int(findPos(bar_, controller().getBar()));
165 fl_set_choice(dialog_->choice_bar, pos+1);
167 pos = int(findPos(color_, controller().getColor()));
168 fl_set_choice(dialog_->choice_color, pos+1);
170 pos = int(findPos(lang_, controller().getLanguage()));
171 combo_language2_->select(pos+1);
173 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
177 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
179 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
181 int pos = fl_get_choice(dialog_->choice_family);
182 if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
183 activate = ButtonPolicy::SMI_VALID;
185 pos = fl_get_choice(dialog_->choice_series);
186 if (series_[pos-1] != LyXFont::IGNORE_SERIES)
187 activate = ButtonPolicy::SMI_VALID;
189 pos = fl_get_choice(dialog_->choice_shape);
190 if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
191 activate = ButtonPolicy::SMI_VALID;
193 pos = fl_get_choice(dialog_->choice_size);
194 if (size_[pos-1] != LyXFont::IGNORE_SIZE)
195 activate = ButtonPolicy::SMI_VALID;
197 pos = fl_get_choice(dialog_->choice_bar);
198 if (bar_[pos-1] != frnt::IGNORE)
199 activate = ButtonPolicy::SMI_VALID;
201 pos = fl_get_choice(dialog_->choice_color);
202 if (color_[pos-1] != LColor::ignore)
203 activate = ButtonPolicy::SMI_VALID;
205 pos = combo_language2_->get();
206 if (lang_[pos-1] != "No change")
207 activate = ButtonPolicy::SMI_VALID;