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