2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 the LyX Team.
10 * ====================================================== */
33 /** This is not quite the correct place for this enum. I think
34 the correct would be to let each subclass of Inset declare
35 its own enum code. Actually the notion of an Inset::Code
36 should be avoided, but I am not sure how this could be done
42 TOC_CODE, // do these insets really need a code? (ale)
100 virtual int ascent(Painter &, LyXFont const &) const = 0;
102 virtual int descent(Painter &, LyXFont const &) const = 0;
104 virtual int width(Painter &, LyXFont const &) const = 0;
106 virtual void draw(Painter &, LyXFont const &,
107 int baseline, float & x) const = 0;
109 virtual LyXFont ConvertFont(LyXFont font);
110 /// what appears in the minibuffer when opening
111 virtual const char * EditMessage() const {return _("Opened inset");}
113 virtual void Edit(BufferView *, int x, int y, unsigned int button);
115 virtual EDITABLE Editable() const;
117 virtual bool AutoDelete() const;
119 virtual void Write(ostream &) const = 0;
121 virtual void Read(LyXLex & lex) = 0;
122 /** returns the number of rows (\n's) of generated tex code.
123 fragile != 0 means, that the inset should take care about
124 fragile commands by adding a \protect before.
125 If the freee_spc (freespacing) variable is set, then this inset
126 is in a free-spacing paragraph.
128 virtual int Latex(ostream &, signed char fragile,
129 bool free_spc) const = 0;
132 virtual int Linuxdoc(ostream &) const = 0;
134 virtual int DocBook(ostream &) const = 0;
135 /// Updates needed features for this inset.
136 virtual void Validate(LaTeXFeatures & features) const;
138 virtual bool Deletable() const;
140 /// returns LyX code associated with the inset. Used for TOC, ...)
141 virtual Inset::Code LyxCode() const = 0;
143 /// Get the label that appears at screen
144 virtual string getLabel(int) const {
149 virtual Inset * Clone() const = 0;
151 /// returns true to override begin and end inset in file
152 virtual bool DirectWrite() const;
154 /// Returns true if the inset should be centered alone
155 virtual bool display() const { return false; }
156 /// Changes the display state of the inset
157 virtual void display(bool) {}
159 virtual int GetNumberOfLabels() const {
163 virtual void init(BufferView *) {}
168 // Updatable Insets. These insets can be locked and receive
169 // directly user interaction. Currently used only for mathed.
170 // Note that all pure methods from Inset class are pure here too.
171 // [Alejandro 080596]
173 /** Extracted from Matthias notes:
175 * An inset can simple call LockInset in it's edit call and *ONLY*
178 * Unlocking is either done by LyX or the inset itself with a
181 * During the lock, all button and keyboard events will be modified
182 * and send to the inset through the following inset-features. Note that
183 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
184 * to contain the code for restoring the menus and things like this.
186 * If a inset wishes any redraw and/or update it just has to call
189 * It's is completly irrelevant, where the inset is. UpdateInset will
190 * find it in any paragraph in any buffer.
191 * Of course the_locking_inset and the insets in the current paragraph/buffer
192 * are checked first, so no performance problem should occur.
194 class UpdatableInset: public Inset {
196 /** Dispatch result codes
197 Now that nested updatable insets are allowed, the local dispatch
198 becomes a bit complex, just two possible results (boolean)
201 DISPATCHED = the inset catched the action
202 FINISHED = the inset must be unlocked as a result
204 UNDISPATCHED = the action was not catched, it should be
205 dispatched by lower level insets
213 /// To convert old binary dispatch results
214 RESULT DISPATCH_RESULT(bool b) {
215 return b ? DISPATCHED : FINISHED;
224 //virtual ~UpdatableInset() {}
226 virtual EDITABLE Editable() const;
228 /// may call ToggleLockedInsetCursor
229 virtual void ToggleInsetCursor(BufferView *);
231 virtual void GetCursorPos(int &, int &) const {}
233 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
235 virtual void InsetButtonRelease(BufferView *,
236 int x, int y, int button);
238 virtual void InsetKeyPress(XKeyEvent * ev);
240 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
242 virtual void InsetUnlock(BufferView *);
244 virtual void Edit(BufferView *, int x, int y, unsigned int button);
246 virtual void draw(Painter &, LyXFont const &,
247 int baseline, float & x) const;
249 virtual void SetFont(BufferView *, LyXFont const &,
250 bool toggleall = false);
252 virtual bool InsertInset(BufferView *, Inset *) { return false; }
254 virtual UpdatableInset * GetLockingInset() { return this; }
256 virtual int InsetInInsetY() { return 0; }
258 virtual bool UpdateInsetInInset(BufferView *, Inset *)
261 virtual bool UnlockInsetInInset(BufferView *, Inset *,
264 /// An updatable inset could handle lyx editing commands
265 virtual RESULT LocalDispatch(BufferView *, int, string const &);
267 virtual bool isCursorVisible() const { return cursor_visible; }
269 virtual int getMaxWidth(Painter & pain) const;
271 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
273 virtual UpdatableInset * owner() { return owner_; }
277 // virtual void UpdateLocal(bool flag=true);
280 mutable int top_baseline;
281 mutable bool cursor_visible;
288 UpdatableInset * owner_;