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