]> git.lyx.org Git - features.git/commitdiff
This commit is purely mechanical and get rid of lyx_gui.[Ch].
authorAbdelrazak Younes <younes@lyx.org>
Thu, 12 Oct 2006 14:10:13 +0000 (14:10 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 12 Oct 2006 14:10:13 +0000 (14:10 +0000)
Only qt4 is guaranted to compile and work. I did not remove gtk and qt3 lyx_gui.C because they might be needed for reference to complete the header declarations in "GuiApplication.C".

 - lyx_gui::use_gui transfered to lyx::use_gui in lyx_main.C
 - all remaining lyx_gui functions transfered to Application and corresponding GuiApplication implementations.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15306 a592a061-630c-0410-9148-cb99ea01b6c8

41 files changed:
development/scons/scons_manifest.py
src/BranchList.C
src/frontends/Alert.C
src/frontends/Application.C
src/frontends/Application.h
src/frontends/Makefile.am
src/frontends/WorkArea.C
src/frontends/gtk/GuiApplication.C
src/frontends/gtk/GuiApplication.h
src/frontends/gtk/Makefile.am
src/frontends/gtk/xftFontLoader.C
src/frontends/lyx_gui.C [deleted file]
src/frontends/lyx_gui.h [deleted file]
src/frontends/qt3/GuiApplication.C
src/frontends/qt3/GuiApplication.h
src/frontends/qt3/GuiFontMetrics.C
src/frontends/qt3/Makefile.am
src/frontends/qt3/QLPopupMenu.C
src/frontends/qt3/QMathDialog.C
src/frontends/qt3/QPrefs.C
src/frontends/qt3/QViewSource.C
src/frontends/qt3/qfont_loader.C
src/frontends/qt4/GuiApplication.C
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiFontLoader.C
src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/Makefile.am
src/frontends/qt4/QLPopupMenu.C
src/frontends/qt4/QMathDialog.C
src/frontends/qt4/QPrefs.C
src/frontends/qt4/QPrefsDialog.C
src/frontends/qt4/lyx_gui.C [deleted file]
src/graphics/PreviewLoader.C
src/insets/insetexternal.C
src/insets/insetgraphicsParams.C
src/lyx_cb.C
src/lyx_main.C
src/lyx_main.h
src/lyxfunc.C
src/lyxserver.C
src/lyxsocket.C

index fc4ca8fb46154bfb7a641eb7486406f1d314734c..21066102039a6ac19837b18d58c097e32ebc81c6 100644 (file)
@@ -448,7 +448,6 @@ src_frontends_header_files = Split('''
     WorkArea.h
     guiapi.h
     key_state.h
-    lyx_gui.h
     mouse_state.h
     nullpainter.h
 ''')
@@ -464,7 +463,6 @@ src_frontends_files = Split('''
     Toolbars.C
     WorkArea.C
     guiapi.C
-    lyx_gui.C
     nullpainter.C
 ''')
 
@@ -956,7 +954,6 @@ src_frontends_qt3_files = Split('''
     iconpalette.C
     lcolorcache.C
     lengthcombo.C
-    lyx_gui.C
     panelstack.C
     qcoloritem.C
     qfont_loader.C
@@ -1337,7 +1334,6 @@ src_frontends_qt4_files = Split('''
     FloatPlacement.C
     iconpalette.C
     lengthcombo.C
-    lyx_gui.C
     panelstack.C
     qfontexample.C
     qsetborder.C
index 75f183a0aa50408d45a42738b7c6289c617605c3..6d5d163026d689649a2fa2d6ad7c36b7a25a1637 100644 (file)
@@ -12,7 +12,9 @@
 
 #include "BranchList.h"
 #include "LColor.h"
-#include "frontends/lyx_gui.h"
+
+#include "frontends/Application.h"
+
 #include <algorithm>
 
 using std::string;
@@ -20,7 +22,7 @@ using std::string;
 
 Branch::Branch()
 {
-       lyx_gui::getRGBColor(LColor::background, color_);
+       theApp->getRgbColor(LColor::background, color_);
 }
 
 
@@ -69,7 +71,7 @@ void Branch::setColor(string const & c)
                color_ = lyx::RGBColor(c);
        else
                // no color set or invalid color - use normal background
-               lyx_gui::getRGBColor(LColor::background, color_);
+               theApp->getRgbColor(LColor::background, color_);
 }
 
 
index 98c971c37a210d46451a59309a1ed9507511febd..1f482ddf8dc828b2e454c20cc3579ab15f9b97b0 100644 (file)
@@ -14,7 +14,6 @@
 #include "Alert_pimpl.h"
 
 #include "debug.h"
-#include "lyx_gui.h"
 
 using lyx::docstring;
 
@@ -25,13 +24,16 @@ using std::string;
 
 
 namespace lyx {
+
+extern bool use_gui;
+
 namespace frontend {
 
 int Alert::prompt(docstring const & title, docstring const & question,
                  int default_button, int escape_button,
                  docstring const & b1, docstring const & b2, docstring const & b3)
 {
-       if (!lyx_gui::use_gui || lyxerr.debugging()) {
+       if (!lyx::use_gui || lyxerr.debugging()) {
                lyxerr << lyx::to_utf8(title) << '\n'
                       << "----------------------------------------\n"
                       << lyx::to_utf8(question) << endl;
@@ -42,7 +44,7 @@ int Alert::prompt(docstring const & title, docstring const & question,
                case 1: lyxerr << lyx::to_utf8(b2) << endl;
                case 2: lyxerr << lyx::to_utf8(b3) << endl;
                }
-               if (!lyx_gui::use_gui)
+               if (!lyx::use_gui)
                        return default_button;
        }
 
@@ -54,35 +56,35 @@ int Alert::prompt(docstring const & title, docstring const & question,
 
 void Alert::warning(docstring const & title, docstring const & message)
 {
-       if (!lyx_gui::use_gui || lyxerr.debugging())
+       if (!lyx::use_gui || lyxerr.debugging())
                lyxerr << "Warning: " << lyx::to_utf8(title) << '\n'
                       << "----------------------------------------\n"
                       << lyx::to_utf8(message) << endl;
-       if (lyx_gui::use_gui)
+       if (lyx::use_gui)
                warning_pimpl(title, message);
 }
 
 
 void Alert::error(docstring const & title, docstring const & message)
 {
-       if (!lyx_gui::use_gui || lyxerr.debugging())
+       if (!lyx::use_gui || lyxerr.debugging())
                lyxerr << "Error: " << lyx::to_utf8(title) << '\n'
                       << "----------------------------------------\n"
                       << lyx::to_utf8(message) << endl;
 
-       if (lyx_gui::use_gui)
+       if (lyx::use_gui)
                error_pimpl(title, message);
 }
 
 
 void Alert::information(docstring const & title, docstring const & message)
 {
-       if (!lyx_gui::use_gui || lyxerr.debugging())
+       if (!lyx::use_gui || lyxerr.debugging())
                lyxerr << lyx::to_utf8(title) << '\n'
                       << "----------------------------------------\n"
                       << lyx::to_utf8(message) << endl;
 
-       if (lyx_gui::use_gui)
+       if (lyx::use_gui)
                information_pimpl(title, message);
 }
 
@@ -90,12 +92,12 @@ void Alert::information(docstring const & title, docstring const & message)
 pair<bool, docstring> const Alert::askForText(docstring const & msg,
                                           docstring const & dflt)
 {
-       if (!lyx_gui::use_gui || lyxerr.debugging()) {
+       if (!lyx::use_gui || lyxerr.debugging()) {
                lyxerr << "----------------------------------------\n"
                       << lyx::to_utf8(msg) << '\n'
                       << "Assuming answer is " << lyx::to_utf8(dflt) << '\n'
                       << "----------------------------------------" << endl;
-               if (!lyx_gui::use_gui)
+               if (!lyx::use_gui)
                        return make_pair<bool, docstring>(true, dflt);
        }
 
index 5b8d846b596e8cbd5cc077954099c74dfd32adb7..b9f257b193baac0ec73ca7da87b726c672c00770 100644 (file)
@@ -32,6 +32,8 @@
 #include "support/os.h"
 #include "support/package.h"
 
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 
 using lyx::support::package;
 
@@ -139,7 +141,6 @@ int Application::start(std::string const & batch)
        return exec();
 }
 
-
 } // namespace frontend
 
 
@@ -185,3 +186,4 @@ lyx::frontend::Selection & theSelection()
 {
        return theApp->selection();
 }
+
index b1eff4ecfa1e5eda62273ef30360d72443ef6a93..6f34a076778c4c76bedb7c94b5cf6ecdebce342c 100644 (file)
@@ -11,7 +11,7 @@
 #ifndef LYX_APPLICATION_H
 #define LYX_APPLICATION_H
 
-#include <boost/scoped_ptr.hpp>
+#include <boost/function.hpp>
 
 #include <string>
 
@@ -21,8 +21,12 @@ class LyXFunc;
 class LyXServer;
 class LyXServerSocket;
 class LyXView;
+class LColor_color;
        
 namespace lyx {
+
+struct RGBColor;
+
 namespace frontend {
 
 struct Application_pimpl;
@@ -62,6 +66,10 @@ public:
        */
        virtual void exit(int status) = 0;
 
+       /**
+       * Synchronise all pending events.
+       */
+       virtual void syncEvents() = 0;
        ///
        virtual Clipboard & clipboard() = 0;
        ///
@@ -78,6 +86,36 @@ public:
        /// return a suitable monospaced font name.
        virtual std::string const typewriterFontName() = 0;
 
+       /**
+       * Given col, fills r, g, b in the range 0-255.
+       * The function returns true if successful.
+       * It returns false on failure and sets r, g, b to 0.
+       */
+       virtual bool getRgbColor(LColor_color col, lyx::RGBColor & rgbcol) = 0;
+
+       /** Eg, passing LColor::black returns "000000",
+       *      passing LColor::white returns "ffffff".
+       */
+       virtual std::string const hexName(LColor_color col) = 0;
+
+       /**
+       * update an altered GUI color
+       */
+       virtual void updateColor(LColor_color col) = 0;
+
+       /**
+       * add a callback for socket read notification
+       * @param fd socket descriptor (file/socket/etc)
+       */
+       virtual void registerSocketCallback(
+               int fd, boost::function<void()> func) = 0;
+
+       /**
+       * remove a I/O read callback
+       * @param fd socket descriptor (file/socket/etc)
+       */
+       virtual void unregisterSocketCallback(int fd) = 0;
+
        ///
        LyXFunc & lyxFunc();
        LyXFunc const & lyxFunc() const;
@@ -108,6 +146,9 @@ private:
 }; // Application
 
 } // namespace frontend
+
+lyx::frontend::Application * createApplication(int & argc, char * argv[]);
+
 } // namespace lyx
 
 extern lyx::frontend::Application * theApp;
index f0387da1ef29bd578740d51fd08c8bffd72b9fd9..c07ad1c533a2cc0e1074fcc4199762f1aae21592 100644 (file)
@@ -42,8 +42,6 @@ libfrontends_la_SOURCES = \
        guiapi.h \
        guiapi.C \
        key_state.h \
-       lyx_gui.C \
-       lyx_gui.h \
        mouse_state.h \
        nullpainter.C \
        nullpainter.h
index 548cc276a5c58cb23d9b73d313bd227f468f8151..1ecab9fdc6bc1d91b2fcc50d21c9d6813b6f990f 100644 (file)
@@ -19,7 +19,6 @@
 #include "frontends/FontMetrics.h"
 
 #include "funcrequest.h"
-#include "lyx_gui.h"
 #include "lyxfunc.h"
 #include "Painter.h"
 
index 431fec949138551b1cc01183e83be43b244a5ff5..6888059cf0e5d113699dadef8c64fb7f43068987 100644 (file)
@@ -49,6 +49,8 @@ using std::endl;
 
 namespace {
 
+std::map<int, boost::shared_ptr<io_callback> > callbacks;
+
 /// estimate DPI from X server
 int getDPI()
 {
@@ -62,6 +64,12 @@ int getDPI()
 
 
 namespace lyx {
+
+lyx::frontend::Application * createApplication(int & argc, char * argv[])
+{
+       return new GuiApplication(argc, argv);
+}
+
 namespace frontend {
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
@@ -122,5 +130,72 @@ string const GuiApplication::typewriterFontName()
 }
 
 
+void GuiApplication::syncEvents()
+{
+       // FIXME
+}
+
+
+bool GuiApplication::getRgbColor(LColor_color col,
+                                                                lyx::RGBColor & rgbcol)
+{
+       Gdk::Color gdkColor;
+       Gdk::Color * gclr = colorCache.getColor(col);
+       if (!gclr) {
+               gclr = &gdkColor;
+               if(!gclr->parse(lcolor.getX11Name(col))) {
+                       rgbcol.r = 0;
+                       rgbcol.g = 0;
+                       rgbcol.b = 0;
+                       return false;
+               }
+       }
+
+       // Note that X stores the RGB values in the range 0 - 65535
+       // whilst we require them in the range 0 - 255.
+       rgbcol.r = gclr->get_red() / 256;
+       rgbcol.g = gclr->get_green() / 256;
+       rgbcol.b = gclr->get_blue() / 256;
+       return true;
+}
+
+
+string const GuiApplication::hexName(LColor_color col)
+{
+       lyx::RGBColor rgbcol;
+       if (!getRGBColor(col, rgbcol)) {
+               lyxerr << "X can't find color for \"" << lcolor.getLyXName(col)
+                      << '"' << std::endl;
+               return string();
+       }
+
+       std::ostringstream os;
+
+       os << std::setbase(16) << std::setfill('0')
+          << std::setw(2) << rgbcol.r
+          << std::setw(2) << rgbcol.g
+          << std::setw(2) << rgbcol.b;
+
+       return os.str();
+}
+
+
+void GuiApplication::updateColor(LColor_color)
+{
+       colorCache.clear();
+}
+
+
+void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
+{
+       callbacks[fd] = boost::shared_ptr<io_callback>(new io_callback(fd, func));
+}
+
+
+void GuiApplication::unregisterSocketCallback(int fd)
+{
+       callbacks.erase(fd);
+}
+
 } // namespace frontend
 } // namespace lyx
index 0ffaa0b4b4a620103901c82eb472adc568a89f3b..d803f77bd4a42114cd48b5b7189a6c0efcce875e 100644 (file)
@@ -57,6 +57,12 @@ public:
        virtual std::string const romanFontName();
        virtual std::string const sansFontName();
        virtual std::string const typewriterFontName();
+       virtual bool getRgbColor(LColor_color col, lyx::RGBColor & rgbcol);
+       virtual std::string const hexName(LColor_color col);
+       virtual void updateColor(LColor_color col);
+       virtual void registerSocketCallback(
+               int fd, boost::function<void()> func);
+       virtual void unregisterSocketCallback(int fd);
        //@}
 
        ///
index 718f4bc1ecfa1eb3930e346637ea1d24a6830ae7..13ea2570a67f8061031ede67b5fa952b9db5c61b 100644 (file)
@@ -144,7 +144,6 @@ libgtk_la_SOURCES = \
        GuiImplementation.C \
        io_callback.C \
        io_callback.h \
-       lyx_gui.C \
        xftFontLoader.C \
        xftFontLoader.h \
        xftFontMetrics.C
index 41214bec35044bb2ec56a7d1d0dd956f9adce3f2..ec86a0c8a08aaa9078961ceed455cbe29118e838 100644 (file)
@@ -26,7 +26,6 @@
 #include "GtkmmX.h"
 
 #include "frontends/LyXView.h"
-#include "frontends/lyx_gui.h"
 
 #include "support/convert.h"
 #include "support/lstrings.h"
 using std::endl;
 using std::string;
 
+namespace lyx {
+extern bool use_gui;
+}
+
 // The global fontLoader
 xftFontLoader fontLoader;
 
@@ -189,7 +192,7 @@ XftFont * xftFontLoader::doLoad(LyXFont::FONT_FAMILY family,
 
 bool xftFontLoader::available(LyXFont const & f)
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return false;
 
        static std::vector<bool> cache_set(LyXFont::NUM_FAMILIES, false);
diff --git a/src/frontends/lyx_gui.C b/src/frontends/lyx_gui.C
deleted file mode 100644 (file)
index 951e2a2..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * \file frontends/lyx_gui.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.
- */
-
-#include <config.h>
-
-#include "lyx_gui.h"
-
-#include "Application.h"
-
-using std::string;
-
-lyx::frontend::Application * theApp;
-
-
-namespace lyx_gui {
-
-bool use_gui = true;
-
-}; // namespace lyx_gui
diff --git a/src/frontends/lyx_gui.h b/src/frontends/lyx_gui.h
deleted file mode 100644 (file)
index 22ed0f1..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// -*- C++ -*-
-/**
- * \file lyx_gui.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef LYX_GUI_H
-#define LYX_GUI_H
-
-
-#include "FuncStatus.h"
-
-#include <boost/function.hpp>
-
-#include <string>
-#include <vector>
-
-class Dialogs;
-class LColor_color;
-class LyXFont;
-class LyXComm;
-class FuncRequest;
-class LyXView;
-namespace lyx {
-struct RGBColor;
-}
-
-/// GUI interaction
-namespace lyx_gui {
-
-/// are we using the GUI at all
-extern bool use_gui;
-
-/**
- * Enter the main event loop (\sa LyX::exec2)
- */
-int exec(int & argc, char * argv[]);
-
-/**
- * Synchronise all pending events.
- */
-void sync_events();
-
-/**
- * Given col, fills r, g, b in the range 0-255.
- * The function returns true if successful.
- * It returns false on failure and sets r, g, b to 0.
- */
-bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol);
-
-/** Eg, passing LColor::black returns "000000",
- *      passing LColor::white returns "ffffff".
- */
-std::string const hexname(LColor_color col);
-
-/**
- * update an altered GUI color
- */
-void update_color(LColor_color col);
-
-/**
- * add a callback for socket read notification
- * @param fd socket descriptor (file/socket/etc)
- */
-void register_socket_callback(int fd, boost::function<void()> func);
-
-/**
- * remove a I/O read callback
- * @param fd socket descriptor (file/socket/etc)
- */
-void unregister_socket_callback(int fd);
-
-} // namespace lyx_gui
-
-#endif // LYX_GUI_H
index 0b4e13fc470212176b7a438a4c25b499a598d859..d167f9fdb83577e9639bba0bb5f9308ace1c8a4f 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "qt_helpers.h"
 #include "QLImage.h"
+#include "socket_callback.h"
 
 #include "graphics/LoaderQueue.h"
 
@@ -60,6 +61,8 @@ extern void initEncodings();
 
 namespace {
 
+map<int, shared_ptr<socket_callback> > socket_callbacks;
+
 int getDPI()
 {
        QWidget w;
@@ -71,6 +74,14 @@ int getDPI()
 
 
 namespace lyx {
+
+lyx::frontend::Application * createApplication(int & argc, char * argv[])
+{
+       GuiApplication app(argc, argv);
+
+       return &app;
+}
+
 namespace frontend {
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
@@ -191,6 +202,60 @@ string const GuiApplication::typewriterFontName()
 }
 
 
+void GuiApplication::syncEvents()
+{
+       // This is the ONLY place where processEvents may be called.
+       // During screen update/ redraw, this method is disabled to
+       // prevent keyboard events being handed to the LyX core, where
+       // they could cause re-entrant calls to screen update.
+#if QT_VERSION >= 0x030100
+       qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
+#endif
+}
+
+
+bool GuiApplication::getRgbColor(LColor_color col,
+                                                                lyx::RGBColor & rgbcol)
+{
+       QColor const & qcol = lcolorcache.get(col);
+       if (!qcol.isValid()) {
+               rgbcol.r = 0;
+               rgbcol.g = 0;
+               rgbcol.b = 0;
+               return false;
+       }
+       rgbcol.r = qcol.red();
+       rgbcol.g = qcol.green();
+       rgbcol.b = qcol.blue();
+       return true;
+}
+
+
+string const GuiApplication::hexName(LColor_color col)
+{
+       return ltrim(fromqstr(lcolorcache.get(col).name()), "#");
+}
+
+
+void GuiApplication::updateColor(LColor_color)
+{
+       // FIXME: Bleh, can't we just clear them all at once ?
+       lcolorcache.clear();
+}
+
+
+void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
+{
+       socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
+}
+
+
+void GuiApplication::unregisterSocketCallback(int fd)
+{
+       socket_callbacks.erase(fd);
+}
+
+
 ////////////////////////////////////////////////////////////////////////
 // X11 specific stuff goes here...
 #ifdef Q_WS_X11
index 82eca1c87011cf3ed0d176a40490b74ad76eac9d..9684b958532f6c7623afa767ba9d57996a414d9e 100644 (file)
@@ -63,6 +63,12 @@ public:
        virtual std::string const romanFontName();
        virtual std::string const sansFontName();
        virtual std::string const typewriterFontName();
+       virtual bool getRgbColor(LColor_color col, lyx::RGBColor & rgbcol);
+       virtual std::string const hexName(LColor_color col);
+       virtual void updateColor(LColor_color col);
+       virtual void registerSocketCallback(
+               int fd, boost::function<void()> func);
+       virtual void unregisterSocketCallback(int fd);
        //@}
 
        ///
index 3e4fdd95e77969c1729593ee957eeced08affd18..166ff65e5bd6f0aecd2a99a7112f9b738820b5f1 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "language.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "support/unicode.h"
 
 using lyx::char_type;
@@ -28,6 +26,9 @@ using std::string;
 
 
 namespace lyx {
+
+extern bool use_gui;
+
 namespace frontend {
 
 
@@ -45,7 +46,7 @@ GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
 
 int GuiFontMetrics::maxAscent() const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        return metrics_.ascent();
 }
@@ -53,7 +54,7 @@ int GuiFontMetrics::maxAscent() const
 
 int GuiFontMetrics::maxDescent() const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        // We add 1 as the value returned by QT is different than X
        // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
@@ -63,7 +64,7 @@ int GuiFontMetrics::maxDescent() const
 
 int GuiFontMetrics::ascent(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
@@ -79,7 +80,7 @@ int GuiFontMetrics::ascent(char_type c) const
 
 int GuiFontMetrics::descent(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
@@ -95,7 +96,7 @@ int GuiFontMetrics::descent(char_type c) const
 
 int GuiFontMetrics::lbearing(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        return metrics_.leftBearing(ucs4_to_qchar(c));
 }
@@ -103,7 +104,7 @@ int GuiFontMetrics::lbearing(char_type c) const
 
 int GuiFontMetrics::rbearing(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
 
        // Qt rbearing is from the right edge of the char's width().
@@ -114,7 +115,7 @@ int GuiFontMetrics::rbearing(char_type c) const
 
 int GuiFontMetrics::smallcapsWidth(QString const & s) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
 
        int w = 0;
@@ -134,7 +135,7 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
 
 int GuiFontMetrics::width(char_type const * s, size_t ls) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return ls;
 
        QString const ucs2 = toqstr(s, ls);
index 65bbd2cf59817742432f6cf9cf8878cb36f3ae67..ad541e77253d1ab8a7189858a443b7b1208949de 100644 (file)
@@ -86,7 +86,6 @@ libqt3_la_SOURCES = \
        Qt2BC.C Qt2BC.h \
        QtLyXView.h \
        checkedwidgets.C checkedwidgets.h \
-       lyx_gui.C \
        lcolorcache.h lcolorcache.C \
        panelstack.h panelstack.C \
        qcoloritem.h qcoloritem.C \
index 636b1384408e579ada560cc03e3e227d94731184..927bb01621dc6ea6bc48d5d6c661234d7332a13c 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "MenuBackend.h"
 
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
 
 #include "support/lstrings.h"
 
@@ -94,7 +94,7 @@ void QLPopupMenu::fire(int index)
 {
        // make sure the interface is repainted correctly (in case the
        // action needs a long time, like File>Open).
-       lyx_gui::sync_events();
+       theApp->syncEvents();
 #ifdef Q_WS_MACX
        if (index >= indexOffset) {
                MenuItem mi = owner_->backend().getMenu("LyX")[index - indexOffset];
index 06ea72ee305bf68b56107da446a5c4d0b1d39a7f..71e65ef3cd91224ad923e07217e049855d82379d 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "controllers/ControlMath.h"
 
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
 
 #include <qwidgetstack.h>
 #include <qcombobox.h>
@@ -55,7 +55,7 @@ protected:
 
                w_->resize(viewport()->width(), w_->height());
                // force the resize to get accurate scrollbar
-               lyx_gui::sync_events();
+               theApp->syncEvents();
                resizeContents(w_->width(), w_->height());
        }
 private:
index c0a874bfda2f1e7b2223c6dae1c4c88b2844fffd..d7926425d22bf56c04464a19e5513b472d5a3cdd 100644 (file)
@@ -47,7 +47,6 @@
 #include "controllers/helper_funcs.h"
 
 #include "frontends/Application.h"
-#include "frontends/lyx_gui.h"
 
 #include <qcheckbox.h>
 #include "qcoloritem.h"
index 174fdd9503b4c9c9d223f234c9ab1dc9d1717452..acb0fff39c0e83f28eb51d748a960589bed7a56c 100644 (file)
@@ -14,7 +14,6 @@
 #include "QViewSource.h"
 #include "QViewSourceDialog.h"
 #include "qt_helpers.h"
-#include "lyx_gui.h"
 
 #include "frontends/Application.h"
 
index 8304584e3ae27baa9321ce2d544d535df0ffa711..8ed07531eb8156391d9ec3626e02e2ec62d78e5c 100644 (file)
@@ -17,8 +17,6 @@
 #include "debug.h"
 #include "lyxrc.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -46,6 +44,10 @@ using std::pair;
 using std::vector;
 using std::string;
 
+namespace lyx {
+extern bool use_gui;
+}
+
 
 GuiFontLoader::~GuiFontLoader() {
 }
@@ -290,7 +292,7 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
 
 bool GuiFontLoader::available(LyXFont const & f)
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return false;
 
        static vector<int> cache_set(LyXFont::NUM_FAMILIES, false);
index 147238249f889ce5e5e6eb04884588bd38847f43..d7293c3004688d56b77f2025d3f2f7e817ef8c05 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "qt_helpers.h"
 #include "QLImage.h"
+#include "socket_callback.h"
 
 #include "graphics/LoaderQueue.h"
 
 #include "support/package.h"
 
 #include "BufferView.h"
+#include "Color.h"
+#include "debug.h"
 #include "lyx_main.h"
 #include "lyxrc.h"
-#include "debug.h"
 
 #include <QApplication>
 #include <QClipboard>
@@ -67,7 +69,25 @@ int getDPI()
 } // namespace anon
 
 
+lyx::frontend::GuiApplication * guiApp;
+
 namespace lyx {
+
+lyx::frontend::Application * createApplication(int & argc, char * argv[])
+{
+       // FIXME: it would be great if we could just do:
+       //return new lyx::frontend::GuiApplication(argc, argv);
+
+#if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
+       static lyx::frontend::GuiApplication app(argc, argv);
+#else
+       lyx::frontend::GuiApplication app(argc, argv);
+#endif
+
+       return &app;
+}
+
+
 namespace frontend {
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
@@ -132,6 +152,8 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        lyxrc.dpi = getDPI();
 
        LoaderQueue::setPriority(10,100);
+
+       guiApp = this;
 }
 
 
@@ -189,6 +211,58 @@ string const GuiApplication::typewriterFontName()
 }
 
 
+void GuiApplication::syncEvents()
+{
+       // This is the ONLY place where processEvents may be called.
+       // During screen update/ redraw, this method is disabled to
+       // prevent keyboard events being handed to the LyX core, where
+       // they could cause re-entrant calls to screen update.
+       processEvents(QEventLoop::ExcludeUserInputEvents);
+}
+
+
+bool GuiApplication::getRgbColor(LColor_color col,
+                                                                lyx::RGBColor & rgbcol)
+{
+       QColor const & qcol = color_cache_.get(col);
+       if (!qcol.isValid()) {
+               rgbcol.r = 0;
+               rgbcol.g = 0;
+               rgbcol.b = 0;
+               return false;
+       }
+       rgbcol.r = qcol.red();
+       rgbcol.g = qcol.green();
+       rgbcol.b = qcol.blue();
+       return true;
+}
+
+
+string const GuiApplication::hexName(LColor_color col)
+{
+       return lyx::support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
+}
+
+
+void GuiApplication::updateColor(LColor_color)
+{
+       // FIXME: Bleh, can't we just clear them all at once ?
+       color_cache_.clear();
+}
+
+
+void GuiApplication::registerSocketCallback(int fd, boost::function<void()> func)
+{
+       socket_callbacks_[fd] =
+               boost::shared_ptr<socket_callback>(new socket_callback(fd, func));
+}
+
+
+void GuiApplication::unregisterSocketCallback(int fd)
+{
+       socket_callbacks_.erase(fd);
+}
+
 ////////////////////////////////////////////////////////////////////////
 // X11 specific stuff goes here...
 #ifdef Q_WS_X11
index 6f3acf8dda78cf05c352499ddabd8b8bd1b1cb33..2212ec44fe105cc3a4b219462f400391538cfd96 100644 (file)
@@ -32,6 +32,7 @@
 ///////////////////////////////////////////////////////////////
 
 class BufferView;
+class socket_callback;
 
 namespace lyx {
 namespace frontend {
@@ -61,9 +62,16 @@ public:
        virtual int const exec();
        virtual Gui & gui() { return gui_; }
        virtual void exit(int status);
+       void syncEvents();
        virtual std::string const romanFontName();
        virtual std::string const sansFontName();
        virtual std::string const typewriterFontName();
+       virtual bool getRgbColor(LColor_color col, lyx::RGBColor & rgbcol);
+       virtual std::string const hexName(LColor_color col);
+       virtual void updateColor(LColor_color col);
+       virtual void registerSocketCallback(
+               int fd, boost::function<void()> func);
+       virtual void unregisterSocketCallback(int fd);
        //@}
 
        ///
@@ -83,6 +91,8 @@ private:
        GuiFontLoader font_loader_;
        ///
        ColorCache color_cache_;
+       ///
+       std::map<int, boost::shared_ptr<socket_callback> > socket_callbacks_;
 
 #ifdef Q_WS_X11
 public:
index f98c4a7324e33ee8e8df95c6f5681534705ac7f7..7b464125399e8f60b7aa0b3244245b4fa240728b 100644 (file)
@@ -17,8 +17,6 @@
 #include "debug.h"
 #include "lyxrc.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -45,6 +43,9 @@ using std::string;
 
 
 namespace lyx {
+
+extern bool use_gui;
+
 namespace frontend {
 
 GuiFontLoader::~GuiFontLoader() {
@@ -303,7 +304,7 @@ QLFontInfo::QLFontInfo(LyXFont const & f)
 
 bool GuiFontLoader::available(LyXFont const & f)
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return false;
 
        static vector<int> cache_set(LyXFont::NUM_FAMILIES, false);
index 8885b5cb0980561f6d41fd6167b4d84728f66f18..a898e6ae3cd36908c7d9596c5426647b05b394aa 100644 (file)
@@ -17,8 +17,6 @@
 
 #include "language.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "support/unicode.h"
 
 using lyx::char_type;
@@ -26,8 +24,10 @@ using lyx::docstring;
 
 using std::string;
 
-
 namespace lyx {
+
+extern bool use_gui;
+
 namespace frontend {
 
 
@@ -45,7 +45,7 @@ GuiFontMetrics::GuiFontMetrics(QFont const & font, QFont const & smallcaps_font)
 
 int GuiFontMetrics::maxAscent() const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        return metrics_.ascent();
 }
@@ -53,7 +53,7 @@ int GuiFontMetrics::maxAscent() const
 
 int GuiFontMetrics::maxDescent() const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        // We add 1 as the value returned by QT is different than X
        // See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
@@ -63,7 +63,7 @@ int GuiFontMetrics::maxDescent() const
 
 int GuiFontMetrics::ascent(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
@@ -79,7 +79,7 @@ int GuiFontMetrics::ascent(char_type c) const
 
 int GuiFontMetrics::descent(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        QRect const & r = metrics_.boundingRect(ucs4_to_qchar(c));
        // Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
@@ -95,7 +95,7 @@ int GuiFontMetrics::descent(char_type c) const
 
 int GuiFontMetrics::lbearing(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
        return metrics_.leftBearing(ucs4_to_qchar(c));
 }
@@ -103,7 +103,7 @@ int GuiFontMetrics::lbearing(char_type c) const
 
 int GuiFontMetrics::rbearing(char_type c) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
 
        // Qt rbearing is from the right edge of the char's width().
@@ -114,7 +114,7 @@ int GuiFontMetrics::rbearing(char_type c) const
 
 int GuiFontMetrics::smallcapsWidth(QString const & s) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return 1;
 
        int w = 0;
@@ -134,7 +134,7 @@ int GuiFontMetrics::smallcapsWidth(QString const & s) const
 
 int GuiFontMetrics::width(char_type const * s, size_t ls) const
 {
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                return ls;
 
        QString ucs2;
index 650ff7b343173bfc7658235e33b808fe5fda1e96..dfd819538ac81b0c90ba971086a36b699ceed2a7 100644 (file)
@@ -84,7 +84,6 @@ libqt4_la_SOURCES = \
        QWrap.C QWrap.h \
        Qt2BC.C Qt2BC.h \
        checkedwidgets.C checkedwidgets.h \
-       lyx_gui.C \
        panelstack.h panelstack.C \
        qfontexample.h qfontexample.C \
        qlkey.h \
index c7becf343cf2c8cb0434c15f93c75e390c308662..763664ff29f1376955ecf18a493b54e5efb7df96 100644 (file)
@@ -23,7 +23,6 @@
 #include "qt_helpers.h"
 #include "MenuBackend.h"
 
-#include "frontends/lyx_gui.h"
 #include "support/lstrings.h"
 #include "debug.h"
 
index 1de28ad8d7a11b598bcc5f3a34e3811e8251d352..bad3fffb9533bd445412e458abf0c896c3444a39 100644 (file)
@@ -25,7 +25,7 @@
 #include "iconpalette.h"
 #include "qt_helpers.h"
 #include "controllers/ControlMath.h"
-#include "frontends/lyx_gui.h"
+
 #include "support/filetools.h"
 
 using std::string;
index 62251df88a4c535385b14002a9d4c8845cd4a7b6..3bd30f2799a1dcddea7ddf4b0f34c1de4b8b3e31 100644 (file)
@@ -27,8 +27,6 @@
 #include "controllers/frnt_lang.h"
 #include "controllers/helper_funcs.h"
 
-#include "frontends/lyx_gui.h"
-
 using namespace Ui;
 
 namespace lyx {
index f92dc97a4bb432e444af13a2e7bc9093bd76d5db..de52935db67b2084b4e6403fd1b9b002aa38157c 100644 (file)
@@ -29,7 +29,7 @@
 #include "controllers/helper_funcs.h"
 
 #include "frontends/Alert.h"
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
 
 #include "QPrefsDialog.h"
 #include "QPrefs.h"
diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C
deleted file mode 100644 (file)
index ea848a2..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * \file qt4/lyx_gui.C
- * 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.
- */
-
-#include <config.h>
-
-#include "lyx_gui.h"
-
-// FIXME: move this stuff out again
-#include "Color.h"
-#include "funcrequest.h"
-#include "LColor.h"
-#include "lyx_main.h"
-#include "LyXAction.h"
-#include "lyxfunc.h"
-#include "lyxrc.h"
-
-
-#include "support/lstrings.h"
-
-#include "GuiView.h"
-#include "QLImage.h"
-#include "qt_helpers.h"
-#include "socket_callback.h"
-#include "GuiApplication.h"
-
-#include <QApplication>
-#include <QEventLoop>
-#include <QTranslator>
-#include <QTextCodec>
-#include <QLocale>
-#include <QLibraryInfo>
-
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-
-
-using lyx::support::ltrim;
-
-using lyx::frontend::GuiImplementation;
-using lyx::frontend::GuiView;
-using lyx::frontend::GuiApplication;
-
-using boost::shared_ptr;
-
-using std::map;
-using std::vector;
-using std::string;
-
-lyx::frontend::GuiApplication * guiApp;
-
-namespace {
-
-map<int, shared_ptr<socket_callback> > socket_callbacks;
-
-} // namespace anon
-
-namespace lyx_gui {
-
-int exec(int & argc, char * argv[])
-{
-       /*
-       FIXME : Abdel 29/05/2006 (younes.a@free.fr)
-       reorganize this code. In particular make sure that this
-       advice from Qt documentation is respected:
-
-               Since the QApplication object does so much initialization, it
-               must be created before any other objects related to the user
-               interface are created.
-
-       Right now this is not the case, I suspect that a number of global variables
-       contains Qt object that are initialized before the passage through
-       parse_init(). This might also explain the message displayed by Qt
-       that caused the hanging:
-
-       QObject::killTimer: timers cannot be stopped from another thread
-
-       I hope that the problem will disappear automagically when we get rid of
-       lyx_gui entirely, thus using theApp directly throughout the code for LyXFunc,
-       Clipboard and Selection access.
-       */
-
-#if defined(Q_WS_WIN) && !defined(Q_CYGWIN_WIN)
-       static GuiApplication app(argc, argv);
-#else
-       GuiApplication app(argc, argv);
-#endif
-
-       guiApp = &app;
-       theApp = guiApp;
-
-       return LyX::ref().exec2(argc, argv);
-}
-
-
-void sync_events()
-{
-       // This is the ONLY place where processEvents may be called.
-       // During screen update/ redraw, this method is disabled to
-       // prevent keyboard events being handed to the LyX core, where
-       // they could cause re-entrant calls to screen update.
-       guiApp->processEvents(QEventLoop::ExcludeUserInputEvents);
-}
-
-
-bool getRGBColor(LColor_color col, lyx::RGBColor & rgbcol)
-{
-       QColor const & qcol = guiApp->colorCache().get(col);
-       if (!qcol.isValid()) {
-               rgbcol.r = 0;
-               rgbcol.g = 0;
-               rgbcol.b = 0;
-               return false;
-       }
-       rgbcol.r = qcol.red();
-       rgbcol.g = qcol.green();
-       rgbcol.b = qcol.blue();
-       return true;
-}
-
-
-string const hexname(LColor_color col)
-{
-       return ltrim(fromqstr(guiApp->colorCache().get(col).name()), "#");
-}
-
-
-void update_color(LColor_color)
-{
-       // FIXME: Bleh, can't we just clear them all at once ?
-       guiApp->colorCache().clear();
-}
-
-
-void register_socket_callback(int fd, boost::function<void()> func)
-{
-       socket_callbacks[fd] = shared_ptr<socket_callback>(new socket_callback(fd, func));
-}
-
-
-void unregister_socket_callback(int fd)
-{
-       socket_callbacks.erase(fd);
-}
-
-}; // namespace lyx_gui
index 0ed2ef8c0b5693b3af927f3685d0b78d0b9c3255..57d100d72233a08204caef0cff09fdb7af7edb1d 100644 (file)
@@ -24,7 +24,7 @@
 #include "outputparams.h"
 #include "paragraph.h"
 
-#include "frontends/lyx_gui.h" // hexname
+#include "frontends/Application.h" // hexName
 
 #include "insets/inset.h"
 
@@ -500,8 +500,8 @@ void PreviewLoader::Impl::startLoading()
        cs << pconverter_->command << ' ' << pconverter_->to << ' '
           << support::quoteName(latexfile) << ' '
           << int(font_scaling_factor_) << ' '
-          << lyx_gui::hexname(LColor::preview) << ' '
-          << lyx_gui::hexname(LColor::background);
+          << theApp->hexName(LColor::preview) << ' '
+          << theApp->hexName(LColor::background);
 
        string const command = support::libScriptSearch(cs.str());
 
index 59f4c6322d21403254d92f0b31542343ae0eb295..ce2e6fff8faa8632d5ff1fa9cbb74ddc4a0279b5 100644 (file)
@@ -22,6 +22,7 @@
 #include "debug.h"
 #include "dispatchresult.h"
 #include "exporter.h"
+#include "FuncStatus.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
@@ -31,8 +32,6 @@
 #include "metricsinfo.h"
 #include "outputparams.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "graphics/PreviewLoader.h"
 
 #include "support/filetools.h"
@@ -58,6 +57,9 @@ using std::ostream;
 using std::ostringstream;
 using std::vector;
 
+namespace lyx {
+extern bool use_gui;
+}
 
 namespace {
 
@@ -563,7 +565,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
        if (gparams.display == graphics::DefaultDisplay)
                gparams.display = lyxrc.display_graphics;
        // Override the above if we're not using a gui
-       if (!lyx_gui::use_gui)
+       if (!lyx::use_gui)
                gparams.display = graphics::NoDisplay;
 
        return gparams;
index c0e140316c02189689f0036aac80bc42a9793483..875b332223e37ec35126b36b2029058bd7bfc16e 100644 (file)
@@ -17,8 +17,6 @@
 #include "lyxlex.h"
 #include "lyxrc.h"
 
-#include "frontends/lyx_gui.h"
-
 #include "graphics/GraphicsParams.h"
 
 #include "support/convert.h"
@@ -35,6 +33,10 @@ using std::string;
 using std::ostream;
 
 
+namespace lyx {
+extern bool use_gui;
+}
+
 InsetGraphicsParams::InsetGraphicsParams()
 {
        init();
@@ -322,7 +324,7 @@ lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
        }
 
        // Override the above if we're not using a gui
-       if (!lyx_gui::use_gui) {
+       if (!lyx::use_gui) {
                pars.display = lyx::graphics::NoDisplay;
        }
 
index 0735a98f9803445709a99213e7183de6c1dd99e8..f1226535ddb754976aecd9374221f441a8520e00 100644 (file)
@@ -34,7 +34,6 @@
 #include "frontends/Alert.h"
 #include "frontends/Application.h"
 #include "frontends/FileDialog.h"
-#include "frontends/lyx_gui.h"
 
 #include "support/filefilterlist.h"
 #include "support/filetools.h"
@@ -94,6 +93,9 @@ using std::istream_iterator;
 // this should be static, but I need it in buffer.C
 bool quitting; // flag, that we are quitting the program
 
+namespace lyx {
+extern bool use_gui;
+}
 
 //
 // Menu callbacks
@@ -192,7 +194,7 @@ void quitLyX(bool noask)
 {
        lyxerr[Debug::INFO] << "Running QuitLyX." << endl;
 
-       if (lyx_gui::use_gui) {
+       if (lyx::use_gui) {
                if (!noask && !theBufferList().quitWriteAll())
                        return;
 
@@ -216,11 +218,12 @@ void quitLyX(bool noask)
                Alert::warning(_("Unable to remove temporary directory"), msg);
        }
 
-       if (lyx_gui::use_gui)
+       if (lyx::use_gui) {
                theApp->exit(0);
 
-       // Restore original font resources after Application is destroyed.
-       lyx::support::restoreFontResources();
+               // Restore original font resources after Application is destroyed.
+               lyx::support::restoreFontResources();
+       }
 }
 
 
index 6a05a113a51503c4f054dd6bea4633ae4857813c..2d1a08489e2c0f7375571d9c923e05db78e1ec1b 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "frontends/Alert.h"
 #include "frontends/Application.h"
-#include "frontends/lyx_gui.h"
 #include "frontends/LyXView.h"
 
 #include "support/environment.h"
@@ -93,9 +92,22 @@ using std::system;
 #endif
 
 
-// convenient to have it here.
+/// convenient to have it here.
 boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+///
+lyx::frontend::Application * theApp;
+
+namespace lyx {
+
+/// are we using the GUI at all?
+/** 
+* We default to true and this is changed to false when the export feature is used.
+*/
+bool use_gui = true;
+
+}
+
 namespace {
 
 // Filled with the command line arguments "foo" of "-sysdir foo" or
@@ -109,7 +121,7 @@ void lyx_exit(int status)
        // FIXME: We should not directly call exit(), since it only
        // guarantees a return to the system, no application cleanup.
        // This may cause troubles with not executed destructors.
-       if (lyx_gui::use_gui) {
+       if (lyx::use_gui) {
                theApp->exit(status);
                // Restore original font resources after Application is destroyed.
                lyx::support::restoreFontResources();
@@ -235,19 +247,23 @@ int LyX::priv_exec(int & argc, char * argv[])
 {
        // Here we need to parse the command line. At least
        // we need to parse for "-dbg" and "-help"
-       lyx_gui::use_gui = easyParse(argc, argv);
+       easyParse(argc, argv);
 
        lyx::support::init_package(argv[0], cl_system_support, cl_user_support,
                                   lyx::support::top_build_dir_is_one_level_up);
 
        // Start the real execution loop.
-       if (lyx_gui::use_gui) {
+       if (lyx::use_gui) {
                // Force adding of font path _before_ Application is initialized
                lyx::support::addFontResources();
-               return lyx_gui::exec(argc, argv);
+               theApp = lyx::createApplication(argc, argv);
        }
-       else
-               return exec2(argc, argv);
+       else {
+               // FIXME: create a ConsoleApplication
+               theApp = 0;
+       }
+       
+       return exec2(argc, argv);
 }
 
 
@@ -323,7 +339,7 @@ int LyX::exec2(int & argc, char * argv[])
                files.clear(); // the files are already loaded
        }
 
-       if (lyx_gui::use_gui) {
+       if (lyx::use_gui) {
                // determine windows size and position, from lyxrc and/or session
                // initial geometry
                unsigned int width = 690;
@@ -518,15 +534,15 @@ bool LyX::init()
 
        if (lyxrc.roman_font_name.empty())
                lyxrc.roman_font_name = 
-                       lyx_gui::use_gui? theApp->romanFontName(): "serif";
+                       lyx::use_gui? theApp->romanFontName(): "serif";
 
        if (lyxrc.sans_font_name.empty())
                lyxrc.sans_font_name =
-                       lyx_gui::use_gui? theApp->sansFontName(): "sans";
+                       lyx::use_gui? theApp->sansFontName(): "sans";
 
        if (lyxrc.typewriter_font_name.empty())
                lyxrc.typewriter_font_name =
-                       lyx_gui::use_gui? theApp->typewriterFontName(): "monospace";
+                       lyx::use_gui? theApp->typewriterFontName(): "monospace";
 
        //
        // Read configuration files
@@ -551,7 +567,7 @@ bool LyX::init()
                reconfigureUserLyXDir();
 
        // no need for a splash when there is no GUI
-       if (!lyx_gui::use_gui) {
+       if (!lyx::use_gui) {
                first_start = false;
        }
 
@@ -582,7 +598,7 @@ bool LyX::init()
        if (!LyXSetStyle())
                return false;
 
-       if (lyx_gui::use_gui) {
+       if (lyx::use_gui) {
                // Set up bindings
                toplevel_keymap.reset(new kb_keymap);
                defaultKeyBindings(toplevel_keymap.get());
@@ -920,7 +936,6 @@ bool LyX::readEncodingsFile(string const & name)
 
 namespace {
 
-bool is_gui = true;
 string batch;
 
 /// return the the number of arguments consumed
@@ -1015,7 +1030,7 @@ int parse_export(string const & type, string const &)
                exit(1);
        }
        batch = "buffer-export " + type;
-       is_gui = false;
+       lyx::use_gui = true;
        return 1;
 }
 
@@ -1038,7 +1053,7 @@ int parse_import(string const & type, string const & file)
 } // namespace anon
 
 
-bool LyX::easyParse(int & argc, char * argv[])
+void LyX::easyParse(int & argc, char * argv[])
 {
        std::map<string, cmd_helper> cmdmap;
 
@@ -1082,6 +1097,4 @@ bool LyX::easyParse(int & argc, char * argv[])
        }
 
        batch_command = batch;
-
-       return is_gui;
 }
index c791c605f8aa4ba913698fe1fb6c58d58deaccb9..c40232f4546ded994f22e8dcc119618fba103293 100644 (file)
@@ -39,9 +39,9 @@ public:
         * Execute LyX. The startup sequence is as follows:
         * -# LyX::exec()
         * -# LyX::priv_exec()
-        * -# lyx_gui::exec()
+        * -# lyx::createApplication()
         * -# LyX::exec2()
-        * Step 3 is omitted if no gui is wanted. We need lyx_gui::exec()
+        * Step 3 is omitted if no gui is wanted. We need lyx::createApplication()
         * only to create the QApplication object in the qt frontend. All
         * attempts with static and dynamically allocated QApplication
         * objects lead either to harmless error messages on exit
@@ -97,8 +97,8 @@ private:
        bool readLanguagesFile(std::string const & name);
        /// read the given encodings file
        bool readEncodingsFile(std::string const & name);
-       /// parsing of non-gui LyX options. Returns true if gui
-       bool easyParse(int & argc, char * argv[]);
+       /// parsing of non-gui LyX options.
+       void easyParse(int & argc, char * argv[]);
        /// shows up a parsing error on screen
        void printError(ErrorItem const &);
 
index b74f997c87b21e6f818fe0523249d8ee34c12106..798cb199b612049f6132e7e9167cf98235e08c09 100644 (file)
@@ -36,6 +36,7 @@
 #include "exporter.h"
 #include "format.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "importer.h"
 #include "insetiterator.h"
@@ -77,7 +78,6 @@
 #include "frontends/Dialogs.h"
 #include "frontends/FileDialog.h"
 #include "frontends/FontLoader.h"
-#include "frontends/lyx_gui.h"
 #include "frontends/LyXKeySym.h"
 #include "frontends/LyXView.h"
 #include "frontends/Menubar.h"
@@ -146,6 +146,9 @@ extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 // (alkis)
 extern tex_accent_struct get_accent(kb_action action);
 
+namespace lyx {
+extern bool use_gui;
+}
 
 namespace {
 
@@ -1000,7 +1003,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
                                // save bookmarks to .lyx/session
                                view()->saveSavedPositions();
-                       }
+                       }                       
                        quitLyX(argument == "force");
                        break;
 
@@ -1377,7 +1380,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                break;
                        }
 
-                       lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
+                       theApp->updateColor(lcolor.getFromLyXName(lyx_name));
 
                        if (graphicsbg_changed) {
 #ifdef WITH_WARNINGS
@@ -1855,7 +1858,7 @@ void LyXFunc::doImport(string const & argument)
        string const lyxfile = changeExtension(filename, ".lyx");
 
        // Check if the document already is open
-       if (lyx_gui::use_gui && theBufferList().exists(lyxfile)) {
+       if (lyx::use_gui && theBufferList().exists(lyxfile)) {
                if (!theBufferList().close(theBufferList().getBuffer(lyxfile), true)) {
                        owner->message(_("Canceled."));
                        return;
index 2f8023b8bd9961b73cd1f659b575b19e13a44a64..90b67e3f6eed2fc928f6599eaead70984b51334d 100644 (file)
@@ -44,7 +44,7 @@
 #include "funcrequest.h"
 #include "LyXAction.h"
 #include "lyxfunc.h"
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 
@@ -189,7 +189,8 @@ int LyXComm::startPipe(string const & filename, bool write)
        }
 
        if (!write) {
-               lyx_gui::register_socket_callback(fd, boost::bind(&LyXComm::read_ready, this));
+               theApp->registerSocketCallback(fd,
+                       boost::bind(&LyXComm::read_ready, this));
        }
 
        return fd;
@@ -202,7 +203,7 @@ void LyXComm::endPipe(int & fd, string const & filename, bool write)
                return;
 
        if (!write) {
-               lyx_gui::unregister_socket_callback(fd);
+               theApp->unregisterSocketCallback(fd);
        }
 
        if (::close(fd) < 0) {
index 4af70e10b22c66843a39c08d009995862c1e72d2..c970e09c8f14bfff783d07edaaaee7e61df48433 100644 (file)
@@ -21,7 +21,7 @@
 #include "LyXAction.h"
 #include "lyxfunc.h"
 
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
 
 #include "support/environment.h"
 #include "support/lyxlib.h"
@@ -61,7 +61,7 @@ LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr)
        // Needed by lyxclient
        lyx::support::setEnv("LYXSOCKET", address_);
 
-       lyx_gui::register_socket_callback(
+       theApp->registerSocketCallback(
                fd_,
                boost::bind(&LyXServerSocket::serverCallback, this)
                );
@@ -75,7 +75,7 @@ LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr)
 LyXServerSocket::~LyXServerSocket()
 {
        if (fd_ != -1) {
-               lyx_gui::unregister_socket_callback(fd_);
+               theApp->unregisterSocketCallback(fd_);
                if (::close(fd_) != 0)
                        lyxerr << "lyx: Server socket " << fd_
                               << " IO error on closing: " << strerror(errno);
@@ -111,7 +111,7 @@ void LyXServerSocket::serverCallback()
        // Register the new client.
        clients[client_fd] =
                shared_ptr<LyXDataSocket>(new LyXDataSocket(client_fd));
-       lyx_gui::register_socket_callback(
+       theApp->registerSocketCallback(
                client_fd,
                boost::bind(&LyXServerSocket::dataCallback,
                            this, client_fd)
@@ -209,7 +209,7 @@ LyXDataSocket::~LyXDataSocket()
                lyxerr << "lyx: Data socket " << fd_
                       << " IO error on closing: " << strerror(errno);
 
-       lyx_gui::unregister_socket_callback(fd_);
+       theApp->unregisterSocketCallback(fd_);
        lyxerr[Debug::LYXSERVER] << "lyx: Data socket " << fd_ << " quitting."
                                 << endl;
 }