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"
35 using support::getStringFromVector;
40 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
42 FormCharacter::FormCharacter(Dialog & parent)
43 : base_class(parent, _("Text Style"), false)
47 void FormCharacter::build()
49 dialog_.reset(build_character(this));
51 vector<FamilyPair> const family = getFamilyData();
52 vector<SeriesPair> const series = getSeriesData();
53 vector<ShapePair> const shape = getShapeData();
54 vector<SizePair> const size = getSizeData();
55 vector<BarPair> const bar = getBarData();
56 vector<ColorPair> const color = getColorData();
57 vector<LanguagePair> const langs = getLanguageData(true);
59 // Store the identifiers for later
60 family_ = getSecond(family);
61 series_ = getSecond(series);
62 shape_ = getSecond(shape);
63 size_ = getSecond(size);
64 bar_ = getSecond(bar);
65 color_ = getSecond(color);
66 lang_ = getSecond(langs);
68 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
69 // with which to initialise the xforms choice object.
70 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
71 fl_addto_choice(dialog_->choice_family, choice.c_str());
73 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
74 fl_addto_choice(dialog_->choice_series, choice.c_str());
76 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
77 fl_addto_choice(dialog_->choice_shape, choice.c_str());
79 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
80 fl_addto_choice(dialog_->choice_size, choice.c_str());
82 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
83 fl_addto_choice(dialog_->choice_bar, choice.c_str());
85 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
86 fl_addto_choice(dialog_->choice_color, choice.c_str());
88 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
89 fl_addto_combox(dialog_->combox_language, choice.c_str());
90 fl_set_combox_browser_height(dialog_->combox_language, 250);
92 // Manage the ok, apply and cancel/close buttons
93 bcview().setApply(dialog_->button_apply);
94 bcview().setCancel(dialog_->button_close);
95 bcview().addReadOnly(dialog_->check_toggle_all);
99 void FormCharacter::apply()
103 int pos = fl_get_choice(dialog_->choice_family);
104 controller().setFamily(family_[pos - 1]);
106 pos = fl_get_choice(dialog_->choice_series);
107 controller().setSeries(series_[pos - 1]);
109 pos = fl_get_choice(dialog_->choice_shape);
110 controller().setShape(shape_[pos - 1]);
112 pos = fl_get_choice(dialog_->choice_size);
113 controller().setSize(size_[pos - 1]);
115 pos = fl_get_choice(dialog_->choice_bar);
116 controller().setBar(bar_[pos - 1]);
118 pos = fl_get_choice(dialog_->choice_color);
119 controller().setColor(color_[pos - 1]);
121 pos = fl_get_combox(dialog_->combox_language);
122 controller().setLanguage(lang_[pos - 1]);
124 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
125 controller().setToggleAll(toggleall);
129 void FormCharacter::update()
131 int pos = int(findPos(family_, controller().getFamily()));
132 fl_set_choice(dialog_->choice_family, pos+1);
134 pos = int(findPos(series_, controller().getSeries()));
135 fl_set_choice(dialog_->choice_series, pos+1);
137 pos = int(findPos(shape_, controller().getShape()));
138 fl_set_choice(dialog_->choice_shape, pos+1);
140 pos = int(findPos(size_, controller().getSize()));
141 fl_set_choice(dialog_->choice_size, pos+1);
143 pos = int(findPos(bar_, controller().getBar()));
144 fl_set_choice(dialog_->choice_bar, pos+1);
146 pos = int(findPos(color_, controller().getColor()));
147 fl_set_choice(dialog_->choice_color, pos+1);
149 pos = int(findPos(lang_, controller().getLanguage()));
150 fl_set_combox(dialog_->combox_language, pos+1);
152 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
156 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
158 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
160 int pos = fl_get_choice(dialog_->choice_family);
161 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
162 activate = ButtonPolicy::SMI_VALID;
164 pos = fl_get_choice(dialog_->choice_series);
165 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
166 activate = ButtonPolicy::SMI_VALID;
168 pos = fl_get_choice(dialog_->choice_shape);
169 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
170 activate = ButtonPolicy::SMI_VALID;
172 pos = fl_get_choice(dialog_->choice_size);
173 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
174 activate = ButtonPolicy::SMI_VALID;
176 pos = fl_get_choice(dialog_->choice_bar);
177 if (bar_[pos - 1] != IGNORE)
178 activate = ButtonPolicy::SMI_VALID;
180 pos = fl_get_choice(dialog_->choice_color);
181 if (color_[pos - 1] != LColor::ignore)
182 activate = ButtonPolicy::SMI_VALID;
184 pos = fl_get_combox(dialog_->combox_language);
185 if (lang_[pos - 1] != "No change")
186 activate = ButtonPolicy::SMI_VALID;
191 } // namespace frontend