]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ButtonController.tmpl
port the graphics dialog to the new scheme and get rid of the ControlInset
[lyx.git] / src / frontends / controllers / ButtonController.tmpl
1 // -*- C++ -*-
2 /**
3  * \file ButtonController.tmpl
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Allan Rae
8  * \author Angus Leeming
9  * \author Baruch Even
10  *
11  * Full author contact details are available in file CREDITS
12  *
13  * GuiBC is a base class and so these templatised methods will be
14  * instantiated if this file is #included in the derived classes' .C file.
15  * see, e.g., xforms/xformsBC.C
16  */
17
18 #include "ButtonController.h"
19 #include "debug.h"
20
21 template <class Button, class Widget>
22 GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
23         : ButtonControllerBase(cancel, close),
24           okay_(0), apply_(0), cancel_(0), restore_(0)
25 {}
26
27
28 template <class Button, class Widget>
29 void GuiBC<Button, Widget>::refresh()
30 {
31         lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
32
33         bool const all_valid = checkWidgets();
34
35         if (okay_) {
36                 bool const enabled =
37                         all_valid && bp().buttonStatus(ButtonPolicy::OKAY);
38                 setButtonEnabled(okay_, enabled);
39         }
40         if (apply_) {
41                 bool const enabled =
42                         all_valid && bp().buttonStatus(ButtonPolicy::APPLY);
43                 setButtonEnabled(apply_, enabled);
44         }
45         if (restore_) {
46                 bool const enabled =
47                         all_valid && bp().buttonStatus(ButtonPolicy::RESTORE);
48                 setButtonEnabled(restore_, enabled);
49         }
50         if (cancel_) {
51                 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
52                 if (enabled)
53                         setButtonLabel(cancel_, cancel_label_);
54                 else
55                         setButtonLabel(cancel_, close_label_);
56         }
57 }
58
59
60 template <class Button, class Widget>
61 void GuiBC<Button, Widget>::refreshReadOnly()
62 {
63         if (read_only_.empty()) return;
64
65         bool const enable = !bp().isReadOnly();
66
67         typename Widgets::const_iterator end = read_only_.end();
68         typename Widgets::const_iterator iter = read_only_.begin();
69         for (; iter != end; ++iter) {
70                 setWidgetEnabled(*iter, enable);
71         }
72 }
73
74
75 template <class BP, class GUIBC>
76 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
77                                               string const & close)
78         : GUIBC(cancel, close)
79 {}