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.
14 #include "FormCharacter.h"
15 #include "forms/form_character.h"
17 #include "xforms_helpers.h"
20 #include "controllers/frnt_lang.h"
21 #include "controllers/helper_funcs.h"
23 #include "support/lstrings.h"
25 #include "lyx_forms.h"
33 using support::getStringFromVector;
38 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
40 FormCharacter::FormCharacter(Dialog & parent)
41 : base_class(parent, _("Text Style"), false)
45 void FormCharacter::build()
47 dialog_.reset(build_character(this));
49 vector<FamilyPair> const family = getFamilyData();
50 vector<SeriesPair> const series = getSeriesData();
51 vector<ShapePair> const shape = getShapeData();
52 vector<SizePair> const size = getSizeData();
53 vector<BarPair> const bar = getBarData();
54 vector<ColorPair> const color = getColorData();
55 vector<LanguagePair> const langs = getLanguageData(true);
57 // Store the identifiers for later
58 family_ = getSecond(family);
59 series_ = getSecond(series);
60 shape_ = getSecond(shape);
61 size_ = getSecond(size);
62 bar_ = getSecond(bar);
63 color_ = getSecond(color);
64 lang_ = getSecond(langs);
66 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
67 // with which to initialise the xforms choice object.
68 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
69 fl_addto_choice(dialog_->choice_family, choice.c_str());
71 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
72 fl_addto_choice(dialog_->choice_series, choice.c_str());
74 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
75 fl_addto_choice(dialog_->choice_shape, choice.c_str());
77 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
78 fl_addto_choice(dialog_->choice_size, choice.c_str());
80 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
81 fl_addto_choice(dialog_->choice_bar, choice.c_str());
83 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
84 fl_addto_choice(dialog_->choice_color, choice.c_str());
86 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
87 fl_addto_combox(dialog_->combox_language, choice.c_str());
88 fl_set_combox_browser_height(dialog_->combox_language, 250);
90 // Manage the ok, apply and cancel/close buttons
91 bcview().setApply(dialog_->button_apply);
92 bcview().setCancel(dialog_->button_close);
93 bcview().addReadOnly(dialog_->check_toggle_all);
97 void FormCharacter::apply()
101 int pos = fl_get_choice(dialog_->choice_family);
102 controller().setFamily(family_[pos - 1]);
104 pos = fl_get_choice(dialog_->choice_series);
105 controller().setSeries(series_[pos - 1]);
107 pos = fl_get_choice(dialog_->choice_shape);
108 controller().setShape(shape_[pos - 1]);
110 pos = fl_get_choice(dialog_->choice_size);
111 controller().setSize(size_[pos - 1]);
113 pos = fl_get_choice(dialog_->choice_bar);
114 controller().setBar(bar_[pos - 1]);
116 pos = fl_get_choice(dialog_->choice_color);
117 controller().setColor(color_[pos - 1]);
119 pos = fl_get_combox(dialog_->combox_language);
120 controller().setLanguage(lang_[pos - 1]);
122 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
123 controller().setToggleAll(toggleall);
127 void FormCharacter::update()
129 int pos = int(findPos(family_, controller().getFamily()));
130 fl_set_choice(dialog_->choice_family, pos+1);
132 pos = int(findPos(series_, controller().getSeries()));
133 fl_set_choice(dialog_->choice_series, pos+1);
135 pos = int(findPos(shape_, controller().getShape()));
136 fl_set_choice(dialog_->choice_shape, pos+1);
138 pos = int(findPos(size_, controller().getSize()));
139 fl_set_choice(dialog_->choice_size, pos+1);
141 pos = int(findPos(bar_, controller().getBar()));
142 fl_set_choice(dialog_->choice_bar, pos+1);
144 pos = int(findPos(color_, controller().getColor()));
145 fl_set_choice(dialog_->choice_color, pos+1);
147 pos = int(findPos(lang_, controller().getLanguage()));
148 fl_set_combox(dialog_->combox_language, pos+1);
150 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
154 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
156 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
158 int pos = fl_get_choice(dialog_->choice_family);
159 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
160 activate = ButtonPolicy::SMI_VALID;
162 pos = fl_get_choice(dialog_->choice_series);
163 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
164 activate = ButtonPolicy::SMI_VALID;
166 pos = fl_get_choice(dialog_->choice_shape);
167 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
168 activate = ButtonPolicy::SMI_VALID;
170 pos = fl_get_choice(dialog_->choice_size);
171 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
172 activate = ButtonPolicy::SMI_VALID;
174 pos = fl_get_choice(dialog_->choice_bar);
175 if (bar_[pos - 1] != IGNORE)
176 activate = ButtonPolicy::SMI_VALID;
178 pos = fl_get_choice(dialog_->choice_color);
179 if (color_[pos - 1] != LColor::ignore)
180 activate = ButtonPolicy::SMI_VALID;
182 pos = fl_get_combox(dialog_->combox_language);
183 if (lang_[pos - 1] != "No change")
184 activate = ButtonPolicy::SMI_VALID;
189 } // namespace frontend