]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlConnections.h
Create a grfx::Loader class and so move large chunks of code out of
[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 <a.leeming@ic.ac.uk>
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 Dialogs;
43 class LyXView;
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 isReadonly() 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         /// Get at the kernel Dispatch methods we need to apply() parameters.
85         LyXView & lv_;
86         /// Contains the signals we have to connect to.
87         Dialogs & d_;
88         /// Hide connection.
89         boost::signals::connection h_;
90         /// Redraw connection.
91         boost::signals::connection r_;
92 };
93
94
95 /** Base class to control connection/disconnection of signals with the LyX
96     kernel for Buffer Independent dialogs.
97     Such dialogs do not require an update Connection although they may use
98     an update() function which is also supported by the Restore button.
99  */
100
101 class ControlConnectBI : public ControlConnectBase
102 {
103 public:
104         ///
105         ControlConnectBI(LyXView &, Dialogs &);
106
107 protected:
108         ///
109         virtual bool isBufferDependent() const { return false; }
110         /// Connect signals
111         virtual void connect();
112 };
113
114
115 /** Base class to control connection/disconnection of signals with the LyX
116     kernel for Buffer Dependent dialogs.
117  */
118 class ControlConnectBD : public ControlConnectBase
119 {
120 public:
121         ///
122         ControlConnectBD(LyXView &, Dialogs &);
123
124 protected:
125         ///
126         virtual bool isBufferDependent() const { return true; }
127         /// Connect signals
128         virtual void connect();
129         /// Disconnect signals
130         virtual void disconnect();
131
132 private:
133         /** Slot connected to update signal.
134             Bool indicates if a buffer switch took place.
135             Default behaviour is to ignore this and simply update().
136         */
137         virtual void updateSlot(bool) { update(); }
138         /// Update connection.
139         boost::signals::connection u_;
140 };
141
142 #endif // CONTROLCONNECTIONS_H