]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.h
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / insettext.h
index 4d2c08985d4c060b58a36f2d92e085ca47be1443..c42a2d0bae9387b7fa4ac337290d29861aa0bb8e 100644 (file)
@@ -1,40 +1,42 @@
 // -*- C++ -*-
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *
- *           Copyright 1998 The LyX Team.
+/**
+ * \file insettext.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
+ * \author Jürgen Vigna
  *
- *======================================================
+ * Full author contact details are available in file CREDITS
  */
-// The pristine updatable inset: Text
-
 
 #ifndef INSETTEXT_H
 #define INSETTEXT_H
 
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "lyxinset.h"
+#include "updatableinset.h"
 #include "LString.h"
-#include "lyxcursor.h"
+#include "LColor.h"
+#include "ParagraphList.h"
+#include "RowList.h"
+#include "dimension.h"
+#include "frontends/mouse_state.h"
+
+#include "support/types.h"
+
+#include <boost/shared_ptr.hpp>
+#include <map>
 
 class Painter;
 class BufferView;
 class Buffer;
+class BufferParams;
 class LyXCursor;
-class LyXParagraph;
-class LColor;
 class LyXText;
-class LyXScreen;
+class Row;
+class Paragraph;
 
 /**
  A text inset is like a TeX box to write full text
- (including styles and other insets) in a given space. 
+ (including styles and other insets) in a given space.
  @author: Jürgen Vigna
  */
 class InsetText : public UpdatableInset {
@@ -48,17 +50,15 @@ public:
                ///
                CURSOR = 1,
                ///
-               CLEAR_FRAME = 2,
-               ///
-               DRAW_FRAME = 4,
+               DRAW_FRAME = 2,
                ///
-               SELECTION = 8,
+               SELECTION = 4,
                ///
-               CURSOR_PAR = 16,
+               CURSOR_PAR = 8,
                ///
-               FULL = 32,
+               FULL = 16,
                ///
-               INIT = 64
+               INIT = 32
        };
        ///
        enum DrawFrame {
@@ -70,133 +70,187 @@ public:
                ALWAYS
        };
        ///
-       InsetText();
+       InsetText(BufferParams const &);
        ///
        explicit
-       InsetText(InsetText const &);
+       InsetText(InsetText const &, bool same_id = false);
        ///
        ~InsetText();
        ///
-       Inset * Clone(Buffer const &) const;
+       Inset * clone(Buffer const &, bool same_id = false) const;
        ///
        InsetText & operator=(InsetText const & it);
+       /// empty inset to empty par, or just mark as erased
+       void clear(bool just_mark_erased);
        ///
-       void clear();
+       void read(Buffer const *, LyXLex &);
        ///
-       void Read(Buffer const *, LyXLex &);
+       void write(Buffer const *, std::ostream &) const;
        ///
-       void Write(Buffer const *, std::ostream &) const;
+       void dimension(BufferView *, LyXFont const &, Dimension &) const;
        ///
-       int ascent(BufferView *, LyXFont const &) const;
+       int textWidth(BufferView *, bool fordraw = false) const;
        ///
-       int descent(BufferView *, LyXFont const &) const;
+       void draw(BufferView *, LyXFont const &, int , float &) const;
        ///
-       int width(BufferView *, LyXFont const & f) const;
+       void update(BufferView *, bool = false);
        ///
-       int textWidth(BufferView *) const;
+       void setUpdateStatus(BufferView *, int what) const;
        ///
-       void draw(BufferView *, LyXFont const &, int , float &, bool) const;
+       string const editMessage() const;
        ///
-       void update(BufferView *, LyXFont const &, bool =false);
+       bool isTextInset() const { return true; }
        ///
-       void SetUpdateStatus(BufferView *, int what) const;
+       void insetUnlock(BufferView *);
        ///
-       string const EditMessage() const;
+       bool lockInsetInInset(BufferView *, UpdatableInset *);
        ///
-       void Edit(BufferView *, int, int, unsigned int);
+       bool unlockInsetInInset(BufferView *,
+                               UpdatableInset *, bool lr = false);
        ///
-       bool IsTextInset() const { return true; }
+       bool updateInsetInInset(BufferView *, Inset *);
        ///
