]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
Hold on to your hats.
[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 #include "support/LAssert.h"
23
24 using std::ostream;
25
26 /* Error, used for the LaTeX-Error Messages */
27
28 InsetError::InsetError(string const & str, bool)
29         : contents(str)
30 {}
31
32
33 InsetError::~InsetError()
34 {
35         if (view())
36                 view()->owner()->getDialogs().hide("error");
37 }
38
39
40 int InsetError::ascent(BufferView *, LyXFont const & font) const
41 {
42         LyXFont efont;
43         efont.setSize(font.size()).decSize();
44         return font_metrics::maxAscent(efont) + 1;
45 }
46
47
48 int InsetError::descent(BufferView *, LyXFont const & font) const
49 {
50         LyXFont efont;
51         efont.setSize(font.size()).decSize();
52         return font_metrics::maxDescent(efont) + 1;
53 }
54
55
56 int InsetError::width(BufferView *, LyXFont const & font) const
57 {
58         LyXFont efont;
59         efont.setSize(font.size()).decSize();
60         return 6 + font_metrics::width(_("Error"), efont);
61 }
62
63
64 void InsetError::draw(BufferView * bv, LyXFont const & font,
65                       int baseline, float & x, bool) const
66 {
67         lyx::Assert(bv);
68         cache(bv);
69
70         Painter & pain = bv->painter();
71         LyXFont efont;
72         efont.setSize(font.size()).decSize();
73         efont.setColor(LColor::error);
74
75         // Draw as "Error" in a framed box
76         x += 1;
77         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
78                           width(bv, font) - 2,
79                           ascent(bv, font) + descent(bv, font) - 2,
80                            LColor::insetbg);
81         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
82                        width(bv, font) - 2,
83                        ascent(bv, font) + descent(bv, font) - 2,
84                        LColor::error);
85         pain.text(int(x + 2), baseline, _("Error"), efont);
86
87         x +=  width(bv, font) - 1;
88 }
89
90
91 string const InsetError::editMessage() const
92 {
93         return _("Opened error");
94 }
95
96
97 void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
98 {
99         bv->owner()->getDialogs().show("error", getContents(), this);
100 }
101
102
103 void InsetError::edit(BufferView * bv, bool)
104 {
105         edit(bv, 0, 0, mouse_button::none);
106 }