]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
ed99e024dfad23c265d9f0eb18cced6a480bf62a
[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
26 class Buffer;
27 class BufferParams;
28 class BufferView;
29 class Dimension;
30 class LColor_color;
31 class CursorSlice;
32 class Painter;
33 class Paragraph;
34 class Row;
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  @author: Jürgen Vigna
40  */
41 class InsetText : public UpdatableInset {
42 public:
43         ///
44         enum DrawFrame {
45                 ///
46                 NEVER = 0,
47                 ///
48                 LOCKED,
49                 ///
50                 ALWAYS
51         };
52         ///
53         explicit InsetText(BufferParams const &);
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         bool insetAllowed(InsetOld::Code) const;
96         ///
97         void setFont(BufferView *, LyXFont const &,
98                      bool toggleall = false,
99                      bool selectall = false);
100         ///
101         void setText(std::string const &, LyXFont const &);
102         ///
103         void setAutoBreakRows(bool);
104         ///
105         bool getAutoBreakRows() const { return autoBreakRows_; }
106         ///
107         void setDrawFrame(DrawFrame);
108         ///
109         LColor_color frameColor() const;
110         ///
111         void setFrameColor(LColor_color);
112         ///
113         void setViewCache(BufferView const * bv) const;
114         ///
115         bool showInsetDialog(BufferView *) const;
116         /// Appends \c list with all labels found within this inset.
117         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
118         ///
119         int scroll(bool recursive = true) const;
120         ///
121         void scroll(BufferView & bv, float sx) const {
122                 UpdatableInset::scroll(bv, sx);
123         }
124         ///
125         void scroll(BufferView & bv, int offset) const {
126                 UpdatableInset::scroll(bv, offset);
127         }
128         ///
129         LyXText * getText(int) const;
130
131         /// mark as erased for change tracking
132         void markErased() { clear(true); };
133         /**
134          * Mark as new. Used when pasting in tabular, and adding rows
135          * or columns. Note that pasting will ensure that tracking already
136          * happens, and this just resets the changes for the copied text,
137          * whereas for row/col add, we need to start tracking changes
138          * for the (empty) paragraph contained.
139          */
140         void markNew(bool track_changes = false);
141
142         /// append text onto the existing text
143         void appendParagraphs(Buffer * bp, ParagraphList &);
144
145         ///
146         void addPreview(lyx::graphics::PreviewLoader &) const;
147
148         ///
149         void edit(LCursor & cur, bool left);
150         ///
151         InsetBase * editXY(LCursor & cur, int x, int y);
152
153         ///
154         int numParagraphs() const { return 1; }
155         ///
156         ParagraphList & paragraphs() const;
157
158 private:
159         ///
160         DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
161         ///
162         void updateLocal(LCursor &);
163         ///
164         void init();
165         // If the inset is empty set the language of the current font to the
166         // language to the surronding text (if different).
167         void sanitizeEmptyText(BufferView &);
168         ///
169         void setCharFont(Buffer const &, int pos, LyXFont const & font);
170         ///
171         void removeNewlines();
172         ///
173         void drawFrame(Painter &, int x, int y) const;
174         ///
175         void clearInset(Painter &, int x, int y) const;
176
177         /* Private structures and variables */
178         ///
179         bool autoBreakRows_;
180         ///
181         DrawFrame drawFrame_;
182         /** We store the LColor::color value as an int to get LColor.h out
183          *  of the header file.
184          */
185         int frame_color_;
186         ///
187         mutable lyx::paroffset_type old_par;
188
189         /** to remember old painted frame dimensions to clear it on
190          *  the right spot!
191          */
192         mutable bool in_insetAllowed;
193 public:
194         ///
195         mutable LyXText text_;
196         ///
197         mutable LyXFont font_;
198 };
199 #endif