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 * ====================================================== */
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)
107 virtual int ascent(Painter &, LyXFont const &) const = 0;
109 virtual int descent(Painter &, LyXFont const &) const = 0;
111 virtual int width(Painter &, LyXFont const &) const = 0;
113 virtual void draw(Painter &, LyXFont const &,
114 int baseline, float & x) const = 0;
116 virtual LyXFont ConvertFont(LyXFont font);
117 /// what appears in the minibuffer when opening
118 virtual const char * EditMessage() const;
120 virtual void Edit(BufferView *, int x, int y, unsigned int button);
122 virtual EDITABLE Editable() const;
124 bool IsTextInset() const;
126 virtual bool AutoDelete() const;
128 virtual void Write(std::ostream &) const = 0;
130 virtual void Read(LyXLex & lex) = 0;
131 /** returns the number of rows (\n's) of generated tex code.
132 fragile != 0 means, that the inset should take care about
133 fragile commands by adding a \protect before.
134 If the free_spc (freespacing) variable is set, then this inset
135 is in a free-spacing paragraph.
137 virtual int Latex(std::ostream &, signed char fragile,
138 bool free_spc) const = 0;
141 virtual int Linuxdoc(std::ostream &) const = 0;
143 virtual int DocBook(std::ostream &) const = 0;
144 /// Updates needed features for this inset.
145 virtual void Validate(LaTeXFeatures & features) const;
147 virtual bool Deletable() const;
149 /// returns LyX code associated with the inset. Used for TOC, ...)
150 virtual Inset::Code LyxCode() const { return NO_CODE; }
152 /// Get the label that appears at screen
153 virtual string getLabel(int) const {
158 virtual Inset * Clone() const = 0;
160 /// returns true to override begin and end inset in file
161 virtual bool DirectWrite() const;
163 /// Returns true if the inset should be centered alone
164 virtual bool display() const { return false; }
165 /// Changes the display state of the inset
166 virtual void display(bool) {}
168 virtual int GetNumberOfLabels() const {
172 virtual void init(BufferView *) {}
174 virtual bool InsertInsetAllowed(Inset *) const { return false; }
178 // Updatable Insets. These insets can be locked and receive
179 // directly user interaction. Currently used only for mathed.
180 // Note that all pure methods from Inset class are pure here too.
181 // [Alejandro 080596]
183 /** Extracted from Matthias notes:
185 * An inset can simple call LockInset in it's edit call and *ONLY*
188 * Unlocking is either done by LyX or the inset itself with a
191 * During the lock, all button and keyboard events will be modified
192 * and send to the inset through the following inset-features. Note that
193 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
194 * to contain the code for restoring the menus and things like this.
196 * If a inset wishes any redraw and/or update it just has to call
199 * It's is completly irrelevant, where the inset is. UpdateInset will
200 * find it in any paragraph in any buffer.
201 * Of course the_locking_inset and the insets in the current paragraph/buffer
202 * are checked first, so no performance problem should occur.
204 class UpdatableInset: public Inset {
206 /** Dispatch result codes
207 Now that nested updatable insets are allowed, the local dispatch
208 becomes a bit complex, just two possible results (boolean)
211 DISPATCHED = the inset catched the action
212 FINISHED = the inset must be unlocked as a result
214 UNDISPATCHED = the action was not catched, it should be
215 dispatched by lower level insets
223 /// To convert old binary dispatch results
224 RESULT DISPATCH_RESULT(bool b) {
225 return b ? DISPATCHED : FINISHED;
234 //virtual ~UpdatableInset() {}
236 virtual EDITABLE Editable() const;
238 /// may call ToggleLockedInsetCursor
239 virtual void ToggleInsetCursor(BufferView *);
241 virtual void GetCursorPos(int &, int &) const {}
243 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
245 virtual void InsetButtonRelease(BufferView *,
246 int x, int y, int button);
248 virtual void InsetKeyPress(XKeyEvent * ev);
250 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
252 virtual void InsetUnlock(BufferView *);
254 virtual void Edit(BufferView *, int x, int y, unsigned int button);
256 virtual void draw(Painter &, LyXFont const &,
257 int baseline, float & x) const;
259 virtual void SetFont(BufferView *, LyXFont const &,
260 bool toggleall = false);
262 virtual bool InsertInset(BufferView *, Inset *) { return false; }
264 virtual bool InsertInsetAllowed(Inset *) const { return true; }
266 virtual UpdatableInset * GetLockingInset() { return this; }
268 virtual int InsetInInsetY() { return 0; }
270 virtual bool UpdateInsetInInset(BufferView *, Inset *)
273 virtual bool UnlockInsetInInset(BufferView *, Inset *,
276 /// An updatable inset could handle lyx editing commands
277 virtual RESULT LocalDispatch(BufferView *, int, string const &);
279 virtual bool isCursorVisible() const { return cursor_visible; }
281 virtual int getMaxWidth(Painter & pain) const;
283 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
285 virtual UpdatableInset * owner() { return owner_; }
289 // virtual void UpdateLocal(bool flag=true);
292 mutable int top_baseline;
293 mutable bool cursor_visible;
300 UpdatableInset * owner_;