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