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 "forms/form_character.h"
24 #include "helper_funcs.h"
25 #include "xforms_helpers.h"
26 #include FORMS_H_LOCATION
28 #include "frnt_lang.h"
30 #include "support/lstrings.h"
37 typedef FormCB<ControlCharacter, FormDB<FD_character> > base_class;
39 FormCharacter::FormCharacter(ControlCharacter & c)
40 : base_class(c, _("Character Layout"), false)
44 void FormCharacter::ComboInputCB(int, void * v, Combox *)
46 FormCharacter * pre = static_cast<FormCharacter*>(v);
47 // must use input() directly, to avoid treating the Combox
48 // as an FL_OBJECT, leading to a crash (bug 406)
49 pre->bc().input(pre->input(0, 0));
52 void FormCharacter::build()
54 dialog_.reset(build_character(this));
56 vector<FamilyPair> const family = getFamilyData();
57 vector<SeriesPair> const series = getSeriesData();
58 vector<ShapePair> const shape = getShapeData();
59 vector<SizePair> const size = getSizeData();
60 vector<BarPair> const bar = getBarData();
61 vector<ColorPair> const color = getColorData();
62 vector<LanguagePair> const langs = getLanguageData(true);
64 // Store the identifiers for later
65 family_ = getSecond(family);
66 series_ = getSecond(series);
67 shape_ = getSecond(shape);
68 size_ = getSecond(size);
69 bar_ = getSecond(bar);
70 color_ = getSecond(color);
71 lang_ = getSecond(langs);
73 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
74 // with which to initialise the xforms choice object.
75 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
76 fl_addto_choice(dialog_->choice_family, choice.c_str());
78 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
79 fl_addto_choice(dialog_->choice_series, choice.c_str());
81 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
82 fl_addto_choice(dialog_->choice_shape, choice.c_str());
84 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
85 fl_addto_choice(dialog_->choice_size, choice.c_str());
87 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
88 fl_addto_choice(dialog_->choice_bar, choice.c_str());
90 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
91 fl_addto_choice(dialog_->choice_color, choice.c_str());
93 // xforms appears to need this to prevent a crash...
94 fl_addto_choice(dialog_->choice_language, "prevent crash");
96 // insert default language box manually
97 fl_addto_form(dialog_->form);
98 FL_OBJECT * ob = dialog_->choice_language;
99 fl_hide_object(dialog_->choice_language);
101 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
102 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
103 combo_language2_->shortcut("#L", 1);
104 combo_language2_->setcallback(ComboInputCB, this);
107 // build up the combox entries
108 vector<LanguagePair>::const_iterator it = langs.begin();
109 vector<LanguagePair>::const_iterator end = langs.end();
110 for (; it != end; ++it) {
111 combo_language2_->addto(it->first);
113 combo_language2_->select(1);
115 // Manage the ok, apply and cancel/close buttons
116 bc().setApply(dialog_->button_apply);
117 bc().setCancel(dialog_->button_close);
118 bc().addReadOnly(dialog_->check_toggle_all);
122 void FormCharacter::apply()
126 int pos = fl_get_choice(dialog_->choice_family);
127 controller().setFamily(family_[pos-1]);
129 pos = fl_get_choice(dialog_->choice_series);
130 controller().setSeries(series_[pos-1]);
132 pos = fl_get_choice(dialog_->choice_shape);
133 controller().setShape(shape_[pos-1]);
135 pos = fl_get_choice(dialog_->choice_size);
136 controller().setSize(size_[pos-1]);
138 pos = fl_get_choice(dialog_->choice_bar);
139 controller().setBar(bar_[pos-1]);
141 pos = fl_get_choice(dialog_->choice_color);
142 controller().setColor(color_[pos-1]);
144 pos = combo_language2_->get();
145 controller().setLanguage(lang_[pos-1]);
147 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
148 controller().setToggleAll(toggleall);
152 void FormCharacter::update()
154 int pos = int(findPos(family_, controller().getFamily()));
155 fl_set_choice(dialog_->choice_family, pos+1);
157 pos = int(findPos(series_, controller().getSeries()));
158 fl_set_choice(dialog_->choice_series, pos+1);
160 pos = int(findPos(shape_, controller().getShape()));
161 fl_set_choice(dialog_->choice_shape, pos+1);
163 pos = int(findPos(size_, controller().getSize()));
164 fl_set_choice(dialog_->choice_size, pos+1);
166 pos = int(findPos(bar_, controller().getBar()));
167 fl_set_choice(dialog_->choice_bar, pos+1);
169 pos = int(findPos(color_, controller().getColor()));
170 fl_set_choice(dialog_->choice_color, pos+1);
172 pos = int(findPos(lang_, controller().getLanguage()));
173 combo_language2_->select(pos+1);
175 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
179 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
181 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
183 int pos = fl_get_choice(dialog_->choice_family);
184 if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
185 activate = ButtonPolicy::SMI_VALID;
187 pos = fl_get_choice(dialog_->choice_series);
188 if (series_[pos-1] != LyXFont::IGNORE_SERIES)
189 activate = ButtonPolicy::SMI_VALID;
191 pos = fl_get_choice(dialog_->choice_shape);
192 if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
193 activate = ButtonPolicy::SMI_VALID;
195 pos = fl_get_choice(dialog_->choice_size);
196 if (size_[pos-1] != LyXFont::IGNORE_SIZE)
197 activate = ButtonPolicy::SMI_VALID;
199 pos = fl_get_choice(dialog_->choice_bar);
200 if (bar_[pos-1] != frnt::IGNORE)
201 activate = ButtonPolicy::SMI_VALID;
203 pos = fl_get_choice(dialog_->choice_color);
204 if (color_[pos-1] != LColor::ignore)
205 activate = ButtonPolicy::SMI_VALID;
207 pos = combo_language2_->get();
208 if (lang_[pos-1] != "No change")
209 activate = ButtonPolicy::SMI_VALID;