2001-04-17 14:06:11 +00:00
|
|
|
// -*- C++ -*-
|
2001-03-30 09:51:46 +00:00
|
|
|
/* This file is part of
|
2001-03-15 13:37:04 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-03-21 13:27:03 +00:00
|
|
|
* Copyright 2000-2001 The LyX Team.
|
2001-03-15 13:37:04 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
2001-03-30 09:51:46 +00:00
|
|
|
* \file ButtonController.h
|
2001-03-22 11:24:36 +00:00
|
|
|
* \author Allan Rae, rae@lyx.org
|
2001-03-30 09:51:46 +00:00
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
|
|
|
* \author Baruch Even, baruch.even@writeme.com
|
2001-03-15 13:37:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BUTTONCONTROLLER_H
|
|
|
|
#define BUTTONCONTROLLER_H
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <list>
|
2001-03-15 13:37:04 +00:00
|
|
|
|
2001-06-16 14:48:12 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-08-28 12:24:03 +00:00
|
|
|
#include "debug.h"
|
2001-06-16 14:48:12 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
template <class Button, class Widget>
|
|
|
|
class GuiBC : public ButtonControllerBase
|
2001-03-15 13:37:04 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
2001-03-30 09:51:46 +00:00
|
|
|
GuiBC(string const & cancel, string const & close);
|
|
|
|
|
|
|
|
///
|
|
|
|
void setOK(Button * obj) { okay_ = obj; }
|
|
|
|
///
|
|
|
|
void setApply(Button * obj) { apply_ = obj; }
|
|
|
|
///
|
|
|
|
void setCancel(Button * obj) { cancel_ = obj; }
|
2001-03-15 13:37:04 +00:00
|
|
|
///
|
2001-04-03 14:30:58 +00:00
|
|
|
void setRestore(Button * obj) { restore_ = obj; }
|
2001-03-15 13:37:04 +00:00
|
|
|
///
|
2001-03-30 09:51:46 +00:00
|
|
|
void addReadOnly(Widget * obj) { read_only_.push_back(obj); }
|
2001-03-15 13:37:04 +00:00
|
|
|
///
|
2001-03-30 09:51:46 +00:00
|
|
|
void eraseReadOnly() { read_only_.clear(); }
|
2001-03-15 13:37:04 +00:00
|
|
|
|
2001-06-02 14:53:35 +00:00
|
|
|
/// Refresh the status of the Ok, Apply, Restore, Cancel buttons.
|
2001-03-30 09:51:46 +00:00
|
|
|
void refresh();
|
2001-06-02 14:53:35 +00:00
|
|
|
/// Refresh the status of any widgets in the read_only list
|
|
|
|
void refreshReadOnly();
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Enable/Disable a widget
|
|
|
|
virtual void setWidgetEnabled(Widget * obj, bool enable) = 0;
|
|
|
|
/// Enable/Disable a button
|
|
|
|
virtual void setButtonEnabled(Button * obj, bool enable) = 0;
|
|
|
|
/// Set the Label on the button
|
|
|
|
virtual void setButtonLabel(Button * obj, string const & label) = 0;
|
|
|
|
|
|
|
|
Button * okay_;
|
|
|
|
Button * apply_;
|
|
|
|
Button * cancel_;
|
2001-04-03 14:30:58 +00:00
|
|
|
Button * restore_;
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
typedef std::list<Widget *> Widgets;
|
|
|
|
Widgets read_only_;
|
2001-03-15 13:37:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
template <class Button, class Widget>
|
|
|
|
GuiBC<Button, Widget>::GuiBC(string const & cancel, string const & close)
|
2001-04-17 14:06:11 +00:00
|
|
|
: ButtonControllerBase(cancel, close),
|
|
|
|
okay_(0), apply_(0), cancel_(0), restore_(0)
|
2001-03-30 09:51:46 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Button, class Widget>
|
|
|
|
void GuiBC<Button, Widget>::refresh()
|
|
|
|
{
|
2001-08-28 12:24:03 +00:00
|
|
|
lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
if (okay_) {
|
|
|
|
bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
|
|
|
|
setButtonEnabled(okay_, enabled);
|
|
|
|
}
|
|
|
|
if (apply_) {
|
|
|
|
bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
|
|
|
|
setButtonEnabled(apply_, enabled);
|
|
|
|
}
|
2001-04-03 14:30:58 +00:00
|
|
|
if (restore_) {
|
|
|
|
bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
|
|
|
|
setButtonEnabled(restore_, enabled);
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
if (cancel_) {
|
|
|
|
bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL);
|
|
|
|
if (enabled)
|
|
|
|
setButtonLabel(cancel_, cancel_label_);
|
|
|
|
else
|
|
|
|
setButtonLabel(cancel_, close_label_);
|
|
|
|
}
|
2001-06-02 14:53:35 +00:00
|
|
|
}
|
2001-03-30 09:51:46 +00:00
|
|
|
|
|
|
|
|
2001-06-02 14:53:35 +00:00
|
|
|
template <class Button, class Widget>
|
|
|
|
void GuiBC<Button, Widget>::refreshReadOnly()
|
|
|
|
{
|
|
|
|
if (read_only_.empty()) return;
|
|
|
|
|
|
|
|
bool const enable = !bp().isReadOnly();
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2001-06-02 14:53:35 +00:00
|
|
|
Widgets::const_iterator end = read_only_.end();
|
|
|
|
Widgets::const_iterator iter = read_only_.begin();
|
|
|
|
for (; iter != end; ++iter) {
|
|
|
|
setWidgetEnabled(*iter, enable);
|
|
|
|
}
|
2001-03-30 09:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
template <class BP, class GUIBC>
|
|
|
|
class ButtonController: public GUIBC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
ButtonController(string const & = _("Cancel"),
|
|
|
|
string const & = _("Close"));
|
|
|
|
///
|
|
|
|
virtual ButtonPolicy & bp() { return bp_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
BP bp_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class BP, class GUIBC>
|
|
|
|
ButtonController<BP, GUIBC>::ButtonController(string const & cancel,
|
|
|
|
string const & close)
|
|
|
|
: GUIBC(cancel, close)
|
|
|
|
{}
|
|
|
|
|
|
|
|
#endif // BUTTONCONTROLLER_H
|