]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
Removed all redundant using directives from the source.
[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::vector;
31
32
33 using namespace frnt;
34
35 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
36
37 FormCharacter::FormCharacter(Dialog & parent)
38         : base_class(parent, _("Text Style"), false)
39 {}
40
41
42 void FormCharacter::build()
43 {
44         dialog_.reset(build_character(this));
45
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);
53
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);
62
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());
67
68         choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
69         fl_addto_choice(dialog_->choice_series, choice.c_str());
70
71         choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
72         fl_addto_choice(dialog_->choice_shape, choice.c_str());
73
74         choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
75         fl_addto_choice(dialog_->choice_size, choice.c_str());
76
77         choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
78         fl_addto_choice(dialog_->choice_bar, choice.c_str());
79
80         choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
81         fl_addto_choice(dialog_->choice_color, choice.c_str());
82
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);
86
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);
91 }
92
93
94 void FormCharacter::apply()
95 {
96         if (!form()) return;
97
98         int pos = fl_get_choice(dialog_->choice_family);
99         controller().setFamily(family_[pos - 1]);
100
101         pos = fl_get_choice(dialog_->choice_series);
102         controller().setSeries(series_[pos - 1]);
103
104         pos = fl_get_choice(dialog_->choice_shape);
105         controller().setShape(shape_[pos - 1]);
106
107         pos = fl_get_choice(dialog_->choice_size);
108         controller().setSize(size_[pos - 1]);
109
110         pos = fl_get_choice(dialog_->choice_bar);
111         controller().setBar(bar_[pos - 1]);
112
113         pos = fl_get_choice(dialog_->choice_color);
114         controller().setColor(color_[pos - 1]);
115
116         pos = fl_get_combox(dialog_->combox_language);
117         controller().setLanguage(lang_[pos - 1]);
118
119         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
120         controller().setToggleAll(toggleall);
121 }
122
123
124 void FormCharacter::update()
125 {
126         int pos = int(findPos(family_, controller().getFamily()));
127         fl_set_choice(dialog_->choice_family, pos+1);
128
129         pos = int(findPos(series_, controller().getSeries()));
130         fl_set_choice(dialog_->choice_series, pos+1);
131
132         pos = int(findPos(shape_, controller().getShape()));
133         fl_set_choice(dialog_->choice_shape, pos+1);
134
135         pos = int(findPos(size_, controller().getSize()));
136         fl_set_choice(dialog_->choice_size, pos+1);
137
138         pos = int(findPos(bar_, controller().getBar()));
139         fl_set_choice(dialog_->choice_bar, pos+1);
140
141         pos = int(findPos(color_, controller().getColor()));
142         fl_set_choice(dialog_->choice_color, pos+1);
143
144         pos = int(findPos(lang_, controller().getLanguage()));
145         fl_set_combox(dialog_->combox_language, pos+1);
146
147         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
148 }
149
150
151 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
152 {
153         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
154
155         int pos = fl_get_choice(dialog_->choice_family);
156         if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
157                 activate = ButtonPolicy::SMI_VALID;
158
159         pos = fl_get_choice(dialog_->choice_series);
160         if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
161                 activate = ButtonPolicy::SMI_VALID;
162
163         pos = fl_get_choice(dialog_->choice_shape);
164         if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
165                 activate = ButtonPolicy::SMI_VALID;
166
167         pos = fl_get_choice(dialog_->choice_size);
168         if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
169                 activate = ButtonPolicy::SMI_VALID;
170
171         pos = fl_get_choice(dialog_->choice_bar);
172         if (bar_[pos - 1] != frnt::IGNORE)
173                 activate = ButtonPolicy::SMI_VALID;
174
175         pos = fl_get_choice(dialog_->choice_color);
176         if (color_[pos - 1] != LColor::ignore)
177                 activate = ButtonPolicy::SMI_VALID;
178
179         pos = fl_get_combox(dialog_->combox_language);
180         if (lang_[pos - 1] != "No change")
181                 activate = ButtonPolicy::SMI_VALID;
182
183         return activate;
184 }