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_FormBaseCancelCB(FL_OBJECT *, long);
30 extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
36 FD_maths_bitmap::~FD_maths_bitmap()
38 if (form->visible) fl_hide_form(form);
43 typedef FormCB<ControlMathSub, FormDB<FD_maths_bitmap> > base_class;
46 FormMathsBitmap::FormMathsBitmap(string const & t, vector<string> const & l)
47 : base_class(t, false),
48 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
50 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
56 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
57 unsigned char const * data, bool vert)
59 bitmaps_.push_back(BitmapStore(nt, nx, ny, bw, bh, data, vert));
61 int wx = bw + ww_ / 2;
62 int wy = bh + ww_ / 2;
69 w_ = max(x_ + wx + ww_, w_);
73 h_ = max(y_ + wy + ww_, h_);
78 void FormMathsBitmap::build()
80 lyx::Assert(bitmaps_.size() > 0);
82 h_+= 42; // Allow room for a Close button
84 FD_maths_bitmap * fdui = new FD_maths_bitmap;
86 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
87 fdui->form->u_vdata = this;
89 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
95 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
96 it < bitmaps_.end(); ++it) {
97 FL_OBJECT * obj = buildBitmap(*it);
99 bcview().addReadOnly(obj);
100 y_close = max(y_close, obj->y + obj->h);
104 x_ = (fdui->form->w - 90) / 2;
107 string const label = _("Close|^[");
108 fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
109 idex(label).c_str());
110 fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
111 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
112 fl_set_object_callback(fdui->button_close, C_FormBaseCancelCB, 0);
116 fdui->form->fdui = fdui;
119 bcview().setCancel(dialog_->button_close);
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_FormBaseInputCB, 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().insertSymbol(latex_chosen_.substr(0,i));
184 controller().insertSymbol(latex_chosen_.substr(i + 1), false);
186 controller().insertSymbol(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;