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