]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / FormCharacter.C
1 /**
2  * \file FormCharacter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "FormCharacter.h"
15 #include "forms/form_character.h"
16
17 #include "xforms_helpers.h"
18 #include "xformsBC.h"
19
20 #include "controllers/frnt_lang.h"
21 #include "controllers/helper_funcs.h"
22
23 #include "support/lstrings.h"
24
25 #include "lyx_forms.h"
26 #include "combox.h"
27
28 using std::vector;
29 using std::string;
30
31 namespace lyx {
32
33 using support::getStringFromVector;
34
35 namespace frontend {
36
37
38 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
39
40 FormCharacter::FormCharacter(Dialog & parent)
41         : base_class(parent, _("Text Style"), false)
42 {}
43
44
45 void FormCharacter::build()
46 {
47         dialog_.reset(build_character(this));
48
49         vector<FamilyPair>   const family = getFamilyData();
50         vector<SeriesPair>   const series = getSeriesData();
51         vector<ShapePair>    const shape  = getShapeData();
52         vector<SizePair>     const size   = getSizeData();
53         vector<BarPair>      const bar    = getBarData();
54         vector<ColorPair>    const color  = getColorData();
55         vector<LanguagePair> const langs  = getLanguageData(true);
56
57         // Store the identifiers for later
58         family_ = getSecond(family);
59         series_ = getSecond(series);
60         shape_  = getSecond(shape);
61         size_   = getSecond(size);
62         bar_    = getSecond(bar);
63         color_  = getSecond(color);
64         lang_   = getSecond(langs);
65
66         // create a string of entries " entry1 | entry2 | entry3 | entry4 "
67         // with which to initialise the xforms choice object.
68         string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
69         fl_addto_choice(dialog_->choice_family, choice.c_str());
70
71         choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
72         fl_addto_choice(dialog_->choice_series, choice.c_str());
73
74         choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
75         fl_addto_choice(dialog_->choice_shape, choice.c_str());
76
77         choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
78         fl_addto_choice(dialog_->choice_size, choice.c_str());
79
80         choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
81         fl_addto_choice(dialog_->choice_bar, choice.c_str());
82
83         choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
84         fl_addto_choice(dialog_->choice_color, choice.c_str());
85
86         choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
87         fl_addto_combox(dialog_->combox_language, choice.c_str());
88         fl_set_combox_browser_height(dialog_->combox_language, 250);
89
90         // Manage the ok, apply and cancel/close buttons
91         bcview().setApply(dialog_->button_apply);
92         bcview().setCancel(dialog_->button_close);
93         bcview().addReadOnly(dialog_->check_toggle_all);
94 }
95
96
97 void FormCharacter::apply()
98 {
99         if (!form()) return;
100
101         int pos = fl_get_choice(dialog_->choice_family);
102         controller().setFamily(family_[pos - 1]);
103
104         pos = fl_get_choice(dialog_->choice_series);
105         controller().setSeries(series_[pos - 1]);
106
107         pos = fl_get_choice(dialog_->choice_shape);
108         controller().setShape(shape_[pos - 1]);
109
110         pos = fl_get_choice(dialog_->choice_size);
111         controller().setSize(size_[pos - 1]);
112
113         pos = fl_get_choice(dialog_->choice_bar);
114         controller().setBar(bar_[pos - 1]);
115
116         pos = fl_get_choice(dialog_->choice_color);
117         controller().setColor(color_[pos - 1]);
118
119         pos = fl_get_combox(dialog_->combox_language);
120         controller().setLanguage(lang_[pos - 1]);
121
122         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
123         controller().setToggleAll(toggleall);
124 }
125
126
127 void FormCharacter::update()
128 {
129         int pos = int(findPos(family_, controller().getFamily()));
130         fl_set_choice(dialog_->choice_family, pos+1);
131
132         pos = int(findPos(series_, controller().getSeries()));
133         fl_set_choice(dialog_->choice_series, pos+1);
134
135         pos = int(findPos(shape_, controller().getShape()));
136         fl_set_choice(dialog_->choice_shape, pos+1);
137
138         pos = int(findPos(size_, controller().getSize()));
139         fl_set_choice(dialog_->choice_size, pos+1);
140
141         pos = int(findPos(bar_, controller().getBar()));
142         fl_set_choice(dialog_->choice_bar, pos+1);
143
144         pos = int(findPos(color_, controller().getColor()));
145         fl_set_choice(dialog_->choice_color, pos+1);
146
147         pos = int(findPos(lang_, controller().getLanguage()));
148         fl_set_combox(dialog_->combox_language, pos+1);
149
150         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
151 }
152
153
154 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
155 {
156         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
157
158         int pos = fl_get_choice(dialog_->choice_family);
159         if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
160                 activate = ButtonPolicy::SMI_VALID;
161
162         pos = fl_get_choice(dialog_->choice_series);
163         if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
164                 activate = ButtonPolicy::SMI_VALID;
165
166         pos = fl_get_choice(dialog_->choice_shape);
167         if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
168                 activate = ButtonPolicy::SMI_VALID;
169
170         pos = fl_get_choice(dialog_->choice_size);
171         if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
172                 activate = ButtonPolicy::SMI_VALID;
173
174         pos = fl_get_choice(dialog_->choice_bar);
175         if (bar_[pos - 1] != IGNORE)
176                 activate = ButtonPolicy::SMI_VALID;
177
178         pos = fl_get_choice(dialog_->choice_color);
179         if (color_[pos - 1] != LColor::ignore)
180                 activate = ButtonPolicy::SMI_VALID;
181
182         pos = fl_get_combox(dialog_->combox_language);
183         if (lang_[pos - 1] != "No change")
184                 activate = ButtonPolicy::SMI_VALID;
185
186         return activate;
187 }
188
189 } // namespace frontend
190 } // namespace lyx