/* * File: math_symbols.C * Purpose: User interface to math symbols * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx> * Created: November 1995 * Version: 0.8 28/03/96 * Description: Provides a GUI to introduce mathematical * symbols in lyx. * * Dependencies: Xlib, XForms, Lyx * * Copyright: (c) 1995, 1996, Alejandro Aguilar Sierra * * You are free to use and modify it under the terms of * the GNU General Public Licence version 2 or later.
*/
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);
x = y = ww;
y += 8;
bitmap = new FL_OBJECTP[nb];
button = bt;
button->u_vdata = this;
prev = prevx;
next = NULL; if (prev)
prev->next = this;
}
BitmapMenu::~BitmapMenu() { if (next) delete next;
fl_free_form(form); delete[] bitmap;
}
void BitmapMenu::Hide() {
fl_hide_form(form);
fl_set_button(button, 0);
active = NULL;
}
void BitmapMenu::Show() { if (active)
active->Hide();
active = this; // int x = button->form->x + button->x, y = button->form->y + button->y; // fl_set_form_position(form, x, y + button->h);
fl_set_button(button, 1);
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)
{ if (i>=nb) return NULL; 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_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);
} else {
x += wx + 8;
w = Maximum(x, w);
h = Maximum(y + wy + ww, h);
}
bitmap[i++] = obj; return obj;
}
void BitmapMenu::Create()
{ if (i<nb) {
fprintf(stderr, "Error: Bitmaps not created!"); return;
}
form = fl_bgn_form(FL_UP_BOX, w, h); for (i=0; i<nb; i++) {
fl_add_object(form, bitmap[i]);
bitmap[i]->u_vdata = this;
}
fl_end_form();
fl_register_raw_callback(form, KeyPressMask, peek_event);
}
int BitmapMenu::GetIndex(FL_OBJECT* ob)
{ if (active==this) { int k = 0; for (i=0; i<nb; i++) { if (bitmap[i]==ob) return k+fl_get_bmtable(ob);
k += fl_get_bmtable_maxitems(bitmap[i]);
}
} return -1;
}
int peek_event(FL_FORM * /*form*/, void *xev)
{ if (BitmapMenu::active==NULL) return 0;
staticvoid math_cb(FL_OBJECT* ob, long data)
{
BitmapMenu* menu = (BitmapMenu*)ob->u_vdata; int i = menu->GetIndex(ob); charconst *s = 0;
// fprintf(stderr, "data[%d]", data); if (i<0) return; switch (data) { case MM_GREEK:
s = latex_greek[i]; break; case MM_ARROW:
s = latex_arrow[i]; break; case MM_BRELATS:
s = latex_brel[i]; break; case MM_BOP:
s = latex_bop[i]; break; case MM_VARSIZE:
s = latex_varsz[i]; break; case MM_MISC:
s = latex_misc[i]; break; case MM_DOTS: // fprintf(stderr, "dots[%s %d]", 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->getOwner()->getLyXFunc()->Dispatch(LFUN_INSERT_MATH, s);
} if (menu)
menu->Hide();
}
char** get_pixmap_from_symbol(charconst *arg, int wx, int hx)
{ char** data=NULL;
latexkeys *l = in_word_set (arg, strlen(arg)); if (!l) return NULL;
switch (l->token) { case LM_TK_FRAC:
data = mathed_get_pixmap_from_icon(MM_FRAC); break; case LM_TK_SQRT:
data = mathed_get_pixmap_from_icon(MM_SQRT); break; case LM_TK_BIGSYM: case LM_TK_SYM: // 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); break;
}
return data;
}
Bool math_insert_greek(charconst c)
{ int i; charconst *s=NULL;
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)
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);
} returnTrue;
} else returnFalse;
}
void math_insert_symbol(charconst* s)
{ if (current_view->available()) { if (!current_view->currentBuffer()->the_locking_inset) {
InsetFormula* new_inset = new InsetFormula();
BeforeChange();
current_view->currentBuffer()->insertInset(new_inset); // Update(1);//BUG
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); else
fprintf(stderr, "Math error: attempt to write on a wrong class of inset.\n");
}
}
static char** pixmapFromBitmapData(charconst *s, int wx, int hx)
{ int i, id; char** data=0;
id=-1;
for (i=0; i<6; i++) { charconst **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;
}
for (int k = 0; latex_str[k][0]>' '; k++) { if (strcmp(latex_str[k], s)==0) {
id = k; break;
}
} if (id>=0) break;
} if (i<6 && id>=0) { char *bdata = 0; int w = 0, h = 0, dw = 0, dh = 0;
lyxerr.debug(LString("Imando ") + int(i) + ", " + int(id), Error::MATHED); 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;
} elseif (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:
w = misc_width;
h = misc_height;
bdata = misc_bits;
dw = 5; dh = 6; break;
} int ww = w/dw, hh = h/dh, x, y;
XImage *xima = XCreateImage(fl_display, NULL, 1, XYBitmap, 0,
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);
// Dirty hack to get blue symbols quickly char *sx = strstr(data[2], "FFFFFFFF"); if (sx) { for (int k=0; k<8; k++) sx[k] = '0';
}
// XDestroyImage(xima);
}
return data;
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.