]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
611558bcb4642928da13c1090e36908b2b7ebe68
[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-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "BufferView.h"
18 #include "font.h"
19 #include "lyxfont.h"
20 #include "gettext.h"
21 #include "inseterror.h"
22 #include "LyXView.h"
23 #include "Painter.h"
24 #include "frontends/Dialogs.h"
25
26 using std::ostream;
27
28 /* Error, used for the LaTeX-Error Messages */
29
30 InsetError::InsetError(string const & str, bool)
31         : contents(str)
32 {}
33
34
35 int InsetError::ascent(BufferView *, LyXFont const & font) const
36 {
37         LyXFont efont;
38         efont.setSize(font.size()).decSize();
39         return lyxfont::maxAscent(efont) + 1;
40 }
41
42
43 int InsetError::descent(BufferView *, LyXFont const & font) const
44 {
45         LyXFont efont;
46         efont.setSize(font.size()).decSize();
47         return lyxfont::maxDescent(efont) + 1;
48 }
49
50
51 int InsetError::width(BufferView *, LyXFont const & font) const
52 {
53         LyXFont efont;
54         efont.setSize(font.size()).decSize();
55         return 6 + lyxfont::width(_("Error"), efont);
56 }
57
58
59 void InsetError::draw(BufferView * bv, LyXFont const & font,
60                       int baseline, float & x, bool) const
61 {
62         Painter & pain = bv->painter();
63         LyXFont efont;
64         efont.setSize(font.size()).decSize();
65         efont.setColor(LColor::error);
66    
67         // Draw as "Error" in a framed box
68         x += 1;
69         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
70                           width(bv, font) - 2,
71                           ascent(bv, font) + descent(bv, font) - 2,
72                            LColor::insetbg);
73         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
74                        width(bv, font) - 2,
75                        ascent(bv, font) + descent(bv, font) - 2,
76                        LColor::error);
77         pain.text(int(x + 2), baseline, _("Error"), efont);
78
79         x +=  width(bv, font) - 1;
80 }
81
82
83 string const InsetError::editMessage() const 
84 {
85         return _("Opened error");
86 }
87
88
89 void InsetError::edit(BufferView * bv, int, int, unsigned int)
90 {
91         bv->owner()->getDialogs()->showError( this );
92 }
93
94
95 void InsetError::edit(BufferView * bv, bool)
96 {
97         edit(bv, 0, 0, 0);
98 }