2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 the LyX Team.
9 * ====================================================== */
37 /** This is not quite the correct place for this enum. I think
38 the correct would be to let each subclass of Inset declare
39 its own enum code. Actually the notion of an Inset::Code
40 should be avoided, but I am not sure how this could be done
46 TOC_CODE, // do these insets really need a code? (ale)
108 Inset() { owner_ = 0; top_x = top_baseline = 0; }
112 virtual int ascent(Painter &, LyXFont const &) const = 0;
114 virtual int descent(Painter &, LyXFont const &) const = 0;
116 virtual int width(Painter &, LyXFont const &) const = 0;
118 virtual void draw(Painter &, LyXFont const &,
119 int baseline, float & x) const = 0;
121 virtual LyXFont ConvertFont(LyXFont font);
122 /// what appears in the minibuffer when opening
123 virtual const char * EditMessage() const;
125 virtual void Edit(BufferView *, int x, int y, unsigned int button);
127 virtual EDITABLE Editable() const;
128 /// This is called when the user clicks inside an inset
129 virtual void InsetButtonPress(BufferView *, int, int, int) {}
130 /// This is called when the user releases the button inside an inset
131 virtual void InsetButtonRelease(BufferView *, int, int, int) {}
132 /// This is caleld when the user moves the mouse inside an inset
133 virtual void InsetMotionNotify(BufferView *, int , int , int) {}
135 bool IsTextInset() const;
137 virtual bool AutoDelete() const;
139 virtual void Write(Buffer const *, std::ostream &) const = 0;
141 virtual void Read(Buffer const *, LyXLex & lex) = 0;
142 /** returns the number of rows (\n's) of generated tex code.
143 fragile == true means, that the inset should take care about
144 fragile commands by adding a \protect before.
145 If the free_spc (freespacing) variable is set, then this inset
146 is in a free-spacing paragraph.
148 virtual int Latex(Buffer const *, std::ostream &, bool fragile,
149 bool free_spc) const = 0;
151 virtual int Ascii(Buffer const *, std::ostream &) const = 0;
153 virtual int Linuxdoc(Buffer const *, std::ostream &) const = 0;
155 virtual int DocBook(Buffer const *, std::ostream &) const = 0;
156 /// Updates needed features for this inset.
157 virtual void Validate(LaTeXFeatures & features) const;
159 virtual bool Deletable() const;
161 /// returns LyX code associated with the inset. Used for TOC, ...)
162 virtual Inset::Code LyxCode() const { return NO_CODE; }
164 virtual std::vector<string> getLabelList() const {
165 return std::vector<string>();
169 virtual Inset * Clone() const = 0;
171 /// returns true to override begin and end inset in file
172 virtual bool DirectWrite() const;
174 /// Returns true if the inset should be centered alone
175 virtual bool display() const { return false; }
176 /// Changes the display state of the inset
177 virtual void display(bool) {}
179 virtual bool InsertInsetAllowed(Inset *) const { return false; }
181 virtual void setInsetName(const char * s) { name = s; }
183 virtual string getInsetName() const { return name; }
185 virtual void setOwner(Inset * inset) { owner_ = inset; }
187 virtual Inset * owner() const { return owner_; }
189 int x() const { return top_x; }
191 int y() const { return top_baseline; }
196 mutable int top_baseline;
206 // Updatable Insets. These insets can be locked and receive
207 // directly user interaction. Currently used only for mathed.
208 // Note that all pure methods from Inset class are pure here too.
209 // [Alejandro 080596]
211 /** Extracted from Matthias notes:
213 * An inset can simple call LockInset in it's edit call and *ONLY*
216 * Unlocking is either done by LyX or the inset itself with a
219 * During the lock, all button and keyboard events will be modified
220 * and send to the inset through the following inset-features. Note that
221 * Inset::InsetUnlock will be called from inside UnlockInset. It is meant
222 * to contain the code for restoring the menus and things like this.
224 * If a inset wishes any redraw and/or update it just has to call
227 * It's is completly irrelevant, where the inset is. UpdateInset will
228 * find it in any paragraph in any buffer.
229 * Of course the_locking_inset and the insets in the current paragraph/buffer
230 * are checked first, so no performance problem should occur.
232 class UpdatableInset: public Inset {
234 /** Dispatch result codes
235 Now that nested updatable insets are allowed, the local dispatch
236 becomes a bit complex, just two possible results (boolean)
239 DISPATCHED = the inset catched the action
240 DISPATCHED_NOUPDATE = the inset catched the action and no update
241 is needed here to redraw the inset
242 FINISHED = the inset must be unlocked as a result
244 UNDISPATCHED = the action was not catched, it should be
245 dispatched by lower level insets
254 /// To convert old binary dispatch results
255 RESULT DISPATCH_RESULT(bool b) {
256 return b ? DISPATCHED : FINISHED;
260 UpdatableInset() { scx = mx_scx = 0; }
262 //virtual ~UpdatableInset() {}
264 virtual EDITABLE Editable() const;
266 /// may call ToggleLockedInsetCursor
267 virtual void ToggleInsetCursor(BufferView *);
269 virtual void ShowInsetCursor(BufferView *);
271 virtual void HideInsetCursor(BufferView *);
273 virtual void GetCursorPos(int &, int &) const {}
275 virtual void InsetButtonPress(BufferView *, int x, int y, int button);
277 virtual void InsetButtonRelease(BufferView *,
278 int x, int y, int button);
280 virtual void InsetKeyPress(XKeyEvent * ev);
282 virtual void InsetMotionNotify(BufferView *, int x, int y, int state);
284 virtual void InsetUnlock(BufferView *);
286 virtual void Edit(BufferView *, int x, int y, unsigned int button);
288 virtual void draw(Painter &, LyXFont const &,
289 int baseline, float & x) const;
291 virtual void SetFont(BufferView *, LyXFont const &,
292 bool toggleall = false);
294 virtual bool InsertInset(BufferView *, Inset *) { return false; }
296 virtual bool InsertInsetAllowed(Inset *) const { return true; }
298 virtual UpdatableInset * GetLockingInset() { return this; }
300 virtual UpdatableInset * GetFirstLockingInsetOfType(Inset::Code c)
301 { return (c == LyxCode()) ? this : 0; }
303 virtual int InsetInInsetY() { return 0; }
305 virtual bool UpdateInsetInInset(BufferView *, Inset *)
308 virtual bool LockInsetInInset(BufferView *, UpdatableInset *)
311 virtual bool UnlockInsetInInset(BufferView *, UpdatableInset *,
314 /// An updatable inset could handle lyx editing commands
315 virtual RESULT LocalDispatch(BufferView *, int, string const &);
317 virtual bool isCursorVisible() const { return cursor_visible; }
319 virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
323 mutable bool cursor_visible;