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