]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
change some __GNUG_ to __GNUG__
[lyx.git] / src / frontends / xforms / FormCharacter.C
1 /**
2  * \file FormCharacter.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven,  leuven@fee.uva.nl
7  * \author Angus Leeming, a.leeming@ic.ac.uk
8  */
9
10 #include <vector>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "xformsBC.h"
19 #include "ControlCharacter.h"
20 #include "FormCharacter.h"
21 #include "form_character.h"
22 #include "gettext.h"
23 #include "combox.h"
24 #include "helper_funcs.h"
25
26 #include "support/lstrings.h"
27
28 using std::vector;
29 using std::find;
30
31 using namespace character;
32
33 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
34
35 FormCharacter::FormCharacter(ControlCharacter & c)
36         : base_class(c, _("Character Layout"), false)
37 {}
38
39
40 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
41 {
42         FormCharacter * pre = static_cast<FormCharacter*>(v);
43         pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
44 }
45
46 void FormCharacter::build()
47 {
48         dialog_.reset(build_character());
49
50         vector<FamilyPair> const family = getFamilyData();
51         vector<SeriesPair> const series = getSeriesData();
52         vector<ShapePair>  const shape  = getShapeData();
53         vector<SizePair>   const size   = getSizeData();
54         vector<BarPair>    const bar    = getBarData();
55         vector<ColorPair>  const color  = getColorData();
56         vector<string> const language = getLanguageData();
57
58         // Store the enums for later
59         family_ = getSecond(family);
60         series_ = getSecond(series);
61         shape_ = getSecond(shape);
62         size_ = getSecond(size);
63         bar_ = getSecond(bar);
64         color_ = getSecond(color);
65
66         // create a string of entries " entry1 | entry2 | entry3 | entry4 "
67         // with which to initialise the xforms choice object.
68         string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
69         fl_addto_choice(dialog_->choice_family, choice.c_str());
70
71         choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
72         fl_addto_choice(dialog_->choice_series, choice.c_str());
73
74         choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
75         fl_addto_choice(dialog_->choice_shape, choice.c_str());
76
77         choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
78         fl_addto_choice(dialog_->choice_size, choice.c_str());
79
80         choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
81         fl_addto_choice(dialog_->choice_bar, choice.c_str());
82
83         choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
84         fl_addto_choice(dialog_->choice_color, choice.c_str());
85
86         // xforms appears to need this to prevent a crash...
87         fl_addto_choice(dialog_->choice_language, "prevent crash");
88
89         // insert default language box manually
90         fl_addto_form(dialog_->form);
91         FL_OBJECT * ob = dialog_->choice_language;
92         fl_hide_object(dialog_->choice_language);
93
94         combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
95         combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
96         combo_language2_->shortcut("#L", 1);
97         combo_language2_->setcallback(ComboInputCB, this);
98         fl_end_form();
99
100         // build up the combox entries
101         for (vector<string>::const_iterator cit = language.begin();
102              cit != language.end(); ++cit) {
103                 combo_language2_->addto(*cit);
104         }
105         combo_language2_->select(*language.begin());
106
107         // Manage the ok, apply and cancel/close buttons
108         bc().setApply(dialog_->button_apply);
109         bc().setCancel(dialog_->button_close);
110         bc().addReadOnly(dialog_->check_toggle_all);
111 }
112
113
114 void FormCharacter::apply()
115 {
116         if (!form()) return;
117
118         int pos = fl_get_choice(dialog_->choice_family);
119         controller().setFamily(family_[pos-1]);
120
121         pos = fl_get_choice(dialog_->choice_series);
122         controller().setSeries(series_[pos-1]);
123
124         pos = fl_get_choice(dialog_->choice_shape);
125         controller().setShape(shape_[pos-1]);
126
127         pos = fl_get_choice(dialog_->choice_size);
128         controller().setSize(size_[pos-1]);
129
130         pos = fl_get_choice(dialog_->choice_bar);
131         controller().setBar(bar_[pos-1]);
132
133         pos = fl_get_choice(dialog_->choice_color);
134         controller().setColor(color_[pos-1]);
135
136         controller().setLanguage(combo_language2_->getline());
137
138         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
139         controller().setToggleAll(toggleall);
140 }
141
142
143 namespace {
144
145 template<class A>
146 typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
147 {
148         typename vector<A>::const_iterator it =
149                 find(vec.begin(), vec.end(), val);
150         if (it == vec.end())
151                 return 0;
152         return it - vec.begin();
153 }
154
155 } // namespace anon
156
157
158 void FormCharacter::update()
159 {
160         int pos = int(findPos(family_, controller().getFamily()));
161         fl_set_choice(dialog_->choice_family, pos+1);
162
163         pos = int(findPos(series_, controller().getSeries()));
164         fl_set_choice(dialog_->choice_series, pos+1);
165
166         pos = int(findPos(shape_, controller().getShape()));
167         fl_set_choice(dialog_->choice_shape, pos+1);
168
169         pos = int(findPos(size_, controller().getSize()));
170         fl_set_choice(dialog_->choice_size, pos+1);
171
172         pos = int(findPos(bar_, controller().getBar()));
173         fl_set_choice(dialog_->choice_bar, pos+1);
174
175         pos = int(findPos(color_, controller().getColor()));
176         fl_set_choice(dialog_->choice_color, pos+1);
177
178         combo_language2_->select(controller().getLanguage());
179
180         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
181 }
182
183
184 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
185 {
186         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
187
188         int pos = fl_get_choice(dialog_->choice_family);
189         if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
190                 activate = ButtonPolicy::SMI_VALID;
191
192         pos = fl_get_choice(dialog_->choice_series);
193         if (series_[pos-1] != LyXFont::IGNORE_SERIES)
194                 activate = ButtonPolicy::SMI_VALID;
195
196         pos = fl_get_choice(dialog_->choice_shape);
197         if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
198                 activate = ButtonPolicy::SMI_VALID;
199
200         pos = fl_get_choice(dialog_->choice_size);
201         if (size_[pos-1] != LyXFont::IGNORE_SIZE)
202                 activate = ButtonPolicy::SMI_VALID;
203
204         pos = fl_get_choice(dialog_->choice_bar);
205         if (bar_[pos-1] != character::IGNORE)
206                 activate = ButtonPolicy::SMI_VALID;
207
208         pos = fl_get_choice(dialog_->choice_color);
209         if (color_[pos-1] != LColor::ignore)
210                 activate = ButtonPolicy::SMI_VALID;
211
212         string const language = combo_language2_->getline();
213         if (language != _("No change"))
214                 activate = ButtonPolicy::SMI_VALID;
215
216         return activate;
217 }