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