3 * \file FormMathsMatrix.C
4 * Copyright 2001 The LyX Team.
5 * See the file COPYING.
7 * \author Alejandro Aguilar Sierra
8 * \author Pablo De Napoli, pdenapo@dm.uba.ar
9 * \author John Levon, moz@compsoc.man.ac.uk
10 * \author Angus Leeming, a.leeming@ic.ac.uk
16 #pragma implementation
19 #include "FormMathsMatrix.h"
20 #include "form_maths_matrix.h"
25 #include "support/LAssert.h"
27 #ifndef CXX_GLOBAL_CSTD
32 static char h_align_str[80] = "c";
33 static char v_align_c[] = "tcb";
36 int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
37 char const * cur, int c)
40 FormMathsMatrix * pre = static_cast<FormMathsMatrix *>(ob->u_vdata);
42 return pre->AlignFilter(cur, c);
46 FormMathsMatrix::FormMathsMatrix(LyXView * lv, Dialogs * d,
47 FormMathsPanel const & p)
48 : FormMathsSub(lv, d, p, _("Maths Matrix"))
52 FL_FORM * FormMathsMatrix::form() const
60 void FormMathsMatrix::build()
62 dialog_.reset(build_maths_matrix());
64 fl_addto_choice(dialog_->choice_valign, _("Top | Center | Bottom"));
65 fl_set_choice(dialog_->choice_valign, 2);
66 fl_set_input(dialog_->input_halign, h_align_str);
67 dialog_->input_halign->u_vdata = this;
68 fl_set_input_filter(dialog_->input_halign,
69 C_FormMathsMatrixAlignFilter);
71 bc().setOK(dialog_->button_ok);
72 bc().setApply(dialog_->button_apply);
73 bc().setCancel(dialog_->button_cancel);
75 bc().addReadOnly(dialog_->slider_rows);
76 bc().addReadOnly(dialog_->slider_columns);
77 bc().addReadOnly(dialog_->choice_valign);
78 bc().addReadOnly(dialog_->input_halign);
82 void FormMathsMatrix::apply()
84 char const c = v_align_c[fl_get_choice(dialog_->choice_valign) - 1];
85 char const * sh = fl_get_input(dialog_->input_halign);
86 int const nx = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
87 int const ny = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
89 std::ostringstream ost;
90 ost << nx << ' ' << ny << ' ' << c << sh;
92 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
95 bool FormMathsMatrix::input(FL_OBJECT * ob, long)
97 if (ob == dialog_->choice_valign ||
98 ob == dialog_->slider_rows) return true;
100 int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
101 for (int i = 0; i < nx; ++i)
102 h_align_str[i] = 'c';
104 h_align_str[nx] = '\0';
106 fl_set_input(dialog_->input_halign, h_align_str);
107 fl_redraw_object(dialog_->input_halign);
112 int FormMathsMatrix::AlignFilter(char const * cur, int c)
114 int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5) -
119 if (c == 'c' || c == 'l' || c == 'r')