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)
91 virtual int ascent(Painter &, LyXFont const &) const = 0;
93 virtual int descent(Painter &, LyXFont const &) const = 0;
95 virtual int width(Painter &, LyXFont const &) const = 0;
97 virtual void draw(Painter &, LyXFont const &,
98 int baseline, float & x) const = 0;
100 virtual LyXFont ConvertFont(LyXFont font);
101 /// what appears in the minibuffer when opening
102 virtual const char * EditMessage() const {return _("Opened inset");}
104 virtual void Edit(BufferView *, int x, int y, unsigned int button);
106 virtual unsigned char Editable() const;
108 virtual bool AutoDelete() const;
110 virtual void Write(ostream &) const = 0;
112 virtual void Read(LyXLex & lex) = 0;
113 /** returns the number of rows (\n's) of generated tex code.
114 fragile != 0 means, that the inset should take care about
115 fragile commands by adding a \protect before.
117 virtual int Latex(ostream &, signed char fragile) const = 0;
118 #ifndef USE_OSTREAM_ONLY
120 virtual int Latex(string & file, signed char fragile) const = 0;
122 virtual int Linuxdoc(string & /*file*/) const = 0;
124 virtual int DocBook(string & /*file*/) const = 0;
127 virtual int Linuxdoc(ostream &) const = 0;
129 virtual int DocBook(ostream &) const = 0;
131 /// Updates needed features for this inset.
132 virtual void Validate(LaTeXFeatures & features) const;
134 virtual bool Deletable() const;
136 /// returns LyX code associated with the inset. Used for TOC, ...)
137 virtual Inset::Code LyxCode() const = 0;
139 /// Get the label that appears at screen
140 virtual string getLabel(int) const {
145 virtual Inset * Clone() const = 0;
147 /// returns true to override begin and end inset in file
148 virtual bool DirectWrite() const;
150 /// Returns true if the inset should be centered alone
151 virtual bool display() const { return false; }
152 /// Changes the display state of the inset
153 virtual void display(bool) {}
155 virtual int GetNumberOfLabels() const {
159 virtual void init(BufferView *) {}
164 // Updatable Insets. These insets can be locked and receive
165 // directly user interaction. Currently used only for mathed.
166 // Note that all pure methods from Inset class are pure here too.
167 // [Alejandro 080596]
169 /** Extracted from Matthias notes:
171 * An inset can simple call LockInset in it's edit call and *ONLY*
174 * Unlocking is either done by LyX or the inset itself with a
177 * During the lock, all button and keyboard events will be modified
178 * and send to the inset through the following inset-features. Note that
179 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
180 * to contain the code for restoring the menus and things like this.
182 * If a inset wishes any redraw and/or update it just has to call
185 * It's is completly irrelevant, where the inset is. UpdateInset will
186 * find it in any paragraph in any buffer.
187 * Of course the_locking_inset and the insets in the current paragraph/buffer
188 * are checked first, so no performance problem should occur.
190 class UpdatableInset: public Inset {
192 /** Dispatch result codes
193 Now that nested updatable insets are allowed, the local dispatch
194 becomes a bit complex, just two possible results (boolean)
197 DISPATCHED = the inset catched the action
198 FINISHED = the inset must be unlocked as a result
200 UNDISPATCHED = the action was not catched, it should be
201 dispatched by lower level insets
209 /// To convert old binary dispatch results
210 RESULT DISPATCH_RESULT(bool b) {
211 return b ? DISPATCHED : FINISHED;
215 UpdatableInset() { scx = mx_scx = 0; }
217 //virtual ~UpdatableInset() {}
219 virtual unsigned char Editable() const;
221 /// may call ToggleLockedInsetCursor
222 virtual void ToggleInsetCursor(BufferView *);
224 virtual void GetCursorPos(int &, int &) const {}
226 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
228 virtual void InsetButtonRelease(BufferView *,
229 int x, int y, int button);
231 virtual void InsetKeyPress(XKeyEvent * ev);
233 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
235 virtual void InsetUnlock(BufferView *);
237 virtual void Edit(BufferView *, int x, int y, unsigned int button);
239 virtual void draw(Painter &, LyXFont const &,
240 int baseline, float & x) const;
242 virtual void SetFont(BufferView *, LyXFont const &,
243 bool toggleall = false);
245 virtual bool InsertInset(BufferView *, Inset *) { return false; }
247 virtual UpdatableInset * GetLockingInset() { return this; }
249 virtual int InsetInInsetY() { return 0; }
251 virtual bool UpdateInsetInInset(BufferView *, Inset *)
254 virtual bool UnlockInsetInInset(BufferView *, Inset *,
257 /// An updatable inset could handle lyx editing commands
258 virtual RESULT LocalDispatch(BufferView *, int, string const &);
260 virtual bool isCursorVisible() const { return cursor_visible; }
262 virtual int getMaxWidth(UpdatableInset *) const { return -1; }
265 // virtual void UpdateLocal(bool flag=true);
268 mutable int top_baseline;
269 mutable bool cursor_visible;