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