2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
36 /** This is not quite the correct place for this enum. I think
37 the correct would be to let each subclass of Inset declare
38 its own enum code. Actually the notion of an Inset::Code
39 should be avoided, but I am not sure how this could be done
45 TOC_CODE, // do these insets really need a code? (ale)
105 Inset() { owner_ = 0; top_x = top_baseline = 0; }
109 virtual int ascent(Painter &, LyXFont const &) const = 0;
111 virtual int descent(Painter &, LyXFont const &) const = 0;
113 virtual int width(Painter &, LyXFont const &) const = 0;
115 virtual void draw(Painter &, LyXFont const &,
116 int baseline, float & x) const = 0;
118 virtual LyXFont ConvertFont(LyXFont font);
119 /// what appears in the minibuffer when opening
120 virtual const char * EditMessage() const;
122 virtual void Edit(BufferView *, int x, int y, unsigned int button);
124 virtual EDITABLE Editable() const;
126 virtual void InsetButtonPress(BufferView *, int, int, int) {}
128 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
130 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
132 bool IsTextInset() const;
134 virtual bool AutoDelete() const;
136 virtual void Write(std::ostream &) const = 0;
138 virtual void Read(LyXLex & lex) = 0;
139 /** returns the number of rows (\n's) of generated tex code.
140 fragile == true means, that the inset should take care about
141 fragile commands by adding a \protect before.
142 If the free_spc (freespacing) variable is set, then this inset
143 is in a free-spacing paragraph.
145 virtual int Latex(std::ostream &, bool fragile,
146 bool free_spc) const = 0;
148 virtual int Ascii(std::ostream &) const = 0;
150 virtual int Linuxdoc(std::ostream &) const = 0;
152 virtual int DocBook(std::ostream &) const = 0;
153 /// Updates needed features for this inset.
154 virtual void Validate(LaTeXFeatures & features) const;
156 virtual bool Deletable() const;
158 /// returns LyX code associated with the inset. Used for TOC, ...)
159 virtual Inset::Code LyxCode() const { return NO_CODE; }
161 virtual std::vector<string> getLabelList() const {
162 return std::vector<string>();
166 virtual Inset * Clone() const = 0;
168 /// returns true to override begin and end inset in file
169 virtual bool DirectWrite() const;
171 /// Returns true if the inset should be centered alone
172 virtual bool display() const { return false; }
173 /// Changes the display state of the inset
174 virtual void display(bool) {}
176 virtual bool InsertInsetAllowed(Inset *) const { return false; }
178 virtual void setInsetName(const char * s) { name = s; }
180 virtual string getInsetName() const { return name; }
182 virtual void setOwner(Inset * inset) { owner_ = inset; }
184 virtual Inset * owner() const { return owner_; }
186 int x() const { return top_x; }
188 int y() const { return top_baseline; }
193 mutable int top_baseline;
203 // Updatable Insets. These insets can be locked and receive
204 // directly user interaction. Currently used only for mathed.
205 // Note that all pure methods from Inset class are pure here too.
206 // [Alejandro 080596]
208 /** Extracted from Matthias notes:
210 * An inset can simple call LockInset in it's edit call and *ONLY*
213 * Unlocking is either done by LyX or the inset itself with a
216 * During the lock, all button and keyboard events will be modified
217 * and send to the inset through the following inset-features. Note that
218 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
219 * to contain the code for restoring the menus and things like this.
221 * If a inset wishes any redraw and/or update it just has to call
224 * It's is completly irrelevant, where the inset is. UpdateInset will
225 * find it in any paragraph in any buffer.
226 * Of course the_locking_inset and the insets in the current paragraph/buffer
227 * are checked first, so no performance problem should occur.
229 class UpdatableInset: public Inset {
231 /** Dispatch result codes
232 Now that nested updatable insets are allowed, the local dispatch
233 becomes a bit complex, just two possible results (boolean)
236 DISPATCHED = the inset catched the action
237 DISPATCHED_NOUPDATE = the inset catched the action and no update
238 is needed here to redraw the inset
239 FINISHED = the inset must be unlocked as a result
241 UNDISPATCHED = the action was not catched, it should be
242 dispatched by lower level insets
251 /// To convert old binary dispatch results
252 RESULT DISPATCH_RESULT(bool b) {
253 return b ? DISPATCHED : FINISHED;
257 UpdatableInset() { scx = mx_scx = 0; }
259 //virtual ~UpdatableInset() {}
261 virtual EDITABLE Editable() const;
263 /// may call ToggleLockedInsetCursor
264 virtual void ToggleInsetCursor(BufferView *);
266 virtual void ShowInsetCursor(BufferView *);
268 virtual void HideInsetCursor(BufferView *);
270 virtual void GetCursorPos(int &, int &) const {}
272 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
274 virtual void InsetButtonRelease(BufferView *,
275 int x, int y, int button);
277 virtual void InsetKeyPress(XKeyEvent * ev);
279 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
281 virtual void InsetUnlock(BufferView *);
283 virtual void Edit(BufferView *, int x, int y, unsigned int button);
285 virtual void draw(Painter &, LyXFont const &,
286 int baseline, float & x) const;
288 virtual void SetFont(BufferView *, LyXFont const &,
289 bool toggleall = false);
291 virtual bool InsertInset(BufferView *, Inset *) { return false; }
293 virtual bool InsertInsetAllowed(Inset *) const { return true; }
295 virtual UpdatableInset * GetLockingInset() { return this; }
297 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
298 { return (c == LyxCode()) ? this : 0; }
300 virtual int InsetInInsetY() { return 0; }
302 virtual bool UpdateInsetInInset(BufferView *, Inset *)
305 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
308 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
311 /// An updatable inset could handle lyx editing commands
312 virtual RESULT LocalDispatch(BufferView *, int, string const &);
314 virtual bool isCursorVisible() const { return cursor_visible; }
316 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
320 mutable bool cursor_visible;