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 #pragma implementation
19 #include "FormMathsBitmap.h"
20 #include "ControlMath.h"
24 #include "forms_gettext.h"
26 #include "support/LAssert.h"
28 #include XPM_H_LOCATION
32 extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
33 extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
39 FD_maths_bitmap::~FD_maths_bitmap()
41 if (form->visible) fl_hide_form(form);
46 typedef FormCB<ControlMathSub, FormDB<FD_maths_bitmap> > base_class;
49 FormMathsBitmap::FormMathsBitmap(string const & t, vector<string> const & l)
50 : base_class(t, false),
51 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
53 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
59 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
60 unsigned char const * data, bool vert)
62 bitmaps_.push_back(BitmapStore(nt, nx, ny, bw, bh, data, vert));
64 int wx = bw + ww_ / 2;
65 int wy = bh + ww_ / 2;
72 w_ = max(x_ + wx + ww_, w_);
76 h_ = max(y_ + wy + ww_, h_);
81 void FormMathsBitmap::build()
83 lyx::Assert(bitmaps_.size() > 0);
85 h_+= 42; // Allow room for a Close button
87 FD_maths_bitmap * fdui = new FD_maths_bitmap;
89 fdui->form = fl_bgn_form(FL_UP_BOX, w_, h_);
90 fdui->form->u_vdata = this;
92 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
97 for (vector<BitmapStore>::const_iterator it = bitmaps_.begin();
98 it < bitmaps_.end(); ++it) {
99 FL_OBJECT * obj = buildBitmap(*it);
101 bc().addReadOnly(obj);
102 y_close = max(y_close, obj->y + obj->h);
106 x_ = (fdui->form->w - 90) / 2;
109 char const * const label = _("Close|^[");
111 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30,
112 idex(_(label)).c_str());
113 fl_set_button_shortcut(fdui->button_close, scex(_(label)).c_str(), 1);
114 fl_set_object_lsize(fdui->button_close, FL_NORMAL_SIZE);
115 fl_set_object_callback(fdui->button_close, C_FormBaseCancelCB, 0);
119 fdui->form->fdui = fdui;
122 bc().setCancel(dialog_->button_close);
127 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
129 // Add a bitmap to a button panel: one bitmap per panel.
130 // nt is the number of buttons and nx, ny the nr. of buttons
131 // in x and y direction.
132 // bw, bh and data are the bitmap dimensions width, height and
133 // bit pattern; these come directly from an .xbm file included
135 // vert indicates whether the next button panel within this
136 // window will be below (true, default) or next to this one.
138 // The scaling of the bitmap on top of the buttons will be
139 // correct if the nx, ny values are given correctly.
140 int wx = bmstore.bw + ww_ / 2;
141 int wy = bmstore.bh + ww_ / 2;
142 wx += (wx % bmstore.nx);
143 wy += (wy % bmstore.ny);
145 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
146 fl_set_object_lcol(obj, FL_BLUE);
147 fl_set_object_boxtype(obj, FL_UP_BOX);
148 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
150 fl_set_bmtable_maxitems(obj, bmstore.nt);
151 fl_set_object_callback(obj, C_FormBaseInputCB, 0);
163 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
167 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
168 if (ob->objclass != FL_BMTABLE)
172 return k + fl_get_bmtable(ob);
174 k += fl_get_bmtable_maxitems(ob);
181 void FormMathsBitmap::apply()
183 string::size_type const i = latex_chosen_.find(' ');
184 if (i != string::npos) {
185 controller().dispatchFunc(LFUN_MATH_MODE);
186 controller().insertSymbol(latex_chosen_.substr(0,i));
187 controller().insertSymbol(latex_chosen_.substr(i + 1), false);
189 controller().insertSymbol(latex_chosen_);
193 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
195 int const i = GetIndex(ob);
198 return ButtonPolicy::SMI_INVALID;
200 latex_chosen_ = latex_[i];
202 return ButtonPolicy::SMI_VALID;