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 * inset);
40 /// Allow the daughter methods to access the inset.
41 Inset * inset() const;
44 /** These 5 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;
51 /// clean-up any daughter class-particular data on hide.
52 virtual void clearDaughterParams() = 0;
53 /// get the parameters from the string passed to createInset.
54 virtual Params const getParams(string const &) = 0;
55 /// get the parameters from the inset passed to showInset.
56 virtual Params const getParams(Inset const &) = 0;
58 /// Instantiation of ControlBase virtual methods.
60 /// Get changed parameters and Dispatch them to the kernel.
62 /// Disconnect signals and hide View.
64 /// Update the dialog.
65 virtual void update();
67 /** Instantiation of ControlConnectBD private virtual method.
68 Slot connected to update signal. */
69 virtual void updateSlot(bool);
72 void show(Params const &);
74 void connectInset(Inset * = 0);
76 /// pointer to the inset passed through connectInset
78 /// inset::hide connection.
80 /** A local copy of the inset's params.
81 Memory is allocated only whilst the dialog is visible.
88 #include "support/LAssert.h"
92 template <class Inset, class Params>
93 ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
94 : ControlConnectBD(lv, d),
95 inset_(0), ih_(0), params_(0)
99 template <class Inset, class Params>
100 void ControlInset<Inset, Params>::showInset(Inset * inset)
102 if (inset == 0) return; // maybe we should Assert this?
105 show(getParams(*inset));
109 template <class Inset, class Params>
110 void ControlInset<Inset, Params>::createInset(string const & arg)
115 bc().valid(); // so that the user can press Ok
117 show(getParams(arg));
121 template <class Inset, class Params>
122 void ControlInset<Inset, Params>::show(Params const & params)
124 if (params_) delete params_;
125 params_ = new Params(params);
127 bc().readOnly(isReadonly());
132 template <class Inset, class Params>
133 void ControlInset<Inset, Params>::hide()
141 clearDaughterParams();
149 template <class Inset, class Params>
150 void ControlInset<Inset, Params>::update()
152 if (params_) delete params_;
155 params_ = new Params(getParams(*inset_));
157 params_ = new Params();
159 bc().readOnly(isReadonly());
164 template <class Inset, class Params>
165 void ControlInset<Inset, Params>::apply()
167 if (lv_.buffer()->isReadonly() || !inset_)
173 if (params() != getParams(*inset_)) applyParamsToInset();
175 applyParamsNoInset();
179 template <class Inset, class Params>
180 Params & ControlInset<Inset, Params>::params() const
187 template <class Inset, class Params>
188 Inset * ControlInset<Inset, Params>::inset() const
195 template <class Inset, class Params>
196 void ControlInset<Inset, Params>::updateSlot(bool switched)
205 template <class Inset, class Params>
206 void ControlInset<Inset, Params>::connectInset(Inset * inset)
208 // If connected to another inset, disconnect from it.
216 ih_ = inset->hideDialog.connect(
217 SigC::slot(this, &ControlInset::hide));
221 #endif // CONTROLINSET_H