]> git.lyx.org Git - lyx.git/blob - src/insets/InsetBranch.h
Fix bad cursor positioning when entering an inset
[lyx.git] / src / insets / InsetBranch.h
1 // -*- C++ -*-
2 /**
3  * \file InsetBranch.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Martin Vermeer
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETBRANCH_H
13 #define INSETBRANCH_H
14
15 #include "InsetCollapsable.h"
16
17 namespace lyx {
18
19 class InsetBranchParams {
20 public:
21         ///
22         explicit InsetBranchParams(docstring const & b = docstring())
23                 : branch(b) {}
24         ///
25         void write(std::ostream & os) const;
26         ///
27         void read(Lexer & lex);
28         ///
29         docstring branch;
30 };
31
32
33 /////////////////////////////////////////////////////////////////////////
34 //
35 // InsetBranch
36 //
37 /////////////////////////////////////////////////////////////////////////
38
39 /// The Branch inset for alternative, conditional output.
40
41 class InsetBranch : public InsetCollapsable
42 {
43 public:
44         ///
45         InsetBranch(Buffer *, InsetBranchParams const &);
46
47         ///
48         static std::string params2string(InsetBranchParams const &);
49         ///
50         static void string2params(std::string const &, InsetBranchParams &);
51         ///
52         docstring branch() const { return params_.branch; }
53         ///
54         void rename(docstring const & newname) { params_.branch = newname; }
55
56 private:
57         ///
58         InsetCode lyxCode() const { return BRANCH_CODE; }
59         ///
60         void write(std::ostream &) const;
61         ///
62         void read(Lexer & lex);
63         ///
64         docstring const buttonLabel(BufferView const &) const;
65         ///
66         ColorCode backgroundColor(PainterInfo const &) const;
67         ///
68         void latex(otexstream &, OutputParams const &) const;
69         ///
70         int plaintext(odocstringstream & ods, OutputParams const & op,
71                       size_t max_length = INT_MAX) const;
72         ///
73         int docbook(odocstream &, OutputParams const &) const;
74         ///
75         docstring xhtml(XHTMLStream &, OutputParams const &) const;
76         ///
77         void toString(odocstream &) const;
78         ///
79         void forOutliner(docstring &, size_t const, bool const) const;
80         ///
81         void validate(LaTeXFeatures &) const;
82         ///
83         std::string contextMenuName() const;
84         ///
85         void addToToc(DocIterator const & di, bool output_active,
86                                   UpdateType utype) const;
87         ///
88         InsetBranchParams const & params() const { return params_; }
89         ///
90         void setParams(InsetBranchParams const & params) { params_ = params; }
91
92         /** \returns true if params_.branch is listed as 'selected' in
93                 \c buffer. \p child only checks within child documents.
94          */
95         bool isBranchSelected(bool const child = false) const;
96         /*!
97          * Is the content of this inset part of the output document?
98          *
99          * Note that Branch insets are only considered part of the
100          * document when they are selected.
101          */
102         bool producesOutput() const { return isBranchSelected(); }
103         ///
104         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
105         ///
106         bool isMacroScope() const;
107         ///
108         docstring toolTip(BufferView const & bv, int x, int y) const;
109         ///
110         bool usePlainLayout() const { return false; }
111         ///
112         void doDispatch(Cursor & cur, FuncRequest & cmd);
113         ///
114         docstring layoutName() const { return from_ascii("Branch:") + branch(); }
115         ///
116         Inset * clone() const { return new InsetBranch(*this); }
117
118         ///
119         friend class InsetBranchParams;
120         ///
121         InsetBranchParams params_;
122 };
123
124 } // namespace lyx
125
126 #endif