]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlCharacter.C
The reference dialog now disconnects from the inset on Apply. Its behaviour
[lyx.git] / src / frontends / controllers / ControlCharacter.C
index ce320474e6c66a3e50bc5c87fb0c4e0019e8cc7c..e9514593587fe0112f635e20bb189339b3975b30 100644 (file)
@@ -3,7 +3,7 @@
  * Copyright 2001 The LyX Team.
  * See the file COPYING.
  *
- * \author Angus Leeming, a.leeming@.ac.uk
+ * \author Angus Leeming, a.leeming@ic.ac.uk
  */
 
 #include <vector>
 
 #include <config.h>
 
+#include "ViewBase.h"
+#include "ButtonControllerBase.h"
 #include "ControlCharacter.h"
 #include "buffer.h"
 #include "Dialogs.h"
 #include "Liason.h"
 #include "LyXView.h"
 #include "bufferview_funcs.h" // ToggleAndShow
+#include "gettext.h"
+#include "language.h"
+#include "BufferView.h"
 
 using Liason::setMinibuffer;
 using SigC::slot;
 using std::vector;
 
+
 ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d)
        : ControlDialog<ControlConnectBD>(lv, d),
          font_(0), toggleall_(false)
 {
-       d_.showLayoutCharacter.connect(slot(this, &ControlCharacter::show));
+       d_.showCharacter.connect(slot(this, &ControlCharacter::show));
        d_.setUserFreeFont.connect(slot(this, &ControlCharacter::apply));
 }
 
 
 void ControlCharacter::setParams()
 {
-       if (font_) delete font_;
-       font_ = new LyXFont(LyXFont::ALL_IGNORE);
-}
-
-
-void ControlCharacter::clearParams()
-{
-       if (font_) {
-               delete font_;
-               font_ = 0;
-       }
+       // 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));
+
+       // 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 (!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 LyXFont::IGNORE_FAMILY;
+       return font_->family();
+}
+
+
 void ControlCharacter::setFamily(LyXFont::FONT_FAMILY val)
 {
        font_->setFamily(val);
 }
 
+
+LyXFont::FONT_SERIES ControlCharacter::getSeries() const
+{
+       if (!font_.get())
+               return LyXFont::IGNORE_SERIES;
+       return font_->series();
+}
+
+
 void ControlCharacter::setSeries(LyXFont::FONT_SERIES val)
 {
        font_->setSeries(val);
 }
 
+
+LyXFont::FONT_SHAPE ControlCharacter::getShape() const
+{
+       if (!font_.get())
+               return LyXFont::IGNORE_SHAPE;
+       return font_->shape();
+}
+
+
 void ControlCharacter::setShape(LyXFont::FONT_SHAPE val)
 {
        font_->setShape(val);
 }
 
+
+LyXFont::FONT_SIZE ControlCharacter::getSize() const
+{
+       if (!font_.get())
+               return LyXFont::IGNORE_SIZE;
+       return font_->size();
+}
+
+
 void ControlCharacter::setSize(LyXFont::FONT_SIZE val)
 {
        font_->setSize(val);
 }
 
+
+character::FONT_STATE ControlCharacter::getBar() const
+{
+       if (!font_.get())
+               return character::IGNORE;
+
+       if (font_->emph() == LyXFont::TOGGLE)
+               return character::EMPH_TOGGLE;
+
+       if (font_->underbar() == LyXFont::TOGGLE)
+               return character::UNDERBAR_TOGGLE;
+
+       if (font_->noun() == LyXFont::TOGGLE)
+               return character::NOUN_TOGGLE;
+
+       if (font_->emph() == LyXFont::IGNORE &&
+           font_->underbar() == LyXFont::IGNORE &&
+           font_->noun() == LyXFont::IGNORE)
+               return character::IGNORE;
+
+       return character::INHERIT;
+}
+
+
 void ControlCharacter::setBar(character::FONT_STATE val)
 {
        switch (val) {
@@ -91,7 +162,6 @@ void ControlCharacter::setBar(character::FONT_STATE val)
                font_->setEmph(LyXFont::IGNORE);
                font_->setUnderbar(LyXFont::IGNORE);
                font_->setNoun(LyXFont::IGNORE);
-               font_->setLatex(LyXFont::IGNORE);
                break;
 
        case character::EMPH_TOGGLE:
@@ -106,19 +176,24 @@ void ControlCharacter::setBar(character::FONT_STATE val)
                font_->setNoun(LyXFont::TOGGLE);
                break;
 
-       case character::LATEX_TOGGLE:
-               font_->setLatex(LyXFont::TOGGLE);
-               break;
-
        case character::INHERIT:
                font_->setEmph(LyXFont::INHERIT);
                font_->setUnderbar(LyXFont::INHERIT);
                font_->setNoun(LyXFont::INHERIT);
-               font_->setLatex(LyXFont::INHERIT);
                break;
        }
 }
 
+
+LColor::color ControlCharacter::getColor() const
+{
+       if (!font_.get())
+               return LColor::ignore;
+
+       return font_->color();
+}
+
+
 void ControlCharacter::setColor(LColor::color val)
 {
        switch (val) {
@@ -135,13 +210,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"))
@@ -154,6 +236,13 @@ void ControlCharacter::setLanguage(string const & val)
                font_->setLanguage(languages.getLanguage(val));
 }
 
+
+bool ControlCharacter::getToggleAll() const
+{
+       return toggleall_;
+}
+
+
 void ControlCharacter::setToggleAll(bool t)
 {
        toggleall_ = t;