merge frontend::Gui and frontend::Application

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21656 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-11-17 20:47:50 +00:00
parent bdf33a2a32
commit 1005c166c2
13 changed files with 169 additions and 307 deletions

View File

@ -79,7 +79,6 @@
#include "frontends/Dialogs.h"
#include "frontends/FileDialog.h"
#include "frontends/FontLoader.h"
#include "frontends/Gui.h"
#include "frontends/KeySymbol.h"
#include "frontends/LyXView.h"
#include "frontends/Selection.h"
@ -702,7 +701,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break;
}
case LFUN_WINDOW_CLOSE: {
enable = (theApp()->gui().viewIds().size() > 1);
enable = (theApp()->viewIds().size() > 1);
break;
}
@ -1245,7 +1244,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// (leaving the event loop).
lyx_view_->message(from_utf8(N_("Exiting.")));
if (theBufferList().quitWriteAll())
theApp()->gui().closeAllViews();
theApp()->closeAllViews();
break;
case LFUN_BUFFER_AUTO_SAVE:
@ -1564,7 +1563,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_DIALOG_HIDE: {
if (quitting || !use_gui)
break;
theApp()->gui().hideDialogs(argument, 0);
theApp()->hideDialogs(argument, 0);
break;
}

View File

@ -16,7 +16,6 @@
#include "frontends/NoGuiFontMetrics.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Gui.h"
#include "frontends/LyXView.h"
#include "FuncRequest.h"

View File

@ -17,10 +17,15 @@
#include <boost/function.hpp>
#include <vector>
namespace lyx {
class BufferView;
struct RGBColor;
class Buffer;
class Inset;
namespace frontend {
@ -149,8 +154,21 @@ public:
virtual ~Application() {}
///
virtual Gui & gui() = 0;
virtual Gui const & gui() const = 0;
virtual int createRegisteredView() = 0;
///
virtual bool unregisterView(int id) = 0;
///
virtual bool closeAllViews() = 0;
///
virtual LyXView & view(int id) const = 0;
///
std::vector<int> const & viewIds() { return view_ids_; }
///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
///
virtual Buffer const * updateInset(Inset const * inset) const = 0;
/// Start the main event loop.
/// The batch command is programmed to be execute once
@ -225,10 +243,12 @@ public:
///
void setCurrentView(LyXView & view) { current_view_ = &view; }
private:
protected:
/// This LyXView is the one receiving Clipboard and Selection
/// events
LyXView * current_view_;
///
std::vector<int> view_ids_;
};
} // namespace frontend
@ -236,7 +256,6 @@ private:
frontend::Application * theApp();
frontend::Application * createApplication(int & argc, char * argv[]);
} // namespace lyx

View File

@ -1,65 +0,0 @@
// -*- C++ -*-
/**
* \file Gui.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author unknown
* \author John Levon
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#ifndef BASE_GUI_H
#define BASE_GUI_H
#include "support/strfwd.h"
#include <vector>
namespace lyx {
class Buffer;
class Inset;
namespace frontend {
class LyXView;
/**
* A Gui class manages the different frontend elements.
*/
class Gui
{
public:
virtual ~Gui() {}
///
virtual int createRegisteredView() = 0;
///
virtual bool unregisterView(int id) = 0;
///
virtual bool closeAllViews() = 0;
///
virtual LyXView & view(int id) const = 0;
///
std::vector<int> const & viewIds() { return view_ids_; }
///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
///
virtual Buffer const * updateInset(Inset const * inset) const = 0;
protected:
///
std::vector<int> view_ids_;
};
} // namespace frontend
} // namespace lyx
#endif // BASE_GUI_H

View File

@ -24,7 +24,6 @@ liblyxfrontends_la_SOURCES = \
Painter.cpp \
Painter.h \
Clipboard.h \
Gui.h \
Selection.h \
WorkArea.h \
WorkAreaManager.cpp \

View File

