]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.h
the dispatch patch
[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 { return code == InsetOld::NEWLINE_CODE; }
61         ///
62         void setFont(BufferView *, LyXFont const &,
63                              bool toggleall = false, bool selectall = false);
64         ///
65         EDITABLE editable() const;
66         ///
67         int latex(Buffer const &, std::ostream &,
68                   LatexRunParams const &) const;
69         ///
70         int ascii(Buffer const &,
71                           std::ostream &, int linelen = 0) const;
72         ///
73         int linuxdoc(Buffer const &, std::ostream &) const;
74         ///
75         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
76         ///
77         void validate(LaTeXFeatures &) const {}
78         ///
79         bool checkInsertChar(LyXFont &);
80         ///
81         // these are needed here because of the label/inlined functionallity
82         ///
83         bool isOpen() const { return status_ == Open || status_ == Inlined; }
84         ///
85         bool inlined() const { return status_ == Inlined; }
86         ///
87         ERTStatus status() const { return status_; }
88         ///
89         void open(BufferView *);
90         ///
91         void close(BufferView *) const;
92         ///
93         bool allowSpellcheck() const { return false; }
94
95         WordLangTuple const
96         selectNextWordToSpellcheck(BufferView *, float &) const;
97         ///
98         void metrics(MetricsInfo &, Dimension &) const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         /// set the status of the inset
102         void status(BufferView *, ERTStatus const st) const;
103         ///
104         bool showInsetDialog(BufferView *) const;
105         ///
106         void getDrawFont(LyXFont &) const;
107         ///
108         bool forceDefaultParagraphs(InsetOld const *) const {
109                 return true;
110         }
111 protected:
112         ///
113         virtual
114         dispatch_result
115         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
116 private:
117         ///
118         void lfunMousePress(FuncRequest const &);
119         ///
120         // the bool return is used to see if we opened a dialog so that we can
121         // check this from an outer inset and open the dialog of the outer inset
122         // if that one has one!
123         ///
124         bool lfunMouseRelease(FuncRequest const &);
125         ///
126         void lfunMouseMotion(FuncRequest const &);
127         ///
128         void init();
129         ///
130         std::string const get_new_label() const;
131         ///
132         void setButtonLabel() const;
133         ///
134         void set_latex_font(BufferView *);
135         /// update status on button
136         void updateStatus(BufferView *, bool = false) const;
137
138         ///
139         mutable ERTStatus status_;
140 };
141
142
143 #include "mailinset.h"
144
145 class InsetERTMailer : public MailInset {
146 public:
147         ///
148         InsetERTMailer(InsetERT & inset);
149         ///
150         virtual InsetBase & inset() const { return inset_; }
151         ///
152         virtual std::string const & name() const { return name_; }
153         ///
154         virtual std::string const inset2string(Buffer const &) const;
155         ///
156         static void string2params(std::string const &, InsetERT::ERTStatus &);
157         ///
158         static std::string const params2string(InsetERT::ERTStatus);
159 private:
160         ///
161         static std::string const name_;
162         ///
163         InsetERT & inset_;
164 };
165
166 #endif