2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2001 The LyX Team.
9 * ======================================================
11 * \file ControlConnections.h
12 * \author Angus Leeming <leeming@lyx.org>
14 * ControlConnections.h contains the definition of three controller classes,
15 * ControlConnectBase, ControlConnectBI and ControlConnectBD.
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.
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.
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.
31 #ifndef CONTROLCONNECTIONS_H
32 #define CONTROLCONNECTIONS_H
38 #include "ControlButtons.h"
40 #include <boost/signals/connection.hpp>
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.
52 class ControlConnectBase : public ControlButtons
67 ControlConnectBase(LyXView &, Dialogs &);
68 /// The View may need to know if the buffer is read-only.
69 bool bufferIsReadonly() const;
71 DocTypes docType() const;
74 /// True if the dialog depends on the buffer, else false.
75 virtual bool isBufferDependent() const = 0;
78 virtual void connect();
79 /// Disconnect signals
80 virtual void disconnect();
82 /** Redraw the dialog (on receipt of a Signal indicating, for example,
83 its colors have been re-mapped).
87 /// a wrapper for BufferView::avaliable()
88 bool bufferIsAvailable() const;
89 /// a wrapper for LyXView::view()
90 BufferView * bufferview();
92 BufferView const * bufferview() const;
93 /// a wrapper for LyXView::buffer()
96 Buffer const * buffer() const;
97 /// a wrapper for LyXView::getLyXFunc()
100 LyXFunc const & lyxfunc() const;
105 /// Contains the signals we have to connect to.
108 boost::signals::connection h_;
109 /// Redraw connection.
110 boost::signals::connection r_;
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.
120 class ControlConnectBI : public ControlConnectBase
124 ControlConnectBI(LyXView &, Dialogs &);
128 virtual bool isBufferDependent() const { return false; }
130 virtual void connect();
134 /** Base class to control connection/disconnection of signals with the LyX
135 kernel for Buffer Dependent dialogs.
137 class ControlConnectBD : public ControlConnectBase
141 ControlConnectBD(LyXView &, Dialogs &);
145 virtual bool isBufferDependent() const { return true; }
147 virtual void connect();
148 /// Disconnect signals
149 virtual void disconnect();
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().
156 virtual void updateSlot(bool) { update(); }
157 /// Update connection.
158 boost::signals::connection u_;
161 #endif // CONTROLCONNECTIONS_H