]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
Clean up InsetGraphics::Cache and rename as GraphicsInset.
[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 "frontends/Painter.h"
26 #include "frontends/mouse_state.h"
27
28 #include "support/lstrings.h"
29
30
31 // Initialization of the counter for the inset id's,
32 unsigned int Inset::inset_id = 0;
33
34 Inset::Inset()
35         : InsetBase(),
36         top_x(0), top_baseline(0), scx(0),
37         id_(inset_id++), owner_(0), par_owner_(0),
38         background_color_(LColor::inherit)
39 {}
40
41
42 Inset::Inset(Inset const & in)
43         : InsetBase(),
44         top_x(0), top_baseline(0), scx(0), owner_(0),
45         name_(in.name_), background_color_(in.background_color_)
46 {
47         id_ = inset_id++;
48 }
49
50
51 bool Inset::directWrite() const
52 {
53         return false;
54 }
55
56
57 Inset::EDITABLE Inset::editable() const
58 {
59         return NOT_EDITABLE;
60 }
61
62
63 bool Inset::autoDelete() const
64 {
65         return false;
66 }
67
68
69 #if 0
70 LyXFont const Inset::convertFont(LyXFont const & font) const
71 {
72 #if 1
73         return font;
74 #else
75         return LyXFont(font);
76 #endif
77 }
78 #endif
79
80
81 string const Inset::editMessage() const
82 {
83         return _("Opened inset");
84 }
85
86
87 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
88 {
89         if (owner())
90                 return owner()->getLyXText(bv, false);
91         else
92                 return bv->text;
93 }
94
95
96 void Inset::setBackgroundColor(LColor::color color)
97 {
98         background_color_ = color;
99 }
100
101
102 LColor::color Inset::backgroundColor() const
103 {
104         if (background_color_ == LColor::inherit) {
105                 if (owner())
106                         return owner()->backgroundColor();
107                 else
108                         return LColor::background;
109         } else
110                 return background_color_;
111 }
112
113
114 int Inset::id() const
115 {
116         return id_;
117 }
118
119 void Inset::id(int id_arg)
120 {
121         id_ = id_arg;
122 }
123
124 void Inset::setFont(BufferView *, LyXFont const &, bool, bool)
125 {}
126
127
128 bool Inset::forceDefaultParagraphs(Inset const * inset) const
129 {
130         if (owner())
131                 return owner()->forceDefaultParagraphs(inset);
132         return false;
133 }
134
135 int Inset::latexTextWidth(BufferView * bv) const
136 {
137         if (owner())
138                 return (owner()->latexTextWidth(bv));
139         return bv->workWidth();
140 }
141
142
143 int Inset::ascent(BufferView * bv, LyXFont const & font) const
144 {
145         Dimension dim;
146         MetricsInfo mi;
147         mi.base.bv = bv;
148         mi.base.font = 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;
158         mi.base.bv = bv;
159         mi.base.font = font;
160         metrics(mi, dim);
161         return dim.descent();
162 }
163
164
165 int Inset::width(BufferView * bv, LyXFont const & font) const
166 {
167         Dimension dim;
168         MetricsInfo mi;
169         mi.base.bv = bv;
170         mi.base.font = font;
171         metrics(mi, dim);
172         return dim.width();
173 }