]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ButtonControllerBase.h
Lars says _(_(b)) is a bug ... fix
[lyx.git] / src / frontends / controllers / ButtonControllerBase.h
1 // -*- C++ -*-
2 /**
3  * \file ButtonControllerBase.h
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  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef BUTTONCONTROLLERBASE_H
13 #define BUTTONCONTROLLERBASE_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "ButtonPolicies.h"
20 #include "LString.h"
21
22 #include <boost/shared_ptr.hpp>
23 #include <list>
24
25 struct CheckedWidget {
26         ///
27         virtual ~CheckedWidget();
28
29         /** Returns true if the widget is in a valid state.
30         *  Might also change the visual appearance of the widget,
31         *  to reflect this state.
32         */
33         virtual bool check() const = 0;
34 };
35
36
37 /** Abstract base class for a ButtonController
38
39  * Controls the activation of the OK, Apply and Cancel buttons.
40  * Actually supports 4 buttons in all and it's up to the user to decide on
41  * the activation policy and which buttons correspond to which output of the
42  * state machine.
43  * Author: Allan Rae <rae@lyx.org>.
44  * This abstract base class stripped of xforms-specific code by
45  * Angus Leeming <leeming@lyx.org>
46  */
47 class ButtonControllerBase : boost::noncopyable {
48 public:
49         /** Constructor.
50             The cancel/close label entries are _not_ managed within the class
51             thereby allowing you to reassign at will and to use static labels.
52             It also means if you really don't want to have the Cancel button
53             label be different when there is nothing changed in the dialog then
54             you can just assign "Cancel" to both labels.  Or even reuse this
55             class for something completely different.
56          */
57         ButtonControllerBase(string const & cancel, string const & close);
58         ///
59         virtual ~ButtonControllerBase() {}
60         ///
61         virtual ButtonPolicy & bp() = 0;
62         ///
63         virtual void input(ButtonPolicy::SMInput);
64         ///
65         void ok();
66         ///
67         void apply();
68         ///
69         void cancel();
70         ///
71         void restore();
72         ///
73         void hide();
74         ///
75         virtual void refresh() = 0;
76         ///
77         virtual void refreshReadOnly() = 0;
78
79         /// Passthrough function -- returns its input value
80         bool readOnly(bool = true);
81         ///
82         void readWrite();
83         ///
84         void valid(bool = true);
85         ///
86         void invalid();
87         ///
88         void addCheckedWidget(CheckedWidget * ptr);
89
90 protected:
91         ///
92         string cancel_label_;
93         ///
94         string close_label_;
95         ///
96         bool checkWidgets();
97
98 private:
99         ///
100         typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
101         typedef std::list<checked_widget_ptr> checked_widget_list;
102         ///
103         checked_widget_list checked_widgets;
104 };
105
106 #endif // BUTTONCONTROLLERBASE_H