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-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);
|
|
|
|
|
|
|
|
QObject::connect(views_[id], SIGNAL(destroyed(QObject *)),
|
|
|
|
this, SLOT(cleanupViews(QObject *)));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiImplementation::cleanupViews(QObject * qobj)
|
|
|
|
{
|
|
|
|
GuiView * view = static_cast<GuiView *>(qobj);
|
|
|
|
std::map<int, GuiView *>::iterator I;
|
|
|
|
|
|
|
|
for (I = views_.begin(); I != views_.end(); ++I) {
|
|
|
|
if (I->second == view) {
|
|
|
|
views_.erase(I->first);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildViewIds();
|
|
|
|
|
|
|
|
if (views_.empty()) {
|
|
|
|
theLyXFunc().setLyXView(0);
|
|
|
|
// dispatch(FuncRequest(LFUN_LYX_QUIT));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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"
|