]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.h
convert graphics for .tex export, fixes bug 1231
[lyx.git] / src / insets / insettext.h
index 7516a4a6b102c447d4748102195e264cd9bf5218..d89bb3413e4aee9d0ec14c8dfea50240d7d174c1 100644 (file)
@@ -1,65 +1,43 @@
 // -*- 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 "updatableinset.h"
+#include "RowList_fwd.h"
+#include "lyxfont.h"
+#include "lyxtext.h"
 
-#include "inset.h"
-#include "LString.h"
-#include "lyxcursor.h"
+#include "support/types.h"
+
+#include "frontends/mouse_state.h"
 
-class Painter;
-class BufferView;
 class Buffer;
-class LyXCursor;
-class Paragraph;
-class LColor;
-class LyXText;
-class LyXScreen;
+class BufferParams;
+class BufferView;
+class Dimension;
+class LColor_color;
+class CursorSlice;
+class Painter;
+class ParagraphList;
+class Row;
+
 
 /**
  A text inset is like a TeX box to write full text
- (including styles and other insets) in a given space. 
- @author: Jürgen Vigna
+ (including styles and other insets) in a given space.
  */
 class InsetText : public UpdatableInset {
 public:
-       ///
-       /// numbers need because of test if codeA < codeB
-       ///
-       enum UpdateCodes {
-               ///
-               NONE = 0,
-               ///
-               CURSOR = 1,
-               ///
-               CLEAR_FRAME = 2,
-               ///
-               DRAW_FRAME = 4,
-               ///
-               SELECTION = 8,
-               ///
-               CURSOR_PAR = 16,
-               ///
-               FULL = 32,
-               ///
-               INIT = 64
-       };
        ///
        enum DrawFrame {
                ///
@@ -70,253 +48,143 @@ public:
                ALWAYS
        };
        ///
-       InsetText();
-       ///
-       explicit
-       InsetText(InsetText const &);
-       ///
-       ~InsetText();
-       ///
-       Inset * Clone(Buffer const &) const;
-       ///
-       InsetText & operator=(InsetText const & it);
-       ///
-       void clear();
-       ///
-       void Read(Buffer const *, LyXLex &);
-       ///
-       void Write(Buffer const *, std::ostream &) const;
-       ///
-       int ascent(BufferView *, LyXFont const &) const;
-       ///
-       int descent(BufferView *, LyXFont const &) const;
-       ///
-       int width(BufferView *, LyXFont const & f) const;
-       ///
-       int textWidth(BufferView *) const;
-       ///
-       void draw(BufferView *, LyXFont const &, int , float &, bool) const;
-       ///
-       void update(BufferView *, LyXFont const &, bool =false);
-       ///
-       void SetUpdateStatus(BufferView *, int what) const;
-       ///
-       string const EditMessage() const;
-       ///
-       void Edit(BufferView *, int, int, unsigned int);
-       ///
-       bool IsTextInset() const { return true; }
-       ///
-       bool doClearArea() const;
-       ///
-       void InsetUnlock(BufferView *);
-       ///
-       bool LockInsetInInset(BufferView *, UpdatableInset *);
-       ///
-       bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
-       ///
-       bool UpdateInsetInInset(BufferView *, Inset *);
-       ///
-       void InsetButtonRelease(BufferView *, int, int, int);
-       ///
-       void InsetButtonPress(BufferView *, int, int, int);
-       ///
-       void InsetMotionNotify(BufferView *, int, int, int);
-       ///
-       void InsetKeyPress(XKeyEvent *);
+       explicit InsetText(BufferParams const &);
        ///
-       UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, string const &);
+       explicit InsetText();
        ///
-       int Latex(Buffer const *, std::ostream &,
-                 bool fragile, bool free_spc) 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 ;
-       ///
-       void Validate(LaTeXFeatures & features) const;
+       InsetText(InsetText const &);
        ///
-       Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
+       virtual std::auto_ptr<InsetBase> clone() const;
        ///
-       void GetCursorPos(BufferView *, int & x, int & y) const;
+       void operator=(InsetText const & it);
+       /// empty inset to empty par, or just mark as erased
+       void clear(bool just_mark_erased);
        ///
-       unsigned int InsetInInsetY();
+       void read(Buffer const & buf, LyXLex & lex);
        ///
-       void ToggleInsetCursor(BufferView *);
+       void write(Buffer const & buf, std::ostream & os) const;
        ///
-       bool InsertInset(BufferView *, Inset *);
+       void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
-       UpdatableInset * GetLockingInset();
+       void draw(PainterInfo & pi, int x, int y) const;
+       /// draw inset selection
+       void drawSelection(PainterInfo & pi, int x, int y) const;
        ///
-       UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+       std::string const editMessage() const;
        ///
-       void SetFont(BufferView *, LyXFont const &, bool toggleall = false,
-                    bool selectall = false);
+       bool isTextInset() const { return true; }
        ///
-       int getMaxWidth(BufferView *, UpdatableInset const *) const;
+       int latex(Buffer const &, std::ostream &,
+                 OutputParams const &) const;
        ///
-       void init(InsetText const * ins = 0);
+       int plaintext(Buffer const &, std::ostream &,
+                 OutputParams const &) const;
        ///
-       void WriteParagraphData(Buffer const *, std::ostream &) const;
+       int linuxdoc(Buffer const &, std::ostream &,
+                    OutputParams const &) const;
        ///
-       void SetParagraphData(Paragraph *);
+       int docbook(Buffer const &, std::ostream &,
+                   OutputParams const &) const;
        ///
-       void SetText(string const &);
+       void validate(LaTeXFeatures & features) const;
        ///
