]> git.lyx.org Git - lyx.git/blob - src/insets/inseterror.C
Remove the 'gross hack' of calling inset->edit when LFUN_MOUSE_RELEASE
[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 /* Error, used for the LaTeX-Error Messages */
30
31 InsetError::InsetError(string const & str, bool)
32         : contents(str)
33 {}
34
35
36 InsetError::~InsetError()
37 {
38         if (view())
39                 view()->owner()->getDialogs().hide("error");
40 }
41
42
43 dispatch_result InsetError::localDispatch(FuncRequest const & cmd)
44 {
45         dispatch_result result = UNDISPATCHED;
46
47         switch (cmd.action) {
48         case LFUN_MOUSE_RELEASE:
49                 edit(cmd.view(), cmd.x, cmd.y, cmd.button());
50                 break;
51
52         default:
53                 break;
54         }
55
56         return result;
57 }
58
59
60 int InsetError::ascent(BufferView *, LyXFont const & font) const
61 {
62         LyXFont efont;
63         efont.setSize(font.size()).decSize();
64         return font_metrics::maxAscent(efont) + 1;
65 }
66
67
68 int InsetError::descent(BufferView *, LyXFont const & font) const
69 {
70         LyXFont efont;
71         efont.setSize(font.size()).decSize();
72         return font_metrics::maxDescent(efont) + 1;
73 }
74
75
76 int InsetError::width(BufferView *, LyXFont const & font) const
77 {
78         LyXFont efont;
79         efont.setSize(font.size()).decSize();
80         return 6 + font_metrics::width(_("Error"), efont);
81 }
82
83
84 void InsetError::draw(BufferView * bv, LyXFont const & font,
85                       int baseline, float & x, bool) const
86 {
87         lyx::Assert(bv);
88         cache(bv);
89
90         Painter & pain = bv->painter();
91         LyXFont efont;
92         efont.setSize(font.size()).decSize();
93         efont.setColor(LColor::error);
94
95         // Draw as "Error" in a framed box
96         x += 1;
97         pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
98                           width(bv, font) - 2,
99                           ascent(bv, font) + descent(bv, font) - 2,
100                            LColor::insetbg);
101         pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
102                        width(bv, font) - 2,
103                        ascent(bv, font) + descent(bv, font) - 2,
104                        LColor::error);
105         pain.text(int(x + 2), baseline, _("Error"), efont);
106
107         x +=  width(bv, font) - 1;
108 }
109
110
111 string const InsetError::editMessage() const
112 {
113         return _("Opened error");
114 }
115
116
117 void InsetError::edit(BufferView * bv, int, int, mouse_button::state)
118 {
119         bv->owner()->getDialogs().show("error", getContents(), this);
120 }
121
122
123 void InsetError::edit(BufferView * bv, bool)
124 {
125         edit(bv, 0, 0, mouse_button::none);
126 }