]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
88e7b0c305576736cdcfef7537089e50309d0e20
[lyx.git] / src / insets / insettext.h
1 // -*- C++ -*-
2 /**
3  * \file insettext.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETTEXT_H
13 #define INSETTEXT_H
14
15 #include "updatableinset.h"
16 #include "RowList_fwd.h"
17 #include "lyxfont.h"
18 #include "lyxtext.h"
19
20 #include "support/types.h"
21
22 #include "frontends/mouse_state.h"
23
24 class Buffer;
25 class BufferParams;
26 class BufferView;
27 class Dimension;
28 class LColor_color;
29 class CursorSlice;
30 class Painter;
31 class ParagraphList;
32 class Row;
33
34
35 /**
36  A text inset is like a TeX box to write full text
37  (including styles and other insets) in a given space.
38  */
39 class InsetText : public UpdatableInset {
40 public:
41         ///
42         enum DrawFrame {
43                 ///
44                 NEVER = 0,
45                 ///
46                 LOCKED,
47                 ///
48                 ALWAYS
49         };
50         ///
51         explicit InsetText(BufferParams const &);
52         ///
53         InsetText(InsetText const &);
54         ///
55         virtual std::auto_ptr<InsetBase> clone() const;
56         ///
57         void operator=(InsetText const & it);
58         /// empty inset to empty par, or just mark as erased
59         void clear(bool just_mark_erased);
60         ///
61         void read(Buffer const & buf, LyXLex & lex);
62         ///
63         void write(Buffer const & buf, std::ostream & os) const;
64         ///
65         void metrics(MetricsInfo & mi, Dimension & dim) const;
66         ///
67         void draw(PainterInfo & pi, int x, int y) const;
68         /// draw inset selection
69         void drawSelection(PainterInfo & pi, int x, int y) const;
70         ///
71         std::string const editMessage() const;
72         ///
73         bool isTextInset() const { return true; }
74         ///
75         int latex(Buffer const &, std::ostream &,
76                   OutputParams const &) const;
77         ///
78         int plaintext(Buffer const &, std::ostream &,
79                   OutputParams const &) const;
80         ///
81         int linuxdoc(Buffer const &, std::ostream &,
82                      OutputParams const &) const ;
83         ///
84         int docbook(Buffer const &, std::ostream &,
85                     OutputParams const &) const ;
86         ///
87         void validate(LaTeXFeatures & features) const;
88         ///
89         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
90         /// FIXME, document
91         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
92         ///
93         void setFont(BufferView *, LyXFont const &,
94                      bool toggleall = false,
95                      bool selectall = false);
96         ///
97         void setText(std::string const &, LyXFont const &);
98         ///
99         void setAutoBreakRows(bool);
100         ///
101         bool getAutoBreakRows() const { return autoBreakRows_; }
102         ///
103         void setDrawFrame(DrawFrame);
104         ///
105         LColor_color frameColor() const;
106         ///
107         void setFrameColor(LColor_color);
108         ///
109         void setViewCache(BufferView const * bv) const;
110         ///
111         bool showInsetDialog(BufferView *) const;
112         /// Appends \c list with all labels found within this inset.
113         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
114         ///
115         LyXText * getText(int) const;
116         ///
117         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
118
119         /// mark as erased for change tracking
120         void markErased() { clear(true); }
121         /**
122          * Mark as new. Used when pasting in tabular, and adding rows
123          * or columns. Note that pasting will ensure that tracking already
124          * happens, and this just resets the changes for the copied text,
125          * whereas for row/col add, we need to start tracking changes
126          * for the (empty) paragraph contained.
127          */
128         void markNew(bool track_changes = false);
129
130         /// append text onto the existing text
131         void appendParagraphs(Buffer * bp, ParagraphList &);
132
133         ///
134         void addPreview(lyx::graphics::PreviewLoader &) const;
135
136         ///
137         void edit(LCursor & cur, bool left);
138         ///
139         InsetBase * editXY(LCursor & cur, int x, int y);
140
141         /// number of cells in this inset
142         size_t nargs() const { return 1; }
143         ///
144         ParagraphList & paragraphs() const;
145         ///
146         bool insetAllowed(Code) const { return true; }
147         
148 protected:
149         ///
150         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
151 private:
152         ///
153         void updateLocal(LCursor &);
154         ///
155         void init();
156         // If the inset is empty set the language of the current font to the
157         // language to the surronding text (if different).
158         void sanitizeEmptyText(BufferView &);
159         ///
160         void setCharFont(Buffer const &, int pos, LyXFont const & font);
161         ///
162         void removeNewlines();
163         ///
164         void drawFrame(Painter &, int x, int y) const;
165         ///
166         void clearInset(Painter &, int x, int y) const;
167
168         ///
169         bool autoBreakRows_;
170         ///
171         DrawFrame drawFrame_;
172         /** We store the LColor::color value as an int to get LColor.h out
173          *  of the header file.
174          */
175         int frame_color_;
176         ///
177         mutable lyx::par_type old_par;
178 public:
179         ///
180         mutable LyXText text_;
181         ///
182         mutable LyXFont font_;
183 };
184 #endif