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"
29 using frnt::ColorPair;
30 using frnt::FamilyPair;
31 using frnt::getBarData;
32 using frnt::getColorData;
33 using frnt::getFamilyData;
34 using frnt::getLanguageData;
35 using frnt::getSeriesData;
36 using frnt::getShapeData;
37 using frnt::getSizeData;
38 using frnt::LanguagePair;
39 using frnt::SeriesPair;
40 using frnt::ShapePair;
43 using lyx::support::getStringFromVector;
48 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
50 FormCharacter::FormCharacter(Dialog & parent)
51 : base_class(parent, _("Text Style"), false)
55 void FormCharacter::build()
57 dialog_.reset(build_character(this));
59 vector<FamilyPair> const family = getFamilyData();
60 vector<SeriesPair> const series = getSeriesData();
61 vector<ShapePair> const shape = getShapeData();
62 vector<SizePair> const size = getSizeData();
63 vector<BarPair> const bar = getBarData();
64 vector<ColorPair> const color = getColorData();
65 vector<LanguagePair> const langs = getLanguageData(true);
67 // Store the identifiers for later
68 family_ = getSecond(family);
69 series_ = getSecond(series);
70 shape_ = getSecond(shape);
71 size_ = getSecond(size);
72 bar_ = getSecond(bar);
73 color_ = getSecond(color);
74 lang_ = getSecond(langs);
76 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
77 // with which to initialise the xforms choice object.
78 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
79 fl_addto_choice(dialog_->choice_family, choice.c_str());
81 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
82 fl_addto_choice(dialog_->choice_series, choice.c_str());
84 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
85 fl_addto_choice(dialog_->choice_shape, choice.c_str());
87 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
88 fl_addto_choice(dialog_->choice_size, choice.c_str());
90 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
91 fl_addto_choice(dialog_->choice_bar, choice.c_str());
93 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
94 fl_addto_choice(dialog_->choice_color, choice.c_str());
96 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
97 fl_addto_combox(dialog_->combox_language, choice.c_str());
98 fl_set_combox_browser_height(dialog_->combox_language, 250);
100 // Manage the ok, apply and cancel/close buttons
101 bcview().setApply(dialog_->button_apply);
102 bcview().setCancel(dialog_->button_close);
103 bcview().addReadOnly(dialog_->check_toggle_all);
107 void FormCharacter::apply()
111 int pos = fl_get_choice(dialog_->choice_family);
112 controller().setFamily(family_[pos - 1]);
114 pos = fl_get_choice(dialog_->choice_series);
115 controller().setSeries(series_[pos - 1]);
117 pos = fl_get_choice(dialog_->choice_shape);
118 controller().setShape(shape_[pos - 1]);
120 pos = fl_get_choice(dialog_->choice_size);
121 controller().setSize(size_[pos - 1]);
123 pos = fl_get_choice(dialog_->choice_bar);
124 controller().setBar(bar_[pos - 1]);
126 pos = fl_get_choice(dialog_->choice_color);
127 controller().setColor(color_[pos - 1]);
129 pos = fl_get_combox(dialog_->combox_language);
130 controller().setLanguage(lang_[pos - 1]);
132 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
133 controller().setToggleAll(toggleall);
137 void FormCharacter::update()
139 int pos = int(findPos(family_, controller().getFamily()));
140 fl_set_choice(dialog_->choice_family, pos+1);
142 pos = int(findPos(series_, controller().getSeries()));
143 fl_set_choice(dialog_->choice_series, pos+1);
145 pos = int(findPos(shape_, controller().getShape()));
146 fl_set_choice(dialog_->choice_shape, pos+1);
148 pos = int(findPos(size_, controller().getSize()));
149 fl_set_choice(dialog_->choice_size, pos+1);
151 pos = int(findPos(bar_, controller().getBar()));
152 fl_set_choice(dialog_->choice_bar, pos+1);
154 pos = int(findPos(color_, controller().getColor()));
155 fl_set_choice(dialog_->choice_color, pos+1);
157 pos = int(findPos(lang_, controller().getLanguage()));
158 fl_set_combox(dialog_->combox_language, pos+1);
160 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
164 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
166 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
168 int pos = fl_get_choice(dialog_->choice_family);
169 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
170 activate = ButtonPolicy::SMI_VALID;
172 pos = fl_get_choice(dialog_->choice_series);
173 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
174 activate = ButtonPolicy::SMI_VALID;
176 pos = fl_get_choice(dialog_->choice_shape);
177 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
178 activate = ButtonPolicy::SMI_VALID;
180 pos = fl_get_choice(dialog_->choice_size);
181 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
182 activate = ButtonPolicy::SMI_VALID;
184 pos = fl_get_choice(dialog_->choice_bar);
185 if (bar_[pos - 1] != frnt::IGNORE)
186 activate = ButtonPolicy::SMI_VALID;
188 pos = fl_get_choice(dialog_->choice_color);
189 if (color_[pos - 1] != LColor::ignore)
190 activate = ButtonPolicy::SMI_VALID;
192 pos = fl_get_combox(dialog_->combox_language);
193 if (lang_[pos - 1] != "No change")
194 activate = ButtonPolicy::SMI_VALID;