3 * \file FormMathsBitmap.C
4 * Copyright 2001 the LyX Team
5 * Read the file COPYING
7 * \author Alejandro Aguilar Sierra
8 * \author John Levon, moz@compsoc.man.ac.uk
9 * \author Angus Leeming, a.leeming@ic.ac.uk
16 #include XPM_H_LOCATION
19 #pragma implementation
22 #include "FormMathsBitmap.h"
28 #include "lyx_gui_misc.h" // scex, idex
30 #include "support/LAssert.h"
37 extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
38 extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
40 FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
41 FormMathsPanel const & p,
42 vector<string> const & l)
43 : FormMathsSub(lv, d, p, _("Maths Bitmaps")),
44 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
46 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
52 FL_FORM * FormMathsBitmap::form() const
58 void FormMathsBitmap::build()
60 lyx::Assert(bitmaps_.size() > 0);
62 h_+= 50; // Allow room for a Close button
64 form_ = fl_bgn_form(FL_UP_BOX, w_, h_);
65 form_->u_vdata = this;
67 FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
70 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
71 it < bitmaps_.end(); ++it) {
72 FL_OBJECT * obj = it->get();
74 fl_add_object(form_, obj);
75 bc().addReadOnly(obj);
77 y_ = max(y_, obj->y + obj->h);
80 char const * const label = N_("Close|^[");
82 x_ = (form_->w - 90) / 2;
85 FL_OBJECT * button_cancel = obj =
86 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
87 fl_set_button_shortcut(obj, scex(_(label)), 1);
89 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
90 fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0);
94 bc().setCancel(button_cancel);
98 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
99 unsigned char const * data, bool vert)
101 int wx = bw + ww_ / 2;
102 int wy = bh + ww_ / 2;
106 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
107 fl_set_object_lcol(obj, FL_BLUE);
108 fl_set_object_boxtype(obj, FL_UP_BOX);
109 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
110 fl_set_bmtable_maxitems(obj, nt);
111 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
116 w_ = max(x_ + wx + ww_, w_);
120 h_ = max(y_ + wy + ww_, h_);
123 bitmaps_.push_back(bm_ptr(obj));
127 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
130 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
131 it < bitmaps_.end(); ++it) {
133 return k + fl_get_bmtable(ob);
135 k += fl_get_bmtable_maxitems(it->get());
141 void FormMathsBitmap::apply()
143 parent_.insertSymbol(latex_chosen_);
147 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
149 int const i = GetIndex(ob);
154 latex_chosen_ = latex_[i];