2 * \file FormMathsMatrix.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Pablo De Napoli
9 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
16 #include "FormMathsMatrix.h"
17 #include "forms/form_maths_matrix.h"
18 #include "ControlMath.h"
22 #include "controllers/ButtonController.h"
24 #include "support/lyxalgo.h" // lyx::count
26 #include "lyx_forms.h"
31 using std::ostringstream;
33 #ifndef CXX_GLOBAL_CSTD
42 char h_align_str[80] = "c";
43 char v_align_c[] = "tcb";
47 int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
48 char const * cur, int c)
51 FormMathsMatrix * pre =
52 static_cast<FormMathsMatrix *>(ob->u_vdata);
54 return pre->AlignFilter(cur, c);
60 typedef FormController<ControlMath, FormView<FD_maths_matrix> > base_class;
62 FormMathsMatrix::FormMathsMatrix(Dialog & parent)
63 : base_class(parent, _("Math Matrix"), false)
67 void FormMathsMatrix::build()
69 dialog_.reset(build_maths_matrix(this));
71 fl_addto_choice(dialog_->choice_valign,
72 _("Top | Middle | Bottom").c_str());
73 fl_set_choice(dialog_->choice_valign, 2);
74 fl_set_input(dialog_->input_halign, h_align_str);
75 dialog_->input_halign->u_vdata = this;
76 fl_set_input_filter(dialog_->input_halign,
77 C_FormMathsMatrixAlignFilter);
78 setPrehandler(dialog_->input_halign);
80 bcview().setOK(dialog_->button_ok);
81 bcview().setApply(dialog_->button_apply);
82 bcview().setCancel(dialog_->button_close);
84 bcview().addReadOnly(dialog_->slider_rows);
85 bcview().addReadOnly(dialog_->slider_columns);
86 bcview().addReadOnly(dialog_->choice_valign);
87 bcview().addReadOnly(dialog_->input_halign);
91 void FormMathsMatrix::apply()
93 char const c = v_align_c[fl_get_choice(dialog_->choice_valign) - 1];
94 char const * sh = fl_get_input(dialog_->input_halign);
95 int const nx = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
96 int const ny = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
99 os << nx << ' ' << ny << ' ' << c << ' ' << sh;
100 controller().dispatchMatrix(os.str());
104 void FormMathsMatrix::update()
110 ButtonPolicy::SMInput FormMathsMatrix::input(FL_OBJECT * ob, long)
112 if (ob == dialog_->choice_valign ||
113 ob == dialog_->slider_rows) return ButtonPolicy::SMI_VALID;
115 int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
116 for (int i = 0; i < nx; ++i)
117 h_align_str[i] = 'c';
119 h_align_str[nx] = '\0';
121 fl_set_input(dialog_->input_halign, h_align_str);
122 fl_redraw_object(dialog_->input_halign);
123 return ButtonPolicy::SMI_VALID;
127 int FormMathsMatrix::AlignFilter(char const * cur, int c)
129 size_t const len = strlen(cur);
131 int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5)
133 + int(count(cur, cur + len, '|'));
137 if (c == 'c' || c == 'l' || c == 'r' || c == '|')
143 } // namespace frontend