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)
89 virtual int ascent(Painter &, LyXFont const &) const = 0;
91 virtual int descent(Painter &, LyXFont const &) const = 0;
93 virtual int width(Painter &, LyXFont const &) const = 0;
95 virtual void draw(Painter &, LyXFont const &,
96 int baseline, float & x) const = 0;
98 virtual LyXFont ConvertFont(LyXFont font);
99 /// what appears in the minibuffer when opening
100 virtual const char * EditMessage() const {return _("Opened inset");}
102 virtual void Edit(BufferView *, int x, int y, unsigned int button);
104 virtual unsigned char Editable() const;
106 virtual bool AutoDelete() const;
108 virtual void Write(ostream &) const = 0;
110 virtual void Read(LyXLex & lex) = 0;
111 /** returns the number of rows (\n's) of generated tex code.
112 fragile != 0 means, that the inset should take care about
113 fragile commands by adding a \protect before.
115 virtual int Latex(ostream &, signed char fragile) const = 0;
117 virtual int Latex(string & file, signed char fragile) const = 0;
119 virtual int Linuxdoc(string & /*file*/) const = 0;
121 virtual int DocBook(string & /*file*/) const = 0;
122 /// Updates needed features for this inset.
123 virtual void Validate(LaTeXFeatures & features) const;
125 virtual bool Deletable() const;
127 /// returns LyX code associated with the inset. Used for TOC, ...)
128 virtual Inset::Code LyxCode() const = 0;
130 /// Get the label that appears at screen
131 virtual string getLabel(int) const {
136 virtual Inset * Clone() const = 0;
138 /// returns true to override begin and end inset in file
139 virtual bool DirectWrite() const;
141 /// Returns true if the inset should be centered alone
142 virtual bool display() const { return false; }
143 /// Changes the display state of the inset
144 virtual void display(bool) {}
146 virtual int GetNumberOfLabels() const {
150 virtual void init(BufferView *) {}
155 // Updatable Insets. These insets can be locked and receive
156 // directly user interaction. Currently used only for mathed.
157 // Note that all pure methods from Inset class are pure here too.
158 // [Alejandro 080596]
160 /** Extracted from Matthias notes:
162 * An inset can simple call LockInset in it's edit call and *ONLY*
165 * Unlocking is either done by LyX or the inset itself with a
168 * During the lock, all button and keyboard events will be modified
169 * and send to the inset through the following inset-features. Note that
170 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
171 * to contain the code for restoring the menus and things like this.
173 * If a inset wishes any redraw and/or update it just has to call
176 * It's is completly irrelevant, where the inset is. UpdateInset will
177 * find it in any paragraph in any buffer.
178 * Of course the_locking_inset and the insets in the current paragraph/buffer
179 * are checked first, so no performance problem should occur.
181 class UpdatableInset: public Inset {
183 /** Dispatch result codes
184 Now that nested updatable insets are allowed, the local dispatch
185 becomes a bit complex, just two possible results (boolean)
188 DISPATCHED = the inset catched the action
189 FINISHED = the inset must be unlocked as a result
191 UNDISPATCHED = the action was not catched, it should be
192 dispatched by lower level insets
200 /// To convert old binary dispatch results
201 RESULT DISPATCH_RESULT(bool b) {
202 return (b) ? DISPATCHED: FINISHED;
206 //virtual ~UpdatableInset() {}
208 virtual unsigned char Editable() const;
210 /// may call ToggleLockedInsetCursor
211 virtual void ToggleInsetCursor(BufferView *);
213 virtual void GetCursorPos(int &, int &) const {}
215 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
217 virtual void InsetButtonRelease(BufferView *,
218 int x, int y, int button);
220 virtual void InsetKeyPress(XKeyEvent * ev);
222 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
224 virtual void InsetUnlock(BufferView *);
226 virtual void Edit(BufferView *, int x, int y, unsigned int button);
228 virtual void draw(Painter &, LyXFont const &,
229 int baseline, float & x) const;
231 virtual void SetFont(BufferView *, LyXFont const &, bool toggleall=false);
233 virtual bool InsertInset(BufferView *, Inset *) { return false; }
235 virtual UpdatableInset * GetLockingInset() { return this; }
237 virtual int InsetInInsetY() { return 0; }
239 virtual bool UpdateInsetInInset(BufferView *, Inset *)
242 virtual bool UnlockInsetInInset(BufferView *, Inset *,
245 /// An updatable inset could handle lyx editing commands
246 virtual RESULT LocalDispatch(BufferView *, int, string const &);
248 virtual bool isCursorVisible() const { return cursor_visible; }
250 virtual int getMaxWidth(UpdatableInset *) const { return -1; }
253 // virtual void UpdateLocal(bool flag=true);
256 mutable int top_baseline;
257 mutable bool cursor_visible;