]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt3/lyx_gui.C
clean up Abdel's cleanup
[lyx.git] / src / frontends / qt3 / lyx_gui.C
index 626eed8dad94bd2da2254efca90e0bba8ad0d17d..4a95a40739bb25992cfee732af56c37e030203af 100644 (file)
 #include "lyxrc.h"
 #include "lyxserver.h"
 #include "lyxsocket.h"
-#include "session.h"
 
 #include "graphics/LoaderQueue.h"
 
 #include "support/lstrings.h"
-#include "support/convert.h"
 #include "support/os.h"
 #include "support/package.h"
 #include "debug.h"
@@ -41,7 +39,9 @@
 #include <boost/signal.hpp> // FIXME: Is this needed? (Lgb)
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
+#include "frontends/WorkArea.h"
 
+#include "GuiImplementation.h"
 #include "QtView.h"
 #include "lcolorcache.h"
 #include "qfont_loader.h"
@@ -64,6 +64,8 @@
 using lyx::support::ltrim;
 using lyx::support::package;
 
+using lyx::frontend::Gui;
+using lyx::frontend::GuiImplementation;
 using lyx::frontend::QtView;
 
 namespace os = lyx::support::os;
@@ -81,6 +83,10 @@ using std::string;
 
 extern BufferList bufferlist;
 
+// FIXME: wrong place !
+LyXServer * lyxserver;
+LyXServerSocket * lyxsocket;
+
 namespace {
 
 int getDPI()
@@ -92,11 +98,15 @@ int getDPI()
 
 map<int, shared_ptr<socket_callback> > socket_callbacks;
 
-} // namespace anon
+void cleanup()
+{
+       delete lyxsocket;
+       lyxsocket = 0;
+       delete lyxserver;
+       lyxserver = 0;
+}
 
-// FIXME: wrong place !
-LyXServer * lyxserver;
-LyXServerSocket * lyxsocket;
+} // namespace anon
 
 // in QLyXKeySym.C
 extern void initEncodings();
@@ -106,7 +116,6 @@ extern bool lyxX11EventFilter(XEvent * xev);
 #endif
 
 #ifdef Q_WS_MACX
-extern bool macEventFilter(EventRef event);
 extern pascal OSErr
 handleOpenDocuments(const AppleEvent* inEvent, AppleEvent* /*reply*/,
                    long /*refCon*/);
@@ -116,13 +125,19 @@ class LQApplication : public QApplication
 {
 public:
        LQApplication(int & argc, char ** argv);
-       ~LQApplication();
+       //
+       Gui & gui() { return gui_; }
+
 #ifdef Q_WS_X11
        bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); }
 #endif
 #ifdef Q_WS_MACX
        bool macEventFilter(EventRef event);
 #endif
+
+private:
+       ///
+       GuiImplementation gui_;
 };
 
 
@@ -137,10 +152,6 @@ LQApplication::LQApplication(int & argc, char ** argv)
 }
 
 
-LQApplication::~LQApplication()
-{}
-
-
 #ifdef Q_WS_MACX
 bool LQApplication::macEventFilter(EventRef event)
 {
@@ -155,27 +166,30 @@ bool LQApplication::macEventFilter(EventRef event)
 }
 #endif
 
+LQApplication * theApp;
 
 namespace lyx_gui {
 
 bool use_gui = true;
 
-void parse_init(int & argc, char * argv[])
+
+int exec(int & argc, char * argv[])
 {
        // Force adding of font path _before_ QApplication is initialized
        FontLoader::initFontPath();
 
-       static LQApplication app(argc, argv);
+       LQApplication app(argc, argv);
+       theApp = &app;
 
 #if QT_VERSION >= 0x030200
        // install translation file for Qt built-in dialogs
        // These are only installed since Qt 3.2.x
-       static QTranslator qt_trans(0);
+       QTranslator qt_trans(0);
        if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
                          qInstallPathTranslations())) {
-               app.installTranslator(&qt_trans);
+               qApp->installTranslator(&qt_trans);
                // even if the language calls for RtL, don't do that
-               app.setReverseLayout(false);
+               qApp->setReverseLayout(false);
                lyxerr[Debug::GUI]
                        << "Successfully installed Qt translations for locale "
                        << QTextCodec::locale() << std::endl;
@@ -189,7 +203,7 @@ void parse_init(int & argc, char * argv[])
        // These translations are meant to break Qt/Mac menu merging
        // algorithm on some entries. It lists the menu names that
        // should not be moved to the LyX menu
-       static QTranslator aqua_trans(0);
+       QTranslator aqua_trans(0);
        aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
                                             "do_not_merge_me"));
        aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
