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