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;
123 virtual int Linuxdoc(string & /*file*/) const = 0;
125 virtual int DocBook(string & /*file*/) const = 0;
126 /// Updates needed features for this inset.
127 virtual void Validate(LaTeXFeatures & features) const;
129 virtual bool Deletable() const;
131 /// returns LyX code associated with the inset. Used for TOC, ...)
132 virtual Inset::Code LyxCode() const = 0;
134 /// Get the label that appears at screen
135 virtual string getLabel(int) const {
140 virtual Inset * Clone() const = 0;
142 /// returns true to override begin and end inset in file
143 virtual bool DirectWrite() const;
145 /// Returns true if the inset should be centered alone
146 virtual bool display() const { return false; }
147 /// Changes the display state of the inset
148 virtual void display(bool) {}
150 virtual int GetNumberOfLabels() const {
154 virtual void init(BufferView *) {}
159 // Updatable Insets. These insets can be locked and receive
160 // directly user interaction. Currently used only for mathed.
161 // Note that all pure methods from Inset class are pure here too.
162 // [Alejandro 080596]
164 /** Extracted from Matthias notes:
166 * An inset can simple call LockInset in it's edit call and *ONLY*
169 * Unlocking is either done by LyX or the inset itself with a
172 * During the lock, all button and keyboard events will be modified
173 * and send to the inset through the following inset-features. Note that
174 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
175 * to contain the code for restoring the menus and things like this.
177 * If a inset wishes any redraw and/or update it just has to call
180 * It's is completly irrelevant, where the inset is. UpdateInset will
181 * find it in any paragraph in any buffer.
182 * Of course the_locking_inset and the insets in the current paragraph/buffer
183 * are checked first, so no performance problem should occur.
185 class UpdatableInset: public Inset {
187 /** Dispatch result codes
188 Now that nested updatable insets are allowed, the local dispatch
189 becomes a bit complex, just two possible results (boolean)
192 DISPATCHED = the inset catched the action
193 FINISHED = the inset must be unlocked as a result
195 UNDISPATCHED = the action was not catched, it should be
196 dispatched by lower level insets
204 /// To convert old binary dispatch results
205 RESULT DISPATCH_RESULT(bool b) {
206 return (b) ? DISPATCHED: FINISHED;
210 UpdatableInset() { scx = mx_scx = 0; }
212 //virtual ~UpdatableInset() {}
214 virtual unsigned char Editable() const;
216 /// may call ToggleLockedInsetCursor
217 virtual void ToggleInsetCursor(BufferView *);
219 virtual void GetCursorPos(int &, int &) const {}
221 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
223 virtual void InsetButtonRelease(BufferView *,
224 int x, int y, int button);
226 virtual void InsetKeyPress(XKeyEvent * ev);
228 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
230 virtual void InsetUnlock(BufferView *);
232 virtual void Edit(BufferView *, int x, int y, unsigned int button);
234 virtual void draw(Painter &, LyXFont const &,
235 int baseline, float & x) const;
237 virtual void SetFont(BufferView *, LyXFont const &, bool toggleall=false);
239 virtual bool InsertInset(BufferView *, Inset *) { return false; }
241 virtual UpdatableInset * GetLockingInset() { return this; }
243 virtual int InsetInInsetY() { return 0; }
245 virtual bool UpdateInsetInInset(BufferView *, Inset *)
248 virtual bool UnlockInsetInInset(BufferView *, Inset *,
251 /// An updatable inset could handle lyx editing commands
252 virtual RESULT LocalDispatch(BufferView *, int, string const &);
254 virtual bool isCursorVisible() const { return cursor_visible; }
256 virtual int getMaxWidth(UpdatableInset *) const { return -1; }
259 // virtual void UpdateLocal(bool flag=true);
262 mutable int top_baseline;
263 mutable bool cursor_visible;