2 * \file FormMathsMatrix.C
3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli, pdenapo@dm.uba.ar
8 * \author John Levon, moz@compsoc.man.ac.uk
9 * \author Angus Leeming, a.leeming@ic.ac.uk
15 #pragma implementation
18 #include "FormMathsMatrix.h"
19 #include "form_maths_matrix.h"
25 static char h_align_str[80] = "c";
26 static char v_align_c[] = "tcb";
28 extern "C" int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
29 char const * cur, int c)
32 FormMathsMatrix * pre = static_cast<FormMathsMatrix *>(ob->u_vdata);
34 return pre->AlignFilter(cur, c);
38 FormMathsMatrix::FormMathsMatrix(LyXView * lv, Dialogs * d,
39 FormMathsPanel const & p)
40 : FormMathsSub(lv, d, p, _("Maths Matrix"))
44 FL_FORM * FormMathsMatrix::form() const
52 void FormMathsMatrix::build()
54 dialog_.reset(build_maths_matrix());
56 fl_addto_choice(dialog_->choice_valign, _("Top | Center | Bottom"));
57 fl_set_choice(dialog_->choice_valign, 2);
58 fl_set_input(dialog_->input_halign, h_align_str);
59 dialog_->input_halign->u_vdata = this;
60 fl_set_input_filter(dialog_->input_halign,
61 C_FormMathsMatrixAlignFilter);
63 bc().setOK(dialog_->button_ok);
64 bc().setApply(dialog_->button_apply);
65 bc().setCancel(dialog_->button_cancel);
67 bc().addReadOnly(dialog_->slider_rows);
68 bc().addReadOnly(dialog_->slider_columns);
69 bc().addReadOnly(dialog_->choice_valign);
70 bc().addReadOnly(dialog_->input_halign);
74 void FormMathsMatrix::apply()
76 char const c = v_align_c[fl_get_choice(dialog_->choice_valign) - 1];
77 char const * sh = fl_get_input(dialog_->input_halign);
78 int const nx = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
79 int const ny = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
81 std::ostringstream ost;
82 ost << nx << ' ' << ny << ' ' << c << sh;
84 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
87 bool FormMathsMatrix::input(FL_OBJECT * ob, long)
89 if (ob == dialog_->choice_valign ||
90 ob == dialog_->slider_rows) return true;
92 int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
93 for (int i = 0; i < nx; ++i)
96 h_align_str[nx] = '\0';
98 fl_set_input(dialog_->input_halign, h_align_str);
99 fl_redraw_object(dialog_->input_halign);
104 int FormMathsMatrix::AlignFilter(char const * cur, int c)
106 int n = int(fl_get_slider_value(dialog_->slider_columns)+0.5) -
111 if (c == 'c' || c == 'l' || c == 'r')