This patch was so good to do I just had to commit it.

It doesn't actually break anything particularly, since nrel was already borked.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5164 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-08-29 08:28:58 +00:00
parent 94045ff809
commit e133fedf82
4 changed files with 13 additions and 311 deletions

View File

@ -1,3 +1,9 @@
2002-08-29 John Levon <levon@movementarian.org>
* MathsSymbols.h:
* MathsSymbols.C:
* Toolbar_pimpl.C: use XPMs for toolbar instead of gook
2002-08-29 John Levon <levon@movementarian.org>
* MathsSymbols.C: implement splitting for AMS. nrel

View File

@ -7,50 +7,10 @@
* \author John Levon, moz@compsoc.man.ac.uk
*/
#include <config.h>
#include <algorithm>
#include XPM_H_LOCATION
#ifdef __GNUG__
#pragma implementation
#endif
#include "support/LAssert.h"
#include "support/lstrings.h"
#include "debug.h"
#include "MathsSymbols.h"
using std::max;
using std::endl;
using std::ostream;
#ifndef CXX_GLOBAL_CSTD
using std::strstr;
#endif
#include FORMS_H_LOCATION
/* Latex code for those bitmaps */
#include "greek.xbm"
#include "arrows.xbm"
#include "brel.xbm"
#include "bop.xbm"
#include "misc.xbm"
#include "varsz.xbm"
#include "dots.xbm"
#include "ams_misc.xbm"
#include "ams_arrows.xbm"
#include "ams_rel.xbm"
#include "ams_nrel.xbm"
#include "ams_ops.xbm"
#include "mathed/math_parser.h"
#include "frac.xpm"
#include "sqrt.xpm"
char const * function_names[] = {
"arccos", "arcsin", "arctan", "arg", "bmod",
"cos", "cosh", "cot", "coth", "csc", "deg",
@ -224,250 +184,3 @@ char const * latex_ams_ops[] = {
};
int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
static char const ** mathed_get_pixmap_from_icon(int d)
{
switch (d) {
case MM_FRAC: return frac;
case MM_SQRT: return sqrt_xpm;
default: return 0;
}
}
static char const ** pixmapFromBitmapData(char const * s, int wx, int hx)
{
char const ** data = 0;
int id = -1;
int i = 0;
for (; i < 11; ++i) {
char const ** latex_str = 0;
switch (i) {
case 0: latex_str = latex_greek; break;
case 1: latex_str = latex_bop; break;
case 2: latex_str = latex_brel; break;
case 3: latex_str = latex_arrow; break;
case 4: latex_str = latex_varsz; break;
case 5: latex_str = latex_misc; break;
case 6: latex_str = latex_ams_misc; break;
case 7: latex_str = latex_ams_arrows; break;
case 8: latex_str = latex_ams_rel; break;
case 9: latex_str = latex_ams_nrel; break;
case 10: latex_str = latex_ams_ops; break;
// Add AMS stuff here -- MV
}
for (int k = 0; latex_str[k][0] > ' '; ++k) {
if (compare(latex_str[k], s) == 0) {
id = k;
break;
}
}
if (id >= 0) break;
}
if (i < 11 && id >= 0) {
unsigned char const * bdata = 0;
int w = 0;
int h = 0;
int dw = 0;
int dh = 0;
lyxerr [Debug::MATHED] << "Imando " << i << ", " << id << endl;
switch (i) {
case 0:
if (id <= 10) {
w = Greek_width;
h = Greek_height;
bdata = Greek_bits;
dw = 6;
dh = 2;
} else {
w = greek_width;
h = greek_height;
bdata = greek_bits;
dw = 7;
dh = 4;
id -= 11;
}
break;
case 1:
w = bop_width;
h = bop_height;
bdata = bop_bits;
dw = 4;
dh = 8;
break;
case 2:
w = brel_width;
h = brel_height;
bdata = brel_bits;
dw = 4;
dh = 9;
break;
case 3:
if (id < 20) {
w = arrow_width;
h = arrow_height;
bdata = arrow_bits;
dw = 5;
dh = 4;
} else if (id > 28) {
w = darrow_width;
h = darrow_height;
bdata = darrow_bits;
dw = 2;
dh = 2;
id -= 29;
} else {
w = larrow_width;
h = larrow_height;
bdata = larrow_bits;
dw = 2;
dh = 4;
id -= 20;
}
break;
case 4:
w = varsz_width;
h = varsz_height;
bdata = varsz_bits;
dw = 3;
dh = 5;
break;
case 5:
if (id < 29) {
w = misc_width;
h = misc_height;
bdata = misc_bits;
dw = 5;
dh = 6;
} else if (id > 36) {
w = misc3_width;
h = misc3_height;
bdata = misc3_bits;
dw = 3;
dh = 2;
id -= 37;
} else {
w = misc2_width;
h = misc2_height;
bdata = misc2_bits;
dw = 2;
dh = 2;
id -= 29;
}
break;
case 6:
if (id < 10) {
w = ams1_width;
h = ams1_height;
bdata = ams1_bits;
dw = 5;
dh = 2;
} else {
w = ams7_width;
h = ams7_height;
bdata = ams7_bits;
dw = 3;
dh = 9;
id -= 9;
}
break;
case 7:
if (id < 33) {
w = ams2_width;
h = ams2_height;
bdata = ams2_bits;
dw = 3;
dh = 11;
} else {
w = ams3_width;
h = ams3_height;
bdata = ams3_bits;
dw = 3;
dh = 2;
id -= 32;
}
break;
case 8:
w = ams_rel_width;
h = ams_rel_height;
bdata = ams_rel_bits;
dw = 6;
dh = 11;
break;
// nrel is BROKEN
case 9:
w = ams_nrel_width;
h = ams_nrel_height;
bdata = ams_nrel_bits;
dw = 6;
dh = 9;
break;
case 10:
w = ams_ops_width;
h = ams_ops_height;
bdata = ams_ops_bits;
dw = 3;
dh = 8;
break;
}
int ww = w / dw;
int hh = h / dh;
XImage * xima = XCreateImage(fl_get_display(), 0, 1, XYBitmap, 0,
const_cast<char*>(reinterpret_cast<char const *>(bdata)), w, h, 8, 0);
xima->byte_order = LSBFirst;
xima->bitmap_bit_order = LSBFirst;
int x = (id % dw) * ww;
int y = (id/dw) * hh;
if (ww > wx) ww = wx;
if (hh > hx) hh = hx;
XImage * sbima = XSubImage(xima, x, y, ww, hh);
XpmCreateDataFromImage(fl_get_display(), const_cast<char***>(&data), sbima, sbima, 0);
// Dirty hack to get blue symbols quickly
char * sx = const_cast<char*>(strstr(data[2], "FFFFFFFF"));
if (sx) {
for (int k = 0; k < 8; ++k) sx[k] = '0';
}
// XDestroyImage(xima);
}
return data;
}
char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx)
{
lyx::Assert(arg);
lyxerr << arg << endl;
char const ** data = 0;
latexkeys const * l = in_word_set(arg);
if (!l)
return 0;
if (l->inset == "frac")
data = mathed_get_pixmap_from_icon(MM_FRAC);
else if (l->inset == "sqrt")
data = mathed_get_pixmap_from_icon(MM_SQRT);
else if (
l->inset == "lyxsymb" ||
l->inset == "cmr" ||
l->inset == "cmsy" ||
l->inset == "cmex" ||
l->inset == "cmm" ||
l->inset == "msa" ||
l->inset == "msb" )
// I have to use directly the bitmap data since the
// bitmap tables are not yet created when this
// function is called.
data = pixmapFromBitmapData(arg, wx, hx);
return data;
}

