2 * \file FormCharacter.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Edwin Leuven, leuven@fee.uva.nl
7 * \author Angus Leeming, a.leeming@ic.ac.uk
13 #pragma implementation
19 #include "ControlCharacter.h"
20 #include "FormCharacter.h"
21 #include "form_character.h"
24 #include "helper_funcs.h"
27 using std::back_inserter;
30 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
32 FormCharacter::FormCharacter(ControlCharacter & c)
33 : base_class(c, _("Character Layout"))
37 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
39 FormCharacter * pre = static_cast<FormCharacter*>(v);
40 pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
43 void FormCharacter::build()
45 dialog_.reset(build_character());
47 vector<ControlCharacter::FamilyPair> const family = getFamilyData();
48 vector<ControlCharacter::SeriesPair> const series = getSeriesData();
49 vector<ControlCharacter::ShapePair> const shape = getShapeData();
50 vector<ControlCharacter::SizePair> const size = getSizeData();
51 vector<ControlCharacter::BarPair> const bar = getBarData();
52 vector<ControlCharacter::ColorPair> const color = getColorData();
53 vector<string> const language = getLanguageData();
55 // Store the enums for later
56 family_ = getSecond(family);
57 series_ = getSecond(series);
58 shape_ = getSecond(shape);
59 size_ = getSecond(size);
60 bar_ = getSecond(bar);
61 color_ = getSecond(color);
63 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
64 // with which to initialise the xforms choice object.
65 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
66 fl_addto_choice(dialog_->choice_family, choice.c_str());
68 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
69 fl_addto_choice(dialog_->choice_series, choice.c_str());
71 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
72 fl_addto_choice(dialog_->choice_shape, choice.c_str());
74 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
75 fl_addto_choice(dialog_->choice_size, choice.c_str());
77 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
78 fl_addto_choice(dialog_->choice_bar, choice.c_str());
80 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
81 fl_addto_choice(dialog_->choice_color, choice.c_str());
83 // xforms appears to need this to prevent a crash...
84 // fl_addto_choice(dialog_->choice_language,
85 // _(" English %l| German | French "));
87 // insert default language box manually
88 fl_addto_form(dialog_->form);
89 FL_OBJECT * ob = dialog_->choice_language;
90 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
91 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
92 combo_language2_->shortcut("#L", 1);
93 combo_language2_->setcallback(ComboInputCB, this);
96 // build up the combox entries
97 for (vector<string>::const_iterator cit = language.begin();
98 cit != language.end(); ++cit) {
99 combo_language2_->addto(*cit);
101 combo_language2_->select_text(*language.begin());
103 // Manage the ok, apply and cancel/close buttons
104 bc().setApply(dialog_->button_apply);
105 bc().setCancel(dialog_->button_close);
107 bc().addReadOnly(dialog_->check_toggle_all);
111 void FormCharacter::apply()
113 int pos = fl_get_choice(dialog_->choice_family);
114 controller().setFamily(family_[pos-1]);
116 pos = fl_get_choice(dialog_->choice_series);
117 controller().setSeries(series_[pos-1]);
119 pos = fl_get_choice(dialog_->choice_shape);
120 controller().setShape(shape_[pos-1]);
122 pos = fl_get_choice(dialog_->choice_size);
123 controller().setSize(size_[pos-1]);
125 pos = fl_get_choice(dialog_->choice_bar);
126 controller().setBar(bar_[pos-1]);
128 pos = fl_get_choice(dialog_->choice_color);
129 controller().setColor(color_[pos-1]);
131 controller().setLanguage(combo_language2_->getline());
133 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
134 controller().setToggleAll(toggleall);