2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 the LyX Team.
10 * ====================================================== */
35 /** This is not quite the correct place for this enum. I think
36 the correct would be to let each subclass of Inset declare
37 its own enum code. Actually the notion of an Inset::Code
38 should be avoided, but I am not sure how this could be done
44 TOC_CODE, // do these insets really need a code? (ale)
102 virtual int ascent(Painter &, LyXFont const &) const = 0;
104 virtual int descent(Painter &, LyXFont const &) const = 0;
106 virtual int width(Painter &, LyXFont const &) const = 0;
108 virtual void draw(Painter &, LyXFont const &,
109 int baseline, float & x) const = 0;
111 virtual LyXFont ConvertFont(LyXFont font);
112 /// what appears in the minibuffer when opening
113 virtual const char * EditMessage() const {return _("Opened inset");}
115 virtual void Edit(BufferView *, int x, int y, unsigned int button);
117 virtual EDITABLE Editable() const;
119 virtual bool AutoDelete() const;
121 virtual void Write(ostream &) const = 0;
123 virtual void Read(LyXLex & lex) = 0;
124 /** returns the number of rows (\n's) of generated tex code.
125 fragile != 0 means, that the inset should take care about
126 fragile commands by adding a \protect before.
127 If the freee_spc (freespacing) variable is set, then this inset
128 is in a free-spacing paragraph.
130 virtual int Latex(ostream &, signed char fragile,
131 bool free_spc) const = 0;
134 virtual int Linuxdoc(ostream &) const = 0;
136 virtual int DocBook(ostream &) const = 0;
137 /// Updates needed features for this inset.
138 virtual void Validate(LaTeXFeatures & features) const;
140 virtual bool Deletable() const;
142 /// returns LyX code associated with the inset. Used for TOC, ...)
143 virtual Inset::Code LyxCode() const = 0;
145 /// Get the label that appears at screen
146 virtual string getLabel(int) const {
151 virtual Inset * Clone() const = 0;
153 /// returns true to override begin and end inset in file
154 virtual bool DirectWrite() const;
156 /// Returns true if the inset should be centered alone
157 virtual bool display() const { return false; }
158 /// Changes the display state of the inset
159 virtual void display(bool) {}
161 virtual int GetNumberOfLabels() const {
165 virtual void init(BufferView *) {}
170 // Updatable Insets. These insets can be locked and receive
171 // directly user interaction. Currently used only for mathed.
172 // Note that all pure methods from Inset class are pure here too.
173 // [Alejandro 080596]
175 /** Extracted from Matthias notes:
177 * An inset can simple call LockInset in it's edit call and *ONLY*
180 * Unlocking is either done by LyX or the inset itself with a
183 * During the lock, all button and keyboard events will be modified
184 * and send to the inset through the following inset-features. Note that
185 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
186 * to contain the code for restoring the menus and things like this.
188 * If a inset wishes any redraw and/or update it just has to call
191 * It's is completly irrelevant, where the inset is. UpdateInset will
192 * find it in any paragraph in any buffer.
193 * Of course the_locking_inset and the insets in the current paragraph/buffer
194 * are checked first, so no performance problem should occur.
196 class UpdatableInset: public Inset {
198 /** Dispatch result codes
199 Now that nested updatable insets are allowed, the local dispatch
200 becomes a bit complex, just two possible results (boolean)
203 DISPATCHED = the inset catched the action
204 FINISHED = the inset must be unlocked as a result
206 UNDISPATCHED = the action was not catched, it should be
207 dispatched by lower level insets
215 /// To convert old binary dispatch results
216 RESULT DISPATCH_RESULT(bool b) {
217 return b ? DISPATCHED : FINISHED;
226 //virtual ~UpdatableInset() {}
228 virtual EDITABLE Editable() const;
230 /// may call ToggleLockedInsetCursor
231 virtual void ToggleInsetCursor(BufferView *);
233 virtual void GetCursorPos(int &, int &) const {}
235 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
237 virtual void InsetButtonRelease(BufferView *,
238 int x, int y, int button);
240 virtual void InsetKeyPress(XKeyEvent * ev);
242 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
244 virtual void InsetUnlock(BufferView *);
246 virtual void Edit(BufferView *, int x, int y, unsigned int button);
248 virtual void draw(Painter &, LyXFont const &,
249 int baseline, float & x) const;
251 virtual void SetFont(BufferView *, LyXFont const &,
252 bool toggleall = false);
254 virtual bool InsertInset(BufferView *, Inset *) { return false; }
256 virtual UpdatableInset * GetLockingInset() { return this; }
258 virtual int InsetInInsetY() { return 0; }
260 virtual bool UpdateInsetInInset(BufferView *, Inset *)
263 virtual bool UnlockInsetInInset(BufferView *, Inset *,
266 /// An updatable inset could handle lyx editing commands
267 virtual RESULT LocalDispatch(BufferView *, int, string const &);
269 virtual bool isCursorVisible() const { return cursor_visible; }
271 virtual int getMaxWidth(Painter & pain) const;
273 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
275 virtual UpdatableInset * owner() { return owner_; }
279 // virtual void UpdateLocal(bool flag=true);
282 mutable int top_baseline;
283 mutable bool cursor_visible;
290 UpdatableInset * owner_;