]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
clear()->erase() ; lots of using directives for cxx
[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::Ascii(ostream &) const
115 {
116         return 0;
117 }
118
119
120 int InsetError::Linuxdoc(ostream &) const
121 {
122         return 0;
123 }
124
125
126 int InsetError::DocBook(ostream &) const
127 {
128         return 0;
129 }
130
131
132 bool InsetError::AutoDelete() const
133 {
134         return true;
135 }
136
137
138 Inset::EDITABLE InsetError::Editable() const
139 {
140         return IS_EDITABLE;
141 }
142
143
144 void InsetError::CloseErrorCB(FL_OBJECT * ob, long)
145 {
146         InsetError * inset = static_cast<InsetError*>(ob->u_vdata);
147         if (inset->form) {
148                 fl_hide_form(inset->form);
149                 fl_free_form(inset->form);
150                 inset->form = 0;
151         }
152 }
153
154
155 // A C wrapper
156 extern "C" void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data)
157 {
158         InsetError::CloseErrorCB(ob , data);
159 }
160
161
162 char const * InsetError::EditMessage() const 
163 {
164         return _("Opened error");
165 }
166
167
168 void InsetError::Edit(BufferView *, int, int, unsigned int)
169 {
170         static int ow = 400, oh = 240;
171
172         if (!form) {
173                 FL_OBJECT * obj;
174                 form = fl_bgn_form(FL_UP_BOX, ow, oh);
175                 strobj = fl_add_box(FL_FRAME_BOX, 10, 10, 380, 180, "");
176                 fl_set_object_color(strobj, FL_MCOL, FL_MCOL);
177                 fl_set_object_gravity(strobj, FL_NorthWest, FL_SouthEast);
178                 obj = fl_add_button(FL_RETURN_BUTTON, 140, 200, 120, 30,
179                                     _("Close"));
180                 fl_set_object_callback(obj, C_InsetError_CloseErrorCB, 0);
181                 obj->u_vdata = this;
182                 fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast);
183                 fl_set_object_resize(obj, FL_RESIZE_NONE);
184                 fl_end_form();
185                 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
186         }
187         fl_set_object_label(strobj, contents.c_str());
188         if (form->visible) {
189                 fl_raise_form(form);
190         } else {
191                 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE,
192                              FL_FULLBORDER, _("LaTeX Error"));
193                 fl_set_form_minsize(form, ow, oh);
194         }
195 }
196
197
198 Inset * InsetError::Clone() const
199 {
200         return new InsetError(contents);
201 }