]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormMathsBitmap.C
Revert "fix" to get LyX working again. Sorry for being precipient.
[lyx.git] / src / frontends / xforms / FormMathsBitmap.C
1 /**
2  * \file FormMathsBitmap.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author John Levon, moz@compsoc.man.ac.uk
8  * \author Angus Leeming, a.leeming@ic.ac.uk
9  */
10
11 #include <config.h>
12 #include <algorithm>
13 #include <iomanip>
14  
15 #include XPM_H_LOCATION
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FormMathsBitmap.h"
22
23 #include "Dialogs.h"
24 #include "LyXView.h"
25 #include "bmtable.h"
26 #include "debug.h"
27 #include "lyx_gui_misc.h" // scex, idex
28 #include "gettext.h"
29 #include "support/LAssert.h"
30
31 using std::vector;
32 using std::endl;
33 using std::setw;
34 using std::max;
35
36 extern  "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long);
37 extern  "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long);
38
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)
44 {
45         ww_ = 2 * FL_abs(FL_BOUND_WIDTH);
46         x_ = y_ = ww_;
47         y_ += 8;
48 }
49
50
51 FL_FORM * FormMathsBitmap::form() const
52 {
53         return form_.get();
54 }
55
56
57 void FormMathsBitmap::build()
58 {
59         lyx::Assert(bitmaps_.size() > 0);
60
61         h_+= 50; // Allow room for a Close button
62
63         form_.reset(fl_bgn_form(FL_UP_BOX, w_, h_));
64         form_->u_vdata = this;
65
66         FL_OBJECT * obj = fl_add_box(FL_UP_BOX, 0, 0, w_, h_, "");
67         //fl_add_object(form_.get(), obj);
68
69         y_ = 0;
70         for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
71              it < bitmaps_.end(); ++it) {
72                 FL_OBJECT * obj = it->get();
73
74                 fl_add_object(form_.get(), obj);
75                 bc().addReadOnly(obj);
76
77                 y_ = max(y_, obj->y + obj->h);
78         }
79  
80         char const * const label = N_("Close|^[");
81
82         x_ = (form_->w - 90) / 2;
83         y_ += 10;
84                 
85         FL_OBJECT * button_cancel = obj =
86                 fl_add_button(FL_NORMAL_BUTTON, x_, y_, 90, 30, idex(_(label)));
87         //fl_add_object(form_.get(), obj);
88         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);
91
92         fl_end_form();
93
94         bc().setCancel(button_cancel);
95 }
96
97
98 void FormMathsBitmap::addBitmap(int nt, int nx, int ny, int bw, int bh,
99                                 unsigned char const * data, bool vert)
100 {
101         int wx = bw + ww_ / 2;
102         int wy = bh + ww_ / 2;
103         wx += (wx % nx);
104         wy += (wy % ny);
105
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);
112
113         if (vert) {
114                 y_ += wy + 8;
115                 h_ = max(y_, h_);
116                 w_ = max(x_ + wx + ww_, w_);
117         } else  {
118                 x_ += wx + 8;
119                 w_ = max(x_, w_);
120                 h_ = max(y_ + wy + ww_, h_);
121         }
122
123         bitmaps_.push_back(bm_ptr(obj));
124 }
125
126
127 int FormMathsBitmap::GetIndex(FL_OBJECT * ob)
128 {
129         int k = 0;
130         for (vector<bm_ptr>::const_iterator it = bitmaps_.begin();
131              it < bitmaps_.end(); ++it) {
132                 if (it->get() == ob)
133                         return k + fl_get_bmtable(ob);
134                 else
135                         k += fl_get_bmtable_maxitems(it->get());
136         }
137         return -1;
138 }
139
140
141 void FormMathsBitmap::apply()
142 {
143         parent_.insertSymbol(latex_chosen_);
144 }
145
146
147 bool FormMathsBitmap::input(FL_OBJECT * ob, long)
148 {
149         int const i = GetIndex(ob);
150
151         if (i < 0) 
152                 return false;
153
154         latex_chosen_ = latex_[i];
155         apply();
156         return true;
157 }