]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsStyle.C
Introduce LFUN_PRINT.
[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
29 char const * latex_mathstyle[] = {
30         "displaystyle", "textstyle", "scriptstyle", "scriptscriptstyle"
31 };
32
33 kb_action latex_mathfontcmds[] = {
34         LFUN_BOLD, LFUN_SANS, LFUN_ROMAN, LFUN_ITAL, LFUN_CODE,
35         LFUN_NOUN, LFUN_FRAK, LFUN_EMPH, LFUN_FREEFONT_APPLY, LFUN_DEFAULT
36 };
37
38
39 typedef FormController<ControlMath, FormView<FD_maths_style> > base_class;
40
41 FormMathsStyle::FormMathsStyle(Dialog & parent)
42         : base_class(parent, _("Math Styles & Fonts"), false),
43           style_(-1)
44 {}
45
46
47 void FormMathsStyle::build()
48 {
49         dialog_.reset(build_maths_style(this));
50
51         fl_set_bmtable_data(dialog_->bmtable_style1, 1, 1,
52                             style1_width, style1_height, style1_bits);
53         fl_set_bmtable_maxitems(dialog_->bmtable_style1, 1);
54         bcview().addReadOnly(dialog_->bmtable_style1);
55
56         fl_set_bmtable_data(dialog_->bmtable_style2, 1, 3,
57                             style2_width, style2_height, style2_bits);
58         fl_set_bmtable_maxitems(dialog_->bmtable_style2, 3);
59         bcview().addReadOnly(dialog_->bmtable_style2);
60
61         fl_set_bmtable_data(dialog_->bmtable_font1, 1, 5,
62                             font1_width, font1_height, font1_bits);
63         fl_set_bmtable_maxitems(dialog_->bmtable_font1, 5);
64         bcview().addReadOnly(dialog_->bmtable_font1);
65
66         fl_set_bmtable_data(dialog_->bmtable_font2, 1, 3,
67                             font2_width, font2_height, font2_bits);
68         fl_set_bmtable_maxitems(dialog_->bmtable_font2, 3);
69         bcview().addReadOnly(dialog_->bmtable_font2);
70
71         bcview().setCancel(dialog_->button_close);
72 }
73
74
75 void FormMathsStyle::apply()
76 {
77         if ((style_ >= 0) && (style_ < 4))
78                 controller().dispatchInsert(latex_mathstyle[style_]);
79         else if ((style_ >= 4) && (style_ < 14))
80                 controller().dispatchFunc(latex_mathfontcmds[style_-4]);
81 }
82
83
84 ButtonPolicy::SMInput FormMathsStyle::input(FL_OBJECT * ob, long data)
85 {
86         style_ = fl_get_bmtable(ob);
87         if (style_ < 0) return ButtonPolicy::SMI_INVALID;
88
89         //if (ob == dialog_->bmtable_style1) style_ += 0;
90         if (ob == dialog_->bmtable_style2) style_ += 1;
91         if (ob == dialog_->bmtable_font1)  style_ += 4;
92         if (ob == dialog_->bmtable_font2)  style_ += 9;
93         if (data >= 12) style_ = short(data);
94         apply();
95
96         return ButtonPolicy::SMI_VALID;
97 }