FIXME: remove global variable theApp

This pointer was one reason for the Mac crashes because it not always had 
the same value as the application_ smart pointer



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16119 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Peter Kümmel 2006-11-30 00:04:51 +00:00
parent 30611541cb
commit 67f2a91dcc
12 changed files with 38 additions and 34 deletions

View File

@ -25,7 +25,7 @@ using std::string;
Branch::Branch()
{
theApp->getRgbColor(LColor::background, color_);
theApp()->getRgbColor(LColor::background, color_);
}
@ -74,7 +74,7 @@ void Branch::setColor(string const & c)
color_ = RGBColor(c);
else
// no color set or invalid color - use normal background
theApp->getRgbColor(LColor::background, color_);
theApp()->getRgbColor(LColor::background, color_);
}

View File

@ -99,8 +99,8 @@ frontend::FontLoader & theFontLoader()
if (!use_gui)
return no_gui_font_loader;
BOOST_ASSERT(theApp);
return theApp->fontLoader();
BOOST_ASSERT(theApp());
return theApp()->fontLoader();
}
@ -111,22 +111,22 @@ frontend::FontMetrics const & theFontMetrics(LyXFont const & f)
if (!use_gui)
return no_gui_font_metrics;
BOOST_ASSERT(theApp);
return theApp->fontLoader().metrics(f);
BOOST_ASSERT(theApp());
return theApp()->fontLoader().metrics(f);
}
frontend::Clipboard & theClipboard()
{
BOOST_ASSERT(theApp);
return theApp->clipboard();
BOOST_ASSERT(theApp());
return theApp()->clipboard();
}
frontend::Selection & theSelection()
{
BOOST_ASSERT(theApp);
return theApp->selection();
BOOST_ASSERT(theApp());
return theApp()->selection();
}

View File

@ -194,7 +194,7 @@ private:
} // namespace frontend
extern frontend::Application * theApp;
frontend::Application * theApp();
frontend::Application * createApplication(int & argc, char * argv[]);

View File

@ -142,7 +142,7 @@ void WorkArea::redraw()
// No need to do anything if this is the current view. The BufferView
// metrics are already up to date.
if (&lyx_view_ != &theApp->currentView())
if (&lyx_view_ != &theApp()->currentView())
// FIXME: it would be nice to optimize for the off-screen case.
buffer_view_->updateMetrics(false);

View File

