+2001-06-13 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * ControlDialogs.h added // -*- C++ -*-
+
+ * ControlCharacter.[Ch]: added // -*- C++ -*-
+ (setParams): Check contents of font_ to activate Apply button.
+ (clearParams): removed.
+ font_ is now stored as a boost::scoped_ptr.
+ font_ is no longer deleted on hide(), so it's contents can now be used
+ by the Font button on the toolbar.
+ Lots of new methods so that the GUI can easily get the contents of
+ font_ when it update()s.
+
2001-06-12 Angus Leeming <a.leeming@ic.ac.uk>
* ControlCharacter.C (apply): test that font_ exists, thereby preventing
+// -*- C++ -*-
/**
* \file ControlCharacter.C
* Copyright 2001 The LyX Team.
void ControlCharacter::setParams()
{
- if (font_) delete font_;
- font_ = new LyXFont(LyXFont::ALL_IGNORE);
-}
-
+ // Do this the first time only. Used as a flag for whether or not the
+ // view has been built
+ if (!font_.get())
+ font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
-void ControlCharacter::clearParams()
-{
- if (font_) {
- delete font_;
- font_ = 0;
- }
+ // so that the user can press Ok
+ if (getFamily() != LyXFont::IGNORE_FAMILY ||
+ getSeries() != LyXFont::IGNORE_SERIES ||
+ getShape() != LyXFont::IGNORE_SHAPE ||
+ getSize() != LyXFont::IGNORE_SIZE ||
+ getBar() != character::IGNORE ||
+ getColor() != LColor::ignore ||
+ font_->language() != ignore_language)
+ bc().valid();
}
void ControlCharacter::apply()
{
- if (!(font_ && lv_.view()->available()))
+ // Nothing to apply. (Can be called from the Toolbar.)
+ if (!font_.get())
return;
-
- view().apply();
- ToggleAndShow(lv_.view(), *font_, toggleall_);
+ // Apply from the view if it's visible. Otherwise, use the stored values
+ if (lv_.view()->available())
+ view().apply();
+
+ ToggleAndShow(lv_.view(), *(font_.get()), toggleall_);
lv_.view()->setState();
lv_.buffer()->markDirty();
setMinibuffer(&lv_, _("Character set"));
}
+LyXFont::FONT_FAMILY ControlCharacter::getFamily() const
+{
+ if (font_.get())
+ return font_->family();
+ return LyXFont::IGNORE_FAMILY;
+}
+
void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
{
font_->setFamily(val);
}
+LyXFont::FONT_SERIES ControlCharacter::getSeries() const
+{
+ if (font_.get())
+ return font_->series();
+ return LyXFont::IGNORE_SERIES;
+}
+
void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
{
font_->setSeries(val);
}
+LyXFont::FONT_SHAPE ControlCharacter::getShape() const
+{
+ if (font_.get())
+ return font_->shape();
+ return LyXFont::IGNORE_SHAPE;
+}
+
void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
{
font_->setShape(val);
}
+LyXFont::FONT_SIZE ControlCharacter::getSize() const
+{
+ if (font_.get())
+ return font_->size();
+ return LyXFont::IGNORE_SIZE;
+}
+
void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
{
font_->setSize(val);
}
+character::FONT_STATE ControlCharacter::getBar() const
+{
+ if (font_.get()) {
+ if (font_->emph() != LyXFont::IGNORE)
+ return character::EMPH_TOGGLE;
+
+ else if (font_->underbar() != LyXFont::IGNORE)
+ return character::UNDERBAR_TOGGLE;
+
+ else if (font_->noun() != LyXFont::IGNORE)
+ return character::NOUN_TOGGLE;
+
+ else if (font_->latex() != LyXFont::IGNORE)
+ return character::LATEX_TOGGLE;
+ }
+ return character::IGNORE;
+}
+
void ControlCharacter::setBar(character::FONT_STATE val)
{
switch (val) {
}
}
+LColor::color ControlCharacter::getColor() const
+{
+ LColor::color col = LColor::ignore;
+
+ if (font_.get()) {
+ switch (font_->color()) {
+ case LColor::ignore:
+ case LColor::none:
+ case LColor::black:
+ case LColor::white:
+ case LColor::red:
+ case LColor::green:
+ case LColor::blue:
+ case LColor::cyan:
+ case LColor::magenta:
+ case LColor::yellow:
+ case LColor::inherit:
+ break;
+ default:
+ col = font_->color();
+ break;
+ }
+ }
+
+ return col;
+}
+
void ControlCharacter::setColor(LColor::color val)
{
switch (val) {
case LColor::inherit:
font_->setColor(val);
break;
-
default:
break;
}
}
-
+
+string ControlCharacter::getLanguage() const
+{
+ if (font_.get() && font_->language())
+ return font_->language()->lang();
+ return _("No change");
+}
+
+
void ControlCharacter::setLanguage(string const & val)
{
if (val == _("No change"))
font_->setLanguage(languages.getLanguage(val));
}
+
+bool ControlCharacter::getToggleAll() const
+{
+ return toggleall_;
+}
+
void ControlCharacter::setToggleAll(bool t)
{
toggleall_ = t;
+// -*- C++ -*-
/**
* \file ControlCharacter.h
* Copyright 2001 The LyX Team.
#ifndef CONTROLCHARACTER_H
#define CONTROLCHARACTER_H
+#include <boost/smart_ptr.hpp>
+
#ifdef __GNUG__
#pragma interface
#endif
///
void setToggleAll(bool);
+ ///
+ LyXFont::FONT_FAMILY getFamily() const;
+ ///
+ LyXFont::FONT_SERIES getSeries() const;
+ ///
+ LyXFont::FONT_SHAPE getShape() const;
+ ///
+ LyXFont::FONT_SIZE getSize() const;
+ ///
+ character::FONT_STATE getBar() const;
+ ///
+ LColor::color getColor() const;
+ ///
+ string getLanguage() const;
+ ///
+ bool getToggleAll() const;
+
private:
/// Get changed parameters and Dispatch them to the kernel.
virtual void apply();
/// set the params before show or update.
virtual void setParams();
- /// clean-up on hide.
- virtual void clearParams();
///
- LyXFont * font_;
+ boost::scoped_ptr<LyXFont> font_;
///
bool toggleall_;
};
+// -*- C++ -*-
/**
* \file FormCharacter.C
* Copyright 2001 The LyX Team.
controller().setToggleAll(toggleall);
}
+namespace {
+
+template<class A>
+typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
+{
+ vector<A>::const_iterator it =
+ std::find(vec.begin(), vec.end(), val);
+ if (it == vec.end())
+ return 0;
+ return it - vec.begin();
+}
+
+} // namespace anon
void FormCharacter::update()
{
- if (input(0,0) == ButtonPolicy::SMI_VALID)
- bc().valid(); // so that the user can press Ok
+ 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);
+
+ combo_language2_->select_text(controller().getLanguage());
+
+ fl_set_button(dialog_->check_toggle_all, controller().getToggleAll());
}