]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
get rid of same_id from function signatures
[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
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::dimension(BufferView *, LyXFont const & font,
64         Dimension & dim) const
65 {
66         LyXFont efont;
67         efont.setSize(font.size()).decSize();
68         dim.a = font_metrics::maxAscent(efont) + 1;
69         dim.d = font_metrics::maxDescent(efont) + 1;
70         dim.w = 6 + font_metrics::width(_("Error"), efont);
71 }
72
73
74 void InsetError::draw(BufferView * bv, LyXFont const & font,
75                       int baseline, float & x) const
76 {
77         lyx::Assert(bv);
78         cache(bv);
79
80         Painter & pain = bv->painter();
81         LyXFont efont;
82         efont.setSize(font.size()).decSize();
83         efont.setColor(LColor::error);
84
85         // Draw as "Error" in a framed box
86         x += 1;
87         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
88                           width(bv, font) - 2,
89                           ascent(bv, font) + descent(bv, font) - 2,
90                            LColor::insetbg);
91         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
92                        width(bv, font) - 2,
93                        ascent(bv, font) + descent(bv, font) - 2,
94                        LColor::error);
95         pain.text(int(x + 2), baseline, _("Error"), efont);
96
97         x +=  width(bv, font) - 1;
98 }
99
100
101 string const InsetError::editMessage() const
102 {
103         return _("Opened error");
104 }