2 * \file FormMathsBitmap.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Alejandro Aguilar Sierra
7 * \author John Levon, moz@compsoc.man.ac.uk
8 * \author Angus Leeming, a.leeming@ic.ac.uk
15 #include XPM_H_LOCATION
18 #pragma implementation
21 #include "FormMathsBitmap.h"
27 #include "lyx_gui_misc.h" // scex, idex
29 #include "support/LAssert.h"
36 extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
37 extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
39 FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
40 FormMathsPanel const & p,
41 vector<string> const & l)
42 : FormMathsSub(lv, d, p, _("Maths Bitmaps")),
43 latex_(l), form_(0), ww_(0), x_(0), y_(0), w_(0), h_(0)
45 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
51 FL_FORM * FormMathsBitmap::form() const
57 void FormMathsBitmap::build()
59 lyx::Assert(bitmaps_.size() > 0);
61 h_+= 50; // Allow room for a Close button
63 form_ = fl_bgn_form(FL_UP_BOX, w_, h_);
64 form_->u_vdata = this;
66 FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
69 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
70 it < bitmaps_.end(); ++it) {
71 FL_OBJECT * obj = it->get();
73 fl_add_object(form_, obj);
74 bc().addReadOnly(obj);
76 y_ = max(y_, obj->y + obj->h);
79 char const * const label = N_("Close|^[");
81 x_ = (form_->w - 90) / 2;
84 FL_OBJECT * button_cancel = obj =
85 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
86 fl_set_button_shortcut(obj, scex(_(label)), 1);
88 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
89 fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0);
93 bc().setCancel(button_cancel);
97 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
98 unsigned char const * data, bool vert)
100 int wx = bw + ww_ / 2;
101 int wy = bh + ww_ / 2;
105 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
106 fl_set_object_lcol(obj, FL_BLUE);
107 fl_set_object_boxtype(obj, FL_UP_BOX);
108 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
109 fl_set_bmtable_maxitems(obj, nt);
110 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
115 w_ = max(x_ + wx + ww_, w_);
119 h_ = max(y_ + wy + ww_, h_);
122 bitmaps_.push_back(bm_ptr(obj));
126 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
129 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
130 it < bitmaps_.end(); ++it) {
132 return k + fl_get_bmtable(ob);
134 k += fl_get_bmtable_maxitems(it->get());
140 void FormMathsBitmap::apply()
142 parent_.insertSymbol(latex_chosen_);
146 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
148 int const i = GetIndex(ob);
153 latex_chosen_ = latex_[i];