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 * ====================================================== */
32 /** This is not quite the correct place for this enum. I think
33 the correct would be to let each subclass of Inset declare
34 its own enum code. Actually the notion of an Inset::Code
35 should be avoided, but I am not sure how this could be done
41 TOC_CODE, // do these insets really need a code? (ale)
87 virtual int ascent(Painter &, LyXFont const &) const = 0;
89 virtual int descent(Painter &, LyXFont const &) const = 0;
91 virtual int width(Painter &, LyXFont const &) const = 0;
93 virtual void draw(Painter &, LyXFont const &,
94 int baseline, float & x) const = 0;
96 virtual LyXFont ConvertFont(LyXFont font);
97 /// what appears in the minibuffer when opening
98 virtual const char * EditMessage() const {return _("Opened inset");}
100 virtual void Edit(BufferView *, int x, int y, unsigned int button);
102 virtual unsigned char Editable() const;
104 virtual bool AutoDelete() const;
106 virtual void Write(ostream &) const = 0;
108 virtual void Read(LyXLex & lex) = 0;
109 /** returns the number of rows (\n's) of generated tex code.
110 fragile != 0 means, that the inset should take care about
111 fragile commands by adding a \protect before.
113 virtual int Latex(ostream &, signed char fragile) const = 0;
115 virtual int Latex(string & file, signed char fragile) const = 0;
117 virtual int Linuxdoc(string & /*file*/) const = 0;
119 virtual int DocBook(string & /*file*/) const = 0;
120 /// Updates needed features for this inset.
121 virtual void Validate(LaTeXFeatures & features) const;
123 virtual bool Deletable() const;
125 /// returns LyX code associated with the inset. Used for TOC, ...)
126 virtual Inset::Code LyxCode() const = 0;
128 /// Get the label that appears at screen
129 virtual string getLabel(int) const {
134 virtual Inset * Clone() const = 0;
136 /// returns true to override begin and end inset in file
137 virtual bool DirectWrite() const;
139 /// Returns true if the inset should be centered alone
140 virtual bool display() const { return false; }
141 /// Changes the display state of the inset
142 virtual void display(bool) {}
144 virtual int GetNumberOfLabels() const {
148 virtual void init(BufferView *) {}
153 // Updatable Insets. These insets can be locked and receive
154 // directly user interaction. Currently used only for mathed.
155 // Note that all pure methods from Inset class are pure here too.
156 // [Alejandro 080596]
158 /** Extracted from Matthias notes:
160 * An inset can simple call LockInset in it's edit call and *ONLY*
163 * Unlocking is either done by LyX or the inset itself with a
166 * During the lock, all button and keyboard events will be modified
167 * and send to the inset through the following inset-features. Note that
168 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
169 * to contain the code for restoring the menus and things like this.
171 * If a inset wishes any redraw and/or update it just has to call
174 * It's is completly irrelevant, where the inset is. UpdateInset will
175 * find it in any paragraph in any buffer.
176 * Of course the_locking_inset and the insets in the current paragraph/buffer
177 * are checked first, so no performance problem should occur.
179 class UpdatableInset: public Inset {
181 /** Dispatch result codes
182 Now that nested updatable insets are allowed, the local dispatch
183 becomes a bit complex, just two possible results (boolean)
186 DISPATCHED = the inset catched the action
187 FINISHED = the inset must be unlocked as a result
189 UNDISPATCHED = the action was not catched, it should be
190 dispatched by lower level insets
198 /// To convert old binary dispatch results
199 RESULT DISPATCH_RESULT(bool b) {
200 return (b) ? DISPATCHED: FINISHED;
204 //virtual ~UpdatableInset() {}
206 virtual unsigned char Editable() const;
208 /// may call ToggleLockedInsetCursor
209 virtual void ToggleInsetCursor(BufferView *);
211 virtual void GetCursorPos(int &, int &) const {}
213 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
215 virtual void InsetButtonRelease(BufferView *,
216 int x, int y, int button);
218 virtual void InsetKeyPress(XKeyEvent * ev);
220 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
222 virtual void InsetUnlock(BufferView *);
224 virtual void Edit(BufferView *, int x, int y, unsigned int button);
226 virtual void draw(Painter &, LyXFont const &,
227 int baseline, float & x) const;
229 virtual void SetFont(BufferView *, LyXFont const &, bool toggleall=false);
231 virtual bool InsertInset(BufferView *, Inset *) { return false; }
233 virtual UpdatableInset * GetLockingInset() { return this; }
235 virtual int InsetInInsetY() { return 0; }
237 virtual bool UpdateInsetInInset(BufferView *, Inset *)
240 virtual bool UnlockInsetInInset(BufferView *, Inset *,
243 /// An updatable inset could handle lyx editing commands
244 virtual RESULT LocalDispatch(BufferView *, int, string const &);
246 virtual bool isCursorVisible() const { return cursor_visible; }
248 virtual int getMaxWidth(UpdatableInset *) const { return -1; }
251 // virtual void UpdateLocal(bool flag=true);
254 mutable int top_baseline;
255 mutable bool cursor_visible;