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"
28 using namespace lyx::support;
36 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
38 FormCharacter::FormCharacter(Dialog & parent)
39 : base_class(parent, _("Text Style"), false)
43 void FormCharacter::build()
45 dialog_.reset(build_character(this));
47 vector<FamilyPair> const family = getFamilyData();
48 vector<SeriesPair> const series = getSeriesData();
49 vector<ShapePair> const shape = getShapeData();
50 vector<SizePair> const size = getSizeData();
51 vector<BarPair> const bar = getBarData();
52 vector<ColorPair> const color = getColorData();
53 vector<LanguagePair> const langs = getLanguageData(true);
55 // Store the identifiers for later
56 family_ = getSecond(family);
57 series_ = getSecond(series);
58 shape_ = getSecond(shape);
59 size_ = getSecond(size);
60 bar_ = getSecond(bar);
61 color_ = getSecond(color);
62 lang_ = getSecond(langs);
64 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
65 // with which to initialise the xforms choice object.
66 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
67 fl_addto_choice(dialog_->choice_family, choice.c_str());
69 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
70 fl_addto_choice(dialog_->choice_series, choice.c_str());
72 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
73 fl_addto_choice(dialog_->choice_shape, choice.c_str());
75 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
76 fl_addto_choice(dialog_->choice_size, choice.c_str());
78 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
79 fl_addto_choice(dialog_->choice_bar, choice.c_str());
81 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
82 fl_addto_choice(dialog_->choice_color, choice.c_str());
84 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
85 fl_addto_combox(dialog_->combox_language, choice.c_str());
86 fl_set_combox_browser_height(dialog_->combox_language, 250);
88 // Manage the ok, apply and cancel/close buttons
89 bcview().setApply(dialog_->button_apply);
90 bcview().setCancel(dialog_->button_close);
91 bcview().addReadOnly(dialog_->check_toggle_all);
95 void FormCharacter::apply()
99 int pos = fl_get_choice(dialog_->choice_family);
100 controller().setFamily(family_[pos - 1]);
102 pos = fl_get_choice(dialog_->choice_series);
103 controller().setSeries(series_[pos - 1]);
105 pos = fl_get_choice(dialog_->choice_shape);
106 controller().setShape(shape_[pos - 1]);
108 pos = fl_get_choice(dialog_->choice_size);
109 controller().setSize(size_[pos - 1]);
111 pos = fl_get_choice(dialog_->choice_bar);
112 controller().setBar(bar_[pos - 1]);
114 pos = fl_get_choice(dialog_->choice_color);
115 controller().setColor(color_[pos - 1]);
117 pos = fl_get_combox(dialog_->combox_language);
118 controller().setLanguage(lang_[pos - 1]);
120 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
121 controller().setToggleAll(toggleall);
125 void FormCharacter::update()
127 int pos = int(findPos(family_, controller().getFamily()));
128 fl_set_choice(dialog_->choice_family, pos+1);
130 pos = int(findPos(series_, controller().getSeries()));
131 fl_set_choice(dialog_->choice_series, pos+1);
133 pos = int(findPos(shape_, controller().getShape()));
134 fl_set_choice(dialog_->choice_shape, pos+1);
136 pos = int(findPos(size_, controller().getSize()));
137 fl_set_choice(dialog_->choice_size, pos+1);
139 pos = int(findPos(bar_, controller().getBar()));
140 fl_set_choice(dialog_->choice_bar, pos+1);
142 pos = int(findPos(color_, controller().getColor()));
143 fl_set_choice(dialog_->choice_color, pos+1);
145 pos = int(findPos(lang_, controller().getLanguage()));
146 fl_set_combox(dialog_->combox_language, pos+1);
148 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
152 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
154 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
156 int pos = fl_get_choice(dialog_->choice_family);
157 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
158 activate = ButtonPolicy::SMI_VALID;
160 pos = fl_get_choice(dialog_->choice_series);
161 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
162 activate = ButtonPolicy::SMI_VALID;
164 pos = fl_get_choice(dialog_->choice_shape);
165 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
166 activate = ButtonPolicy::SMI_VALID;
168 pos = fl_get_choice(dialog_->choice_size);
169 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
170 activate = ButtonPolicy::SMI_VALID;
172 pos = fl_get_choice(dialog_->choice_bar);
173 if (bar_[pos - 1] != frnt::IGNORE)
174 activate = ButtonPolicy::SMI_VALID;
176 pos = fl_get_choice(dialog_->choice_color);
177 if (color_[pos - 1] != LColor::ignore)
178 activate = ButtonPolicy::SMI_VALID;
180 pos = fl_get_combox(dialog_->combox_language);
181 if (lang_[pos - 1] != "No change")
182 activate = ButtonPolicy::SMI_VALID;