]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsMatrix.C
More include changes
[lyx.git] / src / frontends / xforms / FormMathsMatrix.C
1 /**
2  * \file FormMathsMatrix.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
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
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include "FormMathsMatrix.h"
19 #include "form_maths_matrix.h"
20 #include "Dialogs.h"
21 #include "LyXView.h"
22 #include "Lsstream.h"
23 #include "lyxfunc.h"
24 #include "support/LAssert.h"
25
26 static char h_align_str[80] = "c";
27 static char v_align_c[] = "tcb";
28
29 extern "C"
30 int C_FormMathsMatrixAlignFilter(FL_OBJECT * ob, char const *,
31                                             char const * cur, int c)
32 {
33         lyx::Assert(ob);
34         FormMathsMatrix * pre = static_cast<FormMathsMatrix *>(ob->u_vdata);
35         lyx::Assert(pre);
36         return pre->AlignFilter(cur, c);
37 }
38
39
40 FormMathsMatrix::FormMathsMatrix(LyXView * lv, Dialogs * d,
41                                FormMathsPanel const & p)
42         : FormMathsSub(lv, d, p, _("Maths Matrix"))
43 {}
44
45
46 FL_FORM * FormMathsMatrix::form() const
47 {
48         if (dialog_.get())
49                 return dialog_->form;
50         return 0;
51 }
52
53
54 void FormMathsMatrix::build()
55 {
56         dialog_.reset(build_maths_matrix());
57
58         fl_addto_choice(dialog_->choice_valign, _("Top | Center | Bottom"));
59         fl_set_choice(dialog_->choice_valign, 2);
60         fl_set_input(dialog_->input_halign, h_align_str);
61         dialog_->input_halign->u_vdata = this;
62         fl_set_input_filter(dialog_->input_halign,
63                             C_FormMathsMatrixAlignFilter);
64
65         bc().setOK(dialog_->button_ok);
66         bc().setApply(dialog_->button_apply);
67         bc().setCancel(dialog_->button_cancel);
68
69         bc().addReadOnly(dialog_->slider_rows);
70         bc().addReadOnly(dialog_->slider_columns);
71         bc().addReadOnly(dialog_->choice_valign);
72         bc().addReadOnly(dialog_->input_halign);
73 }
74
75
76 void FormMathsMatrix::apply()
77 {
78         char const c = v_align_c[fl_get_choice(dialog_->choice_valign) - 1];
79         char const * sh = fl_get_input(dialog_->input_halign);
80         int const nx = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
81         int const ny = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
82  
83         std::ostringstream ost;
84         ost << nx << ' ' << ny << ' ' << c << sh;
85  
86         lv_->getLyXFunc()->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str());
87 }
88
89 bool FormMathsMatrix::input(FL_OBJECT * ob, long)
90 {
91         if (ob == dialog_->choice_valign ||
92             ob == dialog_->slider_rows) return true;
93
94         int const nx = int(fl_get_slider_value(dialog_->slider_columns)+0.5);
95         for (int i = 0; i < nx; ++i)
96                 h_align_str[i] = 'c';
97  
98         h_align_str[nx] = '\0';
99
100         fl_set_input(dialog_->input_halign, h_align_str);
101         fl_redraw_object(dialog_->input_halign);
102         return true;
103 }
104
105
106 int FormMathsMatrix::AlignFilter(char const * cur, int c)
107 {
108         int n = int(fl_get_slider_value(dialog_->slider_columns)+0.5) -
109                 int(strlen(cur));
110         if (n < 0)
111                 return FL_INVALID;
112
113         if (c == 'c' || c == 'l' || c == 'r') 
114                 return FL_VALID;
115  
116         return FL_INVALID;
117 }