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