]> git.lyx.org Git - lyx.git/blob - src/insets/inset.C
0c9d6602b2d63902e9060573dc28b306c4d0e93f
[lyx.git] / src / insets / inset.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation "lyxinset.h"
15 #endif
16
17 #include "lyxinset.h"
18 #include "debug.h"
19 #include "BufferView.h"
20 #include "support/lstrings.h"
21 #include "Painter.h"
22
23 using std::endl;
24
25 /* Insets default methods */
26
27 bool Inset::Deletable() const
28 {
29   return true;
30 }
31
32
33 bool Inset::DirectWrite() const
34 {
35   return false;
36 }
37
38
39 Inset::EDITABLE Inset::Editable() const
40 {
41   return NOT_EDITABLE;
42 }
43
44
45 void Inset::Validate(LaTeXFeatures &) const
46 {
47 }
48
49
50 bool Inset::AutoDelete() const
51 {
52   return false;
53 }
54
55
56 void Inset::Edit(BufferView *, int, int, unsigned int)
57 {
58 }
59
60
61 LyXFont Inset::ConvertFont(LyXFont font)
62 {
63   return font;
64 }
65
66
67  /* some stuff for inset locking */
68
69 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
70 {
71         lyxerr.debug() << "Inset Button Press x=" << x
72                        << ", y=" << y << ", button=" << button << endl;
73 }
74
75
76 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
77 {
78         lyxerr.debug() << "Inset Button Release x=" << x
79                        << ", y=" << y << ", button=" << button << endl;
80 }
81
82
83 void UpdatableInset::InsetKeyPress(XKeyEvent *)
84 {
85         lyxerr.debug() << "Inset Keypress" << endl;
86 }
87
88
89 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
90 {
91         lyxerr.debug() << "Inset Motion Notify x=" << x
92                        << ", y=" << y << ", state=" << state << endl;
93 }
94
95
96 void UpdatableInset::InsetUnlock(BufferView *)
97 {
98         lyxerr.debug() << "Inset Unlock" << endl;
99 }
100
101
102 // An updatable inset is highly editable by definition
103 Inset::EDITABLE UpdatableInset::Editable() const
104 {
105         return HIGHLY_EDITABLE;
106 }
107
108
109 void UpdatableInset::ToggleInsetCursor(BufferView *)
110 {
111 }
112
113
114 void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
115 {
116     LyXFont font;
117
118     scx = 0;
119
120     mx_scx = abs((width(bv->getPainter(), font) - bv->paperWidth()) / 2);
121 }
122
123
124 void UpdatableInset::draw(Painter &, LyXFont const &,
125                           int baseline, float & x) const
126 {
127     if (scx) x += float(scx);
128     top_x = int(x);
129     top_baseline = baseline;
130 }
131
132
133 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
134 {
135 }
136
137
138 ///  An updatable inset could handle lyx editing commands
139 #ifdef SCROLL_INSET
140 UpdatableInset::RESULT
141 UpdatableInset::LocalDispatch(BufferView *, 
142                               int action, string const & arg) 
143 #else
144 UpdatableInset::RESULT
145 UpdatableInset::LocalDispatch(BufferView *, int, string const &)
146 #endif
147 {
148 #ifdef SCROLL_INSET
149     if (action==LFUN_SCROLL_INSET)
150         {
151             float xx;
152             sscanf(arg.c_str(), "%f", &xx);     
153             scroll(xx);
154
155             return DISPATCHED;
156         }
157 #endif
158     return UNDISPATCHED; 
159 }
160
161 int UpdatableInset::getMaxWidth(Painter & pain) const
162 {
163     if (owner_)
164         return owner_->getMaxWidth(pain);
165     return pain.paperWidth();
166 }
167