*
* Dependencies: Xlib, XForms
*
- * Copyright: (c) 1996, Alejandro Aguilar Sierra
+ * Copyright: 1996, Alejandro Aguilar Sierra
*
* Version: 0.8beta, Mathed & Lyx project.
*
#include "math_root.h"
#include "support/lstrings.h"
#include "debug.h"
-
-extern void mathed_set_font(short type, int style);
-
-extern GC canvasGC, mathGC, latexGC, cursorGC, mathFrameGC;
+#include "LColor.h"
+#include "Painter.h"
static LyxArrayBase * selarray = 0;
-inline bool IsAlpha(char c)
+using std::endl;
+
+inline
+bool IsAlpha(char c)
{
return ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z');
}
// This was very smaller, I'll change it later
-inline bool IsMacro(short tok, int id)
+inline
+bool IsMacro(short tok, int id)
{
return (tok != LM_TK_STACK && tok != LM_TK_FRAC && tok != LM_TK_SQRT
&& tok != LM_TK_WIDE
// Yes, mathed isn't using string yet.
-inline char * strnew(char const * s)
+inline
+char * strnew(char const * s)
{
char * s1 = new char[strlen(s)+1];
strcpy(s1, s);
}
-void MathedCursor::Draw(long unsigned pm, int x, int y)
+void MathedCursor::draw(Painter & pain, int x, int y)
{
-// lyxerr << "Cursor[" << x << " " << y << "] ";
- win = pm; // win = (mathedCanvas) ? mathedCanvas: pm;
- par->Metrics();
- int w = par->Width()+2, a = par->Ascent()+1, h = par->Height()+1;
- if (par->GetType() > LM_OT_PAR) { a += 4; h += 8; }
-
- if (!canvasGC) mathed_set_font(LM_TC_VAR, 1);
- // XFillRectangle(fl_display, pm, canvasGC, x, y-a, w, h);
- XDrawRectangle(fl_display, pm, mathFrameGC, x - 1, y - a, w, h);
- XFlush(fl_display);
- MathParInset::pm = pm;
- par->Draw(x, y);
- cursor->Adjust();
+ // lyxerr << "Cursor[" << x << " " << y << "] ";
+ //win = pm; // win = (mathedCanvas) ? mathedCanvas: pm;
+ par->Metrics();
+ int w = par->Width() + 2;
+ int a = par->Ascent() + 1;
+ int h = par->Height() + 1;
+ if (par->GetType() > LM_OT_PAR) { a += 4; h += 8; }
+
+ pain.rectangle(x - 1, y - a, w, h, LColor::mathframe);
+
+ par->draw(pain, x, y);
+ cursor->Adjust();
}
-void MathedCursor::Redraw()
+void MathedCursor::Redraw(Painter & pain)
{
lyxerr[Debug::MATHED] << "Mathed: Redrawing!" << endl;
- par->Metrics();
- int w = par->Width(), h = par->Height();
- int x, y;
- par->GetXY(x, y);
- mathed_set_font(LM_TC_VAR, 1);
- XFillRectangle(fl_display, win, canvasGC, x, y-par->Ascent(), w, h);
- XFlush(fl_display);
- MathParInset::pm = win;
- par->Draw(x, y);
+ par->Metrics();
+ int w = par->Width(), h = par->Height();
+ int x, y;
+ par->GetXY(x, y);
+ //mathed_set_font(LM_TC_VAR, 1);
+ pain.fillRectangle(x, y - par->Ascent(),
+ x + w, y - par->Ascent() + h,
+ LColor::mathbg);
+ par->draw(pain, x, y);
}
}
-XPoint * MathedCursor::SelGetArea(int & np)
+void MathedCursor::SelGetArea(int ** xp, int ** yp, int & np)
{
+ static int xpoint[10];
+ static int ypoint[10];
+
if (!selection) {
np = 0;
- return 0;
+ xpoint[0] = 0;
+ ypoint[0] = 0;
+ *xp = &xpoint[0];
+ *yp = &ypoint[0];
+ return;
}
- static XPoint point[10];
-
// single row selection
- int i = 0, x, y, a, d, xo, yo, x1, y1, a1, d1; //, p1, p2;
+ int i = 0, x, y, a, d, xo, yo, x1, y1, a1, d1;
// Balance anchor and cursor
SelBalance();
anchor->GetPos(x, y);
anchor->getAD(a, d);
- point[i].x = x;
- point[i++].y = y+d;
- point[i].x = x;
- point[i++].y = y-a;
+ xpoint[i] = x;
+ ypoint[i++] = y + d;
+ xpoint[i] = x;
+ ypoint[i++] = y - a;
if (y != y1) {
- point[i].x = xo + w;
- point[i++].y = y - a;
- if (x1 < xo + w) {
- point[i].x = xo + w;
- point[i++].y = y1 - a;
- }
+ xpoint[i] = xo + w;
+ ypoint[i++] = y - a;
+
+ if (x1 < xo + w) {
+ xpoint[i] = xo + w;
+ ypoint[i++] = y1 - a;
+ }
}
-
- point[i].x = x1;
- point[i++].y = y1 - a;
- point[i].x = x1;
- point[i++].y = y1 + d;
+
+ xpoint[i] = x1;
+ ypoint[i++] = y1 - a;
+ xpoint[i] = x1;
+ ypoint[i++] = y1 + d;
if (y != y1) {
- point[i].x = xo;
- point[i++].y = y1 + d;
- if (x > xo) {
- point[i].x = xo;
- point[i++].y = y + d;
- }
+ xpoint[i] = xo;
+ ypoint[i++] = y1 + d;
+ if (x > xo) {
+ xpoint[i] = xo;
+ ypoint[i++] = y + d;
+ }
}
- point[i].x = point[0].x;
- point[i++].y = point[0].y;
+ xpoint[i] = xpoint[0];
+ ypoint[i++] = ypoint[0];
+
+ *xp = &xpoint[0];
+ *yp = &ypoint[0];
np = i;
// lyxerr << "AN[" << x << " " << y << " " << x1 << " " << y1 << "] ";
// lyxerr << "MT[" << a << " " << d << " " << a1 << " " << d1 << "] ";
-// for (i= 0; i<np; i++)
+// for (i = 0; i < np; ++i)
// lyxerr << "XY[" << point[i].x << " " << point[i].y << "] ";
- return &point[0];
}
-
void MathedCursor::setAccent(int ac)
{
if (ac > 0 && accent < 8) {