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"
31 extern "C" void C_FormDialogView_CancelCB(FL_OBJECT *, long);
32 extern "C" void C_FormDialogView_InputCB(FL_OBJECT *, long);
34 FD_maths_bitmap::~FD_maths_bitmap()
36 if (form->visible) fl_hide_form(form);
41 typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
44 FormMathsBitmap::FormMathsBitmap(Dialog & parent, string const & t, vector<string> const & l)
45 : base_class(parent, t, false),
46 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
48 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
54 void FormMathsBitmap::addBitmap(BitmapStore const & bm)
56 bitmaps_.push_back(bm);
58 int wx = bm.bw + ww_ / 2;
59 int wy = bm.bh + ww_ / 2;
66 w_ = max(x_ + wx + ww_, w_);
70 h_ = max(y_ + wy + ww_, h_);
75 void FormMathsBitmap::build()
77 BOOST_ASSERT(bitmaps_.size() > 0);
79 h_+= 42; // Allow room for a Close button
81 FD_maths_bitmap * fdui = new FD_maths_bitmap;
83 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
84 fdui->form->u_vdata = this;
86 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
92 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
93 it < bitmaps_.end(); ++it) {
94 FL_OBJECT * obj = buildBitmap(*it);
96 bcview().addReadOnly(obj);
97 y_close = max(y_close, obj->y + obj->h);
101 x_ = (fdui->form->w - 90) / 2;
104 string const label = _("Close|^[");
105 fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
106 idex(label).c_str());
107 fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
108 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
109 fl_set_object_callback(fdui->button_close, C_FormDialogView_CancelCB, 0);
113 fdui->form->fdui = fdui;
120 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
122 // Add a bitmap to a button panel: one bitmap per panel.
123 // nt is the number of buttons and nx, ny the nr. of buttons
124 // in x and y direction.
125 // bw, bh and data are the bitmap dimensions width, height and
126 // bit pattern; these come directly from an .xbm file included
128 // vert indicates whether the next button panel within this
129 // window will be below (true, default) or next to this one.
131 // The scaling of the bitmap on top of the buttons will be
132 // correct if the nx, ny values are given correctly.
133 int wx = bmstore.bw + ww_ / 2;
134 int wy = bmstore.bh + ww_ / 2;
135 wx += (wx % bmstore.nx);
136 wy += (wy % bmstore.ny);
138 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
139 fl_set_object_lcol(obj, FL_BLUE);
140 fl_set_object_boxtype(obj, FL_UP_BOX);
141 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
143 fl_set_bmtable_maxitems(obj, bmstore.nt);
144 fl_set_object_callback(obj, C_FormDialogView_InputCB, 0);
156 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
160 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
161 if (ob->objclass != FL_BMTABLE)
165 return k + fl_get_bmtable(ob);
167 k += fl_get_bmtable_maxitems(ob);
174 void FormMathsBitmap::apply()
176 controller().dispatchInsert(latex_chosen_);
180 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
182 int const i = GetIndex(ob);
185 return ButtonPolicy::SMI_INVALID;
187 latex_chosen_ = latex_[i];
189 return ButtonPolicy::SMI_VALID;
192 } // namespace frontend