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
20 #include "FormMathsMatrix.h"
21 #include "form_maths_matrix.h"
26 #include "support/LAssert.h"
27 #include "support/lyxalgo.h" // lyx::count
29 #ifndef CXX_GLOBAL_CSTD
34 static char h_align_str[80] = "c";
35 static char v_align_c[] = "tcb";
41 int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
42 char const * cur, int c)
45 FormMathsMatrix * pre =
46 static_cast<FormMathsMatrix *>(ob->u_vdata);
48 return pre->AlignFilter(cur, c);
54 FormMathsMatrix::FormMathsMatrix(LyXView * lv, Dialogs * d,
55 FormMathsPanel const & p)
56 : FormMathsSub(lv, d, p, _("Maths Matrix"), false)
60 FL_FORM * FormMathsMatrix::form() const
68 void FormMathsMatrix::build()
70 dialog_.reset(build_maths_matrix());
72 fl_addto_choice(dialog_->choice_valign, _("Top | Center | Bottom"));
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 bc().setOK(dialog_->button_ok);
81 bc().setApply(dialog_->button_apply);
82 bc().setCancel(dialog_->button_close);
84 bc().addReadOnly(dialog_->slider_rows);
85 bc().addReadOnly(dialog_->slider_columns);
86 bc().addReadOnly(dialog_->choice_valign);
87 bc().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 ost << nx << ' ' << ny << ' ' << c << ' ' << sh;
101 lv_->getLyXFunc()->dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
104 bool FormMathsMatrix::input(FL_OBJECT * ob, long)
106 if (ob == dialog_->choice_valign ||
107 ob == dialog_->slider_rows) return true;
109 int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
110 for (int i = 0; i < nx; ++i)
111 h_align_str[i] = 'c';
113 h_align_str[nx] = '\0';
115 fl_set_input(dialog_->input_halign, h_align_str);
116 fl_redraw_object(dialog_->input_halign);
121 int FormMathsMatrix::AlignFilter(char const * cur, int c)
123 size_t len = strlen(cur);
125 int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5) -
127 int(lyx::count(cur, cur + len, '|'));
131 if (c == 'c' || c == 'l' || c == 'r' || c == '|')