]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormMathsBitmap.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormMathsBitmap.C
index db4a450c5c5d722ce6c4dfab11fea9304c23590d..932fe932576575989d459145046a7ae829e049de 100644 (file)
@@ -24,7 +24,7 @@
 #include "LyXView.h"
 #include "bmtable.h"
 #include "debug.h"
-#include "lyx_gui_misc.h" // scex, idex
+#include "xforms_helpers.h"
 #include "gettext.h"
 #include "support/LAssert.h"
 
@@ -48,9 +48,19 @@ FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
 }
 
 
+FormMathsBitmap::~FormMathsBitmap()
+{
+       if (!form())
+               return;
+
+       if (form()->visible) fl_hide_form(form());
+       fl_free_form(form());
+}
+
+
 FL_FORM * FormMathsBitmap::form() const
 {
-       return form_;
+       return form_.get();
 }
 
 
@@ -60,33 +70,31 @@ void FormMathsBitmap::build()
 
        h_+= 50; // Allow room for a Close button
 
-       form_ = fl_bgn_form(FL_UP_BOX, w_, h_);
+       form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_));
        form_->u_vdata = this;
 
-       FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
+       fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
 
        y_ = 0;
        for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
             it < bitmaps_.end(); ++it) {
                FL_OBJECT * obj = it->get();
 
-               fl_add_object(form_, obj);
+               fl_add_object(form_.get(), obj);
                bc().addReadOnly(obj);
 
                y_ = max(y_, obj->y + obj->h);
        }
  
        char const * const label = N_("Close|^[");
-
        x_ = (form_->w - 90) / 2;
        y_ += 10;
-               
-       FL_OBJECT * button_cancel = obj = 
-               fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
-       fl_set_button_shortcut(obj, scex(_(label)), 1);
 
-       fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-       fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0);
+       FL_OBJECT * button_cancel =
+               fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
+       fl_set_button_shortcut(button_cancel, scex(_(label)), 1);
+       fl_set_object_lsize(button_cancel, FL_NORMAL_SIZE);
+       fl_set_object_callback(button_cancel, C_FormBaseDeprecatedCancelCB, 0);
 
        fl_end_form();
 
@@ -97,11 +105,21 @@ void FormMathsBitmap::build()
 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
                                unsigned char const * data, bool vert)
 {
+       // Add a bitmap to a button panel: one bitmap per panel.
+       // nt is the number of buttons and nx, ny the nr. of buttons 
+       // in x and y direction.
+       // bw, bh and data are the bitmap dimensions width, height and
+       // bit pattern; these come directly from an .xbm file included
+       // as source.
+       // vert indicates whether the next button panel within this
+       // window will be below (true, default) or next to this one.
+       //
+       // The scaling of the bitmap on top of the buttons will be 
+       // correct if the nx, ny values are given correctly.
        int wx = bw + ww_ / 2;
        int wy = bh + ww_ / 2;
        wx += (wx % nx);
        wy += (wy % ny);
-
        FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
        fl_set_object_lcol(obj, FL_BLUE);
        fl_set_object_boxtype(obj, FL_UP_BOX);
@@ -139,7 +157,13 @@ int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
 
 void FormMathsBitmap::apply()
 {
-       parent_.insertSymbol(latex_chosen_);
+       string::size_type const i = latex_chosen_.find(' ');
+       if (i != string::npos) {
+               parent_.dispatchFunc(LFUN_MATH_MODE);
+               parent_.insertSymbol(latex_chosen_.substr(0,i));
+               parent_.insertSymbol(latex_chosen_.substr(i + 1), false);
+       } else
+               parent_.insertSymbol(latex_chosen_);
 }