// Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv));
- initGuiFont();
-
// Parse and remove all known arguments in the LyX singleton
// Give an error for all remaining ones.
int exit_status = init(argc, argv);
}
-void LyX::initGuiFont()
-{
- if (lyxrc.roman_font_name.empty())
- lyxrc.roman_font_name = pimpl_->application_->romanFontName();
-
- if (lyxrc.sans_font_name.empty())
- lyxrc.sans_font_name = pimpl_->application_->sansFontName();
-
- if (lyxrc.typewriter_font_name.empty())
- lyxrc.typewriter_font_name
- = pimpl_->application_->typewriterFontName();
-}
-
-
bool LyX::init()
{
#ifdef SIGHUP
/// Create a View, load files and restore GUI Session.
void restoreGuiSession();
- /// Initialize RC font for the GUI.
- void initGuiFont();
-
/// initial LyX set up
bool init();
/// set up the default dead key bindings if requested
{
public:
///
- Application() : current_view_(0) {}
+ Application() {}
///
virtual ~Application() {}
///
virtual bool closeAllViews() = 0;
-
///
virtual LyXView & view(int id) const = 0;
///
virtual size_t viewCount() const = 0;
-
///
virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
///
*/
virtual void exit(int status) = 0;
- /**
- * Synchronise all pending events.
- */
- virtual void syncEvents() = 0;
- ///
- virtual FontLoader & fontLoader() = 0;
-
- /// return a suitable serif font name.
- virtual std::string const romanFontName() = 0;
-
- /// return a suitable sans serif font name.
- virtual std::string const sansFontName() = 0;
-
- /// return a suitable monospaced font name.
- virtual std::string const typewriterFontName() = 0;
-
/**
* Given col, fills r, g, b in the range 0-255.
* The function returns true if successful.
/// Create the main window with given geometry settings.
/// \param geometry_arg: only for Windows platform.
virtual LyXView & createView(std::string const & geometry_arg) = 0;
-
- ///
- LyXView const * currentView() const { return current_view_; }
- ///
- LyXView * currentView() { return current_view_; }
- ///
- void setCurrentView(LyXView & view) { current_view_ = &view; }
-
-protected:
- /// This LyXView is the one receiving Clipboard and Selection
- /// events
- LyXView * current_view_;
};
} // namespace frontend
// This call has no effect if the cursor has not been overridden.
qApp->changeOverrideCursor(Qt::ArrowCursor);
- // FIXME replace that with theApp->gui()->currentView()
+ // FIXME replace that with guiApp->currentView()
int res = QMessageBox::information(qApp->focusWidget(),
toqstr(title),
toqstr(formatted(question)),
GuiApplication::GuiApplication(int & argc, char ** argv)
- : QApplication(argc, argv), Application()
+ : QApplication(argc, argv), Application(), current_view_(0)
{
QString app_name = "LyX";
QCoreApplication::setOrganizationName(app_name);
// Set the cache to 5120 kilobytes which corresponds to screen size of
// 1280 by 1024 pixels with a color depth of 32 bits.
QPixmapCache::setCacheLimit(5120);
+
+ // Initialize RC Fonts
+ if (lyxrc.roman_font_name.empty())
+ lyxrc.roman_font_name = fromqstr(romanFontName());
+
+ if (lyxrc.sans_font_name.empty())
+ lyxrc.sans_font_name = fromqstr(sansFontName());
+
+ if (lyxrc.typewriter_font_name.empty())
+ lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
}
}
+static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
+{
+ ids.clear();
+ map<int, GuiView *>::const_iterator it;
+ for (it = stdmap.begin(); it != stdmap.end(); ++it)
+ ids.push_back(it->first);
+}
+
+
LyXView & GuiApplication::createView(string const & geometry_arg)
{
- int const id = createRegisteredView();
+ updateIds(views_, view_ids_);
+ int id = 0;
+ while (views_.find(id) != views_.end())
+ id++;
+ views_[id] = new GuiView(id);
+ updateIds(views_, view_ids_);
+
GuiView * view = views_[id];
theLyXFunc().setLyXView(view);
}
-string const GuiApplication::romanFontName()
+QString const GuiApplication::romanFontName()
{
QFont font;
font.setKerning(false);
font.setStyleHint(QFont::Serif);
font.setFamily("serif");
- return fromqstr(QFontInfo(font).family());
+ return QFontInfo(font).family();
}
-string const GuiApplication::sansFontName()
+QString const GuiApplication::sansFontName()
{
QFont font;
font.setKerning(false);
font.setStyleHint(QFont::SansSerif);
font.setFamily("sans");
- return fromqstr(QFontInfo(font).family());
+ return QFontInfo(font).family();
}
-string const GuiApplication::typewriterFontName()
+QString const GuiApplication::typewriterFontName()
{
QFont font;
font.setKerning(false);
font.setStyleHint(QFont::TypeWriter);
font.setFamily("monospace");
- return fromqstr(QFontInfo(font).family());
+ return QFontInfo(font).family();
}
// Open a file; this happens only on Mac OS X for now
QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
- if (!currentView() || !currentView()->view())
+ if (!current_view_ || !current_view_->view())
// The application is not properly initialized yet.
// So we acknowledge the event and delay the file opening
// until LyX is ready.
}
-void GuiApplication::syncEvents()
-{
- // This is the ONLY place where processEvents may be called.
- // During screen update/ redraw, this method is disabled to
- // prevent keyboard events being handed to the LyX core, where
- // they could cause re-entrant calls to screen update.
- processEvents(QEventLoop::ExcludeUserInputEvents);
-}
-
-
bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
{
QColor const & qcol = color_cache_.get(col);
}
-static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
-{
- ids.clear();
- map<int, GuiView *>::const_iterator it;
- for (it = stdmap.begin(); it != stdmap.end(); ++it)
- ids.push_back(it->first);
-}
-
-
-int GuiApplication::createRegisteredView()
-{
- updateIds(views_, view_ids_);
- int id = 0;
- while (views_.find(id) != views_.end())
- id++;
- views_[id] = new GuiView(id);
- updateIds(views_, view_ids_);
- return id;
-}
-
-
bool GuiApplication::unregisterView(int id)
{
updateIds(views_, view_ids_);
#ifdef Q_WS_X11
bool GuiApplication::x11EventFilter(XEvent * xev)
{
- if (!currentView())
+ if (!current_view_)
return false;
switch (xev->type) {
if (xev->xselectionrequest.selection != XA_PRIMARY)
break;
LYXERR(Debug::GUI, "X requested selection.");
- BufferView * bv = currentView()->view();
+ BufferView * bv = current_view_->view();
if (bv) {
docstring const sel = bv->requestSelection();
if (!sel.empty())
if (xev->xselectionclear.selection != XA_PRIMARY)
break;
LYXERR(Debug::GUI, "Lost selection.");
- BufferView * bv = currentView()->view();
+ BufferView * bv = current_view_->view();
if (bv)
bv->clearSelection();
break;
if (!use_gui)
return no_gui_font_loader;
- BOOST_ASSERT(theApp());
- return theApp()->fontLoader();
+ BOOST_ASSERT(frontend::guiApp);
+ return frontend::guiApp->fontLoader();
}
if (!use_gui)
return no_gui_font_metrics;
- BOOST_ASSERT(theApp());
- return theApp()->fontLoader().metrics(f);
+ BOOST_ASSERT(frontend::guiApp);
+ return frontend::guiApp->fontLoader().metrics(f);
}
virtual int exec();
virtual void exit(int status);
virtual bool event(QEvent * e);
- void syncEvents();
- virtual std::string const romanFontName();
- virtual std::string const sansFontName();
- virtual std::string const typewriterFontName();
virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
virtual std::string const hexName(ColorCode col);
virtual void updateColor(ColorCode col);
void commitData(QSessionManager & sm);
//@}
+ ///
+ GuiView const * currentView() const { return current_view_; }
+ ///
+ GuiView * currentView() { return current_view_; }
+ ///
+ void setCurrentView(GuiView & view) { current_view_ = &view; }
+ ///
virtual size_t viewCount() const { return view_ids_.size(); }
+ ///
std::vector<int> const & viewIds() { return view_ids_; }
///
///
GuiFontLoader & guiFontLoader() { return font_loader_; }
+ /// return a suitable serif font name.
+ virtual QString const romanFontName();
- virtual int createRegisteredView();
+ /// return a suitable sans serif font name.
+ virtual QString const sansFontName();
+
+ /// return a suitable monospaced font name.
+ virtual QString const typewriterFontName();
+ ///
virtual bool closeAllViews();
+ ///
virtual bool unregisterView(int id);
-
+ ///
virtual LyXView & view(int id) const;
///
virtual void hideDialogs(std::string const & name, Inset * inset) const;
std::map<int, GuiView *> views_;
///
std::vector<int> view_ids_;
+ /// This LyXView is the one receiving Clipboard and Selection
+ /// events
+ GuiView * current_view_;
}; // GuiApplication
extern GuiApplication * guiApp;
#include "GuiLog.h"
+#include "GuiApplication.h"
#include "qt_helpers.h"
#include "gettext.h"
#include "Lexer.h"
-#include "frontends/Application.h"
-
#include <QCloseEvent>
#include <QTextBrowser>
#include <QSyntaxHighlighter>
highlighter = new LogHighlighter(logTB->document());
logTB->setReadOnly(true);
- QFont font(toqstr(theApp()->typewriterFontName()));
+ QFont font(guiApp->typewriterFontName());
font.setKerning(false);
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
QFont font;
font.setKerning(false);
- if (family == theApp()->romanFontName()) {
+ QString const font_family = toqstr(family);
+ if (font_family == guiApp->romanFontName()) {
font.setStyleHint(QFont::Serif);
- font.setFamily(family.c_str());
- } else if (family == theApp()->sansFontName()) {
+ font.setFamily(font_family);
+ } else if (font_family == guiApp->sansFontName()) {
font.setStyleHint(QFont::SansSerif);
- font.setFamily(family.c_str());
- } else if (family == theApp()->typewriterFontName()) {
+ font.setFamily(font_family);
+ } else if (font_family == guiApp->typewriterFontName()) {
font.setStyleHint(QFont::TypeWriter);
- font.setFamily(family.c_str());
+ font.setFamily(font_family);
} else {
lyxerr << "FAILED to find the default font: '"
<< foundry << "', '" << family << '\''<< endl;
#include <config.h>
+#include "GuiApplication.h"
#include "GuiViewSource.h"
#include "LaTeXHighlighter.h"
#include "qt_helpers.h"
-#include "Application.h"
#include "BufferView.h"
#include "Buffer.h"
#include "Cursor.h"
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(guiApp->typewriterFontName());
font.setKerning(false);
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
// 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_ != guiApp->currentView()) {
// FIXME: it would be nice to optimize for the off-screen case.
buffer_view_->updateMetrics();
buffer_view_->cursor().fixIfBroken();
support::FileFilterList const & filters,
FileDialog::Button const & b1,
FileDialog::Button const & b2)
- // FIXME replace that with theApp->gui()->currentView()
+ // FIXME replace that with guiApp->currentView()
: QFileDialog(qApp->focusWidget(),
toqstr(t), toqstr(p), toqstr(filters.as_string()))
{