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 popups that display and
14 * can perhaps modify the contents of an individual inset. An example being the
15 * ubiquitous Citation popup.
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 ControlBase 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.
98 #include "support/LAssert.h"
102 template <class Inset, class Params>
103 ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
104 : ControlConnectBD(lv, d),
105 inset_(0), ih_(0), params_(0)
109 template <class Inset, class Params>
110 void ControlInset<Inset, Params>::showInset(Inset * inset)
112 if (inset == 0) return; // maybe we should Assert this?
115 show(getParams(*inset));
119 template <class Inset, class Params>
120 void ControlInset<Inset, Params>::createInset(string const & arg)
125 bc().valid(); // so that the user can press Ok
127 show(getParams(arg));
131 template <class Inset, class Params>
132 void ControlInset<Inset, Params>::show(Params const & params)
134 if (params_) delete params_;
135 params_ = new Params(params);
139 bc().readOnly(isReadonly());
144 template <class Inset, class Params>
145 void ControlInset<Inset, Params>::hide()
153 clearDaughterParams();
161 template <class Inset, class Params>
162 void ControlInset<Inset, Params>::update()
164 if (params_) delete params_;
167 params_ = new Params(getParams(*inset_));
169 params_ = new Params();
171 bc().readOnly(isReadonly());
176 template <class Inset, class Params>
177 void ControlInset<Inset, Params>::apply()
179 if (lv_.buffer()->isReadonly())
184 if (inset_ && params() != getParams(*inset_))
185 applyParamsToInset();
187 applyParamsNoInset();
191 template <class Inset, class Params>
192 Params & ControlInset<Inset, Params>::params() const
199 template <class Inset, class Params>
200 Inset * ControlInset<Inset, Params>::inset() const
207 template <class Inset, class Params>
208 void ControlInset<Inset, Params>::updateSlot(bool switched)
217 template <class Inset, class Params>
218 void ControlInset<Inset, Params>::connectInset(Inset * inset)
220 // If connected to another inset, disconnect from it.
228 ih_ = inset->hideDialog.connect(
229 SigC::slot(this, &ControlInset::hide));
233 #endif // CONTROLINSET_H