2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsDelim.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
* \author Pablo De Napoli, pdenapo@dm.uba.ar
|
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-04-23 08:16:27 +00:00
|
|
|
#ifdef __GNUG__
|
2001-03-19 15:38:22 +00:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "FormMathsDelim.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_maths_delim.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "Dialogs.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "bmtable.h"
|
|
|
|
#include "debug.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
#include "lyxfunc.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
#include "delim.xbm"
|
|
|
|
#include "delim0.xpm"
|
2002-06-12 14:21:58 +00:00
|
|
|
#include "delim1.xpm"
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
static int const delim_rversion[] = {
|
2001-03-19 15:38:22 +00:00
|
|
|
1,1,3,3,4,5,7,7,9,9,10,11,
|
|
|
|
13,13,14,15,16,17,19,19,20,21,22,23 };
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-09 15:55:58 +00:00
|
|
|
static char const * delim_values[] = {
|
|
|
|
"(", ")", "lceil", "rceil", "uparrow", "Uparrow",
|
|
|
|
"[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
|
|
|
|
"{", "}", "/", "\\", "downarrow", "Downarrow",
|
|
|
|
"langle", "rangle", "|", "Vert", ".", 0
|
2001-03-19 15:38:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
FormMathsDelim::FormMathsDelim(LyXView * lv, Dialogs * d,
|
2001-03-19 15:38:22 +00:00
|
|
|
FormMathsPanel const & p)
|
2001-09-07 17:55:37 +00:00
|
|
|
: FormMathsSub(lv, d, p, _("Maths Delimiters"), false)
|
2001-03-19 15:38:22 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
FL_FORM * FormMathsDelim::form() const
|
|
|
|
{
|
|
|
|
if (dialog_.get())
|
2002-03-21 21:21:28 +00:00
|
|
|
return dialog_->form;
|
2001-03-19 15:38:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsDelim::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_maths_delim(this));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
fl_set_button(dialog_->radio_left, 1);
|
2002-06-12 14:21:58 +00:00
|
|
|
// Initialize button_pix to "()" as found in images/delim0.xpm:
|
2001-03-19 15:38:22 +00:00
|
|
|
fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim0));
|
|
|
|
dialog_->radio_left->u_ldata = 0;
|
|
|
|
dialog_->radio_right->u_ldata = 1;
|
2002-06-12 14:21:58 +00:00
|
|
|
//dialog_->radio_both->u_ldata = 2;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-06-19 15:24:51 +00:00
|
|
|
fl_set_bmtable_data(dialog_->bmtable, 12, 2,
|
2001-03-19 15:38:22 +00:00
|
|
|
delim_width, delim_height, delim_bits);
|
|
|
|
fl_set_bmtable_maxitems(dialog_->bmtable, 23);
|
|
|
|
|
|
|
|
bc().setOK(dialog_->button_ok);
|
|
|
|
bc().setApply(dialog_->button_apply);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->bmtable);
|
|
|
|
bc().addReadOnly(dialog_->radio_right);
|
|
|
|
bc().addReadOnly(dialog_->radio_left);
|
2002-01-15 15:31:19 +00:00
|
|
|
bc().addReadOnly(dialog_->radio_both);
|
2001-03-19 15:38:22 +00:00
|
|
|
bc().addReadOnly(dialog_->button_pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsDelim::apply()
|
|
|
|
{
|
2001-04-24 17:33:01 +00:00
|
|
|
int const left = int(dialog_->radio_left->u_ldata);
|
|
|
|
int const right= int(dialog_->radio_right->u_ldata);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
ostringstream ost;
|
2001-03-19 15:38:22 +00:00
|
|
|
ost << delim_values[left] << ' ' << delim_values[right];
|
|
|
|
|
2002-07-20 17:27:03 +00:00
|
|
|
lv_->getLyXFunc()->dispatch(LFUN_MATH_DELIM, ost.str().c_str(), false);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FormMathsDelim::input(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
int left = int(dialog_->radio_left->u_ldata);
|
|
|
|
int right= int(dialog_->radio_right->u_ldata);
|
|
|
|
int const side = (fl_get_button(dialog_->radio_right) != 0);
|
|
|
|
|
|
|
|
int const i = fl_get_bmtable(dialog_->bmtable);
|
|
|
|
int const button = fl_get_bmtable_numb(dialog_->bmtable);
|
2002-03-21 16:59:12 +00:00
|
|
|
bool const both = (button == FL_MIDDLE_MOUSE ||
|
|
|
|
fl_get_button(dialog_->radio_both) != 0);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
if (i >= 0) {
|
2001-03-19 15:38:22 +00:00
|
|
|
if (side || (button == FL_RIGHT_MOUSE))
|
|
|
|
right = i;
|
|
|
|
else {
|
|
|
|
left = i;
|
2002-06-12 14:21:58 +00:00
|
|
|
if (both) {
|
2001-03-19 15:38:22 +00:00
|
|
|
right = delim_rversion[i];
|
2002-06-12 14:21:58 +00:00
|
|
|
// Add left delimiter in "both" case if right one was pressed:
|
|
|
|
for (int j = 0; j <= 23; ++j) {
|
|
|
|
if (delim_rversion[j] == left) {
|
|
|
|
right = left;
|
|
|
|
left = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-06-12 14:21:58 +00:00
|
|
|
// Re-initialize button_pix to solid blue
|
|
|
|
// (not elegant but works, MV 24.5.2002)
|
|
|
|
fl_free_pixmap_pixmap(dialog_->button_pix);
|
|
|
|
fl_set_pixmap_data(dialog_->button_pix, const_cast<char**>(delim1));
|
|
|
|
Pixmap p1;
|
|
|
|
fl_get_pixmap_pixmap(dialog_->button_pix, &p1, 0);
|
|
|
|
|
2002-06-19 15:24:51 +00:00
|
|
|
fl_draw_bmtable_item(dialog_->bmtable, left, p1, 0, 0);
|
|
|
|
fl_draw_bmtable_item(dialog_->bmtable, right, p1, 16, 0);
|
2001-03-19 15:38:22 +00:00
|
|
|
fl_redraw_object(dialog_->button_pix);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
dialog_->radio_left->u_ldata = left;
|
|
|
|
dialog_->radio_right->u_ldata = right;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|