]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormCharacter.C
6071f51b6d13f4429e87642853a7a3c6c0141c81
[features.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 frnt::BarPair;
29 using frnt::ColorPair;
30 using frnt::FamilyPair;
31 using frnt::getBarData;
32 using frnt::getColorData;
33 using frnt::getFamilyData;
34 using frnt::getLanguageData;
35 using frnt::getSeriesData;
36 using frnt::getShapeData;
37 using frnt::getSizeData;
38 using frnt::LanguagePair;
39 using frnt::SeriesPair;
40 using frnt::ShapePair;
41 using frnt::SizePair;
42
43 using lyx::support::getStringFromVector;
44
45 using std::vector;
46
47
48 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
49
50 FormCharacter::FormCharacter(Dialog & parent)
51         : base_class(parent, _("Text Style"), false)
52 {}
53
54
55 void FormCharacter::build()
56 {
57         dialog_.reset(build_character(this));
58
59         vector<FamilyPair>   const family = getFamilyData();
60         vector<SeriesPair>   const series = getSeriesData();
61         vector<ShapePair>    const shape  = getShapeData();
62         vector<SizePair>     const size   = getSizeData();
63         vector<BarPair>      const bar    = getBarData();
64         vector<ColorPair>    const color  = getColorData();
65         vector<LanguagePair> const langs  = getLanguageData(true);
66
67         // Store the identifiers for later
68         family_ = getSecond(family);
69         series_ = getSecond(series);
70         shape_  = getSecond(shape);
71         size_   = getSecond(size);
72         bar_    = getSecond(bar);
73         color_  = getSecond(color);
74         lang_   = getSecond(langs);
75
76         // create a string of entries " entry1 | entry2 | entry3 | entry4 "
77         // with which to initialise the xforms choice object.
78         string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
79         fl_addto_choice(dialog_->choice_family, choice.c_str());
80
81         choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
82         fl_addto_choice(dialog_->choice_series, choice.c_str());
83
84         choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
85         fl_addto_choice(dialog_->choice_shape, choice.c_str());
86
87         choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
88         fl_addto_choice(dialog_->choice_size, choice.c_str());
89
90         choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
91         fl_addto_choice(dialog_->choice_bar, choice.c_str());
92
93         choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
94         fl_addto_choice(dialog_->choice_color, choice.c_str());
95
96         choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
97         fl_addto_combox(dialog_->combox_language, choice.c_str());
98         fl_set_combox_browser_height(dialog_->combox_language, 250);
99
100         // Manage the ok, apply and cancel/close buttons
101         bcview().setApply(dialog_->button_apply);
102         bcview().setCancel(dialog_->button_close);
103         bcview().addReadOnly(dialog_->check_toggle_all);
104 }
105
106
107 void FormCharacter::apply()
108 {
109         if (!form()) return;
110
111         int pos = fl_get_choice(dialog_->choice_family);
112         controller().setFamily(family_[pos - 1]);
113
114         pos = fl_get_choice(dialog_->choice_series);
115         controller().setSeries(series_[pos - 1]);
116
117         pos = fl_get_choice(dialog_->choice_shape);
118         controller().setShape(shape_[pos - 1]);
119
120         pos = fl_get_choice(dialog_->choice_size);
121         controller().setSize(size_[pos - 1]);
122
123         pos = fl_get_choice(dialog_->choice_bar);
124         controller().setBar(bar_[pos - 1]);
125
126         pos = fl_get_choice(dialog_->choice_color);
127         controller().setColor(color_[pos - 1]);
128
129         pos = fl_get_combox(dialog_->combox_language);
130         controller().setLanguage(lang_[pos - 1]);
131
132         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
133         controller().setToggleAll(toggleall);
134 }
135
136
137 void FormCharacter::update()
138 {
139         int pos = int(findPos(family_, controller().getFamily()));
140         fl_set_choice(dialog_->choice_family, pos+1);
141
142         pos = int(findPos(series_, controller().getSeries()));
143         fl_set_choice(dialog_->choice_series, pos+1);
144
145         pos = int(findPos(shape_, controller().getShape()));
146         fl_set_choice(dialog_->choice_shape, pos+1);
147
148         pos = int(findPos(size_, controller().getSize()));
149         fl_set_choice(dialog_->choice_size, pos+1);
150
151         pos = int(findPos(bar_, controller().getBar()));
152         fl_set_choice(dialog_->choice_bar, pos+1);
153
154         pos = int(findPos(color_, controller().getColor()));
155         fl_set_choice(dialog_->choice_color, pos+1);
156
157         pos = int(findPos(lang_, controller().getLanguage()));
158         fl_set_combox(dialog_->combox_language, pos+1);
159
160         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
161 }
162
163
164 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
165 {
166         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
167
168         int pos = fl_get_choice(dialog_->choice_family);
169         if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
170                 activate = ButtonPolicy::SMI_VALID;
171
172         pos = fl_get_choice(dialog_->choice_series);
173         if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
174                 activate = ButtonPolicy::SMI_VALID;
175
176         pos = fl_get_choice(dialog_->choice_shape);
177         if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
178                 activate = ButtonPolicy::SMI_VALID;
179
180         pos = fl_get_choice(dialog_->choice_size);
181         if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
182                 activate = ButtonPolicy::SMI_VALID;
183
184         pos = fl_get_choice(dialog_->choice_bar);
185         if (bar_[pos - 1] != frnt::IGNORE)
186                 activate = ButtonPolicy::SMI_VALID;
187
188         pos = fl_get_choice(dialog_->choice_color);
189         if (color_[pos - 1] != LColor::ignore)
190                 activate = ButtonPolicy::SMI_VALID;
191
192         pos = fl_get_combox(dialog_->combox_language);
193         if (lang_[pos - 1] != "No change")
194                 activate = ButtonPolicy::SMI_VALID;
195
196         return activate;
197 }