2002-01-16 14:47:58 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-05 14:10:50 +00:00
|
|
|
/**
|
2002-01-16 14:47:58 +00:00
|
|
|
* \file ControlInset.tmpl
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-01-16 14:47:58 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-01-16 14:47:58 +00:00
|
|
|
*
|
|
|
|
* ControlInset is a base class and so these templatised methods will be
|
|
|
|
* instantiated if this file is #included in the derived classes' .C file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ControlInset.h"
|
2002-08-12 20:17:41 +00:00
|
|
|
|
2002-06-12 13:10:19 +00:00
|
|
|
#include "ButtonControllerBase.h"
|
2002-06-10 07:57:39 +00:00
|
|
|
#include "ViewBase.h"
|
2002-01-16 14:47:58 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-06-10 07:57:39 +00:00
|
|
|
#include <boost/bind.hpp>
|
2002-01-16 14:47:58 +00:00
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlConnectBD(lv, d),
|
2002-05-29 16:21:03 +00:00
|
|
|
inset_(0), params_(0), dialog_built_(false)
|
2002-01-16 14:47:58 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::showInset(Inset * inset)
|
|
|
|
{
|
|
|
|
if (inset == 0) return; // maybe we should Assert this?
|
|
|
|
|
|
|
|
connectInset(inset);
|
|
|
|
show(getParams(*inset));
|
2002-10-22 12:39:05 +00:00
|
|
|
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
2002-01-16 14:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::createInset(string const & arg)
|
|
|
|
{
|
|
|
|
connectInset();
|
|
|
|
|
|
|
|
if (!arg.empty())
|
|
|
|
bc().valid(); // so that the user can press Ok
|
|
|
|
|
|
|
|
show(getParams(arg));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::show(Params const & params)
|
|
|
|
{
|
|
|
|
// paranoia check
|
|
|
|
if (params_) delete params_;
|
|
|
|
|
|
|
|
params_ = new Params(params);
|
|
|
|
setDaughterParams();
|
|
|
|
|
|
|
|
if (emergency_exit_) {
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dialog_built_) {
|
|
|
|
view().build();
|
|
|
|
dialog_built_ = true;
|
|
|
|
}
|
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
bc().readOnly(bufferIsReadonly());
|
2002-01-16 14:47:58 +00:00
|
|
|
view().show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::update()
|
|
|
|
{
|
|
|
|
// paranoia check
|
|
|
|
if (params_) delete params_;
|
|
|
|
|
|
|
|
if (inset_)
|
|
|
|
params_ = new Params(getParams(*inset_));
|
|
|
|
else
|
|
|
|
params_ = new Params();
|
|
|
|
|
|
|
|
if (emergency_exit_) {
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
bc().readOnly(bufferIsReadonly());
|
2002-01-16 14:47:58 +00:00
|
|
|
view().update();
|
2002-10-22 12:39:05 +00:00
|
|
|
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
2002-01-16 14:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::hide()
|
|
|
|
{
|
|
|
|
emergency_exit_ = false;
|
|
|
|
if (params_) {
|
|
|
|
delete params_;
|
|
|
|
params_ = 0;
|
|
|
|
}
|
|
|
|
inset_ = 0;
|
|
|
|
|
|
|
|
clearDaughterParams();
|
|
|
|
|
|
|
|
ih_.disconnect();
|
|
|
|
disconnect();
|
|
|
|
view().hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::apply()
|
|
|
|
{
|
2002-08-12 20:17:41 +00:00
|
|
|
if (bufferIsReadonly())
|
2002-01-16 14:47:58 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
view().apply();
|
|
|
|
|
|
|
|
if (inset_) {
|
|
|
|
if (params() != getParams(*inset_)) {
|
|
|
|
applyParamsToInset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
applyParamsNoInset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disconnectOnApply() && !isClosing()) {
|
|
|
|
*params_ = getParams(string());
|
|
|
|
inset_ = 0;
|
|
|
|
ih_.disconnect();
|
|
|
|
|
|
|
|
view().update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
Params & ControlInset<Inset, Params>::params()
|
|
|
|
{
|
|
|
|
lyx::Assert(params_);
|
|
|
|
return *params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
Params const & ControlInset<Inset, Params>::params() const
|
|
|
|
{
|
|
|
|
lyx::Assert(params_);
|
|
|
|
return *params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
Inset * ControlInset<Inset, Params>::inset() const
|
|
|
|
{
|
|
|
|
lyx::Assert(inset_);
|
|
|
|
return inset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::updateSlot(bool switched)
|
|
|
|
{
|
|
|
|
if (switched)
|
|
|
|
hide();
|
|
|
|
else
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class Inset, class Params>
|
|
|
|
void ControlInset<Inset, Params>::connectInset(Inset * inset)
|
|
|
|
{
|
|
|
|
// If connected to another inset, disconnect from it.
|
|
|
|
if (inset_) {
|
|
|
|
ih_.disconnect();
|
|
|
|
inset_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inset) {
|
|
|
|
inset_ = inset;
|
|
|
|
ih_ = inset->hideDialog.connect(
|
2002-05-29 16:21:03 +00:00
|
|
|
boost::bind(&ControlInset::hide, this));
|
2002-01-16 14:47:58 +00:00
|
|
|
}
|
|
|
|
connect();
|
|
|
|
}
|