]> git.lyx.org Git - features.git/commitdiff
Move window width/height/posx/posy from frontends to lyx_main.C, from Bo Peng (ben...
authorBo Peng <bpeng@lyx.org>
Mon, 29 May 2006 15:11:19 +0000 (15:11 +0000)
committerBo Peng <bpeng@lyx.org>
Mon, 29 May 2006 15:11:19 +0000 (15:11 +0000)
* 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

src/frontends/gtk/lyx_gui.C
src/frontends/lyx_gui.h
src/frontends/qt3/lyx_gui.C
src/frontends/qt4/lyx_gui.C
src/frontends/xforms/lyx_gui.C
src/lyx_main.C

index fef13b1af14eba2e3278b660c60121182f08828c..e392acba82ae820d998a72a0d282929f0fe07025 100644 (file)
@@ -120,7 +120,8 @@ void lyx_gui::parse_lyxrc()
 }
 
 
-void lyx_gui::start(string const & batch, std::vector<string> const & files)
+void lyx_gui::start(string const & batch, std::vector<string> const & files,
+               int width, int height, int posx, int posy)
 {
        boost::shared_ptr<GView> view_ptr(new GView);
        LyX::ref().addLyXView(view_ptr);
index f3829b2af3a18c9b1a68ecac259cd4a5cd943a16..397fd4eebb979f67e6493ce81ef830fcdb5dbc59 100644 (file)
@@ -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<std::string> const & files);
+void start(std::string const & batch, std::vector<std::string> const & files,
+               int width, int height, int posx, int posy);
 
 /**
  * Synchronise all pending events.
index 626eed8dad94bd2da2254efca90e0bba8ad0d17d..57790a40b7c8a13b7af43a2c658cc213e69e73bb 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"
@@ -218,45 +216,20 @@ void parse_lyxrc()
 {}
 
 
-void start(string const & batch, vector<string> const & files)
+void start(string const & batch, vector<string> 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<unsigned int>(val);
-               val = LyX::ref().session().loadSessionInfo("WindowHeight");
-               if (val != "")
-                       height = convert<unsigned int>(val);
-       }
-
        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);
-       }
+       if (posx != -1 && posy != -1)
+               view.move(QPoint(posx, posy));
+
        view.show();
        view.init();
 
index 2e8779094ce89544839287e3a4e4a027f4a33d3b..385b1e2b4fc943b026d859327d287f3ce53209e0 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"
@@ -242,45 +240,20 @@ void parse_lyxrc()
 {}
 
 
-void start(string const & batch, vector<string> const & files)
+void start(string const & batch, vector<string> 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<unsigned int>(val);
-               val = LyX::ref().session().loadSessionInfo("WindowHeight");
-               if (val != "")
-                       height = convert<unsigned int>(val);
-       }
-
        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);
-       }
+       if (posx != -1 && posy != -1)
+               view.move(QPoint(posx, posy));
+
        view.show();
        view.init();
 
index a35383f3e2b38223bd116df1341fb0c830067bab..874b3eceef0a8324e360ce395ac5d8f40462e91e 100644 (file)
@@ -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<string> const & files)
+void start(string const & batch, vector<string> 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<unsigned int>(val);
-               val = LyX::ref().session().loadSessionInfo("WindowHeight");
-               if (val != "")
-                       height = convert<unsigned int>(val);
-       }
-
        int const geometryBitmask =
                XParseGeometry(geometry,
                               &xpos, &ypos, &width, &height);
@@ -296,21 +275,14 @@ void start(string const & batch, vector<string> 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<XFormsView> 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
index 3823fba93bc3ec20285cb3d12f67276a789dfe9f..ecea886fc3e529c9b8d8fcf6b9513a51faa528ce 100644 (file)
@@ -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<unsigned int>(val);
+                       val = LyX::ref().session().loadSessionInfo("WindowHeight");
+                       if (!val.empty())
+                               height = convert<unsigned int>(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<int>(val);
+                       val = LyX::ref().session().loadSessionInfo("WindowPosY");
+                       if (!val.empty())
+                               posy = convert<int>(val);
+               }
+               lyx_gui::start(batch_command, files, width, height, posx, posy);
+       } else {
                // Something went wrong above
                quitLyX(false);
                exit(EXIT_FAILURE);