]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/BCView.tmpl
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / BCView.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 "BCView.h"
19 #include "ButtonPolicies.h"
20 #include "debug.h"
21
22 namespace lyx {
23 namespace frontend {
24
25 template <class Button, class Widget>
26 GuiBC<Button, Widget>::GuiBC(ButtonController const & parent,
27                              std::string const & cancel, std::string const & close)
28         : BCView(parent),
29           cancel_label_(cancel), close_label_(close),
30           okay_(0), apply_(0), cancel_(0), restore_(0)
31 {}
32
33
34 template <class Button, class Widget>
35 void GuiBC<Button, Widget>::refresh() const
36 {
37         lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
38
39         bool const all_valid = checkWidgets();
40
41         if (okay_) {
42                 bool const enabled =
43                         all_valid && bp().buttonStatus(ButtonPolicy::OKAY);
44                 setButtonEnabled(okay_, enabled);
45         }
46         if (apply_) {
47                 bool const enabled =
48                         all_valid && bp().buttonStatus(ButtonPolicy::APPLY);
49                 setButtonEnabled(apply_, enabled);
50         }
51         if (restore_) {
52                 bool const enabled =
53                         all_valid && bp().buttonStatus(ButtonPolicy::RESTORE);
54                 setButtonEnabled(restore_, enabled);
55         }
56         if (cancel_) {
57                 bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
58                 if (enabled)
59                         setButtonLabel(cancel_, cancel_label_);
60                 else
61                         setButtonLabel(cancel_, close_label_);
62         }
63 }
64
65
66 template <class Button, class Widget>
67 void GuiBC<Button, Widget>::refreshReadOnly() const
68 {
69         if (read_only_.empty()) return;
70
71         bool const enable = !bp().isReadOnly();
72
73         typename Widgets::const_iterator end = read_only_.end();
74         typename Widgets::const_iterator iter = read_only_.begin();
75         for (; iter != end; ++iter) {
76                 setWidgetEnabled(*iter, enable);
77         }
78 }
79
80 } // namespace frontend
81 } // namespace lyx