-       bool doClearArea() const;
+       RESULT localDispatch(FuncRequest const &);
        ///
-       void InsetUnlock(BufferView *);
+       int latex(Buffer const *, std::ostream &,
+                 LatexRunParams const &) const;
        ///
-       bool LockInsetInInset(BufferView *, UpdatableInset *);
+       int ascii(Buffer const *, std::ostream &, int linelen) const;
        ///
-       bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
+       int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
        ///
-       bool UpdateInsetInInset(BufferView *, Inset *);
+       int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
        ///
-       void InsetButtonRelease(BufferView *, int, int, int);
+       void validate(LaTeXFeatures & features) const;
        ///
-       void InsetButtonPress(BufferView *, int, int, int);
+       Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
+       /// FIXME, document
+       void getCursorPos(BufferView *, int & x, int & y) const;
+       /// Get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView &, int &, int &) const;
        ///
-       void InsetMotionNotify(BufferView *, int, int, int);
+       int insetInInsetY() const;
        ///
-       void InsetKeyPress(XKeyEvent *);
+       void fitInsetCursor(BufferView *) const;
        ///
-       UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, string const &);
+       bool insertInset(BufferView *, Inset *);
        ///
-       int Latex(Buffer const *, std::ostream &,
-                 bool fragile, bool free_spc) const;
+       bool insetAllowed(Inset::Code) const;
        ///
-       int Ascii(Buffer const *, std::ostream &, int linelen) const;
+       UpdatableInset * getLockingInset() const;
        ///
-       int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+       UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
        ///
-       int DocBook(Buffer const *, std::ostream &) const ;
+       void setFont(BufferView *, LyXFont const &,
+                    bool toggleall = false,
+                    bool selectall = false);
        ///
-       void Validate(LaTeXFeatures & features) const;
+       int getMaxWidth(BufferView *, UpdatableInset const *) const;
        ///
-       Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
+       void init(InsetText const * ins = 0, bool same_id = false);
        ///
-       void GetCursorPos(BufferView *, int & x, int & y) const;
+       void writeParagraphData(Buffer const *, std::ostream &) const;
        ///
-       unsigned int InsetInInsetY();
+       void setParagraphData(ParagraphList const &, bool same_id = false);
        ///
-       void ToggleInsetCursor(BufferView *);
+       void setText(string const &, LyXFont const &);
        ///
-       bool InsertInset(BufferView *, Inset *);
+       void setAutoBreakRows(bool);
        ///
-       UpdatableInset * GetLockingInset();
+       bool getAutoBreakRows() const { return autoBreakRows; }
        ///
-       UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+       void setDrawFrame(BufferView *, DrawFrame);
        ///
-       void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+       void setFrameColor(BufferView *, LColor::color);
        ///
-       int getMaxWidth(BufferView *, UpdatableInset const *) const;
+       LyXText * getLyXText(BufferView const *,
+                            bool const recursive = false) const;
+       ///
+       void deleteLyXText(BufferView *, bool recursive = true) const;
+       ///
+       void resizeLyXText(BufferView *, bool force = false) const;
+       ///
+       bool showInsetDialog(BufferView *) const;
+       ///
+       std::vector<string> const getLabelList() const;
+       ///
+       bool nodraw() const;
        ///
-       void init(InsetText const * ins = 0);
+       int scroll(bool recursive = true) const;
        ///
-       void WriteParagraphData(Buffer const *, std::ostream &) const;
+       void scroll(BufferView * bv, float sx) const {
+               UpdatableInset::scroll(bv, sx);
+       }
        ///
-       void SetParagraphData(LyXParagraph *);
+       void scroll(BufferView * bv, int offset) const {
+               UpdatableInset::scroll(bv, offset);
+       }
        ///
-       void SetText(string const &);
+       void selectAll(BufferView * bv);
        ///
-       void SetAutoBreakRows(bool);
+       void clearSelection(BufferView * bv);
        ///
-       void SetDrawFrame(BufferView *, DrawFrame);
+       Inset * getInsetFromID(int id) const;
        ///
-       void SetFrameColor(BufferView *, LColor::color);
+       ParagraphList * getParagraphs(int) const;
        ///
