2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsBitmap.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "FormMathsBitmap.h"
|
|
|
|
#include "bmtable.h"
|
|
|
|
#include "debug.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>
|
|
|
|
#include <iomanip>
|
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::endl;
|
|
|
|
using std::setw;
|
|
|
|
using std::max;
|
|
|
|
|
|
|
|
extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
|
|
|
|
extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
|
2002-03-01 09:52:49 +00:00
|
|
|
FormMathsPanel const & p, string const & t,
|
2001-03-19 15:38:22 +00:00
|
|
|
vector<string> const & l)
|
2002-03-01 09:52:49 +00:00
|
|
|
: FormMathsSub(lv, d, p, t, false),
|
2001-07-30 13:35:08 +00:00
|
|
|
latex_(l), form_(0), 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-13 11:44:07 +00:00
|
|
|
FormMathsBitmap::~FormMathsBitmap()
|
|
|
|
{
|
|
|
|
if (!form())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (form()->visible) fl_hide_form(form());
|
|
|
|
fl_free_form(form());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
FL_FORM * FormMathsBitmap::form() const
|
|
|
|
{
|
2001-09-09 23:00:05 +00:00
|
|
|
return form_.get();
|
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
|
|
|
|
|
|
|
h_+= 50; // Allow room for a Close button
|
|
|
|
|
2001-09-09 23:00:05 +00:00
|
|
|
form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_));
|
2001-03-19 15:38:22 +00:00
|
|
|
form_->u_vdata = this;
|
|
|
|
|
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
|
|
|
|
|
|
|
y_ = 0;
|
|
|
|
for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
|
|
|
|
it < bitmaps_.end(); ++it) {
|
|
|
|
FL_OBJECT * obj = it->get();
|
|
|
|
|
2001-09-09 23:00:05 +00:00
|
|
|
fl_add_object(form_.get(), obj);
|
2001-03-19 15:38:22 +00:00
|
|
|
bc().addReadOnly(obj);
|
|
|
|
|
|
|
|
y_ = max(y_, obj->y + obj->h);
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-04-02 17:04:23 +00:00
|
|
|
char const * const label = _("Close|^[");
|
2001-03-19 15:38:22 +00:00
|
|
|
x_ = (form_->w - 90) / 2;
|
|
|
|
y_ += 10;
|
2001-09-13 11:44:07 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
FL_OBJECT * button_close =
|
2001-09-10 12:37:00 +00:00
|
|
|
fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
|
2002-03-12 14:11:15 +00:00
|
|
|
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_FormBaseDeprecatedCancelCB, 0);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
fl_end_form();
|
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(button_close);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
|
|
|
|
unsigned char const * data, bool vert)
|
|
|
|
{
|
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.
|
2001-03-19 15:38:22 +00:00
|
|
|
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);
|
|
|
|
fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
|
|
|
|
fl_set_bmtable_maxitems(obj, nt);
|
|
|
|
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
|
|
|
|
|
|
|
|
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_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmaps_.push_back(bm_ptr(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
int k = 0;
|
|
|
|
for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
|
|
|
|
it < bitmaps_.end(); ++it) {
|
|
|
|
if (it->get() == ob)
|
|
|
|
return k + fl_get_bmtable(ob);
|
|
|
|
else
|
|
|
|
k += fl_get_bmtable_maxitems(it->get());
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
parent_.dispatchFunc(LFUN_MATH_MODE);
|
|
|
|
parent_.insertSymbol(latex_chosen_.substr(0,i));
|
|
|
|
parent_.insertSymbol(latex_chosen_.substr(i + 1), false);
|
2002-01-18 12:18:20 +00:00
|
|
|
} else
|
2002-01-15 15:31:19 +00:00
|
|
|
parent_.insertSymbol(latex_chosen_);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FormMathsBitmap::input(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
int const i = GetIndex(ob);
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
if (i < 0)
|
2001-03-19 15:38:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
latex_chosen_ = latex_[i];
|
|
|
|
apply();
|
|
|
|
return true;
|
|
|
|
}
|