From: Bo Peng Date: Mon, 29 May 2006 15:11:19 +0000 (+0000) Subject: Move window width/height/posx/posy from frontends to lyx_main.C, from Bo Peng (ben... X-Git-Tag: 1.6.10~13178 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f9c7473ed367731fc3a1c76ad7d66e8ee57a0523;p=features.git Move window width/height/posx/posy from frontends to lyx_main.C, from Bo Peng (ben.bob@gmail.com) * src/frontends/ALLFRONTENDS/lyx_gui.C: use passed width/height/posx/posy in lyx_gui::start * src/frontends/lyx_gui.h: prototype change for lyx_gui::start * src/lyx_main.C: determine windows size and position from lyxrc or session. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13953 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index fef13b1af1..e392acba82 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -120,7 +120,8 @@ void lyx_gui::parse_lyxrc() } -void lyx_gui::start(string const & batch, std::vector const & files) +void lyx_gui::start(string const & batch, std::vector const & files, + int width, int height, int posx, int posy) { boost::shared_ptr view_ptr(new GView); LyX::ref().addLyXView(view_ptr); diff --git a/src/frontends/lyx_gui.h b/src/frontends/lyx_gui.h index f3829b2af3..397fd4eebb 100644 --- a/src/frontends/lyx_gui.h +++ b/src/frontends/lyx_gui.h @@ -59,7 +59,8 @@ void parse_lyxrc(); * Start the main event loop, after executing the given * batch commands, and loading the given documents */ -void start(std::string const & batch, std::vector const & files); +void start(std::string const & batch, std::vector const & files, + int width, int height, int posx, int posy); /** * Synchronise all pending events. diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 626eed8dad..57790a40b7 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -25,12 +25,10 @@ #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" @@ -218,45 +216,20 @@ void parse_lyxrc() {} -void start(string const & batch, vector const & files) +void start(string const & batch, vector const & files, + int width, int height, int posx, int posy) { // 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(val); - val = LyX::ref().session().loadSessionInfo("WindowHeight"); - if (val != "") - height = convert(val); - } - boost::shared_ptr 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(val)); - val = LyX::ref().session().loadSessionInfo("WindowPosY"); - if (val != "") - p.setY(convert(val)); - view.move(p); - } + if (posx != -1 && posy != -1) + view.move(QPoint(posx, posy)); + view.show(); view.init(); diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index 2e8779094c..385b1e2b4f 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -25,12 +25,10 @@ #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" @@ -242,45 +240,20 @@ void parse_lyxrc() {} -void start(string const & batch, vector const & files) +void start(string const & batch, vector const & files, + int width, int height, int posx, int posy) { // 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(val); - val = LyX::ref().session().loadSessionInfo("WindowHeight"); - if (val != "") - height = convert(val); - } - boost::shared_ptr 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(val)); - val = LyX::ref().session().loadSessionInfo("WindowPosY"); - if (val != "") - p.setY(convert(val)); - view.move(p); - } + if (posx != -1 && posy != -1) + view.move(QPoint(posx, posy)); + view.show(); view.init(); diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index a35383f3e2..874b3eceef 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -28,7 +28,6 @@ #include "LyXAction.h" #include "lyxfunc.h" #include "lyxrc.h" -#include "session.h" #include "lyxserver.h" #include "lyxsocket.h" @@ -38,7 +37,6 @@ #include "support/lyxlib.h" #include "support/os.h" #include "support/package.h" -#include "support/convert.h" #include "lyx_forms.h" @@ -254,28 +252,9 @@ void parse_lyxrc() } -void start(string const & batch, vector const & files) +void start(string const & batch, vector const & files, + int width, int height, int posx, int posy) { - // initial geometry - int xpos = -1; - int ypos = -1; - 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(val); - val = LyX::ref().session().loadSessionInfo("WindowHeight"); - if (val != "") - height = convert(val); - } - int const geometryBitmask = XParseGeometry(geometry, &xpos, &ypos, &width, &height); @@ -296,21 +275,14 @@ void start(string const & batch, vector const & files) Screen * s = ScreenOfDisplay(fl_get_display(), fl_screen); - // recalculate xpos if it's not set - if (xpos == -1) - xpos = (WidthOfScreen(s) - width) / 2; - - // recalculate ypos if it's not set - if (ypos == -1) - ypos = (HeightOfScreen(s) - height) / 2; - lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height - << '+' << xpos << '+' << ypos << endl; + << '+' << posx << '+' << posy << endl; boost::shared_ptr view(new XFormsView(width, height)); LyX::ref().addLyXView(view); - view->show(xpos, ypos, "LyX"); + view->show(posx == -1 ? (WidthOfScreen(s) - width) / 2 : posx, + posy == -1 ? (HeightOfScreen(s) - height) / 2 : posy, "LyX"); view->init(); // FIXME: some code below needs moving diff --git a/src/lyx_main.C b/src/lyx_main.C index 3823fba93b..ecea886fc3 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -49,6 +49,7 @@ #include "support/environment.h" #include "support/filetools.h" #include "support/lyxlib.h" +#include "support/convert.h" #include "support/os.h" #include "support/package.h" #include "support/path.h" @@ -283,9 +284,38 @@ void LyX::priv_exec(int & argc, char * argv[]) files.clear(); // the files are already loaded } - if (want_gui) - lyx_gui::start(batch_command, files); - else { + if (want_gui) { + // determine windows size and position, from lyxrc and/or session + // 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.empty()) + width = convert(val); + val = LyX::ref().session().loadSessionInfo("WindowHeight"); + if (!val.empty()) + height = convert(val); + } + // if user wants to restore window position + int posx = -1; + int posy = -1; + if (lyxrc.geometry_xysaved) { + string val = LyX::ref().session().loadSessionInfo("WindowPosX"); + if (!val.empty()) + posx = convert(val); + val = LyX::ref().session().loadSessionInfo("WindowPosY"); + if (!val.empty()) + posy = convert(val); + } + lyx_gui::start(batch_command, files, width, height, posx, posy); + } else { // Something went wrong above quitLyX(false); exit(EXIT_FAILURE);