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