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 <leeming@lyx.org>
14 #pragma implementation
17 #include "FormMathsBitmap.h"
20 #include "forms_gettext.h"
22 #include "support/LAssert.h"
24 #include XPM_H_LOCATION
34 extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
35 extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
37 FormMathsBitmap::FormMathsBitmap(LyXView & lv, Dialogs & d,
38 FormMathsPanel const & p, string const & t,
39 vector<string> const & l)
40 : FormMathsSub(lv, d, p, t, false),
41 latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0)
43 ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
49 FormMathsBitmap::~FormMathsBitmap()
54 if (form()->visible) fl_hide_form(form());
59 FL_FORM * FormMathsBitmap::form() const
65 void FormMathsBitmap::build()
67 lyx::Assert(bitmaps_.size() > 0);
69 h_+= 50; // Allow room for a Close button
71 form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_), fl_free_form);
72 form_->u_vdata = this;
74 fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
77 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
78 it < bitmaps_.end(); ++it) {
79 FL_OBJECT * obj = it->get();
81 fl_add_object(form_.get(), obj);
82 bc().addReadOnly(obj);
84 y_ = max(y_, obj->y + obj->h);
87 char const * const label = _("Close|^[");
88 x_ = (form_->w - 90) / 2;
91 FL_OBJECT * button_close =
92 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
93 fl_set_button_shortcut(button_close, scex(_(label)), 1);
94 fl_set_object_lsize(button_close, FL_NORMAL_SIZE);
95 fl_set_object_callback(button_close, C_FormBaseDeprecatedCancelCB, 0);
99 bc().setCancel(button_close);
103 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
104 unsigned char const * data, bool vert)
106 // Add a bitmap to a button panel: one bitmap per panel.
107 // nt is the number of buttons and nx, ny the nr. of buttons
108 // in x and y direction.
109 // bw, bh and data are the bitmap dimensions width, height and
110 // bit pattern; these come directly from an .xbm file included
112 // vert indicates whether the next button panel within this
113 // window will be below (true, default) or next to this one.
115 // The scaling of the bitmap on top of the buttons will be
116 // correct if the nx, ny values are given correctly.
117 int wx = bw + ww_ / 2;
118 int wy = bh + ww_ / 2;
121 FL_OBJECT * obj = fl_create_bmtable(1, x_, y_, wx, wy, "");
122 fl_set_object_lcol(obj, FL_BLUE);
123 fl_set_object_boxtype(obj, FL_UP_BOX);
124 fl_set_bmtable_data(obj, nx, ny, bw, bh, data);
125 fl_set_bmtable_maxitems(obj, nt);
126 fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0);
131 w_ = max(x_ + wx + ww_, w_);
135 h_ = max(y_ + wy + ww_, h_);
138 bitmaps_.push_back(bm_ptr(obj, fl_free_object));
142 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
145 for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
146 it < bitmaps_.end(); ++it) {
148 return k + fl_get_bmtable(ob);
150 k += fl_get_bmtable_maxitems(it->get());
156 void FormMathsBitmap::apply()
158 string::size_type const i = latex_chosen_.find(' ');
159 if (i != string::npos) {
160 parent_.dispatchFunc(LFUN_MATH_MODE);
161 parent_.insertSymbol(latex_chosen_.substr(0,i));
162 parent_.insertSymbol(latex_chosen_.substr(i + 1), false);
164 parent_.insertSymbol(latex_chosen_);
168 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
170 int const i = GetIndex(ob);
175 latex_chosen_ = latex_[i];