From 1005c166c2dcd7a31dd11a290b44d48957b04a5b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 17 Nov 2007 20:47:50 +0000 Subject: [PATCH] merge frontend::Gui and frontend::Application git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21656 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXFunc.cpp | 7 +- src/frontends/Application.cpp | 1 - src/frontends/Application.h | 27 ++++- src/frontends/Gui.h | 65 ------------ src/frontends/Makefile.am | 1 - src/frontends/qt4/GuiApplication.cpp | 131 ++++++++++++++++++++--- src/frontends/qt4/GuiApplication.h | 30 ++++-- src/frontends/qt4/GuiImplementation.cpp | 135 ------------------------ src/frontends/qt4/GuiImplementation.h | 62 ----------- src/frontends/qt4/GuiView.cpp | 9 +- src/frontends/qt4/Makefile.am | 2 - src/insets/Inset.cpp | 3 +- src/insets/MailInset.cpp | 3 +- 13 files changed, 169 insertions(+), 307 deletions(-) delete mode 100644 src/frontends/Gui.h delete mode 100644 src/frontends/qt4/GuiImplementation.cpp delete mode 100644 src/frontends/qt4/GuiImplementation.h diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 28ff404be2..0ec1e9c4e9 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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; } diff --git a/src/frontends/Application.cpp b/src/frontends/Application.cpp index 890aa257ac..c62bf8d584 100644 --- a/src/frontends/Application.cpp +++ b/src/frontends/Application.cpp @@ -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" diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 8fbdc47989..28e74f10c8 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -17,10 +17,15 @@ #include +#include + + 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 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 view_ids_; }; } // namespace frontend @@ -236,7 +256,6 @@ private: frontend::Application * theApp(); frontend::Application * createApplication(int & argc, char * argv[]); - } // namespace lyx diff --git a/src/frontends/Gui.h b/src/frontends/Gui.h deleted file mode 100644 index f0372f6d14..0000000000 --- a/src/frontends/Gui.h +++ /dev/null @@ -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 - - -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 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 view_ids_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // BASE_GUI_H diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index 5e361c4771..5c6cf8e727 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -24,7 +24,6 @@ liblyxfrontends_la_SOURCES = \ Painter.cpp \ Painter.h \ Clipboard.h \ - Gui.h \ Selection.h \ WorkArea.h \ WorkAreaManager.cpp \ diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index c7e963ed59..6edfdd7c88 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -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 -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(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 const & stdmap, vector & ids) +{ + ids.clear(); + map::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::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 const cmap = views_; + map::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::const_iterator it = view_ids_.begin(); + vector::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::const_iterator it = view_ids_.begin(); + vector::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 diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 22b55beaf7..702051d380 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -16,14 +16,16 @@ #include "ColorCache.h" #include "GuiFontLoader.h" #include "GuiClipboard.h" -#include "GuiImplementation.h" #include "GuiSelection.h" #include "frontends/Application.h" +#include #include #include +#include + 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 views_; }; // GuiApplication extern GuiApplication * guiApp; diff --git a/src/frontends/qt4/GuiImplementation.cpp b/src/frontends/qt4/GuiImplementation.cpp deleted file mode 100644 index d370ffb9e0..0000000000 --- a/src/frontends/qt4/GuiImplementation.cpp +++ /dev/null @@ -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 - -#include "GuiImplementation.h" -#include "GuiView.h" -#include "Dialogs.h" - -#include - -#include - -using std::map; -using std::vector; -using std::string; - - -namespace lyx { -namespace frontend { - - -static void updateIds(map const & stdmap, vector & ids) -{ - ids.clear(); - map::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::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 const cmap = views_; - map::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::const_iterator it = view_ids_.begin(); - vector::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::const_iterator it = view_ids_.begin(); - vector::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" diff --git a/src/frontends/qt4/GuiImplementation.h b/src/frontends/qt4/GuiImplementation.h deleted file mode 100644 index 4474949172..0000000000 --- a/src/frontends/qt4/GuiImplementation.h +++ /dev/null @@ -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 - -#include - -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 views_; -}; - -} // namespace frontend -} // namespace lyx - -#endif // GUI_H diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index ebd6ad54fb..11f90e2039 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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(); diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index e3700f6ddf..88cc6d165e 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 \ diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index b8e6c7cb51..e2213ef51d 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -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 diff --git a/src/insets/MailInset.cpp b/src/insets/MailInset.cpp index a7a843845c..57658ab391 100644 --- a/src/insets/MailInset.cpp +++ b/src/insets/MailInset.cpp @@ -16,7 +16,6 @@ #include "debug.h" #include "frontends/Application.h" -#include "frontends/Gui.h" #include @@ -42,7 +41,7 @@ void MailInset::updateDialog(BufferView * bv) const void MailInset::hideDialog() const { - theApp()->gui().hideDialogs(name(), &inset()); + theApp()->hideDialogs(name(), &inset()); } -- 2.39.2