2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2001 The LyX Team.
9 * ======================================================
11 * \file ControlInsets.h
12 * \author Angus Leeming <a.leeming@ic.ac.uk>
14 * ControlInset is to be used as a parent class for dialogs that display and
15 * can perhaps modify the contents of an individual inset. An example being the
16 * ubiquitous Citation dialog.
19 #ifndef CONTROLINSET_H
20 #define CONTROLINSET_H
22 #include "support/LAssert.h"
23 #include "ControlConnections.h"
27 template <class Inset, class Params>
28 class ControlInset : public ControlConnectBD
32 ControlInset(LyXView &, Dialogs &);
33 /// Allow the View access to the local copy.
36 Params const & params() const;
39 /// Slots connected in the daughter classes c-tor.
40 /// Slot launching dialog to (possibly) create a new inset.
41 void createInset(string const &);
42 /// Slot launching dialog to an existing inset.
43 void showInset(Inset *);
44 /// Allow the daughter methods to access the inset.
45 Inset * inset() const;
48 /** These 6 methods are all that the individual daughter classes
49 should need to instantiate. */
51 /// if the inset exists then do this...
52 virtual void applyParamsToInset() = 0;
54 virtual void applyParamsNoInset() = 0;
56 /// get the parameters from the string passed to createInset.
57 virtual Params const getParams(string const &) = 0;
58 /// get the parameters from the inset passed to showInset.
59 virtual Params const getParams(Inset const &) = 0;
61 /** Most derived classes won't need these two, so they default to empty.
64 /// set any daughter class-particular data on show().
65 virtual void setDaughterParams() {}
66 /// clean-up any daughter class-particular data on hide().
67 virtual void clearDaughterParams() {}
72 /// Instantiation of ControlButtons virtual methods.
74 /// Get changed parameters and Dispatch them to the kernel.
76 /// Disconnect signals and hide View.
78 /// Update the dialog.
79 virtual void update();
81 /** Instantiation of ControlConnectBD private virtual method.
82 Slot connected to update signal. */
83 virtual void updateSlot(bool);
86 void show(Params const &);
88 void connectInset(Inset * = 0);
90 /// pointer to the inset passed through connectInset
92 /// inset::hide connection.
94 /** A local copy of the inset's params.
95 Memory is allocated only whilst the dialog is visible.
101 template <class Inset, class Params>
102 ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
103 : ControlConnectBD(lv, d),
104 inset_(0), ih_(0), params_(0)
108 template <class Inset, class Params>
109 void ControlInset<Inset, Params>::showInset(Inset * inset)
111 if (inset == 0) return; // maybe we should Assert this?
114 show(getParams(*inset));
118 template <class Inset, class Params>
119 void ControlInset<Inset, Params>::createInset(string const & arg)
124 bc().valid(); // so that the user can press Ok
126 show(getParams(arg));
130 template <class Inset, class Params>
131 void ControlInset<Inset, Params>::show(Params const & params)
133 if (params_) delete params_;
134 params_ = new Params(params);
138 bc().readOnly(isReadonly());
143 template <class Inset, class Params>
144 void ControlInset<Inset, Params>::hide()
152 clearDaughterParams();
160 template <class Inset, class Params>
161 void ControlInset<Inset, Params>::update()
163 if (params_) delete params_;
166 params_ = new Params(getParams(*inset_));
168 params_ = new Params();
170 bc().readOnly(isReadonly());
175 template <class Inset, class Params>
176 void ControlInset<Inset, Params>::apply()
178 if (lv_.buffer()->isReadonly())
183 if (inset_ && params() != getParams(*inset_))
184 applyParamsToInset();
186 applyParamsNoInset();
190 template <class Inset, class Params>
191 Params & ControlInset<Inset, Params>::params()
193 lyx::Assert(params_);
198 template <class Inset, class Params>
199 Params const & ControlInset<Inset, Params>::params() const
201 lyx::Assert(params_);
206 template <class Inset, class Params>
207 Inset * ControlInset<Inset, Params>::inset() const
214 template <class Inset, class Params>
215 void ControlInset<Inset, Params>::updateSlot(bool switched)
224 template <class Inset, class Params>
225 void ControlInset<Inset, Params>::connectInset(Inset * inset)
227 // If connected to another inset, disconnect from it.
235 ih_ = inset->hideDialog.connect(
236 SigC::slot(this, &ControlInset::hide));
240 #endif // CONTROLINSET_H