From: Angus Leeming Date: Wed, 13 Jun 2001 13:44:23 +0000 (+0000) Subject: Once again the user can use the Font button on the toolbar to get the current X-Git-Tag: 1.6.10~21188 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3e22b13963ca573b670135b4301f833da6ecd429;p=features.git 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 --- diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 9e959f06e6..9a6f3fdb5f 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,16 @@ +2001-06-13 Angus Leeming + + * 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 * ControlCharacter.C (apply): test that font_ exists, thereby preventing diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index b8c6df7203..61e8bc5d9e 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -1,3 +1,4 @@ +// -*- C++ -*- /** * \file ControlCharacter.C * Copyright 2001 The LyX Team. @@ -40,54 +41,106 @@ ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d) 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) { @@ -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) { switch (val) { @@ -139,13 +219,20 @@ void ControlCharacter::setColor(LColor::color 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")) @@ -158,6 +245,12 @@ void ControlCharacter::setLanguage(string const & val) font_->setLanguage(languages.getLanguage(val)); } + +bool ControlCharacter::getToggleAll() const +{ + return toggleall_; +} + void ControlCharacter::setToggleAll(bool t) { toggleall_ = t; diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index 6266b10f38..b479886633 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -1,3 +1,4 @@ +// -*- C++ -*- /** * \file ControlCharacter.h * Copyright 2001 The LyX Team. @@ -9,6 +10,8 @@ #ifndef CONTROLCHARACTER_H #define CONTROLCHARACTER_H +#include + #ifdef __GNUG__ #pragma interface #endif @@ -41,16 +44,31 @@ public: /// 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 font_; /// bool toggleall_; }; diff --git a/src/frontends/controllers/ControlDialogs.h b/src/frontends/controllers/ControlDialogs.h index 3898cffac4..c07de11329 100644 --- a/src/frontends/controllers/ControlDialogs.h +++ b/src/frontends/controllers/ControlDialogs.h @@ -1,3 +1,4 @@ +// -*- C++ -*- /* This file is part of * ====================================================== * diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 20403c4fe6..2b2ac1010c 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2001-06-13 Angus Leeming + + * 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 * FormInclude.C: diff --git a/src/frontends/xforms/FormCharacter.C b/src/frontends/xforms/FormCharacter.C index d75bb8954d..5324a56149 100644 --- a/src/frontends/xforms/FormCharacter.C +++ b/src/frontends/xforms/FormCharacter.C @@ -1,3 +1,4 @@ +// -*- C++ -*- /** * \file FormCharacter.C * Copyright 2001 The LyX Team. @@ -137,11 +138,43 @@ void FormCharacter::apply() controller().setToggleAll(toggleall); } +namespace { + +template +typename vector::size_type findPos(vector const & vec, A const & val) +{ + vector::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()); } diff --git a/src/frontends/xforms/FormCharacter.h b/src/frontends/xforms/FormCharacter.h index 91d17e4cab..8e6fd23233 100644 --- a/src/frontends/xforms/FormCharacter.h +++ b/src/frontends/xforms/FormCharacter.h @@ -1,3 +1,4 @@ +// -*- C++ -*- /** * \file FormCharacter.h * Copyright 2001 The LyX Team.