From 3a1f656e4e60091daaf5cad91c970ade945ef63d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 29 Sep 2006 23:10:17 +0000 Subject: [PATCH] * Application: new createView() method * gtk/qt3/qt4/GuiApplication: createView() method deleted * LyXView: - init(): is now a pure virtual method. autoSave code transferred to constructor and updates to the frontends. - setGeometry(): new pure virtual method * gtk/GView, qt3/QtView, qt4/GuiView: adapted to above change - setGeometry(): code transfered from GuiApplication * lyx_main.C: call LyX::ref().addLyXView() in there instead of in Application::createView() * git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15183 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Application.C | 31 +++++++++++++++++- src/frontends/Application.h | 6 ++++ src/frontends/LyXView.C | 21 ++++-------- src/frontends/LyXView.h | 8 ++++- src/frontends/gtk/GView.C | 16 ++++++++++ src/frontends/gtk/GView.h | 10 ++++++ src/frontends/gtk/GuiApplication.C | 23 -------------- src/frontends/qt3/GuiApplication.C | 15 --------- src/frontends/qt3/QtView.C | 22 ++++++++++++- src/frontends/qt3/QtView.h | 9 +++++- src/frontends/qt4/GuiApplication.C | 51 +----------------------------- src/frontends/qt4/GuiApplication.h | 4 --- src/frontends/qt4/GuiView.C | 31 +++++++++++++++++- src/frontends/qt4/GuiView.h | 7 ++++ src/lyx_main.C | 1 + 15 files changed, 143 insertions(+), 112 deletions(-) diff --git a/src/frontends/Application.C b/src/frontends/Application.C index 9e95d81b38..87d40fa60a 100644 --- a/src/frontends/Application.C +++ b/src/frontends/Application.C @@ -14,11 +14,12 @@ #include "Application_pimpl.h" #include "Gui.h" +#include "LyXView.h" +#include "WorkArea.h" #include "LyXAction.h" #include "lyxfunc.h" #include "lyxrc.h" -#include "LyXView.h" #include "support/lstrings.h" #include "support/os.h" @@ -90,6 +91,34 @@ void Application::setBufferView(BufferView * buffer_view) } +// FIXME: this whole method needs to be moved to Application. +LyXView & Application::createView(unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) +{ + // 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)); + + // 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_); + + view.init(); + view.setGeometry(width, height, posx, posy, maximize); + + return view; +} + + int Application::start(std::string const & batch) { pimpl_->lyx_server_.reset(new LyXServer(pimpl_->lyxfunc_.get(), lyxrc.lyxpipes)); diff --git a/src/frontends/Application.h b/src/frontends/Application.h index d8cee6ca4b..64c3402473 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -20,6 +20,7 @@ class BufferView; class LyXFunc; class LyXServer; class LyXServerSocket; +class LyXView; namespace lyx { namespace frontend { @@ -71,6 +72,11 @@ public: BufferList & bufferList(); BufferList const & bufferList() const; + /// + LyXView & createView(unsigned int width, unsigned int height, + int posx, int posy, bool maximize); + + /// void setBufferView(BufferView * buffer_view); protected: diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index a7eb12bbb1..f6a2b9302e 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -71,7 +71,12 @@ LyXView::LyXView() dialogs_(new Dialogs(*this)), controlcommand_(new ControlCommandBuffer(*this)) { - lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl; + // Start autosave timer + if (lyxrc.autosave) { + autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this)); + autosave_timeout_->setTimeout(lyxrc.autosave * 1000); + autosave_timeout_->start(); + } } @@ -99,20 +104,6 @@ WorkArea * LyXView::workArea() } -void LyXView::init() -{ - updateLayoutChoice(); - updateMenubar(); - - // Start autosave timer - if (lyxrc.autosave) { - autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this)); - autosave_timeout_->setTimeout(lyxrc.autosave * 1000); - autosave_timeout_->start(); - } -} - - Buffer * LyXView::buffer() const { return work_area_->bufferView().buffer(); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index a36178a7e1..a52d484c20 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -69,7 +69,13 @@ public: * We have to have the toolbar and the other stuff created * before we can populate it with this call. */ - void init(); + virtual void init() = 0; + + virtual void setGeometry( + unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) = 0; /// show busy cursor virtual void busy(bool) const = 0; diff --git a/src/frontends/gtk/GView.C b/src/frontends/gtk/GView.C index dae159db6a..73edeb76e3 100644 --- a/src/frontends/gtk/GView.C +++ b/src/frontends/gtk/GView.C @@ -131,6 +131,22 @@ GView::~GView() {} +void GView::init() +{ + updateLayoutChoice(); + updateMenubar(); +} + + +void GView::setGeometry(unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) +{ +// FIXME: do something here... +} + + Gtk::Box & GView::getBox(Position pos) { return *box_map_[pos]; diff --git a/src/frontends/gtk/GView.h b/src/frontends/gtk/GView.h index 655cdb4646..dc3179b307 100644 --- a/src/frontends/gtk/GView.h +++ b/src/frontends/gtk/GView.h @@ -38,6 +38,16 @@ public: GView(); ~GView(); + /// initialize the object + virtual void init(); + + /// FIXME: not implemented! + virtual void setGeometry( + unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize); + Gtk::Box & getBox(Position pos); virtual void prohibitInput() const; diff --git a/src/frontends/gtk/GuiApplication.C b/src/frontends/gtk/GuiApplication.C index 3e0dc71482..3abf2f4679 100644 --- a/src/frontends/gtk/GuiApplication.C +++ b/src/frontends/gtk/GuiApplication.C @@ -110,28 +110,5 @@ void GuiApplication::exit(int /*status*/) } -// FIXME: this whole method needs to be moved to Application. -LyXView & GuiApplication::createView(unsigned int width, - unsigned int height, - int posx, int posy, - bool maximize) -{ - // 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 view_id = gui().newView(width, height); - GView & view = static_cast(gui().view(view_id)); - - pimpl_->lyxfunc_.reset(new LyXFunc(&view)); - - LyX::ref().addLyXView(&view); - - view.show(); - view.init(); - - return view; -} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt3/GuiApplication.C b/src/frontends/qt3/GuiApplication.C index ccc4a51387..da58d7941d 100644 --- a/src/frontends/qt3/GuiApplication.C +++ b/src/frontends/qt3/GuiApplication.C @@ -190,21 +190,6 @@ LyXView & GuiApplication::createView(unsigned int width, view.init(); - // FIXME: put this initialisation code in GuiView accessible via - // a pure virtual method in LyXView. - - // only true when the -geometry option was NOT used - 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; } diff --git a/src/frontends/qt3/QtView.C b/src/frontends/qt3/QtView.C index 1f7b3eacd0..9052cf3ae6 100644 --- a/src/frontends/qt3/QtView.C +++ b/src/frontends/qt3/QtView.C @@ -91,7 +91,27 @@ void QtView::init() // and we don't save their orientation anyway. Disable the handle. setToolBarsMovable(false); - LyXView::init(); + updateLayoutChoice(); + updateMenubar(); +} + + +void QtView::setGeometry(unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) +{ + // only true when the -geometry option was NOT used + if (width != 0 && height != 0) { + initFloatingGeometry(QRect(posx, posy, width, height)); + resize(width, height); + if (posx != -1 && posy != -1) + move(posx, posy); + show(); + if (maximize) + setWindowState(Qt::WindowMaximized); + } else + show(); } diff --git a/src/frontends/qt3/QtView.h b/src/frontends/qt3/QtView.h index 89668fdab1..44ee0f3392 100644 --- a/src/frontends/qt3/QtView.h +++ b/src/frontends/qt3/QtView.h @@ -41,7 +41,14 @@ public: ~QtView(); /// initialise the object members (menubars, toolbars, etc..) - void init(); + virtual void init(); + + /// + virtual void setGeometry( + unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize); /// show - display the top-level window void show(); diff --git a/src/frontends/qt4/GuiApplication.C b/src/frontends/qt4/GuiApplication.C index a18fb3c388..47877f8a66 100644 --- a/src/frontends/qt4/GuiApplication.C +++ b/src/frontends/qt4/GuiApplication.C @@ -14,8 +14,6 @@ #include "GuiApplication.h" -#include "GuiView.h" -#include "GuiWorkArea.h" #include "qt_helpers.h" #include "QLImage.h" @@ -42,6 +40,7 @@ #include #include #include +#include #ifdef Q_WS_X11 #include @@ -165,54 +164,6 @@ void GuiApplication::exit(int status) } -// FIXME: this whole method needs to be moved to Application. -LyXView & GuiApplication::createView(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(); - - int view_id = gui().newView(width, height); - GuiView & view = static_cast (gui().view(view_id)); - - pimpl_->lyxfunc_.reset(new LyXFunc(&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_); - - LyX::ref().addLyXView(&view); - - view.init(); - - // FIXME: put this initialisation code in GuiView accessible via - // a pure virtual method in LyXView. - - // only true when the -geometry option was NOT used - if (width != 0 && height != 0) { - if (posx != -1 && posy != -1) { -#ifdef Q_OS_WIN32 - // FIXME: use only setGeoemtry when Trolltech has - // fixed the qt4/X11 bug - view.setGeometry(posx, posy,width, height); -#else - view.resize(width, height); - view.move(posx, posy); -#endif - } else { - view.resize(width, height); - } - - if (maximize) - view.setWindowState(Qt::WindowMaximized); - } - - view.show(); - - return view; -} //////////////////////////////////////////////////////////////////////// diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index aace15e84e..8bc3b97815 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -65,10 +65,6 @@ public: /// FontLoader & fontLoader() { return font_loader_; } - /// - LyXView & createView(unsigned int width, unsigned int height, - int posx, int posy, bool maximize); - private: /// GuiImplementation gui_; diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 59bc76c6a2..c3ac402172 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -104,10 +104,39 @@ void GuiView::init() // make sure the buttons are disabled if needed updateToolbars(); + updateLayoutChoice(); + updateMenubar(); +} + - LyXView::init(); +void GuiView::setGeometry(unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) +{ + // only true when the -geometry option was NOT used + if (width != 0 && height != 0) { + if (posx != -1 && posy != -1) { +#ifdef Q_OS_WIN32 + // FIXME: use only setGeoemtry when Trolltech has + // fixed the qt4/X11 bug + QMainWindow::setGeometry(posx, posy,width, height); +#else + resize(width, height); + move(posx, posy); +#endif + } else { + resize(width, height); + } + + if (maximize) + setWindowState(Qt::WindowMaximized); + } + + show(); } + void GuiView::updateMenu(QAction * /*action*/) { menubar_->update(); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index d4858a6acd..509807d2c8 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -54,6 +54,13 @@ public: /// initialize the object virtual void init(); + /// + virtual void setGeometry( + unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize); + /// show - display the top-level window void show(); diff --git a/src/lyx_main.C b/src/lyx_main.C index 1e328ac1d9..1d77e53ff7 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -338,6 +338,7 @@ int LyX::exec2(int & argc, char * argv[]) } // create the main window LyXView * view = lyx_gui::create_view(width, height, posx, posy, maximize); + ref().addLyXView(view); // load files for_each(files.begin(), files.end(), -- 2.39.2