2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
38 /** This is not quite the correct place for this enum. I think
39 the correct would be to let each subclass of Inset declare
40 its own enum code. Actually the notion of an Inset::Code
41 should be avoided, but I am not sure how this could be done
47 TOC_CODE, // do these insets really need a code? (ale)
109 enum { TEXT_TO_INSET_OFFSET = 2 };
118 Inset() { owner_ = 0; top_x = top_baseline = 0; }
122 virtual int ascent(BufferView *, LyXFont const &) const = 0;
124 virtual int descent(BufferView *, LyXFont const &) const = 0;
126 virtual int width(BufferView *, LyXFont const &) const = 0;
128 virtual void draw(BufferView *, LyXFont const &,
129 int baseline, float & x, bool cleared) const = 0;
130 /// update the inset representation
131 virtual void update(BufferView *, LyXFont const &, bool =false)
134 virtual LyXFont ConvertFont(LyXFont font);
135 /// what appears in the minibuffer when opening
136 virtual const char * EditMessage() const;
138 virtual void Edit(BufferView *, int x, int y, unsigned int button);
140 virtual EDITABLE Editable() const;
141 /// This is called when the user clicks inside an inset
142 virtual void InsetButtonPress(BufferView *, int, int, int) {}
143 /// This is called when the user releases the button inside an inset
144 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
145 /// This is caleld when the user moves the mouse inside an inset
146 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
148 virtual bool IsTextInset() const { return false; }
150 virtual bool doClearArea() const { return true; }
152 virtual bool AutoDelete() const;
154 virtual void Write(Buffer const *, std::ostream &) const = 0;
156 virtual void Read(Buffer const *, LyXLex & lex) = 0;
157 /** returns the number of rows (\n's) of generated tex code.
158 fragile == true means, that the inset should take care about
159 fragile commands by adding a \protect before.
160 If the free_spc (freespacing) variable is set, then this inset
161 is in a free-spacing paragraph.
163 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
164 bool free_spc) const = 0;
166 virtual int Ascii(Buffer const *, std::ostream &) const = 0;
168 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
170 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
171 /// Updates needed features for this inset.
172 virtual void Validate(LaTeXFeatures & features) const;
174 virtual bool Deletable() const;
176 /// returns LyX code associated with the inset. Used for TOC, ...)
177 virtual Inset::Code LyxCode() const { return NO_CODE; }
179 virtual std::vector<string> getLabelList() const {
180 return std::vector<string>();
184 virtual Inset * Clone() const = 0;
186 /// returns true to override begin and end inset in file
187 virtual bool DirectWrite() const;
189 /// Returns true if the inset should be centered alone
190 virtual bool display() const { return false; }
191 /// Changes the display state of the inset
192 virtual void display(bool) {}
194 /// returns true if this inset needs a row on it's own
196 virtual bool needFullRow() const { return false; }
198 virtual bool InsertInsetAllowed(Inset *) const { return false; }
200 virtual void setInsetName(const char * s) { name = s; }
202 virtual string getInsetName() const { return name; }
204 virtual void setOwner(Inset * inset) { owner_ = inset; }
206 virtual Inset * owner() const { return owner_; }
208 int x() const { return top_x; }
210 int y() const { return top_baseline; }
212 /// because we could have fake text insets and have to call this
213 /// inside them without cast!!!
214 virtual LyXText * getLyXText(BufferView *) const;
215 virtual void deleteLyXText(BufferView *, bool =true) const {}
216 virtual void resizeLyXText(BufferView *) const {}
221 mutable int top_baseline;
231 // Updatable Insets. These insets can be locked and receive
232 // directly user interaction. Currently used only for mathed.
233 // Note that all pure methods from Inset class are pure here too.
234 // [Alejandro 080596]
236 /** Extracted from Matthias notes:
238 * An inset can simple call LockInset in it's edit call and *ONLY*
241 * Unlocking is either done by LyX or the inset itself with a
244 * During the lock, all button and keyboard events will be modified
245 * and send to the inset through the following inset-features. Note that
246 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
247 * to contain the code for restoring the menus and things like this.
249 * If a inset wishes any redraw and/or update it just has to call
252 * It's is completly irrelevant, where the inset is. UpdateInset will
253 * find it in any paragraph in any buffer.
254 * Of course the_locking_inset and the insets in the current paragraph/buffer
255 * are checked first, so no performance problem should occur.
257 class UpdatableInset: public Inset {
259 /** Dispatch result codes
260 Now that nested updatable insets are allowed, the local dispatch
261 becomes a bit complex, just two possible results (boolean)
264 DISPATCHED = the inset catched the action
265 DISPATCHED_NOUPDATE = the inset catched the action and no update
266 is needed here to redraw the inset
267 FINISHED = the inset must be unlocked as a result
269 UNDISPATCHED = the action was not catched, it should be
270 dispatched by lower level insets
279 /// To convert old binary dispatch results
280 RESULT DISPATCH_RESULT(bool b) {
281 return b ? DISPATCHED : FINISHED;
285 UpdatableInset() { scx = mx_scx = 0; }
287 virtual EDITABLE Editable() const;
289 /// may call ToggleLockedInsetCursor
290 virtual void ToggleInsetCursor(BufferView *);
292 virtual void ShowInsetCursor(BufferView *);
294 virtual void HideInsetCursor(BufferView *);
296 virtual void GetCursorPos(BufferView *, int &, int &) const {}
298 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
300 virtual void InsetButtonRelease(BufferView *,
301 int x, int y, int button);
303 virtual void InsetKeyPress(XKeyEvent * ev);
305 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
307 virtual void InsetUnlock(BufferView *);
309 virtual void Edit(BufferView *, int x, int y, unsigned int button);
311 virtual void draw(BufferView *, LyXFont const &,
312 int baseline, float & x, bool cleared) const;
314 virtual void SetFont(BufferView *, LyXFont const &,
315 bool toggleall = false);
317 virtual bool InsertInset(BufferView *, Inset *) { return false; }
319 virtual bool InsertInsetAllowed(Inset *) const { return true; }
321 virtual UpdatableInset * GetLockingInset() { return this; }
323 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
324 { return (c == LyxCode()) ? this : 0; }
326 virtual int InsetInInsetY() { return 0; }
328 virtual bool UpdateInsetInInset(BufferView *, Inset *)
331 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
334 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
337 /// An updatable inset could handle lyx editing commands
338 virtual RESULT LocalDispatch(BufferView *, int, string const &);
340 virtual bool isCursorVisible() const { return cursor_visible; }
342 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
346 mutable bool cursor_visible;