2001-02-26 15:17:19 +00:00
|
|
|
/**
|
|
|
|
* \file FormCharacter.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
2001-03-21 13:27:03 +00:00
|
|
|
* \author Edwin Leuven, leuven@fee.uva.nl
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
2001-02-26 15:17:19 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
#include <vector>
|
2001-03-15 13:37:04 +00:00
|
|
|
|
2001-02-26 15:17:19 +00:00
|
|
|
#ifdef __GNUG_
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlCharacter.h"
|
2001-02-26 15:17:19 +00:00
|
|
|
#include "FormCharacter.h"
|
|
|
|
#include "form_character.h"
|
2001-03-21 13:27:03 +00:00
|
|
|
#include "gettext.h"
|
2001-02-26 15:17:19 +00:00
|
|
|
#include "combox.h"
|
2001-03-21 13:27:03 +00:00
|
|
|
#include "helper_funcs.h"
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
using std::vector;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::find;
|
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
using namespace character;
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
FormCharacter::FormCharacter(ControlCharacter & c)
|
2001-08-28 13:48:40 +00:00
|
|
|
: base_class(c, _("Character Layout"), false)
|
2001-03-21 13:27:03 +00:00
|
|
|
{}
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
|
2001-02-26 15:17:19 +00:00
|
|
|
{
|
2001-03-21 13:27:03 +00:00
|
|
|
FormCharacter * pre = static_cast<FormCharacter*>(v);
|
|
|
|
pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
|
2001-02-26 15:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormCharacter::build()
|
|
|
|
{
|
2001-03-21 13:27:03 +00:00
|
|
|
dialog_.reset(build_character());
|
|
|
|
|
2001-03-28 13:11:08 +00:00
|
|
|
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();
|
2001-03-21 13:27:03 +00:00
|
|
|
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...
|
2001-03-22 11:24:36 +00:00
|
|
|
fl_addto_choice(dialog_->choice_language, "prevent crash");
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
// insert default language box manually
|
|
|
|
fl_addto_form(dialog_->form);
|
2002-03-21 16:59:12 +00:00
|
|
|
FL_OBJECT * ob = dialog_->choice_language;
|
|
|
|
fl_hide_object(dialog_->choice_language);
|
2001-03-22 11:24:36 +00:00
|
|
|
|
2002-03-21 16:59:12 +00:00
|
|
|
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);
|
2001-03-21 13:27:03 +00:00
|
|
|
fl_end_form();
|
|
|
|
|
|
|
|
// build up the combox entries
|
|
|
|
for (vector<string>::const_iterator cit = language.begin();
|
|
|
|
cit != language.end(); ++cit) {
|
|
|
|
combo_language2_->addto(*cit);
|
|
|
|
}
|
2001-09-06 12:42:47 +00:00
|
|
|
combo_language2_->select(*language.begin());
|
2001-03-21 13:27:03 +00:00
|
|
|
|
|
|
|
// Manage the ok, apply and cancel/close buttons
|
|
|
|
bc().setApply(dialog_->button_apply);
|
|
|
|
bc().setCancel(dialog_->button_close);
|
|
|
|
bc().addReadOnly(dialog_->check_toggle_all);
|
2001-02-26 15:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormCharacter::apply()
|
|
|
|
{
|
2001-06-12 13:54:04 +00:00
|
|
|
if (!form()) return;
|
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
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]);
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
pos = fl_get_choice(dialog_->choice_shape);
|
|
|
|
controller().setShape(shape_[pos-1]);
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
pos = fl_get_choice(dialog_->choice_size);
|
|
|
|
controller().setSize(size_[pos-1]);
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
pos = fl_get_choice(dialog_->choice_bar);
|
|
|
|
controller().setBar(bar_[pos-1]);
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_color);
|
|
|
|
controller().setColor(color_[pos-1]);
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
controller().setLanguage(combo_language2_->getline());
|
2001-02-26 15:17:19 +00:00
|
|
|
|
2001-03-21 13:27:03 +00:00
|
|
|
bool const toggleall = fl_get_button(dialog_->check_toggle_all);
|
|
|
|
controller().setToggleAll(toggleall);
|
2001-02-26 15:17:19 +00:00
|
|
|
}
|
2001-06-12 13:54:04 +00:00
|
|
|
|
2002-03-21 16:59:12 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template<class A>
|
|
|
|
typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<A>::const_iterator it = find(vec.begin(), vec.end(), val);
|
2001-06-13 13:44:23 +00:00
|
|
|
if (it == vec.end())
|
|
|
|
return 0;
|
|
|
|
return it - vec.begin();
|
|
|
|
}
|
2002-03-21 16:59:12 +00:00
|
|
|
|
2001-06-13 13:44:23 +00:00
|
|
|
} // namespace anon
|
2001-06-12 13:54:04 +00:00
|
|
|
|
2002-03-21 16:59:12 +00:00
|
|
|
|
2001-06-12 13:54:04 +00:00
|
|
|
void FormCharacter::update()
|
|
|
|
{
|
2001-06-13 13:44:23 +00:00
|
|
|
int pos = int(findPos(family_, controller().getFamily()));
|
|
|
|
fl_set_choice(dialog_->choice_family, pos+1);
|
|
|
|
|
|
|
|
pos = int(findPos(series_, controller().getSeries()));
|
|
|
|
fl_set_choice(dialog_->choice_series, pos+1);
|
|
|
|
|
|
|
|
pos = int(findPos(shape_, controller().getShape()));
|
|
|
|
fl_set_choice(dialog_->choice_shape, pos+1);
|
|
|
|
|
|
|
|
pos = int(findPos(size_, controller().getSize()));
|
|
|
|
fl_set_choice(dialog_->choice_size, pos+1);
|
|
|
|
|
|
|
|
pos = int(findPos(bar_, controller().getBar()));
|
|
|
|
fl_set_choice(dialog_->choice_bar, pos+1);
|
|
|
|
|
|
|
|
pos = int(findPos(color_, controller().getColor()));
|
|
|
|
fl_set_choice(dialog_->choice_color, pos+1);
|
|
|
|
|
2001-09-06 12:42:47 +00:00
|
|
|
combo_language2_->select(controller().getLanguage());
|
2001-06-13 13:44:23 +00:00
|
|
|
|
|
|
|
fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
|
2001-06-12 13:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormCharacter::input(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
|
|
|
|
|
|
|
|
int pos = fl_get_choice(dialog_->choice_family);
|
|
|
|
if (family_[pos-1] != LyXFont::IGNORE_FAMILY)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_series);
|
|
|
|
if (series_[pos-1] != LyXFont::IGNORE_SERIES)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_shape);
|
|
|
|
if (shape_[pos-1] != LyXFont::IGNORE_SHAPE)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_size);
|
|
|
|
if (size_[pos-1] != LyXFont::IGNORE_SIZE)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_bar);
|
|
|
|
if (bar_[pos-1] != character::IGNORE)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
pos = fl_get_choice(dialog_->choice_color);
|
|
|
|
if (color_[pos-1] != LColor::ignore)
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
string const language = combo_language2_->getline();
|
|
|
|
if (language != _("No change"))
|
|
|
|
activate = ButtonPolicy::SMI_VALID;
|
|
|
|
|
|
|
|
return activate;
|
|
|
|
}
|