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