2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsMatrix.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
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-19 15:38:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "FormMathsMatrix.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_maths_matrix.h"
|
2003-06-17 12:53:35 +00:00
|
|
|
#include "ControlMath.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
#include "xformsBC.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
|
|
|
#include "controllers/ButtonController.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2001-04-26 19:05:06 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-01-14 13:04:06 +00:00
|
|
|
#include "support/lyxalgo.h" // lyx::count
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2003-05-14 09:17:22 +00:00
|
|
|
#include "lyx_forms.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
#include "support/std_sstream.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2001-06-01 10:53:24 +00:00
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
using std::strlen;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
static char h_align_str[80] = "c";
|
|
|
|
static char v_align_c[] = "tcb";
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
|
|
|
extern "C" {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
static
|
|
|
|
int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
|
|
|
|
char const * cur, int c)
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(ob);
|
2001-09-09 22:02:19 +00:00
|
|
|
FormMathsMatrix * pre =
|
|
|
|
static_cast<FormMathsMatrix *>(ob->u_vdata);
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(pre);
|
2001-09-09 22:02:19 +00:00
|
|
|
return pre->AlignFilter(cur, c);
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 12:53:35 +00:00
|
|
|
typedef FormController<ControlMath, FormView<FD_maths_matrix> > base_class;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-06-17 10:30:38 +00:00
|
|
|
FormMathsMatrix::FormMathsMatrix(Dialog & parent)
|
|
|
|
: base_class(parent, _("Math Matrix"), false)
|
2002-11-25 18:58:15 +00:00
|
|
|
{}
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FormMathsMatrix::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_maths_matrix(this));
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-05-19 21:08:58 +00:00
|
|
|
fl_addto_choice(dialog_->choice_valign,
|
2003-08-14 15:45:09 +00:00
|
|
|
_("Top | Middle | Bottom").c_str());
|
2001-03-19 15:38:22 +00:00
|
|
|
fl_set_choice(dialog_->choice_valign, 2);
|
|
|
|
fl_set_input(dialog_->input_halign, h_align_str);
|
|
|
|
dialog_->input_halign->u_vdata = this;
|
|
|
|
fl_set_input_filter(dialog_->input_halign,
|
|
|
|
C_FormMathsMatrixAlignFilter);
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(dialog_->input_halign);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->button_ok);
|
|
|
|
bcview().setApply(dialog_->button_apply);
|
|
|
|
bcview().setCancel(dialog_->button_close);
|
2001-03-19 15:38:22 +00:00
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().addReadOnly(dialog_->slider_rows);
|
|
|
|
bcview().addReadOnly(dialog_->slider_columns);
|
|
|
|
bcview().addReadOnly(dialog_->choice_valign);
|
|
|
|
bcview().addReadOnly(dialog_->input_halign);
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormMathsMatrix::apply()
|
|
|
|
{
|
|
|
|
char const c = v_align_c[fl_get_choice(dialog_->choice_valign) - 1];
|
|
|
|
char const * sh = fl_get_input(dialog_->input_halign);
|
|
|
|
int const nx = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
|
|
|
|
int const ny = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
ostringstream os;
|
|
|
|
os << nx << ' ' << ny << ' ' << c << ' ' << sh;
|
2003-06-17 10:30:38 +00:00
|
|
|
controller().dispatchMatrix(STRCONV(os.str()));
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
void FormMathsMatrix::update()
|
|
|
|
{
|
|
|
|
bc().valid();
|
|
|
|
}
|
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
|
2002-11-25 18:58:15 +00:00
|
|
|
ButtonPolicy::SMInput FormMathsMatrix::input(FL_OBJECT * ob, long)
|
2001-03-19 15:38:22 +00:00
|
|
|
{
|
|
|
|
if (ob == dialog_->choice_valign ||
|
2002-11-25 18:58:15 +00:00
|
|
|
ob == dialog_->slider_rows) return ButtonPolicy::SMI_VALID;
|
2001-03-19 15:38:22 +00:00
|
|
|
|
|
|
|
int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
|
|
|
|
for (int i = 0; i < nx; ++i)
|
|
|
|
h_align_str[i] = 'c';
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
h_align_str[nx] = '\0';
|
|
|
|
|
|
|
|
fl_set_input(dialog_->input_halign, h_align_str);
|
|
|
|
fl_redraw_object(dialog_->input_halign);
|
2002-11-25 18:58:15 +00:00
|
|
|
return ButtonPolicy::SMI_VALID;
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FormMathsMatrix::AlignFilter(char const * cur, int c)
|
|
|
|
{
|
2002-08-13 17:43:40 +00:00
|
|
|
size_t const len = strlen(cur);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5)
|
|
|
|
- int(len)
|
|
|
|
+ int(lyx::count(cur, cur + len, '|'));
|
2001-03-19 15:38:22 +00:00
|
|
|
if (n < 0)
|
|
|
|
return FL_INVALID;
|
|
|
|
|
2001-12-29 17:20:57 +00:00
|
|
|
if (c == 'c' || c == 'l' || c == 'r' || c == '|')
|
2001-03-19 15:38:22 +00:00
|
|
|
return FL_VALID;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
return FL_INVALID;
|
|
|
|
}
|