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"), false),
43 latex_(l), form_(0), ww_(0), x_(0), y_(0), w_(0), h_(0)
45 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
51 FormMathsBitmap::~FormMathsBitmap()
56 if (form()->visible) fl_hide_form(form());
61 FL_FORM * FormMathsBitmap::form() const
67 void FormMathsBitmap::build()
69 lyx::Assert(bitmaps_.size() > 0);
71 h_+= 50; // Allow room for a Close button
73 form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_));
74 form_->u_vdata = this;
76 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
79 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
80 it < bitmaps_.end(); ++it) {
81 FL_OBJECT * obj = it->get();
83 fl_add_object(form_.get(), obj);
84 bc().addReadOnly(obj);
86 y_ = max(y_, obj->y + obj->h);
89 char const * const label = N_("Close|^[");
90 x_ = (form_->w - 90) / 2;
93 FL_OBJECT * button_cancel =
94 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
95 fl_set_button_shortcut(button_cancel, scex(_(label)), 1);
96 fl_set_object_lsize(button_cancel, FL_NORMAL_SIZE);
97 fl_set_object_callback(button_cancel, C_FormBaseDeprecatedCancelCB, 0);
101 bc().setCancel(button_cancel);
105 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
106 unsigned char const * data, bool vert)
108 int wx = bw + ww_ / 2;
109 int wy = bh + ww_ / 2;
113 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
114 fl_set_object_lcol(obj, FL_BLUE);
115 fl_set_object_boxtype(obj, FL_UP_BOX);
116 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
117 fl_set_bmtable_maxitems(obj, nt);
118 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
123 w_ = max(x_ + wx + ww_, w_);
127 h_ = max(y_ + wy + ww_, h_);
130 bitmaps_.push_back(bm_ptr(obj));
134 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
137 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
138 it < bitmaps_.end(); ++it) {
140 return k + fl_get_bmtable(ob);
142 k += fl_get_bmtable_maxitems(it->get());
148 void FormMathsBitmap::apply()
150 parent_.insertSymbol(latex_chosen_);
154 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
156 int const i = GetIndex(ob);
161 latex_chosen_ = latex_[i];