]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
reduce number of metrics calls in InsetTabular calculate_dimensions_
[lyx.git] / src / insets / inset.C
1 /**
2  * \file inset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Matthias Ettrich
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #include <config.h>
15
16 #include "inset.h"
17 #include "BufferView.h"
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "lyxfont.h"
21 #include "lyxtext.h"
22 #include "dimension.h"
23 #include "metricsinfo.h"
24
25 #include "insets/updatableinset.h"
26
27 #include "frontends/Painter.h"
28 #include "frontends/mouse_state.h"
29
30 #include "support/lstrings.h"
31
32
33 // Initialization of the counter for the inset id's,
34 unsigned int Inset::inset_id = 0;
35
36 Inset::Inset()
37         : InsetBase(),
38         top_x(0), top_baseline(0), scx(0),
39         id_(inset_id++), owner_(0), par_owner_(0),
40         background_color_(LColor::inherit)
41 {}
42
43
44 Inset::Inset(Inset const & in)
45         : InsetBase(),
46         top_x(0), top_baseline(0), scx(0), owner_(0),
47         name_(in.name_), background_color_(in.background_color_)
48 {
49         id_ = inset_id++;
50 }
51
52
53 bool Inset::directWrite() const
54 {
55         return false;
56 }
57
58
59 Inset::EDITABLE Inset::editable() const
60 {
61         return NOT_EDITABLE;
62 }
63
64
65 bool Inset::autoDelete() const
66 {
67         return false;
68 }
69
70
71 #if 0
72 LyXFont const Inset::convertFont(LyXFont const & font) const
73 {
74 #if 1
75         return font;
76 #else
77         return LyXFont(font);
78 #endif
79 }
80 #endif
81
82
83 string const Inset::editMessage() const
84 {
85         return _("Opened inset");
86 }
87
88
89 LyXText * Inset::getLyXText(BufferView const * bv, bool /*recursive*/) const
90 {
91         if (owner())
92                 return owner()->getLyXText(bv, false);
93         else
94                 return bv->text;
95 }
96
97
98 void Inset::setBackgroundColor(LColor::color color)
99 {
100         background_color_ = color;
101 }
102
103
104 LColor::color Inset::backgroundColor() const
105 {
106         if (background_color_ == LColor::inherit) {
107                 if (owner())
108                         return owner()->backgroundColor();
109                 else
110                         return LColor::background;
111         } else
112                 return background_color_;
113 }
114
115
116 int Inset::id() const
117 {
118         return id_;
119 }
120
121 void Inset::id(int id_arg)
122 {
123         id_ = id_arg;
124 }
125
126 void Inset::setFont(BufferView *, LyXFont const &, bool, bool)
127 {}
128
129
130 bool Inset::forceDefaultParagraphs(Inset const * inset) const
131 {
132         if (owner())
133                 return owner()->forceDefaultParagraphs(inset);
134         return false;
135 }
136
137 int Inset::latexTextWidth(BufferView * bv) const
138 {
139         if (owner())
140                 return (owner()->latexTextWidth(bv));
141         return bv->workWidth();
142 }
143
144
145 int Inset::ascent(BufferView * bv, LyXFont const & font) const
146 {
147         Dimension dim;
148         MetricsInfo mi(bv, font);
149         metrics(mi, dim);
150         return dim.ascent();
151 }
152
153
154 int Inset::descent(BufferView * bv, LyXFont const & font) const
155 {
156         Dimension dim;
157         MetricsInfo mi(bv, font);
158         metrics(mi, dim);
159         return dim.descent();
160 }
161
162
163 int Inset::width(BufferView * bv, LyXFont const & font) const
164 {
165         Dimension dim;
166         MetricsInfo mi(bv, font);
167         metrics(mi, dim);
168         return dim.width();
169 }