4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
12 #ifndef INSET_INCLUDE_H
13 #define INSET_INCLUDE_H
16 #include "insetcommandparams.h"
17 #include "render_button.h"
18 #include "mailinset.h"
20 #include "support/filename.h"
22 #include <boost/scoped_ptr.hpp>
29 class RenderMonitoredPreview;
32 /// for including tex/lyx files
33 class InsetInclude : public InsetOld {
36 InsetInclude(InsetCommandParams const &);
39 /// Override these InsetButton methods if Previewing
40 bool metrics(MetricsInfo & mi, Dimension & dim) const;
42 void draw(PainterInfo & pi, int x, int y) const;
44 virtual bool display() const;
46 /// get the parameters
47 InsetCommandParams const & params() const;
50 InsetBase::Code lyxCode() const { return InsetBase::INCLUDE_CODE; }
52 * \param buffer the Buffer containing this inset.
53 * \param list the list of labels in the child buffer.
55 void getLabelList(Buffer const & buffer,
56 std::vector<docstring> & list) const;
58 * \param buffer the Buffer containing this inset.
59 * \param keys the list of bibkeys in the child buffer.
61 void fillWithBibKeys(Buffer const & buffer,
62 std::vector<std::pair<std::string,std::string> > & keys) const;
63 /** Update the cache with all bibfiles in use of the child buffer
64 * (including bibfiles of grandchild documents).
65 * Does nothing if the child document is not loaded to prevent
66 * automatic loading of all child documents upon loading the master.
67 * \param buffer the Buffer containing this inset.
69 void updateBibfilesCache(Buffer const & buffer);
70 /** Return the cache with all bibfiles in use of the child buffer
71 * (including bibfiles of grandchild documents).
72 * Return an empty vector if the child doc is not loaded.
73 * \param buffer the Buffer containing this inset.
75 std::vector<support::FileName> const &
76 getBibfilesCache(Buffer const & buffer) const;
78 EDITABLE editable() const { return IS_EDITABLE; }
80 void write(Buffer const &, std::ostream &) const;
82 void read(Buffer const &, LyXLex &);
84 int latex(Buffer const &, odocstream &,
85 OutputParams const &) const;
87 int plaintext(Buffer const &, odocstream &,
88 OutputParams const &) const;
90 int docbook(Buffer const &, odocstream &,
91 OutputParams const &) const;
93 void validate(LaTeXFeatures &) const;
95 void addPreview(graphics::PreviewLoader &) const;
97 void addToToc(TocList &, Buffer const &) const;
99 void updateLabels(Buffer const & buffer) const;
101 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
103 InsetInclude(InsetInclude const &);
105 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
107 virtual std::auto_ptr<InsetBase> doClone() const;
109 /** Slot receiving a signal that the external file has changed
110 * and the preview should be regenerated.
112 void fileChanged() const;
114 friend class InsetIncludeMailer;
116 /// set the parameters
117 void set(InsetCommandParams const & params, Buffer const &);
118 /// get the text displayed on the button
119 docstring const getScreenLabel(Buffer const &) const;
121 void write(std::ostream &) const;
126 InsetCommandParams params_;
127 /// holds the entity name that defines the file location (SGML)
128 docstring const include_label;
130 /// The pointer never changes although *preview_'s contents may.
131 boost::scoped_ptr<RenderMonitoredPreview> const preview_;
134 mutable bool set_label_;
135 mutable RenderButton button_;
139 class InsetIncludeMailer : public MailInset {
142 InsetIncludeMailer(InsetInclude & inset);
144 virtual InsetBase & inset() const { return inset_; }
146 virtual std::string const & name() const { return name_; }
148 virtual std::string const inset2string(Buffer const &) const;
150 static void string2params(std::string const &, InsetCommandParams &);
152 static std::string const params2string(InsetCommandParams const &);
155 static std::string const name_;
157 InsetInclude & inset_;
163 #endif // INSETINCLUDE_H