2006-06-20 08:39:16 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GuiImplementation.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-07-08 13:27:43 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
// This include must be declared before everything else because
|
|
|
|
// of boost/Qt/LyX clash...
|
|
|
|
#include "GuiView.h"
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#include "GuiImplementation.h"
|
|
|
|
#include "GuiWorkArea.h"
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
#include "BufferView.h"
|
2006-10-24 15:01:07 +00:00
|
|
|
#include "bufferlist.h"
|
2006-10-23 16:29:24 +00:00
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "lyxfunc.h"
|
2006-06-20 08:39:16 +00:00
|
|
|
|
|
|
|
using boost::shared_ptr;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
GuiImplementation::GuiImplementation(): max_view_id_(0), max_wa_id_(0)
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-12 22:30:42 +00:00
|
|
|
int GuiImplementation::newView()
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
2006-06-26 16:55:35 +00:00
|
|
|
size_t const id = max_view_id_;
|
|
|
|
++max_view_id_;
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
views_[id] = new GuiView(id);
|
|
|
|
view_ids_.push_back(id);
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
LyXView& GuiImplementation::view(int id)
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
2006-06-26 16:55:35 +00:00
|
|
|
BOOST_ASSERT(views_.find(id) != views_.end());
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
return *views_[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-24 15:01:07 +00:00
|
|
|
bool GuiImplementation::closeAll()
|
|
|
|
{
|
|
|
|
if (!theBufferList().quitWriteAll())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// In order to know if it is the last opened window,
|
|
|
|
// GuiView::closeEvent() check for (view_ids_.size() == 1)
|
|
|
|
// We deny this check by setting the vector size to zero.
|
|
|
|
// But we still need the vector, hence the temporary copy.
|
|
|
|
std::vector<int> view_ids_tmp = view_ids_;
|
|
|
|
view_ids_.clear();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < view_ids_tmp.size(); ++i) {
|
|
|
|
// LFUN_LYX_QUIT has already been triggered so we need
|
|
|
|
// to disable the lastWindowClosed() signal before closing
|
|
|
|
// the last window.
|
|
|
|
views_[view_ids_tmp[i]]->setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
views_[view_ids_tmp[i]]->close();
|
|
|
|
// The view_ids_ vector is reconstructed in the closeEvent; so
|
|
|
|
// let's clear that out again!
|
|
|
|
view_ids_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
views_.clear();
|
|
|
|
view_ids_.clear();
|
|
|
|
work_areas_.clear();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiImplementation::unregisterView(GuiView * view)
|
2006-10-23 16:29:24 +00:00
|
|
|
{
|
|
|
|
std::map<int, GuiView *>::iterator I;
|
|
|
|
|
|
|
|
for (I = views_.begin(); I != views_.end(); ++I) {
|
|
|
|
if (I->second == view) {
|
2006-10-24 15:01:07 +00:00
|
|
|
std::vector<int> const & wa_ids = view->workAreaIds();
|
|
|
|
for (size_t i = 0; i < wa_ids.size(); ++i)
|
|
|
|
work_areas_.erase(wa_ids[i]);
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
views_.erase(I->first);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildViewIds();
|
|
|
|
|
|
|
|
if (views_.empty()) {
|
|
|
|
theLyXFunc().setLyXView(0);
|
|
|
|
// dispatch(FuncRequest(LFUN_LYX_QUIT));
|
|
|
|
return;
|
|
|
|
}
|
2006-10-24 15:01:07 +00:00
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
theLyXFunc().setLyXView(views_.begin()->second);
|
2006-06-26 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
void GuiImplementation::buildViewIds()
|
2006-06-26 16:55:35 +00:00
|
|
|
{
|
2006-10-23 16:29:24 +00:00
|
|
|
view_ids_.clear();
|
|
|
|
std::map<int, GuiView *>::const_iterator I;
|
|
|
|
for (I = views_.begin(); I != views_.end(); ++I)
|
|
|
|
view_ids_.push_back(I->first);
|
2006-06-26 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
|
|
|
|
{
|
|
|
|
size_t const id = max_wa_id_;
|
|
|
|
++max_wa_id_;
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
GuiView * view = views_[view_id];
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
work_areas_[id] = new GuiWorkArea(w, h, id, *view);
|
2006-06-26 16:55:35 +00:00
|
|
|
|
|
|
|
// FIXME BufferView creation should be independant of WorkArea creation
|
2006-09-26 12:46:27 +00:00
|
|
|
buffer_views_[id].reset(new BufferView);
|
2006-06-26 16:55:35 +00:00
|
|
|
work_areas_[id]->setBufferView(buffer_views_[id].get());
|
2006-10-23 16:29:24 +00:00
|
|
|
view->setWorkArea(work_areas_[id]);
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
view->setCentralWidget(work_areas_[id]);
|
2006-06-20 08:39:16 +00:00
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WorkArea& GuiImplementation::workArea(int id)
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
return *work_areas_[id];
|
2006-06-20 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-10-23 16:29:24 +00:00
|
|
|
|
|
|
|
#include "GuiImplementation_moc.cpp"
|