2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
37 /** This is not quite the correct place for this enum. I think
38 the correct would be to let each subclass of Inset declare
39 its own enum code. Actually the notion of an Inset::Code
40 should be avoided, but I am not sure how this could be done
46 TOC_CODE, // do these insets really need a code? (ale)
112 TEXT_TO_INSET_OFFSET = 2
126 Inset() { owner_ = 0; top_x = top_baseline = 0; scx = 0; }
130 virtual int ascent(BufferView *, LyXFont const &) const = 0;
132 virtual int descent(BufferView *, LyXFont const &) const = 0;
134 virtual int width(BufferView *, LyXFont const &) const = 0;
136 virtual void draw(BufferView *, LyXFont const &,
137 int baseline, float & x, bool cleared) const = 0;
138 /// update the inset representation
139 virtual void update(BufferView *, LyXFont const &, bool = false)
142 virtual LyXFont const ConvertFont(LyXFont const & font) const;
143 /// what appears in the minibuffer when opening
144 virtual string const EditMessage() const;
146 virtual void Edit(BufferView *, int x, int y, unsigned int button);
148 virtual EDITABLE Editable() const;
149 /// This is called when the user clicks inside an inset
150 virtual void InsetButtonPress(BufferView *, int, int, int) {}
151 /// This is called when the user releases the button inside an inset
152 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
153 /// This is caleld when the user moves the mouse inside an inset
154 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
156 virtual bool IsTextInset() const { return false; }
158 virtual bool doClearArea() const { return true; }
160 virtual bool AutoDelete() const;
162 virtual void Write(Buffer const *, std::ostream &) const = 0;
164 virtual void Read(Buffer const *, LyXLex & lex) = 0;
165 /** returns the number of rows (\n's) of generated tex code.
166 fragile == true means, that the inset should take care about
167 fragile commands by adding a \protect before.
168 If the free_spc (freespacing) variable is set, then this inset
169 is in a free-spacing paragraph.
171 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
172 bool free_spc) const = 0;
174 virtual int Ascii(Buffer const *,
175 std::ostream &, int linelen = 0) const = 0;
177 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
179 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
180 /// Updates needed features for this inset.
181 virtual void Validate(LaTeXFeatures & features) const;
183 virtual bool Deletable() const;
185 /// returns LyX code associated with the inset. Used for TOC, ...)
186 virtual Inset::Code LyxCode() const { return NO_CODE; }
188 virtual std::vector<string> const getLabelList() const {
189 return std::vector<string>();
193 virtual Inset * Clone() const = 0;
195 /// returns true to override begin and end inset in file
196 virtual bool DirectWrite() const;
198 /// Returns true if the inset should be centered alone
199 virtual bool display() const { return false; }
200 /// Changes the display state of the inset
201 virtual void display(bool) {}
203 /// returns true if this inset needs a row on it's own
205 virtual bool needFullRow() const { return false; }
207 virtual bool InsertInsetAllowed(Inset *) const { return false; }
209 void setInsetName(string const & s) { name = s; }
211 string const getInsetName() const { return name; }
213 void setOwner(Inset * inset) { owner_ = inset; }
215 Inset * owner() const { return owner_; }
217 int x() const { return top_x; }
219 int y() const { return top_baseline; }
221 // because we could have fake text insets and have to call this
222 // inside them without cast!!!
224 virtual LyXText * getLyXText(BufferView *) const;
226 virtual void deleteLyXText(BufferView *, bool = true) const {}
228 virtual void resizeLyXText(BufferView *) const {}
229 /// returns the actuall scroll-value
230 int scroll() const { return scx; }
235 mutable int top_baseline;
246 // Updatable Insets. These insets can be locked and receive
247 // directly user interaction. Currently used only for mathed.
248 // Note that all pure methods from Inset class are pure here too.
249 // [Alejandro 080596]
251 /** Extracted from Matthias notes:
253 * An inset can simple call LockInset in it's edit call and *ONLY*
256 * Unlocking is either done by LyX or the inset itself with a
259 * During the lock, all button and keyboard events will be modified
260 * and send to the inset through the following inset-features. Note that
261 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
262 * to contain the code for restoring the menus and things like this.
264 * If a inset wishes any redraw and/or update it just has to call
267 * It's is completly irrelevant, where the inset is. UpdateInset will
268 * find it in any paragraph in any buffer.
269 * Of course the_locking_inset and the insets in the current paragraph/buffer
270 * are checked first, so no performance problem should occur.
272 class UpdatableInset: public Inset {
274 /** Dispatch result codes
275 Now that nested updatable insets are allowed, the local dispatch
276 becomes a bit complex, just two possible results (boolean)
279 DISPATCHED = the inset catched the action
280 DISPATCHED_NOUPDATE = the inset catched the action and no update
281 is needed here to redraw the inset
282 FINISHED = the inset must be unlocked as a result
284 UNDISPATCHED = the action was not catched, it should be
285 dispatched by lower level insets
294 /// To convert old binary dispatch results
295 RESULT DISPATCH_RESULT(bool b) {
296 return b ? DISPATCHED : FINISHED;
302 virtual EDITABLE Editable() const;
304 /// may call ToggleLockedInsetCursor
305 virtual void ToggleInsetCursor(BufferView *);
307 virtual void ShowInsetCursor(BufferView *);
309 virtual void HideInsetCursor(BufferView *);
311 virtual void GetCursorPos(BufferView *, int &, int &) const {}
313 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
315 virtual void InsetButtonRelease(BufferView *,
316 int x, int y, int button);
318 virtual void InsetKeyPress(XKeyEvent * ev);
320 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
322 virtual void InsetUnlock(BufferView *);
324 virtual void Edit(BufferView *, int x, int y, unsigned int button);
326 virtual void draw(BufferView *, LyXFont const &,
327 int baseline, float & x, bool cleared) const;
329 virtual void SetFont(BufferView *, LyXFont const &,
330 bool toggleall = false);
332 virtual bool InsertInset(BufferView *, Inset *) { return false; }
334 virtual bool InsertInsetAllowed(Inset *) const { return true; }
336 virtual UpdatableInset * GetLockingInset() { return this; }
338 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
339 { return (c == LyxCode()) ? this : 0; }
341 virtual int InsetInInsetY() { return 0; }
343 virtual bool UpdateInsetInInset(BufferView *, Inset *)
346 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
349 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
352 /// An updatable inset could handle lyx editing commands
353 virtual RESULT LocalDispatch(BufferView *, int, string const &);
355 virtual bool isCursorVisible() const { return cursor_visible; }
357 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
359 int scroll() const { return scx; }
363 mutable bool cursor_visible;
365 // scrolls to absolute position in bufferview-workwidth * sx units
366 void scroll(BufferView *, float sx) const;
367 // scrolls offset pixels
368 void scroll(BufferView *, int offset) const;