]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsBitmap.C
Add fl_set_input_return to input_paperoption.
[lyx.git] / src / frontends / xforms / FormMathsBitmap.C
1 /**
2  * \file FormMathsBitmap.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author John Levon, moz@compsoc.man.ac.uk
8  * \author Angus Leeming, a.leeming@ic.ac.uk
9  */
10
11 #include <config.h>
12 #include <algorithm>
13 #include <iomanip>
14  
15 #include XPM_H_LOCATION
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FormMathsBitmap.h"
22
23 #include "Dialogs.h"
24 #include "LyXView.h"
25 #include "bmtable.h"
26 #include "debug.h"
27 #include "lyx_gui_misc.h" // scex, idex
28 #include "gettext.h"
29 #include "support/LAssert.h"
30
31 using std::vector;
32 using std::endl;
33 using std::setw;
34 using std::max;
35
36 extern  "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
37 extern  "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
38
39 FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,   
40                                  FormMathsPanel const & p,
41                                  vector<string> const & l)
42         : FormMathsSub(lv, d, p, _("Maths Bitmaps")),
43           latex_(l), form_(0), ww_(0), x_(0), y_(0), w_(0), h_(0)
44 {
45         ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
46         x_ = y_ = ww_;
47         y_ += 8;
48 }
49
50
51 FL_FORM * FormMathsBitmap::form() const
52 {
53         return form_;
54 }
55
56
57 void FormMathsBitmap::build()
58 {
59         lyx::Assert(bitmaps_.size() > 0);
60
61         h_+= 50; // Allow room for a Close button
62
63         form_ = fl_bgn_form(FL_UP_BOX, w_, h_);
64         form_->u_vdata = this;
65
66         FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
67
68         y_ = 0;
69         for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
70              it < bitmaps_.end(); ++it) {
71                 FL_OBJECT * obj = it->get();
72
73                 fl_add_object(form_, obj);
74                 bc().addReadOnly(obj);
75
76                 y_ = max(y_, obj->y + obj->h);
77         }
78  
79         char const * const label = N_("Close|^[");
80
81         x_ = (form_->w - 90) / 2;
82         y_ += 10;
83                 
84         FL_OBJECT * button_cancel = obj = 
85                 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
86         fl_set_button_shortcut(obj, scex(_(label)), 1);
87
88         fl_set_object_lsize(obj, FL_NORMAL_SIZE);
89         fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0);
90
91         fl_end_form();
92
93         bc().setCancel(button_cancel);
94 }
95
96
97 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
98                                 unsigned char const * data, bool vert)
99 {
100         int wx = bw + ww_ / 2;
101         int wy = bh + ww_ / 2;
102         wx += (wx % nx);
103         wy += (wy % ny);
104
105         FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
106         fl_set_object_lcol(obj, FL_BLUE);
107         fl_set_object_boxtype(obj, FL_UP_BOX);
108         fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
109         fl_set_bmtable_maxitems(obj, nt);
110         fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
111
112         if (vert) {
113                 y_ += wy + 8;
114                 h_ = max(y_, h_);
115                 w_ = max(x_ + wx + ww_, w_);
116         } else  {
117                 x_ += wx + 8;
118                 w_ = max(x_, w_);
119                 h_ = max(y_ + wy + ww_, h_);
120         }
121
122         bitmaps_.push_back(bm_ptr(obj));
123 }
124
125
126 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
127 {
128         int k = 0;
129         for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
130              it < bitmaps_.end(); ++it) {
131                 if (it->get() == ob)
132                         return k + fl_get_bmtable(ob);
133                 else
134                         k += fl_get_bmtable_maxitems(it->get());
135         }
136         return -1;
137 }
138
139
140 void FormMathsBitmap::apply()
141 {
142         parent_.insertSymbol(latex_chosen_);
143 }
144
145
146 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
147 {
148         int const i = GetIndex(ob);
149
150         if (i < 0) 
151                 return false;
152
153         latex_chosen_ = latex_[i];
154         apply();
155         return true;
156 }