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, "prevent crash");
86 // insert default language box manually
87 fl_addto_form(dialog_->form);
88 FL_OBJECT * ob = dialog_->choice_language;
89 fl_deactivate_object(dialog_->choice_language);
91 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
92 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
93 combo_language2_->shortcut("#L", 1);
94 combo_language2_->setcallback(ComboInputCB, this);
97 // build up the combox entries
98 for (vector<string>::const_iterator cit = language.begin();
99 cit != language.end(); ++cit) {
100 combo_language2_->addto(*cit);
102 combo_language2_->select_text(*language.begin());
104 // Manage the ok, apply and cancel/close buttons
105 bc().setApply(dialog_->button_apply);
106 bc().setCancel(dialog_->button_close);
108 bc().addReadOnly(dialog_->check_toggle_all);
112 void FormCharacter::apply()
114 int pos = fl_get_choice(dialog_->choice_family);
115 controller().setFamily(family_[pos-1]);
117 pos = fl_get_choice(dialog_->choice_series);
118 controller().setSeries(series_[pos-1]);
120 pos = fl_get_choice(dialog_->choice_shape);
121 controller().setShape(shape_[pos-1]);
123 pos = fl_get_choice(dialog_->choice_size);
124 controller().setSize(size_[pos-1]);
126 pos = fl_get_choice(dialog_->choice_bar);
127 controller().setBar(bar_[pos-1]);
129 pos = fl_get_choice(dialog_->choice_color);
130 controller().setColor(color_[pos-1]);
132 controller().setLanguage(combo_language2_->getline());
134 bool const toggleall = fl_get_button(dialog_->check_toggle_all);
135 controller().setToggleAll(toggleall);