]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
Add fl_set_input_return to input_paperoption.
[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 using std::vector;
27 using std::back_inserter;
28 using std::transform;
29 using namespace character;
30
31 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
32
33 FormCharacter::FormCharacter(ControlCharacter & c)
34         : base_class(c, _("Character Layout"), false)
35 {}
36
37
38 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
39 {
40         FormCharacter * pre = static_cast<FormCharacter*>(v);
41         pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
42 }
43
44 void FormCharacter::build()
45 {
46         dialog_.reset(build_character());
47
48         vector<FamilyPair> const family = getFamilyData();
49         vector<SeriesPair> const series = getSeriesData();
50         vector<ShapePair>  const shape  = getShapeData();
51         vector<SizePair>   const size   = getSizeData();
52         vector<BarPair>    const bar    = getBarData();
53         vector<ColorPair>  const color  = getColorData();
54         vector<string> const language = getLanguageData();
55
56         // Store the enums for later
57         family_ = getSecond(family);
58         series_ = getSecond(series);
59         shape_ = getSecond(shape);
60         size_ = getSecond(size);
61         bar_ = getSecond(bar);
62         color_ = getSecond(color);
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         // xforms appears to need this to prevent a crash...
85         fl_addto_choice(dialog_->choice_language, "prevent crash");
86
87         // insert default language box manually
88         fl_addto_form(dialog_->form);
89                 FL_OBJECT * ob = dialog_->choice_language;
90                 fl_hide_object(dialog_->choice_language);
91
92                 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
93                 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
94                 combo_language2_->shortcut("#L", 1);
95                 combo_language2_->setcallback(ComboInputCB, this);
96         fl_end_form();
97
98         // build up the combox entries
99         for (vector<string>::const_iterator cit = language.begin(); 
100              cit != language.end(); ++cit) {
101                 combo_language2_->addto(*cit);
102         }
103         combo_language2_->select_text(*language.begin());
104
105         // Manage the ok, apply and cancel/close buttons
106         bc().setApply(dialog_->button_apply);
107         bc().setCancel(dialog_->button_close);
108         bc().addReadOnly(dialog_->check_toggle_all);
109 }
110
111
112 void FormCharacter::apply()
113 {
114         if (!form()) return;
115
116         int pos = fl_get_choice(dialog_->choice_family);
117         controller().setFamily(family_[pos-1]);
118
119         pos = fl_get_choice(dialog_->choice_series);
120         controller().setSeries(series_[pos-1]);
121    
122         pos = fl_get_choice(dialog_->choice_shape);
123         controller().setShape(shape_[pos-1]);
124
125         pos = fl_get_choice(dialog_->choice_size);
126         controller().setSize(size_[pos-1]);
127    
128         pos = fl_get_choice(dialog_->choice_bar);
129         controller().setBar(bar_[pos-1]);
130    
131         pos = fl_get_choice(dialog_->choice_color);
132         controller().setColor(color_[pos-1]);
133
134         controller().setLanguage(combo_language2_->getline());
135
136         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
137         controller().setToggleAll(toggleall);
138 }
139
140 namespace {
141
142 template<class A>
143 typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
144 {
145         vector<A>::const_iterator it =
146                 std::find(vec.begin(), vec.end(), val);
147         if (it == vec.end())
148                 return 0;
149         return it - vec.begin();
150 }
151  
152 } // namespace anon
153
154 void FormCharacter::update()
155 {
156         int pos = int(findPos(family_, controller().getFamily()));
157         fl_set_choice(dialog_->choice_family, pos+1);
158         
159         pos = int(findPos(series_, controller().getSeries()));
160         fl_set_choice(dialog_->choice_series, pos+1);
161
162         pos = int(findPos(shape_, controller().getShape()));
163         fl_set_choice(dialog_->choice_shape, pos+1);
164
165         pos = int(findPos(size_, controller().getSize()));
166         fl_set_choice(dialog_->choice_size, pos+1);
167
168         pos = int(findPos(bar_, controller().getBar()));
169         fl_set_choice(dialog_->choice_bar, pos+1);
170
171         pos = int(findPos(color_, controller().getColor()));
172         fl_set_choice(dialog_->choice_color, pos+1);
173
174         combo_language2_->select_text(controller().getLanguage());
175
176         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
177 }
178
179
180 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
181 {
182         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
183
184         int pos = fl_get_choice(dialog_->choice_family);
185         if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
186                 activate = ButtonPolicy::SMI_VALID;
187         
188         pos = fl_get_choice(dialog_->choice_series);
189         if (series_[pos-1] != LyXFont::IGNORE_SERIES)
190                 activate = ButtonPolicy::SMI_VALID;
191
192         pos = fl_get_choice(dialog_->choice_shape);
193         if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
194                 activate = ButtonPolicy::SMI_VALID;
195
196         pos = fl_get_choice(dialog_->choice_size);
197         if (size_[pos-1] != LyXFont::IGNORE_SIZE)
198                 activate = ButtonPolicy::SMI_VALID;
199
200         pos = fl_get_choice(dialog_->choice_bar);
201         if (bar_[pos-1] != character::IGNORE)
202                 activate = ButtonPolicy::SMI_VALID;
203
204         pos = fl_get_choice(dialog_->choice_color);
205         if (color_[pos-1] != LColor::ignore)
206                 activate = ButtonPolicy::SMI_VALID;
207
208         string const language = combo_language2_->getline();
209         if (language != _("No change"))
210                 activate = ButtonPolicy::SMI_VALID;
211
212         return activate;
213 }