]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInset.h
99236cdc84321118cfa7b6a74d938cd4e77a61a3
[lyx.git] / src / frontends / controllers / ControlInset.h
1 // -*- C++ -*-
2 /**
3  * \file ControlInset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS
10  *
11  * ControlInset is to be used as a parent class for dialogs that display and
12  * can perhaps modify the contents of an individual inset. An example being the
13  * ubiquitous Citation dialog.
14  */
15
16 #ifndef CONTROLINSET_H
17 #define CONTROLINSET_H
18
19 #include "ControlConnections.h"
20 #include "LString.h"
21
22 #include <boost/signals/connection.hpp>
23
24 class Inset;
25
26 template <class Inset, class Params>
27 class ControlInset : public ControlConnectBD {
28 public:
29         ///
30         ControlInset(LyXView &, Dialogs &);
31         /// Allow the View access to the local copy.
32         Params & params();
33         ///
34         Params const & params() const;
35
36         /// Slots connected in the daughter classes c-tor.
37         /// Slot launching dialog to (possibly) create a new inset.
38         void createInset(string const &);
39         /// Slot launching dialog to an existing inset.
40         void showInset(Inset *);
41 protected:
42         /// Allow the daughter methods to access the inset.
43         Inset * inset() const;
44 private:
45         /** These 7 methods are all that the individual daughter classes
46             should need to instantiate. */
47
48         /// if the inset exists then do this...
49         virtual void applyParamsToInset() = 0;
50         /// else this...
51         virtual void applyParamsNoInset() = 0;
52
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;
57
58         /** Most derived classes won't need these two, so they default to empty.
59          */
60
61         /// set any daughter class-particular data on show().
62         virtual void setDaughterParams() {}
63         /// clean-up any daughter class-particular data on hide().
64         virtual void clearDaughterParams() {}
65
66         /** Some dialogs may find it beneficial to disconnect from the inset
67          when the Apply button is pressed. E.g., doing this with the citation
68          dialog allows multiple citiations to be inserted easily. */
69         virtual bool disconnectOnApply() { return false; }
70
71         /// Instantiation of ControlButtons virtual methods.
72
73         /// Get changed parameters and Dispatch them to the kernel.
74         virtual void apply();
75         /// Disconnect signals and hide View.
76         virtual void hide();
77         /// Update the dialog.
78         virtual void update();
79
80         /** Instantiation of ControlConnectBD private virtual method.
81             Slot connected to update signal. */
82         virtual void updateSlot(bool);
83
84         /// Show the dialog.
85         void show(Params const &);
86         /// Connect signals
87         void connectInset(Inset * = 0);
88
89         /// pointer to the inset passed through connectInset
90         Inset * inset_;
91         /// inset::hide connection.
92         boost::signals::connection ih_;
93         /** A local copy of the inset's params.
94             Memory is allocated only whilst the dialog is visible.
95         */
96         Params * params_;
97
98         /// is the dialog built ?
99         bool dialog_built_;
100 };
101
102 #include "ControlInset.tmpl"
103
104 #endif // CONTROLINSET_H