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