2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 the LyX Team.
10 * ====================================================== */
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 virtual int ascent(Painter &, LyXFont const &) const = 0;
108 virtual int descent(Painter &, LyXFont const &) const = 0;
110 virtual int width(Painter &, LyXFont const &) const = 0;
112 virtual void draw(Painter &, LyXFont const &,
113 int baseline, float & x) const = 0;
115 virtual LyXFont ConvertFont(LyXFont font);
116 /// what appears in the minibuffer when opening
117 virtual const char * EditMessage() const {return _("Opened inset");}
119 virtual void Edit(BufferView *, int x, int y, unsigned int button);
121 virtual EDITABLE Editable() const;
123 bool IsTextInset() const;
125 virtual bool AutoDelete() const;
127 virtual void Write(ostream &) const = 0;
129 virtual void Read(LyXLex & lex) = 0;
130 /** returns the number of rows (\n's) of generated tex code.
131 fragile != 0 means, that the inset should take care about
132 fragile commands by adding a \protect before.
133 If the freee_spc (freespacing) variable is set, then this inset
134 is in a free-spacing paragraph.
136 virtual int Latex(ostream &, signed char fragile,
137 bool free_spc) const = 0;
140 virtual int Linuxdoc(ostream &) const = 0;
142 virtual int DocBook(ostream &) const = 0;
143 /// Updates needed features for this inset.
144 virtual void Validate(LaTeXFeatures & features) const;
146 virtual bool Deletable() const;
148 /// returns LyX code associated with the inset. Used for TOC, ...)
149 virtual Inset::Code LyxCode() const { return NO_CODE; }
151 /// Get the label that appears at screen
152 virtual string getLabel(int) const {
157 virtual Inset * Clone() const = 0;
159 /// returns true to override begin and end inset in file
160 virtual bool DirectWrite() const;
162 /// Returns true if the inset should be centered alone
163 virtual bool display() const { return false; }
164 /// Changes the display state of the inset
165 virtual void display(bool) {}
167 virtual int GetNumberOfLabels() const {
171 virtual void init(BufferView *) {}
176 // Updatable Insets. These insets can be locked and receive
177 // directly user interaction. Currently used only for mathed.
178 // Note that all pure methods from Inset class are pure here too.
179 // [Alejandro 080596]
181 /** Extracted from Matthias notes:
183 * An inset can simple call LockInset in it's edit call and *ONLY*
186 * Unlocking is either done by LyX or the inset itself with a
189 * During the lock, all button and keyboard events will be modified
190 * and send to the inset through the following inset-features. Note that
191 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
192 * to contain the code for restoring the menus and things like this.
194 * If a inset wishes any redraw and/or update it just has to call
197 * It's is completly irrelevant, where the inset is. UpdateInset will
198 * find it in any paragraph in any buffer.
199 * Of course the_locking_inset and the insets in the current paragraph/buffer
200 * are checked first, so no performance problem should occur.
202 class UpdatableInset: public Inset {
204 /** Dispatch result codes
205 Now that nested updatable insets are allowed, the local dispatch
206 becomes a bit complex, just two possible results (boolean)
209 DISPATCHED = the inset catched the action
210 FINISHED = the inset must be unlocked as a result
212 UNDISPATCHED = the action was not catched, it should be
213 dispatched by lower level insets
221 /// To convert old binary dispatch results
222 RESULT DISPATCH_RESULT(bool b) {
223 return b ? DISPATCHED : FINISHED;
232 //virtual ~UpdatableInset() {}
234 virtual EDITABLE Editable() const;
236 /// may call ToggleLockedInsetCursor
237 virtual void ToggleInsetCursor(BufferView *);
239 virtual void GetCursorPos(int &, int &) const {}
241 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
243 virtual void InsetButtonRelease(BufferView *,
244 int x, int y, int button);
246 virtual void InsetKeyPress(XKeyEvent * ev);
248 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
250 virtual void InsetUnlock(BufferView *);
252 virtual void Edit(BufferView *, int x, int y, unsigned int button);
254 virtual void draw(Painter &, LyXFont const &,
255 int baseline, float & x) const;
257 virtual void SetFont(BufferView *, LyXFont const &,
258 bool toggleall = false);
260 virtual bool InsertInset(BufferView *, Inset *) { return false; }
262 virtual UpdatableInset * GetLockingInset() { return this; }
264 virtual int InsetInInsetY() { return 0; }
266 virtual bool UpdateInsetInInset(BufferView *, Inset *)
269 virtual bool UnlockInsetInInset(BufferView *, Inset *,
272 /// An updatable inset could handle lyx editing commands
273 virtual RESULT LocalDispatch(BufferView *, int, string const &);
275 virtual bool isCursorVisible() const { return cursor_visible; }
277 virtual int getMaxWidth(Painter & pain) const;
279 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
281 virtual UpdatableInset * owner() { return owner_; }
285 // virtual void UpdateLocal(bool flag=true);
288 mutable int top_baseline;
289 mutable bool cursor_visible;
296 UpdatableInset * owner_;