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
18 #include "ButtonController.h"
19 #include "ControlCharacter.h"
20 #include "FormCharacter.h"
21 #include "forms/form_character.h"
23 #include "helper_funcs.h"
24 #include "xforms_helpers.h"
25 #include FORMS_H_LOCATION
28 #include "frnt_lang.h"
30 #include "support/lstrings.h"
37 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
39 FormCharacter::FormCharacter(Dialog & parent)
40 : base_class(parent, _("Character Layout"), false)
44 void FormCharacter::build()
46 dialog_.reset(build_character(this));
48 vector<FamilyPair> const family = getFamilyData();
49 vector<SeriesPair> const series = getSeriesData();
50 vector<ShapePair> const shape = getShapeData();
51 vector<SizePair> const size = getSizeData();
52 vector<BarPair> const bar = getBarData();
53 vector<ColorPair> const color = getColorData();
54 vector<LanguagePair> const langs = getLanguageData(true);
56 // Store the identifiers for later
57 family_ = getSecond(family);
58 series_ = getSecond(series);
59 shape_ = getSecond(shape);
60 size_ = getSecond(size);
61 bar_ = getSecond(bar);
62 color_ = getSecond(color);
63 lang_ = getSecond(langs);
65 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
66 // with which to initialise the xforms choice object.
67 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
68 fl_addto_choice(dialog_->choice_family, choice.c_str());
70 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
71 fl_addto_choice(dialog_->choice_series, choice.c_str());
73 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
74 fl_addto_choice(dialog_->choice_shape, choice.c_str());
76 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
77 fl_addto_choice(dialog_->choice_size, choice.c_str());
79 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
80 fl_addto_choice(dialog_->choice_bar, choice.c_str());
82 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
83 fl_addto_choice(dialog_->choice_color, choice.c_str());
85 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
86 fl_addto_combox(dialog_->combox_language, choice.c_str());
87 fl_set_combox_browser_height(dialog_->combox_language, 250);
89 // Manage the ok, apply and cancel/close buttons
90 bcview().setApply(dialog_->button_apply);
91 bcview().setCancel(dialog_->button_close);
92 bcview().addReadOnly(dialog_->check_toggle_all);
96 void FormCharacter::apply()
100 int pos = fl_get_choice(dialog_->choice_family);
101 controller().setFamily(family_[pos - 1]);
103 pos = fl_get_choice(dialog_->choice_series);
104 controller().setSeries(series_[pos - 1]);
106 pos = fl_get_choice(dialog_->choice_shape);
107 controller().setShape(shape_[pos - 1]);
109 pos = fl_get_choice(dialog_->choice_size);
110 controller().setSize(size_[pos - 1]);
112 pos = fl_get_choice(dialog_->choice_bar);
113 controller().setBar(bar_[pos - 1]);
115 pos = fl_get_choice(dialog_->choice_color);
116 controller().setColor(color_[pos - 1]);
118 pos = fl_get_combox(dialog_->combox_language);
119 controller().setLanguage(lang_[pos - 1]);
121 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
122 controller().setToggleAll(toggleall);
126 void FormCharacter::update()
128 int pos = int(findPos(family_, controller().getFamily()));
129 fl_set_choice(dialog_->choice_family, pos+1);
131 pos = int(findPos(series_, controller().getSeries()));
132 fl_set_choice(dialog_->choice_series, pos+1);
134 pos = int(findPos(shape_, controller().getShape()));
135 fl_set_choice(dialog_->choice_shape, pos+1);
137 pos = int(findPos(size_, controller().getSize()));
138 fl_set_choice(dialog_->choice_size, pos+1);
140 pos = int(findPos(bar_, controller().getBar()));
141 fl_set_choice(dialog_->choice_bar, pos+1);
143 pos = int(findPos(color_, controller().getColor()));
144 fl_set_choice(dialog_->choice_color, pos+1);
146 pos = int(findPos(lang_, controller().getLanguage()));
147 fl_set_combox(dialog_->combox_language, pos+1);
149 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
153 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
155 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
157 int pos = fl_get_choice(dialog_->choice_family);
158 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
159 activate = ButtonPolicy::SMI_VALID;
161 pos = fl_get_choice(dialog_->choice_series);
162 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
163 activate = ButtonPolicy::SMI_VALID;
165 pos = fl_get_choice(dialog_->choice_shape);
166 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
167 activate = ButtonPolicy::SMI_VALID;
169 pos = fl_get_choice(dialog_->choice_size);
170 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
171 activate = ButtonPolicy::SMI_VALID;
173 pos = fl_get_choice(dialog_->choice_bar);
174 if (bar_[pos - 1] != frnt::IGNORE)
175 activate = ButtonPolicy::SMI_VALID;
177 pos = fl_get_choice(dialog_->choice_color);
178 if (color_[pos - 1] != LColor::ignore)
179 activate = ButtonPolicy::SMI_VALID;
181 pos = fl_get_combox(dialog_->combox_language);
182 if (lang_[pos - 1] != "No change")
183 activate = ButtonPolicy::SMI_VALID;