2004-04-29 09:54:59 +00:00
|
|
|
/**
|
|
|
|
* \file Toolbars.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Lars Gullik Bjønnes
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Toolbars.h"
|
|
|
|
|
2004-11-09 12:40:34 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "bufferparams.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "FuncStatus.h"
|
2004-11-09 12:40:34 +00:00
|
|
|
#include "gettext.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
#include "lyxfunc.h"
|
2004-11-09 12:40:34 +00:00
|
|
|
#include "lyxtextclass.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
#include "LyXView.h"
|
2006-11-02 16:01:36 +00:00
|
|
|
#include "lyx_main.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
Toolbars::Toolbars(LyXView & owner)
|
|
|
|
: owner_(owner),
|
|
|
|
layout_(0),
|
|
|
|
last_textclass_(-1)
|
|
|
|
{}
|
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
#define TurnOnFlag(x) flags |= ToolbarBackend::x
|
|
|
|
#define TurnOffFlag(x) flags &= ~ToolbarBackend::x
|
|
|
|
|
|
|
|
void Toolbars::initFlags(ToolbarBackend::Toolbar & tbb)
|
|
|
|
{
|
|
|
|
ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbb.name);
|
|
|
|
|
|
|
|
unsigned int flags = static_cast<unsigned int>(tbb.flags);
|
|
|
|
// remove position
|
|
|
|
TurnOffFlag(TOP);
|
|
|
|
TurnOffFlag(BOTTOM);
|
|
|
|
TurnOffFlag(RIGHT);
|
|
|
|
TurnOffFlag(LEFT);
|
|
|
|
|
|
|
|
bool valid_location = true;
|
|
|
|
// init tbb.flags with saved location
|
|
|
|
if (info.location == ToolbarSection::ToolbarInfo::TOP)
|
|
|
|
TurnOnFlag(TOP);
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM)
|
|
|
|
TurnOnFlag(BOTTOM);
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::RIGHT)
|
|
|
|
TurnOnFlag(RIGHT);
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::LEFT)
|
|
|
|
TurnOnFlag(LEFT);
|
|
|
|
else {
|
|
|
|
TurnOnFlag(TOP);
|
|
|
|
valid_location = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// invalid location is for a new toolbar that has no saved information,
|
|
|
|
// so info.visible is not used for this case.
|
|
|
|
if (valid_location) {
|
|
|
|
// init tbb.flags with saved visibility,
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
TurnOffFlag(OFF);
|
|
|
|
TurnOffFlag(AUTO);
|
|
|
|
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
|
|
|
TurnOnFlag(ON);
|
|
|
|
else if (info.state == ToolbarSection::ToolbarInfo::OFF)
|
|
|
|
TurnOnFlag(OFF);
|
|
|
|
else
|
|
|
|
TurnOnFlag(AUTO);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
std::cout << "State " << info.state << " FLAGS: " << flags
|
|
|
|
<< " ON:" << (flags & ToolbarBackend::ON)
|
|
|
|
<< " OFF:" << (flags & ToolbarBackend::OFF)
|
|
|
|
<< " L:" << (flags & ToolbarBackend::LEFT)
|
|
|
|
<< " R:" << (flags & ToolbarBackend::RIGHT)
|
|
|
|
<< " T:" << (flags & ToolbarBackend::TOP)
|
|
|
|
<< " B:" << (flags & ToolbarBackend::BOTTOM)
|
|
|
|
<< " MA:" << (flags & ToolbarBackend::MATH)
|
|
|
|
<< " RE:" << (flags & ToolbarBackend::REVIEW)
|
|
|
|
<< " TB:" << (flags & ToolbarBackend::TABLE)
|
|
|
|
<< " AU:" << (flags & ToolbarBackend::AUTO)
|
|
|
|
<< std::endl;
|
|
|
|
*/
|
|
|
|
// now set the flags
|
|
|
|
tbb.flags = static_cast<lyx::ToolbarBackend::Flags>(flags);
|
|
|
|
}
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
void Toolbars::init()
|
|
|
|
{
|
|
|
|
// extracts the toolbars from the backend
|
2006-11-02 16:01:36 +00:00
|
|
|
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
initFlags(*cit);
|
2004-04-29 09:54:59 +00:00
|
|
|
add(*cit);
|
2006-11-02 16:01:36 +00:00
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::display(string const & name, bool show)
|
|
|
|
{
|
|
|
|
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
|
|
|
|
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
if (cit->name == name) {
|
|
|
|
displayToolbar(*cit, show);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
|
|
|
|
<< name << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-02 18:59:33 +00:00
|
|
|
ToolbarBackend::Flags Toolbars::getToolbarState(string const & name)
|
|
|
|
{
|
|
|
|
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
|
|
|
|
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
if (cit->name == name)
|
|
|
|
return cit->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
|
|
|
|
<< name << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
void Toolbars::toggleToolbarState(string const & name)
|
|
|
|
{
|
|
|
|
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
if (cit->name == name) {
|
|
|
|
int flags = cit->flags;
|
|
|
|
if (flags & ToolbarBackend::ON) {
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
TurnOnFlag(OFF);
|
|
|
|
} else if (flags & ToolbarBackend::AUTO) {
|
|
|
|
TurnOffFlag(AUTO);
|
|
|
|
TurnOnFlag(ON);
|
|
|
|
} else if ((flags & ToolbarBackend::MATH) || (flags & ToolbarBackend::TABLE)
|
|
|
|
|| (flags & ToolbarBackend::REVIEW)) {
|
|
|
|
// for math etc, toggle from off -> auto
|
|
|
|
TurnOffFlag(OFF);
|
|
|
|
TurnOnFlag(AUTO);
|
|
|
|
} else {
|
|
|
|
// for others, toggle from off -> on
|
|
|
|
TurnOffFlag(OFF);
|
|
|
|
TurnOnFlag(ON);
|
|
|
|
}
|
|
|
|
cit->flags = static_cast<lyx::ToolbarBackend::Flags>(flags);
|
2006-11-02 18:59:33 +00:00
|
|
|
return;
|
2006-11-02 16:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-02 18:59:33 +00:00
|
|
|
lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
|
|
|
|
<< name << endl;
|
2006-11-02 16:01:36 +00:00
|
|
|
}
|
|
|
|
#undef TurnOnFlag
|
|
|
|
#undef TurnOffFlag
|
|
|
|
|
|
|
|
|
2006-10-29 22:50:24 +00:00
|
|
|
void Toolbars::update(bool in_math, bool in_table, bool review)
|
2004-04-29 09:54:59 +00:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
|
|
|
|
// extracts the toolbars from the backend
|
|
|
|
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
|
|
|
|
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
2006-11-02 16:01:36 +00:00
|
|
|
if (cit->flags & ToolbarBackend::ON)
|
|
|
|
displayToolbar(*cit, true);
|
|
|
|
else if (cit->flags & ToolbarBackend::OFF)
|
|
|
|
displayToolbar(*cit, false);
|
|
|
|
else if ((cit->flags & ToolbarBackend::AUTO) && (cit->flags & ToolbarBackend::MATH))
|
2004-04-29 09:54:59 +00:00
|
|
|
displayToolbar(*cit, in_math);
|
2006-11-02 16:01:36 +00:00
|
|
|
else if ((cit->flags & ToolbarBackend::AUTO) && (cit->flags & ToolbarBackend::TABLE))
|
2004-04-29 09:54:59 +00:00
|
|
|
displayToolbar(*cit, in_table);
|
2006-11-02 16:01:36 +00:00
|
|
|
else if ((cit->flags & ToolbarBackend::AUTO) && (cit->flags & ToolbarBackend::REVIEW))
|
2006-10-29 22:50:24 +00:00
|
|
|
displayToolbar(*cit, review);
|
2004-04-29 09:54:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
void Toolbars::saveToolbarInfo()
|
|
|
|
{
|
|
|
|
ToolbarSection & tb = LyX::ref().session().toolbars();
|
|
|
|
|
|
|
|
for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
cit != toolbarbackend.end(); ++cit) {
|
|
|
|
ToolbarsMap::iterator it = toolbars_.find(cit->name);
|
|
|
|
BOOST_ASSERT(it != toolbars_.end());
|
|
|
|
// get toolbar info from session.
|
|
|
|
ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
|
|
|
|
if (cit->flags & ToolbarBackend::ON)
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::ON;
|
|
|
|
else if (cit->flags & ToolbarBackend::OFF)
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::OFF;
|
|
|
|
else if (cit->flags & ToolbarBackend::AUTO)
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::AUTO;
|
|
|
|
// save other information
|
|
|
|
// if auto, frontend should *not* set on/off
|
|
|
|
it->second->saveInfo(info);
|
|
|
|
// maybe it is useful to update flags with real status. I do not know
|
|
|
|
/*
|
|
|
|
if (!(cit->flags & ToolbarBackend::AUTO)) {
|
|
|
|
unsigned int flags = static_cast<unsigned int>(cit->flags);
|
|
|
|
flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarBackend::OFF : ToolbarBackend::ON);
|
|
|
|
flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarBackend::ON : ToolbarBackend::OFF);
|
|
|
|
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
|
|
|
cit->flags = static_cast<lyx::ToolbarBackend::Flags>(flags);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void Toolbars::setLayout(string const & layout)
|
|
|
|
{
|
|
|
|
if (layout_)
|
|
|
|
layout_->set(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Toolbars::updateLayoutList(int textclass)
|
|
|
|
{
|
|
|
|
// update the layout display
|
|
|
|
if (last_textclass_ != textclass) {
|
|
|
|
if (layout_)
|
|
|
|
layout_->update();
|
|
|
|
last_textclass_ = textclass;
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::openLayoutList()
|
|
|
|
{
|
|
|
|
if (layout_)
|
|
|
|
layout_->open();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::clearLayoutList()
|
|
|
|
{
|
|
|
|
last_textclass_ = -1;
|
|
|
|
if (layout_)
|
|
|
|
layout_->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::add(ToolbarBackend::Toolbar const & tbb)
|
|
|
|
{
|
2006-09-10 11:03:21 +00:00
|
|
|
ToolbarPtr tb_ptr = owner_.makeToolbar(tbb);
|
2004-04-29 09:54:59 +00:00
|
|
|
toolbars_[tbb.name] = tb_ptr;
|
|
|
|
|
2006-10-31 13:59:22 +00:00
|
|
|
if (tbb.flags & ToolbarBackend::ON)
|
|
|
|
tb_ptr->show(false);
|
|
|
|
else
|
|
|
|
tb_ptr->hide(false);
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
if (tb_ptr->layout())
|
|
|
|
layout_ = tb_ptr->layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::displayToolbar(ToolbarBackend::Toolbar const & tbb,
|
|
|
|
bool show_it)
|
|
|
|
{
|
|
|
|
ToolbarsMap::iterator it = toolbars_.find(tbb.name);
|
|
|
|
BOOST_ASSERT(it != toolbars_.end());
|
|
|
|
|
|
|
|
if (show_it)
|
|
|
|
it->second->show(true);
|
|
|
|
else
|
|
|
|
it->second->hide(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::update()
|
|
|
|
{
|
|
|
|
ToolbarsMap::const_iterator it = toolbars_.begin();
|
|
|
|
ToolbarsMap::const_iterator const end = toolbars_.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
it->second->update();
|
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
bool const enable =
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
if (layout_)
|
|
|
|
layout_->setEnabled(enable);
|
|
|
|
}
|
2004-11-09 12:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
void layoutSelected(LyXView & lv, string const & name)
|
|
|
|
{
|
|
|
|
LyXTextClass const & tc = lv.buffer()->params().getLyXTextClass();
|
|
|
|
|
|
|
|
LyXTextClass::const_iterator it = tc.begin();
|
|
|
|
LyXTextClass::const_iterator const end = tc.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
string const & itname = (*it)->name();
|
2006-09-09 15:27:44 +00:00
|
|
|
// Yes, the lyx::to_utf8(_()) is correct
|
|
|
|
if (lyx::to_utf8(_(itname)) == name) {
|
2004-11-26 14:52:54 +00:00
|
|
|
FuncRequest const func(LFUN_LAYOUT, itname,
|
2004-11-09 12:40:34 +00:00
|
|
|
FuncRequest::UI);
|
2006-10-11 17:24:46 +00:00
|
|
|
lv.dispatch(func);
|
2004-11-09 12:40:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-11-26 14:52:54 +00:00
|
|
|
lyxerr << "ERROR (layoutSelected): layout not found!"
|
2004-11-09 12:40:34 +00:00
|
|
|
<< endl;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|