2 * \file FormMathsBitmap.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "FormMathsBitmap.h"
18 #include "forms_gettext.h"
21 #include "ControlMath.h"
28 extern "C" void C_FormDialogView_CancelCB(FL_OBJECT *, long);
29 extern "C" void C_FormDialogView_InputCB(FL_OBJECT *, long);
31 FD_maths_bitmap::~FD_maths_bitmap()
33 if (form->visible) fl_hide_form(form);
38 typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
41 FormMathsBitmap::FormMathsBitmap(Dialog & parent, string const & t, vector<string> const & l)
42 : base_class(parent, t, false),
43 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
45 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
51 void FormMathsBitmap::addBitmap(BitmapStore const & bm)
53 bitmaps_.push_back(bm);
55 int wx = bm.bw + ww_ / 2;
56 int wy = bm.bh + ww_ / 2;
63 w_ = max(x_ + wx + ww_, w_);
67 h_ = max(y_ + wy + ww_, h_);
72 void FormMathsBitmap::build()
74 BOOST_ASSERT(bitmaps_.size() > 0);
76 h_+= 42; // Allow room for a Close button
78 FD_maths_bitmap * fdui = new FD_maths_bitmap;
80 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
81 fdui->form->u_vdata = this;
83 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
89 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
90 it < bitmaps_.end(); ++it) {
91 FL_OBJECT * obj = buildBitmap(*it);
93 bcview().addReadOnly(obj);
94 y_close = max(y_close, obj->y + obj->h);
98 x_ = (fdui->form->w - 90) / 2;
101 string const label = _("Close|^[");
102 fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
103 idex(label).c_str());
104 fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
105 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
106 fl_set_object_callback(fdui->button_close, C_FormDialogView_CancelCB, 0);
110 fdui->form->fdui = fdui;
117 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
119 // Add a bitmap to a button panel: one bitmap per panel.
120 // nt is the number of buttons and nx, ny the nr. of buttons
121 // in x and y direction.
122 // bw, bh and data are the bitmap dimensions width, height and
123 // bit pattern; these come directly from an .xbm file included
125 // vert indicates whether the next button panel within this
126 // window will be below (true, default) or next to this one.
128 // The scaling of the bitmap on top of the buttons will be
129 // correct if the nx, ny values are given correctly.
130 int wx = bmstore.bw + ww_ / 2;
131 int wy = bmstore.bh + ww_ / 2;
132 wx += (wx % bmstore.nx);
133 wy += (wy % bmstore.ny);
135 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
136 fl_set_object_lcol(obj, FL_BLUE);
137 fl_set_object_boxtype(obj, FL_UP_BOX);
138 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
140 fl_set_bmtable_maxitems(obj, bmstore.nt);
141 fl_set_object_callback(obj, C_FormDialogView_InputCB, 0);
153 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
157 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
158 if (ob->objclass != FL_BMTABLE)
162 return k + fl_get_bmtable(ob);
164 k += fl_get_bmtable_maxitems(ob);
171 void FormMathsBitmap::apply()
173 string::size_type const i = latex_chosen_.find(' ');
174 if (i != string::npos) {
175 controller().dispatchFunc(LFUN_MATH_MODE);
176 controller().dispatchInsert(latex_chosen_.substr(0,i));
177 controller().dispatchInsert('\\' + latex_chosen_.substr(i + 1));
179 controller().dispatchInsert(latex_chosen_);
183 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
185 int const i = GetIndex(ob);
188 return ButtonPolicy::SMI_INVALID;
190 latex_chosen_ = latex_[i];
192 return ButtonPolicy::SMI_VALID;