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 /** When applying, it's useful to know whether the dialog is about
74 * to close or not (no point refreshing the display for example).
76 bool isClosing() const { return is_closing_; }
78 /** The LyX kernel is made available through this wrapper class.
79 * In an ideal world, it will shrink as more info is passed to the
80 * show() and update() methods.
82 Kernel & kernel() { return kernel_; }
84 /** Different dialogs will have different Controllers and Views.
85 * deriving from these base classes.
92 /** \name Dialog Specialization
93 * Methods to set the Controller and View and so specialise
94 * to a particular dialog.
97 /// \param ptr is stored and destroyed by \c Dialog.
98 void setController(Controller * ptr);
99 /// \param ptr is stored and destroyed by \c Dialog.
100 void setView(View * ptr);
103 /** \name Dialog Components
104 * Methods to access the various components making up a dialog.
107 Controller & controller() const;
108 ButtonController & bc() const;
118 boost::scoped_ptr<ButtonController> bc_ptr_;
119 boost::scoped_ptr<Controller> controller_ptr_;
120 boost::scoped_ptr<View> view_ptr_;
124 /** \c Dialog::Controller is an abstract base class for the Controller
125 * of a Model-Controller-View split of a generic dialog.
127 class Dialog::Controller : boost::noncopyable {
129 /// \param parent Dialog owning this Controller.
130 Controller(Dialog & parent);
131 virtual ~Controller() {}
133 /** \name Generic Controller
134 * These few methods are all that a generic dialog needs of a
138 /** Enable the controller to initialise its data structures.
139 * \param data is a string encoding of the parameters to be displayed.
140 * \return true if the translation was successful.
142 virtual bool initialiseParams(std::string const & data) = 0;
144 /// Enable the controller to clean up its data structures.
145 virtual void clearParams() = 0;
147 /// Enable the Controller to dispatch its data back to the LyX kernel.
148 virtual void dispatchParams() = 0;
150 /** \return true if the dialog should be shown only when
153 virtual bool isBufferDependent() const = 0;
155 /** \return true if the kernel should disconnect the dialog from
156 * a particular inset after the data has been applied to it.
157 * Clearly this makes sense only for dialogs modifying the contents
159 * In practise, only a very few dialogs (e.g. the citation dialog)
162 virtual bool disconnectOnApply() const { return false; }
166 /** \name Controller Access
167 * Enable the derived classes to access the other parts of the whole.
170 Dialog & dialog() { return parent_; }
171 Dialog const & dialog() const { return parent_; }
173 Kernel & kernel() { return parent_.kernel(); }
174 Kernel const & kernel() const { return parent_.kernel(); }
182 /** \c Dialog::View is an abstract base class to the View
183 * of a Model-Controller-View split of a generic dialog.
185 class Dialog::View : boost::noncopyable {
187 /** \param parent Dialog owning this Controller.
188 * \param title is the dialog title displayed by the WM.
190 View(Dialog & parent, std::string title);
193 /** \name Generic View
194 * These few methods are all that a generic dialog needs of a
198 /** A request to modify the data structures stored by the
199 * accompanying Controller in preparation for their dispatch to
202 virtual void apply() = 0;
204 /// Hide the dialog from sight
205 virtual void hide() = 0;
207 /// Redraw the dialog (e.g. if the colors have been remapped).
208 virtual void redraw() {}
210 /// Create the dialog if necessary, update it and display it.
211 virtual void show() = 0;
213 /// Update the display of the dialog whilst it is still visible.
214 virtual void update() = 0;
216 /// \return true if the dialog is visible.
217 virtual bool isVisible() const = 0;
220 /** Defaults to nothing. Can be used by the Controller, however, to
221 * indicate to the View that something has changed and that the
222 * dialog therefore needs updating.
223 * \param id identifies what should be updated.
225 virtual void partialUpdate(int id);
227 /// sets the title of the dialog (window caption)
228 void setTitle(std::string const &);
229 /// gets the title of the dialog (window caption)
230 std::string const & getTitle() const;
232 /** \name View Access
233 * Enable the derived classes to access the other parts of the whole.
236 Dialog & dialog() { return p_; }
237 Dialog const & dialog() const { return p_; }
240 Kernel & kernel() { return p_.kernel(); }
241 Kernel const & kernel() const { return p_.kernel(); }
243 Controller & getController() { return p_.controller(); }
244 Controller const & getController() const { return p_.controller(); }
246 ButtonController & bc() { return p_.bc(); }
247 ButtonController const & bc() const { return p_.bc(); }
255 } // namespace frontend