]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlConnections.h
Move the external dialog to the new scheme.
[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
32 #include "ControlButtons.h"
33
34 #include <boost/signals/connection.hpp>
35
36 class Buffer;
37 class BufferView;
38 class Dialogs;
39 class LyXView;
40 class LyXFunc;
41
42 /** Base class to control connection/disconnection of signals with the LyX
43     kernel. It is meant to be used solely as the parent class to
44     ControlConnectBI and ControlConnectBD.
45 */
46 class ControlConnectBase : public ControlButtons {
47 public:
48         ///
49         enum DocTypes {
50                 ///
51                 LATEX,
52                 ///
53                 LITERATE,
54                 ///
55                 LINUXDOC,
56                 ///
57                 DOCBOOK
58         };
59         ///
60         ControlConnectBase(LyXView &, Dialogs &);
61         /// The View may need to know if the buffer is read-only.
62         bool bufferIsReadonly() const;
63         ///
64         DocTypes docType() const;
65 protected:
66         /// True if the dialog depends on the buffer, else false.
67         virtual bool isBufferDependent() const = 0;
68
69         /// Connect signals
70         virtual void connect();
71         /// Disconnect signals
72         virtual void disconnect();
73
74         /** Redraw the dialog (on receipt of a Signal indicating, for example,
75             its colors have been re-mapped).
76         */
77         void redraw();
78
79         /// a wrapper for BufferView::avaliable()
80         bool bufferIsAvailable() const;
81         /// a wrapper for LyXView::view()
82         BufferView * bufferview();
83         ///
84         BufferView const * bufferview() const;
85         /// a wrapper for LyXView::buffer()
86         Buffer * buffer();
87         ///
88         Buffer const * buffer() const;
89         /// a wrapper for LyXView::getLyXFunc()
90         LyXFunc & lyxfunc();
91         ///
92         LyXFunc const & lyxfunc() const;
93
94         ///
95         LyXView & lv_;
96         /// Contains the signals we have to connect to.
97         Dialogs & d_;
98         /// Hide connection.
99         boost::signals::connection h_;
100         /// Redraw connection.
101         boost::signals::connection r_;
102 };
103
104
105 /** Base class to control connection/disconnection of signals with the LyX
106     kernel for Buffer Independent dialogs.
107     Such dialogs do not require an update Connection although they may use
108     an update() function which is also supported by the Restore button.
109  */
110
111 class ControlConnectBI : public ControlConnectBase {
112 public:
113         ///
114         ControlConnectBI(LyXView &, Dialogs &);
115 protected:
116         ///
117         virtual bool isBufferDependent() const { return false; }
118         /// Connect signals
119         virtual void connect();
120 };
121
122
123 /** Base class to control connection/disconnection of signals with the LyX
124     kernel for Buffer Dependent dialogs.
125  */
126 class ControlConnectBD : public ControlConnectBase {
127 public:
128         ///
129         ControlConnectBD(LyXView &, Dialogs &);
130 protected:
131         ///
132         virtual bool isBufferDependent() const { return true; }
133         /// Connect signals
134         virtual void connect();
135         /// Disconnect signals
136         virtual void disconnect();
137 private:
138         /** Slot connected to update signal.
139             Bool indicates if a buffer switch took place.
140             Default behaviour is to ignore this and simply update().
141         */
142         virtual void updateSlot(bool) { update(); }
143         /// Update connection.
144         boost::signals::connection u_;
145 };
146
147 #endif // CONTROLCONNECTIONS_H