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
22 #include "support/LAssert.h"
24 #include "ControlConnections.h"
28 template <class Inset, class Params>
29 class ControlInset : public ControlConnectBD
33 ControlInset(LyXView &, Dialogs &);
34 /// Allow the View access to the local copy.
35 Params & params() const;
38 /// Slots connected in the daughter classes c-tor.
39 /// Slot launching dialog to (possibly) create a new inset.
40 void createInset(string const &);
41 /// Slot launching dialog to an existing inset.
42 void showInset(Inset *);
43 /// Allow the daughter methods to access the inset.
44 Inset * inset() const;
47 /** These 6 methods are all that the individual daughter classes
48 should need to instantiate. */
50 /// if the inset exists then do this...
51 virtual void applyParamsToInset() = 0;
53 virtual void applyParamsNoInset() = 0;
55 /// get the parameters from the string passed to createInset.
56 virtual Params const getParams(string const &) = 0;
57 /// get the parameters from the inset passed to showInset.
58 virtual Params const getParams(Inset const &) = 0;
60 /** Most derived classes won't need these two, so they default to empty.
63 /// set any daughter class-particular data on show().
64 virtual void setDaughterParams() {}
65 /// clean-up any daughter class-particular data on hide().
66 virtual void clearDaughterParams() {}
71 /// Instantiation of ControlButtons virtual methods.
73 /// Get changed parameters and Dispatch them to the kernel.
75 /// Disconnect signals and hide View.
77 /// Update the dialog.
78 virtual void update();
80 /** Instantiation of ControlConnectBD private virtual method.
81 Slot connected to update signal. */
82 virtual void updateSlot(bool);
85 void show(Params const &);
87 void connectInset(Inset * = 0);
89 /// pointer to the inset passed through connectInset
91 /// inset::hide connection.
93 /** A local copy of the inset's params.
94 Memory is allocated only whilst the dialog is visible.
100 template <class Inset, class Params>
101 ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
102 : ControlConnectBD(lv, d),
103 inset_(0), ih_(0), params_(0)
107 template <class Inset, class Params>
108 void ControlInset<Inset, Params>::showInset(Inset * inset)
110 if (inset == 0) return; // maybe we should Assert this?
113 show(getParams(*inset));
117 template <class Inset, class Params>
118 void ControlInset<Inset, Params>::createInset(string const & arg)
123 bc().valid(); // so that the user can press Ok
125 show(getParams(arg));
129 template <class Inset, class Params>
130 void ControlInset<Inset, Params>::show(Params const & params)
132 if (params_) delete params_;
133 params_ = new Params(params);
137 bc().readOnly(isReadonly());
142 template <class Inset, class Params>
143 void ControlInset<Inset, Params>::hide()
151 clearDaughterParams();
159 template <class Inset, class Params>
160 void ControlInset<Inset, Params>::update()
162 if (params_) delete params_;
165 params_ = new Params(getParams(*inset_));
167 params_ = new Params();
169 bc().readOnly(isReadonly());
174 template <class Inset, class Params>
175 void ControlInset<Inset, Params>::apply()
177 if (lv_.buffer()->isReadonly())
182 if (inset_ && params() != getParams(*inset_))
183 applyParamsToInset();
185 applyParamsNoInset();
189 template <class Inset, class Params>
190 Params & ControlInset<Inset, Params>::params() const
197 template <class Inset, class Params>
198 Inset * ControlInset<Inset, Params>::inset() const
205 template <class Inset, class Params>
206 void ControlInset<Inset, Params>::updateSlot(bool switched)
215 template <class Inset, class Params>
216 void ControlInset<Inset, Params>::connectInset(Inset * inset)
218 // If connected to another inset, disconnect from it.
226 ih_ = inset->hideDialog.connect(
227 SigC::slot(this, &ControlInset::hide));
231 #endif // CONTROLINSET_H