]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_draw.C
Hopefully fix the problem with stateText() in lyxfont.C
[lyx.git] / src / mathed / math_draw.C
index a0f8409a3fe9ba6548e797fb4fec98a9f46c0ed7..c3c01b20250553456407cbd9ef56ec0595a1db6a 100644 (file)
@@ -7,7 +7,7 @@
  *
  *  Dependencies: Xlib, XForms
  *
- *  Copyright: (c) 1996, Alejandro Aguilar Sierra
+ *  Copyright: 1996, Alejandro Aguilar Sierra
  *
  *   Version: 0.8beta, Mathed & Lyx project.
  *
 #include "math_cursor.h"
 #include "math_parser.h"
 #include "debug.h"
+#include "lyxfont.h"
+#include "Painter.h"
 
-extern void mathed_set_font(short type, int style);
+using std::endl;
+
+extern LyXFont mathed_get_font(short type, int size);
 extern int mathed_char_width(short type, int style, byte c);
 extern int mathed_string_width(short type, int style, byte const* s, int ls);
 extern int mathed_string_height(short, int, byte const*, int, int&, int&);
 extern int mathed_char_height(short, int, byte, int&, int&);
-   
-GC canvasGC= 0, mathGC= 0, mathLineGC= 0, latexGC= 0, cursorGC= 0, mathFrameGC= 0;
-
-
-long unsigned int MathedInset::pm;
 
 void
-MathSpaceInset::Draw(int x, int y)
+MathSpaceInset::draw(Painter & pain, int x, int y)
 { 
 
 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
 
 // Sadly, HP-UX CC can't handle that kind of initialization.
 
-   XPoint p[4];
-   p[0].x = ++x;       p[0].y = y-3;
-   p[1].x = x;         p[1].y = y;
-   p[2].x = x+width-2; p[2].y = y;
-   p[3].x = x+width-2; p[3].y = y-3;
+   int xp[4];
+   int yp[4];
+   
+   xp[0] = ++x;            yp[0] = y - 3;
+   xp[1] = x;             yp[1] = y;
+   xp[2] = x + width - 2;  yp[2] = y;
+   xp[3] = x + width - 2;  yp[3] = y - 3;
 
-   XDrawLines(fl_display, pm,(space) ? latexGC: mathGC, p, 4, CoordModeOrigin);
-   XFlush(fl_display);
+   pain.lines(xp, yp, 4, (space) ? LColor::latex : LColor::math);
 }
 
+
 void 
