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