]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/ButtonController.h
try this for distinguishing inner and outer tabs
[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         ///
93         void addDontTriggerChange(FL_OBJECT * obj) {
94                 dont_trigger_change_.push_back(obj);
95         }
96         ///
97         void eraseDontTriggerChange() {
98                 dont_trigger_change_.clear();
99         }
100
101         /* Action Functions */
102         /// force a refresh of the buttons
103         void refresh();
104
105         ///
106         void input(ButtonPolicy::SMInput in);
107         ///
108         void ok();
109         ///
110         void apply();
111         ///
112         void cancel();
113         ///
114         void undoAll();
115         ///
116         void hide();
117         /// Passthrough function -- returns its input value
118         bool readOnly(bool ro = true);
119         ///
120         void readWrite();
121         /// Passthrough function -- returns its input value
122         bool valid(bool v = true, FL_OBJECT * obj = 0);
123         ///
124         void invalid();
125 private:
126         ///
127         ButtonPolicy * bp_;
128         ///
129         FL_OBJECT * okay_;
130         ///
131         FL_OBJECT * apply_;
132         ///
133         FL_OBJECT * cancel_;
134         ///
135         FL_OBJECT * undo_all_;
136         /// List of items to be deactivated when in one of the read-only states
137         std::list<FL_OBJECT *> read_only_;
138         /// container of items that do not trigger a change in activation status
139         std::vector<FL_OBJECT *> dont_trigger_change_;
140         ///
141         char const * cancel_label;
142         ///
143         char const * close_label;       
144 };
145
146 #endif