X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_symbols.C;h=8d268a9a93ff8add142c9eb4420cd518f9186664;hb=8dccec5c46a1689fe3ea37144252e952771e1e1c;hp=4457fc29e892a4b610678faaa049e50815d8e757;hpb=27de1486ca34aaad446adb798d71a77d6f6304da;p=lyx.git diff --git a/src/mathed/math_symbols.C b/src/mathed/math_symbols.C index 4457fc29e8..8d268a9a93 100644 --- a/src/mathed/math_symbols.C +++ b/src/mathed/math_symbols.C @@ -22,34 +22,29 @@ #pragma implementation "math_panel.h" #endif +#include +using std::max; + #include "lyx_main.h" #include "buffer.h" #include "BufferView.h" #include "minibuffer.h" #include "lyxrc.h" -#include "lyxlib.h" #include "LyXView.h" -#include "error.h" +#include "support/lstrings.h" +#include "debug.h" #include "formula.h" #include "math_panel.h" #include "math_parser.h" -// $Id: math_symbols.C,v 1.1 1999/09/27 18:44:40 larsbj Exp $ - -#if !defined(lint) && !defined(WITH_WARNINGS) -static char vcid[] = "$Id: math_symbols.C,v 1.1 1999/09/27 18:44:40 larsbj Exp $"; -#endif /* lint */ - -extern void SmallUpdate(signed char); extern void BeforeChange(); extern void Update(signed char); -extern int UnlockInset(UpdatableInset*); +extern int UnlockInset(UpdatableInset *); extern short greek_kb_flag; -extern MiniBuffer *minibuffer; -extern BufferView *current_view; +extern BufferView * current_view; /* Bitmaps */ #include "greek.xbm" @@ -61,7 +56,7 @@ extern BufferView *current_view; #include "dots.xbm" /* Latex code for those bitmaps */ -static char const *latex_greek[] = { +static char const * latex_greek[] = { "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma", "Upsilon", "Phi", "Psi", "Omega", "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta", @@ -70,7 +65,7 @@ static char const *latex_greek[] = { "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", "" }; -static char const *latex_brel[] = { +static char const * latex_brel[] = { "leq", "geq", "equiv", "models", "prec", "succ", "sim", "perp", "preceq", "succeq", "simeq", "mid", @@ -82,10 +77,10 @@ static char const *latex_brel[] = { "vdash", "dashv", "bowtie", "" }; -static char const* latex_arrow[] = { +static char const * latex_arrow[] = { "downarrow", "leftarrow", "Downarrow", "Leftarrow", "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow", - "hookrightarrow","updownarrow", "Leftrightarrow", "leftharpoonup", + "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup", "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow", "leftharpoondown", "rightharpoondown", "mapsto", "Longleftarrow", "Longrightarrow", "Longleftrightarrow", @@ -93,7 +88,7 @@ static char const* latex_arrow[] = { "nwarrow", "nearrow", "swarrow", "searrow", "", }; -char const* latex_varsz[] = { +char const * latex_varsz[] = { "sum", "int", "oint", "prod", "coprod", "bigsqcup", "bigotimes", "bigodot", "bigoplus", @@ -101,7 +96,7 @@ char const* latex_varsz[] = { "bigvee", "bigwedge", "" }; -static char const* latex_bop[] = { +static char const * latex_bop[] = { "pm", "cap", "diamond", "oplus", "mp", "cup", "bigtriangleup", "ominus", "times", "uplus", "bigtriangledown", "otimes", @@ -112,7 +107,7 @@ static char const* latex_bop[] = { "bullet", "wr", "ddagger", "" }; -static char const* latex_misc[] = { +static char const * latex_misc[] = { "nabla", "partial", "infty", "prime", "ell", "emptyset", "exists", "forall", "imath", "jmath", "Re", "Im", "aleph", "wp", "hbar", @@ -121,7 +116,7 @@ static char const* latex_misc[] = { "diamondsuit", "heartsuit", "clubsuit", "spadesuit", "" }; -static char const* latex_dots[] = { +static char const * latex_dots[] = { "ldots", "cdots", "vdots", "ddots" }; @@ -135,44 +130,51 @@ static signed char Latin2Greek[] = { 5, 2, -1, 6, -1, 7, -1, 10, 4, 9, -1 }; -extern char** mathed_get_pixmap_from_icon(int d); -static void math_cb(FL_OBJECT*, long); -static char** pixmapFromBitmapData(char const *, int, int); -void math_insert_symbol(char const* s); +extern char const ** mathed_get_pixmap_from_icon(int d); +extern "C" void math_cb(FL_OBJECT*, long); +static char const ** pixmapFromBitmapData(char const *, int, int); +void math_insert_symbol(char const * s); Bool math_insert_greek(char const c); -BitmapMenu *BitmapMenu::active = NULL; +BitmapMenu * BitmapMenu::active = 0; -BitmapMenu::BitmapMenu(int n, FL_OBJECT* bt, BitmapMenu* prevx): nb(n) { +BitmapMenu::BitmapMenu(int n, FL_OBJECT * bt, BitmapMenu * prevx): nb(n) +{ w = h = 0; form = 0; i = 0; - ww = 2*FL_abs(FL_BOUND_WIDTH); + ww = 2 * FL_abs(FL_BOUND_WIDTH); x = y = ww; y += 8; bitmap = new FL_OBJECTP[nb]; button = bt; button->u_vdata = this; prev = prevx; - next = NULL; + next = 0; if (prev) prev->next = this; } -BitmapMenu::~BitmapMenu() { + +BitmapMenu::~BitmapMenu() +{ if (next) delete next; if (form->visible) Hide(); fl_free_form(form); delete[] bitmap; } -void BitmapMenu::Hide() { + +void BitmapMenu::Hide() +{ fl_hide_form(form); fl_set_button(button, 0); - active = NULL; + active = 0; } -void BitmapMenu::Show() { + +void BitmapMenu::Show() +{ if (active) active->Hide(); active = this; @@ -182,27 +184,27 @@ void BitmapMenu::Show() { fl_show_form(form, FL_PLACE_MOUSE, FL_NOBORDER, ""); } -FL_OBJECT* -BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, char* data, Bool vert) +FL_OBJECT * +BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, unsigned char const * data, Bool vert) { - if (i>=nb) - return NULL; - int wx=bw+ww/2, wy=bh+ww/2; + if (i >= nb) + return 0; + int wx = bw+ww/2, wy = bh+ww/2; wx += (wx % nx); wy += (wy % ny); - FL_OBJECT *obj = fl_create_bmtable(1, x, y, wx, wy, ""); + FL_OBJECT * obj = fl_create_bmtable(1, x, y, wx, wy, ""); fl_set_object_callback(obj, math_cb, id); fl_set_object_lcol(obj, FL_BLUE); fl_set_object_boxtype(obj, FL_UP_BOX); fl_set_bmtable_data(obj, nx, ny, bw, bh, data); if (vert) { y += wy + 8; - h = Maximum(y, h); - w = Maximum(x + wx + ww, w); + h = max(y, h); + w = max(x + wx + ww, w); } else { x += wx + 8; - w = Maximum(x, w); - h = Maximum(y + wy + ww, h); + w = max(x, w); + h = max(y + wy + ww, h); } bitmap[i++] = obj; return obj; @@ -211,24 +213,24 @@ BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, char* data, Bool v void BitmapMenu::Create() { if (iu_vdata = this; } fl_end_form(); - fl_register_raw_callback(form, KeyPressMask, peek_event); + fl_register_raw_callback(form, KeyPressMask, C_peek_event); } int BitmapMenu::GetIndex(FL_OBJECT* ob) { - if (active==this) { + if (active == this) { int k = 0; - for (i=0; itype == ButtonPress) + if(static_cast(xev)->type == ButtonPress) { BitmapMenu::active->Hide(); return 1; } - if(((XEvent *)xev)->type == KeyPress) + if(static_cast(xev)->type == KeyPress) { char c[5]; KeySym keysym; - XLookupString(&((XEvent *)xev)->xkey, &c[0], 5, &keysym, NULL); - if (keysym==XK_Left) + XLookupString(&static_cast(xev)->xkey, &c[0], 5, &keysym, 0); + if (keysym == XK_Left) BitmapMenu::active->Prev(); else - if (keysym==XK_Right) + if (keysym == XK_Right) BitmapMenu::active->Next(); else BitmapMenu::active->Hide(); @@ -262,13 +264,19 @@ int peek_event(FL_FORM * /*form*/, void *xev) return 0; } -static void math_cb(FL_OBJECT* ob, long data) +// This is just a wrapper. +extern "C" int C_peek_event(FL_FORM *form, void *ptr) { + return peek_event(form, ptr); +} + + +extern "C" void math_cb(FL_OBJECT* ob, long data) { BitmapMenu* menu = (BitmapMenu*)ob->u_vdata; int i = menu->GetIndex(ob); char const *s = 0; -// fprintf(stderr, "data[%d]", data); +// lyxerr << "data[" << data << "]"; if (i<0) return; switch (data) { case MM_GREEK: @@ -290,27 +298,27 @@ static void math_cb(FL_OBJECT* ob, long data) s = latex_misc[i]; break; case MM_DOTS: -// fprintf(stderr, "dots[%s %d]", latex_dots[i], i); +// lyxerr << "dots[" << latex_dots[i] << " " << i << "]"; s = latex_dots[i-29]; break; } if (s) { if (current_view->available() && lyxrc->display_shortcuts) { - minibuffer->Set("Inserting symbol ", s); + current_view->owner()->getMiniBuffer()->Set("Inserting symbol ", s); } - current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_INSERT_MATH, s); + current_view->owner()->getLyXFunc()->Dispatch(LFUN_INSERT_MATH, s); } if (menu) menu->Hide(); } -char** get_pixmap_from_symbol(char const *arg, int wx, int hx) +char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx) { - char** data=NULL; - latexkeys *l = in_word_set (arg, strlen(arg)); + char const ** data = 0; + latexkeys * l = in_word_set (arg, strlen(arg)); if (!l) - return NULL; + return 0; switch (l->token) { case LM_TK_FRAC: @@ -334,21 +342,21 @@ char** get_pixmap_from_symbol(char const *arg, int wx, int hx) Bool math_insert_greek(char const c) { int i; - char const *s=NULL; + char const * s= 0; - if ('A'<=c && c<='Z') { - if ((i=Latin2Greek[c - 'A'])>=0) + if ('A' <= c && c <= 'Z') { + if ((i = Latin2Greek[c - 'A']) >= 0) s = latex_greek[i]; } - if ('a'<=c && c<='z') { - if ((i=latin2greek[c - 'a'])>=0) + if ('a'<= c && c<= 'z') { + if ((i= latin2greek[c - 'a'])>= 0) s = latex_greek[i+11]; } if (s) { math_insert_symbol(s); if (greek_kb_flag<2) { greek_kb_flag = 0; - UnlockInset(current_view->currentBuffer()->the_locking_inset); + UnlockInset(current_view->buffer()->the_locking_inset); } return True; } else @@ -358,27 +366,28 @@ Bool math_insert_greek(char const c) void math_insert_symbol(char const* s) { if (current_view->available()) { - if (!current_view->currentBuffer()->the_locking_inset) { - InsetFormula* new_inset = new InsetFormula(); + if (!current_view->buffer()->the_locking_inset) { + InsetFormula * new_inset = new InsetFormula(); BeforeChange(); - current_view->currentBuffer()->insertInset(new_inset); + current_view->buffer()->insertInset(new_inset); // Update(1);//BUG - new_inset->Edit(0,0); + new_inset->Edit(0, 0); new_inset->InsertSymbol(s); } else - if (current_view->currentBuffer()->the_locking_inset->LyxCode()==Inset::MATH_CODE) - ((InsetFormula*)current_view->currentBuffer()->the_locking_inset)->InsertSymbol(s); + if (current_view->buffer()->the_locking_inset->LyxCode() == Inset::MATH_CODE) + static_cast(current_view->buffer()->the_locking_inset)->InsertSymbol(s); else - fprintf(stderr, "Math error: attempt to write on a wrong class of inset.\n"); + lyxerr << "Math error: attempt to write on a wrong " + "class of inset." << endl; } } -BitmapMenu* sym_menu=0; +BitmapMenu * sym_menu= 0; -void create_symbol_menues(FD_panel *symb_form) +void create_symbol_menues(FD_panel * symb_form) { - FL_OBJECT* obj; - BitmapMenu* menu; + FL_OBJECT * obj; + BitmapMenu * menu; sym_menu = menu = new BitmapMenu(2, symb_form->greek); obj = menu->AddBitmap(MM_GREEK, 6, 2, Greek_width, Greek_height, @@ -426,15 +435,15 @@ void create_symbol_menues(FD_panel *symb_form) } static -char** pixmapFromBitmapData(char const *s, int wx, int hx) +char const ** pixmapFromBitmapData(char const * s, int wx, int hx) { - int i, id; - char** data=0; + int i; + char const ** data = 0; - id=-1; + int id = -1; - for (i=0; i<6; i++) { - char const **latex_str = 0; + for (i = 0; i < 6; ++i) { + char const ** latex_str = 0; switch (i) { case 0: latex_str = latex_greek; break; case 1: latex_str = latex_bop; break; @@ -445,21 +454,21 @@ char** pixmapFromBitmapData(char const *s, int wx, int hx) } for (int k = 0; latex_str[k][0]>' '; k++) { - if (strcmp(latex_str[k], s)==0) { + if (strcmp(latex_str[k], s) == 0) { id = k; break; } } - if (id>=0) break; + if (id >= 0) break; } - if (i<6 && id>=0) { - char *bdata = 0; + if (i < 6 && id >= 0) { + unsigned char const * bdata = 0; int w = 0, h = 0, dw = 0, dh = 0; - lyxerr.debug(LString("Imando ") + int(i) + ", " + int(id), Error::MATHED); + lyxerr[Debug::MATHED] << "Imando " << i << ", " << id << endl; switch (i) { case 0: - if (id<=10) { + if (id<= 10) { w = Greek_width; h = Greek_height; bdata = Greek_bits; @@ -519,21 +528,21 @@ char** pixmapFromBitmapData(char const *s, int wx, int hx) } int ww = w/dw, hh = h/dh, x, y; - XImage *xima = XCreateImage(fl_display, NULL, 1, XYBitmap, 0, - bdata, w, h, 8, 0); + XImage * xima = XCreateImage(fl_display, 0, 1, XYBitmap, 0, + const_cast(reinterpret_cast(bdata)), w, h, 8, 0); xima->byte_order = LSBFirst; xima->bitmap_bit_order = LSBFirst; x = (id % dw)*ww; y = (id/dw)*hh; - if (ww>wx) ww = wx; - if (hh>hx) hh = hx; - XImage *sbima = XSubImage(xima, x, y, ww, hh); - XpmCreateDataFromImage(fl_display, &data, sbima, sbima, 0); + if (ww > wx) ww = wx; + if (hh > hx) hh = hx; + XImage * sbima = XSubImage(xima, x, y, ww, hh); + XpmCreateDataFromImage(fl_display, const_cast(&data), sbima, sbima, 0); // Dirty hack to get blue symbols quickly - char *sx = strstr(data[2], "FFFFFFFF"); + char * sx = strstr(data[2], "FFFFFFFF"); if (sx) { - for (int k=0; k<8; k++) sx[k] = '0'; + for (int k = 0; k < 8; ++k) sx[k] = '0'; } // XDestroyImage(xima);