]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlDialogs.h
John's controller patch
[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         /// is the dialog built ?
51         bool dialog_built_;
52 };
53
54
55 #include "LyXView.h"
56
57 template <class Base>
58 ControlDialog<Base>::ControlDialog(LyXView & lv, Dialogs & d)
59         : Base(lv, d), dialog_built_(false)
60 {}
61
62
63 template <class Base>
64 void ControlDialog<Base>::show()
65 {
66         if (isBufferDependent() && !lv_.view()->available())
67                 return;
68
69         setParams();
70
71         if (!dialog_built_) {
72                 view().build();
73                 dialog_built_ = true;
74         }
75
76         bc().readOnly(isReadonly());
77         view().show();
78 }
79
80 template <class Base>
81 void ControlDialog<Base>::update()
82 {
83         if (isBufferDependent() && !lv_.view()->available())
84                 return;
85
86         setParams();
87
88         bc().readOnly(isReadonly());
89         view().update();
90 }
91
92 template <class Base>
93 void ControlDialog<Base>::hide()
94 {
95         clearParams();
96
97         disconnect();
98         view().hide();
99 }
100
101 #endif // CONTROLDIALOGS_H