2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsBitmap.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-19 15:38:22 +00:00
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author John Levon
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-19 15:38:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "FormMathsBitmap.h"
|
2002-11-25 18:58:15 +00:00
|
|
|
#include "ControlMath.h"
|
|
|
|
#include "xformsBC.h"
|
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "bmtable.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms_gettext.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "gettext.h"
|
2001-04-26 19:05:06 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-05-24 10:39:34 +00:00
|
|
|
#include XPM_H_LOCATION
|
|
|
|
|
|
|
|
#include <algorithm>
|
2002-11-25 18:58:15 +00:00
|
|
|
|
|
|
|
extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
|
|
|
|
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
|
2002-05-24 10:39:34 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
FD_maths_bitmap::~FD_maths_bitmap()
|
|
|
|
{
|
|
|
|
if (form->visible) fl_hide_form(form);
|
|
|
|
fl_free_form(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef FormCB<ControlMathSub, FormDB<FD_maths_bitmap> > base_class;
|
|
|
|
|
|
|
|
|
|
|
|
FormMathsBitmap::FormMathsBitmap(string const & t, vector<string> const & l)
|
|
|
|
: base_class(t, false),
|
2002-08-20 20:43:10 +00:00
|
|
|
latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
|
|
|
ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
|
|
|
|
x_ = y_ = ww_;
|
|
|
|
y_ += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
|
|
|
|
unsigned char const * data, bool vert)
|
2001-09-13 11:44:07 +00:00
|
|
|
{
|
2002-11-25 18:58:15 +00:00
|
|
|
bitmaps_.push_back(BitmapStore(nt, nx, ny, bw, bh, data, vert));
|
2001-09-13 11:44:07 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
int wx = bw + ww_ / 2;
|
|
|
|
int wy = bh + ww_ / 2;
|
|
|
|
wx += (wx % nx);
|
|
|
|
wy += (wy % ny);
|
2001-09-13 11:44:07 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
if (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_);
|
|
|
|
}
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
void FormMathsBitmap::build()
|
|
|
|
{
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(bitmaps_.size() > 0);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
h_+= 42; // Allow room for a Close button
|
|
|
|
|
|
|
|
FD_maths_bitmap * fdui = new FD_maths_bitmap;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
|
|
|
|
fdui->form->u_vdata = this;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2001-09-13 11:44:07 +00:00
|
|
|
fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-12-02 13:05:16 +00:00
|
|
|
x_ = y_ = ww_;
|
|
|
|
y_ += 8;
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
int y_close = 0;
|
|
|
|
for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
|
2001-03-19 15:38:22 +00:00
|
|
|
it < bitmaps_.end(); ++it) {
|
2002-11-25 18:58:15 +00:00
|
|
|
FL_OBJECT * obj = buildBitmap(*it);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().addReadOnly(obj);
|
2002-11-25 18:58:15 +00:00
|
|
|
y_close = max(y_close, obj->y + obj->h);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
2002-11-25 18:58:15 +00:00
|
|
|
bitmaps_.clear();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
x_ = (fdui->form->w - 90) / 2;
|
|
|
|
y_ = y_close + 10;
|
2001-09-13 11:44:07 +00:00
|
|
|
|
2002-11-29 09:26:53 +00:00
|
|
|
char const * const label = _("Close|^[");
|
2002-12-02 13:05:16 +00:00
|
|
|
fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
|
|
|
|
idex(label).c_str());
|
2002-12-01 03:11:56 +00:00
|
|
|
fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
|
2002-11-30 04:08:21 +00:00
|
|
|
fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(fdui->button_close, C_FormBaseCancelCB, 0);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
fl_end_form();
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
fdui->form->fdui = fdui;
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
dialog_.reset(fdui);
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setCancel(dialog_->button_close);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
2002-01-15 15:31:19 +00:00
|
|
|
// Add a bitmap to a button panel: one bitmap per panel.
|
2002-03-21 21:21:28 +00:00
|
|
|
// nt is the number of buttons and nx, ny the nr. of buttons
|
2002-01-15 15:31:19 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2002-03-21 21:21:28 +00:00
|
|
|
// The scaling of the bitmap on top of the buttons will be
|
2002-01-15 15:31:19 +00:00
|
|
|
// correct if the nx, ny values are given correctly.
|
2002-11-25 18:58:15 +00:00
|
|
|
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, "");
|
2001-03-19 15:38:22 +00:00
|
|
|
fl_set_object_lcol(obj, FL_BLUE);
|
|
|
|
fl_set_object_boxtype(obj, FL_UP_BOX);
|
2002-11-25 18:58:15 +00:00
|
|
|
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);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
if (bmstore.vert) {
|
2001-03-19 15:38:22 +00:00
|
|
|
y_ += wy + 8;
|
|
|
|
} else {
|
|
|
|
x_ += wx + 8;
|
|
|
|
}
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
return obj;
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
|
|
|
int k = 0;
|
2002-11-25 18:58:15 +00:00
|
|
|
|
|
|
|
for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
|
|
|
|
if (ob->objclass != FL_BMTABLE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ob == ob_in)
|
2001-03-19 15:38:22 +00:00
|
|
|
return k + fl_get_bmtable(ob);
|
|
|
|
else
|
2002-11-25 18:58:15 +00:00
|
|
|
k += fl_get_bmtable_maxitems(ob);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
2002-11-25 18:58:15 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsBitmap::apply()
|
|
|
|
{
|
2002-01-18 12:18:20 +00:00
|
|
|
string::size_type const i = latex_chosen_.find(' ');
|
2002-01-15 15:31:19 +00:00
|
|
|
if (i != string::npos) {
|
2002-11-25 18:58:15 +00:00
|
|
|
controller().dispatchFunc(LFUN_MATH_MODE);
|
|
|
|
controller().insertSymbol(latex_chosen_.substr(0,i));
|
|
|
|
controller().insertSymbol(latex_chosen_.substr(i + 1), false);
|
2002-01-18 12:18:20 +00:00
|
|
|
} else
|
2002-11-25 18:58:15 +00:00
|
|
|
controller().insertSymbol(latex_chosen_);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
|
|
|
int const i = GetIndex(ob);
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
if (i < 0)
|
2002-11-25 18:58:15 +00:00
|
|
|
return ButtonPolicy::SMI_INVALID;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
latex_chosen_ = latex_[i];
|
|
|
|
apply();
|
2002-11-25 18:58:15 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|