]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlDialogs.h
4026d20daa4d6bc6a47f0d2361ab81fbf3a16f4a
[lyx.git] / src / frontends / controllers / ControlDialogs.h
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlDialogs.h
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  *
13  * ControlDialogs.h contains the definition of two template controller classes,
14  * ControlDialog and ControlInset, rather clumsy names for classes that
15  * control the showing, updating and hiding of popups.
16  *
17  * ControlInset is to be used as a parent class for popups that display and
18  * can perhaps modify the contents of an individual inset. An example being the
19  * ubiquitous Citation popup.
20  *
21  * ControlDialog is to be used as a parent class for popups that are not
22  * Inset-popups. (An ugly description I know, but I hope the meaning is clear!
23  * Can anyone do any better?) Examples would be the Document and Paragraph
24  * popups.
25  *
26  * At the moment, ControlDialog is reaching a state of maturity as several
27  * controllers are now derived from it and its required functionality
28  * becaomes clear.
29  *
30  * ControlInset is still in a state of flux as currently only InsetCommand-type
31  * insets have a controller.
32  *
33  */
34
35 #ifndef CONTROLCONNECTIONS2_H
36 #define CONTROLCONNECTIONS2_H
37
38 #include "ControlConnections.h"
39 #include "LyXView.h"
40
41 /** Base class to control connection/disconnection of signals with the LyX
42     kernel for dialogs NOT used with insets.
43     The Base class will be either ControlConnectBI or ControlConnectBD.
44  */
45 template <class Base>
46 class ControlDialog : public Base
47 {
48 public:
49         ///
50         ControlDialog(LyXView &, Dialogs &);
51
52 protected:
53         /// Show the dialog.
54         virtual void show();
55         /// Hide the dialog.
56         virtual void hide();
57         /// Update the dialog.
58         virtual void update();
59
60         /// set the params before show or update
61         virtual void setParams() {}
62         /// clean-up on hide.
63         virtual void clearParams() {}
64 };
65
66
67 /** Base class to control connection/disconnection of signals with the LyX
68     kernel for Inset dialogs.
69  */
70 class Inset;
71
72 template <class Inset>
73 class ControlInset : public ControlConnectBD
74 {
75 public:
76         ///
77         ControlInset(LyXView &, Dialogs &);
78
79 protected:
80         /// Slot connected to update signal.
81         virtual void updateSlot(bool);
82         /// Connect signals
83         void connectInset(Inset * = 0);
84         /// Disconnect signals
85         virtual void disconnect();
86         ///
87         void disconnectInset();
88
89 protected:
90         /// pointer to the inset passed through connectInset
91         Inset * inset_;
92
93 private:
94         /// inset::hide connection.
95         SigC::Connection ih_;
96 };
97
98
99
100
101
102 template <class Base>
103 ControlDialog<Base>::ControlDialog(LyXView & lv, Dialogs & d)
104         : Base(lv, d)
105 {}
106
107
108 template <class Base>
109 void ControlDialog<Base>::show()
110 {
111         if (isBufferDependent() && !lv_.view()->available())
112                 return;
113
114         setParams();
115
116         bc().readOnly(isReadonly());
117         view().show();
118 }
119
120 template <class Base>
121 void ControlDialog<Base>::update()
122 {
123         if (isBufferDependent() && !lv_.view()->available())
124                 return;
125
126         setParams();
127         
128         bc().readOnly(isReadonly());
129         view().update();
130 }
131
132 template <class Base>
133 void ControlDialog<Base>::hide()
134 {
135         clearParams();
136
137         disconnect();
138         view().hide();
139 }
140
141
142 template <class Inset>
143 ControlInset<Inset>::ControlInset(LyXView & lv, Dialogs & d)
144         : ControlConnectBD(lv, d),
145           inset_(0), ih_(0)
146 {}
147
148
149 template <class Inset>
150 void ControlInset<Inset>::updateSlot(bool switched)
151 {
152         if (switched)
153                 hide();
154         else
155                 update();
156 }
157
158
159 template <class Inset>
160 void ControlInset<Inset>::disconnect()
161 {
162         inset_ = 0;
163         ih_.disconnect();
164         ControlConnectBD::disconnect();
165 }
166
167
168 template <class Inset>
169 void ControlInset<Inset>::connectInset(Inset * inset)
170 {
171         // If connected to another inset, disconnect from it.
172         if (inset_) {
173                 ih_.disconnect();
174                 inset_ = 0;
175         }
176
177         if (inset) {
178                 inset_ = inset;
179                 ih_ = inset->hideDialog.connect(
180                         SigC::slot(this, &ControlInset::hide));
181         }
182         connect();
183 }
184
185
186 template <class Inset>
187 void ControlInset<Inset>::disconnectInset()
188 {
189         ih_.disconnect();
190 }
191
192
193 #endif // CONTROLCONNECTIONS2_H