2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsDelim.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 Pablo De Napoli
|
|
|
|
* \author John Levon
|
2002-11-04 02:12:42 +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>
|
|
|
|
|
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"
|
2002-11-25 18:58:15 +00:00
|
|
|
#include "ControlMath.h"
|
|
|
|
#include "xformsBC.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "bmtable.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
#include "Lsstream.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
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-08-13 17:43:40 +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,
|
2002-08-07 08:11:41 +00:00
|
|
|
13,13,14,15,16,17,19,19,20,21,22,23
|
|
|
|
};
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
2001-08-09 15:55:58 +00:00
|
|
|
static char const * delim_values[] = {
|
|
|
|
"(", ")", "lceil", "rceil", "uparrow", "Uparrow",
|
|
|
|
"[", "]", "lfloor", "rfloor", "updownarrow", "Updownarrow",
|
2002-10-22 17:32:20 +00:00
|
|
|
"{", "}", "/", "backslash", "downarrow", "Downarrow",
|
2001-08-09 15:55:58 +00:00
|
|
|
"langle", "rangle", "|", "Vert", ".", 0
|
2001-03-19 15:38:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
typedef FormCB<ControlMathSub, FormDB<FD_maths_delim> > base_class;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
FormMathsDelim::FormMathsDelim()
|
|
|
|
: base_class(_("Maths Delimiters"), false)
|
|
|
|
{}
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2002-08-13 17:43:40 +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
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
ostringstream os;
|
|
|
|
os << delim_values[left] << ' ' << delim_values[right];
|
2002-11-25 18:58:15 +00:00
|
|
|
controller().dispatchFunc(LFUN_MATH_DELIM, STRCONV(os.str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsDelim::update()
|
|
|
|
{
|
|
|
|
bc().valid();
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
ButtonPolicy::SMInput FormMathsDelim::input(FL_OBJECT *, long)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
|
|
|
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-11-04 02:12:42 +00:00
|
|
|
// Re-initialize button_pix to solid blue
|
2002-06-12 14:21:58 +00:00
|
|
|
// (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-11-04 02:12:42 +00:00
|
|
|
|
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;
|
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|