lyx_mirror/src/frontends/controllers/ControlInset.tmpl
Angus Leeming 649e3fee9a Rob's patch, part 1: the checked widget stuff.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5467 a592a061-630c-0410-9148-cb99ea01b6c8
2002-10-22 12:39:05 +00:00

197 lines
3.5 KiB
C++

// -*- C++ -*-
/**
* \file ControlInset.tmpl
* 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
*
* 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"
#include "ButtonControllerBase.h"
#include "ViewBase.h"
#include "support/LAssert.h"
#include <boost/bind.hpp>
template <class Inset, class Params>
ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
: ControlConnectBD(lv, d),
inset_(0), params_(0), dialog_built_(false)
{}
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));
// The widgets may not be valid, so refresh the button controller
bc().refresh();
}
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;
}
bc().readOnly(bufferIsReadonly());
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;
}
bc().readOnly(bufferIsReadonly());
view().update();
// The widgets may not be valid, so refresh the button controller
bc().refresh();
}
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()
{
if (bufferIsReadonly())
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(
boost::bind(&ControlInset::hide, this));
}
connect();
}