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