]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
prepare for 1.1.6pre2
[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-2000 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 #ifdef SIGC_CXX_NAMESPACES
24 using SigC::Signal0;
25 #endif
26
27 // Created by Alejandro 970222
28 /** Used to insert a LaTeX command automatically
29  *
30  * Similar to InsetLaTeX but having control of the basic structure of a
31  *   LaTeX command: \name[options]{contents}. 
32  */
33 class InsetCommandParams {
34 public:
35         ///
36         InsetCommandParams();
37         ///
38         explicit
39         InsetCommandParams( string const & n,
40                             string const & c = string(),
41                             string const & o = string());
42         ///
43         bool operator==(InsetCommandParams const &) const;
44         ///
45         bool operator!=(InsetCommandParams const &) const;
46         ///
47         void Read(LyXLex &);
48         /// Parse the command
49         void scanCommand(string const &);
50         ///
51         void Write(std::ostream &) const;
52         /// Build the complete LaTeX command
53         string const getCommand() const;
54         ///
55         string const & getCmdName() const { return cmdname; }
56         ///
57         string const & getOptions() const { return options; }
58         ///
59         string const & getContents() const { return contents; }
60         ///
61         void setCmdName( string const & n) { cmdname = n; }
62         ///
63         void setOptions(string const & o) { options = o; }
64         ///
65         void setContents(string const & c) { contents = c; }
66         ///
67         string const getAsString() const;
68         ///
69         void setFromString( string const & );
70 private:
71         ///    
72         string cmdname;
73         ///    
74         string contents;
75         ///    
76         string options;
77 };
78
79
80 ///
81 class InsetCommand : public InsetButton, public noncopyable {
82 public:
83         ///
84         explicit
85         InsetCommand(InsetCommandParams const &);
86         ///
87         virtual ~InsetCommand() { hide(); }
88         ///
89         void Write(Buffer const *, std::ostream & os) const
90                 { p_.Write( os ); }
91         ///
92         virtual void Read(Buffer const *, LyXLex & lex)
93                 { p_.Read( lex ); }
94         /// Can remove one InsetBibKey is modified
95         void scanCommand(string const & c) { p_.scanCommand( c ); };
96         /// 
97         virtual int Latex(Buffer const *, std::ostream &,
98                           bool fragile, bool free_spc) const;
99         ///
100         int Ascii(Buffer const *, std::ostream &, int linelen) const;
101         ///
102         virtual int Linuxdoc(Buffer const *, std::ostream &) const;
103         ///
104         virtual int DocBook(Buffer const *, std::ostream &) const;
105         ///
106         Inset::Code LyxCode() const { return Inset::NO_CODE; }
107         
108         /** Get the label that appears at screen.
109           
110          I thought it was enough to eliminate the argument to avoid
111          confusion with lyxinset::getLabel(int), but I've seen that
112          it wasn't. I hope you never confuse again both methods.  (ale)
113          */
114         virtual string const getScreenLabel() const = 0;
115         ///
116         string const getCommand() const { return p_.getCommand(); }
117         ///
118         string const & getCmdName() const { return p_.getCmdName(); }
119         ///
120         string const & getOptions() const { return p_.getOptions(); }
121         ///
122         string const & getContents() const { return p_.getContents(); }
123         ///
124         void setCmdName(string const & n) { p_.setCmdName(n); }
125         ///
126         void setOptions(string const & o) { p_.setOptions(o); }
127         ///
128         void setContents(string const & c) { p_.setContents(c); }
129         ///
130         InsetCommandParams const & params() const { return p_; }
131         ///
132         void setParams(InsetCommandParams const &);
133         ///
134         Signal0<void> hide;
135 private:
136         ///
137         InsetCommandParams p_;
138 };
139
140 #endif