@ -14,9 +14,10 @@
#include "GuiApplication.h"
#include "GuiView.h"
#include "qt_helpers.h"
#include "GuiImage.h"
#include "GuiView.h"
#include "Dialogs.h"
#include "frontends/alert.h"
@ -64,8 +65,10 @@
#include <exception>
using std::string;
using std::endl;
using std::map;
using std::string;
using std::vector;
namespace lyx {
@ -197,12 +200,12 @@ GuiApplication::~GuiApplication()
LyXView & GuiApplication::createView(string const & geometry_arg)
{
int const id = gui_.createRegisteredView();
GuiView & view = static_cast<GuiView &>(gui_.view(id));
theLyXFunc().setLyXView(&view);
int const id = createRegisteredView();
GuiView * view = views_[id];
theLyXFunc().setLyXView(view);
view.init();
view.show();
view->init();
view->show();
if (!geometry_arg.empty()) {
#ifdef Q_WS_WIN
int x, y;
@ -213,14 +216,14 @@ LyXView & GuiApplication::createView(string const & geometry_arg)
h = re.cap(2).toInt();
x = re.cap(3).toInt();
y = re.cap(4).toInt();
view.setGeometry(x, y, w, h);
view->setGeometry(x, y, w, h);
#endif
}
view.setFocus();
view->setFocus();
setCurrentView(view);
setCurrentView(*view);
return view;
return *view;
}
@ -424,6 +427,106 @@ void GuiApplication::commitData(QSessionManager & sm)
}
void GuiApplication::addMenuTranslator()
{
installTranslator(new MenuTranslator(this));
}
static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
{
ids.clear();
map<int, GuiView *>::const_iterator it;
for (it = stdmap.begin(); it != stdmap.end(); ++it)
ids.push_back(it->first);
}
int GuiApplication::createRegisteredView()
{
updateIds(views_, view_ids_);
int id = 0;
while (views_.find(id) != views_.end())
id++;
views_[id] = new GuiView(id);
updateIds(views_, view_ids_);
return id;
}
bool GuiApplication::unregisterView(int id)
{
updateIds(views_, view_ids_);
BOOST_ASSERT(views_.find(id) != views_.end());
BOOST_ASSERT(views_[id]);
map<int, GuiView *>::iterator it;
for (it = views_.begin(); it != views_.end(); ++it) {
if (it->first == id) {
views_.erase(id);
break;
}
}
updateIds(views_, view_ids_);
return true;
}
bool GuiApplication::closeAllViews()
{
updateIds(views_, view_ids_);
if (views_.empty()) {
// quit in CloseEvent will not be triggert
qApp->quit();
return true;
}
map<int, GuiView*> const cmap = views_;
map<int, GuiView*>::const_iterator it;
for (it = cmap.begin(); it != cmap.end(); ++it) {
// TODO: return false when close event was ignored
// e.g. quitWriteAll()->'Cancel'
// maybe we need something like 'bool closeView()'
it->second->close();
// unregisterd by the CloseEvent
}
views_.clear();
view_ids_.clear();
return true;
}
LyXView & GuiApplication::view(int id) const
{
BOOST_ASSERT(views_.find(id) != views_.end());
return *views_.find(id)->second;
}
void GuiApplication::hideDialogs(string const & name, Inset * inset) const
{
vector<int>::const_iterator it = view_ids_.begin();
vector<int>::const_iterator const end = view_ids_.end();
for (; it != end; ++it)
view(*it).getDialogs().hide(name, inset);
}
Buffer const * GuiApplication::updateInset(Inset const * inset) const
{
Buffer const * buffer_ = 0;
vector<int>::const_iterator it = view_ids_.begin();
vector<int>::const_iterator const end = view_ids_.end();
for (; it != end; ++it) {
Buffer const * ptr = view(*it).updateInset(inset);
if (ptr)
buffer_ = ptr;
}
return buffer_;
}
////////////////////////////////////////////////////////////////////////
// X11 specific stuff goes here...
#ifdef Q_WS_X11
@ -459,12 +562,6 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
}
#endif
void GuiApplication::addMenuTranslator()
{
installTranslator(new MenuTranslator(this));
}
} // namespace frontend
} // namespace lyx

View File

