]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlDialogs.h
John's character.C patch (bug fix).
[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
25 /** Base class to control connection/disconnection of signals with the LyX
26     kernel for dialogs NOT used with insets.
27     The Base class will be either ControlConnectBI or ControlConnectBD.
28  */
29 template <class Base>
30 class ControlDialog : public Base
31 {
32 public:
33         ///
34         ControlDialog(LyXView &, Dialogs &);
35
36 protected:
37         /// Show the dialog.
38         virtual void show();
39         /// Hide the dialog.
40         virtual void hide();
41         /// Update the dialog.
42         virtual void update();
43
44         /// clean-up on hide.
45         virtual void clearParams() {}
46         /// set the params before show or update
47         virtual void setParams() {}
48 };
49
50
51 #include "LyXView.h"
52
53 template <class Base>
54 ControlDialog<Base>::ControlDialog(LyXView & lv, Dialogs & d)
55         : Base(lv, d)
56 {}
57
58
59 template <class Base>
60 void ControlDialog<Base>::show()
61 {
62         if (isBufferDependent() && !lv_.view()->available())
63                 return;
64
65         setParams();
66
67         static bool isBuilt = false;
68         if (!isBuilt) {
69                 isBuilt = true;
70                 view().build();
71         }
72
73         bc().readOnly(isReadonly());
74         view().show();
75 }
76
77 template <class Base>
78 void ControlDialog<Base>::update()
79 {
80         if (isBufferDependent() && !lv_.view()->available())
81                 return;
82
83         setParams();
84
85         bc().readOnly(isReadonly());
86         // Reset the Button Controller to it's initial state
87         bc().invalid();
88         bc().restore();
89
90         view().update();
91 }
92
93 template <class Base>
94 void ControlDialog<Base>::hide()
95 {
96         clearParams();
97
98         disconnect();
99         view().hide();
100 }
101
102 #endif // CONTROLDIALOGS_H