]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/ButtonController.h
changes read the dirr and changelog, something should be remvoed/changed
[lyx.git] / src / frontends / xforms / ButtonController.h
1 // -*- C++ -*-
2 /* ButtonController.h
3  * Controls the activation of the OK, Apply and Cancel buttons.
4  * Actually supports 4 buttons in all and it's up to the user to decide on
5  * the activation policy and which buttons correspond to which output of the
6  * state machine.
7  * Author: Allan Rae <rae@lyx.org>
8  * This file is part of
9  * ======================================================
10  *
11  *           LyX, The Document Processor
12  *
13  *           Copyright 1995 Matthias Ettrich
14  *           Copyright 1995-2000 The LyX Team.
15  *
16  *           This file Copyright 2000
17  *           Allan Rae
18  * ======================================================
19  */
20
21 #ifndef BUTTONCONTROLLER_H
22 #define BUTTONCONTROLLER_H
23
24 #include "ButtonPolicies.h"
25 #include <list>
26
27 #ifdef __GNUG__
28 #pragma interface
29 #endif
30
31 /** General purpose button controller for up to four buttons.
32     Controls the activation of the OK, Apply and Cancel buttons.
33     Actually supports 4 buttons in all and it's up to the user to decide on
34     the activation policy and which buttons correspond to which output of the
35     state machine.
36     @author Allan Rae <rae@lyx.org>
37     20001001 Switch from template implementation to taking Policy parameter.
38              Allows FormBase to provide a ButtonController for any dialog.
39 */
40 class ButtonController : public noncopyable
41 {
42 public:
43         /** Constructor.
44             The cancel/close label entries are _not_ managed within the class
45             thereby allowing you to reassign at will and to use static labels.
46             It also means if you really don't want to have the Cancel button
47             label be different when there is nothing changed in the dialog then
48             you can just assign "Cancel" to both labels.  Or even reuse this
49             class for something completely different.
50          */
51         ButtonController(ButtonPolicy * bp,
52                          char const * cancel, char const * close);
53
54         // Somebody else owns the FL_OBJECTs we just manipulate them.
55         // so? (Lgb)
56         //~ButtonController() {}
57
58         /* Initialise Button Functions */
59         /// Call refresh() when finished setting the buttons.
60         void setOK(FL_OBJECT * obj) {
61                 okay_ = obj;
62         }
63         ///
64         void setApply(FL_OBJECT * obj) {
65                 apply_ = obj;
66         }
67         ///
68         void setCancel(FL_OBJECT * obj) {
69                 cancel_ = obj;
70         }
71         ///
72         void setUndoAll(FL_OBJECT * obj) {
73                 undo_all_ = obj;
74         }
75         ///
76         void setCancelTrueLabel(char const * c) {
77                 cancel_label = c;
78         }
79         ///
80         void setCancelFalseLabel(char const * c) {
81                 close_label = c;
82         }
83         ///
84         void addReadOnly(FL_OBJECT * obj) {
85                 read_only_.push_front(obj);
86         }
87         ///
88         void eraseReadOnly() {
89                 read_only_.erase(read_only_.begin(), read_only_.end());
90         }
91
92         /* Action Functions */
93         /// force a refresh of the buttons
94         void refresh();
95
96         ///
97         void input(ButtonPolicy::SMInput in);
98         ///
99         void ok();
100         ///
101         void apply();
102         ///
103         void cancel();
104         ///
105         void undoAll();
106         ///
107         void hide();
108         /// Passthrough function -- returns its input value
109         bool readOnly(bool ro = true);
110         ///
111         void readWrite();
112         /// Passthrough function -- returns its input value
113         bool valid(bool v = true);
114         ///
115         void invalid();
116 private:
117         ///
118         ButtonPolicy * bp_;
119         ///
120         FL_OBJECT * okay_;
121         ///
122         FL_OBJECT * apply_;
123         ///
124         FL_OBJECT * cancel_;
125         ///
126         FL_OBJECT * undo_all_;
127         /// List of items to be deactivated when in one of the read-only states
128         std::list<FL_OBJECT *> read_only_;
129         ///
130         char const * cancel_label;
131         ///
132         char const * close_label;       
133 };
134
135 #endif