@ -16,14 +16,16 @@
#include "ColorCache.h"
#include "GuiFontLoader.h"
#include "GuiClipboard.h"
#include "GuiImplementation.h"
#include "GuiSelection.h"
#include "frontends/Application.h"
#include <QObject>
#include <QApplication>
#include <QTranslator>
#include <map>
class QSessionManager;
namespace lyx {
@ -32,6 +34,8 @@ class BufferView;
namespace frontend {
class GuiView;
class LyXView;
class GuiWorkArea;
class SocketNotifier;
@ -58,8 +62,6 @@ public:
virtual Selection & selection();
virtual FontLoader & fontLoader() { return font_loader_; }
virtual int exec();
virtual Gui & gui() { return gui_; }
virtual Gui const & gui() const { return gui_; }
virtual void exit(int status);
virtual bool event(QEvent * e);
void syncEvents();
@ -83,9 +85,19 @@ public:
///
ColorCache & colorCache() { return color_cache_; }
///
///
GuiFontLoader & guiFontLoader() { return font_loader_; }
virtual int createRegisteredView();
virtual bool closeAllViews();
virtual bool unregisterView(int id);
virtual LyXView & view(int id) const;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const;
///
virtual Buffer const * updateInset(Inset const * inset) const;
private Q_SLOTS:
///
void execBatchCommands();
@ -93,8 +105,6 @@ private Q_SLOTS:
void socketDataReceived(int fd);
private:
///
GuiImplementation gui_;
///
GuiClipboard clipboard_;
///
@ -115,6 +125,14 @@ public:
/// A translator suitable for the entries in the LyX menu.
/// Only needed with Qt/Mac.
void addMenuTranslator();
/// Multiple views container.
/**
* Warning: This must not be a smart pointer as the destruction of the
* object is handled by Qt when the view is closed
* \sa Qt::WA_DeleteOnClose attribute.
*/
std::map<int, GuiView *> views_;
}; // GuiApplication
extern GuiApplication * guiApp;

View File

@ -1,135 +0,0 @@
// -*- C++ -*-
/**
* \file GuiImplementation.cpp
* 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.
*/
#include <config.h>
#include "GuiImplementation.h"
#include "GuiView.h"
#include "Dialogs.h"
#include <boost/assert.hpp>
#include <QApplication>
using std::map;
using std::vector;
using std::string;
namespace lyx {
namespace frontend {
static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
{
ids.clear();
map<int, GuiView *>::const_iterator it;
for (it = stdmap.begin(); it != stdmap.end(); ++it)
ids.push_back(it->first);
}
GuiImplementation::GuiImplementation()
{
view_ids_.clear();
}
int GuiImplementation::createRegisteredView()
{
updateIds(views_, view_ids_);
int id = 0;
while (views_.find(id) != views_.end())
id++;
views_[id] = new GuiView(id);
updateIds(views_, view_ids_);
return id;
}
bool GuiImplementation::unregisterView(int id)
{
updateIds(views_, view_ids_);
BOOST_ASSERT(views_.find(id) != views_.end());
BOOST_ASSERT(views_[id]);
map<int, GuiView *>::iterator it;
for (it = views_.begin(); it != views_.end(); ++it) {
if (it->first == id) {
views_.erase(id);
break;
}
}
updateIds(views_, view_ids_);
return true;
}
bool GuiImplementation::closeAllViews()
{
updateIds(views_, view_ids_);
if (views_.empty()) {
// quit in CloseEvent will not be triggert
qApp->quit();
return true;
}
map<int, GuiView*> const cmap = views_;
map<int, GuiView*>::const_iterator it;
for (it = cmap.begin(); it != cmap.end(); ++it) {
// TODO: return false when close event was ignored
// e.g. quitWriteAll()->'Cancel'
// maybe we need something like 'bool closeView()'
it->second->close();
// unregisterd by the CloseEvent
}
views_.clear();
view_ids_.clear();
return true;
}
LyXView & GuiImplementation::view(int id) const
{
BOOST_ASSERT(views_.find(id) != views_.end());
return *views_.find(id)->second;
}
void GuiImplementation::hideDialogs(string const & name, Inset * inset) const
{
vector<int>::const_iterator it = view_ids_.begin();
vector<int>::const_iterator const end = view_ids_.end();
for (; it != end; ++it)
view(*it).getDialogs().hide(name, inset);
}
Buffer const * GuiImplementation::updateInset(Inset const * inset) const
{
Buffer const * buffer_ptr = 0;
vector<int>::const_iterator it = view_ids_.begin();
vector<int>::const_iterator const end = view_ids_.end();
for (; it != end; ++it) {
Buffer const * ptr = view(*it).updateInset(inset);
if (ptr)
buffer_ptr = ptr;
}
return buffer_ptr;
}
} // namespace frontend
} // namespace lyx
#include "GuiImplementation_moc.cpp"

View File

@ -1,62 +0,0 @@
// -*- C++ -*-
/**
* \file GuiImplementation.h
* 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.
*/
#ifndef GUI_H
#define GUI_H
#include "frontends/Gui.h"
#include <QObject>
#include <map>
namespace lyx {
namespace frontend {
class GuiView;
class LyXView;
/**
* The GuiImplementation class is the interface to all Qt4 components.
*/
class GuiImplementation : public QObject, public Gui
{
Q_OBJECT
public:
GuiImplementation();
virtual ~GuiImplementation() {}
virtual int createRegisteredView();
virtual bool closeAllViews();
virtual bool unregisterView(int id);
virtual LyXView& view(int id) const;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const;
///
virtual Buffer const * updateInset(Inset const * inset) const;
private:
/// Multiple views container.
/**
* Warning: This must not be a smart pointer as the destruction of the
* object is handled by Qt when the view is closed
* \sa Qt::WA_DeleteOnClose attribute.
*/
std::map<int, GuiView *> views_;
};
} // namespace frontend
} // namespace lyx
#endif // GUI_H

View File

@ -15,20 +15,17 @@
#include "GuiView.h"
#include "GuiImplementation.h"
#include "GuiWorkArea.h"
#include "GuiKeySymbol.h"
#include "GuiMenubar.h"
#include "GuiToolbar.h"
#include "GuiToolbars.h"
#include "Dialogs.h"
#include "Gui.h"
#include "qt_helpers.h"
#include "frontends/Application.h"
#include "frontends/Dialogs.h"
#include "frontends/Gui.h"
#include "support/filetools.h"
#include "support/convert.h"
@ -406,7 +403,7 @@ void GuiView::closeEvent(QCloseEvent * close_event)
{
// we may have been called through the close window button
// which bypasses the LFUN machinery.
if (!quitting_by_menu_ && theApp()->gui().viewIds().size() == 1) {
if (!quitting_by_menu_ && theApp()->viewIds().size() == 1) {
if (!theBufferList().quitWriteAll()) {
close_event->ignore();
return;
@ -431,8 +428,8 @@ void GuiView::closeEvent(QCloseEvent * close_event)
d.toolbars_->saveToolbarInfo();
}
theApp()->gui().unregisterView(id());
if (!theApp()->gui().viewIds().empty()) {
theApp()->unregisterView(id());
if (!theApp()->viewIds().empty()) {
// Just close the window and do nothing else if this is not the
// last window.
close_event->accept();

View File

@ -87,7 +87,6 @@ SOURCEFILES = \
GuiGraphics.cpp \
GuiHyperlink.cpp \
GuiImage.cpp \
GuiImplementation.cpp \
GuiInclude.cpp \
GuiIndex.cpp \
GuiKeySymbol.cpp \
@ -176,7 +175,6 @@ MOCHEADER = \
GuiFontExample.h \
GuiGraphics.h \
GuiHyperlink.h \
GuiImplementation.h \
GuiInclude.h \
GuiIndex.h \
GuiKeySymbol.h \

View File

@ -34,7 +34,6 @@
#include "frontends/Painter.h"
#include "frontends/Application.h"
#include "frontends/Gui.h"
#include "support/convert.h"
@ -390,7 +389,7 @@ Buffer const * Inset::updateFrontend() const
{
if (quitting)
return 0;
return theApp()->gui().updateInset(this);
return theApp()->updateInset(this);
}
} // namespace lyx

View File

@ -16,7 +16,6 @@
#include "debug.h"
#include "frontends/Application.h"
#include "frontends/Gui.h"
#include <boost/assert.hpp>
@ -42,7 +41,7 @@ void MailInset::updateDialog(BufferView * bv) const
void MailInset::hideDialog() const
{
theApp()->gui().hideDialogs(name(), &inset());
theApp()->hideDialogs(name(), &inset());
}