]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/Application.C
* src/frontends/qt4/GuiSelection.C
[lyx.git] / src / frontends / Application.C
index b9f257b193baac0ec73ca7da87b726c672c00770..35eeaa9418dcf26bedfec3180d63a32eed2263d0 100644 (file)
 
 #include "frontends/Application.h"
 
+#include "frontends/NoGuiFontLoader.h"
+#include "frontends/NoGuiFontMetrics.h"
 #include "frontends/FontLoader.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/Gui.h"
 #include "frontends/LyXView.h"
 #include "frontends/WorkArea.h"
 
-#include "bufferlist.h"
 #include "funcrequest.h"
 #include "FuncStatus.h"
-#include "LyXAction.h"
+#include "lyx_main.h"  // for lyx::use_gui
 #include "lyxfont.h"
 #include "lyxfunc.h"
 #include "lyxrc.h"
-#include "lyxserver.h"
-#include "lyxsocket.h"
 
 #include "support/lstrings.h"
 #include "support/os.h"
-#include "support/package.h"
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
-using lyx::support::package;
 
 namespace lyx {
 namespace frontend {
 
-/// The main application class private implementation.
-struct Application_pimpl 
-{
-       /// our function handler
-       boost::scoped_ptr<LyXFunc> lyxfunc_;
-       ///
-       boost::scoped_ptr<LyXServer> lyx_server_;
-       ///
-       boost::scoped_ptr<LyXServerSocket> lyx_socket_;
-};
-
 
 Application::Application(int &, char **)
-{
-       pimpl_ = new Application_pimpl;
-}
-
-
-LyXFunc & Application::lyxFunc()
-{
-       return *pimpl_->lyxfunc_.get();
-}
-
-
-LyXFunc const & Application::lyxFunc() const
-{
-       return *pimpl_->lyxfunc_.get(); 
-}
-
-
-LyXServer & Application::server()
-{
-       return *pimpl_->lyx_server_.get(); 
-}
-
-
-LyXServer const & Application::server() const 
-{
-       return *pimpl_->lyx_server_.get(); 
-}
-
-
-LyXServerSocket & Application::socket()
-{
-       return *pimpl_->lyx_socket_.get();
-}
-
-
-LyXServerSocket const & Application::socket() const
-{
-       return *pimpl_->lyx_socket_.get();
-}
-
-
-void Application::setBufferView(BufferView * buffer_view)
-{
-       buffer_view_ = buffer_view;
-}
-
-
-LyXView & Application::createView(unsigned int width,
-                                                                 unsigned int height,
-                                                                 int posx, int posy,
-                                                                 bool maximize)
+       : current_view_(0)
 {
        // FIXME: please confirm: with unicode, I think initEncoding()
        // is not needed anymore!
        
        // this can't be done before because it needs the Languages object
        //initEncodings();
+}
 
-       int view_id = gui().newView(width, height);
-       LyXView & view = gui().view(view_id);
 
-       pimpl_->lyxfunc_.reset(new LyXFunc(&view));
+LyXView & Application::createView(unsigned int width,
+                                 unsigned int height,
+                                 int posx, int posy,
+                                 bool maximize,
+                                 unsigned int iconSizeXY,
+                                 const std::string & geometryArg)
+{
+       LyXView & view = gui().createRegisteredView();
+       int view_id = view.id();
+       
+       theLyXFunc().setLyXView(&view);
 
-       // FIXME: for now we assume that there is only one LyXView with id = 0.
-       /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
-       //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
+       /*int workArea_id_ =*/ gui().newWorkArea(width, height, view_id);
 
        view.init();
-       view.setGeometry(width, height, posx, posy, maximize);
+       view.setGeometry(width, height, posx, posy, maximize, iconSizeXY, geometryArg);
+       view.setFocus();
+
+       setCurrentView(view);
 
        return view;
 }
 
 
-int Application::start(std::string const & batch)
+LyXView const * Application::currentView() const
 {
-       pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes));
-       pimpl_->lyx_socket_.reset(new LyXServerSocket(pimpl_->lyxfunc_.get(), 
-               lyx::support::os::internal_path(package().temp_dir() + "/lyxsocket")));
-
-       // handle the batch commands the user asked for
-       if (!batch.empty()) {
-               pimpl_->lyxfunc_->dispatch(lyxaction.lookupFunc(batch));
-       }
-
-       return exec();
+       return current_view_;
 }
 
-} // namespace frontend
-
 
-FuncStatus getStatus(FuncRequest const & action)
+LyXView * Application::currentView()
 {
-       return theApp->lyxFunc().getStatus(action);
+       return current_view_;
 }
 
 
-void dispatch(FuncRequest const & action)
+void Application::setCurrentView(LyXView & current_view)
 {
-       theApp->lyxFunc().dispatch(action);
+       current_view_ = &current_view;
 }
 
-} // namespace lyx
+} // namespace frontend
+
 
 
-LyXFunc & theLyXFunc()
+frontend::FontLoader & theFontLoader()
 {
-       return theApp->lyxFunc();
-}
+       static frontend::NoGuiFontLoader no_gui_font_loader;
 
+       if (!use_gui)
+               return no_gui_font_loader;
 
-lyx::frontend::FontLoader & theFontLoader()
-{
-       return theApp->fontLoader();
+       BOOST_ASSERT(theApp());
+       return theApp()->fontLoader();
 }
 
 
-lyx::frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
+frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
 {
-       return theApp->fontLoader().metrics(f);
+       static frontend::NoGuiFontMetrics no_gui_font_metrics;
+
+       if (!use_gui)
+               return no_gui_font_metrics;
+
+       BOOST_ASSERT(theApp());
+       return theApp()->fontLoader().metrics(f);
 }
 
 
-lyx::frontend::Clipboard & theClipboard()
+frontend::Clipboard & theClipboard()
 {
-       return theApp->clipboard();
+       BOOST_ASSERT(theApp());
+       return theApp()->clipboard();
 }
 
 
-lyx::frontend::Selection & theSelection()
+frontend::Selection & theSelection()
 {
-       return theApp->selection();
+       BOOST_ASSERT(theApp());
+       return theApp()->selection();
 }
 
+
+} // namespace lyx