]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
9b5ce26375e42288b62b43a3f046c0e767ffb020
[lyx.git] / src / insets / insetcommand.h
1 // -*- C++ -*-
2 /* This file is part of*
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef INSET_LATEXCOMMAND_H
13 #define INSET_LATEXCOMMAND_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "insetbutton.h"
20 #include <sigc++/signal_system.h>
21 #include <boost/utility.hpp>
22
23 // Created by Alejandro 970222
24 /** Used to insert a LaTeX command automatically
25  *
26  * Similar to InsetLaTeX but having control of the basic structure of a
27  *   LaTeX command: \name[options]{contents}.
28  */
29 class InsetCommandParams {
30 public:
31         ///
32         InsetCommandParams();
33         ///
34         explicit
35         InsetCommandParams(string const & n,
36                             string const & c = string(),
37                             string const & o = string());
38         ///
39         bool operator==(InsetCommandParams const &) const;
40         ///
41         bool operator!=(InsetCommandParams const &) const;
42         ///
43         void read(LyXLex &);
44         /// Parse the command
45         void scanCommand(string const &);
46         ///
47         void write(std::ostream &) const;
48         /// Build the complete LaTeX command
49         string const getCommand() const;
50         ///
51         string const & getCmdName() const { return cmdname; }
52         ///
53         string const & getOptions() const { return options; }
54         ///
55         string const & getContents() const { return contents; }
56         ///
57         void setCmdName(string const & n) { cmdname = n; }
58         ///
59         void setOptions(string const & o) { options = o; }
60         ///
61         void setContents(string const & c) { contents = c; }
62         ///
63         string const getAsString() const;
64         ///
65         void setFromString(string const &);
66 private:
67         ///
68         string cmdname;
69         ///
70         string contents;
71         ///
72         string options;
73 };
74
75
76 ///
77 class InsetCommand : public InsetButton, boost::noncopyable {
78 public:
79         ///
80         explicit
81         InsetCommand(InsetCommandParams const &, bool same_id = false);
82         ///
83         virtual ~InsetCommand() { hideDialog(); }
84         ///
85         void write(Buffer const *, std::ostream & os) const
86                 { p_.write(os); }
87         ///
88         virtual void read(Buffer const *, LyXLex & lex)
89                 { p_.read(lex); }
90         /// Can remove one InsetBibKey is modified
91         void scanCommand(string const & c) { p_.scanCommand(c); };
92         ///
93         virtual int latex(Buffer const *, std::ostream &,
94                           bool fragile, bool free_spc) const;
95         ///
96         int ascii(Buffer const *, std::ostream &, int linelen) const;
97         ///
98         virtual int linuxdoc(Buffer const *, std::ostream &) const;
99         ///
100         virtual int docbook(Buffer const *, std::ostream &) const;
101         ///
102         Inset::Code lyxCode() const { return Inset::NO_CODE; }
103
104         ///
105         string const getCommand() const { return p_.getCommand(); }
106         ///
107         string const & getCmdName() const { return p_.getCmdName(); }
108         ///
109         string const & getOptions() const { return p_.getOptions(); }
110         ///
111         string const & getContents() const { return p_.getContents(); }
112         ///
113         void setCmdName(string const & n) { p_.setCmdName(n); }
114         ///
115         void setOptions(string const & o) { p_.setOptions(o); }
116         ///
117         void setContents(string const & c) { p_.setContents(c); }
118         ///
119         InsetCommandParams const & params() const { return p_; }
120         ///
121         void setParams(InsetCommandParams const &);
122         ///
123         SigC::Signal0<void> hideDialog;
124
125 private:
126         ///
127         InsetCommandParams p_;
128 };
129
130 #endif