]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
fix math fonts with LyX/Mac
[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 <config.h>
13
14 #include "FormCharacter.h"
15 #include "forms/form_character.h"
16
17 #include "xforms_helpers.h"
18 #include "xformsBC.h"
19
20 #include "controllers/frnt_lang.h"
21 #include "controllers/helper_funcs.h"
22
23 #include "LColor.h"
24
25 #include "support/lstrings.h"
26
27 #include "lyx_forms.h"
28 #include "combox.h"
29
30 using std::vector;
31 using std::string;
32
33 namespace lyx {
34
35 using support::getStringFromVector;
36
37 namespace frontend {
38
39
40 typedef FormController<ControlCharacter, FormView<FD_character> > base_class;
41
42 FormCharacter::FormCharacter(Dialog & parent)
43         : base_class(parent, _("Text Style"), false)
44 {}
45
46
47 void FormCharacter::build()
48 {
49         dialog_.reset(build_character(this));
50
51         vector<FamilyPair>   const family = getFamilyData();
52         vector<SeriesPair>   const series = getSeriesData();
53         vector<ShapePair>    const shape  = getShapeData();
54         vector<SizePair>     const size   = getSizeData();
55         vector<BarPair>      const bar    = getBarData();
56         vector<ColorPair>    const color  = getColorData();
57         vector<LanguagePair> const langs  = getLanguageData(true);
58
59         // Store the identifiers for later
60         family_ = getSecond(family);
61         series_ = getSecond(series);
62         shape_  = getSecond(shape);
63         size_   = getSecond(size);
64         bar_    = getSecond(bar);
65         color_  = getSecond(color);
66         lang_   = getSecond(langs);
67
68         // create a string of entries " entry1 | entry2 | entry3 | entry4 "
69         // with which to initialise the xforms choice object.
70         string choice = ' ' + getStringFromVector(getFirst(family), " | ") + ' ';
71         fl_addto_choice(dialog_->choice_family, choice.c_str());
72
73         choice = ' ' + getStringFromVector(getFirst(series), " | ") + ' ';
74         fl_addto_choice(dialog_->choice_series, choice.c_str());
75
76         choice = ' ' + getStringFromVector(getFirst(shape), " | ") + ' ';
77         fl_addto_choice(dialog_->choice_shape, choice.c_str());
78
79         choice = ' ' + getStringFromVector(getFirst(size), " | ") + ' ';
80         fl_addto_choice(dialog_->choice_size, choice.c_str());
81
82         choice = ' ' + getStringFromVector(getFirst(bar), " | ") + ' ';
83         fl_addto_choice(dialog_->choice_bar, choice.c_str());
84
85         choice = ' ' + getStringFromVector(getFirst(color), " | ") + ' ';
86         fl_addto_choice(dialog_->choice_color, choice.c_str());
87
88         choice = ' ' + getStringFromVector(getFirst(langs), " | ") + ' ';
89         fl_addto_combox(dialog_->combox_language, choice.c_str());
90         fl_set_combox_browser_height(dialog_->combox_language, 250);
91
92         // Manage the ok, apply and cancel/close buttons
93         bcview().setApply(dialog_->button_apply);
94         bcview().setCancel(dialog_->button_close);
95         bcview().addReadOnly(dialog_->check_toggle_all);
96 }
97
98
99 void FormCharacter::apply()
100 {
101         if (!form()) return;
102
103         int pos = fl_get_choice(dialog_->choice_family);
104         controller().setFamily(family_[pos - 1]);
105
106         pos = fl_get_choice(dialog_->choice_series);
107         controller().setSeries(series_[pos - 1]);
108
109         pos = fl_get_choice(dialog_->choice_shape);
110         controller().setShape(shape_[pos - 1]);
111
112         pos = fl_get_choice(dialog_->choice_size);
113         controller().setSize(size_[pos - 1]);
114
115         pos = fl_get_choice(dialog_->choice_bar);
116         controller().setBar(bar_[pos - 1]);
117
118         pos = fl_get_choice(dialog_->choice_color);
119         controller().setColor(color_[pos - 1]);
120
121         pos = fl_get_combox(dialog_->combox_language);
122         controller().setLanguage(lang_[pos - 1]);
123
124         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
125         controller().setToggleAll(toggleall);
126 }
127
128
129 void FormCharacter::update()
130 {
131         int pos = int(findPos(family_, controller().getFamily()));
132         fl_set_choice(dialog_->choice_family, pos+1);
133
134         pos = int(findPos(series_, controller().getSeries()));
135         fl_set_choice(dialog_->choice_series, pos+1);
136
137         pos = int(findPos(shape_, controller().getShape()));
138         fl_set_choice(dialog_->choice_shape, pos+1);
139
140         pos = int(findPos(size_, controller().getSize()));
141         fl_set_choice(dialog_->choice_size, pos+1);
142
143         pos = int(findPos(bar_, controller().getBar()));
144         fl_set_choice(dialog_->choice_bar, pos+1);
145
146         pos = int(findPos(color_, controller().getColor()));
147         fl_set_choice(dialog_->choice_color, pos+1);
148
149         pos = int(findPos(lang_, controller().getLanguage()));
150         fl_set_combox(dialog_->combox_language, pos+1);
151
152         fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
153 }
154
155
156 ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
157 {
158         ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
159
160         int pos = fl_get_choice(dialog_->choice_family);
161         if (family_[pos - 1] != LyXFont::IGNORE_FAMILY)
162                 activate = ButtonPolicy::SMI_VALID;
163
164         pos = fl_get_choice(dialog_->choice_series);
165         if (series_[pos - 1] != LyXFont::IGNORE_SERIES)
166                 activate = ButtonPolicy::SMI_VALID;
167
168         pos = fl_get_choice(dialog_->choice_shape);
169         if (shape_[pos - 1] != LyXFont::IGNORE_SHAPE)
170                 activate = ButtonPolicy::SMI_VALID;
171
172         pos = fl_get_choice(dialog_->choice_size);
173         if (size_[pos - 1] != LyXFont::IGNORE_SIZE)
174                 activate = ButtonPolicy::SMI_VALID;
175
176         pos = fl_get_choice(dialog_->choice_bar);
177         if (bar_[pos - 1] != IGNORE)
178                 activate = ButtonPolicy::SMI_VALID;
179
180         pos = fl_get_choice(dialog_->choice_color);
181         if (color_[pos - 1] != LColor::ignore)
182                 activate = ButtonPolicy::SMI_VALID;
183
184         pos = fl_get_combox(dialog_->combox_language);
185         if (lang_[pos - 1] != "No change")
186                 activate = ButtonPolicy::SMI_VALID;
187
188         return activate;
189 }
190
191 } // namespace frontend
192 } // namespace lyx