]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
setFont rework + some code simplification
[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 "lyxtext.h"
19
20 #include "support/types.h"
21
22 #include "frontends/mouse_state.h"
23
24
25 class Buffer;
26 class BufferParams;
27 class BufferView;
28 class Dimension;
29 class LColor_color;
30 class LyXCursor;
31 class Painter;
32 class Paragraph;
33 class Row;
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  @author: Jürgen Vigna
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 &, LyXLex &);
63         ///
64         void write(Buffer const &, std::ostream &) const;
65         ///
66         void metrics(MetricsInfo &, Dimension &) const;
67         ///
68         void draw(PainterInfo & pi, int x, int y) const;
69         ///
70         std::string const editMessage() const;
71         ///
72         bool isTextInset() const { return true; }
73         ///
74         int latex(Buffer const &, std::ostream &,
75                   OutputParams const &) const;
76         ///
77         int plaintext(Buffer const &, std::ostream &,
78                   OutputParams const &) const;
79         ///
80         int linuxdoc(Buffer const &, std::ostream &,
81                      OutputParams const &) const ;
82         ///
83         int docbook(Buffer const &, std::ostream &,
84                     OutputParams const &) const ;
85         ///
86         void validate(LaTeXFeatures & features) const;
87         ///
88         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
89         /// FIXME, document
90         void getCursorPos(int & x, int & y) const;
91         ///
92         int insetInInsetY() const;
93         ///
94         bool insertInset(BufferView *, InsetOld *);
95         ///
96         bool insetAllowed(InsetOld::Code) const;
97         ///
98         void setFont(BufferView *, LyXFont const &,
99                      bool toggleall = false,
100                      bool selectall = false);
101         ///
102         void writeParagraphData(Buffer const &, std::ostream &) const;
103         ///
104         void setText(std::string const &, LyXFont const &);
105         ///
106         void setAutoBreakRows(bool);
107         ///
108         bool getAutoBreakRows() const { return autoBreakRows_; }
109         ///
110         void setDrawFrame(DrawFrame);
111         ///
112         LColor_color frameColor() const;
113         ///
114         void setFrameColor(LColor_color);
115         ///
116         void setViewCache(BufferView const * bv) const;
117         ///
118         bool showInsetDialog(BufferView *) const;
119         /// Appends \c list with all labels found within this inset.
120         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
121         ///
122         int scroll(bool recursive = true) const;
123         ///
124         void scroll(BufferView * bv, float sx) const {
125                 UpdatableInset::scroll(bv, sx);
126         }
127         ///
128         void scroll(BufferView * bv, int offset) const {
129                 UpdatableInset::scroll(bv, offset);
130         }
131         ///
132         void clearSelection(BufferView * bv);
133         ///
134         ParagraphList * getParagraphs(int) const;
135         ///
136         LyXText * getText(int) const;
137
138         /// mark as erased for change tracking
139         void markErased() { clear(true); };
140         /**
141          * Mark as new. Used when pasting in tabular, and adding rows
142          * or columns. Note that pasting will ensure that tracking already
143          * happens, and this just resets the changes for the copied text,
144          * whereas for row/col add, we need to start tracking changes
145          * for the (empty) paragraph contained.
146          */
147         void markNew(bool track_changes = false);
148
149         ///
150         bool checkInsertChar(LyXFont &);
151         ///
152         void getDrawFont(LyXFont &) const;
153         /// append text onto the existing text
154         void appendParagraphs(Buffer * bp, ParagraphList &);
155
156         ///
157         void addPreview(lyx::graphics::PreviewLoader &) const;
158
159         ///
160         void edit(BufferView *, bool);
161         ///
162         void edit(BufferView *, int, int);
163
164         ///
165         int numParagraphs() const { return 1; }
166         ///
167         mutable ParagraphList paragraphs;
168 protected:
169         ///
170         DispatchResult
171         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
172         ///
173         void updateLocal(BufferView *, bool mark_dirty);
174
175 private:
176         ///
177         void init();
178         // If the inset is empty set the language of the current font to the
179         // language to the surronding text (if different).
180         void sanitizeEmptyText(BufferView *);
181         ///
182         void setCharFont(Buffer const &, int pos, LyXFont const & font);
183         ///
184         void removeNewlines();
185         ///
186         lyx::pos_type cpos() const;
187         ///
188         ParagraphList::iterator cpar() const;
189         ///
190         RowList::iterator crow() const;
191         ///
192         void drawFrame(Painter &, int x) const;
193         ///
194         void clearInset(BufferView *, int start_x, int baseline) const;
195         ///
196         void collapseParagraphs(BufferView *);
197
198         /* Private structures and variables */
199         ///
200         bool autoBreakRows_;
201         ///
202         DrawFrame drawFrame_;
203         /** We store the LColor::color value as an int to get LColor.h out
204          *  of the header file.
205          */
206         int frame_color_;
207         ///
208         bool no_selection;
209         ///
210         mutable lyx::paroffset_type old_par;
211
212         /** to remember old painted frame dimensions to clear it on
213          *  the right spot!
214          */
215         mutable bool in_insetAllowed;
216 public:
217         ///
218         mutable LyXText text_;
219         ///
220         mutable int textwidth_;
221 };
222 #endif