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"
24 #include "frontends/LyXView.h"
27 #include "xforms_helpers.h"
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, string const & t,
41 vector<string> const & l)
42 : FormMathsSub(lv, d, p, t, 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 = _("Close|^[");
90 x_ = (form_->w - 90) / 2;
93 FL_OBJECT * button_close =
94 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
95 fl_set_button_shortcut(button_close, scex(_(label)), 1);
96 fl_set_object_lsize(button_close, FL_NORMAL_SIZE);
97 fl_set_object_callback(button_close, C_FormBaseDeprecatedCancelCB, 0);
101 bc().setCancel(button_close);
105 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
106 unsigned char const * data, bool vert)
108 // Add a bitmap to a button panel: one bitmap per panel.
109 // nt is the number of buttons and nx, ny the nr. of buttons
110 // in x and y direction.
111 // bw, bh and data are the bitmap dimensions width, height and
112 // bit pattern; these come directly from an .xbm file included
114 // vert indicates whether the next button panel within this
115 // window will be below (true, default) or next to this one.
117 // The scaling of the bitmap on top of the buttons will be
118 // correct if the nx, ny values are given correctly.
119 int wx = bw + ww_ / 2;
120 int wy = bh + ww_ / 2;
123 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
124 fl_set_object_lcol(obj, FL_BLUE);
125 fl_set_object_boxtype(obj, FL_UP_BOX);
126 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
127 fl_set_bmtable_maxitems(obj, nt);
128 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
133 w_ = max(x_ + wx + ww_, w_);
137 h_ = max(y_ + wy + ww_, h_);
140 bitmaps_.push_back(bm_ptr(obj));
144 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
147 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
148 it < bitmaps_.end(); ++it) {
150 return k + fl_get_bmtable(ob);
152 k += fl_get_bmtable_maxitems(it->get());
158 void FormMathsBitmap::apply()
160 string::size_type const i = latex_chosen_.find(' ');
161 if (i != string::npos) {
162 parent_.dispatchFunc(LFUN_MATH_MODE);
163 parent_.insertSymbol(latex_chosen_.substr(0,i));
164 parent_.insertSymbol(latex_chosen_.substr(i + 1), false);
166 parent_.insertSymbol(latex_chosen_);
170 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
172 int const i = GetIndex(ob);
177 latex_chosen_ = latex_[i];