]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlConnections.h
This file is part of LyX, the document processor.
[lyx.git] / src / frontends / controllers / ControlConnections.h
1 // -*- C++ -*-
2 /**
3  * \file ControlConnections.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  * ControlConnections.h contains the definition of three controller classes,
12  * ControlConnectBase, ControlConnectBI and ControlConnectBD.
13  *
14  * Together they control the connection/disconnection of signals with the LyX
15  * kernel. Controllers of individual dialogs interacting with the kernel through
16  * signals/slots will all be derived from ControlConnectBI or ControlConnectBD.
17  *
18  * A dialog is classed as "Buffer Dependent" if its contents change with the
19  * buffer (document). An example would be the Citation dialog. Such a dialog
20  * would be derived, therefore, from ControlConnectBD.
21  *
22  * Conversely, a dialog is "Buffer Independent" if its contents do not change
23  * when the buffer changes. An example would be the Copyright dialog. Such a
24  * dialog is therefore derived from ControlConnectBI.
25  *
26  */
27
28 #ifndef CONTROLCONNECTIONS_H
29 #define CONTROLCONNECTIONS_H
30
31 #ifdef __GNUG__
32 #pragma interface
33 #endif
34
35 #include "ControlButtons.h"
36
37 #include <boost/signals/connection.hpp>
38
39 class Buffer;
40 class BufferView;
41 class Dialogs;
42 class LyXView;
43 class LyXFunc;
44
45 /** Base class to control connection/disconnection of signals with the LyX
46     kernel. It is meant to be used solely as the parent class to
47     ControlConnectBI and ControlConnectBD.
48 */
49 class ControlConnectBase : public ControlButtons
50 {
51 public:
52         ///
53         enum DocTypes {
54                 ///
55                 LATEX,
56                 ///
57                 LITERATE,
58                 ///
59                 LINUXDOC,
60                 ///
61                 DOCBOOK
62         };
63         ///
64         ControlConnectBase(LyXView &, Dialogs &);
65         /// The View may need to know if the buffer is read-only.
66         bool bufferIsReadonly() const;
67         ///
68         DocTypes docType() const;
69
70 protected:
71         /// True if the dialog depends on the buffer, else false.
72         virtual bool isBufferDependent() const = 0;
73
74         /// Connect signals
75         virtual void connect();
76         /// Disconnect signals
77         virtual void disconnect();
78
79         /** Redraw the dialog (on receipt of a Signal indicating, for example,
80             its colors have been re-mapped).
81         */
82         void redraw();
83
84         /// a wrapper for BufferView::avaliable()
85         bool bufferIsAvailable() const;
86         /// a wrapper for LyXView::view()
87         BufferView * bufferview();
88         ///
89         BufferView const * bufferview() const;
90         /// a wrapper for LyXView::buffer()
91         Buffer * buffer();
92         ///
93         Buffer const * buffer() const;
94         /// a wrapper for LyXView::getLyXFunc()
95         LyXFunc & lyxfunc();
96         ///
97         LyXFunc const & lyxfunc() const;
98         
99
100         ///
101         LyXView & lv_;
102         /// Contains the signals we have to connect to.
103         Dialogs & d_;
104         /// Hide connection.
105         boost::signals::connection h_;
106         /// Redraw connection.
107         boost::signals::connection r_;
108 };
109
110
111 /** Base class to control connection/disconnection of signals with the LyX
112     kernel for Buffer Independent dialogs.
113     Such dialogs do not require an update Connection although they may use
114     an update() function which is also supported by the Restore button.
115  */
116
117 class ControlConnectBI : public ControlConnectBase
118 {
119 public:
120         ///
121         ControlConnectBI(LyXView &, Dialogs &);
122
123 protected:
124         ///
125         virtual bool isBufferDependent() const { return false; }
126         /// Connect signals
127         virtual void connect();
128 };
129
130
131 /** Base class to control connection/disconnection of signals with the LyX
132     kernel for Buffer Dependent dialogs.
133  */
134 class ControlConnectBD : public ControlConnectBase
135 {
136 public:
137         ///
138         ControlConnectBD(LyXView &, Dialogs &);
139
140 protected:
141         ///
142         virtual bool isBufferDependent() const { return true; }
143         /// Connect signals
144         virtual void connect();
145         /// Disconnect signals
146         virtual void disconnect();
147
148 private:
149         /** Slot connected to update signal.
150             Bool indicates if a buffer switch took place.
151             Default behaviour is to ignore this and simply update().
152         */
153         virtual void updateSlot(bool) { update(); }
154         /// Update connection.
155         boost::signals::connection u_;
156 };
157
158 #endif // CONTROLCONNECTIONS_H