]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsStyle.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / FormMathsStyle.C
1 /**
2  * \file FormMathsStyle.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Pablo De Napoli
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS.
12  * Adapted from FormMathsSpace martin.vermeer@hut.fi
13  */
14
15 #include <config.h>
16
17 #include "FormMathsStyle.h"
18 #include "forms/form_maths_style.h"
19 #include "ControlMath.h"
20 #include "xformsBC.h"
21
22 #include "lyx_forms.h"
23 #include "bmtable.h"
24
25 #include "style.xbm"
26 #include "font.xbm"
27
28 namespace lyx {
29 namespace frontend {
30
31 namespace {
32
33 char const * latex_mathstyle[] = {
34         "displaystyle", "textstyle", "scriptstyle", "scriptscriptstyle"
35 };
36
37 kb_action latex_mathfontcmds[] = {
38         LFUN_BOLD, LFUN_SANS, LFUN_ROMAN, LFUN_ITAL, LFUN_CODE,
39         LFUN_NOUN, LFUN_FRAK, LFUN_EMPH, LFUN_FREEFONT_APPLY, LFUN_DEFAULT
40 };
41
42 } // namespace anon
43
44
45 typedef FormController<ControlMath, FormView<FD_maths_style> > base_class;
46
47 FormMathsStyle::FormMathsStyle(Dialog & parent)
48         : base_class(parent, _("Math Styles & Fonts"), false),
49           style_(-1)
50 {}
51
52
53 void FormMathsStyle::build()
54 {
55         dialog_.reset(build_maths_style(this));
56
57         fl_set_bmtable_data(dialog_->bmtable_style1, 1, 1,
58                             style1_width, style1_height, style1_bits);
59         fl_set_bmtable_maxitems(dialog_->bmtable_style1, 1);
60         bcview().addReadOnly(dialog_->bmtable_style1);
61
62         fl_set_bmtable_data(dialog_->bmtable_style2, 1, 3,
63                             style2_width, style2_height, style2_bits);
64         fl_set_bmtable_maxitems(dialog_->bmtable_style2, 3);
65         bcview().addReadOnly(dialog_->bmtable_style2);
66
67         fl_set_bmtable_data(dialog_->bmtable_font1, 1, 5,
68                             font1_width, font1_height, font1_bits);
69         fl_set_bmtable_maxitems(dialog_->bmtable_font1, 5);
70         bcview().addReadOnly(dialog_->bmtable_font1);
71
72         fl_set_bmtable_data(dialog_->bmtable_font2, 1, 3,
73                             font2_width, font2_height, font2_bits);
74         fl_set_bmtable_maxitems(dialog_->bmtable_font2, 3);
75         bcview().addReadOnly(dialog_->bmtable_font2);
76
77         bcview().setCancel(dialog_->button_close);
78 }
79
80
81 void FormMathsStyle::apply()
82 {
83         if ((style_ >= 0) && (style_ < 4))
84                 controller().dispatchInsert(latex_mathstyle[style_]);
85         else if ((style_ >= 4) && (style_ < 14))
86                 controller().dispatchFunc(latex_mathfontcmds[style_-4]);
87 }
88
89
90 ButtonPolicy::SMInput FormMathsStyle::input(FL_OBJECT * ob, long data)
91 {
92         style_ = fl_get_bmtable(ob);
93         if (style_ < 0) return ButtonPolicy::SMI_INVALID;
94
95         //if (ob == dialog_->bmtable_style1) style_ += 0;
96         if (ob == dialog_->bmtable_style2) style_ += 1;
97         if (ob == dialog_->bmtable_font1)  style_ += 4;
98         if (ob == dialog_->bmtable_font2)  style_ += 9;
99         if (data >= 12) style_ = short(data);
100         apply();
101
102         return ButtonPolicy::SMI_VALID;
103 }
104
105 } // namespace frontend
106 } // namespace lyx