Transfer geometry related session code from LyX::newLyXView() to GuiView::setGeometry().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21606 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-11-14 13:56:13 +00:00
parent 9c928fba07
commit e5eabfe067
6 changed files with 68 additions and 81 deletions

View File

@ -56,7 +56,6 @@
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/convert.h"
#include "support/ExceptionMessage.h"
#include "support/os.h"
#include "support/Package.h"
@ -712,58 +711,8 @@ LyXView * LyX::newLyXView()
if (!lyx::use_gui)
return 0;
// FIXME: transfer all this geometry stuff to the frontend.
// determine windows size and position, from lyxrc and/or session
// initial geometry
unsigned int width = 690;
unsigned int height = 510;
// default icon size, will be overwritten by stored session value
unsigned int iconSizeXY = 0;
// FIXME: 0 means GuiView::NotMaximized by default!
int maximized = 0;
// 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 = session().sessionInfo().load("WindowWidth");
if (!val.empty())
width = convert<unsigned int>(val);
val = session().sessionInfo().load("WindowHeight");
if (!val.empty())
height = convert<unsigned int>(val);
val = session().sessionInfo().load("WindowMaximized");
if (!val.empty())
maximized = convert<int>(val);
val = session().sessionInfo().load("IconSizeXY");
if (!val.empty())
iconSizeXY = convert<unsigned int>(val);
}
// if user wants to restore window position
int posx = -1;
int posy = -1;
if (lyxrc.geometry_xysaved) {
string val = session().sessionInfo().load("WindowPosX");
if (!val.empty())
posx = convert<int>(val);
val = session().sessionInfo().load("WindowPosY");
if (!val.empty())
posy = convert<int>(val);
}
if (!geometryArg.empty())
{
width = 0;
height = 0;
}
// create the main window
LyXView * view = &pimpl_->application_->createView(width, height,
posx, posy, maximized, iconSizeXY, geometryArg);
LyXView * view = &pimpl_->application_->createView(geometryArg);
return view;
}

View File

@ -214,9 +214,7 @@ public:
virtual void unregisterSocketCallback(int fd) = 0;
/// Create the main window with given geometry settings.
virtual LyXView & createView(unsigned int width, unsigned int height,
int posx, int posy, int maximized,
unsigned int iconSizeXY, const std::string & geometryArg) = 0;
virtual LyXView & createView(std::string const & geometryArg) = 0;
///
LyXView const * currentView() const { return current_view_; }

View File

@ -194,21 +194,14 @@ GuiApplication::~GuiApplication()
}
LyXView & GuiApplication::createView(unsigned int width,
unsigned int height,
int posx, int posy,
int maximized,
unsigned int iconSizeXY,
const std::string & geometryArg)
LyXView & GuiApplication::createView(string const & geometryArg)
{
int const id = gui_.createRegisteredView();
GuiView & view = static_cast<GuiView &>(gui_.view(id));
theLyXFunc().setLyXView(&view);
view.init();
view.setGeometry(width, height, posx, posy, GuiView::Maximized(maximized),
iconSizeXY, geometryArg);
view.setGeometry(geometryArg);
view.setFocus();
setCurrentView(view);

View File

@ -70,10 +70,7 @@ public:
virtual void updateColor(ColorCode col);
virtual void registerSocketCallback(int fd, SocketCallback func);
void unregisterSocketCallback(int fd);
/// Create the main window with given geometry settings.
LyXView & createView(unsigned int width, unsigned int height,
int posx, int posy, int maximized,
unsigned int iconSizeXY, const std::string & geometryArg);
LyXView & createView(std::string const & geometryArg);
//@}
/// Methods inherited from \c QApplication class

View File

@ -494,13 +494,69 @@ void GuiView::saveGeometry()
}
void GuiView::setGeometry(unsigned int width,
unsigned int height,
int posx, int posy,
GuiView::Maximized maximized,
unsigned int iconSizeXY,
const string & geometryArg)
void GuiView::setGeometry(string const & geometryArg)
{
// *******************************************
// Beginning of the session handling stuff
//FIXME: Instead of the stuff below, we should use QSettings:
/*
QSettings settings;
QString key = "view " + QString::number(id) + "/geometry";
view.restoreGeometry(settings.value(key).toByteArray());
*/
// determine windows size and position, from lyxrc and/or session
// initial geometry
unsigned int width = 690;
unsigned int height = 510;
// default icon size, will be overwritten by stored session value
unsigned int iconSizeXY = 0;
Maximized maximized = NotMaximized;
SessionInfoSection & session = LyX::ref().session().sessionInfo();
// 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 = session.load("WindowWidth");
if (!val.empty())
width = convert<unsigned int>(val);
val = session.load("WindowHeight");
if (!val.empty())
height = convert<unsigned int>(val);
val = session.load("WindowMaximized");
if (!val.empty())
maximized = GuiView::Maximized(convert<int>(val));
val = session.load("IconSizeXY");
if (!val.empty())
iconSizeXY = convert<unsigned int>(val);
}
// if user wants to restore window position
int posx = -1;
int posy = -1;
if (lyxrc.geometry_xysaved) {
string val = session.load("WindowPosX");
if (!val.empty())
posx = convert<int>(val);
val = session.load("WindowPosY");
if (!val.empty())
posy = convert<int>(val);
}
if (!geometryArg.empty())
{
width = 0;
height = 0;
}
// End of the sesssion handling stuff
// *******************************************
// use last value (not at startup)
if (d.lastIconSize != 0)
setIconSize(d.lastIconSize);

View File

@ -67,13 +67,7 @@ public:
CompletelyMaximized
};
///
virtual void setGeometry(
unsigned int width,
unsigned int height,
int posx, int posy,
Maximized maximized,
unsigned int iconSizeXY,
const std::string & geometryArg);
virtual void setGeometry(std::string const & geometryArg);
/// save the geometry state in the session manager.
virtual void saveGeometry();
virtual void setBusy(bool);