-MathParInset::Draw(int x, int y)
+MathParInset::draw(Painter & pain, int x, int y)
 {
-   byte cx, cxp= 0;
-   int xp= 0, ls;
-   int asc= df_asc, des= 0;
+   byte cx, cxp = 0;
+   int xp = 0, ls;
+   int asc = df_asc, des = 0;
    bool limits = false;
     
    xo = x;  yo = y; 
    if (!array || array->empty()) {
-      mathed_set_font(LM_TC_VAR, 1);
        if (array) {
           MathedXIter data(this);
           data.GetPos(x, y);
        }
-      XDrawRectangle(fl_display, pm, mathLineGC, x, y-df_asc, df_width, df_asc);
-      XFlush(fl_display);
+       pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
       return;
    }  
    MathedXIter data(this);
@@ -75,15 +74,15 @@ MathParInset::Draw(int x, int y)
       data.GetPos(x, y);
       cx = data.GetChar();
       if (cx >= ' ') {
-        byte *s = data.GetString(ls);
-         drawStr(data.FCode(), size, x, y, s, ls);
+        byte * s = data.GetString(ls);
+         drawStr(pain, data.FCode(), size, x, y, s, ls);
          mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
          limits = false;
       } else {
          if (cx == 0) break;
         if (MathIsInset(cx)) {
            int yy = y;
-           MathedInset *p = data.GetInset();
+           MathedInset * p = data.GetInset();
            if (cx == LM_TC_UP) {
               if (limits) {
                  x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;  
@@ -101,7 +100,7 @@ MathParInset::Draw(int x, int y)
               asc = p->Ascent();
               des = p->Descent();
            }
-           p->Draw(x, yy);
+           p->draw(pain, x, yy);
            if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
               limits = p->GetLimits();
               if (limits) xp = p->Width();
@@ -110,17 +109,16 @@ MathParInset::Draw(int x, int y)
         } else 
           if (cx == LM_TC_TAB) {
               if ((cxp == cx || cxp == LM_TC_CR || data.IsFirst())) { // && objtype == L
-                  XDrawRectangle(fl_display, pm, mathLineGC,
-                                 x, y-df_asc, df_width, df_asc);
+                      pain.rectangle(x, y - df_asc, df_width, df_asc,
+                                     LColor::mathline);
               }
-          
-             XFlush(fl_display);
              data.Next();
              limits = false;
           } else
            if (cx == LM_TC_CR) {
                if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) { //  && objtype == LM_OT_MATRIX) {
-                 XDrawRectangle(fl_display, pm, mathLineGC, x, y-df_asc, df_width, df_asc);
+                       pain.rectangle(x, y - df_asc, df_width, df_asc,
+                                      LColor::mathline);
                }
                data.Next();
                limits = false;
@@ -135,8 +133,7 @@ MathParInset::Draw(int x, int y)
    }
    if (cxp == LM_TC_TAB || cxp == LM_TC_CR) { // && objtype == LM_OT_MATRIX) {
       data.GetPos(x, y);
-      XDrawRectangle(fl_display, pm, mathLineGC, x, y-df_asc, df_width, df_asc);
-      XFlush(fl_display);
+      pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
    }
 }
 
@@ -199,7 +196,7 @@ MathParInset::Metrics()
              }
              data.setTab(x-tb, tab);
              tb = x;
-             tab++;
+             ++tab;
              limits = false;                   
              data.Next();
          } else
@@ -249,19 +246,22 @@ MathParInset::Metrics()
 
 
 void
-MathSqrtInset::Draw(int x, int y)
+MathSqrtInset::draw(Painter & pain, int x, int y)
 { 
-   MathParInset::Draw(x+hmax+2, y); 
-   int h= ascent, d= descent, h2= Height()/2, w2 = (Height()>4*hmax)?hmax:hmax/2; 
-   XPoint p[4];
-   p[0].x = x + hmax + wbody, p[0].y = y-h;
-   p[1].x = x+hmax,    p[1].y = y-h;
-   p[2].x = x+w2,      p[2].y = y+d;
-   p[3].x = x,         p[3].y = y+d-h2;
-   XDrawLines(fl_display, pm, mathLineGC, p, 4, CoordModeOrigin);
-   XFlush(fl_display);
+   MathParInset::draw(pain, x + hmax + 2, y); 
+   int h = ascent;
+   int d = descent;
+   int h2 = Height() / 2;
+   int w2 = (Height() > 4 * hmax) ? hmax : hmax / 2; 
+   int xp[4], yp[4];
+   xp[0] = x + hmax + wbody; yp[0] = y - h;
+   xp[1] = x + hmax;         yp[1] = y - h;
+   xp[2] = x + w2;           yp[2] = y + d;
+   xp[3] = x;                yp[3] = y + d - h2;
+   pain.lines(xp, yp, 4, LColor::mathline);
 }
 
+
 void
 MathSqrtInset::Metrics()
 {
@@ -270,28 +270,29 @@ MathSqrtInset::Metrics()
    descent += 2;
    int a, b;
    hmax = mathed_char_height(LM_TC_VAR, size, 'I', a, b);
-   if (hmax<10) hmax = 10;
+   if (hmax < 10) hmax = 10;
    wbody = width + 4;
    width += hmax + 4;
 }
 
+
 void
