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