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.
17 #include <boost/utility.hpp>
18 #include <boost/scoped_ptr.hpp>
25 class ButtonController;
27 /** \c Dialog collects the different parts of a Model-Controller-View
28 * split of a generic dialog together.
30 class Dialog : boost::noncopyable {
32 /// \param lv is the access point for the dialog to the LyX kernel.
33 /// \param name is the identifier given to the dialog by its parent
35 Dialog(LyXView & lv, std::string const & name);
38 /** The Dialog's name is the means by which a dialog identifies
39 * itself to the kernel.
41 std::string const & name() const { return name_; }
44 * These methods are publicly accessible because they are invoked
45 * by the View when the user presses... guess what ;-)
54 /** \name Container Access
55 * These methods are publicly accessible because they are invoked
56 * by the parent container acting on commands from the LyX kernel.
59 /// \param data is a string encoding of the data to be displayed.
60 /// It is passed to the Controller to be translated into a useable form.
61 void show(std::string const & data);
62 void update(std::string const & data);
65 bool isVisible() const;
67 /** This function is called, for example, if the GUI colours
73 /** Check wether we may apply our data.
75 * The buttons are disabled if not and (re-)enabled if yes.
79 /** When applying, it's useful to know whether the dialog is about
80 * to close or not (no point refreshing the display for example).
82 bool isClosing() const { return is_closing_; }
84 /** The LyX kernel is made available through this wrapper class.
85 * In an ideal world, it will shrink as more info is passed to the
86 * show() and update() methods.
88 Kernel & kernel() { return kernel_; }
90 /** Different dialogs will have different Controllers and Views.
91 * deriving from these base classes.
98 /** \name Dialog Specialization
99 * Methods to set the Controller and View and so specialise
100 * to a particular dialog.
103 /// \param ptr is stored and destroyed by \c Dialog.
104 void setController(Controller * ptr);
105 /// \param ptr is stored and destroyed by \c Dialog.
106 void setView(View * ptr);
109 /** \name Dialog Components
110 * Methods to access the various components making up a dialog.
113 Controller & controller() const;
114 ButtonController & bc() const;
124 boost::scoped_ptr<ButtonController> bc_ptr_;
125 boost::scoped_ptr<Controller> controller_ptr_;
126 boost::scoped_ptr<View> view_ptr_;
130 /** \c Dialog::Controller is an abstract base class for the Controller
131 * of a Model-Controller-View split of a generic dialog.
133 class Dialog::Controller : boost::noncopyable {
135 /// \param parent Dialog owning this Controller.
136 Controller(Dialog & parent);
137 virtual ~Controller() {}
139 /** \name Generic Controller
140 * These few methods are all that a generic dialog needs of a
144 /** Enable the controller to initialise its data structures.
145 * \param data is a string encoding of the parameters to be displayed.
146 * \return true if the translation was successful.
148 virtual bool initialiseParams(std::string const & data) = 0;
150 /// Enable the controller to clean up its data structures.
151 virtual void clearParams() = 0;
153 /// Enable the Controller to dispatch its data back to the LyX kernel.
154 virtual void dispatchParams() = 0;
156 /** \return true if the dialog should be shown only when
159 virtual bool isBufferDependent() const = 0;
161 /** \return true if the kernel should disconnect the dialog from
162 * a particular inset after the data has been applied to it.
163 * Clearly this makes sense only for dialogs modifying the contents
165 * In practise, only a very few dialogs (e.g. the citation dialog)
168 virtual bool disconnectOnApply() const { return false; }
172 /** \name Controller Access
173 * Enable the derived classes to access the other parts of the whole.
176 Dialog & dialog() { return parent_; }
177 Dialog const & dialog() const { return parent_; }
179 Kernel & kernel() { return parent_.kernel(); }
180 Kernel const & kernel() const { return parent_.kernel(); }
188 /** \c Dialog::View is an abstract base class to the View
189 * of a Model-Controller-View split of a generic dialog.
191 class Dialog::View : boost::noncopyable {
193 /** \param parent Dialog owning this Controller.
194 * \param title is the dialog title displayed by the WM.
196 View(Dialog & parent, std::string title);
199 /** \name Generic View
200 * These few methods are all that a generic dialog needs of a
204 /** A request to modify the data structures stored by the
205 * accompanying Controller in preparation for their dispatch to
208 virtual void apply() = 0;
210 /// Hide the dialog from sight
211 virtual void hide() = 0;
213 /// Redraw the dialog (e.g. if the colors have been remapped).
214 virtual void redraw() {}
216 /// Create the dialog if necessary, update it and display it.
217 virtual void show() = 0;
219 /// Update the display of the dialog whilst it is still visible.
220 virtual void update() = 0;
222 /// \return true if the dialog is visible.
223 virtual bool isVisible() const = 0;
226 /** Defaults to nothing. Can be used by the Controller, however, to
227 * indicate to the View that something has changed and that the
228 * dialog therefore needs updating.
229 * \param id identifies what should be updated.
231 virtual void partialUpdate(int id);
233 /// sets the title of the dialog (window caption)
234 void setTitle(std::string const &);
235 /// gets the title of the dialog (window caption)
236 std::string const & getTitle() const;
238 /** \name View Access
239 * Enable the derived classes to access the other parts of the whole.
242 Dialog & dialog() { return p_; }
243 Dialog const & dialog() const { return p_; }
246 Kernel & kernel() { return p_.kernel(); }
247 Kernel const & kernel() const { return p_.kernel(); }
249 Controller & getController() { return p_.controller(); }
250 Controller const & getController() const { return p_.controller(); }
252 ButtonController & bc() { return p_.bc(); }
253 ButtonController const & bc() const { return p_.bc(); }
261 } // namespace frontend