Uwe Stöhr wrote:
Abdelrazak Younes schrieb:
As I said, I am not discussing the merging. I would just prefer many
small methods instead of a big fat one.
I don't understand, what do you propose?
This... not tested nor compiled...
Abdel.
Index: insets/InsetBranch.cpp
===================================================================
--- insets/InsetBranch.cpp (revision 29119)
+++ insets/InsetBranch.cpp (working copy)
@@ -141,13 +141,12 @@
case LFUN_BRANCH_ACTIVATE:
case LFUN_BRANCH_DEACTIVATE: {
- // FIXME: I do not like this cast, but have no other idea...
- Buffer * realbuffer = const_cast<Buffer *>(buffer().masterBuffer());
- BranchList & branchlist = realbuffer->params().branchlist();
- Branch * ourBranch = branchlist.find(params_.branch);
- if (!ourBranch)
+ BranchList const & branchlist = buffer().masterBuffer()->
+ params().branchlist();
+ Branch const * our_branch = branchlist.find(params_.branch);
+ if (!our_branch)
break;
- ourBranch->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE);
+ const_cast<Branch *>(our_branch)->setSelected(cmd.action == LFUN_BRANCH_ACTIVATE);
break;
}
Index: mathed/InsetMathFrac.h
===================================================================
--- mathed/InsetMathFrac.h (revision 29119)
+++ mathed/InsetMathFrac.h (working copy)
@@ -87,6 +87,14 @@
Inset * clone() const;
///
Kind kind_;
+private:
+ void drawFrac(PainterInfo & pi, int x, int y) const;
+ void drawCFrac(PainterInfo & pi, int x, int y) const;
+ void drawDFrac(PainterInfo & pi, int x, int y) const;
+ void drawTFrac(PainterInfo & pi, int x, int y) const;
+ void drawNiceFrac(PainterInfo & pi, int x, int y) const;
+ void drawUnitFrac(PainterInfo & pi, int x, int y) const;
+ void drawUnit(PainterInfo & pi, int x, int y) const;
};
Index: mathed/InsetMathFrac.cpp
===================================================================
--- mathed/InsetMathFrac.cpp (revision 29119)
+++ mathed/InsetMathFrac.cpp (working copy)
@@ -24,6 +24,8 @@
#include "frontends/Painter.h"
+#include "support/lassert.h"
+
using namespace std;
namespace lyx {
@@ -214,99 +216,175 @@
}
-void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
+void InsetMathFrac::drawUnit(PainterInfo & pi, int x, int y) const
{
- setPosCache(pi, x, y);
- Dimension const dim = dimension(*pi.base.bv);
Dimension const dim0 = cell(0).dimension(*pi.base.bv);
- int m = x + dim.wid / 2;
- if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
- if (nargs() == 1) {
- ShapeChanger dummy2(pi.base.font, UP_SHAPE);
- cell(0).draw(pi, x + 1, y);
- } else if (nargs() == 2) {
- cell(0).draw(pi, x + 1, y);
- ShapeChanger dummy2(pi.base.font, UP_SHAPE);
- cell(1).draw(pi, x + dim0.width() + 5, y);
- } else {
- cell(2).draw(pi, x + 1, y);
- ShapeChanger dummy2(pi.base.font, UP_SHAPE);
- FracChanger dummy(pi.base);
- Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- Dimension const dim2 = cell(2).dimension(*pi.base.bv);
- int xx = x + dim2.wid + 5;
- cell(0).draw(pi, xx + 2,
+ switch (nargs()) {
+ case 1: {
+ ShapeChanger dummy2(pi.base.font, UP_SHAPE);
+ cell(0).draw(pi, x + 1, y);
+ break;
+ }
+ case 2: {
+ cell(0).draw(pi, x + 1, y);
+ ShapeChanger dummy2(pi.base.font, UP_SHAPE);
+ cell(1).draw(pi, x + dim0.width() + 5, y);
+ break;
+ }
+ case 3: {
+ cell(2).draw(pi, x + 1, y);
+ ShapeChanger dummy2(pi.base.font, UP_SHAPE);
+ FracChanger dummy(pi.base);
+ Dimension const dim1 = cell(1).dimension(*pi.base.bv);
+ Dimension const dim2 = cell(2).dimension(*pi.base.bv);
+ int xx = x + dim2.wid + 5;
+ cell(0).draw(pi, xx + 2,
y - dim0.des - 5);
- cell(1).draw(pi, xx + dim0.width() + 5,
+ cell(1).draw(pi, xx + dim0.width() + 5,
y + dim1.asc / 2);
- }
- } else {
+ break;
+ }
+ default:
+ LASSERT(false, return);
+ }
+}
+
+
+void InsetMathFrac::drawUnitFrac(PainterInfo & pi, int x, int y) const
+{
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ if (narg() == 2) {
+ ShapeChanger dummy2(pi.base.font, UP_SHAPE);
+ cell(0).draw(pi, x + 2, y - dim0.des - 5);
+ cell(1).draw(pi, x + dim0.width() + 5, y + dim1.asc / 2);
+ } else { // narg() == 3
+ cell(2).draw(pi, x + 1, y);
+ ShapeChanger dummy2(pi.base.font, UP_SHAPE);
FracChanger dummy(pi.base);
Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- if (kind_ == NICEFRAC) {
- cell(0).draw(pi, x + 2,
- y - dim0.des - 5);
- cell(1).draw(pi, x + dim0.width() + 5,
- y + dim1.asc / 2);
- } else if (kind_ == UNITFRAC) {
- ShapeChanger dummy2(pi.base.font, UP_SHAPE);
- cell(0).draw(pi, x + 2,
- y - dim0.des - 5);
- cell(1).draw(pi, x + dim0.width() + 5,
- y + dim1.asc / 2);
- } else if (kind_ == CFRAC) {
- if (nargs() == 2) {
- // cfrac is always in display size
- StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
- Dimension const dim0 = cell(0).dimension(*pi.base.bv);
- Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- int m = x + dim.wid / 2;
- cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
- cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
- } else {
- // cfrac is always in display size
- StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
- // use text font for the optional argument
- FontSetChanger dummy3(pi.base, "textnormal");
- Dimension const dim2 = cell(2).dimension(*pi.base.bv);
- int w = mathed_char_width(pi.base.font, '[');
- drawStrBlack(pi, x, y, from_ascii("["));
- x += w;
- cell(2).draw(pi, x + 1, y);
- x += dim2.wid;
- drawStrBlack(pi, x, y, from_ascii("]"));
- x += w;
- // return to math font
- FontSetChanger dummy4(pi.base, "mathnormal");
- Dimension const dim0 = cell(0).dimension(*pi.base.bv);
- Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- int m = x + dim.wid / 2;
- cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
- cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
- }
- } else if (kind_ == DFRAC) {
- // dfrac is in always in display size
- StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
- //Dimension const dim = dimension(*pi.base.bv);
- Dimension const dim0 = cell(0).dimension(*pi.base.bv);
- Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- int m = x + dim.wid / 2;
- cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
- cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
- } else if (kind_ == TFRAC) {
- // tfrac is in always in text size
- StyleChanger dummy2(pi.base, LM_ST_SCRIPT);
- Dimension const dim0 = cell(0).dimension(*pi.base.bv);
- Dimension const dim1 = cell(1).dimension(*pi.base.bv);
- int m = x + dim.wid / 2;
- cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
- cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
- } else {
- // FRAC
- cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
- cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
- }
+ Dimension const dim2 = cell(2).dimension(*pi.base.bv);
+ int xx = x + dim2.wid + 5;
+ cell(0).draw(pi, xx + 2,
+ y - dim0.des - 5);
+ cell(1).draw(pi, xx + dim0.width() + 5,
+ y + dim1.asc / 2);
}
+}
+
+
+void InsetMathFrac::drawCFrac(PainterInfo & pi, int x, int y) const
+{
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ Dimension const dim1 = cell(1).dimension(*pi.base.bv);
+ switch (nargs()) {
+ case 2: {
+ // cfrac is always in display size
+ StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
+ int m = x + dim.wid / 2;
+ cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+ cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
+ break;
+ }
+ case 3: {
+ // cfrac is always in display size
+ StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
+ // use text font for the optional argument
+ FontSetChanger dummy3(pi.base, "textnormal");
+ Dimension const dim2 = cell(2).dimension(*pi.base.bv);
+ int w = mathed_char_width(pi.base.font, '[');
+ drawStrBlack(pi, x, y, from_ascii("["));
+ x += w;
+ cell(2).draw(pi, x + 1, y);
+ x += dim2.wid;
+ drawStrBlack(pi, x, y, from_ascii("]"));
+ x += w;
+ // return to math font
+ FontSetChanger dummy4(pi.base, "mathnormal");
+ int m = x + dim.wid / 2;
+ cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+ cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
+ break;
+ }
+ default:
+ LASSERT(false, return);
+ }
+}
+
+
+void InsetMathFrac::drawNiceFrac(PainterInfo & pi, int x, int y) const
+{
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ Dimension const dim1 = cell(1).dimension(*pi.base.bv);
+ cell(0).draw(pi, x + 2, y - dim0.des - 5);
+ cell(1).draw(pi, x + dim0.width() + 5, y + dim1.asc / 2);
+}
+
+
+void InsetMathFrac::drawDFrac(PainterInfo & pi, int x, int y) const
+{
+ // dfrac is in always in display size
+ StyleChanger dummy2(pi.base, LM_ST_DISPLAY);
+ //Dimension const dim = dimension(*pi.base.bv);
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ Dimension const dim1 = cell(1).dimension(*pi.base.bv);
+ int m = x + dim.wid / 2;
+ cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+ cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
+}
+
+
+void InsetMathFrac::drawTFrac(PainterInfo & pi, int x, int y) const
+{
+ // tfrac is in always in text size
+ StyleChanger dummy2(pi.base, LM_ST_SCRIPT);
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ Dimension const dim1 = cell(1).dimension(*pi.base.bv);
+ int m = x + dim.wid / 2;
+ cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+ cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
+}
+
+
+void InsetMathFrac::drawFrac(PainterInfo & pi, int x, int y) const
+{
+ cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+ cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5);
+}
+
+
+void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
+{
+ setPosCache(pi, x, y);
+ Dimension const dim = dimension(*pi.base.bv);
+ Dimension const dim0 = cell(0).dimension(*pi.base.bv);
+ int m = x + dim.wid / 2;
+ switch (kind_) {
+ case FRAC:
+ drawFrac(pi, x, y);
+ break;
+ case CFRAC:
+ drawCFrac(pi, x, y);
+ break;
+ case DFRAC:
+ drawDFrac(pi, x, y);
+ break;
+ case TFRAC:
+ drawTFrac(pi, x, y);
+ break;
+ case NICEFRAC:
+ drawNiceFrac(pi, x, y);
+ break;
+ case UNITFRAC:
+ drawUnitFrac(pi, x, y);
+ break;
+ case UNIT:
+ drawUnit(pi, x, y);
+ break;
+ case OVER:
+ case ATOP:
+ // Nothing to do?
+ break;
+ }
if (kind_ == NICEFRAC || kind_ == UNITFRAC) {
// Diag line:
int xx = x;