]> git.lyx.org Git - lyx.git/blobdiff - src/metricsinfo.C
more cursor dispatch
[lyx.git] / src / metricsinfo.C
index 34b504fd3d00f18ce3d7458b14bba62c058e661f..1283c687f2e5b8fb2f75bd10b2d411c5acd4964f 100644 (file)
@@ -1,31 +1,53 @@
+/**
+ * \file metricsinfo.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "metricsinfo.h"
 #include "mathed/math_support.h"
 #include "frontends/Painter.h"
-#include "debug.h"
+#include "BufferView.h"
+#include "LColor.h"
 
+using std::string;
 
 
 MetricsBase::MetricsBase()
-       : font(), style(LM_ST_TEXT), fontname("mathnormal"),
-         restrictwidth(false), textwidth(0)
+       : bv(0), font(), style(LM_ST_TEXT), fontname("mathnormal"),
+         textwidth(0)
 {}
 
 
 
+MetricsBase::MetricsBase(BufferView * b, LyXFont const & f, int w)
+       : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
+         textwidth(w)
+{}
+
+
 
 MetricsInfo::MetricsInfo()
-       : fullredraw(false)
 {}
 
 
+MetricsInfo::MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth)
+       : base(bv, font, textwidth)
+{}
 
 
-PainterInfo::PainterInfo(Painter & p)
-       : pain(p)
-{}
+
+PainterInfo::PainterInfo(BufferView * bv)
+       : pain(bv->painter())
+{
+       base.bv = bv;
+}
 
 
 void PainterInfo::draw(int x, int y, char c)
@@ -42,11 +64,9 @@ Styles smallerScriptStyle(Styles st)
                        return LM_ST_SCRIPT;
                case LM_ST_SCRIPT:
                case LM_ST_SCRIPTSCRIPT:
+               default: // shut up compiler
                        return LM_ST_SCRIPTSCRIPT;
        }
-       // shut up compiler
-       lyxerr << "should not happen\n";
-       return LM_ST_DISPLAY;
 }
 
 ScriptChanger::ScriptChanger(MetricsBase & mb)
@@ -64,13 +84,12 @@ Styles smallerFracStyle(Styles st)
                        return LM_ST_SCRIPT;
                case LM_ST_SCRIPT:
                case LM_ST_SCRIPTSCRIPT:
+               default: // shut up compiler
                        return LM_ST_SCRIPTSCRIPT;
        }
-       // shut up compiler
-       lyxerr << "should not happen\n";
-       return LM_ST_DISPLAY;
 }
 
+
 FracChanger::FracChanger(MetricsBase & mb)
        : StyleChanger(mb, smallerFracStyle(mb.style))
 {}
@@ -127,9 +146,11 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name)
 {
        save_ = mb;
        mb.fontname = name;
+       mb.font = LyXFont();
        augmentFont(mb.font, name);
 }
 
+
 FontSetChanger::~FontSetChanger()
 {
        orig_ = save_;
@@ -140,8 +161,7 @@ WidthChanger::WidthChanger(MetricsBase & mb, int w)
        :       Changer<MetricsBase>(mb)
 {
        save_ = mb;
-       mb.restrictwidth = true;
-       mb.textwidth     = w;
+       mb.textwidth = w;
 }
 
 
@@ -149,3 +169,19 @@ WidthChanger::~WidthChanger()
 {
        orig_ = save_;
 }
+
+
+
+
+ColorChanger::ColorChanger(LyXFont & font, string const & color)
+       : Changer<LyXFont, string>(font)
+{
+       save_ = lcolor.getFromLyXName(color);
+       font.setColor(lcolor.getFromLyXName(color));
+}
+
+
+ColorChanger::~ColorChanger()
+{
+       orig_.setColor(lcolor.getFromLyXName(save_));
+}