/**
* \file FormMathsBitmap.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
- * \author John Levon, moz@compsoc.man.ac.uk
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author John Levon
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include <algorithm>
-#include <iomanip>
-
-#include XPM_H_LOCATION
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "FormMathsBitmap.h"
-#include "Dialogs.h"
-#include "LyXView.h"
#include "bmtable.h"
-#include "debug.h"
-#include "xforms_helpers.h"
-#include "gettext.h"
-#include "support/LAssert.h"
+#include "forms_gettext.h"
+#include "xformsBC.h"
+
+#include "ControlMath.h"
+
-using std::vector;
-using std::endl;
-using std::setw;
using std::max;
+using std::vector;
+using std::string;
-extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
-extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
+namespace lyx {
+namespace frontend {
-FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
- FormMathsPanel const & p,
- vector<string> const & l)
- : FormMathsSub(lv, d, p, _("Maths Bitmaps"), false),
- latex_(l), form_(0), ww_(0), x_(0), y_(0), w_(0), h_(0)
+extern "C" void C_FormDialogView_CancelCB(FL_OBJECT *, long);
+extern "C" void C_FormDialogView_InputCB(FL_OBJECT *, long);
+
+FD_maths_bitmap::~FD_maths_bitmap()
+{
+ if (form->visible) fl_hide_form(form);
+ fl_free_form(form);
+}
+
+
+typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
+
+
+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);
x_ = y_ = ww_;
}
-FormMathsBitmap::~FormMathsBitmap()
+void FormMathsBitmap::addBitmap(BitmapStore const & bm)
{
- if (!form())
- return;
+ bitmaps_.push_back(bm);
- if (form()->visible) fl_hide_form(form());
- fl_free_form(form());
-}
+ int wx = bm.bw + ww_ / 2;
+ int wy = bm.bh + ww_ / 2;
+ wx += (wx % bm.nx);
+ wy += (wy % bm.ny);
-
-FL_FORM * FormMathsBitmap::form() const
-{
- return form_.get();
+ if (bm.vert) {
+ y_ += wy + 8;
+ h_ = max(y_, h_);
+ w_ = max(x_ + wx + ww_, w_);
+ } else {
+ x_ += wx + 8;
+ w_ = max(x_, w_);
+ h_ = max(y_ + wy + ww_, h_);
+ }
}
void FormMathsBitmap::build()
{
- lyx::Assert(bitmaps_.size() > 0);
+ BOOST_ASSERT(bitmaps_.size() > 0);
- h_+= 50; // Allow room for a Close button
+ h_+= 42; // Allow room for a Close button
- form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_));
- form_->u_vdata = this;
+ FD_maths_bitmap * fdui = new FD_maths_bitmap;
+
+ fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
+ fdui->form->u_vdata = this;
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();
+ x_ = y_ = ww_;
+ y_ += 8;
- fl_add_object(form_.get(), obj);
- bc().addReadOnly(obj);
+ int y_close = 0;
+ for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
+ it < bitmaps_.end(); ++it) {
+ FL_OBJECT * obj = buildBitmap(*it);
- y_ = max(y_, obj->y + obj->h);
+ bcview().addReadOnly(obj);
+ y_close = max(y_close, obj->y + obj->h);
}
-
- char const * const label = N_("Close|^[");
- x_ = (form_->w - 90) / 2;
- y_ += 10;
+ bitmaps_.clear();
+
+ x_ = (fdui->form->w - 90) / 2;
+ y_ = y_close + 10;
- 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);
+ 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();
- bc().setCancel(button_cancel);
+ fdui->form->fdui = fdui;
+
+ dialog_.reset(fdui);
}
-void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
- unsigned char const * data, bool vert)
+
+FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
{
// Add a bitmap to a button panel: one bitmap per panel.
- // nt is the number of buttons and nx, ny the nr. of buttons
+ // 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
// 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
+ // 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, "");
+ int wx = bmstore.bw + ww_ / 2;
+ int wy = bmstore.bh + ww_ / 2;
+ wx += (wx % bmstore.nx);
+ wy += (wy % bmstore.ny);
+
+ FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
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);
- fl_set_bmtable_maxitems(obj, nt);
- fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
+ 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_FormDialogView_InputCB, 0);
- if (vert) {
+ if (bmstore.vert) {
y_ += wy + 8;
- h_ = max(y_, h_);
- w_ = max(x_ + wx + ww_, w_);
} else {
x_ += wx + 8;
- w_ = max(x_, w_);
- h_ = max(y_ + wy + ww_, h_);
}
- bitmaps_.push_back(bm_ptr(obj));
+ return obj;
}
-int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
+int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
{
int k = 0;
- for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
- it < bitmaps_.end(); ++it) {
- if (it->get() == ob)
+
+ for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
+ if (ob->objclass != FL_BMTABLE)
+ continue;
+
+ if (ob == ob_in)
return k + fl_get_bmtable(ob);
else
- k += fl_get_bmtable_maxitems(it->get());
+ k += fl_get_bmtable_maxitems(ob);
}
+
return -1;
}
void FormMathsBitmap::apply()
{
- unsigned int i = latex_chosen_.find(' ');
+ 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_);
+ controller().dispatchFunc(LFUN_MATH_MODE);
+ controller().dispatchInsert(latex_chosen_.substr(0,i));
+ controller().dispatchInsert('\\' + latex_chosen_.substr(i + 1));
+ } else
+ controller().dispatchInsert(latex_chosen_);
}
-bool FormMathsBitmap::input(FL_OBJECT * ob, long)
+ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
{
int const i = GetIndex(ob);
- if (i < 0)
- return false;
+ if (i < 0)
+ return ButtonPolicy::SMI_INVALID;
latex_chosen_ = latex_[i];
apply();
- return true;
+ return ButtonPolicy::SMI_VALID;
}
+
+} // namespace frontend
+} // namespace lyx