]> 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 f58f5cf564bfb695829f5144d640959be7efe09f..4a95a40739bb25992cfee732af56c37e030203af 100644 (file)
@@ -39,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"
@@ -62,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;
@@ -121,12 +125,19 @@ class LQApplication : public QApplication
 {
 public:
        LQApplication(int & argc, char ** argv);
+       //
+       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_;
 };
 
 
@@ -155,18 +166,20 @@ bool LQApplication::macEventFilter(EventRef event)
 }
 #endif
 
+LQApplication * theApp;
 
 namespace lyx_gui {
 
 bool use_gui = true;
 
 
-void exec(int & argc, char * argv[])
+int exec(int & argc, char * argv[])
 {
        // Force adding of font path _before_ QApplication is initialized
        FontLoader::initFontPath();
 
        LQApplication app(argc, argv);
+       theApp = &app;
 
 #if QT_VERSION >= 0x030200
        // install translation file for Qt built-in dialogs
@@ -213,7 +226,7 @@ void exec(int & argc, char * argv[])
 
        LoaderQueue::setPriority(10,100);
 
-       LyX::ref().exec2(argc, argv);
+       return LyX::ref().exec2(argc, argv);
 }
 
 
@@ -221,41 +234,53 @@ void parse_lyxrc()
 {}
 
 
-void start(string const & batch, vector<string> const & files,
-          unsigned int width, unsigned int height, int posx, int posy, bool)
+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();
 
-       boost::shared_ptr<QtView> view_ptr(new QtView(width, height));
-       LyX::ref().addLyXView(view_ptr);
+       int view_id = theApp->gui().newView(width, height);
+       QtView & view = static_cast<QtView &> (theApp->gui().view(view_id));
+       theApp->gui().newWorkArea(width, height, 0);
 
-       QtView & view = *view_ptr.get();
+       LyX::ref().addLyXView(&view);
 
-       if (posx != -1 && posy != -1)
-               view.move(QPoint(posx, posy));
-
-       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
        cleanup();
+       return status;
 }
 
 
@@ -274,13 +299,7 @@ void sync_events()
 void exit(int status)
 {
        cleanup();
-
-       // we cannot call QApplication::exit(status) - 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(status);
+       QApplication::exit(status);
 }
 
 
@@ -288,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;