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);
36 FD_maths_bitmap::~FD_maths_bitmap()
38 if (form->visible) fl_hide_form(form);
43 typedef FormController<ControlMath, FormView<FD_maths_bitmap> > base_class;
46 FormMathsBitmap::FormMathsBitmap(Dialog & parent, string const & t, vector<string> const & l)
47 : base_class(parent, 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(BitmapStore const & bm)
58 bitmaps_.push_back(bm);
60 int wx = bm.bw + ww_ / 2;
61 int wy = bm.bh + ww_ / 2;
68 w_ = max(x_ + wx + ww_, w_);
72 h_ = max(y_ + wy + ww_, h_);
77 void FormMathsBitmap::build()
79 lyx::Assert(bitmaps_.size() > 0);
81 h_+= 42; // Allow room for a Close button
83 FD_maths_bitmap * fdui = new FD_maths_bitmap;
85 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
86 fdui->form->u_vdata = this;
88 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
94 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
95 it < bitmaps_.end(); ++it) {
96 FL_OBJECT * obj = buildBitmap(*it);
98 bcview().addReadOnly(obj);
99 y_close = max(y_close, obj->y + obj->h);
103 x_ = (fdui->form->w - 90) / 2;
106 string const label = _("Close|^[");
107 fdui->button_close = fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
108 idex(label).c_str());
109 fl_set_button_shortcut(fdui->button_close, scex(label).c_str(), 1);
110 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
111 fl_set_object_callback(fdui->button_close, C_FormDialogView_CancelCB, 0);
115 fdui->form->fdui = fdui;
122 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
124 // Add a bitmap to a button panel: one bitmap per panel.
125 // nt is the number of buttons and nx, ny the nr. of buttons
126 // in x and y direction.
127 // bw, bh and data are the bitmap dimensions width, height and
128 // bit pattern; these come directly from an .xbm file included
130 // vert indicates whether the next button panel within this
131 // window will be below (true, default) or next to this one.
133 // The scaling of the bitmap on top of the buttons will be
134 // correct if the nx, ny values are given correctly.
135 int wx = bmstore.bw + ww_ / 2;
136 int wy = bmstore.bh + ww_ / 2;
137 wx += (wx % bmstore.nx);
138 wy += (wy % bmstore.ny);
140 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
141 fl_set_object_lcol(obj, FL_BLUE);
142 fl_set_object_boxtype(obj, FL_UP_BOX);
143 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
145 fl_set_bmtable_maxitems(obj, bmstore.nt);
146 fl_set_object_callback(obj, C_FormDialogView_InputCB, 0);
158 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
162 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
163 if (ob->objclass != FL_BMTABLE)
167 return k + fl_get_bmtable(ob);
169 k += fl_get_bmtable_maxitems(ob);
176 void FormMathsBitmap::apply()
178 string::size_type const i = latex_chosen_.find(' ');
179 if (i != string::npos) {
180 controller().dispatchFunc(LFUN_MATH_MODE);
181 controller().dispatchInsert(latex_chosen_.substr(0,i));
182 controller().dispatchInsert('\\' + latex_chosen_.substr(i + 1));
184 controller().dispatchInsert(latex_chosen_);
188 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
190 int const i = GetIndex(ob);
193 return ButtonPolicy::SMI_INVALID;
195 latex_chosen_ = latex_[i];
197 return ButtonPolicy::SMI_VALID;