]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ButtonController.h
891889e3a1cef8a82c34b9f50bac22c1ed1a0622
[lyx.git] / src / frontends / controllers / ButtonController.h
1 /*
2  * \file ButtonController.h
3  *
4  * This file is part of
5  * ====================================================== 
6  *
7  *           LyX, The Document Processor
8  *
9  *           Copyright 2000-2001 The LyX Team.
10  *
11  * ======================================================
12  *
13  * \author Allan Rae, rae@lyx.org
14  */
15
16 #ifndef BUTTONCONTROLLER_H
17 #define BUTTONCONTROLLER_H
18
19 #ifdef __GNUG__
20 #pragma interface
21 #endif
22
23 #include "ButtonPolicies.h"
24 #include "LString.h"
25 #include "gettext.h"
26
27 /** Abstract base class for a ButtonController
28
29  * Controls the activation of the OK, Apply and Cancel buttons.
30  * Actually supports 4 buttons in all and it's up to the user to decide on
31  * the activation policy and which buttons correspond to which output of the
32  * state machine.
33  * Author: Allan Rae <rae@lyx.org>.
34  * This abstract base class stripped of xforms-specific code by
35  * Angus Leeming <a.leeming@ic.ac.uk>
36  */
37 class ButtonControllerBase : public boost::noncopyable
38 {
39 public:
40         /** Constructor.
41             The cancel/close label entries are _not_ managed within the class
42             thereby allowing you to reassign at will and to use static labels.
43             It also means if you really don't want to have the Cancel button
44             label be different when there is nothing changed in the dialog then
45             you can just assign "Cancel" to both labels.  Or even reuse this
46             class for something completely different.
47          */
48         ButtonControllerBase(string const & cancel, string const & close);
49         ///
50         virtual ~ButtonControllerBase() {}
51         ///
52         virtual void refresh() = 0;
53         ///
54         virtual ButtonPolicy & bp() = 0;
55         ///
56         virtual void input(ButtonPolicy::SMInput);
57         ///
58         void ok();
59         ///
60         void apply();
61         ///
62         void cancel();
63         ///
64         void undoAll();
65         ///
66         void hide();
67         /// Passthrough function -- returns its input value
68         bool readOnly(bool = true);
69         ///
70         void readWrite();
71         ///
72         void valid(bool = true);
73         ///
74         void invalid();
75
76 protected:
77         ///
78         string cancel_label;
79         ///
80         string close_label;     
81 };
82
83
84 template <class BP, class GUIBC>
85 class ButtonController: public GUIBC
86 {
87 public:
88         ///
89         ButtonController(string const & = _("Cancel"),
90                          string const & = _("Close"));
91         ///
92         virtual ButtonPolicy & bp() { return bp_; }
93
94 protected:
95         ///
96         BP bp_;
97 };
98
99
100 template <class BP, class GUIBC>
101 ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
102                                               string const & close)
103         : GUIBC(cancel, close)
104 {}
105
106 #endif // BUTTONCONTROLLER_H