4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
18 #include <boost/utility.hpp>
19 #include <boost/scoped_ptr.hpp>
23 class ButtonController;
26 /** \c Dialog collects the different parts of a Model-Controller-View
27 * split of a generic dialog together.
29 class Dialog : boost::noncopyable {
31 /// \param lv is the access point for the dialog to the LyX kernel.
32 /// \param name is the identifier given to the dialog by its parent
34 Dialog(LyXView & lv, std::string const & name);
37 /** The Dialog's name is the means by which a dialog identifies
38 * itself to the kernel.
40 std::string const & name() const { return name_; }
43 * These methods are publicly accessible because they are invoked
44 * by the View when the user presses... guess what ;-)
53 /** \name Container Access
54 * These methods are publicly accessible because they are invoked
55 * by the parent container acting on commands from the LyX kernel.
58 /// \param data is a string encoding of the data to be displayed.
59 /// It is passed to the Controller to be translated into a useable form.
60 void show(std::string const & data);
61 void update(std::string const & data);
64 bool isVisible() const;
66 /** This function is called, for example, if the GUI colours
72 /** When applying, it's useful to know whether the dialog is about
73 * to close or not (no point refreshing the display for example).
75 bool isClosing() const { return is_closing_; }
77 /** The LyX kernel is made available through this wrapper class.
78 * In an ideal world, it will shrink as more info is passed to the
79 * show() and update() methods.
81 Kernel & kernel() { return kernel_; }
83 /** Different dialogs will have different Controllers and Views.
84 * deriving from these base classes.
91 /** \name Dialog Specialization
92 * Methods to set the Controller and View and so specialise
93 * to a particular dialog.
96 /// \param ptr is stored and destroyed by \c Dialog.
97 void setController(Controller * ptr);
98 /// \param ptr is stored and destroyed by \c Dialog.
99 void setView(View * ptr);
102 /** \name Dialog Components
103 * Methods to access the various components making up a dialog.
106 Controller & controller() const;
107 ButtonController & bc() const;
117 boost::scoped_ptr<ButtonController> bc_ptr_;
118 boost::scoped_ptr<Controller> controller_ptr_;
119 boost::scoped_ptr<View> view_ptr_;
123 /** \c Dialog::Controller is an abstract base class for the Controller
124 * of a Model-Controller-View split of a generic dialog.
126 class Dialog::Controller : boost::noncopyable {
128 /// \param parent Dialog owning this Controller.
129 Controller(Dialog & parent);
130 virtual ~Controller() {}
132 /** \name Generic Controller
133 * These few methods are all that a generic dialog needs of a
137 /** Enable the controller to initialise its data structures.
138 * \param data is a string encoding of the parameters to be displayed.
139 * \return true if the translation was successful.
141 virtual bool initialiseParams(std::string const & data) = 0;
143 /// Enable the controller to clean up its data structures.
144 virtual void clearParams() = 0;
146 /// Enable the Controller to dispatch its data back to the LyX kernel.
147 virtual void dispatchParams() = 0;
149 /** \return true if the dialog should be shown only when
152 virtual bool isBufferDependent() const = 0;
154 /** \return true if the kernel should disconnect the dialog from
155 * a particular inset after the data has been applied to it.
156 * Clearly this makes sense only for dialogs modifying the contents
158 * In practise, only a very few dialogs (e.g. the citation dialog)
161 virtual bool disconnectOnApply() const { return false; }
165 /** \name Controller Access
166 * Enable the derived classes to access the other parts of the whole.
169 Dialog & dialog() { return parent_; }
170 Dialog const & dialog() const { return parent_; }
172 Kernel & kernel() { return parent_.kernel(); }
173 Kernel const & kernel() const { return parent_.kernel(); }
181 /** \c Dialog::View is an abstract base class to the View
182 * of a Model-Controller-View split of a generic dialog.
184 class Dialog::View : boost::noncopyable {
186 /** \param parent Dialog owning this Controller.
187 * \param title is the dialog title displayed by the WM.
189 View(Dialog & parent, std::string title);
192 /** \name Generic View
193 * These few methods are all that a generic dialog needs of a
197 /** A request to modify the data structures stored by the
198 * accompanying Controller in preparation for their dispatch to
201 virtual void apply() = 0;
203 /// Hide the dialog from sight
204 virtual void hide() = 0;
206 /// Redraw the dialog (e.g. if the colors have been remapped).
207 virtual void redraw() {}
209 /// Create the dialog if necessary, update it and display it.
210 virtual void show() = 0;
212 /// Update the display of the dialog whilst it is still visible.
213 virtual void update() = 0;
215 /// \return true if the dialog is visible.
216 virtual bool isVisible() const = 0;
219 /** Defaults to nothing. Can be used by the Controller, however, to
220 * indicate to the View that something has changed and that the
221 * dialog therefore needs updating.
222 * \param id identifies what should be updated.
224 virtual void partialUpdate(int id);
226 /// sets the title of the dialog (window caption)
227 void setTitle(std::string const &);
228 /// gets the title of the dialog (window caption)
229 std::string const & getTitle() const;
231 /** \name View Access
232 * Enable the derived classes to access the other parts of the whole.
235 Dialog & dialog() { return p_; }
236 Dialog const & dialog() const { return p_; }
239 Kernel & kernel() { return p_.kernel(); }
240 Kernel const & kernel() const { return p_.kernel(); }
242 Controller & getController() { return p_.controller(); }
243 Controller const & getController() const { return p_.controller(); }
245 ButtonController & bc() { return p_.bc(); }
246 ButtonController const & bc() const { return p_.bc(); }