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