View File

@ -11,10 +11,6 @@
#ifndef MATHS_SYMBOLS_H
#define MATHS_SYMBOLS_H
#ifdef __GNUG__
#pragma interface
#endif
/// values used by the xforms callbacks
enum MathsCallbackValues {
MM_GREEK,
@ -70,8 +66,4 @@ extern int const nr_latex_ams_nrel;
extern char const * latex_ams_ops[];
extern int const nr_latex_ams_ops;
char const ** get_pixmap_from_symbol(char const *, int, int);
#endif /* MATHS_SYMBOLS_H */

View File

@ -23,7 +23,6 @@
#include "FuncStatus.h"
#include "buffer.h"
#include "funcrequest.h"
#include "MathsSymbols.h"
#include "gettext.h"
#include "Tooltips.h"
#include FORMS_H_LOCATION
@ -245,7 +244,7 @@ extern "C" {
}
void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
void setPixmap(FL_OBJECT * obj, int action)
{
string xpm_name;
FuncRequest ev = lyxaction.retrieveActionArg(action);
@ -258,6 +257,11 @@ void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
string fullname = LibFileSearch("images", xpm_name, "xpm");
if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
string arg = ev.argument.substr(1);
fullname = LibFileSearch("images/math/", arg, "xpm");
}
if (!fullname.empty()) {
lyxerr[Debug::GUI] << "Full icon name is `"
<< fullname << "'" << endl;
@ -265,19 +269,6 @@ void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
return;
}
if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
char const ** pixmap = get_pixmap_from_symbol(ev.argument.c_str(),
buttonwidth,
height);
if (pixmap) {
lyxerr[Debug::GUI] << "Using mathed-provided icon"
<< endl;
fl_set_pixmapbutton_data(obj,
const_cast<char **>(pixmap));
return;
}
}
lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
fullname = LibFileSearch("images", "unknown", "xpm");
if (!fullname.empty()) {
@ -337,7 +328,7 @@ void Toolbar::Pimpl::add(int action)
// The view that this object belongs to.
obj->u_vdata = owner_;
setPixmap(obj, action, buttonwidth, height);
setPixmap(obj, action);
// we must remember to update the positions
xpos += buttonwidth;
// ypos is constant