]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormMathsBitmap.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / FormMathsBitmap.C
index 9b0595c46eee0c8023202d811fde7449bbdd87d6..7280b2f091bae7572f05804e0fb60ab63e1a3b53 100644 (file)
@@ -5,36 +5,29 @@
  *
  * \author Alejandro Aguilar Sierra
  * \author John Levon
- * \author Angus Leeming 
+ * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "FormMathsBitmap.h"
-#include "ControlMath.h"
-#include "xformsBC.h"
 
 #include "bmtable.h"
 #include "forms_gettext.h"
-#include "gettext.h"
-#include "support/LAssert.h"
-
-#include XPM_H_LOCATION
+#include "xformsBC.h"
 
-#include <algorithm>
+#include "ControlMath.h"
 
-extern  "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
-extern  "C" void C_FormBaseInputCB(FL_OBJECT *, long);
 
-using std::vector;
 using std::max;
+using std::vector;
+using std::string;
+
 
+extern  "C" void C_FormDialogView_CancelCB(FL_OBJECT *, long);
+extern  "C" void C_FormDialogView_InputCB(FL_OBJECT *, long);
 
 FD_maths_bitmap::~FD_maths_bitmap()
 {
@@ -43,11 +36,11 @@ FD_maths_bitmap::~FD_maths_bitmap()
 }
 
 
-typedef FormCB<ControlMathSub, FormDB<FD_maths_bitmap> > base_class;
+typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
 
 
-FormMathsBitmap::FormMathsBitmap(string const & t, vector<string> const & l)
-       : base_class(t, false),
+FormMathsBitmap::FormMathsBitmap(Dialog & parent, string const & t, vector<string> const & l)
+       : base_class(parent, t, false),
          latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
 {
        ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
@@ -56,17 +49,16 @@ FormMathsBitmap::FormMathsBitmap(string const & t, vector<string> const & l)
 }
 
 
-void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
-                               unsigned char const * data, bool vert)
+void FormMathsBitmap::addBitmap(BitmapStore const & bm)
 {
-       bitmaps_.push_back(BitmapStore(nt, nx, ny, bw, bh, data, vert));
+       bitmaps_.push_back(bm);
 
-       int wx = bw + ww_ / 2;
-       int wy = bh + ww_ / 2;
-       wx += (wx % nx);
-       wy += (wy % ny);
+       int wx = bm.bw + ww_ / 2;
+       int wy = bm.bh + ww_ / 2;
+       wx += (wx % bm.nx);
+       wy += (wy % bm.ny);
 
-       if (vert) {
+       if (bm.vert) {
                y_ += wy + 8;
                h_ = max(y_, h_);
                w_ = max(x_ + wx + ww_, w_);
@@ -76,11 +68,11 @@ void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
                h_ = max(y_ + wy + ww_, h_);
        }
 }
+
 
 void FormMathsBitmap::build()
 {
-       lyx::Assert(bitmaps_.size() > 0);
+       BOOST_ASSERT(bitmaps_.size() > 0);
 
        h_+= 42; // Allow room for a Close button
 
@@ -91,38 +83,38 @@ void FormMathsBitmap::build()
 
        fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
 
-       x_ = 0;
-       y_ = 0;
+       x_ = y_ = ww_;
+       y_ += 8;
+
        int y_close = 0;
        for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
             it < bitmaps_.end(); ++it) {
                FL_OBJECT * obj = buildBitmap(*it);
 
-               bc().addReadOnly(obj);
+               bcview().addReadOnly(obj);
                y_close = max(y_close, obj->y + obj->h);
        }
        bitmaps_.clear();
 
-       char const * const label = _("Close|^[");
        x_ = (fdui->form->w - 90) / 2;
        y_ = y_close + 10;
 
-       FL_OBJECT * button_close =
-               fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
-       fl_set_button_shortcut(button_close, scex(_(label)), 1);
-       fl_set_object_lsize(button_close, FL_NORMAL_SIZE);
-       fl_set_object_callback(button_close, C_FormBaseCancelCB, 0);
+       string const label = _("Close|^[");
+       fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
+                                          idex(label).c_str());
+       fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
+       fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
+       fl_set_object_callback(fdui->button_close, C_FormDialogView_CancelCB, 0);
 
        fl_end_form();
 
        fdui->form->fdui = fdui;
 
-       dialog_.reset(fdui);
-       bc().setCancel(dialog_->button_close);
+       dialog_.reset(fdui);
 }
 
 
-                       
+
 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
 {
        // Add a bitmap to a button panel: one bitmap per panel.
@@ -147,7 +139,7 @@ FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
        fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
                            bmstore.data);
        fl_set_bmtable_maxitems(obj, bmstore.nt);
-       fl_set_object_callback(obj, C_FormBaseInputCB, 0);
+       fl_set_object_callback(obj, C_FormDialogView_InputCB, 0);
 
        if (bmstore.vert) {
                y_ += wy + 8;
@@ -182,10 +174,10 @@ void FormMathsBitmap::apply()
        string::size_type const i = latex_chosen_.find(' ');
        if (i != string::npos) {
                controller().dispatchFunc(LFUN_MATH_MODE);
-               controller().insertSymbol(latex_chosen_.substr(0,i));
-               controller().insertSymbol(latex_chosen_.substr(i + 1), false);
+               controller().dispatchInsert(latex_chosen_.substr(0,i));
+               controller().dispatchInsert('\\' + latex_chosen_.substr(i + 1));
        } else
-               controller().insertSymbol(latex_chosen_);
+               controller().dispatchInsert(latex_chosen_);
 }