]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_symbols.C
Added the ability to select both delimiters at one click (based in part
[lyx.git] / src / mathed / math_symbols.C
index 133834774b5c51c5b2f3b2089a7cd04d43145807..72b103638db1b97b7bb5e1cb21270cd1425f2d7a 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include <algorithm>
+using std::max;
 
 #include "lyx_main.h"
 #include "buffer.h"
@@ -81,7 +82,7 @@ static char const *latex_brel[] = {
 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", 
@@ -132,7 +133,7 @@ static signed char Latin2Greek[] =  {
 }; 
 
 extern char** mathed_get_pixmap_from_icon(int d);
-static void math_cb(FL_OBJECT*, long);
+extern "C" void math_cb(FL_OBJECT*, long);
 static char** pixmapFromBitmapData(char const *, int, int);
 void math_insert_symbol(char const* s);
 Bool math_insert_greek(char const c);
@@ -179,11 +180,11 @@ void BitmapMenu::Show()  {
 }
 
 FL_OBJECT*
-BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, char* data, Bool vert)
+BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, unsigned char* data, Bool vert)
 {
-   if (i>=nb)
+   if (i>= nb)
      return 0;
-   int wx=bw+ww/2, wy=bh+ww/2;
+   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, "");   
@@ -211,20 +212,20 @@ void BitmapMenu::Create()
       return;
    }
    form = fl_bgn_form(FL_UP_BOX, w, h);   
-   for (i=0; i<nb; i++) {
+   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);
+   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; i<nb; i++) {
-        if (bitmap[i]==ob) 
+      for (i= 0; i<nb; i++) {
+        if (bitmap[i] == ob) 
           return k+fl_get_bmtable(ob);
         k += fl_get_bmtable_maxitems(bitmap[i]);
       }
@@ -234,7 +235,7 @@ int BitmapMenu::GetIndex(FL_OBJECT* ob)
 
 int peek_event(FL_FORM * /*form*/, void *xev)
 {
-   if (BitmapMenu::active==0)
+   if (BitmapMenu::active == 0)
      return 0;
   
    if(((XEvent *)xev)->type == ButtonPress)
@@ -247,9 +248,9 @@ int peek_event(FL_FORM * /*form*/, void *xev)
       char c[5];
       KeySym keysym;
       XLookupString(&((XEvent *)xev)->xkey, &c[0], 5, &keysym, 0);
-      if (keysym==XK_Left) 
+      if (keysym == XK_Left) 
        BitmapMenu::active->Prev(); else
-      if (keysym==XK_Right) 
+      if (keysym == XK_Right) 
        BitmapMenu::active->Next(); 
       else 
        BitmapMenu::active->Hide();
@@ -258,7 +259,13 @@ 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);   
@@ -295,7 +302,7 @@ static void math_cb(FL_OBJECT* ob, long data)
       if (current_view->available() && lyxrc->display_shortcuts) {
          minibuffer->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(); 
@@ -303,7 +310,7 @@ static void math_cb(FL_OBJECT* ob, long data)
 
 char** get_pixmap_from_symbol(char const *arg, int wx, int hx)
 {
-   char** data=0;                  
+   char** data= 0;                 
    latexkeys *l = in_word_set (arg, strlen(arg));
    if (!l) 
     return 0;
@@ -330,21 +337,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=0;
+   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
@@ -354,28 +361,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) {
+      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<InsetFormula*>(current_view->buffer()->the_locking_inset)->InsertSymbol(s);
         else 
                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,11 +433,11 @@ static
 char** pixmapFromBitmapData(char const *s, int wx, int hx)
 {
     int i, id;
-    char** data=0;
+    char** data= 0;
     
-    id=-1;
+    id= -1;
     
-    for (i=0; i<6; i++) {
+    for (i= 0; i<6; i++) {
        char const **latex_str = 0;
        switch (i) {
         case 0: latex_str = latex_greek; break;
@@ -442,21 +449,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 *bdata = 0;
        int w = 0, h = 0, dw = 0, dh = 0;
 
        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;
@@ -517,7 +524,7 @@ char** pixmapFromBitmapData(char const *s, int wx, int hx)
        int ww = w/dw, hh = h/dh, x, y;
    
        XImage *xima = XCreateImage(fl_display, 0, 1, XYBitmap, 0, 
-                                   bdata, w, h, 8, 0);
+                                   reinterpret_cast<char*>(bdata), w, h, 8, 0);
        xima->byte_order = LSBFirst;
        xima->bitmap_bit_order = LSBFirst;
        x = (id % dw)*ww;
@@ -530,7 +537,7 @@ char** pixmapFromBitmapData(char const *s, int wx, int hx)
        // 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';
+           for (int k= 0; k<8; k++) sx[k] = '0';
        }
 
 //     XDestroyImage(xima);