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 * ====================================================== */
29 #define USE_OSTREAM_ONLY 1
34 /** This is not quite the correct place for this enum. I think
35 the correct would be to let each subclass of Inset declare
36 its own enum code. Actually the notion of an Inset::Code
37 should be avoided, but I am not sure how this could be done
43 TOC_CODE, // do these insets really need a code? (ale)
101 virtual int ascent(Painter &, LyXFont const &) const = 0;
103 virtual int descent(Painter &, LyXFont const &) const = 0;
105 virtual int width(Painter &, LyXFont const &) const = 0;
107 virtual void draw(Painter &, LyXFont const &,
108 int baseline, float & x) const = 0;
110 virtual LyXFont ConvertFont(LyXFont font);
111 /// what appears in the minibuffer when opening
112 virtual const char * EditMessage() const {return _("Opened inset");}
114 virtual void Edit(BufferView *, int x, int y, unsigned int button);
116 virtual EDITABLE Editable() const;
118 virtual bool AutoDelete() const;
120 virtual void Write(ostream &) const = 0;
122 virtual void Read(LyXLex & lex) = 0;
123 /** returns the number of rows (\n's) of generated tex code.
124 fragile != 0 means, that the inset should take care about
125 fragile commands by adding a \protect before.
126 If the freee_spc (freespacing) variable is set, then this inset
127 is in a free-spacing paragraph.
129 virtual int Latex(ostream &, signed char fragile, bool free_spc) const = 0;
131 #ifndef USE_OSTREAM_ONLY
133 virtual int Latex(string & file, signed char fragile, bool free_spc) const = 0;
135 virtual int Linuxdoc(string & /*file*/) const = 0;
137 virtual int DocBook(string & /*file*/) const = 0;
140 virtual int Linuxdoc(ostream &) const = 0;
142 virtual int DocBook(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 = 0;
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 *) {}
177 // Updatable Insets. These insets can be locked and receive
178 // directly user interaction. Currently used only for mathed.
179 // Note that all pure methods from Inset class are pure here too.
180 // [Alejandro 080596]
182 /** Extracted from Matthias notes:
184 * An inset can simple call LockInset in it's edit call and *ONLY*
187 * Unlocking is either done by LyX or the inset itself with a
190 * During the lock, all button and keyboard events will be modified
191 * and send to the inset through the following inset-features. Note that
192 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
193 * to contain the code for restoring the menus and things like this.
195 * If a inset wishes any redraw and/or update it just has to call
198 * It's is completly irrelevant, where the inset is. UpdateInset will
199 * find it in any paragraph in any buffer.
200 * Of course the_locking_inset and the insets in the current paragraph/buffer
201 * are checked first, so no performance problem should occur.
203 class UpdatableInset: public Inset {
205 /** Dispatch result codes
206 Now that nested updatable insets are allowed, the local dispatch
207 becomes a bit complex, just two possible results (boolean)
210 DISPATCHED = the inset catched the action
211 FINISHED = the inset must be unlocked as a result
213 UNDISPATCHED = the action was not catched, it should be
214 dispatched by lower level insets
222 /// To convert old binary dispatch results
223 RESULT DISPATCH_RESULT(bool b) {
224 return b ? DISPATCHED : FINISHED;
233 //virtual ~UpdatableInset() {}
235 virtual EDITABLE Editable() const;
237 /// may call ToggleLockedInsetCursor
238 virtual void ToggleInsetCursor(BufferView *);
240 virtual void GetCursorPos(int &, int &) const {}
242 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
244 virtual void InsetButtonRelease(BufferView *,
245 int x, int y, int button);
247 virtual void InsetKeyPress(XKeyEvent * ev);
249 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
251 virtual void InsetUnlock(BufferView *);
253 virtual void Edit(BufferView *, int x, int y, unsigned int button);
255 virtual void draw(Painter &, LyXFont const &,
256 int baseline, float & x) const;
258 virtual void SetFont(BufferView *, LyXFont const &,
259 bool toggleall = false);
261 virtual bool InsertInset(BufferView *, Inset *) { return false; }
263 virtual UpdatableInset * GetLockingInset() { return this; }
265 virtual int InsetInInsetY() { return 0; }
267 virtual bool UpdateInsetInInset(BufferView *, Inset *)
270 virtual bool UnlockInsetInInset(BufferView *, Inset *,
273 /// An updatable inset could handle lyx editing commands
274 virtual RESULT LocalDispatch(BufferView *, int, string const &);
276 virtual bool isCursorVisible() const { return cursor_visible; }
278 virtual int getMaxWidth(Painter & pain) const;
280 virtual void setOwner(UpdatableInset * inset) { owner_ = inset; }
282 virtual UpdatableInset * owner() { return owner_; }
286 // virtual void UpdateLocal(bool flag=true);
289 mutable int top_baseline;
290 mutable bool cursor_visible;
297 UpdatableInset * owner_;