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
This commit is contained in:
Bo Peng 2006-05-29 15:11:19 +00:00
parent 16a8861cd5
commit f9c7473ed3
6 changed files with 52 additions and 102 deletions

View 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);

View 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.

View File

@ -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<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();

View File

@ -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<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();

View 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

View 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);