]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.h
* buffer.[Ch]:
[lyx.git] / src / insets / insetert.h
1 // -*- C++ -*-
2 /**
3  * \file insetert.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  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSETERT_H
14 #define INSETERT_H
15
16
17 #include "insetcollapsable.h"
18
19 /** A collapsable text inset for LaTeX insertions.
20
21   To write full ert (including styles and other insets) in a given
22   space.
23
24   Note that collapsed_ encompasses both the inline and collapsed button
25   versions of this inset.
26 */
27
28 class Language;
29
30 class InsetERT : public InsetCollapsable {
31 public:
32         ///
33         enum ERTStatus {
34                 Open,
35                 Collapsed,
36                 Inlined
37         };
38         ///
39         InsetERT(BufferParams const &, bool collapsed = false);
40         ///
41         InsetERT(InsetERT const &);
42         ///
43         virtual std::auto_ptr<InsetBase> clone() const;
44         ///
45         InsetERT(BufferParams const &,
46                  Language const *, std::string const & contents, bool collapsed);
47         ///
48         ~InsetERT();
49         ///
50         InsetOld::Code lyxCode() const { return InsetOld::ERT_CODE; }
51         ///
52         void read(Buffer const & buf, LyXLex & lex);
53         ///
54         void write(Buffer const & buf, std::ostream & os) const;
55         ///
56         std::string const editMessage() const;
57         ///
58         bool insertInset(BufferView *, InsetOld *);
59         ///
60         bool insetAllowed(InsetOld::Code code) const {
61                 return code == InsetOld::NEWLINE_CODE;
62         }
63         ///
64         EDITABLE editable() const;
65         ///
66         int latex(Buffer const &, std::ostream &,
67                   OutputParams const &) const;
68         ///
69         int plaintext(Buffer const &, std::ostream &,
70                   OutputParams const & runparams) const;
71         ///
72         int linuxdoc(Buffer const &, std::ostream &,
73                      OutputParams const &) const;
74         ///
75         int docbook(Buffer const &, std::ostream &,
76                     OutputParams const & runparams) const;
77         ///
78         void validate(LaTeXFeatures &) const {}
79         ///
80         // these are needed here because of the label/inlined functionallity
81         ///
82         bool isOpen() const { return status_ == Open || status_ == Inlined; }
83         ///
84         bool inlined() const { return status_ == Inlined; }
85         ///
86         ERTStatus status() const { return status_; }
87         ///
88         void open();
89         ///
90         void close() const;
91         ///
92         void metrics(MetricsInfo &, Dimension &) const;
93         ///
94         void draw(PainterInfo & pi, int x, int y) const;
95         /// set the status of the inset
96         void status(ERTStatus const st) const;
97         ///
98         bool showInsetDialog(BufferView *) const;
99         ///
100         void getDrawFont(LyXFont &) const;
101         ///
102         bool forceDefaultParagraphs(InsetOld const *) const { return true; }
103 protected:
104         ///
105         virtual
106         DispatchResult
107         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
108 private:
109         ///
110         void lfunMousePress(FuncRequest const &);
111         ///
112         // the bool return is used to see if we opened a dialog so that we can
113         // check this from an outer inset and open the dialog of the outer inset
114         // if that one has one!
115         ///
116         bool lfunMouseRelease(FuncRequest const &);
117         ///
118         void lfunMouseMotion(FuncRequest const &);
119         ///
120         void init();
121         ///
122         std::string const getNewLabel() const;
123         ///
124         void setButtonLabel() const;
125         ///
126         void setLatexFont(BufferView *);
127         /// update status on button
128         void updateStatus(bool = false) const;
129         ///
130         void edit(BufferView * bv, bool left);
131         ///
132         bool allowSpellCheck() const { return false; }
133
134         ///
135         mutable ERTStatus status_;
136 };
137
138
139 #include "mailinset.h"
140
141 class InsetERTMailer : public MailInset {
142 public:
143         ///
144         InsetERTMailer(InsetERT & inset);
145         ///
146         virtual InsetBase & inset() const { return inset_; }
147         ///
148         virtual std::string const & name() const { return name_; }
149         ///
150         virtual std::string const inset2string(Buffer const &) const;
151         ///
152         static void string2params(std::string const &, InsetERT::ERTStatus &);
153         ///
154         static std::string const params2string(InsetERT::ERTStatus);
155 private:
156         ///
157         static std::string const name_;
158         ///
159         InsetERT & inset_;
160 };
161
162 #endif