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"
25 #include "support/lstrings.h"
27 #include "lyx_forms.h"
31 using frnt::ColorPair;
32 using frnt::FamilyPair;
33 using frnt::getBarData;
34 using frnt::getColorData;
35 using frnt::getFamilyData;
36 using frnt::getLanguageData;
37 using frnt::getSeriesData;
38 using frnt::getShapeData;
39 using frnt::getSizeData;
40 using frnt::LanguagePair;
41 using frnt::SeriesPair;
42 using frnt::ShapePair;
45 using lyx::support::getStringFromVector;
50 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
52 FormCharacter::FormCharacter(Dialog & parent)
53 : base_class(parent, _("Text Style"), false)
57 void FormCharacter::build()
59 dialog_.reset(build_character(this));
61 vector<FamilyPair> const family = getFamilyData();
62 vector<SeriesPair> const series = getSeriesData();
63 vector<ShapePair> const shape = getShapeData();
64 vector<SizePair> const size = getSizeData();
65 vector<BarPair> const bar = getBarData();
66 vector<ColorPair> const color = getColorData();
67 vector<LanguagePair> const langs = getLanguageData(true);
69 // Store the identifiers for later
70 family_ = getSecond(family);
71 series_ = getSecond(series);
72 shape_ = getSecond(shape);
73 size_ = getSecond(size);
74 bar_ = getSecond(bar);
75 color_ = getSecond(color);
76 lang_ = getSecond(langs);
78 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
79 // with which to initialise the xforms choice object.
80 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
81 fl_addto_choice(dialog_->choice_family, choice.c_str());
83 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
84 fl_addto_choice(dialog_->choice_series, choice.c_str());
86 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
87 fl_addto_choice(dialog_->choice_shape, choice.c_str());
89 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
90 fl_addto_choice(dialog_->choice_size, choice.c_str());
92 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
93 fl_addto_choice(dialog_->choice_bar, choice.c_str());
95 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
96 fl_addto_choice(dialog_->choice_color, choice.c_str());
98 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
99 fl_addto_combox(dialog_->combox_language, choice.c_str());
100 fl_set_combox_browser_height(dialog_->combox_language, 250);
102 // Manage the ok, apply and cancel/close buttons
103 bcview().setApply(dialog_->button_apply);
104 bcview().setCancel(dialog_->button_close);
105 bcview().addReadOnly(dialog_->check_toggle_all);
109 void FormCharacter::apply()
113 int pos = fl_get_choice(dialog_->choice_family);
114 controller().setFamily(family_[pos - 1]);
116 pos = fl_get_choice(dialog_->choice_series);
117 controller().setSeries(series_[pos - 1]);
119 pos = fl_get_choice(dialog_->choice_shape);
120 controller().setShape(shape_[pos - 1]);
122 pos = fl_get_choice(dialog_->choice_size);
123 controller().setSize(size_[pos - 1]);
125 pos = fl_get_choice(dialog_->choice_bar);
126 controller().setBar(bar_[pos - 1]);
128 pos = fl_get_choice(dialog_->choice_color);
129 controller().setColor(color_[pos - 1]);
131 pos = fl_get_combox(dialog_->combox_language);
132 controller().setLanguage(lang_[pos - 1]);
134 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
135 controller().setToggleAll(toggleall);
139 void FormCharacter::update()
141 int pos = int(findPos(family_, controller().getFamily()));
142 fl_set_choice(dialog_->choice_family, pos+1);
144 pos = int(findPos(series_, controller().getSeries()));
145 fl_set_choice(dialog_->choice_series, pos+1);
147 pos = int(findPos(shape_, controller().getShape()));
148 fl_set_choice(dialog_->choice_shape, pos+1);
150 pos = int(findPos(size_, controller().getSize()));
151 fl_set_choice(dialog_->choice_size, pos+1);
153 pos = int(findPos(bar_, controller().getBar()));
154 fl_set_choice(dialog_->choice_bar, pos+1);
156 pos = int(findPos(color_, controller().getColor()));
157 fl_set_choice(dialog_->choice_color, pos+1);
159 pos = int(findPos(lang_, controller().getLanguage()));
160 fl_set_combox(dialog_->combox_language, pos+1);
162 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
166 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
168 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
170 int pos = fl_get_choice(dialog_->choice_family);
171 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
172 activate = ButtonPolicy::SMI_VALID;
174 pos = fl_get_choice(dialog_->choice_series);
175 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
176 activate = ButtonPolicy::SMI_VALID;
178 pos = fl_get_choice(dialog_->choice_shape);
179 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
180 activate = ButtonPolicy::SMI_VALID;
182 pos = fl_get_choice(dialog_->choice_size);
183 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
184 activate = ButtonPolicy::SMI_VALID;
186 pos = fl_get_choice(dialog_->choice_bar);
187 if (bar_[pos - 1] != frnt::IGNORE)
188 activate = ButtonPolicy::SMI_VALID;
190 pos = fl_get_choice(dialog_->choice_color);
191 if (color_[pos - 1] != LColor::ignore)
192 activate = ButtonPolicy::SMI_VALID;
194 pos = fl_get_combox(dialog_->combox_language);
195 if (lang_[pos - 1] != "No change")
196 activate = ButtonPolicy::SMI_VALID;