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;
29 using namespace character;
31 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
33 FormCharacter::FormCharacter(ControlCharacter & c)
34 : base_class(c, _("Character Layout"))
38 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
40 FormCharacter * pre = static_cast<FormCharacter*>(v);
41 pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
44 void FormCharacter::build()
46 dialog_.reset(build_character());
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<string> const language = getLanguageData();
56 // Store the enums 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);
64 // create a string of entries " entry1 | entry2 | entry3 | entry4 "
65 // with which to initialise the xforms choice object.
66 string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
67 fl_addto_choice(dialog_->choice_family, choice.c_str());
69 choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
70 fl_addto_choice(dialog_->choice_series, choice.c_str());
72 choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
73 fl_addto_choice(dialog_->choice_shape, choice.c_str());
75 choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
76 fl_addto_choice(dialog_->choice_size, choice.c_str());
78 choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
79 fl_addto_choice(dialog_->choice_bar, choice.c_str());
81 choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
82 fl_addto_choice(dialog_->choice_color, choice.c_str());
84 // xforms appears to need this to prevent a crash...
85 fl_addto_choice(dialog_->choice_language, "prevent crash");
87 // insert default language box manually
88 fl_addto_form(dialog_->form);
89 FL_OBJECT * ob = dialog_->choice_language;
90 fl_deactivate_object(dialog_->choice_language);
92 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
93 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
94 combo_language2_->shortcut("#L", 1);
95 combo_language2_->setcallback(ComboInputCB, this);
98 // build up the combox entries
99 for (vector<string>::const_iterator cit = language.begin();
100 cit != language.end(); ++cit) {
101 combo_language2_->addto(*cit);
103 combo_language2_->select_text(*language.begin());
105 // Manage the ok, apply and cancel/close buttons
106 bc().setApply(dialog_->button_apply);
107 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);