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)
114 TEXT_TO_INSET_OFFSET = 2
128 Inset() { owner_ = 0; top_x = top_baseline = 0; scx = 0; }
132 virtual int ascent(BufferView *, LyXFont const &) const = 0;
134 virtual int descent(BufferView *, LyXFont const &) const = 0;
136 virtual int width(BufferView *, LyXFont const &) const = 0;
138 virtual void draw(BufferView *, LyXFont const &,
139 int baseline, float & x, bool cleared) const = 0;
140 /// update the inset representation
141 virtual void update(BufferView *, LyXFont const &, bool = false)
144 virtual LyXFont const ConvertFont(LyXFont const & font) const;
145 /// what appears in the minibuffer when opening
146 virtual string const EditMessage() const;
148 virtual void Edit(BufferView *, int x, int y, unsigned int button);
150 virtual EDITABLE Editable() const;
151 /// This is called when the user clicks inside an inset
152 virtual void InsetButtonPress(BufferView *, int, int, int) {}
153 /// This is called when the user releases the button inside an inset
154 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
155 /// This is caleld when the user moves the mouse inside an inset
156 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
158 virtual bool IsTextInset() const { return false; }
160 virtual bool doClearArea() const { return true; }
162 virtual bool AutoDelete() const;
164 virtual void Write(Buffer const *, std::ostream &) const = 0;
166 virtual void Read(Buffer const *, LyXLex & lex) = 0;
167 /** returns the number of rows (\n's) of generated tex code.
168 fragile == true means, that the inset should take care about
169 fragile commands by adding a \protect before.
170 If the free_spc (freespacing) variable is set, then this inset
171 is in a free-spacing paragraph.
173 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
174 bool free_spc) const = 0;
176 virtual int Ascii(Buffer const *,
177 std::ostream &, int linelen = 0) const = 0;
179 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
181 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
182 /// Updates needed features for this inset.
183 virtual void Validate(LaTeXFeatures & features) const;
185 virtual bool Deletable() const;
187 /// returns LyX code associated with the inset. Used for TOC, ...)
188 virtual Inset::Code LyxCode() const { return NO_CODE; }
190 virtual std::vector<string> const getLabelList() const {
191 return std::vector<string>();
195 virtual Inset * Clone(Buffer const &) const = 0;
197 /// returns true to override begin and end inset in file
198 virtual bool DirectWrite() const;
200 /// Returns true if the inset should be centered alone
201 virtual bool display() const { return false; }
202 /// Changes the display state of the inset
203 virtual void display(bool) {}
205 /// returns true if this inset needs a row on it's own
207 virtual bool needFullRow() const { return false; }
209 virtual bool InsertInsetAllowed(Inset *) const { return false; }
211 void setInsetName(string const & s) { name = s; }
213 string const getInsetName() const { return name; }
215 void setOwner(Inset * inset) { owner_ = inset; }
217 Inset * owner() const { return owner_; }
219 int x() const { return top_x; }
221 int y() const { return top_baseline; }
223 // because we could have fake text insets and have to call this
224 // inside them without cast!!!
226 virtual LyXText * getLyXText(BufferView const *) const;
228 virtual void deleteLyXText(BufferView *, bool = true) const {}
230 virtual void resizeLyXText(BufferView *) const {}
231 /// returns the actuall scroll-value
232 int scroll() const { return scx; }
237 mutable int top_baseline;
248 // Updatable Insets. These insets can be locked and receive
249 // directly user interaction. Currently used only for mathed.
250 // Note that all pure methods from Inset class are pure here too.
251 // [Alejandro 080596]
253 /** Extracted from Matthias notes:
255 * An inset can simple call LockInset in it's edit call and *ONLY*
258 * Unlocking is either done by LyX or the inset itself with a
261 * During the lock, all button and keyboard events will be modified
262 * and send to the inset through the following inset-features. Note that
263 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
264 * to contain the code for restoring the menus and things like this.
266 * If a inset wishes any redraw and/or update it just has to call
269 * It's is completly irrelevant, where the inset is. UpdateInset will
270 * find it in any paragraph in any buffer.
271 * Of course the_locking_inset and the insets in the current paragraph/buffer
272 * are checked first, so no performance problem should occur.
274 class UpdatableInset: public Inset {
276 /** Dispatch result codes
277 Now that nested updatable insets are allowed, the local dispatch
278 becomes a bit complex, just two possible results (boolean)
281 DISPATCHED = the inset catched the action
282 DISPATCHED_NOUPDATE = the inset catched the action and no update
283 is needed here to redraw the inset
284 FINISHED = the inset must be unlocked as a result
286 UNDISPATCHED = the action was not catched, it should be
287 dispatched by lower level insets
296 /// To convert old binary dispatch results
297 RESULT DISPATCH_RESULT(bool b) {
298 return b ? DISPATCHED : FINISHED;
304 virtual EDITABLE Editable() const;
306 /// may call ToggleLockedInsetCursor
307 virtual void ToggleInsetCursor(BufferView *);
309 virtual void ShowInsetCursor(BufferView *, bool show=true);
311 virtual void HideInsetCursor(BufferView *);
313 virtual void GetCursorPos(BufferView *, int &, int &) const {}
315 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
317 virtual void InsetButtonRelease(BufferView *,
318 int x, int y, int button);
320 virtual void InsetKeyPress(XKeyEvent * ev);
322 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
324 virtual void InsetUnlock(BufferView *);
326 virtual void Edit(BufferView *, int x, int y, unsigned int button);
328 virtual void draw(BufferView *, LyXFont const &,
329 int baseline, float & x, bool cleared) const;
331 virtual void SetFont(BufferView *, LyXFont const &,
332 bool toggleall = false);
334 virtual bool InsertInset(BufferView *, Inset *) { return false; }
336 virtual bool InsertInsetAllowed(Inset *) const { return true; }
338 virtual UpdatableInset * GetLockingInset() { return this; }
340 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
341 { return (c == LyxCode()) ? this : 0; }
343 virtual unsigned int InsetInInsetY() { return 0; }
345 virtual bool UpdateInsetInInset(BufferView *, Inset *)
348 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
351 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
354 /// An updatable inset could handle lyx editing commands
355 virtual RESULT LocalDispatch(BufferView *, int, string const &);
357 virtual bool isCursorVisible() const { return cursor_visible; }
359 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
361 int scroll() const { return scx; }
365 mutable bool cursor_visible;
367 // scrolls to absolute position in bufferview-workwidth * sx units
368 void scroll(BufferView *, float sx) const;
369 // scrolls offset pixels
370 void scroll(BufferView *, int offset) const;