]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
Georg's add an editor to Formats / safe external_templates patch.
[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         explicit InsetText();
54         ///
55         InsetText(InsetText const &);
56         ///
57         virtual std::auto_ptr<InsetBase> clone() const;
58         ///
59         void operator=(InsetText const & it);
60         /// empty inset to empty par, or just mark as erased
61         void clear(bool just_mark_erased);
62         ///
63         void read(Buffer const & buf, LyXLex & lex);
64         ///
65         void write(Buffer const & buf, std::ostream & os) const;
66         ///
67         void metrics(MetricsInfo & mi, Dimension & dim) const;
68         ///
69         void draw(PainterInfo & pi, int x, int y) const;
70         /// draw inset selection
71         void drawSelection(PainterInfo & pi, int x, int y) const;
72         ///
73         std::string const editMessage() const;
74         ///
75         bool isTextInset() const { return true; }
76         ///
77         int latex(Buffer const &, std::ostream &,
78                   OutputParams const &) const;
79         ///
80         int plaintext(Buffer const &, std::ostream &,
81                   OutputParams const &) const;
82         ///
83         int linuxdoc(Buffer const &, std::ostream &,
84                      OutputParams const &) const;
85         ///
86         int docbook(Buffer const &, std::ostream &,
87                     OutputParams const &) const;
88         ///
89         void validate(LaTeXFeatures & features) const;
90         ///
91         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
92         /// FIXME, document
93         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
94         ///
95         void setFont(BufferView *, LyXFont const &,
96                      bool toggleall = false,
97                      bool selectall = false);
98         ///
99         void setText(std::string const &, LyXFont const &);
100         ///
101         void setAutoBreakRows(bool);
102         ///
103         bool getAutoBreakRows() const { return autoBreakRows_; }
104         ///
105         void setDrawFrame(DrawFrame);
106         ///
107         LColor_color frameColor() const;
108         ///
109         void setFrameColor(LColor_color);
110         ///
111         void setViewCache(BufferView const * bv) const;
112         ///
113         bool showInsetDialog(BufferView *) const;
114         /// Appends \c list with all labels found within this inset.
115         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
116         ///
117         LyXText * getText(int) const;
118         ///
119         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
120
121         /// mark as erased for change tracking
122         void markErased() { clear(true); }
123         /**
124          * Mark as new. Used when pasting in tabular, and adding rows
125          * or columns. Note that pasting will ensure that tracking already
126          * happens, and this just resets the changes for the copied text,
127          * whereas for row/col add, we need to start tracking changes
128          * for the (empty) paragraph contained.
129          */
130         void markNew(bool track_changes = false);
131
132         /// append text onto the existing text
133         void appendParagraphs(Buffer * bp, ParagraphList &);
134
135         ///
136         void addPreview(lyx::graphics::PreviewLoader &) const;
137
138         ///
139         void edit(LCursor & cur, bool left);
140         ///
141         InsetBase * editXY(LCursor & cur, int x, int y);
142
143         /// number of cells in this inset
144         size_t nargs() const { return 1; }
145         ///
146         ParagraphList & paragraphs();
147         ///
148         ParagraphList const & paragraphs() const;
149         ///
150         bool insetAllowed(Code) const { return true; }
151         ///
152         bool allowSpellCheck() const { return true; }
153
154 protected:
155         ///
156         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
157 private:
158         ///
159         void updateLocal(LCursor &);
160         ///
161         void init();
162         // If the inset is empty set the language of the current font to the
163         // language to the surronding text (if different).
164         void sanitizeEmptyText(BufferView &);
165         ///
166         void setCharFont(Buffer const &, int pos, LyXFont const & font);
167         ///
168         void removeNewlines();
169         ///
170         void drawFrame(Painter &, int x, int y) const;
171         ///
172         void clearInset(Painter &, int x, int y) const;
173
174         ///
175         bool autoBreakRows_;
176         ///
177         DrawFrame drawFrame_;
178         /** We store the LColor::color value as an int to get LColor.h out
179          *  of the header file.
180          */
181         int frame_color_;
182         ///
183         mutable lyx::par_type old_par;
184 public:
185         ///
186         mutable LyXText text_;
187         ///
188         mutable LyXFont font_;
189 };
190 #endif