]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInset.h
Nothing but a changed email address (trying to factor my tree in in small steps)
[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 <leeming@lyx.org>
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         /// Slots connected in the daughter classes c-tor.
41         /// Slot launching dialog to (possibly) create a new inset.
42         void createInset(string const &);
43         /// Slot launching dialog to an existing inset.
44         void showInset(Inset *);
45
46 protected:
47         /// Allow the daughter methods to access the inset.
48         Inset * inset() const;
49
50 private:
51         /** These 7 methods are all that the individual daughter classes
52             should need to instantiate. */
53
54         /// if the inset exists then do this...
55         virtual void applyParamsToInset() = 0;
56         /// else this...
57         virtual void applyParamsNoInset() = 0;
58
59         /// get the parameters from the string passed to createInset.
60         virtual Params const getParams(string const &) = 0;
61         /// get the parameters from the inset passed to showInset.
62         virtual Params const getParams(Inset const &) = 0;
63
64         /** Most derived classes won't need these two, so they default to empty.
65          */
66
67         /// set any daughter class-particular data on show().
68         virtual void setDaughterParams() {}
69         /// clean-up any daughter class-particular data on hide().
70         virtual void clearDaughterParams() {}
71
72         /** Some dialogs may find it beneficial to disconnect from the inset
73          when the Apply button is pressed. E.g., doing this with the citation
74          dialog allows multiple citiations to be inserted easily. */
75         virtual bool disconnectOnApply() { return false; }
76
77
78
79         /// Instantiation of ControlButtons virtual methods.
80
81         /// Get changed parameters and Dispatch them to the kernel.
82         virtual void apply();
83         /// Disconnect signals and hide View.
84         virtual void hide();
85         /// Update the dialog.
86         virtual void update();
87
88         /** Instantiation of ControlConnectBD private virtual method.
89             Slot connected to update signal. */
90         virtual void updateSlot(bool);
91
92         /// Show the dialog.
93         void show(Params const &);
94         /// Connect signals
95         void connectInset(Inset * = 0);
96
97         /// pointer to the inset passed through connectInset
98         Inset * inset_;
99         /// inset::hide connection.
100         boost::signals::connection ih_;
101         /** A local copy of the inset's params.
102             Memory is allocated only whilst the dialog is visible.
103         */
104         Params * params_;
105
106         /// is the dialog built ?
107         bool dialog_built_;
108
109 };
110
111 #include "ControlInset.tmpl"
112
113 #endif // CONTROLINSET_H
114