@ -555,7 +555,7 @@ void GuiView::moveEvent(QMoveEvent *)
void GuiView::closeEvent(QCloseEvent * close_event)
{
GuiImplementation & gui
= static_cast<GuiImplementation &>(theApp->gui());
= static_cast<GuiImplementation &>(theApp()->gui());
vector<int> const & view_ids = gui.viewIds();

View File

@ -254,10 +254,10 @@ void GuiWorkArea::dropEvent(QDropEvent* event)
void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
{
// No need to do anything if we didn't change views...
if (theApp == 0 || &lyx_view_ == &theApp->currentView())
if (theApp() == 0 || &lyx_view_ == &theApp()->currentView())
return;
theApp->setCurrentView(lyx_view_);
theApp()->setCurrentView(lyx_view_);
// FIXME: it would be better to send a signal "newBuffer()"
// in BufferList that could be connected to the different tabbars.
@ -286,7 +286,7 @@ void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/)
void GuiWorkArea::focusOutEvent(QFocusEvent * /*event*/)
{
// No need to do anything if we didn't change views...
if (&lyx_view_ == &theApp->currentView())
if (&lyx_view_ == &theApp()->currentView())
return;
stopBlinkingCursor();

View File

@ -130,13 +130,13 @@ void setComboxFont(QComboBox * cb, string const & family, string const & foundry
QFont font;
font.setKerning(false);
if (family == theApp->romanFontName()) {
if (family == theApp()->romanFontName()) {
font.setStyleHint(QFont::Serif);
font.setFamily(family.c_str());
} else if (family == theApp->sansFontName()) {
} else if (family == theApp()->sansFontName()) {
font.setStyleHint(QFont::SansSerif);
font.setFamily(family.c_str());
} else if (family == theApp->typewriterFontName()) {
} else if (family == theApp()->typewriterFontName()) {
font.setStyleHint(QFont::TypeWriter);
font.setFamily(family.c_str());
} else {

View File

@ -91,7 +91,7 @@ void QViewSource::build_dialog()
dialog_->viewSourceTV->setReadOnly(true);
///dialog_->viewSourceTV->setAcceptRichText(false);
// this is personal. I think source code should be in fixed-size font
QFont font(toqstr(theApp->typewriterFontName()));
QFont font(toqstr(theApp()->typewriterFontName()));
font.setKerning(false);
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);

View File

@ -592,8 +592,8 @@ void PreviewLoader::Impl::startLoading()
cs << pconverter_->command << ' ' << pconverter_->to << ' '
<< support::quoteName(latexfile) << ' '
<< int(font_scaling_factor_) << ' '
<< theApp->hexName(LColor::preview) << ' '
<< theApp->hexName(LColor::background);
<< theApp()->hexName(LColor::preview) << ' '
<< theApp()->hexName(LColor::background);
string const command = support::libScriptSearch(cs.str());

View File

@ -99,8 +99,6 @@ using std::signal;
using std::system;
#endif
///
frontend::Application * theApp = 0;
/// are we using the GUI at all?
/**
@ -167,6 +165,15 @@ struct LyX::Singletons
IconvProcessor iconv;
};
///
frontend::Application * theApp()
{
if (singleton_)
return &singleton_->application();
else
return 0;
}
LyX::~LyX()
{
@ -365,8 +372,6 @@ int LyX::exec(int & argc, char * argv[])
// Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv));
// FIXME: this global pointer should probably go.
theApp = pimpl_->application_.get();
initGuiFont();
@ -462,7 +467,6 @@ void LyX::quit()
pimpl_->lyx_socket_.reset();
if (pimpl_->application_)
pimpl_->application_->exit(0);
theApp = 0;
}
}

View File

@ -1035,7 +1035,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_LYX_QUIT:
if (argument == "closeOnly") {
if (!theApp->gui().closeAll())
if (!theApp()->gui().closeAll())
break;
lyx_view_ = 0;
}
@ -1456,7 +1456,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
}
theApp->updateColor(lcolor.getFromLyXName(lyx_name));
theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
if (graphicsbg_changed) {
#ifdef WITH_WARNINGS

View File

@ -64,7 +64,7 @@ LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr)
// Needed by lyxclient
support::setEnv("LYXSOCKET", address_);
theApp->registerSocketCallback(
theApp()->registerSocketCallback(
fd_,
boost::bind(&LyXServerSocket::serverCallback, this)
);
@ -78,8 +78,8 @@ LyXServerSocket::LyXServerSocket(LyXFunc * f, string const & addr)
LyXServerSocket::~LyXServerSocket()
{
if (fd_ != -1) {
BOOST_ASSERT (theApp);
theApp->unregisterSocketCallback(fd_);
BOOST_ASSERT (theApp());
theApp()->unregisterSocketCallback(fd_);
if (::close(fd_) != 0)
lyxerr << "lyx: Server socket " << fd_
<< " IO error on closing: " << strerror(errno);
@ -115,7 +115,7 @@ void LyXServerSocket::serverCallback()
// Register the new client.
clients[client_fd] =
shared_ptr<LyXDataSocket>(new LyXDataSocket(client_fd));
theApp->registerSocketCallback(
theApp()->registerSocketCallback(
client_fd,
boost::bind(&LyXServerSocket::dataCallback,
this, client_fd)
@ -213,7 +213,7 @@ LyXDataSocket::~LyXDataSocket()
lyxerr << "lyx: Data socket " << fd_
<< " IO error on closing: " << strerror(errno);
theApp->unregisterSocketCallback(fd_);
theApp()->unregisterSocketCallback(fd_);
lyxerr[Debug::LYXSERVER] << "lyx: Data socket " << fd_ << " quitting."
<< endl;
}