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