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)
106 Inset() { owner_ = 0; }
110 virtual int ascent(Painter &, LyXFont const &) const = 0;
112 virtual int descent(Painter &, LyXFont const &) const = 0;
114 virtual int width(Painter &, LyXFont const &) const = 0;
116 virtual void draw(Painter &, LyXFont const &,
117 int baseline, float & x) const = 0;
119 virtual LyXFont ConvertFont(LyXFont font);
120 /// what appears in the minibuffer when opening
121 virtual const char * EditMessage() const;
123 virtual void Edit(BufferView *, int x, int y, unsigned int button);
125 virtual EDITABLE Editable() const;
127 virtual void InsetButtonPress(BufferView *, int, int, int) {}
129 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
131 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
133 bool IsTextInset() const;
135 virtual bool AutoDelete() const;
137 virtual void Write(std::ostream &) const = 0;
139 virtual void Read(LyXLex & lex) = 0;
140 /** returns the number of rows (\n's) of generated tex code.
141 fragile == true means, that the inset should take care about
142 fragile commands by adding a \protect before.
143 If the free_spc (freespacing) variable is set, then this inset
144 is in a free-spacing paragraph.
146 virtual int Latex(std::ostream &, bool fragile,
147 bool free_spc) 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 /// Get the label that appears at screen
162 virtual string getLabel(int) const {
167 virtual Inset * Clone() const = 0;
169 /// returns true to override begin and end inset in file
170 virtual bool DirectWrite() const;
172 /// Returns true if the inset should be centered alone
173 virtual bool display() const { return false; }
174 /// Changes the display state of the inset
175 virtual void display(bool) {}
177 virtual int GetNumberOfLabels() const {
181 virtual void init(BufferView *) {}
183 virtual bool InsertInsetAllowed(Inset *) const { return false; }
185 virtual void setInsetName(const char * s) { name = s; }
187 virtual string getInsetName() const { return name; }
189 virtual void setOwner(Inset * inset) { owner_ = inset; }
191 virtual Inset * owner() const { return owner_; }
201 // Updatable Insets. These insets can be locked and receive
202 // directly user interaction. Currently used only for mathed.
203 // Note that all pure methods from Inset class are pure here too.
204 // [Alejandro 080596]
206 /** Extracted from Matthias notes:
208 * An inset can simple call LockInset in it's edit call and *ONLY*
211 * Unlocking is either done by LyX or the inset itself with a
214 * During the lock, all button and keyboard events will be modified
215 * and send to the inset through the following inset-features. Note that
216 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
217 * to contain the code for restoring the menus and things like this.
219 * If a inset wishes any redraw and/or update it just has to call
222 * It's is completly irrelevant, where the inset is. UpdateInset will
223 * find it in any paragraph in any buffer.
224 * Of course the_locking_inset and the insets in the current paragraph/buffer
225 * are checked first, so no performance problem should occur.
227 class UpdatableInset: public Inset {
229 /** Dispatch result codes
230 Now that nested updatable insets are allowed, the local dispatch
231 becomes a bit complex, just two possible results (boolean)
234 DISPATCHED = the inset catched the action
235 DISPATCHED_NOUPDATE = the inset catched the action and no update
236 is needed here to redraw the inset
237 FINISHED = the inset must be unlocked as a result
239 UNDISPATCHED = the action was not catched, it should be
240 dispatched by lower level insets
249 /// To convert old binary dispatch results
250 RESULT DISPATCH_RESULT(bool b) {
251 return b ? DISPATCHED : FINISHED;
255 UpdatableInset() { scx = mx_scx = 0; }
257 //virtual ~UpdatableInset() {}
259 virtual EDITABLE Editable() const;
261 /// may call ToggleLockedInsetCursor
262 virtual void ToggleInsetCursor(BufferView *);
264 virtual void ShowInsetCursor(BufferView *);
266 virtual void HideInsetCursor(BufferView *);
268 virtual void GetCursorPos(int &, int &) const {}
270 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
272 virtual void InsetButtonRelease(BufferView *,
273 int x, int y, int button);
275 virtual void InsetKeyPress(XKeyEvent * ev);
277 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
279 virtual void InsetUnlock(BufferView *);
281 virtual void Edit(BufferView *, int x, int y, unsigned int button);
283 virtual void draw(Painter &, LyXFont const &,
284 int baseline, float & x) const;
286 virtual void SetFont(BufferView *, LyXFont const &,
287 bool toggleall = false);
289 virtual bool InsertInset(BufferView *, Inset *) { return false; }
291 virtual bool InsertInsetAllowed(Inset *) const { return true; }
293 virtual UpdatableInset * GetLockingInset() { return this; }
295 virtual int InsetInInsetY() { return 0; }
297 virtual bool UpdateInsetInInset(BufferView *, Inset *)
300 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
303 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
306 /// An updatable inset could handle lyx editing commands
307 virtual RESULT LocalDispatch(BufferView *, int, string const &);
309 virtual bool isCursorVisible() const { return cursor_visible; }
311 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
315 // virtual void UpdateLocal(bool flag=true);
318 mutable int top_baseline;
319 mutable bool cursor_visible;