]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/BCView.h
Add a buffer_path arg to InsetGraphicsMailer's params2string, string2params.
[lyx.git] / src / frontends / controllers / BCView.h
1 // -*- C++ -*-
2 /**
3  * \file BCView.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  * \author Angus Leeming
9  * \author Baruch Even
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #ifndef BCVIEW_H
15 #define BCVIEW_H
16
17
18 #include "LString.h"
19 #include <boost/shared_ptr.hpp>
20 #include <list>
21
22
23 class ButtonController;
24 class ButtonPolicy;
25
26
27 /** \c CheckedWidget is an abstract base class that can be stored
28  *  in the button controller's view and can be interrogated by it
29  *  when the activation state of the Ok, Apply buttons is refreshed.
30  *  Ideally, the user will be prevented from returning invalid data
31  *  to the LyX kernel.
32  *
33  *  Many widgets can be grouped together in the derived class if they
34  *  make a logical whole. E.g., an input and a choice widget that together
35  *  are used to set a LyXLength can be interrogated together.
36  */
37 struct CheckedWidget {
38         ///
39         virtual ~CheckedWidget();
40
41         /** Returns true if the widget is in a valid state.
42         *  Might also change the visual appearance of the widget,
43         *  to reflect this state.
44         */
45         virtual bool check() const = 0;
46 };
47
48
49 /** \c BCView is the View to ButtonController's Controller. It
50  *  stores the individual GUI widgets and sets their activation state
51  *  upon receipt of instructions from the controller.
52  *
53  *  It is a base class. The true, GUI, instantiations derive from it.
54  */
55 class BCView {
56 public:
57         BCView(ButtonController const &);
58         virtual ~BCView() {}
59
60         //@{
61         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
62         virtual void refresh() const = 0;
63         /// Refresh the status of any widgets in the read_only list
64         virtual void refreshReadOnly() const = 0;
65         //@}
66
67         /// A shortcut to the BP of the BC.
68         ButtonPolicy & bp() const;
69
70         /** Add a widget to the list of all widgets whose validity should
71          *  be checked explicitly when the buttons are refreshed.
72          */
73         void addCheckedWidget(CheckedWidget * ptr);
74
75 protected:
76         /// \return true if all CheckedWidgets are in a valid state.
77         bool checkWidgets() const;
78
79 private:
80         typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
81         typedef std::list<checked_widget_ptr> checked_widget_list;
82         checked_widget_list checked_widgets;
83         ButtonController const & parent;
84 };
85
86
87 /** A templatised instantiation of the ButtonController's View requiring the
88  *  gui-frontend widgets.
89  */
90 template <class Button, class Widget>
91 class GuiBC : public BCView {
92 public:
93         ///
94         GuiBC(ButtonController const & parent,
95               string const & cancel, string const & close);
96
97         //@{
98         /** Store pointers to these widgets. The pointers are _not_
99          *  owned by GuiBC.
100          */
101         void setOK(Button * obj) { okay_ = obj; }
102         void setApply(Button * obj) { apply_ = obj; }
103         void setCancel(Button * obj) { cancel_ = obj; }
104         void setRestore(Button * obj) { restore_ = obj; }
105         //@}
106
107         /** Add a pointer to the list of widgets whose activation
108          *  state is dependent upon the read-only status of the
109          *  underlying buffer.
110          */
111         void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
112
113         /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
114         virtual void refresh() const;
115         /// Refresh the status of any widgets in the read_only list
116         virtual void refreshReadOnly() const;
117
118 private:
119         /// Enable/Disable a widget
120         virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0;
121         /// Enable/Disable a button
122         virtual void setButtonEnabled(Button * obj, bool enable) const = 0;
123         /// Set the Label on the button
124         virtual void setButtonLabel(Button * obj, string const & label) const = 0;
125
126         string const cancel_label_;
127         string const close_label_;
128
129         Button * okay_;
130         Button * apply_;
131         Button * cancel_;
132         Button * restore_;
133
134         typedef std::list<Widget *> Widgets;
135         Widgets read_only_;
136 };
137
138
139 #include "BCView.tmpl"
140
141 #endif // BCVIEW_H