2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2001 the LyX Team.
9 * ====================================================== */
21 #include "commandtags.h"
39 /** This is not quite the correct place for this enum. I think
40 the correct would be to let each subclass of Inset declare
41 its own enum code. Actually the notion of an Inset::Code
42 should be avoided, but I am not sure how this could be done
48 TOC_CODE, // do these insets really need a code? (ale)
94 SPECIALCHAR_CODE, // 25
106 MATHMACRO_CODE, // 30
120 TEXT_TO_INSET_OFFSET = 2
136 Inset(Inset const & in, bool same_id = false);
140 virtual int ascent(BufferView *, LyXFont const &) const = 0;
142 virtual int descent(BufferView *, LyXFont const &) const = 0;
144 virtual int width(BufferView *, LyXFont const &) const = 0;
146 virtual void draw(BufferView *, LyXFont const &,
147 int baseline, float & x, bool cleared) const = 0;
148 /// update the inset representation
149 virtual void update(BufferView *, LyXFont const &, bool = false)
152 virtual LyXFont const convertFont(LyXFont const & font) const;
153 /// what appears in the minibuffer when opening
154 virtual string const editMessage() const;
156 virtual void edit(BufferView *, int x, int y, unsigned int button);
158 virtual void edit(BufferView *, bool front = true);
160 virtual EDITABLE editable() const;
161 /// This is called when the user clicks inside an inset
162 virtual void insetButtonPress(BufferView *, int, int, int) {}
163 /// This is called when the user releases the button inside an inset
164 virtual void insetButtonRelease(BufferView *, int, int, int) {}
165 /// This is called when the user moves the mouse inside an inset
166 virtual void insetMotionNotify(BufferView *, int , int , int) {}
168 virtual bool isTextInset() const { return false; }
170 virtual bool doClearArea() const { return true; }
172 virtual bool autoDelete() const;
173 /// returns true the inset can hold an inset of given type
174 virtual bool insetAllowed(Inset::Code) const { return false; }
175 /// wrapper around the above
176 bool insetAllowed(Inset * in) const;
178 virtual void write(Buffer const *, std::ostream &) const = 0;
180 virtual void read(Buffer const *, LyXLex & lex) = 0;
181 /** returns the number of rows (\n's) of generated tex code.
182 fragile == true means, that the inset should take care about
183 fragile commands by adding a \protect before.
184 If the free_spc (freespacing) variable is set, then this inset
185 is in a free-spacing paragraph.
187 virtual int latex(Buffer const *, std::ostream &, bool fragile,
188 bool free_spc) const = 0;
190 virtual int ascii(Buffer const *,
191 std::ostream &, int linelen = 0) const = 0;
193 virtual int linuxdoc(Buffer const *, std::ostream &) const = 0;
195 virtual int docBook(Buffer const *, std::ostream &) const = 0;
196 /// Updates needed features for this inset.
197 virtual void validate(LaTeXFeatures & features) const;
199 virtual bool deletable() const;
201 /// returns LyX code associated with the inset. Used for TOC, ...)
202 virtual Inset::Code lyxCode() const { return NO_CODE; }
204 virtual std::vector<string> const getLabelList() const {
205 return std::vector<string>();
209 virtual Inset * clone(Buffer const &, bool same_ids = false) const = 0;
211 /// returns true to override begin and end inset in file
212 virtual bool directWrite() const;
214 /// Returns true if the inset should be centered alone
215 virtual bool display() const { return false; }
216 /// Changes the display state of the inset
217 virtual void display(bool) {}
219 /// returns true if this inset needs a row on it's own
221 virtual bool needFullRow() const { return false; }
223 void setInsetName(string const & s) { name_ = s; }
225 string const & getInsetName() const { return name_; }
227 void setOwner(Inset * inset) { owner_ = inset; }
229 Inset * owner() const { return owner_; }
231 void setBackgroundColor(LColor::color);
233 LColor::color backgroundColor() const;
235 int x() const { return top_x; }
237 int y() const { return top_baseline; }
239 // because we could have fake text insets and have to call this
240 // inside them without cast!!!
242 virtual LyXText * getLyXText(BufferView const *,
243 bool const recursive = false) const;
245 virtual void deleteLyXText(BufferView *, bool = true) const {}
247 virtual void resizeLyXText(BufferView *, bool /*force*/= false) const {}
248 /// returns the actuall scroll-value
249 virtual int scroll(bool recursive=true) const {
250 if (!recursive || !owner_)
254 /// try to get a paragraph pointer from it's id if we have a
255 /// paragraph to give back!
256 virtual Paragraph * getParFromID(int /* id */) const {
259 /// try to get a inset pointer from it's id if we have
260 /// an inset to give back!
261 virtual Inset * getInsetFromID(int /* id */) const {
264 /// if this insets owns paragraphs (f.ex. InsetText) then it
265 /// should return it's very first one!
266 virtual Paragraph * firstParagraph() const {
269 /// return the cursor if we own one otherwise giv'em just the
270 /// BufferView cursor to work with.
271 virtual LyXCursor const & cursor(BufferView * bview) const;
277 /// used to toggle insets
278 // is the inset open?
279 virtual bool isOpen() const { return false; }
281 virtual void open(BufferView *) {}
283 virtual void close(BufferView *) {}
284 /// check if the font of the char we want inserting is correct
285 /// and modify it if it is not.
286 virtual bool checkInsertChar(LyXFont &);
291 mutable int top_baseline;
297 static unsigned int inset_id;
305 LColor::color background_color_;
310 bool Inset::insetAllowed(Inset * in) const
312 return insetAllowed(in->lyxCode());
317 bool Inset::checkInsertChar(LyXFont &)
322 // Updatable Insets. These insets can be locked and receive
323 // directly user interaction. Currently used only for mathed.
324 // Note that all pure methods from Inset class are pure here too.
325 // [Alejandro 080596]
327 /** Extracted from Matthias notes:
329 * An inset can simple call LockInset in it's edit call and *ONLY*
332 * Unlocking is either done by LyX or the inset itself with a
335 * During the lock, all button and keyboard events will be modified
336 * and send to the inset through the following inset-features. Note that
337 * Inset::insetUnlock will be called from inside UnlockInset. It is meant
338 * to contain the code for restoring the menus and things like this.
340 * If a inset wishes any redraw and/or update it just has to call
343 * It's is completly irrelevant, where the inset is. UpdateInset will
344 * find it in any paragraph in any buffer.
345 * Of course the_locking_inset and the insets in the current paragraph/buffer
346 * are checked first, so no performance problem should occur.
348 class UpdatableInset : public Inset {
350 /** Dispatch result codes
351 Now that nested updatable insets are allowed, the local dispatch
352 becomes a bit complex, just two possible results (boolean)
355 DISPATCHED = the inset catched the action
356 DISPATCHED_NOUPDATE = the inset catched the action and no update
357 is needed here to redraw the inset
358 FINISHED = the inset must be unlocked as a result
360 UNDISPATCHED = the action was not catched, it should be
361 dispatched by lower level insets
370 /// To convert old binary dispatch results
371 RESULT DISPATCH_RESULT(bool b) {
372 return b ? DISPATCHED : FINISHED;
378 UpdatableInset(UpdatableInset const & in, bool same_id = false);
381 virtual EDITABLE editable() const;
383 /// may call ToggleLockedInsetCursor
384 virtual void toggleInsetCursor(BufferView *);
386 virtual void showInsetCursor(BufferView *, bool show = true);
388 virtual void hideInsetCursor(BufferView *);
390 virtual void fitInsetCursor(BufferView *) const;
392 virtual void getCursorPos(BufferView *, int &, int &) const {}
394 virtual void insetButtonPress(BufferView *, int x, int y, int button);
396 virtual void insetButtonRelease(BufferView *,
397 int x, int y, int button);
399 virtual void insetKeyPress(XKeyEvent * ev);
401 virtual void insetMotionNotify(BufferView *, int x, int y, int state);
403 virtual void insetUnlock(BufferView *);
405 virtual void edit(BufferView *, int x, int y, unsigned int button);
407 virtual void edit(BufferView *, bool front = true);
409 virtual void draw(BufferView *, LyXFont const &,
410 int baseline, float & x, bool cleared) const;
412 virtual void setFont(BufferView *, LyXFont const &,
413 bool toggleall = false, bool selectall = false);
415 virtual bool insertInset(BufferView *, Inset *) { return false; }
417 virtual UpdatableInset * getLockingInset() const {
418 return const_cast<UpdatableInset *>(this);
421 virtual UpdatableInset * getFirstLockingInsetOfType(Inset::Code c)
422 { return (c == lyxCode()) ? this : 0; }
424 virtual unsigned int insetInInsetY() { return 0; }
426 virtual bool updateInsetInInset(BufferView *, Inset *)
429 virtual bool lockInsetInInset(BufferView *, UpdatableInset *)
432 virtual bool unlockInsetInInset(BufferView *, UpdatableInset *,
435 /// An updatable inset could handle lyx editing commands
436 virtual RESULT localDispatch(BufferView *, kb_action, string const &);
438 bool isCursorVisible() const { return cursor_visible_; }
440 virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
442 int scroll(bool recursive = true) const {
443 // We need this method to not clobber the real method in Inset
444 return Inset::scroll(recursive);
447 virtual bool showInsetDialog(BufferView *) const { return false; }
449 virtual void nodraw(bool b) {
453 virtual bool nodraw() const {
454 return block_drawing_;
457 // needed for spellchecking text
459 virtual string const selectNextWord(BufferView *, float & value) const;
461 virtual void selectSelectedWord(BufferView *) { return; }
463 virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {
467 // needed for search/replace functionality
469 virtual bool searchForward(BufferView *, string const &,
470 bool const & = true, bool const & = false);
472 virtual bool searchBackward(BufferView *, string const &,
473 bool const & = true, bool const & = false);
477 void toggleCursorVisible() const {
478 cursor_visible_ = !cursor_visible_;
481 void setCursorVisible(bool b) const {
484 /// scrolls to absolute position in bufferview-workwidth * sx units
485 void scroll(BufferView *, float sx) const;
486 /// scrolls offset pixels
487 void scroll(BufferView *, int offset) const;
491 mutable bool cursor_visible_;