]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlDialogs.h
The reference dialog now disconnects from the inset on Apply. Its behaviour
[lyx.git] / src / frontends / controllers / ControlDialogs.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 ControlDialogs.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  *
14  * ControlDialog is to be used as a parent class for dialogs that are not
15  * views onto parameters of insets. (An ugly description I know, but I hope 
16  * the meaning is clear!  * Can anyone do any better?) Examples would be the 
17  * Document and Paragraph dialogs.
18  */
19
20 #ifndef CONTROLDIALOGS_H
21 #define CONTROLDIALOGS_H
22
23 #include "ControlConnections.h"
24 #include "debug.h"
25
26 /** Base class to control connection/disconnection of signals with the LyX
27     kernel for dialogs NOT used with insets.
28     The Base class will be either ControlConnectBI or ControlConnectBD.
29  */
30 template <class Base>
31 class ControlDialog : public Base
32 {
33 public:
34         ///
35         ControlDialog(LyXView &, Dialogs &);
36
37 protected:
38         /// Show the dialog.
39         virtual void show();
40         /// Hide the dialog.
41         virtual void hide();
42         /// Update the dialog.
43         virtual void update();
44
45         /// clean-up on hide.
46         virtual void clearParams() {}
47         /// set the params before show or update
48         virtual void setParams() {}
49
50 private:
51         /// is the dialog built ?
52         bool dialog_built_;
53 };
54
55
56 #include "LyXView.h"
57
58 template <class Base>
59 ControlDialog<Base>::ControlDialog(LyXView & lv, Dialogs & d)
60         : Base(lv, d), dialog_built_(false)
61 {}
62
63
64 template <class Base>
65 void ControlDialog<Base>::show()
66 {
67         if (isBufferDependent() && !lv_.view()->available())
68                 return;
69
70         connect();
71
72         setParams();
73
74         if (!dialog_built_) {
75                 view().build();
76                 dialog_built_ = true;
77         }
78
79         bc().readOnly(isReadonly());
80         view().show();
81 }
82
83 template <class Base>
84 void ControlDialog<Base>::update()
85 {
86         if (isBufferDependent() && !lv_.view()->available())
87                 return;
88
89         setParams();
90
91         bc().readOnly(isReadonly());
92         view().update();
93 }
94
95 template <class Base>
96 void ControlDialog<Base>::hide()
97 {
98         clearParams();
99
100         disconnect();
101         view().hide();
102 }
103
104 #endif // CONTROLDIALOGS_H