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