@@ -199,7 +213,7 @@ void parse_init(int & argc, char * argv[])
        aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
                                             "do_not_merge_me"));
 
-       app.installTranslator(&aqua_trans);
+       qApp->installTranslator(&aqua_trans);
 #endif
 
        using namespace lyx::graphics;
@@ -211,6 +225,8 @@ void parse_init(int & argc, char * argv[])
        lyxrc.dpi = getDPI();
 
        LoaderQueue::setPriority(10,100);
+
+       return LyX::ref().exec2(argc, argv);
 }
 
 
@@ -218,68 +234,53 @@ void parse_lyxrc()
 {}
 
 
-void start(string const & batch, vector<string> const & files)
+LyXView* create_view(unsigned int width, unsigned int height, int posx, int posy,
+             bool maximize)
 {
        // this can't be done before because it needs the Languages object
        initEncodings();
 
-       // initial geometry
-       unsigned int width = 690;
-       unsigned int height = 510;
-       // first try lyxrc
-       if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) {
-               width = lyxrc.geometry_width;
-               height = lyxrc.geometry_height;
-       }
-       // if lyxrc returns (0,0), then use session info
-       else {
-               string val = LyX::ref().session().loadSessionInfo("WindowWidth");
-               if (val != "")
-                       width = convert<unsigned int>(val);
-               val = LyX::ref().session().loadSessionInfo("WindowHeight");
-               if (val != "")
-                       height = convert<unsigned int>(val);
-       }
+       int view_id = theApp->gui().newView(width, height);
+       QtView & view = static_cast<QtView &> (theApp->gui().view(view_id));
+       theApp->gui().newWorkArea(width, height, 0);
+
+       LyX::ref().addLyXView(&view);
 
-       boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
-       LyX::ref().addLyXView(view_ptr);
-
-       QtView & view = *view_ptr.get();
-
-       // if user wants to restore window position
-       if (lyxrc.geometry_xysaved) {
-               QPoint p = view.pos();
-               string val = LyX::ref().session().loadSessionInfo("WindowPosX");
-               if (val != "")
-                       p.setX(convert<unsigned int>(val));
-               val = LyX::ref().session().loadSessionInfo("WindowPosY");
-               if (val != "")
-                       p.setY(convert<unsigned int>(val));
-               view.move(p);
-       }
-       view.show();
        view.init();
 
+       if (width != 0 && height != 0) {
+               view.initFloatingGeometry(QRect(posx, posy, width, height));
+               view.resize(width, height);
+               if (posx != -1 && posy != -1)
+                       view.move(posx, posy);
+               view.show();
+               if (maximize)
+                       view.setWindowState(Qt::WindowMaximized);
+       } else
+               view.show();
+
+       return &view;
+}
+
+
+int start(LyXView * view, string const & batch)
+{
        // FIXME: some code below needs moving
 
-       lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
-       lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
+       lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes);
+       lyxsocket = new LyXServerSocket(&view->getLyXFunc(),
                          os::internal_path(package().temp_dir() + "/lyxsocket"));
 
-       for_each(files.begin(), files.end(),
-                bind(&BufferView::loadLyXFile, view.view(), _1, true));
-
        // handle the batch commands the user asked for
        if (!batch.empty()) {
-               view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
+               view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch));
        }
 
-       qApp->exec();
+       int const status = qApp->exec();
 
        // FIXME
-       delete lyxsocket;
-       delete lyxserver;
-       lyxserver = 0;
+       cleanup();
+       return status;
 }
 
 
@@ -295,18 +296,10 @@ void sync_events()
 }
 
 
-void exit()
+void exit(int status)
 {
-       delete lyxsocket;
-       delete lyxserver;
-       lyxserver = 0;
-
-       // we cannot call qApp->exit(0) - that could return us
-       // into a static dialog return in the lyx code (for example,
-       // load autosave file QMessageBox. We have to just get the hell
-       // out.
-
-       ::exit(0);
+       cleanup();
+       QApplication::exit(status);
 }
 
 
@@ -314,10 +307,6 @@ FuncStatus getStatus(FuncRequest const & ev)
 {
        FuncStatus flag;
        switch (ev.action) {
-       case LFUN_DIALOG_SHOW:
-               if (ev.argument == "preamble")
-                       flag.unknown(true);
-               break;
        case LFUN_TOOLTIPS_TOGGLE:
                flag.unknown(true);
                break;