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
35 extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
36 extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
38 FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
39 FormMathsPanel const & p,
40 vector<string> const & l)
41 : FormMathsSub(lv, d, p, _("Maths Bitmaps")),
42 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
44 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
50 FL_FORM * FormMathsBitmap::form() const
56 void FormMathsBitmap::build()
58 Assert(bitmaps_.size() > 0);
60 h_+= 50; // Allow room for a Close button
62 form_ = fl_bgn_form(FL_UP_BOX, w_, h_);
63 form_->u_vdata = this;
65 FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
68 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
69 it < bitmaps_.end(); ++it) {
70 FL_OBJECT * obj = it->get();
72 fl_add_object(form_, obj);
73 bc().addReadOnly(obj);
75 y_ = max(y_, obj->y + obj->h);
78 char const * const label = N_("Close|^[");
80 x_ = (form_->w - 90) / 2;
83 FL_OBJECT * button_cancel = obj =
84 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
85 fl_set_button_shortcut(obj, scex(_(label)), 1);
87 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
88 fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0);
92 bc().setCancel(button_cancel);
96 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
97 unsigned char const * data, bool vert)
99 int wx = bw + ww_ / 2;
100 int wy = bh + ww_ / 2;
104 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
105 fl_set_object_lcol(obj, FL_BLUE);
106 fl_set_object_boxtype(obj, FL_UP_BOX);
107 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
108 fl_set_bmtable_maxitems(obj, nt);
109 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
114 w_ = max(x_ + wx + ww_, w_);
118 h_ = max(y_ + wy + ww_, h_);
121 bitmaps_.push_back(bm_ptr(obj));
125 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
128 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
129 it < bitmaps_.end(); ++it) {
131 return k + fl_get_bmtable(ob);
133 k += fl_get_bmtable_maxitems(it->get());
139 void FormMathsBitmap::apply()
141 parent_.insertSymbol(latex_chosen_);
145 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
147 int const i = GetIndex(ob);
152 latex_chosen_ = latex_[i];