-MathFracInset::Draw(int x, int y)
+MathFracInset::draw(Painter & pain, int x, int y)
 { 
     short idxp = idx;
     short sizex = size;
     
     idx = 0;
-    if (size == LM_ST_DISPLAY) size++;
-    MathParInset::Draw(x+(width-w0)/2, y - des0);
-    den->Draw(x+(width-w1)/2, y + den->Ascent() + 2 - dh);
+    if (size == LM_ST_DISPLAY) ++size;
+    MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
+    den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
     size = sizex;
     if (objtype == LM_OT_FRAC)
-      XDrawLine(fl_display, pm, mathLineGC, x+2, y-dh, x+width-4, y - dh);
-    XFlush(fl_display);
+           pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
     idx = idxp;
 }
 
+
 void
 MathFracInset::Metrics()
 {
@@ -302,7 +303,7 @@ MathFracInset::Metrics()
     short idxp = idx;
     short sizex = size; 
     idx = 0;
-    if (size == LM_ST_DISPLAY) size++
+    if (size == LM_ST_DISPLAY) ++size
     MathParInset::Metrics();
     size = sizex;
     w0 = width;
@@ -318,16 +319,16 @@ MathFracInset::Metrics()
 
 
 void
-MathBigopInset::Draw(int x, int y)
+MathBigopInset::draw(Painter & pain, int x, int y)
 {
    int ls;
    char c;
    char const *s;
    short t;
    
-   if (sym<256 || sym == LM_oint) {
+   if (sym < 256 || sym == LM_oint) {
       ls = 1;
-      c = (sym == LM_oint) ? LM_int: sym;
+      c = (sym == LM_oint) ? LM_int : sym;
       s = &c;
       t = LM_TC_BSYM;
    } else {
@@ -335,37 +336,38 @@ MathBigopInset::Draw(int x, int y)
       ls = strlen(name);
       t = LM_TC_TEXTRM;
    }
-   mathed_set_font(t, size);
    if (sym == LM_oint) {
-      XDrawArc(fl_display, pm, mathLineGC, x, y-5*width/4, width, width, 0, 23040);
-      XFlush(fl_display);
-      x++;
+          pain.arc(x, y - 5 * width / 4, width, width, 0, 360*64,
+                   LColor::mathline);
+          ++x;
    }
-   XDrawString(fl_display, pm, mathGC, x, y, s, ls);
-   XFlush(fl_display);
+   pain.text(x, y, s, ls, mathed_get_font(t, size));
 }
 
+
 void
 MathBigopInset::Metrics()
 {   
-   int ls;
-   char c;
-   char const *s;
-   short t;
-
-   if (sym<256 || sym == LM_oint) {
-      ls = 1;
-      c = (sym == LM_oint) ? LM_int: sym;
-      s = &c;
-      t = LM_TC_BSYM;
-   } else {
-      s = name;
-      ls = strlen(name);
-      t = LM_TC_TEXTRM;
-   }
-   mathed_set_font(t, size);
-   mathed_string_height(t, size, reinterpret_cast<const unsigned char*>(s), ls, ascent, descent);
-   width = mathed_string_width(t, size, reinterpret_cast<const unsigned char*>(s), ls);
-   if (sym == LM_oint) width += 2;
+       int ls;
+       char c;
+       char const *s;
+       short t;
+       
+       if (sym < 256 || sym == LM_oint) {
+               ls = 1;
+               c = (sym == LM_oint) ? LM_int: sym;
+               s = &c;
+               t = LM_TC_BSYM;
+       } else {
+               s = name;
+               ls = strlen(name);
+               t = LM_TC_TEXTRM;
+       }
+       mathed_string_height(t, size,
+                            reinterpret_cast<const unsigned char*>(s),
+                            ls, ascent, descent);
+       width = mathed_string_width(t, size,
+                                   reinterpret_cast<const unsigned char*>(s),
+                                   ls);
+       if (sym == LM_oint) width += 2;
 }
-