]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ButtonControllerBase.C
Rob's patch, part 1: the checked widget stuff.
[lyx.git] / src / frontends / controllers / ButtonControllerBase.C
1 /**
2  * \file ButtonControllerBase.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Allan Rae
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <config.h>
16 #include "ButtonControllerBase.h"
17 #include "support/LAssert.h"
18 #include "debug.h"
19
20
21 CheckedWidget::~CheckedWidget()
22 {}
23
24
25 ButtonControllerBase::ButtonControllerBase(string const & cancel,
26                                            string const & close)
27         : cancel_label_(cancel), close_label_(close)
28 {}
29
30
31 void ButtonControllerBase::ok()
32 {
33         input(ButtonPolicy::SMI_OKAY);
34 }
35
36
37 void ButtonControllerBase::input(ButtonPolicy::SMInput in)
38 {
39         if (ButtonPolicy::SMI_NOOP == in)
40                 return;
41         bp().input(in);
42         refresh();
43 }
44
45
46 void ButtonControllerBase::apply()
47 {
48         input(ButtonPolicy::SMI_APPLY);
49 }
50
51
52 void ButtonControllerBase::cancel()
53 {
54         input(ButtonPolicy::SMI_CANCEL);
55 }
56
57
58 void ButtonControllerBase::restore()
59 {
60         input(ButtonPolicy::SMI_RESTORE);
61 }
62
63
64 void ButtonControllerBase::hide()
65 {
66         input(ButtonPolicy::SMI_HIDE);
67 }
68
69
70 void ButtonControllerBase::valid(bool v)
71 {
72         if (v) {
73                 input(ButtonPolicy::SMI_VALID);
74         } else {
75                 input(ButtonPolicy::SMI_INVALID);
76         }
77 }
78
79
80 void ButtonControllerBase::invalid()
81 {
82         input(ButtonPolicy::SMI_INVALID);
83 }
84
85
86 bool ButtonControllerBase::readOnly(bool ro)
87 {
88         lyxerr[Debug::GUI] << "Setting controller ro: " << ro << std::endl;
89
90         if (ro) {
91                 bp().input(ButtonPolicy::SMI_READ_ONLY);
92         } else {
93                 bp().input(ButtonPolicy::SMI_READ_WRITE);
94         }
95         refreshReadOnly();
96         refresh();
97         return ro;
98 }
99
100
101 void ButtonControllerBase::readWrite()
102 {
103         readOnly(false);
104 }
105
106
107 void ButtonControllerBase::addCheckedWidget(CheckedWidget * ptr)
108 {
109         if (ptr)
110                 checked_widgets.push_back(checked_widget_ptr(ptr));
111 }
112
113
114 bool ButtonControllerBase::checkWidgets()
115 {
116         bool valid = true;
117
118         checked_widget_list::const_iterator it  = checked_widgets.begin();
119         checked_widget_list::const_iterator end = checked_widgets.end();
120
121         for (; it != end; ++it) {
122                 valid &= (*it)->check();
123         }
124
125         // return valid status after checking ALL widgets
126         return valid;
127 }
128