2001-03-19 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* \file FormMathsMatrix.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
|
|
|
|
|
2001-12-29 17:20:57 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "FormMathsMatrix.h"
|
|
|
|
#include "form_maths_matrix.h"
|
|
|
|
#include "Dialogs.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-03-19 15:38:22 +00:00
|
|
|
#include "Lsstream.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
#include "lyxfunc.h"
|
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
|
2001-03-19 15:38:22 +00:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
lyx::Assert(ob);
|
|
|
|
FormMathsMatrix * pre =
|
|
|
|
static_cast<FormMathsMatrix *>(ob->u_vdata);
|
|
|
|
lyx::Assert(pre);
|
|
|
|
return pre->AlignFilter(cur, c);
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormMathsMatrix::FormMathsMatrix(LyXView * lv, Dialogs * d,
|
2002-03-21 16:59:12 +00:00
|
|
|
FormMathsPanel const & p)
|
2001-09-07 17:55:37 +00:00
|
|
|
: FormMathsSub(lv, d, p, _("Maths Matrix"), false)
|
2001-03-19 15:38:22 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
FL_FORM * FormMathsMatrix::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 FormMathsMatrix::build()
|
|
|
|
{
|
|
|
|
dialog_.reset(build_maths_matrix());
|
|
|
|
|
|
|
|
fl_addto_choice(dialog_->choice_valign, _("Top | Center | Bottom"));
|
|
|
|
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
|
|
|
|
|
|
|
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_->slider_rows);
|
|
|
|
bc().addReadOnly(dialog_->slider_columns);
|
|
|
|
bc().addReadOnly(dialog_->choice_valign);
|
|
|
|
bc().addReadOnly(dialog_->input_halign);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
ostringstream ost;
|
2001-10-10 15:28:19 +00:00
|
|
|
ost << nx << ' ' << ny << ' ' << c << ' ' << sh;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-07-16 15:42:57 +00:00
|
|
|
lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
|
2001-03-19 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FormMathsMatrix::input(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
if (ob == dialog_->choice_valign ||
|
|
|
|
ob == dialog_->slider_rows) return true;
|
|
|
|
|
|
|
|
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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FormMathsMatrix::AlignFilter(char const * cur, int c)
|
|
|
|
{
|
2001-12-29 17:20:57 +00:00
|
|
|
size_t len = strlen(cur);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5) -
|
2002-01-14 13:04:06 +00:00
|
|
|
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;
|
|
|
|
}
|