2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
35 /** This is not quite the correct place for this enum. I think
36 the correct would be to let each subclass of Inset declare
37 its own enum code. Actually the notion of an Inset::Code
38 should be avoided, but I am not sure how this could be done
44 TOC_CODE, // do these insets really need a code? (ale)
104 Inset() { owner_ = 0; }
108 virtual int ascent(Painter &, LyXFont const &) const = 0;
110 virtual int descent(Painter &, LyXFont const &) const = 0;
112 virtual int width(Painter &, LyXFont const &) const = 0;
114 virtual void draw(Painter &, LyXFont const &,
115 int baseline, float & x) const = 0;
117 virtual LyXFont ConvertFont(LyXFont font);
118 /// what appears in the minibuffer when opening
119 virtual const char * EditMessage() const;
121 virtual void Edit(BufferView *, int x, int y, unsigned int button);
123 virtual EDITABLE Editable() const;
125 virtual void InsetButtonPress(BufferView *, int, int, int) {}
127 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
129 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
131 bool IsTextInset() const;
133 virtual bool AutoDelete() const;
135 virtual void Write(std::ostream &) const = 0;
137 virtual void Read(LyXLex & lex) = 0;
138 /** returns the number of rows (\n's) of generated tex code.
139 fragile == true means, that the inset should take care about
140 fragile commands by adding a \protect before.
141 If the free_spc (freespacing) variable is set, then this inset
142 is in a free-spacing paragraph.
144 virtual int Latex(std::ostream &, bool fragile,
145 bool free_spc) const = 0;
147 virtual int Ascii(std::ostream &) const = 0;
149 virtual int Linuxdoc(std::ostream &) const = 0;
151 virtual int DocBook(std::ostream &) const = 0;
152 /// Updates needed features for this inset.
153 virtual void Validate(LaTeXFeatures & features) const;
155 virtual bool Deletable() const;
157 /// returns LyX code associated with the inset. Used for TOC, ...)
158 virtual Inset::Code LyxCode() const { return NO_CODE; }
160 /// Get the label that appears at screen
161 virtual string getLabel(int) const {
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 int GetNumberOfLabels() const {
180 virtual void init(BufferView *) {}
182 virtual bool InsertInsetAllowed(Inset *) const { return false; }
184 virtual void setInsetName(const char * s) { name = s; }
186 virtual string getInsetName() const { return name; }
188 virtual void setOwner(Inset * inset) { owner_ = inset; }
190 virtual Inset * owner() const { return owner_; }
200 // Updatable Insets. These insets can be locked and receive
201 // directly user interaction. Currently used only for mathed.
202 // Note that all pure methods from Inset class are pure here too.
203 // [Alejandro 080596]
205 /** Extracted from Matthias notes:
207 * An inset can simple call LockInset in it's edit call and *ONLY*
210 * Unlocking is either done by LyX or the inset itself with a
213 * During the lock, all button and keyboard events will be modified
214 * and send to the inset through the following inset-features. Note that
215 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
216 * to contain the code for restoring the menus and things like this.
218 * If a inset wishes any redraw and/or update it just has to call
221 * It's is completly irrelevant, where the inset is. UpdateInset will
222 * find it in any paragraph in any buffer.
223 * Of course the_locking_inset and the insets in the current paragraph/buffer
224 * are checked first, so no performance problem should occur.
226 class UpdatableInset: public Inset {
228 /** Dispatch result codes
229 Now that nested updatable insets are allowed, the local dispatch
230 becomes a bit complex, just two possible results (boolean)
233 DISPATCHED = the inset catched the action
234 DISPATCHED_NOUPDATE = the inset catched the action and no update
235 is needed here to redraw the inset
236 FINISHED = the inset must be unlocked as a result
238 UNDISPATCHED = the action was not catched, it should be
239 dispatched by lower level insets
248 /// To convert old binary dispatch results
249 RESULT DISPATCH_RESULT(bool b) {
250 return b ? DISPATCHED : FINISHED;
254 UpdatableInset() { scx = mx_scx = 0; }
256 //virtual ~UpdatableInset() {}
258 virtual EDITABLE Editable() const;
260 /// may call ToggleLockedInsetCursor
261 virtual void ToggleInsetCursor(BufferView *);
263 virtual void ShowInsetCursor(BufferView *);
265 virtual void HideInsetCursor(BufferView *);
267 virtual void GetCursorPos(int &, int &) const {}
269 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
271 virtual void InsetButtonRelease(BufferView *,
272 int x, int y, int button);
274 virtual void InsetKeyPress(XKeyEvent * ev);
276 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
278 virtual void InsetUnlock(BufferView *);
280 virtual void Edit(BufferView *, int x, int y, unsigned int button);
282 virtual void draw(Painter &, LyXFont const &,
283 int baseline, float & x) const;
285 virtual void SetFont(BufferView *, LyXFont const &,
286 bool toggleall = false);
288 virtual bool InsertInset(BufferView *, Inset *) { return false; }
290 virtual bool InsertInsetAllowed(Inset *) const { return true; }
292 virtual UpdatableInset * GetLockingInset() { return this; }
294 virtual int InsetInInsetY() { return 0; }
296 virtual bool UpdateInsetInInset(BufferView *, Inset *)
299 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
302 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
305 /// An updatable inset could handle lyx editing commands
306 virtual RESULT LocalDispatch(BufferView *, int, string const &);
308 virtual bool isCursorVisible() const { return cursor_visible; }
310 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
314 // virtual void UpdateLocal(bool flag=true);
317 mutable int top_baseline;
318 mutable bool cursor_visible;