]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
dont use pragma impementation and interface anymore
[lyx.git] / src / insets / inseterror.C
1 /**
2  * \file inseterror.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include "BufferView.h"
15 #include "frontends/font_metrics.h"
16 #include "lyxfont.h"
17 #include "gettext.h"
18 #include "inseterror.h"
19 #include "frontends/LyXView.h"
20 #include "frontends/Painter.h"
21 #include "frontends/Dialogs.h"
22
23 using std::ostream;
24
25 /* Error, used for the LaTeX-Error Messages */
26
27 InsetError::InsetError(string const & str, bool)
28         : contents(str)
29 {}
30
31
32 int InsetError::ascent(BufferView *, LyXFont const & font) const
33 {
34         LyXFont efont;
35         efont.setSize(font.size()).decSize();
36         return font_metrics::maxAscent(efont) + 1;
37 }
38
39
40 int InsetError::descent(BufferView *, LyXFont const & font) const
41 {
42         LyXFont efont;
43         efont.setSize(font.size()).decSize();
44         return font_metrics::maxDescent(efont) + 1;
45 }
46
47
48 int InsetError::width(BufferView *, LyXFont const & font) const
49 {
50         LyXFont efont;
51         efont.setSize(font.size()).decSize();
52         return 6 + font_metrics::width(_("Error"), efont);
53 }
54
55
56 void InsetError::draw(BufferView * bv, LyXFont const & font,
57                       int baseline, float & x, bool) const
58 {
59         Painter & pain = bv->painter();
60         LyXFont efont;
61         efont.setSize(font.size()).decSize();
62         efont.setColor(LColor::error);
63
64         // Draw as "Error" in a framed box
65         x += 1;
66         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
67                           width(bv, font) - 2,
68                           ascent(bv, font) + descent(bv, font) - 2,
69                            LColor::insetbg);
70         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
71                        width(bv, font) - 2,
72                        ascent(bv, font) + descent(bv, font) - 2,
73                        LColor::error);
74         pain.text(int(x + 2), baseline, _("Error"), efont);
75
76         x +=  width(bv, font) - 1;
77 }
78
79
80 string const InsetError::editMessage() const
81 {
82         return _("Opened error");
83 }
84
85
86 void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
87 {
88         bv->owner()->getDialogs().showError(this);
89 }
90
91
92 void InsetError::edit(BufferView * bv, bool)
93 {
94         edit(bv, 0, 0, mouse_button::none);
95 }