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
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
#include <QApplication>
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
using boost::shared_ptr;
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template<class T>
|
|
|
|
void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids)
|
|
|
|
{
|
|
|
|
ids.clear();
|
|
|
|
typename std::map<int, T*>::const_iterator it;
|
|
|
|
for (it = stdmap.begin(); it != stdmap.end(); ++it)
|
|
|
|
ids.push_back(it->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
GuiImplementation::GuiImplementation()
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
view_ids_.clear();
|
|
|
|
work_area_ids_.clear();
|
2006-06-20 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
LyXView& GuiImplementation::createRegisteredView()
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
int id = 0;
|
|
|
|
while (views_.find(id) != views_.end())
|
|
|
|
id++;
|
|
|
|
views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
return *views_[id];
|
2006-06-20 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
bool GuiImplementation::unregisterView(int id)
|
2006-06-20 08:39:16 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
updateIds(views_, view_ids_);
|
2006-06-26 16:55:35 +00:00
|
|
|
BOOST_ASSERT(views_.find(id) != views_.end());
|
2006-12-02 17:39:31 +00:00
|
|
|
BOOST_ASSERT(views_[id]);
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
std::map<int, GuiView *>::iterator it;
|
|
|
|
for (it = views_.begin(); it != views_.end(); ++it) {
|
|
|
|
if (it->first == id) {
|
|
|
|
std::vector<int> const & wa_ids = it->second->workAreaIds();
|
|
|
|
for (size_t i = 0; i < wa_ids.size(); ++i)
|
|
|
|
work_areas_.erase(wa_ids[i]);
|
|
|
|
views_.erase(id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
return true;
|
2006-10-23 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
bool GuiImplementation::closeAllViews()
|
2006-10-24 15:01:07 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
if (views_.empty())
|
|
|
|
{
|
|
|
|
// quit in CloseEvent will not be triggert
|
|
|
|
qApp->quit();
|
|
|
|
return true;
|
|
|
|
}
|
2006-10-24 15:01:07 +00:00
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
std::map<int, GuiView*> const cmap = views_;
|
|
|
|
std::map<int, GuiView*>::const_iterator it;
|
|
|
|
for (it = cmap.begin(); it != cmap.end(); ++it)
|
|
|
|
{
|
2006-12-12 10:54:37 +00:00
|
|
|
// TODO: return false when close event was ignored
|
|
|
|
// e.g. quitWriteAll()->'Cancel'
|
|
|
|
// maybe we need something like 'bool closeView()'
|
|
|
|
it->second->close();
|
2006-12-02 17:39:31 +00:00
|
|
|
// unregisterd by the CloseEvent
|
2006-10-24 15:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
views_.clear();
|
|
|
|
work_areas_.clear();
|
2006-12-02 17:39:31 +00:00
|
|
|
view_ids_.clear();
|
|
|
|
work_area_ids_.clear();
|
2006-10-24 15:01:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
LyXView& GuiImplementation::view(int id) const
|
2006-10-23 16:29:24 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
BOOST_ASSERT(views_.find(id) != views_.end());
|
|
|
|
return *views_.find(id)->second;
|
2006-06-26 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
std::vector<int> const & GuiImplementation::workAreaIds()
|
2006-06-26 16:55:35 +00:00
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
updateIds(work_areas_, work_area_ids_);
|
|
|
|
return work_area_ids_;
|
2006-06-26 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
|
|
|
|
{
|
2006-12-02 17:39:31 +00:00
|
|
|
updateIds(views_, view_ids_);
|
|
|
|
int id = 0;
|
|
|
|
while (work_areas_.find(id) != work_areas_.end())
|
|
|
|
id++;
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-10-23 16:29:24 +00:00
|
|
|
GuiView * view = views_[view_id];
|
2006-06-26 16:55:35 +00:00
|
|
|
|
2006-12-02 17:39:31 +00:00
|
|
|
work_areas_.insert(std::pair<int, GuiWorkArea *>
|
|
|
|
(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-31 14:12:46 +00:00
|
|
|
view->setWorkArea(work_areas_[id]);
|
|
|
|
view->initTab(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"
|