From 83ffa28e7717a120eeda917bc9d83b335815fcde Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 12 Oct 2006 14:10:13 +0000 Subject: [PATCH] This commit is purely mechanical and get rid of lyx_gui.[Ch]. 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 --- development/scons/scons_manifest.py | 4 - src/BranchList.C | 8 +- src/frontends/Alert.C | 24 +++-- src/frontends/Application.C | 4 +- src/frontends/Application.h | 43 +++++++- src/frontends/Makefile.am | 2 - src/frontends/WorkArea.C | 1 - src/frontends/gtk/GuiApplication.C | 75 ++++++++++++++ src/frontends/gtk/GuiApplication.h | 6 ++ src/frontends/gtk/Makefile.am | 1 - src/frontends/gtk/xftFontLoader.C | 7 +- src/frontends/lyx_gui.C | 27 ----- src/frontends/lyx_gui.h | 80 --------------- src/frontends/qt3/GuiApplication.C | 65 ++++++++++++ src/frontends/qt3/GuiApplication.h | 6 ++ src/frontends/qt3/GuiFontMetrics.C | 21 ++-- src/frontends/qt3/Makefile.am | 1 - src/frontends/qt3/QLPopupMenu.C | 4 +- src/frontends/qt3/QMathDialog.C | 4 +- src/frontends/qt3/QPrefs.C | 1 - src/frontends/qt3/QViewSource.C | 1 - src/frontends/qt3/qfont_loader.C | 8 +- src/frontends/qt4/GuiApplication.C | 76 +++++++++++++- src/frontends/qt4/GuiApplication.h | 10 ++ src/frontends/qt4/GuiFontLoader.C | 7 +- src/frontends/qt4/GuiFontMetrics.C | 22 ++-- src/frontends/qt4/Makefile.am | 1 - src/frontends/qt4/QLPopupMenu.C | 1 - src/frontends/qt4/QMathDialog.C | 2 +- src/frontends/qt4/QPrefs.C | 2 - src/frontends/qt4/QPrefsDialog.C | 2 +- src/frontends/qt4/lyx_gui.C | 154 ---------------------------- src/graphics/PreviewLoader.C | 6 +- src/insets/insetexternal.C | 8 +- src/insets/insetgraphicsParams.C | 8 +- src/lyx_cb.C | 13 ++- src/lyx_main.C | 51 +++++---- src/lyx_main.h | 8 +- src/lyxfunc.C | 11 +- src/lyxserver.C | 7 +- src/lyxsocket.C | 10 +- 41 files changed, 415 insertions(+), 377 deletions(-) delete mode 100644 src/frontends/lyx_gui.C delete mode 100644 src/frontends/lyx_gui.h delete mode 100644 src/frontends/qt4/lyx_gui.C diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index fc4ca8fb46..2106610203 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -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 diff --git a/src/BranchList.C b/src/BranchList.C index 75f183a0aa..6d5d163026 100644 --- a/src/BranchList.C +++ b/src/BranchList.C @@ -12,7 +12,9 @@ #include "BranchList.h" #include "LColor.h" -#include "frontends/lyx_gui.h" + +#include "frontends/Application.h" + #include 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_); } diff --git a/src/frontends/Alert.C b/src/frontends/Alert.C index 98c971c37a..1f482ddf8d 100644 --- a/src/frontends/Alert.C +++ b/src/frontends/Alert.C @@ -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 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(true, dflt); } diff --git a/src/frontends/Application.C b/src/frontends/Application.C index 5b8d846b59..b9f257b193 100644 --- a/src/frontends/Application.C +++ b/src/frontends/Application.C @@ -32,6 +32,8 @@ #include "support/os.h" #include "support/package.h" +#include +#include 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(); } + diff --git a/src/frontends/Application.h b/src/frontends/Application.h index b1eff4ecfa..6f34a07677 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -11,7 +11,7 @@ #ifndef LYX_APPLICATION_H #define LYX_APPLICATION_H -#include +#include #include @@ -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 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; diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index f0387da1ef..c07ad1c533 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -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 diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 548cc276a5..1ecab9fdc6 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -19,7 +19,6 @@ #include "frontends/FontMetrics.h" #include "funcrequest.h" -#include "lyx_gui.h" #include "lyxfunc.h" #include "Painter.h" diff --git a/src/frontends/gtk/GuiApplication.C b/src/frontends/gtk/GuiApplication.C index 431fec9491..6888059cf0 100644 --- a/src/frontends/gtk/GuiApplication.C +++ b/src/frontends/gtk/GuiApplication.C @@ -49,6 +49,8 @@ using std::endl; namespace { +std::map > 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 func) +{ + callbacks[fd] = boost::shared_ptr(new io_callback(fd, func)); +} + + +void GuiApplication::unregisterSocketCallback(int fd) +{ + callbacks.erase(fd); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/gtk/GuiApplication.h b/src/frontends/gtk/GuiApplication.h index 0ffaa0b4b4..d803f77bd4 100644 --- a/src/frontends/gtk/GuiApplication.h +++ b/src/frontends/gtk/GuiApplication.h @@ -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 func); + virtual void unregisterSocketCallback(int fd); //@} /// diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 718f4bc1ec..13ea2570a6 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -144,7 +144,6 @@ libgtk_la_SOURCES = \ GuiImplementation.C \ io_callback.C \ io_callback.h \ - lyx_gui.C \ xftFontLoader.C \ xftFontLoader.h \ xftFontMetrics.C diff --git a/src/frontends/gtk/xftFontLoader.C b/src/frontends/gtk/xftFontLoader.C index 41214bec35..ec86a0c8a0 100644 --- a/src/frontends/gtk/xftFontLoader.C +++ b/src/frontends/gtk/xftFontLoader.C @@ -26,7 +26,6 @@ #include "GtkmmX.h" #include "frontends/LyXView.h" -#include "frontends/lyx_gui.h" #include "support/convert.h" #include "support/lstrings.h" @@ -39,6 +38,10 @@ 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 cache_set(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/lyx_gui.C b/src/frontends/lyx_gui.C deleted file mode 100644 index 951e2a2827..0000000000 --- a/src/frontends/lyx_gui.C +++ /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 - -#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 index 22ed0f1360..0000000000 --- a/src/frontends/lyx_gui.h +++ /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 - -#include -#include - -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 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 diff --git a/src/frontends/qt3/GuiApplication.C b/src/frontends/qt3/GuiApplication.C index 0b4e13fc47..d167f9fdb8 100644 --- a/src/frontends/qt3/GuiApplication.C +++ b/src/frontends/qt3/GuiApplication.C @@ -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 > 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 func) +{ + socket_callbacks[fd] = shared_ptr(new socket_callback(fd, func)); +} + + +void GuiApplication::unregisterSocketCallback(int fd) +{ + socket_callbacks.erase(fd); +} + + //////////////////////////////////////////////////////////////////////// // X11 specific stuff goes here... #ifdef Q_WS_X11 diff --git a/src/frontends/qt3/GuiApplication.h b/src/frontends/qt3/GuiApplication.h index 82eca1c870..9684b95853 100644 --- a/src/frontends/qt3/GuiApplication.h +++ b/src/frontends/qt3/GuiApplication.h @@ -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 func); + virtual void unregisterSocketCallback(int fd); //@} /// diff --git a/src/frontends/qt3/GuiFontMetrics.C b/src/frontends/qt3/GuiFontMetrics.C index 3e4fdd95e7..166ff65e5b 100644 --- a/src/frontends/qt3/GuiFontMetrics.C +++ b/src/frontends/qt3/GuiFontMetrics.C @@ -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); diff --git a/src/frontends/qt3/Makefile.am b/src/frontends/qt3/Makefile.am index 65bbd2cf59..ad541e7725 100644 --- a/src/frontends/qt3/Makefile.am +++ b/src/frontends/qt3/Makefile.am @@ -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 \ diff --git a/src/frontends/qt3/QLPopupMenu.C b/src/frontends/qt3/QLPopupMenu.C index 636b138440..927bb01621 100644 --- a/src/frontends/qt3/QLPopupMenu.C +++ b/src/frontends/qt3/QLPopupMenu.C @@ -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]; diff --git a/src/frontends/qt3/QMathDialog.C b/src/frontends/qt3/QMathDialog.C index 06ea72ee30..71e65ef3cd 100644 --- a/src/frontends/qt3/QMathDialog.C +++ b/src/frontends/qt3/QMathDialog.C @@ -18,7 +18,7 @@ #include "controllers/ControlMath.h" -#include "frontends/lyx_gui.h" +#include "frontends/Application.h" #include #include @@ -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: diff --git a/src/frontends/qt3/QPrefs.C b/src/frontends/qt3/QPrefs.C index c0a874bfda..d7926425d2 100644 --- a/src/frontends/qt3/QPrefs.C +++ b/src/frontends/qt3/QPrefs.C @@ -47,7 +47,6 @@ #include "controllers/helper_funcs.h" #include "frontends/Application.h" -#include "frontends/lyx_gui.h" #include #include "qcoloritem.h" diff --git a/src/frontends/qt3/QViewSource.C b/src/frontends/qt3/QViewSource.C index 174fdd9503..acb0fff39c 100644 --- a/src/frontends/qt3/QViewSource.C +++ b/src/frontends/qt3/QViewSource.C @@ -14,7 +14,6 @@ #include "QViewSource.h" #include "QViewSourceDialog.h" #include "qt_helpers.h" -#include "lyx_gui.h" #include "frontends/Application.h" diff --git a/src/frontends/qt3/qfont_loader.C b/src/frontends/qt3/qfont_loader.C index 8304584e3a..8ed07531eb 100644 --- a/src/frontends/qt3/qfont_loader.C +++ b/src/frontends/qt3/qfont_loader.C @@ -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 cache_set(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C index 147238249f..d7293c3004 100644 --- a/src/frontends/qt4/GuiApplication.C +++ b/src/frontends/qt4/GuiApplication.C @@ -16,6 +16,7 @@ #include "qt_helpers.h" #include "QLImage.h" +#include "socket_callback.h" #include "graphics/LoaderQueue.h" @@ -24,9 +25,10 @@ #include "support/package.h" #include "BufferView.h" +#include "Color.h" +#include "debug.h" #include "lyx_main.h" #include "lyxrc.h" -#include "debug.h" #include #include @@ -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 func) +{ + socket_callbacks_[fd] = + boost::shared_ptr(new socket_callback(fd, func)); +} + + +void GuiApplication::unregisterSocketCallback(int fd) +{ + socket_callbacks_.erase(fd); +} + //////////////////////////////////////////////////////////////////////// // X11 specific stuff goes here... #ifdef Q_WS_X11 diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 6f3acf8dda..2212ec44fe 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -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 func); + virtual void unregisterSocketCallback(int fd); //@} /// @@ -83,6 +91,8 @@ private: GuiFontLoader font_loader_; /// ColorCache color_cache_; + /// + std::map > socket_callbacks_; #ifdef Q_WS_X11 public: diff --git a/src/frontends/qt4/GuiFontLoader.C b/src/frontends/qt4/GuiFontLoader.C index f98c4a7324..7b46412539 100644 --- a/src/frontends/qt4/GuiFontLoader.C +++ b/src/frontends/qt4/GuiFontLoader.C @@ -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 cache_set(LyXFont::NUM_FAMILIES, false); diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index 8885b5cb09..a898e6ae3c 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -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; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 650ff7b343..dfd819538a 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 \ diff --git a/src/frontends/qt4/QLPopupMenu.C b/src/frontends/qt4/QLPopupMenu.C index c7becf343c..763664ff29 100644 --- a/src/frontends/qt4/QLPopupMenu.C +++ b/src/frontends/qt4/QLPopupMenu.C @@ -23,7 +23,6 @@ #include "qt_helpers.h" #include "MenuBackend.h" -#include "frontends/lyx_gui.h" #include "support/lstrings.h" #include "debug.h" diff --git a/src/frontends/qt4/QMathDialog.C b/src/frontends/qt4/QMathDialog.C index 1de28ad8d7..bad3fffb95 100644 --- a/src/frontends/qt4/QMathDialog.C +++ b/src/frontends/qt4/QMathDialog.C @@ -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; diff --git a/src/frontends/qt4/QPrefs.C b/src/frontends/qt4/QPrefs.C index 62251df88a..3bd30f2799 100644 --- a/src/frontends/qt4/QPrefs.C +++ b/src/frontends/qt4/QPrefs.C @@ -27,8 +27,6 @@ #include "controllers/frnt_lang.h" #include "controllers/helper_funcs.h" -#include "frontends/lyx_gui.h" - using namespace Ui; namespace lyx { diff --git a/src/frontends/qt4/QPrefsDialog.C b/src/frontends/qt4/QPrefsDialog.C index f92dc97a4b..de52935db6 100644 --- a/src/frontends/qt4/QPrefsDialog.C +++ b/src/frontends/qt4/QPrefsDialog.C @@ -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 index ea848a26ce..0000000000 --- a/src/frontends/qt4/lyx_gui.C +++ /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 - -#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 -#include -#include -#include -#include -#include - -#include -#include - - -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 > 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 func) -{ - socket_callbacks[fd] = shared_ptr(new socket_callback(fd, func)); -} - - -void unregister_socket_callback(int fd) -{ - socket_callbacks.erase(fd); -} - -}; // namespace lyx_gui diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 0ed2ef8c0b..57d100d722 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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()); diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 59f4c6322d..ce2e6fff8f 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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; diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index c0e140316c..875b332223 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -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; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 0735a98f98..f1226535dd 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -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(); + } } diff --git a/src/lyx_main.C b/src/lyx_main.C index 6a05a113a5..2d1a08489e 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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 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 cmdmap; @@ -1082,6 +1097,4 @@ bool LyX::easyParse(int & argc, char * argv[]) } batch_command = batch; - - return is_gui; } diff --git a/src/lyx_main.h b/src/lyx_main.h index c791c605f8..c40232f454 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -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 &); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b74f997c87..798cb199b6 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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 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; diff --git a/src/lyxserver.C b/src/lyxserver.C index 2f8023b8bd..90b67e3f6e 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -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) { diff --git a/src/lyxsocket.C b/src/lyxsocket.C index 4af70e10b2..c970e09c8f 100644 --- a/src/lyxsocket.C +++ b/src/lyxsocket.C @@ -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(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; } -- 2.39.2