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;
35 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
37 FormCharacter::FormCharacter(Dialog & parent)
38 : base_class(parent, _("Text Style"), false)
42 void FormCharacter::build()
44 dialog_.reset(build_character(this));
46 vector<FamilyPair> const family = getFamilyData();
47 vector<SeriesPair> const series = getSeriesData();
48 vector<ShapePair> const shape = getShapeData();
49 vector<SizePair> const size = getSizeData();
50 vector<BarPair> const bar = getBarData();
51 vector<ColorPair> const color = getColorData();
52 vector<LanguagePair> const langs = getLanguageData(true);
54 // Store the identifiers for later
55 family_ = getSecond(family);
56 series_ = getSecond(series);
57 shape_ = getSecond(shape);
58 size_ = getSecond(size);
59 bar_ = getSecond(bar);
60 color_ = getSecond(color);
61 lang_ = getSecond(langs);
63 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
64 // with which to initialise the xforms choice object.
65 string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
66 fl_addto_choice(dialog_->choice_family, choice.c_str());
68 choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
69 fl_addto_choice(dialog_->choice_series, choice.c_str());
71 choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
72 fl_addto_choice(dialog_->choice_shape, choice.c_str());
74 choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
75 fl_addto_choice(dialog_->choice_size, choice.c_str());
77 choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
78 fl_addto_choice(dialog_->choice_bar, choice.c_str());
80 choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
81 fl_addto_choice(dialog_->choice_color, choice.c_str());
83 choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
84 fl_addto_combox(dialog_->combox_language, choice.c_str());
85 fl_set_combox_browser_height(dialog_->combox_language, 250);
87 // Manage the ok, apply and cancel/close buttons
88 bcview().setApply(dialog_->button_apply);
89 bcview().setCancel(dialog_->button_close);
90 bcview().addReadOnly(dialog_->check_toggle_all);
94 void FormCharacter::apply()
98 int pos = fl_get_choice(dialog_->choice_family);
99 controller().setFamily(family_[pos - 1]);
101 pos = fl_get_choice(dialog_->choice_series);
102 controller().setSeries(series_[pos - 1]);
104 pos = fl_get_choice(dialog_->choice_shape);
105 controller().setShape(shape_[pos - 1]);
107 pos = fl_get_choice(dialog_->choice_size);
108 controller().setSize(size_[pos - 1]);
110 pos = fl_get_choice(dialog_->choice_bar);
111 controller().setBar(bar_[pos - 1]);
113 pos = fl_get_choice(dialog_->choice_color);
114 controller().setColor(color_[pos - 1]);
116 pos = fl_get_combox(dialog_->combox_language);
117 controller().setLanguage(lang_[pos - 1]);
119 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
120 controller().setToggleAll(toggleall);
124 void FormCharacter::update()
126 int pos = int(findPos(family_, controller().getFamily()));
127 fl_set_choice(dialog_->choice_family, pos+1);
129 pos = int(findPos(series_, controller().getSeries()));
130 fl_set_choice(dialog_->choice_series, pos+1);
132 pos = int(findPos(shape_, controller().getShape()));
133 fl_set_choice(dialog_->choice_shape, pos+1);
135 pos = int(findPos(size_, controller().getSize()));
136 fl_set_choice(dialog_->choice_size, pos+1);
138 pos = int(findPos(bar_, controller().getBar()));
139 fl_set_choice(dialog_->choice_bar, pos+1);
141 pos = int(findPos(color_, controller().getColor()));
142 fl_set_choice(dialog_->choice_color, pos+1);
144 pos = int(findPos(lang_, controller().getLanguage()));
145 fl_set_combox(dialog_->combox_language, pos+1);
147 fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
151 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
153 ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
155 int pos = fl_get_choice(dialog_->choice_family);
156 if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
157 activate = ButtonPolicy::SMI_VALID;
159 pos = fl_get_choice(dialog_->choice_series);
160 if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
161 activate = ButtonPolicy::SMI_VALID;
163 pos = fl_get_choice(dialog_->choice_shape);
164 if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
165 activate = ButtonPolicy::SMI_VALID;
167 pos = fl_get_choice(dialog_->choice_size);
168 if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
169 activate = ButtonPolicy::SMI_VALID;
171 pos = fl_get_choice(dialog_->choice_bar);
172 if (bar_[pos - 1] != frnt::IGNORE)
173 activate = ButtonPolicy::SMI_VALID;
175 pos = fl_get_choice(dialog_->choice_color);
176 if (color_[pos - 1] != LColor::ignore)
177 activate = ButtonPolicy::SMI_VALID;
179 pos = fl_get_combox(dialog_->combox_language);
180 if (lang_[pos - 1] != "No change")
181 activate = ButtonPolicy::SMI_VALID;