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