2003-02-25 14:51:38 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file Dialog.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-25 14:51:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIALOG_H
|
|
|
|
#define DIALOG_H
|
|
|
|
|
|
|
|
#include "Kernel.h"
|
2005-04-26 09:37:52 +00:00
|
|
|
#include "lfuns.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
#include <boost/utility.hpp>
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
|
|
class LyXView;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
class ButtonController;
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
/** \c Dialog collects the different parts of a Model-Controller-View
|
2003-03-14 00:20:42 +00:00
|
|
|
* split of a generic dialog together.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
class Dialog : boost::noncopyable {
|
|
|
|
public:
|
2003-07-16 20:10:59 +00:00
|
|
|
/// \param lv is the access point for the dialog to the LyX kernel.
|
|
|
|
/// \param name is the identifier given to the dialog by its parent
|
|
|
|
/// container.
|
2003-10-06 15:43:21 +00:00
|
|
|
Dialog(LyXView & lv, std::string const & name);
|
2003-03-10 03:13:28 +00:00
|
|
|
~Dialog();
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** The Dialog's name is the means by which a dialog identifies
|
2003-03-14 00:20:42 +00:00
|
|
|
* itself to the kernel.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & name() const { return name_; }
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Buttons
|
|
|
|
* These methods are publicly accessible because they are invoked
|
2003-03-14 00:20:42 +00:00
|
|
|
* by the View when the user presses... guess what ;-)
|
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
2003-02-25 14:51:38 +00:00
|
|
|
void ApplyButton();
|
|
|
|
void OKButton();
|
|
|
|
void CancelButton();
|
|
|
|
void RestoreButton();
|
|
|
|
//@}
|
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Container Access
|
|
|
|
* These methods are publicly accessible because they are invoked
|
|
|
|
* by the parent container acting on commands from the LyX kernel.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
|
|
|
/// \param data is a string encoding of the data to be displayed.
|
|
|
|
/// It is passed to the Controller to be translated into a useable form.
|
2003-10-06 15:43:21 +00:00
|
|
|
void show(std::string const & data);
|
|
|
|
void update(std::string const & data);
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
void hide();
|
|
|
|
bool isVisible() const;
|
2003-03-14 00:20:42 +00:00
|
|
|
|
|
|
|
/** This function is called, for example, if the GUI colours
|
|
|
|
* have been changed.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
void redraw();
|
|
|
|
//@}
|
|
|
|
|
2005-04-13 09:43:58 +00:00
|
|
|
/** Check wether we may apply our data.
|
|
|
|
*
|
|
|
|
* The buttons are disabled if not and (re-)enabled if yes.
|
|
|
|
*/
|
|
|
|
void checkStatus();
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** When applying, it's useful to know whether the dialog is about
|
2003-02-25 14:51:38 +00:00
|
|
|
* to close or not (no point refreshing the display for example).
|
|
|
|
*/
|
|
|
|
bool isClosing() const { return is_closing_; }
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** The LyX kernel is made available through this wrapper class.
|
|
|
|
* In an ideal world, it will shrink as more info is passed to the
|
|
|
|
* show() and update() methods.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
Kernel & kernel() { return kernel_; }
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** Different dialogs will have different Controllers and Views.
|
2003-07-16 20:10:59 +00:00
|
|
|
* deriving from these base classes.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
2003-02-25 14:51:38 +00:00
|
|
|
class Controller;
|
|
|
|
class View;
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Dialog Specialization
|
|
|
|
* Methods to set the Controller and View and so specialise
|
2003-03-14 00:20:42 +00:00
|
|
|
* to a particular dialog.
|
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
|
|
|
/// \param ptr is stored and destroyed by \c Dialog.
|
2003-03-14 00:20:42 +00:00
|
|
|
void setController(Controller * ptr);
|
2003-07-16 20:10:59 +00:00
|
|
|
/// \param ptr is stored and destroyed by \c Dialog.
|
2003-03-14 00:20:42 +00:00
|
|
|
void setView(View * ptr);
|
|
|
|
//@}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Dialog Components
|
|
|
|
* Methods to access the various components making up a dialog.
|
|
|
|
*/
|
2003-03-14 00:20:42 +00:00
|
|
|
//@{
|
2003-02-25 14:51:38 +00:00
|
|
|
Controller & controller() const;
|
2003-03-10 03:13:28 +00:00
|
|
|
ButtonController & bc() const;
|
2003-02-25 14:51:38 +00:00
|
|
|
View & view() const;
|
|
|
|
//@}
|
|
|
|
|
2003-03-05 11:30:35 +00:00
|
|
|
private:
|
2003-02-25 14:51:38 +00:00
|
|
|
void apply();
|
|
|
|
|
|
|
|
bool is_closing_;
|
|
|
|
Kernel kernel_;
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string name_;
|
2003-03-10 03:13:28 +00:00
|
|
|
boost::scoped_ptr<ButtonController> bc_ptr_;
|
2003-02-25 14:51:38 +00:00
|
|
|
boost::scoped_ptr<Controller> controller_ptr_;
|
|
|
|
boost::scoped_ptr<View> view_ptr_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
/** \c Dialog::Controller is an abstract base class for the Controller
|
2003-03-14 00:20:42 +00:00
|
|
|
* of a Model-Controller-View split of a generic dialog.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
class Dialog::Controller : boost::noncopyable {
|
|
|
|
public:
|
2003-07-16 20:10:59 +00:00
|
|
|
/// \param parent Dialog owning this Controller.
|
|
|
|
Controller(Dialog & parent);
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual ~Controller() {}
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Generic Controller
|
|
|
|
* These few methods are all that a generic dialog needs of a
|
2003-03-14 00:20:42 +00:00
|
|
|
* controller.
|
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
|
|
|
/** Enable the controller to initialise its data structures.
|
|
|
|
* \param data is a string encoding of the parameters to be displayed.
|
2003-03-14 00:20:42 +00:00
|
|
|
* \return true if the translation was successful.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
virtual bool initialiseParams(std::string const & data) = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Enable the controller to clean up its data structures.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void clearParams() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Enable the Controller to dispatch its data back to the LyX kernel.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void dispatchParams() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** \return true if the dialog should be shown only when
|
2003-07-16 20:10:59 +00:00
|
|
|
* a buffer is open.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual bool isBufferDependent() const = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
2005-04-26 09:37:52 +00:00
|
|
|
/** The lfun that is sent for applying the data.
|
|
|
|
*
|
|
|
|
* This method is used by the default implementation of canApply()
|
|
|
|
* for buffer dependant dialogs that send one lfun when applying the
|
|
|
|
* data.
|
|
|
|
* It should be used in dispatchParams(), too for consistency reasons.
|
|
|
|
* \returns the lfun that is sent for applying the data.
|
|
|
|
*/
|
|
|
|
virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
|
|
|
|
|
|
|
|
/** Check whether we may apply our data.
|
|
|
|
*
|
|
|
|
* The default implementation works for all dialogs that send one
|
|
|
|
* lfun when applying the data. Dialogs that send none or more than
|
|
|
|
* one lfun need to reimplement it.
|
|
|
|
* \returns whether the data can be applied or not.
|
|
|
|
*/
|
|
|
|
virtual bool canApply() const;
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** \return true if the kernel should disconnect the dialog from
|
|
|
|
* a particular inset after the data has been applied to it.
|
|
|
|
* Clearly this makes sense only for dialogs modifying the contents
|
|
|
|
* of an inset :-)
|
|
|
|
* In practise, only a very few dialogs (e.g. the citation dialog)
|
|
|
|
* return true.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual bool disconnectOnApply() const { return false; }
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
protected:
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Controller Access
|
|
|
|
* Enable the derived classes to access the other parts of the whole.
|
2003-03-14 00:20:42 +00:00
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
2003-03-05 11:30:35 +00:00
|
|
|
Dialog & dialog() { return parent_; }
|
|
|
|
Dialog const & dialog() const { return parent_; }
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
Kernel & kernel() { return parent_.kernel(); }
|
|
|
|
Kernel const & kernel() const { return parent_.kernel(); }
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Dialog & parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
/** \c Dialog::View is an abstract base class to the View
|
2003-03-14 00:20:42 +00:00
|
|
|
* of a Model-Controller-View split of a generic dialog.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
class Dialog::View : boost::noncopyable {
|
|
|
|
public:
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \param parent Dialog owning this Controller.
|
|
|
|
* \param title is the dialog title displayed by the WM.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
View(Dialog & parent, std::string title);
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual ~View() {}
|
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name Generic View
|
|
|
|
* These few methods are all that a generic dialog needs of a
|
2003-03-14 00:20:42 +00:00
|
|
|
* view.
|
|
|
|
*/
|
2003-07-16 20:10:59 +00:00
|
|
|
//@{
|
2003-03-14 00:20:42 +00:00
|
|
|
/** A request to modify the data structures stored by the
|
|
|
|
* accompanying Controller in preparation for their dispatch to
|
|
|
|
* the LyX kernel.
|
|
|
|
*/
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void apply() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Hide the dialog from sight
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void hide() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Redraw the dialog (e.g. if the colors have been remapped).
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void redraw() {}
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Create the dialog if necessary, update it and display it.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void show() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
|
|
|
/// Update the display of the dialog whilst it is still visible.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual void update() = 0;
|
2003-07-16 20:10:59 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/// \return true if the dialog is visible.
|
2003-02-25 14:51:38 +00:00
|
|
|
virtual bool isVisible() const = 0;
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
/** Defaults to nothing. Can be used by the Controller, however, to
|
|
|
|
* indicate to the View that something has changed and that the
|
2003-02-25 14:51:38 +00:00
|
|
|
* dialog therefore needs updating.
|
2003-07-16 20:10:59 +00:00
|
|
|
* \param id identifies what should be updated.
|
2003-02-25 14:51:38 +00:00
|
|
|
*/
|
2003-07-17 15:35:42 +00:00
|
|
|
virtual void partialUpdate(int id);
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-05-22 15:42:50 +00:00
|
|
|
/// sets the title of the dialog (window caption)
|
2003-10-06 15:43:21 +00:00
|
|
|
void setTitle(std::string const &);
|
2003-05-22 15:42:50 +00:00
|
|
|
/// gets the title of the dialog (window caption)
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & getTitle() const;
|
2003-05-22 15:42:50 +00:00
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
/** \name View Access
|
|
|
|
* Enable the derived classes to access the other parts of the whole.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
Dialog & dialog() { return p_; }
|
|
|
|
Dialog const & dialog() const { return p_; }
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
protected:
|
2003-02-25 14:51:38 +00:00
|
|
|
Kernel & kernel() { return p_.kernel(); }
|
|
|
|
Kernel const & kernel() const { return p_.kernel(); }
|
|
|
|
|
|
|
|
Controller & getController() { return p_.controller(); }
|
|
|
|
Controller const & getController() const { return p_.controller(); }
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
ButtonController & bc() { return p_.bc(); }
|
|
|
|
ButtonController const & bc() const { return p_.bc(); }
|
2003-03-14 00:20:42 +00:00
|
|
|
//@}
|
2003-03-10 03:13:28 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
private:
|
2003-02-25 14:51:38 +00:00
|
|
|
Dialog & p_;
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string title_;
|
2003-02-25 14:51:38 +00:00
|
|
|
};
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
#endif // DIALOG_H
|