]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
fix #832
[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 #include "inseterror.h"
14
15 #include "BufferView.h"
16 #include "funcrequest.h"
17 #include "gettext.h"
18 #include "lyxfont.h"
19
20 #include "frontends/Dialogs.h"
21 #include "frontends/font_metrics.h"
22 #include "frontends/LyXView.h"
23 #include "frontends/Painter.h"
24
25 #include "support/LAssert.h"
26
27 using std::ostream;
28
29
30 InsetError::InsetError(string const & str, bool)
31         : contents(str)
32 {}
33
34
35 InsetError::~InsetError()
36 {
37         Dialogs::hide("error", this);
38 }
39
40
41 dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
42 {
43         dispatch_result result = UNDISPATCHED;
44
45         switch (cmd.action) {
46         case LFUN_MOUSE_RELEASE: 
47         case LFUN_INSET_EDIT: 
48                 cmd.view()->owner()->getDialogs().show("error", getContents(), this);
49                 return DISPATCHED;
50
51         default:
52                 return Inset::localDispatch(cmd);
53         }
54 }
55
56
57 int InsetError::ascent(BufferView *, LyXFont const & font) const
58 {
59         LyXFont efont;
60         efont.setSize(font.size()).decSize();
61         return font_metrics::maxAscent(efont) + 1;
62 }
63
64
65 int InsetError::descent(BufferView *, LyXFont const & font) const
66 {
67         LyXFont efont;
68         efont.setSize(font.size()).decSize();
69         return font_metrics::maxDescent(efont) + 1;
70 }
71
72
73 int InsetError::width(BufferView *, LyXFont const & font) const
74 {
75         LyXFont efont;
76         efont.setSize(font.size()).decSize();
77         return 6 + font_metrics::width(_("Error"), efont);
78 }
79
80
81 void InsetError::draw(BufferView * bv, LyXFont const & font,
82                       int baseline, float & x) const
83 {
84         lyx::Assert(bv);
85         cache(bv);
86
87         Painter & pain = bv->painter();
88         LyXFont efont;
89         efont.setSize(font.size()).decSize();
90         efont.setColor(LColor::error);
91
92         // Draw as "Error" in a framed box
93         x += 1;
94         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
95                           width(bv, font) - 2,
96                           ascent(bv, font) + descent(bv, font) - 2,
97                            LColor::insetbg);
98         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
99                        width(bv, font) - 2,
100                        ascent(bv, font) + descent(bv, font) - 2,
101                        LColor::error);
102         pain.text(int(x + 2), baseline, _("Error"), efont);
103
104         x +=  width(bv, font) - 1;
105 }
106
107
108 string const InsetError::editMessage() const
109 {
110         return _("Opened error");
111 }