-       LyXText * getLyXText(BufferView const *, bool const recursive=false) const;
+       LyXCursor const & cursor(BufferView *) const;
        ///
-       void deleteLyXText(BufferView *, bool recursive=true) const;
+       bool allowSpellcheck() const { return true; }
        ///
-       void resizeLyXText(BufferView *) const;
+       WordLangTuple const
+       selectNextWordToSpellcheck(BufferView *, float & value) const;
        ///
-       bool ShowInsetDialog(BufferView *) const;
+       void selectSelectedWord(BufferView *);
        ///
-       std::vector<string> const getLabelList() const;
+       void toggleSelection(BufferView *, bool kill_selection);
+
+       /// mark as erased for change tracking
+       void markErased() { clear(true); };
+       /**
+        * Mark as new. Used when pasting in tabular, and adding rows
+        * or columns. Note that pasting will ensure that tracking already
+        * happens, and this just resets the changes for the copied text,
+        * whereas for row/col add, we need to start tracking changes
+        * for the (empty) paragraph contained.
+        */
+       void markNew(bool track_changes = false);
+       /// find next change
+       bool nextChange(BufferView *, lyx::pos_type & length);
+
        ///
-       bool nodraw() const;
+       bool searchForward(BufferView *, string const &,
+                          bool = true, bool = false);
        ///
-       int scroll(bool recursive=true) const;
-       void scroll(BufferView *bv, float sx) const {
-               UpdatableInset::scroll(bv, sx);
-       }
-       void scroll(BufferView *bv, int offset) const {
-               UpdatableInset::scroll(bv, offset);
-       }
+       bool searchBackward(BufferView *, string const &,
+                           bool = true, bool = false);
+       ///
+       bool checkInsertChar(LyXFont &);
+       ///
+       void getDrawFont(LyXFont &) const;
+       /// append text onto the existing text
+       void appendParagraphs(Buffer * bp, ParagraphList &);
 
-       LyXParagraph * par;
+       ///
+       void addPreview(grfx::PreviewLoader &) const;
+
+       //
+       // Public structures and variables
        ///
        mutable int need_update;
 
+       bool haveParagraphs() const {
+               return true;
+       }
+       ///
+       ParagraphList paragraphs;
 protected:
        ///
-       void UpdateLocal(BufferView *, int what, bool mark_dirty);
+       void updateLocal(BufferView *, int what, bool mark_dirty);
+       /// set parameters for an initial lock of this inset
+       void lockInset(BufferView *);
+       /// lock an inset inside this one
+       void lockInset(BufferView *, UpdatableInset *);
        ///
        mutable int drawTextXOffset;
        ///
@@ -210,86 +264,95 @@ protected:
 
 private:
        ///
-       typedef std::map<BufferView *, LyXText *> Cache;
+       void lfunMousePress(FuncRequest const &);
        ///
-       typedef Cache::value_type value_type;
+       bool lfunMouseRelease(FuncRequest const &);
        ///
-       int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
+       void lfunMouseMotion(FuncRequest const &);
+
+       ///
+       struct InnerCache {
+               ///
+               InnerCache(boost::shared_ptr<LyXText>);
+               ///
+               boost::shared_ptr<LyXText> text;
+               ///
+               bool remove;
+       };
        ///
-       void ShowInsetCursor(BufferView *, bool show=true);
+       typedef std::map<BufferView *, InnerCache> Cache;
        ///
-       void HideInsetCursor(BufferView *);
+       typedef Cache::value_type value_type;
        ///
-       UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
+       RESULT moveRight(BufferView *,
+                                        bool activate_inset = true,
                                         bool selecting = false);
        ///
-       UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
+       RESULT moveLeft(BufferView *,
+                                       bool activate_inset = true,
                                        bool selecting = false);
        ///
-       UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
+       RESULT moveRightIntern(BufferView *, bool front,
                                               bool activate_inset = true,
                                               bool selecting = false);
        ///
-       UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
+       RESULT moveLeftIntern(BufferView *, bool front,
                                              bool activate_inset = true,
                                              bool selecting = false);
 
        ///
-       UpdatableInset::RESULT moveUp(BufferView *);
-       ///
-       UpdatableInset::RESULT moveDown(BufferView *);
+       RESULT moveUp(BufferView *);
        ///
