]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.h
Don't remove cell selections after fontchange.
[lyx.git] / src / insets / insettext.h
index 67faf394c3d39dca8504252c1045680cdeaa0ff4..54ee58bec7f553e06ea28ea003eaf37bd17b6ad8 100644 (file)
 
 #include "inset.h"
 #include "LString.h"
+#include "LColor.h"
+#include "paragraph.h"
 #include "lyxcursor.h"
 
+#include <boost/smart_ptr.hpp>
+
 class Painter;
 class BufferView;
 class Buffer;
 class LyXCursor;
-class Paragraph;
-class LColor;
 class LyXText;
 class LyXScreen;
+class Row;
 
 /**
  A text inset is like a TeX box to write full text
@@ -73,11 +76,11 @@ public:
        InsetText();
        ///
        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);
        ///
@@ -93,11 +96,11 @@ public:
        ///
        int width(BufferView *, LyXFont const & f) const;
        ///
-       int textWidth(BufferView *) const;
+       int textWidth(BufferView *, bool fordraw = false) const;
        ///
        void draw(BufferView *, LyXFont const &, int , float &, bool) const;
        ///
-       void update(BufferView *, LyXFont const &, bool =false);
+       void update(BufferView *, LyXFont const &, bool = false);
        ///
        void setUpdateStatus(BufferView *, int what) const;
        ///
@@ -105,6 +108,8 @@ public:
        ///
        void edit(BufferView *, int, int, unsigned int);
        ///
+       void edit(BufferView *, bool front = true);
+       ///
        bool isTextInset() const { return true; }
        ///
        bool doClearArea() const;
@@ -118,7 +123,7 @@ public:
        ///
        bool updateInsetInInset(BufferView *, Inset *);
        ///
-       void insetButtonRelease(BufferView *, int, int, int);
+       bool insetButtonRelease(BufferView *, int, int, int);
        ///
        void insetButtonPress(BufferView *, int, int, int);
        ///
@@ -136,7 +141,7 @@ public:
        ///
        int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
        ///
-       int docBook(Buffer const *, std::ostream &) const ;
+       int docbook(Buffer const *, std::ostream &) const ;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
@@ -148,9 +153,17 @@ public:
        ///
        void toggleInsetCursor(BufferView *);
        ///
+       void showInsetCursor(BufferView *, bool show = true);
+       ///
+       void hideInsetCursor(BufferView *);
+       ///
+       void fitInsetCursor(BufferView *) const;
+       ///
        bool insertInset(BufferView *, Inset *);
        ///
-       UpdatableInset * getLockingInset();
+       bool insetAllowed(Inset::Code) const;
+       ///
+       UpdatableInset * getLockingInset() const;
        ///
        UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
        ///
@@ -160,16 +173,18 @@ public:
        ///
        int getMaxWidth(BufferView *, UpdatableInset const *) const;
        ///
-       void init(InsetText const * ins = 0);
+       void init(InsetText const * ins = 0, bool same_id = false);
        ///
        void writeParagraphData(Buffer const *, std::ostream &) const;
        ///
-       void setParagraphData(Paragraph *);
+       void setParagraphData(Paragraph *, bool same_id = false);
        ///
        void setText(string const &);
        ///
        void setAutoBreakRows(bool);
        ///
+       bool getAutoBreakRows() const { return autoBreakRows; }
+       ///
        void setDrawFrame(BufferView *, DrawFrame);
        ///
        void setFrameColor(BufferView *, LColor::color);
@@ -187,27 +202,60 @@ public:
        ///
        bool nodraw() const;
        ///
-       int scroll(bool recursive=true) const;
+       int scroll(bool recursive = true) const;
        ///
-       void scroll(BufferView *bv, float sx) const {
+       void scroll(BufferView * bv, float sx) const {
                UpdatableInset::scroll(bv, sx);
        }
        ///
-       void scroll(BufferView *bv, int offset) const {
+       void scroll(BufferView * bv, int offset) const {
                UpdatableInset::scroll(bv, offset);
        }
        ///
-       void selectAll(BufferView *bv);
+       void selectAll(BufferView * bv);
        ///
-       void clearSelection(BufferView *bv);
-
-       Paragraph * par;
+       void clearSelection(BufferView * bv);
+       ///
+       Paragraph * getParFromID(int id) const;
+       ///
+       Inset * getInsetFromID(int id) const;
+       ///
+       Paragraph * firstParagraph() const;
+       ///
+       Paragraph * getFirstParagraph(int) const;
+       ///
+       LyXCursor const & cursor(BufferView *) const;
+       ///
+       Paragraph * paragraph() const;
+       ///
+       void paragraph(Paragraph *);
+       ///
+       bool allowSpellcheck() { return true; }
+       ///
+       string const selectNextWordToSpellcheck(BufferView *,
+                                               float & value) const;
+       void selectSelectedWord(BufferView *);
+       ///
+       void toggleSelection(BufferView *, bool kill_selection);
+       ///
+       bool searchForward(BufferView *, string const &,
+                          bool = true, bool = false);
+       ///
+       bool searchBackward(BufferView *, string const &,
+                           bool = true, bool = false);
+       ///
+       bool checkInsertChar(LyXFont &);
+       ///
+       //
+       // Public structures and variables
        ///
        mutable int need_update;
 
 protected:
        ///
-       void updateLocal(BufferView *, int what, bool mark_dirty);
+       void updateLocal(BufferView *, int what, bool mark_dirty) const;
+       ///
+       void lockInset(BufferView *, UpdatableInset *);
        ///
        mutable int drawTextXOffset;
        ///
@@ -221,16 +269,21 @@ protected:
 
 private:
        ///
-       typedef std::map<BufferView *, LyXText *> Cache;
+       struct InnerCache {
+               ///
+               InnerCache(boost::shared_ptr<LyXText>);
+               ///
+               boost::shared_ptr<LyXText> text;
+               ///
+               bool remove;
+       };
+       ///
+       typedef std::map<BufferView *, InnerCache> Cache;
        ///
        typedef Cache::value_type value_type;
        ///
        int beginningOfMainBody(Buffer const *, Paragraph * par) const;
        ///
-       void showInsetCursor(BufferView *, bool show=true);
-       ///
-       void hideInsetCursor(BufferView *);
-       ///
        UpdatableInset::RESULT moveRight(BufferView *,
                                         bool activate_inset = true,
                                         bool selecting = false);
@@ -254,12 +307,10 @@ private:
        ///
        void setCharFont(Buffer const *, int pos, LyXFont const & font);
        ///
-       string const getText(int);
-       ///
        bool checkAndActivateInset(BufferView * bv, bool behind);
        ///
        bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
-                                  int button = 0);
+                                  int button = 0);
        ///
        void removeNewlines();
        ///
@@ -267,7 +318,7 @@ private:
        ///
        int cy(BufferView *) const;
        ///
-       Paragraph::size_type cpos(BufferView *) const;
+       lyx::pos_type cpos(BufferView *) const;
        ///
        Paragraph * cpar(BufferView *) const;
        ///
@@ -275,19 +326,24 @@ private:
        ///
        Row * crow(BufferView *) const;
        ///
-       /// This instead of a macro
-       LyXText * TEXT(BufferView * bv) const {
-               return getLyXText(bv);
-       }
-       ///
        void drawFrame(Painter &, bool cleared) const;
        ///
        void clearFrame(Painter &, bool cleared) const;
        ///
-       void clearInset(Painter &, int baseline, bool & cleared) const;
+       void clearInset(BufferView *, int baseline, bool & cleared) const;
+       ///
+       void saveLyXTextState(LyXText *) const;
+       ///
+       void restoreLyXTextState(BufferView *, LyXText *) const;
+       ///
+       void reinitLyXText() const;
+       ///
+       void collapseParagraphs(BufferParams const & bparams) const;
        
        /* Private structures and variables */
        ///
+       Paragraph * par;
+       ///
        mutable bool locked;
        ///
        mutable int insetAscent;
@@ -296,15 +352,11 @@ private:
        ///
        mutable int insetWidth;
        ///
-       mutable int last_width;
-       ///
-       mutable int last_height;
-       ///
        mutable int top_y;
        ///
        Paragraph * inset_par;
        ///
-       Paragraph::size_type inset_pos;
+       lyx::pos_type inset_pos;
        ///
        bool inset_boundary;
        ///
@@ -312,7 +364,7 @@ private:
        ///
        mutable int inset_y;
        ///
-       mutable unsigned int old_max_width;
+       mutable int old_max_width;
        ///
        bool no_selection;
        ///
@@ -320,12 +372,55 @@ private:
        ///
        UpdatableInset * the_locking_inset;
        ///
-       Paragraph * old_par;
+       mutable Paragraph * 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;
+               bool refresh;
+       };
+       ///
+       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