]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
Various updates for insets mostly regarding fixes for text-insets.
[lyx.git] / src / insets / inseterror.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-1999 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "inseterror.h"
18 #include "gettext.h"
19 #include "lyx_gui_misc.h" // CancelCloseBoxCB
20 #include "Painter.h"
21
22 /* Error, used for the LaTeX-Error Messages */
23
24 InsetError::InsetError()
25 {
26         form = 0;
27 }
28
29
30 InsetError::InsetError(string const & str)
31         : contents(str)
32 {
33         form = 0;
34 }
35
36
37 InsetError::~InsetError()
38 {
39         if (form) {
40                 fl_hide_form(form);
41                 fl_free_form(form);
42                 form = 0;
43         }
44 }
45
46
47 int InsetError::ascent(Painter &, LyXFont const & font) const
48 {
49         LyXFont efont;
50         efont.setSize(font.size()).decSize();
51         return efont.maxAscent() + 1;
52 }
53
54
55 int InsetError::descent(Painter &, LyXFont const & font) const
56 {
57         LyXFont efont;
58         efont.setSize(font.size()).decSize();
59         return efont.maxDescent() + 1;
60 }
61
62
63 int InsetError::width(Painter &, LyXFont const & font) const
64 {
65         LyXFont efont;
66         efont.setSize(font.size()).decSize();
67         return 6 + efont.textWidth(_("Error"), strlen(_("Error")));
68 }
69
70
71 void InsetError::draw(Painter & pain, LyXFont const & font,
72                       int baseline, float & x) const
73 {
74         LyXFont efont;
75         efont.setSize(font.size()).decSize();
76         efont.setColor(LColor::error);
77    
78         // Draw as "Error" in a framed box
79         x += 1;
80         pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
81                           width(pain, font) - 2,
82                           ascent(pain, font) + descent(pain, font) - 2,
83                            LColor::insetbg);
84         pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
85                        width(pain, font) - 2,
86                        ascent(pain, font) + descent(pain, font) - 2,
87                        LColor::error);
88         pain.text(int(x + 2), baseline, _("Error"), efont);
89
90         x +=  width(pain, font) - 1;
91 }
92
93
94 void InsetError::Write(ostream &) const
95 {
96 }
97
98
99 void InsetError::Read(LyXLex &)
100 {
101 }
102
103
104 int InsetError::Latex(ostream &, signed char /*fragile*/) const
105 {
106         return 0;
107 }
108
109
110 #ifndef USE_OSTREAM_ONLY
111 int InsetError::Latex(string &, signed char /*fragile*/) const
112 {
113         return 0;
114 }
115
116
117 int InsetError::Linuxdoc(string &) const
118 {
119         return 0;
120 }
121
122
123 int InsetError::DocBook(string &) const
124 {
125         return 0;
126 }
127
128 #else
129
130 int InsetError::Linuxdoc(ostream &) const
131 {
132         return 0;
133 }
134
135
136 int InsetError::DocBook(ostream &) const
137 {
138         return 0;
139 }
140 #endif
141
142
143 bool InsetError::AutoDelete() const
144 {
145         return true;
146 }
147
148
149 Inset::EDITABLE InsetError::Editable() const
150 {
151         return IS_EDITABLE;
152 }
153
154
155 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
156 {
157         InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
158         if (inset->form) {
159                 fl_hide_form(inset->form);
160                 fl_free_form(inset->form);
161                 inset->form = 0;
162         }
163 }
164
165
166 // A C wrapper
167 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
168 {
169         InsetError::CloseErrorCB(ob , data);
170 }
171
172
173 void InsetError::Edit(BufferView *, int, int, unsigned int)
174 {
175         static int ow = 400, oh = 240;
176
177         if (!form) {
178                 FL_OBJECT * obj;
179                 form = fl_bgn_form(FL_UP_BOX, ow, oh);
180                 strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
181                 fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
182                 fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
183                 obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
184                                     _("Close"));
185                 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
186                 obj->u_vdata = this;
187                 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
188                 fl_set_object_resize(obj, FL_RESIZE_NONE);
189                 fl_end_form();
190                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
191         }
192         fl_set_object_label(strobj, contents.c_str());
193         if (form->visible) {
194                 fl_raise_form(form);
195         } else {
196                 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
197                              FL_FULLBORDER, _("LaTeX Error"));
198                 fl_set_form_minsize(form, ow, oh);
199         }
200 }
201
202
203 Inset * InsetError::Clone() const
204 {
205         return new InsetError(contents);
206 }