// -*- C++ -*- /* * \file ControlInset.tmpl * Copyright 2002 the LyX Team * Read the file COPYING * * \author Angus Leeming * * 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 template ControlInset::ControlInset(LyXView & lv, Dialogs & d) : ControlConnectBD(lv, d), inset_(0), params_(0), dialog_built_(false) {} template void ControlInset::showInset(Inset * inset) { if (inset == 0) return; // maybe we should Assert this? connectInset(inset); show(getParams(*inset)); } template void ControlInset::createInset(string const & arg) { connectInset(); if (!arg.empty()) bc().valid(); // so that the user can press Ok show(getParams(arg)); } template void ControlInset::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 void ControlInset::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(); } template void ControlInset::hide() { emergency_exit_ = false; if (params_) { delete params_; params_ = 0; } inset_ = 0; clearDaughterParams(); ih_.disconnect(); disconnect(); view().hide(); } template void ControlInset::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 Params & ControlInset::params() { lyx::Assert(params_); return *params_; } template Params const & ControlInset::params() const { lyx::Assert(params_); return *params_; } template Inset * ControlInset::inset() const { lyx::Assert(inset_); return inset_; } template void ControlInset::updateSlot(bool switched) { if (switched) hide(); else update(); } template void ControlInset::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(); }