-       void SetAutoBreakRows(bool);
+       InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
+       /// FIXME, document
+       void getCursorPos(LCursor const & cur, int & x, int & y) const;
        ///
-       void SetDrawFrame(BufferView *, DrawFrame);
+       void setFont(BufferView *, LyXFont const &,
+                    bool toggleall = false,
+                    bool selectall = false);
        ///
-       void SetFrameColor(BufferView *, LColor::color);
+       void setText(std::string const &, LyXFont const &);
        ///
-       LyXText * getLyXText(BufferView const *, bool const recursive=false) const;
+       void setAutoBreakRows(bool);
        ///
-       void deleteLyXText(BufferView *, bool recursive=true) const;
+       bool getAutoBreakRows() const { return autoBreakRows_; }
        ///
-       void resizeLyXText(BufferView *, bool force=false) const;
+       void setDrawFrame(DrawFrame);
        ///
-       bool ShowInsetDialog(BufferView *) const;
+       LColor_color frameColor() const;
        ///
-       std::vector<string> const getLabelList() const;
+       void setFrameColor(LColor_color);
        ///
-       bool nodraw() const;
+       void setViewCache(BufferView const * bv) 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);
-       }
+       bool showInsetDialog(BufferView *) const;
+       /// Appends \c list with all labels found within this inset.
+       void getLabelList(Buffer const &, std::vector<std::string> & list) const;
        ///
-       void selectAll(BufferView *bv);
+       LyXText * getText(int) const;
        ///
-       void clearSelection(BufferView *bv);
+       bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
 
-       Paragraph * par;
-       ///
-       mutable int need_update;
+       /// 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);
 
-protected:
-       ///
-       void UpdateLocal(BufferView *, int what, bool mark_dirty);
-       ///
-       mutable int drawTextXOffset;
-       ///
-       mutable int drawTextYOffset;
-       ///
-       bool autoBreakRows;
-       ///
-       DrawFrame drawFrame_;
-       ///
-       LColor::color frame_color;
+       /// append text onto the existing text
+       void appendParagraphs(Buffer * bp, ParagraphList &);
 
-private:
        ///
-       typedef std::map<BufferView *, LyXText *> Cache;
-       ///
-       typedef Cache::value_type value_type;
-       ///
-       int BeginningOfMainBody(Buffer const *, Paragraph * par) const;
+       void addPreview(lyx::graphics::PreviewLoader &) const;
+
        ///
-       void ShowInsetCursor(BufferView *, bool show=true);
+       void edit(LCursor & cur, bool left);
        ///
-       void HideInsetCursor(BufferView *);
+       InsetBase * editXY(LCursor & cur, int x, int y);
+
+       /// number of cells in this inset
+       size_t nargs() const { return 1; }
        ///
-       UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
-                                        bool selecting = false);
+       ParagraphList & paragraphs();
        ///
-       UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
-                                       bool selecting = false);
+       ParagraphList const & paragraphs() const;
        ///
-       UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
-                                              bool activate_inset = true,
-                                              bool selecting = false);
+       bool insetAllowed(Code) const { return true; }
        ///
-       UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
-                                             bool activate_inset = true,
-                                             bool selecting = false);
+       bool allowSpellCheck() const { return true; }
 
+protected:
        ///
-       UpdatableInset::RESULT moveUp(BufferView *);
-       ///
-       UpdatableInset::RESULT moveDown(BufferView *);
-       ///
-       void SetCharFont(Buffer const *, int pos, LyXFont const & font);
+       void priv_dispatch(LCursor & cur, FuncRequest & cmd);
+private:
        ///
-       string const getText(int);
+       void updateLocal(LCursor &);
        ///
-       bool checkAndActivateInset(BufferView * bv, bool behind);
+       void init();
+       // If the inset is empty set the language of the current font to the
+       // language to the surronding text (if different).
+       void sanitizeEmptyText(BufferView &);
        ///
-       bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
-                                  int button = 0);
+       void setCharFont(Buffer const &, int pos, LyXFont const & font);
        ///
        void removeNewlines();
        ///
-       int cx(BufferView *) const;
-       ///
-       int cy(BufferView *) const;
+       void drawFrame(Painter &, int x, int y) const;
        ///
-       Paragraph::size_type cpos(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(Painter &, int baseline, bool & cleared) const;
-       
-       /* Private structures and variables */
-       ///
-       mutable bool locked;
-       ///
-       mutable int insetAscent;
-       ///
-       mutable int insetDescent;
-       ///
-       mutable int insetWidth;
-       ///
-       mutable int last_width;
-       ///
-       mutable int last_height;
-       ///
-       mutable int top_y;
-       ///
-       Paragraph * inset_par;
-       ///
-       Paragraph::size_type inset_pos;
-       ///
-       bool inset_boundary;
-       ///
-       mutable int inset_x;
-       ///
-       mutable int inset_y;
-       ///
-       mutable unsigned int old_max_width;
-       ///
-       bool no_selection;
+       void clearInset(Painter &, int x, int y) const;
+
        ///
-       mutable float xpos;
+       bool autoBreakRows_;
        ///
-       UpdatableInset * the_locking_inset;
+       DrawFrame drawFrame_;
+       /** We store the LColor::color value as an int to get LColor.h out
+        *  of the header file.
+        */
+       int frame_color_;
        ///
-       Paragraph * old_par;
-       /// The cache.
-       mutable Cache cache;
+       mutable lyx::par_type old_par;
+public:
        ///
-       mutable int last_drawn_width;
+       mutable LyXText text_;
        ///
-       mutable bool frame_is_visible;
+       mutable LyXFont font_;
 };
 #endif