-       void SetCharFont(Buffer const *, int pos, LyXFont const & font);
+       RESULT moveDown(BufferView *);
        ///
-       string const getText(int);
+       void setCharFont(Buffer const *, int pos, LyXFont const & font);
        ///
-       bool checkAndActivateInset(BufferView * bv, bool behind);
+       bool checkAndActivateInset(BufferView * bv, bool front);
        ///
        bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
-                                  int button = 0);
+                                  mouse_button::state button = mouse_button::none);
        ///
        void removeNewlines();
        ///
        int cx(BufferView *) const;
        ///
+       int cix(BufferView *) const;
+       ///
        int cy(BufferView *) const;
        ///
-       LyXParagraph::size_type cpos(BufferView *) const;
+       int ciy(BufferView *) const;
+       ///
+       lyx::pos_type cpos(BufferView *) const;
        ///
-       LyXParagraph * cpar(BufferView *) const;
+       ParagraphList::iterator cpar(BufferView *) const;
        ///
        bool cboundary(BufferView *) const;
        ///
-       Row * crow(BufferView *) const;
+       RowList::iterator crow(BufferView *) const;
        ///
-       /// This instead of a macro
-       LyXText * TEXT(BufferView * bv) const {
-               return getLyXText(bv);
-       }
+       void drawFrame(Painter &, int x) const;
        ///
-       void drawFrame(Painter &, bool cleared) const;
-       void clearFrame(Painter &, bool cleared) const;
+       void clearInset(BufferView *, int start_x, int baseline) const;
        ///
-       
-       /* Private structures and variables */
+       void saveLyXTextState(LyXText *) const;
        ///
-       mutable bool locked;
-       ///
-       mutable int insetAscent;
+       void restoreLyXTextState(LyXText *) const;
        ///
-       mutable int insetDescent;
+       void reinitLyXText() const;
        ///
-       mutable int insetWidth;
+       void collapseParagraphs(BufferView *);
+
+       /* Private structures and variables */
        ///
-       mutable int last_width;
+       mutable bool locked;
        ///
-       mutable int last_height;
+       mutable Dimension dim_;
        ///
        mutable int top_y;
        ///
-       LyXParagraph * inset_par;
+       ParagraphList::iterator inset_par;
        ///
-       LyXParagraph::size_type inset_pos;
+       lyx::pos_type inset_pos;
        ///
        bool inset_boundary;
        ///
@@ -297,20 +360,58 @@ private:
        ///
        mutable int inset_y;
        ///
-       int interline_space;
+       mutable int old_max_width;
        ///
        bool no_selection;
        ///
-       mutable float xpos;
-       ///
        UpdatableInset * the_locking_inset;
        ///
-       LyXParagraph * old_par;
+       mutable ParagraphList::iterator old_par;
        /// The cache.
        mutable Cache cache;
        ///
        mutable int last_drawn_width;
        ///
-       mutable bool frame_is_visible;
+       mutable BufferView * cached_bview;
+       ///
+       mutable boost::shared_ptr<LyXText> cached_text;
+       ///
+       struct save_state {
+               Paragraph * lpar;
+               Paragraph * selstartpar;
+               Paragraph * selendpar;
+               lyx::pos_type pos;
+               lyx::pos_type selstartpos;
+               lyx::pos_type selendpos;
+               bool boundary;
+               bool selstartboundary;
+               bool selendboundary;
+               bool selection;
+               bool mark_set;
+       };
+       ///
+       mutable save_state sstate;
+
+       ///
+       // this is needed globally so we know that we're using it actually and
+       // so the LyXText-Cache is not erased until used!
+       mutable LyXText * lt;
+       ///
+       // to remember old painted frame dimensions to clear it on the right spot!
+       ///
+       mutable int frame_x;
+       mutable int frame_y;
+       mutable int frame_w;
+       mutable int frame_h;
+       ///
+       bool in_update; /* as update is not reentrant! */
+       mutable BufferView * do_resize;
+       mutable bool do_reinit;
+       mutable bool in_insetAllowed;
+       ///
+       // these are used to check for mouse movement in Motion selection code
+       ///
+       int mouse_x;
+       int mouse_y;
 };
 #endif