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