]> git.lyx.org Git - lyx.git/blob - src/insets/InsetBranch.h
Merge branch 'master' of git.lyx.org:lyx
[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 & bv) const;
65         ///
66         ColorCode backgroundColor(PainterInfo const &) const;
67         ///
68         void latex(otexstream &, OutputParams const &) const;
69         ///
70         int plaintext(odocstream &, OutputParams const &) const;
71         ///
72         int docbook(odocstream &, OutputParams const &) const;
73         ///
74         docstring xhtml(XHTMLStream &, OutputParams const &) const;
75         ///
76         void toString(odocstream &) const;
77         ///
78         void forToc(docstring &, size_t) const;
79         ///
80         void validate(LaTeXFeatures &) const;
81         ///
82         std::string contextMenuName() const;
83         ///
84         void addToToc(DocIterator const &) const;
85         ///
86         InsetBranchParams const & params() const { return params_; }
87         ///
88         void setParams(InsetBranchParams const & params) { params_ = params; }
89
90         /** \returns true if params_.branch is listed as 'selected' in
91             \c buffer. This handles the case of child documents.
92          */
93         bool isBranchSelected() const;
94         /*!
95          * Is the content of this inset part of the output document?
96          *
97          * Note that Branch insets are only considered part of the
98          * document when they are selected.
99          */
100         bool producesOutput() const { return isBranchSelected(); }
101         ///
102         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
103         ///
104         bool isMacroScope() const;
105         ///
106         docstring toolTip(BufferView const & bv, int x, int y) const;
107         ///
108         bool usePlainLayout() const { return false; }
109         ///
110         void doDispatch(Cursor & cur, FuncRequest & cmd);
111         ///
112         docstring layoutName() const { return from_ascii("Branch:") + branch(); }
113         ///
114         Inset * clone() const { return new InsetBranch(*this); }
115
116         ///
117         friend class InsetBranchParams;
118         ///
119         InsetBranchParams params_;
120 };
121
122 } // namespace lyx
123
124 #endif