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.
16 #include "FormMathsBitmap.h"
17 #include "ControlMath.h"
21 #include "forms_gettext.h"
23 #include "support/LAssert.h"
29 extern "C" void C_FormDialogView_CancelCB(FL_OBJECT *, long);
30 extern "C" void C_FormDialogView_InputCB(FL_OBJECT *, long);
32 using namespace lyx::support;
38 FD_maths_bitmap::~FD_maths_bitmap()
40 if (form->visible) fl_hide_form(form);
45 typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
48 FormMathsBitmap::FormMathsBitmap(Dialog & parent, string const & t, vector<string> const & l)
49 : base_class(parent, t, false),
50 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
52 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
58 void FormMathsBitmap::addBitmap(BitmapStore const & bm)
60 bitmaps_.push_back(bm);
62 int wx = bm.bw + ww_ / 2;
63 int wy = bm.bh + ww_ / 2;
70 w_ = max(x_ + wx + ww_, w_);
74 h_ = max(y_ + wy + ww_, h_);
79 void FormMathsBitmap::build()
81 Assert(bitmaps_.size() > 0);
83 h_+= 42; // Allow room for a Close button
85 FD_maths_bitmap * fdui = new FD_maths_bitmap;
87 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
88 fdui->form->u_vdata = this;
90 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
96 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
97 it < bitmaps_.end(); ++it) {
98 FL_OBJECT * obj = buildBitmap(*it);
100 bcview().addReadOnly(obj);
101 y_close = max(y_close, obj->y + obj->h);
105 x_ = (fdui->form->w - 90) / 2;
108 string const label = _("Close|^[");
109 fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
110 idex(label).c_str());
111 fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
112 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
113 fl_set_object_callback(fdui->button_close, C_FormDialogView_CancelCB, 0);
117 fdui->form->fdui = fdui;
124 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
126 // Add a bitmap to a button panel: one bitmap per panel.
127 // nt is the number of buttons and nx, ny the nr. of buttons
128 // in x and y direction.
129 // bw, bh and data are the bitmap dimensions width, height and
130 // bit pattern; these come directly from an .xbm file included
132 // vert indicates whether the next button panel within this
133 // window will be below (true, default) or next to this one.
135 // The scaling of the bitmap on top of the buttons will be
136 // correct if the nx, ny values are given correctly.
137 int wx = bmstore.bw + ww_ / 2;
138 int wy = bmstore.bh + ww_ / 2;
139 wx += (wx % bmstore.nx);
140 wy += (wy % bmstore.ny);
142 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
143 fl_set_object_lcol(obj, FL_BLUE);
144 fl_set_object_boxtype(obj, FL_UP_BOX);
145 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
147 fl_set_bmtable_maxitems(obj, bmstore.nt);
148 fl_set_object_callback(obj, C_FormDialogView_InputCB, 0);
160 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
164 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
165 if (ob->objclass != FL_BMTABLE)
169 return k + fl_get_bmtable(ob);
171 k += fl_get_bmtable_maxitems(ob);
178 void FormMathsBitmap::apply()
180 string::size_type const i = latex_chosen_.find(' ');
181 if (i != string::npos) {
182 controller().dispatchFunc(LFUN_MATH_MODE);
183 controller().dispatchInsert(latex_chosen_.substr(0,i));
184 controller().dispatchInsert('\\' + latex_chosen_.substr(i + 1));
186 controller().dispatchInsert(latex_chosen_);
190 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
192 int const i = GetIndex(ob);
195 return ButtonPolicy::SMI_INVALID;
197 latex_chosen_ = latex_[i];
199 return ButtonPolicy::SMI_VALID;