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