Once again the user can use the Font button on the toolbar to get the current

contents of the character dialog even if the dialog is hidden.

I think that the functionality of the character dialog/Font button on the
toolbar is now as it was in 1.1.6. Oh, but we now have a working button
controller that the GUI's get for free...

Keep up the bug reports!
Angus


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2114 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2001-06-13 13:44:23 +00:00
parent 3f11b9242b
commit 3e22b13963
7 changed files with 186 additions and 21 deletions

View File

@ -1,3 +1,16 @@
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> 2001-06-12 Angus Leeming <a.leeming@ic.ac.uk>
* ControlCharacter.C (apply): test that font_ exists, thereby preventing * ControlCharacter.C (apply): test that font_ exists, thereby preventing

View File

@ -1,3 +1,4 @@
// -*- C++ -*-
/** /**
* \file ControlCharacter.C * \file ControlCharacter.C
* Copyright 2001 The LyX Team. * Copyright 2001 The LyX Team.
@ -40,54 +41,106 @@ ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
void ControlCharacter::setParams() void ControlCharacter::setParams()
{ {
if (font_) delete font_; // Do this the first time only. Used as a flag for whether or not the
font_ = new LyXFont(LyXFont::ALL_IGNORE); // view has been built
} if (!font_.get())
font_.reset(new LyXFont(LyXFont::ALL_IGNORE));
// so that the user can press Ok
void ControlCharacter::clearParams() if (getFamily() != LyXFont::IGNORE_FAMILY ||
{ getSeries() != LyXFont::IGNORE_SERIES ||
if (font_) { getShape() != LyXFont::IGNORE_SHAPE ||
delete font_; getSize() != LyXFont::IGNORE_SIZE ||
font_ = 0; getBar() != character::IGNORE ||
} getColor() != LColor::ignore ||
font_->language() != ignore_language)
bc().valid();
} }
void ControlCharacter::apply() void ControlCharacter::apply()
{ {
if (!(font_ && lv_.view()->available())) // Nothing to apply. (Can be called from the Toolbar.)
if (!font_.get())
return; 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_.view()->setState();
lv_.buffer()->markDirty(); lv_.buffer()->markDirty();
setMinibuffer(&lv_, _("Character set")); 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) void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
{ {
font_->setFamily(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) void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
{ {
font_->setSeries(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) void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
{ {
font_->setShape(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) void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
{ {
font_->setSize(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) void ControlCharacter::setBar(character::FONT_STATE val)
{ {
switch (val) { switch (val) {
@ -123,6 +176,33 @@ void ControlCharacter::setBar(character::FONT_STATE 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) void ControlCharacter::setColor(LColor::color val)
{ {
switch (val) { switch (val) {
@ -139,13 +219,20 @@ void ControlCharacter::setColor(LColor::color val)
case LColor::inherit: case LColor::inherit:
font_->setColor(val); font_->setColor(val);
break; break;
default: default:
break; break;
} }
} }
string ControlCharacter::getLanguage() const
{
if (font_.get() && font_->language())
return font_->language()->lang();
return _("No change");
}
void ControlCharacter::setLanguage(string const & val) void ControlCharacter::setLanguage(string const & val)
{ {
if (val == _("No change")) if (val == _("No change"))
@ -158,6 +245,12 @@ void ControlCharacter::setLanguage(string const & val)
font_->setLanguage(languages.getLanguage(val)); font_->setLanguage(languages.getLanguage(val));
} }
bool ControlCharacter::getToggleAll() const
{
return toggleall_;
}
void ControlCharacter::setToggleAll(bool t) void ControlCharacter::setToggleAll(bool t)
{ {
toggleall_ = t; toggleall_ = t;

View File

@ -1,3 +1,4 @@
// -*- C++ -*-
/** /**
* \file ControlCharacter.h * \file ControlCharacter.h
* Copyright 2001 The LyX Team. * Copyright 2001 The LyX Team.
@ -9,6 +10,8 @@
#ifndef CONTROLCHARACTER_H #ifndef CONTROLCHARACTER_H
#define CONTROLCHARACTER_H #define CONTROLCHARACTER_H
#include <boost/smart_ptr.hpp>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
@ -41,16 +44,31 @@ public:
/// ///
void setToggleAll(bool); 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: private:
/// Get changed parameters and Dispatch them to the kernel. /// Get changed parameters and Dispatch them to the kernel.
virtual void apply(); virtual void apply();
/// set the params before show or update. /// set the params before show or update.
virtual void setParams(); virtual void setParams();
/// clean-up on hide.
virtual void clearParams();
/// ///
LyXFont * font_; boost::scoped_ptr<LyXFont> font_;
/// ///
bool toggleall_; bool toggleall_;
}; };

View File

@ -1,3 +1,4 @@
// -*- C++ -*-
/* This file is part of /* This file is part of
* ====================================================== * ======================================================
* *

View File

@ -1,3 +1,9 @@
2001-06-13 Angus Leeming <a.leeming@ic.ac.uk>
* FormCharacter.[Ch]: added // -*- C++ -*-
* FormCharacter.C (update): now uses contents of font_, stored
permanently by the controller to update() the dialog.
2001-06-12 Angus Leeming <a.leeming@ic.ac.uk> 2001-06-12 Angus Leeming <a.leeming@ic.ac.uk>
* FormInclude.C: * FormInclude.C:

View File

@ -1,3 +1,4 @@
// -*- C++ -*-
/** /**
* \file FormCharacter.C * \file FormCharacter.C
* Copyright 2001 The LyX Team. * Copyright 2001 The LyX Team.
@ -137,11 +138,43 @@ void FormCharacter::apply()
controller().setToggleAll(toggleall); 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() void FormCharacter::update()
{ {
if (input(0,0) == ButtonPolicy::SMI_VALID) int pos = int(findPos(family_, controller().getFamily()));
bc().valid(); // so that the user can press Ok 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());
} }

View File

@ -1,3 +1,4 @@
// -*- C++ -*-
/** /**
* \file FormCharacter.h * \file FormCharacter.h
* Copyright 2001 The LyX Team. * Copyright 2001 The LyX Team.