]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlConnections.h
Implementation of controller-view split for FormCharacter.
[lyx.git] / src / frontends / controllers / ControlConnections.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 ControlConnections.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  */
14
15 #ifndef CONTROLCONNECTIONS_H
16 #define CONTROLCONNECTIONS_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "ControlBase.h"
23
24 /** Base class to control connection/disconnection of signals with the LyX
25     kernel. It is meant to be used solely as the parent class to
26     ControlConnectBI and ControlConnectBD.
27 */
28 class ControlConnectBase : public ControlBase
29 {
30 public:
31         ///
32         ControlConnectBase(LyXView &, Dialogs &);
33
34 protected:
35         /// Connect signals
36         virtual void connect();
37         /// Disconnect signals
38         virtual void disconnect();
39
40         /** Redraw the dialog (on receipt of a Signal indicating, for example,
41             its colors have been re-mapped).
42         */
43         void redraw();
44
45         /// Contains the signals we have to connect to.
46         Dialogs & d_;
47         /// Hide connection.
48         SigC::Connection h_;
49         /// Redraw connection.
50         SigC::Connection r_;
51 };
52
53
54 /** Base class to control connection/disconnection of signals with the LyX
55     kernel for Buffer Independent dialogs.
56     Such dialogs do not require an update Connection although they may use
57     an update() function which is also supported by the Restore button.
58  */
59
60 class ControlConnectBI : public ControlConnectBase
61 {
62 public:
63         ///
64         ControlConnectBI(LyXView &, Dialogs &);
65
66 protected:
67         /// Connect signals
68         virtual void connect();
69 };
70
71
72 /** Base class to control connection/disconnection of signals with the LyX
73     kernel for Buffer Dependent dialogs.
74  */
75 class ControlConnectBD : public ControlConnectBase
76 {
77 public:
78         ///
79         ControlConnectBD(LyXView &, Dialogs &);
80
81 protected:
82         /** Slot connected to update signal.
83             Bool indicates if a buffer switch took place.
84             Default behaviour is to ignore this and simply update().
85         */
86         virtual void updateSlot(bool) { update(); }
87         /// Connect signals
88         virtual void connect();
89         /// Disconnect signals
90         virtual void disconnect();
91
92 private:
93         /// Update connection.
94         SigC::Connection u_;
95 };
96
97 /** Base class to control connection/disconnection of signals with the LyX
98     kernel for Inset dialogs.
99  */
100 class Inset;
101
102 template <class Inset>
103 class ControlConnectInset : public ControlConnectBD
104 {
105 public:
106         ///
107         ControlConnectInset(LyXView &, Dialogs &);
108
109 protected:
110         /// Slot connected to update signal.
111         virtual void updateSlot(bool);
112         /// Connect signals
113         void connectInset(Inset * = 0);
114         /// Disconnect signals
115         virtual void disconnect();
116         ///
117         void disconnectInset();
118
119 protected:
120         /// pointer to the inset passed through connectInset
121         Inset * inset_;
122
123 private:
124         /// inset::hide connection.
125         SigC::Connection ih_;
126 };
127
128
129 template <class Inset>
130 ControlConnectInset<Inset>::ControlConnectInset(LyXView & lv, Dialogs & d)
131         : ControlConnectBD(lv, d),
132           inset_(0), ih_(0)
133 {}
134
135
136 template <class Inset>
137 void ControlConnectInset<Inset>::updateSlot(bool switched)
138 {
139         if (switched)
140                 hide();
141         else
142                 update();
143 }
144
145
146 template <class Inset>
147 void ControlConnectInset<Inset>::disconnect()
148 {
149         inset_ = 0;
150         ih_.disconnect();
151         ControlConnectBD::disconnect();
152 }
153
154
155 template <class Inset>
156 void ControlConnectInset<Inset>::connectInset(Inset * inset)
157 {
158         // If connected to another inset, disconnect from it.
159         if (inset_) {
160                 ih_.disconnect();
161                 inset_ = 0;
162         }
163
164         if (inset) {
165                 inset_ = inset;
166                 ih_ = inset->hideDialog.connect(
167                         SigC::slot(this, &ControlConnectInset::hide));
168         }
169         connect();
170 }
171
172
173 template <class Inset>
174 void ControlConnectInset<Inset>::disconnectInset()
175 {
176         ih_.disconnect();
177 }
178
179
180 #endif // CONTROLCONNECTIONS_H