lyx_mirror/src/frontends/xforms/FormCharacter.C
Angus Leeming 8999098e94 Remove some xforms cruft from BufferView.h BufferView_pimpl.h.
John's name-changing patch.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1878 a592a061-630c-0410-9148-cb99ea01b6c8
2001-04-03 14:30:58 +00:00

137 lines
3.9 KiB
C

/**
* \file FormCharacter.C
* Copyright 2001 The LyX Team.
* See the file COPYING.
*
* \author Edwin Leuven, leuven@fee.uva.nl
* \author Angus Leeming, a.leeming@ic.ac.uk
*/
#include <vector>
#ifdef __GNUG_
#pragma implementation
#endif
#include <config.h>
#include "xformsBC.h"
#include "ControlCharacter.h"
#include "FormCharacter.h"
#include "form_character.h"
#include "gettext.h"
#include "combox.h"
#include "helper_funcs.h"
using std::vector;
using std::back_inserter;
using std::transform;
using namespace character;
typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
FormCharacter::FormCharacter(ControlCharacter & c)
: base_class(c, _("Character Layout"))
{}
void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
{
FormCharacter * pre = static_cast<FormCharacter*>(v);
pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
}
void FormCharacter::build()
{
dialog_.reset(build_character());
vector<FamilyPair> const family = getFamilyData();
vector<SeriesPair> const series = getSeriesData();
vector<ShapePair> const shape = getShapeData();
vector<SizePair> const size = getSizeData();
vector<BarPair> const bar = getBarData();
vector<ColorPair> const color = getColorData();
vector<string> const language = getLanguageData();
// Store the enums for later
family_ = getSecond(family);
series_ = getSecond(series);
shape_ = getSecond(shape);
size_ = getSecond(size);
bar_ = getSecond(bar);
color_ = getSecond(color);
// create a string of entries " entry1 | entry2 | entry3 | entry4 "
// with which to initialise the xforms choice object.
string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
fl_addto_choice(dialog_->choice_family, choice.c_str());
choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
fl_addto_choice(dialog_->choice_series, choice.c_str());
choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
fl_addto_choice(dialog_->choice_shape, choice.c_str());
choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
fl_addto_choice(dialog_->choice_size, choice.c_str());
choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
fl_addto_choice(dialog_->choice_bar, choice.c_str());
choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
fl_addto_choice(dialog_->choice_color, choice.c_str());
// xforms appears to need this to prevent a crash...
fl_addto_choice(dialog_->choice_language, "prevent crash");
// insert default language box manually
fl_addto_form(dialog_->form);
FL_OBJECT * ob = dialog_->choice_language;
fl_deactivate_object(dialog_->choice_language);
combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
combo_language2_->shortcut("#L", 1);
combo_language2_->setcallback(ComboInputCB, this);
fl_end_form();
// build up the combox entries
for (vector<string>::const_iterator cit = language.begin();
cit != language.end(); ++cit) {
combo_language2_->addto(*cit);
}
combo_language2_->select_text(*language.begin());
// Manage the ok, apply and cancel/close buttons
bc().setApply(dialog_->button_apply);
bc().setCancel(dialog_->button_close);
bc().addReadOnly(dialog_->check_toggle_all);
}
void FormCharacter::apply()
{
int pos = fl_get_choice(dialog_->choice_family);
controller().setFamily(family_[pos-1]);
pos = fl_get_choice(dialog_->choice_series);
controller().setSeries(series_[pos-1]);
pos = fl_get_choice(dialog_->choice_shape);
controller().setShape(shape_[pos-1]);
pos = fl_get_choice(dialog_->choice_size);
controller().setSize(size_[pos-1]);
pos = fl_get_choice(dialog_->choice_bar);
controller().setBar(bar_[pos-1]);
pos = fl_get_choice(dialog_->choice_color);
controller().setColor(color_[pos-1]);
controller().setLanguage(combo_language2_->getline());
bool const toggleall = fl_get_button(dialog_->check_toggle_all);
controller().setToggleAll(toggleall);
}