]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.h
remove lowercase, better layout handling and some variable renameing
[lyx.git] / src / insets / insettext.h
index a473e816287eaddf69e396af0a598046c50e52ee..91fe8da05baba4fe2d5e2dd1b6ea2cafcb2b2887 100644 (file)
 #pragma interface
 #endif
 
-#include "lyxinset.h"
+#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 BufferParams;
 class LyXCursor;
-class LyXParagraph;
-class LColor;
 class LyXText;
 class LyXScreen;
+class Row;
 
 /**
  A text inset is like a TeX box to write full text
@@ -70,22 +74,22 @@ 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);
        ///
        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;
        ///
        int ascent(BufferView *, LyXFont const &) const;
        ///
@@ -93,100 +97,168 @@ 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;
        ///
-       void SetUpdateStatus(BufferView *, int what);
+       string const editMessage() const;
        ///
-       string const EditMessage() const;
+       void edit(BufferView *, int, int, unsigned int);
        ///
-       void Edit(BufferView *, int, int, unsigned int);
+       void edit(BufferView *, bool front = true);
        ///
-       bool IsTextInset() const { return true; }
+       bool isTextInset() const { return true; }
        ///
-       bool doClearArea() const { return !locked; }
+       bool doClearArea() const;
        ///
-       void InsetUnlock(BufferView *);
+       void insetUnlock(BufferView *);
        ///
-       bool LockInsetInInset(BufferView *, UpdatableInset *);
+       bool lockInsetInInset(BufferView *, UpdatableInset *);
        ///
-       bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
+       bool unlockInsetInInset(BufferView *,
+                               UpdatableInset *, bool lr = false);
        ///
-       bool UpdateInsetInInset(BufferView *, Inset *);
+       bool updateInsetInInset(BufferView *, Inset *);
        ///
-       void InsetButtonRelease(BufferView *, int, int, int);
+       bool insetButtonRelease(BufferView *, int, int, int);
        ///
-       void InsetButtonPress(BufferView *, int, int, int);
+       void insetButtonPress(BufferView *, int, int, int);
        ///
-       void InsetMotionNotify(BufferView *, int, int, int);
+       void insetMotionNotify(BufferView *, int, int, int);
        ///
-       void InsetKeyPress(XKeyEvent *);
+       void insetKeyPress(XKeyEvent *);
        ///
-       UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, string const &);
+       UpdatableInset::RESULT localDispatch(BufferView *,
+                                            kb_action, string const &);
        ///
-       int Latex(Buffer const *, std::ostream &,
+       int latex(Buffer const *, std::ostream &,
                  bool fragile, bool free_spc) const;
        ///
-       int Ascii(Buffer const *, std::ostream &, int linelen) const;
+       int ascii(Buffer const *, std::ostream &, int linelen) const;
+       ///
+       int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+       ///
+       int docbook(Buffer const *, std::ostream &) const ;
        ///
-       int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+       void validate(LaTeXFeatures & features) const;
        ///
-       int DocBook(Buffer const *, std::ostream &) const ;
+       Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
        ///
-       void Validate(LaTeXFeatures & features) const;
+       void getCursorPos(BufferView *, int & x, int & y) const;
        ///
-       Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
+       unsigned int insetInInsetY();
        ///
-       void GetCursorPos(BufferView *, int & x, int & y) const;
+       void toggleInsetCursor(BufferView *);
        ///
-       unsigned int InsetInInsetY();
+       void showInsetCursor(BufferView *, bool show = true);
        ///
-       void ToggleInsetCursor(BufferView *);
+       void hideInsetCursor(BufferView *);
        ///
-       bool InsertInset(BufferView *, Inset *);
+       void fitInsetCursor(BufferView *) const;
        ///
-       UpdatableInset * GetLockingInset();
+       bool insertInset(BufferView *, Inset *);
        ///
-       UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+       bool insetAllowed(Inset::Code) const;
        ///
-       void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+       UpdatableInset * getLockingInset() const;
+       ///
+       UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
+       ///
+       void setFont(BufferView *, LyXFont const &,
+                    bool toggleall = false,
+                    bool selectall = false);
        ///
        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 writeParagraphData(Buffer const *, std::ostream &) const;
        ///
-       void SetParagraphData(LyXParagraph *);
+       void setParagraphData(Paragraph *, bool same_id = false);
        ///
-       void SetText(string const &);
+       void setText(string const &);
        ///
-       void SetAutoBreakRows(bool);
+       void setAutoBreakRows(bool);
        ///
-       void SetDrawFrame(BufferView *, DrawFrame);
+       bool getAutoBreakRows() const { return autoBreakRows; }
        ///
-       void SetFrameColor(BufferView *, LColor::color);
+       void setDrawFrame(BufferView *, DrawFrame);
        ///
-       LyXText * getLyXText(BufferView const *, bool const recursive=false) const;
+       void setFrameColor(BufferView *, LColor::color);
        ///
-       void deleteLyXText(BufferView *, bool recursive=true) const;
+       LyXText * getLyXText(BufferView const *,
+                            bool const recursive = false) const;
        ///
-       void resizeLyXText(BufferView *) const;
+       void deleteLyXText(BufferView *, bool recursive = true) const;
        ///
-       bool ShowInsetDialog(BufferView *) const;
+       void resizeLyXText(BufferView *, bool force = false) const;
+       ///
+       bool showInsetDialog(BufferView *) const;
        ///
        std::vector<string> const getLabelList() const;
        ///
-       LyXParagraph * par;
+       bool nodraw() const;
+       ///
+       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);
+       }
+       ///
+       void selectAll(BufferView * bv);
+       ///
+       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 &);
+       ///
+       void getDrawFont(LyXFont &) const;
+       ///
+       //
+       // 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;
        ///
@@ -194,26 +266,33 @@ protected:
        ///
        bool autoBreakRows;
        ///
-       DrawFrame drawFrame;
+       DrawFrame drawFrame_;
        ///
        LColor::color frame_color;
 
 private:
        ///
-       typedef std::map<BufferView *, LyXText *> Cache;
-       ///
-       typedef Cache::value_type value_type;
+       struct InnerCache {
+               ///
+               InnerCache(boost::shared_ptr<LyXText>);
+               ///
+               boost::shared_ptr<LyXText> text;
+               ///
+               bool remove;
+       };
        ///
-       int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
+       typedef std::map<BufferView *, InnerCache> Cache;
        ///
-       void ShowInsetCursor(BufferView *, bool show=true);
+       typedef Cache::value_type value_type;
        ///
-       void HideInsetCursor(BufferView *);
+       int beginningOfMainBody(Buffer const *, Paragraph * par) const;
        ///
-       UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
+       UpdatableInset::RESULT moveRight(BufferView *,
+                                        bool activate_inset = true,
                                         bool selecting = false);
        ///
-       UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
+       UpdatableInset::RESULT moveLeft(BufferView *,
+                                       bool activate_inset = true,
                                        bool selecting = false);
        ///
        UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
@@ -229,36 +308,45 @@ private:
        ///
        UpdatableInset::RESULT moveDown(BufferView *);
        ///
-       void SetCharFont(Buffer const *, int pos, LyXFont const & font);
-       ///
-       string const getText(int);
+       void setCharFont(Buffer const *, int pos, LyXFont const & font);
        ///
        bool checkAndActivateInset(BufferView * bv, bool behind);
        ///
        bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
-                                  int button = 0);
+                                  int button = 0);
+       ///
        void removeNewlines();
-
        ///
        int cx(BufferView *) const;
        ///
        int cy(BufferView *) const;
        ///
-       LyXParagraph::size_type cpos(BufferView *) const;
+       lyx::pos_type cpos(BufferView *) const;
        ///
-       LyXParagraph * cpar(BufferView *) const;
+       Paragraph * cpar(BufferView *) const;
        ///
        bool cboundary(BufferView *) const;
        ///
        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(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;
@@ -267,15 +355,11 @@ private:
        ///
        mutable int insetWidth;
        ///
-       mutable int last_width;
-       ///
-       mutable int last_height;
-       ///
        mutable int top_y;
        ///
-       LyXParagraph * inset_par;
+       Paragraph * inset_par;
        ///
-       LyXParagraph::size_type inset_pos;
+       lyx::pos_type inset_pos;
        ///
        bool inset_boundary;
        ///
@@ -283,7 +367,7 @@ private:
        ///
        mutable int inset_y;
        ///
-       int interline_space;
+       mutable int old_max_width;
        ///
        bool no_selection;
        ///
@@ -291,10 +375,55 @@ private:
        ///
        UpdatableInset * the_locking_inset;
        ///
-       LyXParagraph * 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