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 char const * const label = _("Close|^[");
107 x_ = (fdui->form->w - 90) / 2;
110 FL_OBJECT * button_close =
111 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
112 fl_set_button_shortcut(button_close, scex(_(label)), 1);
113 fl_set_object_lsize(button_close, FL_NORMAL_SIZE);
114 fl_set_object_callback(button_close, C_FormBaseCancelCB, 0);
118 fdui->form->fdui = fdui;
121 bc().setCancel(dialog_->button_close);
126 FL_OBJECT * FormMathsBitmap::buildBitmap(BitmapStore const & bmstore)
128 // Add a bitmap to a button panel: one bitmap per panel.
129 // nt is the number of buttons and nx, ny the nr. of buttons
130 // in x and y direction.
131 // bw, bh and data are the bitmap dimensions width, height and
132 // bit pattern; these come directly from an .xbm file included
134 // vert indicates whether the next button panel within this
135 // window will be below (true, default) or next to this one.
137 // The scaling of the bitmap on top of the buttons will be
138 // correct if the nx, ny values are given correctly.
139 int wx = bmstore.bw + ww_ / 2;
140 int wy = bmstore.bh + ww_ / 2;
141 wx += (wx % bmstore.nx);
142 wy += (wy % bmstore.ny);
144 FL_OBJECT * obj = fl_add_bmtable(1, x_, y_, wx, wy, "");
145 fl_set_object_lcol(obj, FL_BLUE);
146 fl_set_object_boxtype(obj, FL_UP_BOX);
147 fl_set_bmtable_data(obj, bmstore.nx, bmstore.ny, bmstore.bw, bmstore.bh,
149 fl_set_bmtable_maxitems(obj, bmstore.nt);
150 fl_set_object_callback(obj, C_FormBaseInputCB, 0);
162 int FormMathsBitmap::GetIndex(FL_OBJECT * ob_in)
166 for (FL_OBJECT * ob = form()->first; ob; ob = ob->next) {
167 if (ob->objclass != FL_BMTABLE)
171 return k + fl_get_bmtable(ob);
173 k += fl_get_bmtable_maxitems(ob);
180 void FormMathsBitmap::apply()
182 string::size_type const i = latex_chosen_.find(' ');
183 if (i != string::npos) {
184 controller().dispatchFunc(LFUN_MATH_MODE);
185 controller().insertSymbol(latex_chosen_.substr(0,i));
186 controller().insertSymbol(latex_chosen_.substr(i + 1), false);
188 controller().insertSymbol(latex_chosen_);
192 ButtonPolicy::SMInput FormMathsBitmap::input(FL_OBJECT * ob, long)
194 int const i = GetIndex(ob);
197 return ButtonPolicy::SMI_INVALID;
199 latex_chosen_ = latex_[i];
201 return ButtonPolicy::SMI_VALID;