]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetcommand.h
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / insetcommand.h
index b1a53e82bf6088273c36d8b996aaf44ad4734aaf..969f987da073b53f902ec245907b8b9b6acc5625 100644 (file)
 // -*- C++ -*-
-/* This file is part of*
- * ======================================================
+/**
+ * \file insetcommand.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
- *      
- *         Copyright (C) 1995 Matthias Ettrich
- *          Copyright (C) 1996-1999 The LyX Team.
+ * \author Angus Leeming
+ * \author Lars Gullik Bjønnes
  *
- * ======================================================*/
+ * Full author contact details are available in file CREDITS.
+ */
 
 #ifndef INSET_LATEXCOMMAND_H
 #define INSET_LATEXCOMMAND_H
 
-#ifdef __GNUG__
-#pragma interface
-#endif
 
-#include "lyxinset.h"
-#include "LString.h"
+#include "inset.h"
+#include "insetcommandparams.h"
+#include "render_button.h"
+#include "mailinset.h"
 
 // Created by Alejandro 970222
 /** Used to insert a LaTeX command automatically
  *
  * Similar to InsetLaTeX but having control of the basic structure of a
- *   LaTeX command: \name[options]{contents}. 
+ *   LaTeX command: \name[options]{contents}.
  */
-class InsetCommand: public Inset {
+
+///
+class InsetCommand : public InsetOld {
 public:
        ///
-       InsetCommand();
-       ///
-       InsetCommand(string const & name, string const & arg = string(), 
-                    string const & opt = string());
+       explicit
+       InsetCommand(InsetCommandParams const &);
        ///
-       ~InsetCommand();
+       void metrics(MetricsInfo &, Dimension &) const;
        ///
-       int Ascent(LyXFont const & font) const;
+       void draw(PainterInfo & pi, int x, int y) const;
        ///
-       int Descent(LyXFont const & font) const;
+       void write(Buffer const &, std::ostream & os) const
+               { p_.write(os); }
        ///
-       int Width(LyXFont const & font) const;
+       virtual void read(Buffer const &, LyXLex & lex)
+               { p_.read(lex); }
+       /// Can remove one InsetBibKey is modified
+       void scanCommand(std::string const & c) { p_.scanCommand(c); };
        ///
-       void Draw(LyXFont, LyXScreen & scr, int baseline, float & x);
+       virtual int latex(Buffer const &, std::ostream &,
+                         LatexRunParams const &) const;
        ///
-       void Write(FILE * file);
-       /// Parse the command.
-       void scanCommand(string const & cmd);
-       /// Will not be used when lyxf3
-       void Read(LyXLex & lex);
-       /// 
-       virtual int Latex(FILE * file, signed char fragile);
+       int ascii(Buffer const &, std::ostream &, int linelen) const;
        ///
-       virtual int Latex(string & file, signed char fragile);
+       virtual int linuxdoc(Buffer const &, std::ostream &) const;
        ///
-       virtual int Linuxdoc(string & file);
+       virtual int docbook(Buffer const &, std::ostream &, bool) const;
        ///
-       virtual int DocBook(string & file);
+       InsetOld::Code lyxCode() const { return InsetOld::NO_CODE; }
        ///
-       Inset * Clone();
-       ///  
-       Inset::Code LyxCode() const
-       {
-               return Inset::NO_CODE;
-       }
+       virtual bool display() const { return true; }
        
-       /** Get the label that appears at screen.
-         
-         I thought it was enough to eliminate the argument to avoid
-         confusion with lyxinset::getLabel(int), but I've seen that
-         it wasn't. I hope you never confuse again both methods.  (ale)
-        */
-       virtual string getScreenLabel() const
-       {
-               return getCommand();
-       }
-       
-       /// Build the complete LaTeX command
-       string getCommand() const;
-       ///
-       string const & getCmdName() const {
-               return command;
-       }
        ///
-       string const & getOptions() const {
-               return options;
-       }
+       InsetCommandParams const & params() const { return p_; }
        ///
-       string const & getContents() const {
-               return contents;
-       }
+       std::string const & getContents() const { return p_.getContents(); }
        ///
-       void setCmdName(string const & n) {
-               command = n;
-       }
+       void setContents(std::string const & c) { p_.setContents(c); }
        ///
-       void setOptions(string const & o) {
-               options = o;
-       }
+       std::string const & getOptions() const { return p_.getOptions(); }
        ///
-       virtual void setContents(string const & c) {
-               contents = c;
-       }
+       RenderButton & button() const { return button_; }
+
 protected:
-       ///    
-       string command;
-       ///    
-       string options;
-       ///    
-       string contents;
+       ///
+       virtual
+       dispatch_result
+       priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
+       ///
+       std::string const getCommand() const { return p_.getCommand(); }
+       ///
+       std::string const & getCmdName() const { return p_.getCmdName(); }
+       ///
+       void setCmdName(std::string const & n) { p_.setCmdName(n); }
+       ///
+       void setOptions(std::string const & o) { p_.setOptions(o); }
+       ///
+       void setParams(InsetCommandParams const &);
+       /// This should provide the text for the button
+       virtual std::string const getScreenLabel(Buffer const &) const = 0;
+
+private:
+       ///
+       InsetCommandParams p_;
+       mutable bool set_label_;
+       mutable RenderButton button_;
+};
+
+
+class InsetCommandMailer : public MailInset {
+public:
+       ///
+       InsetCommandMailer(std::string const & name, InsetCommand & inset);
+       ///
+       virtual InsetBase & inset() const { return inset_; }
+       ///
+       virtual std::string const & name() const { return name_; }
+       ///
+       virtual std::string const inset2string(Buffer const &) const;
+       ///
+       static void string2params(std::string const &, InsetCommandParams &);
+       ///
+       static std::string const params2string(std::string const & name,
+                                         InsetCommandParams const &);
+private:
+       ///
+       std::string const name_;
+       ///
+       InsetCommand & inset_;
 };
 
+
 #endif