}
-bool BCView::checkWidgets()
+bool BCView::checkWidgets() const
{
bool valid = true;
#ifndef BCVIEW_H
#define BCVIEW_H
+
#include "LString.h"
#include <boost/shared_ptr.hpp>
#include <list>
+
class ButtonController;
class ButtonPolicy;
+
+/** \class CheckedWidget is an abstract base class that can be stored
+ * in the button controller's view and can be interrogated by it
+ * when the activation state of the Ok, Apply buttons is refreshed.
+ * Ideally, the user will be prevented from returning invalid data
+ * to the LyX kernel.
+ *
+ * Many widgets can be grouped together in the derived class if they
+ * make a logical whole. E.g., an input and a choice widget that together
+ * are used to set a LyXLength can be interrogated together.
+ */
struct CheckedWidget {
///
virtual ~CheckedWidget();
};
+/** \class BCView is the View to ButtonController's Controller. It
+ * stores the individual GUI widgets and sets their activation state
+ * upon receipt of instructions from the controller.
+ *
+ * It is a base class. The true, GUI, instantiations derive from it.
+ */
class BCView {
public:
BCView(ButtonController const &);
- ///
virtual ~BCView() {}
- ///
- virtual void refresh() = 0;
- ///
- virtual void refreshReadOnly() = 0;
- ///
+
+ //@{
+ /// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
+ virtual void refresh() const = 0;
+ /// Refresh the status of any widgets in the read_only list
+ virtual void refreshReadOnly() const = 0;
+ //@}
+
+ /// A shortcut to the BP of the BC.
ButtonPolicy & bp() const;
- ///
+
+ /** Add a widget to the list of all widgets whose validity should
+ * be checked explicitly when the buttons are refreshed.
+ */
void addCheckedWidget(CheckedWidget * ptr);
+
protected:
- ///
- bool checkWidgets();
+ /// \return true if all CheckedWidgets are in a valid state.
+ bool checkWidgets() const;
private:
- ///
typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
typedef std::list<checked_widget_ptr> checked_widget_list;
- ///
checked_widget_list checked_widgets;
- ///
ButtonController const & parent;
};
GuiBC(ButtonController const & parent,
string const & cancel, string const & close);
- ///
+ //@{
+ /** Store pointers to these widgets. The pointers are _not_
+ * owned by GuiBC.
+ */
void setOK(Button * obj) { okay_ = obj; }
- ///
void setApply(Button * obj) { apply_ = obj; }
- ///
void setCancel(Button * obj) { cancel_ = obj; }
- ///
void setRestore(Button * obj) { restore_ = obj; }
- ///
+ //@}
+
+ /** Add a pointer to the list of widgets whose activation
+ * state is dependent upon the read-only status of the
+ * underlying buffer.
+ */
void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
- ///
- void eraseReadOnly() { read_only_.clear(); }
/// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
- void refresh();
+ virtual void refresh() const;
/// Refresh the status of any widgets in the read_only list
- void refreshReadOnly();
+ virtual void refreshReadOnly() const;
+
private:
/// Enable/Disable a widget
- virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
+ virtual void setWidgetEnabled(Widget * obj, bool enable) const = 0;
/// Enable/Disable a button
- virtual void setButtonEnabled(Button * obj, bool enable) = 0;
+ virtual void setButtonEnabled(Button * obj, bool enable) const = 0;
/// Set the Label on the button
- virtual void setButtonLabel(Button * obj, string const & label) = 0;
+ virtual void setButtonLabel(Button * obj, string const & label) const = 0;
- string cancel_label_;
- string close_label_;
+ string const cancel_label_;
+ string const close_label_;
Button * okay_;
Button * apply_;
template <class Button, class Widget>
-void GuiBC<Button, Widget>::refresh()
+void GuiBC<Button, Widget>::refresh() const
{
lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
template <class Button, class Widget>
-void GuiBC<Button, Widget>::refreshReadOnly()
+void GuiBC<Button, Widget>::refreshReadOnly() const
{
if (read_only_.empty()) return;
#include "debug.h"
-ButtonController::~ButtonController()
-{}
-
-
BCView & ButtonController::view() const
{
lyx::Assert(view_.get());
}
-void ButtonController::refresh()
+void ButtonController::refresh() const
{
view().refresh();
}
-
-void ButtonController::refreshReadOnly()
+
+void ButtonController::refreshReadOnly() const
{
view().refreshReadOnly();
}
-void ButtonController::ok()
+void ButtonController::ok() const
{
input(ButtonPolicy::SMI_OKAY);
}
-void ButtonController::input(ButtonPolicy::SMInput in)
+void ButtonController::input(ButtonPolicy::SMInput in) const
{
if (ButtonPolicy::SMI_NOOP == in)
return;
}
-void ButtonController::apply()
+void ButtonController::apply() const
{
input(ButtonPolicy::SMI_APPLY);
}
-void ButtonController::cancel()
+void ButtonController::cancel() const
{
input(ButtonPolicy::SMI_CANCEL);
}
-void ButtonController::restore()
+void ButtonController::restore() const
{
input(ButtonPolicy::SMI_RESTORE);
}
-void ButtonController::hide()
+void ButtonController::hide() const
{
input(ButtonPolicy::SMI_HIDE);
}
-void ButtonController::valid(bool v)
+void ButtonController::valid(bool v) const
{
if (v) {
input(ButtonPolicy::SMI_VALID);
}
-void ButtonController::invalid()
-{
- input(ButtonPolicy::SMI_INVALID);
-}
-
-
-bool ButtonController::readOnly(bool ro)
+bool ButtonController::readOnly(bool ro) const
{
lyxerr[Debug::GUI] << "Setting controller ro: " << ro << std::endl;
view().refresh();
return ro;
}
-
-
-void ButtonController::readWrite()
-{
- readOnly(false);
-}
#include <boost/scoped_ptr.hpp>
-/** Controls the activation of the OK, Apply and Cancel buttons.
+class BCView;
+
+
+/** \class ButtonController controls the activation of the OK, Apply and
+ * Cancel buttons.
*
- * Actually supports 4 buttons in all and it's up to the user to decide on
+ * It actually supports 4 buttons in all and it's up to the user to decide on
* the activation policy and which buttons correspond to which output of the
* state machine.
- * Author: Allan Rae <rae@lyx.org>.
- * This class stripped of xforms-specific code by
- * Angus Leeming <leeming@lyx.org>
*/
-class BCView;
class ButtonController : boost::noncopyable {
public:
- ///
- ~ButtonController();
-
- ///
+ //@{
+ /** Methods to set and get the GUI view (containing the actual
+ * button widgets.
+ * \param ptr is owned by the ButtonController.
+ */
+ void view(BCView * ptr);
BCView & view() const;
- ///
- void view(BCView *);
+ //@}
- ///
+ //@{
+ /** Methods to set and get the ButtonPolicy.
+ * \param ptr is owned by the ButtonController.
+ */
+ void bp(ButtonPolicy * ptr);
ButtonPolicy & bp() const;
- ///
- void bp(ButtonPolicy *);
+ //@}
///
- void input(ButtonPolicy::SMInput);
- ///
- void ok();
- ///
- void apply();
- ///
- void cancel();
- ///
- void restore();
- ///
- void hide();
+ void input(ButtonPolicy::SMInput) const;
- ///
- void refresh();
- ///
- void refreshReadOnly();
+ //@{
+ /// Tell the BC that a particular button has been pressed.
+ void ok() const;
+ void apply() const;
+ void cancel() const;
+ void restore() const;
+ //@}
- /// Passthrough function -- returns its input value
- bool readOnly(bool = true);
- ///
- void readWrite();
+ /// Tell the BC that the dialog is being hidden
+ void hide() const;
- ///
- void valid(bool = true);
- ///
- void invalid();
+ /**Refresh the activation state of the Ok, Apply, Close and
+ * Restore buttons.
+ */
+ void refresh() const;
+
+ /** Refresh the activation state of all the widgets under the control
+ * of the BC to reflect the read-only status of the underlying buffer.
+ */
+ void refreshReadOnly() const;
+ //@}
+
+ /** Passthrough function -- returns its input value
+ * Tell the BC about the read-only status of the underlying buffer.
+ */
+ bool readOnly(bool = true) const;
+
+ /** \param validity Tell the BC that the data is, or is not, valid.
+ * Sets the activation state of the buttons immediately.
+ */
+ void valid(bool = true) const;
private:
- ///
boost::scoped_ptr<ButtonPolicy> bp_;
- ///
boost::scoped_ptr<BCView> view_;
};
+2003-03-13 Angus Leeming <angus@localhost.localdomain>
+
+ * ButtonController.h:
+
+2003-03-13 Angus Leeming <leeming@lyx.org>
+
+ * Dialog.h (initialiseParams): return a bool to indicate successful
+ translation of the string.
+
+ * Dialog.h:
+ * Kernel.h
+ * ControlAbout.h: a serious attempt at documenting the code.
+
+ * ButtonController.[Ch] (readWrite): it wasn't used, so remove it.
+
2003-03-13 Angus Leeming <leeming@lyx.org>
* ControlParagraph.[Ch]: rewrite to use the Dialog-based scheme and
#include "Dialog.h"
#include <iosfwd>
-/** A controller for the About LyX dialogs.
+/** \class ControlAboutlyx is a controller for the "About LyX" dialogs.
*/
class ControlAboutlyx : public Dialog::Controller {
public:
- ///
- ControlAboutlyx(Dialog &);
- ///
- virtual void initialiseParams(string const &) {}
- ///
+ ControlAboutlyx(Dialog & parent);
+
+ //@{
+ /// Instantiate Dialog::Controller methods.
+ virtual bool initialiseParams(string const &) { return true; }
virtual void clearParams() {}
- ///
virtual void dispatchParams() {}
- ///
virtual bool isBufferDependent() const { return false; }
+ //@}
- ///
+ //@{
+ /// Provide the View with specific pieces of information.
void getCredits(std::ostream &) const;
- ///
string const getCopyright() const;
- ///
string const getLicense() const;
- ///
string const getDisclaimer() const;
- ///
string const getVersion() const;
+ //@}
};
#endif // CONTROLABOUTLYX_H
///
ControlChanges(Dialog &);
///
- virtual void initialiseParams(string const &) {}
+ virtual bool initialiseParams(string const &) { return true; }
///
virtual void clearParams() {}
///
{}
-void ControlCharacter::initialiseParams(string const &)
+bool ControlCharacter::initialiseParams(string const &)
{
// Do this the first time only.
if (!font_.get())
getColor() != LColor::ignore ||
font_->language() != ignore_language)
dialog().bc().valid();
+
+ return true;
}
///
ControlCharacter(Dialog &);
///
- virtual void initialiseParams(string const &);
+ virtual bool initialiseParams(string const & data);
///
virtual void clearParams();
///
{}
-void ControlCitation::initialiseParams(string const & data)
+bool ControlCitation::initialiseParams(string const & data)
{
ControlCommand::initialiseParams(data);
(!usingNatbib() && citeStyles_.size() != 1))
citeStyles_ = biblio::getCiteStyles(usingNatbib());
}
+
+ return true;
}
ControlCitation(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
{}
-void ControlCommand::initialiseParams(string const & data)
+bool ControlCommand::initialiseParams(string const & data)
{
InsetCommandMailer::string2params(data, params_);
+ return true;
}
///
InsetCommandParams const & params() const { return params_; }
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlERT::initialiseParams(string const & data)
+bool ControlERT::initialiseParams(string const & data)
{
InsetERTMailer::string2params(data, status_);
+ return true;
}
///
void setStatus(InsetERT::ERTStatus status) { status_ = status; }
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlError::initialiseParams(string const & data)
+bool ControlError::initialiseParams(string const & data)
{
params_ = data;
}
///
ControlError(Dialog &);
///
- virtual void initialiseParams(string const &);
+ virtual bool initialiseParams(string const & data);
///
virtual void clearParams();
///
{}
-void ControlExternal::initialiseParams(string const & data)
+bool ControlExternal::initialiseParams(string const & data)
{
inset_.reset(new InsetExternal);
InsetExternal::Params params;
InsetExternalMailer::string2params(data, params);
inset_->setFromParams(params);
inset_->setView(kernel().bufferview());
+ return true;
}
///
ControlExternal(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlFloat::initialiseParams(string const & data)
+bool ControlFloat::initialiseParams(string const & data)
{
InsetFloatParams params;
InsetFloatMailer::string2params(data, params);
params_.reset(new InsetFloatParams(params));
+ return true;
}
///
ControlFloat(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlGraphics::initialiseParams(string const & data)
+bool ControlGraphics::initialiseParams(string const & data)
{
InsetGraphicsParams params;
InsetGraphicsMailer::string2params(data, params);
params_.reset(new InsetGraphicsParams(params));
+ return true;
}
///
ControlGraphics(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlInclude::initialiseParams(string const & data)
+bool ControlInclude::initialiseParams(string const & data)
{
InsetInclude::Params params;
InsetIncludeMailer::string2params(data, params);
inset_.reset(new InsetInclude(params));
+ return true;
}
ControlInclude(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
virtual bool isBufferDependent() const { return true; }
///
- InsetInclude::Params const & params() const
+ InsetInclude::Params const & params() const
{ return inset_->params(); }
///
void setParams(InsetInclude::Params const &);
{}
-void ControlMinipage::initialiseParams(string const & data)
+bool ControlMinipage::initialiseParams(string const & data)
{
InsetMinipage::Params params;
InsetMinipageMailer::string2params(data, params);
params_.reset(new InsetMinipage::Params(params));
+ return true;
}
///
ControlMinipage(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlParagraph::initialiseParams(string const & data)
+bool ControlParagraph::initialiseParams(string const & data)
{
istringstream is(data);
LyXLex lex(0,0);
// action == 1: update dialog, accept changes
// action == 2: update dialog, do not accept changes
int action = 0;
-
+
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
action = accept ? 1 : 2;
} else {
// Unrecognised token
- lyx::Assert(0);
+ return false;
}
}
Int = lex.getInteger();
} else {
// Unrecognised token
- break;
+ return false;
}
-
+
++nset;
if (token == "\\alignpossible") {
ininset_ = Int;
}
}
- lyx::Assert(nset == 3);
+ if (nset != 3)
+ return false;
// If "update", then set the activation status of the button controller
if (action > 0) {
bool const accept = action == 1;
dialog().bc().valid(accept);
}
+ return true;
}
///
ControlParagraph(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
{}
-void ControlTabular::initialiseParams(string const & data)
+bool ControlTabular::initialiseParams(string const & data)
{
Buffer * buffer = kernel().buffer();
if (!buffer)
- return;
+ return false;
InsetTabular tmp(*buffer);
int cell = InsetTabularMailer::string2params(data, tmp);
params_.reset(new LyXTabular(*tmp.tabular.get()));
active_cell_ = cell;
}
+ return true;
}
ControlTabular(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// We use set() instead.
{}
-void ControlTabularCreate::initialiseParams(string const &)
+bool ControlTabularCreate::initialiseParams(string const &)
{
params_.first = params_.second = 5;
+ return true;
}
///
ControlTabularCreate(Dialog &);
///
- virtual void initialiseParams(string const &);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
///
{}
-void ControlWrap::initialiseParams(string const & data)
+bool ControlWrap::initialiseParams(string const & data)
{
InsetWrapParams params;
InsetWrapMailer::string2params(data, params);
params_.reset(new InsetWrapParams(params));
+ return true;
}
///
ControlWrap(Dialog &);
///
- virtual void initialiseParams(string const & data);
+ virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
#include "ButtonController.h"
#include "BCView.h"
+#include "debug.h"
#include "support/LAssert.h"
if (controller().isBufferDependent() && !kernel().isBufferAvailable())
return;
- controller().initialiseParams(data);
+ if (!controller().initialiseParams(data)) {
+ lyxerr << "Dialog \"" << name_
+ << "\" failed to translate the data "
+ "string passed to show()" << std::endl;
+ return;
+ }
+
bc().readOnly(kernel().isBufferReadonly());
view().show();
if (controller().isBufferDependent() && !kernel().isBufferAvailable())
return;
- controller().initialiseParams(data);
+ if (!controller().initialiseParams(data)) {
+ lyxerr << "Dialog \"" << name_
+ << "\" failed to translate the data "
+ "string passed to update()" << std::endl;
+ return;
+ }
bc().readOnly(kernel().isBufferReadonly());
view().update();
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
- *
- * The dialogs use a Model-Controller-View split, instantiated here
- * by class Dialog.
*/
#ifndef DIALOG_H
class ButtonController;
+/** \class Dialog collects the different parts of a Model-Controller-View
+ * split of a generic dialog together.
+ */
class Dialog : boost::noncopyable {
public:
- /** the Dialog's "name" is the means with which a dialog identifies
- * itself to the kernel.
+ /** \param name is the identifier given to the dialog by its parent
+ * container.
*/
Dialog(LyXView &, string const & name);
- ///
~Dialog();
- ///
+ /** the Dialog's name is the means by which a dialog identifies
+ * itself to the kernel.
+ */
string const & name() const { return name_; }
- /** These methods are publicly accessible because they are invoked
- by the View.
- */
//@{
- ///
+ /** These methods are publicly accessible because they are invoked
+ * by the View when the user presses... guess what ;-)
+ */
void ApplyButton();
- ///
void OKButton();
- ///
void CancelButton();
- ///
void RestoreButton();
//@}
+ //@{
/** These methods are publicly accessible because they are invoked
- * by the Dialogs class.
+ * by the parent container acting on commands from the kernel.
*/
- //@{
- /** Some dialogs, eg the Tabular or Preferences dialog, can extract
- the information they require from the kernel. These dialogs will
- probably be passed an empty string by the calling Dialogs class.
- The inset dialogs, however, require information specific to
- an individual inset. This information will be encoded in "data"
- and must be translated into a set of parameters that can be
- updated from the dialog.
- */
- void show(string const & data = string());
- ///
- void update(string const & data = string());
- ///
+ /** \param data The dialog is passed a string encoding the data
+ * that it is to display. This string is passed to the Controller
+ * which translates it into a useable form.
+ */
+ void show(string const & data);
+ /// \param data \see show().
+ void update(string const & data);
+
void hide();
- ///
bool isVisible() const;
- /// (Eg, the GUI colours have been changed.)
+
+ /** This function is called, for example, if the GUI colours
+ * have been changed.
+ */
void redraw();
//@}
- /** When Applying it's useful to know whether the dialog is about
+ /** When applying, it's useful to know whether the dialog is about
* to close or not (no point refreshing the display for example).
*/
bool isClosing() const { return is_closing_; }
- /// The LyX kernel is made available through this.
+ /** 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.
+ */
Kernel & kernel() { return kernel_; }
- /** Different dialogs will have different
- Controllers, Views and ButtonControllers.
- */
//@{
- ///
+ /** Different dialogs will have different Controllers and Views.
+ * deriving from these base classes.
+ */
class Controller;
- ///
class View;
+ //@}
- ///
- void setController(Controller *);
- ///
- void setView(View *);
+ //@{
+ /** Methods to set the Controller and View and so specialise
+ * to a particular dialog.
+ * \param ptr is stored here.
+ */
+ void setController(Controller * ptr);
+ void setView(View * ptr);
+ //@}
- ///
+ //@{
+ /// Get methods for the various components making up a dialog.
Controller & controller() const;
- ///
ButtonController & bc() const;
- ///
View & view() const;
//@}
private:
- ///
+ /// Invoked by both OKButton() and ApplyButton().
void apply();
- ///
bool is_closing_;
- ///
Kernel kernel_;
- ///
string name_;
- ///
boost::scoped_ptr<ButtonController> bc_ptr_;
- ///
boost::scoped_ptr<Controller> controller_ptr_;
- ///
boost::scoped_ptr<View> view_ptr_;
};
+/** \class Dialog::Controller is an abstract base class for the Controller
+ * of a Model-Controller-View split of a generic dialog.
+ */
class Dialog::Controller : boost::noncopyable {
public:
- ///
Controller(Dialog & parent) : parent_(parent) {}
- ///
virtual ~Controller() {}
- ///
- virtual void initialiseParams(string const & data) = 0;
- ///
+
+ //@{
+ /** These few methods are all that a generic dialog needs of a
+ * controller.
+ */
+ /** \param data The controller is passed a string encoding of the
+ * parameters that the dialog is to display.
+ * \return true if the translation was successful.
+ */
+ virtual bool initialiseParams(string const & data) = 0;
+ /** Invoked by Dialog::hide, allowing the controller to
+ * clean up its data structures.
+ */
virtual void clearParams() = 0;
- ///
+ /** Invoked by Dialog::apply, enabling the Controller to
+ * dispatch its data back to the LyX kernel.
+ */
virtual void dispatchParams() = 0;
- ///
+ /** \return true if the dialog should be shown only when
+ * a buffer is open
+ */
virtual bool isBufferDependent() const = 0;
- ///
+ /** \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.
+ */
virtual bool disconnectOnApply() const { return false; }
- ///
+ //@}
+
+protected:
+ //@{
+ /** Enable the derived classes to access the other parts of the
+ * whole.
+ */
Dialog & dialog() { return parent_; }
- ///
Dialog const & dialog() const { return parent_; }
- ///
+
Kernel & kernel() { return parent_.kernel(); }
- ///
Kernel const & kernel() const { return parent_.kernel(); }
+ //@}
private:
- ///
Dialog & parent_;
};
+/** \class Dialog::View is an abstract base class to the View
+ * of a Model-Controller-View split of a generic dialog.
+ */
class Dialog::View : boost::noncopyable {
public:
- ///
View(Dialog & parent) : p_(parent) {}
- ///
virtual ~View() {}
- /// Apply changes to LyX data from dialog.
+ //@{
+ /** These few methods are all that a generic dialog needs of a
+ * view.
+ */
+ /** A request to modify the data structures stored by the
+ * accompanying Controller in preparation for their dispatch to
+ * the LyX kernel.
+ * Invoked by Dialog::apply.
+ */
virtual void apply() = 0;
- /// Hide the dialog.
+ /** Hide the dialog from sight
+ * Invoked by Dialog::hide.
+ */
virtual void hide() = 0;
- /// Redraw the dialog (e.g. if the colors have been remapped).
+ /** Redraw the dialog (e.g. if the colors have been remapped).
+ * Invoked by Dialog::redraw.
+ */
virtual void redraw() {}
- /// Create the dialog if necessary, update it and display it.
+ /** Create the dialog if necessary, update it and display it.
+ * Invoked by Dialog::show.
+ */
virtual void show() = 0;
- /// Update dialog before/whilst showing it.
+ /** Update the display of the dialog whilst it is still visible.
+ * Invoked by Dialog::update.
+ */
virtual void update() = 0;
- ///
+ /// \return true if the dialog is visible.
virtual bool isVisible() const = 0;
+ //@}
- /** Defaults to nothing. Can be used by the controller, however, to
- * indicate to the view that something has changed and that the
+ /** Defaults to nothing. Can be used by the Controller, however, to
+ * indicate to the View that something has changed and that the
* dialog therefore needs updating.
*/
virtual void partialUpdate(int) {}
- ///
+ //@{
+ /** Enable the derived classes to access the other parts of the
+ * whole.
+ */
Dialog & dialog() { return p_; }
- ///
Dialog const & dialog() const { return p_; }
- ///
+protected:
Kernel & kernel() { return p_.kernel(); }
- ///
Kernel const & kernel() const { return p_.kernel(); }
- ///
Controller & getController() { return p_.controller(); }
- ///
Controller const & getController() const { return p_.controller(); }
- ///
ButtonController & bc() { return p_.bc(); }
- ///
ButtonController const & bc() const { return p_.bc(); }
+ //@}
-protected:
+private:
///
Dialog & p_;
};
+/**
+ * \file Kernel.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
#include "Kernel.h"
#include "buffer.h"
return DOCBOOK;
}
+
BufferView * Kernel::bufferview()
{
return lyxview_.view().get();
// -*- C++ -*-
+/**
+ * \file Kernel.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
#ifndef KERNEL_H
#define KERNEL_H
class LyXView;
+/** \class Kernel is a wrapper making the LyX kernel available to the dialog.
+ * (Ie, it provides an interface to the Model part of the Model-Controller-
+ * View split.
+ * In an ideal world, it will shrink as more info is passed to the
+ * Dialog::show() and update() methods.
+ */
class Kernel {
public:
- ///
+ /// \param lv is the access point for the dialog to the LyX kernel.
+ Kernel(LyXView & lv);
+
+ /** This method is the primary prupose of the class. It provides
+ the "gateway" by which the dialog can send a request (of a
+ change in the data, for more information) to the kernel,
+ encoded as \param fr.
+ \param verbose Set to true if the completed action should
+ be displayed in the minibuffer.
+ */
+ void dispatch(FuncRequest const & fr, bool verbose = false) const;
+
+ /** The dialog has received a request from the user
+ (who pressed the "Restore" buuton) to update contents.
+ It must, therefore, ask the kernel to provide this information.
+ \param name is used as an identifier by the kernel
+ when the information is posted.
+ */
+ void updateDialog(string const & name) const;
+
+ /** A request from the Controller that future changes to the data
+ * stored by the dialog are not applied to the inset currently
+ * connected to the dialog. Instead, they will be used to generate
+ * a new inset at the cursor position.
+ */
+ void disconnect(string const & name) const;
+
+ //@{
+ /// Simple wrapper functions to Buffer methods.
+ bool isBufferAvailable() const;
+ bool isBufferReadonly() const;
+ //@}
+
+ //@{
+ /** \enum DocTypes is used to flag the different kinds of buffer
+ * without making the kernel header files available to the
+ * dialog's Controller or View.
+ */
enum DocTypes {
- ///
LATEX,
- ///
LITERATE,
- ///
LINUXDOC,
- ///
DOCBOOK
};
+ /// The type of the current buffer.
+ DocTypes docType() const;
+ //@}
- ///
- Kernel(LyXView &);
- ///
- void dispatch(FuncRequest const &, bool verbose = false) const;
- /** The Dialog has received a request from the user to update
- its contents. It must, therefore, ask the kernel to provide
- this information to Dialog 'name'.
+
+ //@{
+ /** Unpleasantly public internals of the LyX kernel.
+ * We should aim to reduce/remove these from the interface.
*/
- void updateDialog(string const & name) const;
- ///
- void disconnect(string const & name) const;
- ///
- bool isBufferAvailable() const;
- ///
- bool isBufferReadonly() const;
- ///
- DocTypes docType() const;
- ///
LyXView & lyxview() { return lyxview_; }
- ///
LyXView const & lyxview() const { return lyxview_; }
- ///
+
Buffer * buffer();
- ///
Buffer const * buffer() const;
- ///
+
BufferView * bufferview();
- ///
BufferView const * bufferview() const;
+ //@}
private:
LyXView & lyxview_;
{
if (updating_)
return;
-
- if (isValid())
- bc().valid();
- else
- bc().invalid();
+ bc().valid(isValid());
}
{}
-void Qt2BC::setButtonEnabled(QButton * obj, bool enabled)
+void Qt2BC::setButtonEnabled(QButton * obj, bool enabled) const
{
obj->setEnabled(enabled);
}
-void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled)
+void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled) const
{
// yuck, rtti, but the user comes first
if (obj->inherits("QLineEdit")) {
}
-void Qt2BC::setButtonLabel(QButton * obj, string const & label)
+void Qt2BC::setButtonLabel(QButton * obj, string const & label) const
{
obj->setText(toqstr(label));
}
string const & = _("Cancel"), string const & = _("Close"));
private:
/// Updates the button sensitivity (enabled/disabled)
- void setButtonEnabled(QButton *, bool enabled);
+ void setButtonEnabled(QButton *, bool enabled) const;
/// Updates the widget sensitivity (enabled/disabled)
- void setWidgetEnabled(QWidget *, bool enabled);
+ void setWidgetEnabled(QWidget *, bool enabled) const;
/// Set the label on the button
- void setButtonLabel(QButton *, string const & label);
+ void setButtonLabel(QButton *, string const & label) const;
};
#endif // QT2BC_H
{
if (updating_)
return;
-
- if (isValid())
- bc().valid();
- else
- bc().invalid();
+ bc().valid(isValid());
}
/// the mini-pixmap used for backing store for the blinking cursor
boost::scoped_ptr<QPixmap> nocursor_pixmap_;
- //{@ the cursor pixmap position/size
+ //@{ the cursor pixmap position/size
int cursor_x_;
int cursor_y_;
int cursor_w_;
/**
- * \file QSetBorder.C
+ * \file qsetborder.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
// -*- C++ -*-
/**
- * \file QSetBorder.h
+ * \file qsetborder.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_close);
- bc().invalid();
+ bc().valid(false);
// Set up the tooltip mechanism
string str = _("All currently running child processes forked by LyX.");
{}
-void xformsBC::setButtonEnabled(FL_OBJECT * obj, bool enabled)
+void xformsBC::setButtonEnabled(FL_OBJECT * obj, bool enabled) const
{
setEnabled(obj, enabled);
}
-void xformsBC::setWidgetEnabled(FL_OBJECT * obj, bool enabled)
+void xformsBC::setWidgetEnabled(FL_OBJECT * obj, bool enabled) const
{
setEnabled(obj, enabled);
}
-void xformsBC::setButtonLabel(FL_OBJECT * obj, string const & label)
+void xformsBC::setButtonLabel(FL_OBJECT * obj, string const & label) const
{
fl_set_object_label(obj, label.c_str());
}
private:
/// Updates the button sensitivity (enabled/disabled)
- void setButtonEnabled(FL_OBJECT *, bool enabled);
+ void setButtonEnabled(FL_OBJECT *, bool enabled) const;
/// Updates the widget sensitivity (enabled/disabled)
- void setWidgetEnabled(FL_OBJECT *, bool enabled);
+ void setWidgetEnabled(FL_OBJECT *, bool enabled) const;
/// Set the label on the button
- void setButtonLabel(FL_OBJECT *, string const & label);
+ void setButtonLabel(FL_OBJECT *, string const & label) const;
};
#endif // XFORMSBC_H