1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlInsets.h
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
13 * ControlInset is to be used as a parent class for dialogs that display and
14 * can perhaps modify the contents of an individual inset. An example being the
15 * ubiquitous Citation dialog.
18 #ifndef CONTROLINSET_H
19 #define CONTROLINSET_H
21 #include "ControlConnections.h"
25 template <class Inset, class Params>
26 class ControlInset : public ControlConnectBD
30 ControlInset(LyXView &, Dialogs &);
31 /// Allow the View access to the local copy.
32 Params & params() const;
35 /// Slots connected in the daughter classes c-tor.
36 /// Slot launching dialog to (possibly) create a new inset.
37 void createInset(string const &);
38 /// Slot launching dialog to an existing inset.
39 void showInset(Inset *);
40 /// Allow the daughter methods to access the inset.
41 Inset * inset() const;
44 /** These 6 methods are all that the individual daughter classes
45 should need to instantiate. */
47 /// if the inset exists then do this...
48 virtual void applyParamsToInset() = 0;
50 virtual void applyParamsNoInset() = 0;
52 /// get the parameters from the string passed to createInset.
53 virtual Params const getParams(string const &) = 0;
54 /// get the parameters from the inset passed to showInset.
55 virtual Params const getParams(Inset const &) = 0;
57 /** Most derived classes won't need these two, so they default to empty.
60 /// set any daughter class-particular data on show().
61 virtual void setDaughterParams() {}
62 /// clean-up any daughter class-particular data on hide().
63 virtual void clearDaughterParams() {}
68 /// Instantiation of ControlButtons virtual methods.
70 /// Get changed parameters and Dispatch them to the kernel.
72 /// Disconnect signals and hide View.
74 /// Update the dialog.
75 virtual void update();
77 /** Instantiation of ControlConnectBD private virtual method.
78 Slot connected to update signal. */
79 virtual void updateSlot(bool);
82 void show(Params const &);
84 void connectInset(Inset * = 0);
86 /// pointer to the inset passed through connectInset
88 /// inset::hide connection.
90 /** A local copy of the inset's params.
91 Memory is allocated only whilst the dialog is visible.
97 template <class Inset, class Params>
98 ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
99 : ControlConnectBD(lv, d),
100 inset_(0), ih_(0), params_(0)
104 template <class Inset, class Params>
105 void ControlInset<Inset, Params>::showInset(Inset * inset)
107 if (inset == 0) return; // maybe we should Assert this?
110 show(getParams(*inset));
114 template <class Inset, class Params>
115 void ControlInset<Inset, Params>::createInset(string const & arg)
120 bc().valid(); // so that the user can press Ok
122 show(getParams(arg));
126 template <class Inset, class Params>
127 void ControlInset<Inset, Params>::show(Params const & params)
129 if (params_) delete params_;
130 params_ = new Params(params);
134 bc().readOnly(isReadonly());
139 template <class Inset, class Params>
140 void ControlInset<Inset, Params>::hide()
148 clearDaughterParams();
156 template <class Inset, class Params>
157 void ControlInset<Inset, Params>::update()
159 if (params_) delete params_;
162 params_ = new Params(getParams(*inset_));
164 params_ = new Params();
166 bc().readOnly(isReadonly());
171 template <class Inset, class Params>
172 void ControlInset<Inset, Params>::apply()
174 if (lv_.buffer()->isReadonly())
179 if (inset_ && params() != getParams(*inset_))
180 applyParamsToInset();
182 applyParamsNoInset();
186 template <class Inset, class Params>
187 Params & ControlInset<Inset, Params>::params() const
189 lyx::Assert(params_);
194 template <class Inset, class Params>
195 Inset * ControlInset<Inset, Params>::inset() const
202 template <class Inset, class Params>
203 void ControlInset<Inset, Params>::updateSlot(bool switched)
212 template <class Inset, class Params>
213 void ControlInset<Inset, Params>::connectInset(Inset * inset)
215 // If connected to another inset, disconnect from it.
223 ih_ = inset->hideDialog.connect(
224 SigC::slot(this, &ControlInset::hide));
228 #endif // CONTROLINSET_H