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