2 * \file GuiApplication.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "GuiApplication.h"
17 #include "ColorCache.h"
18 #include "GuiClipboard.h"
20 #include "GuiKeySymbol.h"
21 #include "GuiSelection.h"
24 #include "qt_helpers.h"
26 #include "frontends/alert.h"
27 #include "frontends/Application.h"
28 #include "frontends/FontLoader.h"
29 #include "frontends/FontMetrics.h"
32 #include "BufferList.h"
33 #include "BufferView.h"
36 #include "FuncRequest.h"
37 #include "FuncStatus.h"
45 #include "support/lassert.h"
46 #include "support/debug.h"
47 #include "support/ExceptionMessage.h"
48 #include "support/FileName.h"
49 #include "support/foreach.h"
50 #include "support/ForkedCalls.h"
51 #include "support/gettext.h"
52 #include "support/lstrings.h"
53 #include "support/os.h"
54 #include "support/Package.h"
57 #include "support/linkback/LinkBackProxy.h"
62 #include <QFileOpenEvent>
65 #include <QLibraryInfo>
66 #include <QMacPasteboardMime>
69 #include <QPixmapCache>
71 #include <QSessionManager>
72 #include <QSocketNotifier>
73 #include <QSortFilterProxyModel>
74 #include <QStandardItemModel>
77 #include <QTranslator>
81 #include <X11/Xatom.h>
89 #include <QWindowsMime>
90 #if defined(Q_CYGWIN_WIN) || defined(Q_CC_MINGW)
96 #include <boost/bind.hpp>
101 using namespace lyx::support;
103 // FIXME: These strings are also used in GuiClipboard.cpp.
104 static char const * const lyx_mime_type = "application/x-lyx";
105 static char const * const pdf_mime_type = "application/pdf";
106 static char const * const emf_mime_type = "image/x-emf";
107 static char const * const wmf_mime_type = "image/x-wmf";
111 frontend::Application * createApplication(int & argc, char * argv[])
113 return new frontend::GuiApplication(argc, argv);
119 class SocketNotifier : public QSocketNotifier
122 /// connect a connection notification from the LyXServerSocket
123 SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
124 : QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
128 /// The callback function
129 Application::SocketCallback func_;
133 ////////////////////////////////////////////////////////////////////////
134 // Mac specific stuff goes here...
136 class MenuTranslator : public QTranslator
139 MenuTranslator(QObject * parent)
140 : QTranslator(parent)
143 QString translate(const char * /*context*/,
144 const char * sourceText,
145 const char * /*comment*/ = 0)
147 string const s = sourceText;
148 if (s == N_("About %1") || s == N_("Preferences")
149 || s == N_("Reconfigure") || s == N_("Quit %1"))
156 class GlobalMenuBar : public QMenuBar
160 GlobalMenuBar() : QMenuBar(0) {}
163 bool event(QEvent * e)
165 if (e->type() == QEvent::ShortcutOverride) {
166 // && activeWindow() == 0) {
167 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
169 setKeySymbol(&sym, ke);
170 theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
179 // QMacPasteboardMimeGraphics can only be compiled on Mac.
181 class QMacPasteboardMimeGraphics : public QMacPasteboardMime
184 QMacPasteboardMimeGraphics()
185 : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL)
188 QString convertorName() { return "Graphics"; }
190 QString flavorFor(QString const & mime)
192 LYXERR(Debug::ACTION, "flavorFor " << mime);
193 if (mime == QLatin1String(pdf_mime_type))
194 return QLatin1String("com.adobe.pdf");
198 QString mimeFor(QString flav)
200 LYXERR(Debug::ACTION, "mimeFor " << flav);
201 if (flav == QLatin1String("com.adobe.pdf"))
202 return QLatin1String(pdf_mime_type);
206 bool canConvert(QString const & mime, QString flav)
207 { return mimeFor(flav) == mime; }
209 QVariant convertToMime(QString const & mime, QList<QByteArray> data, QString flav)
212 qWarning("QMacPasteboardMimeGraphics: Cannot handle multiple member data");
216 QList<QByteArray> convertFromMime(QString const & mime, QVariant data, QString flav)
218 QList<QByteArray> ret;
219 ret.append(data.toByteArray());
225 ///////////////////////////////////////////////////////////////
226 // You can find more platform specific stuff
227 // at the end of this file...
228 ///////////////////////////////////////////////////////////////
230 ////////////////////////////////////////////////////////////////////////
231 // Windows specific stuff goes here...
234 // QWindowsMimeMetafile can only be compiled on Windows.
236 static FORMATETC cfFromMime(QString const & mimetype)
239 if (mimetype == emf_mime_type) {
240 formatetc.cfFormat = CF_ENHMETAFILE;
241 formatetc.tymed = TYMED_ENHMF;
242 } else if (mimetype == wmf_mime_type) {
243 formatetc.cfFormat = CF_METAFILEPICT;
244 formatetc.tymed = TYMED_MFPICT;
247 formatetc.dwAspect = DVASPECT_CONTENT;
248 formatetc.lindex = -1;
253 class QWindowsMimeMetafile : public QWindowsMime {
255 QWindowsMimeMetafile() {}
257 bool canConvertFromMime(FORMATETC const & formatetc,
258 QMimeData const * mimedata) const
263 bool canConvertToMime(QString const & mimetype,
264 IDataObject * pDataObj) const
266 if (mimetype != emf_mime_type && mimetype != wmf_mime_type)
268 FORMATETC formatetc = cfFromMime(mimetype);
269 return pDataObj->QueryGetData(&formatetc) == S_OK;
272 bool convertFromMime(FORMATETC const & formatetc,
273 const QMimeData * mimedata, STGMEDIUM * pmedium) const
278 QVariant convertToMime(QString const & mimetype, IDataObject * pDataObj,
279 QVariant::Type preferredType) const
282 if (!canConvertToMime(mimetype, pDataObj))
285 FORMATETC formatetc = cfFromMime(mimetype);
287 if (pDataObj->GetData(&formatetc, &s) != S_OK)
291 if (s.tymed == TYMED_ENHMF) {
292 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, 0, 0);
293 data.resize(dataSize);
294 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, dataSize,
295 (LPBYTE)data.data());
296 } else if (s.tymed == TYMED_MFPICT) {
297 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, 0, 0);
298 data.resize(dataSize);
299 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, dataSize,
300 (LPBYTE)data.data());
303 ReleaseStgMedium(&s);
309 QVector<FORMATETC> formatsForMime(QString const & mimeType,
310 QMimeData const * mimeData) const
312 QVector<FORMATETC> formats;
313 formats += cfFromMime(mimeType);
317 QString mimeForFormat(FORMATETC const & formatetc) const
319 switch (formatetc.cfFormat) {
321 return emf_mime_type;
322 case CF_METAFILEPICT:
323 return wmf_mime_type;
331 ////////////////////////////////////////////////////////////////////////
332 // GuiApplication::Private definition and implementation.
333 ////////////////////////////////////////////////////////////////////////
335 struct GuiApplication::Private
338 : language_model_(0), global_menubar_(0)
341 // Create the global default menubar which is shown for the dialogs
342 // and if no GuiView is visible.
343 global_menubar_ = new GlobalMenuBar();
348 QSortFilterProxyModel * language_model_;
350 GuiClipboard clipboard_;
352 GuiSelection selection_;
354 FontLoader font_loader_;
356 ColorCache color_cache_;
358 QTranslator qt_trans_;
360 QHash<int, SocketNotifier *> socket_notifiers_;
363 /// this timer is used for any regular events one wants to
364 /// perform. at present it is used to check if forked processes
366 QTimer general_timer_;
368 /// Multiple views container.
370 * Warning: This must not be a smart pointer as the destruction of the
371 * object is handled by Qt when the view is closed
372 * \sa Qt::WA_DeleteOnClose attribute.
374 QHash<int, GuiView *> views_;
376 /// Only used on mac.
377 GlobalMenuBar * global_menubar_;
380 /// Linkback mime handler for MacOSX.
381 QMacPasteboardMimeGraphics mac_pasteboard_mime_;
385 /// WMF Mime handler for Windows clipboard.
386 // FIXME for Windows Vista and Qt4 (see http://bugzilla.lyx.org/show_bug.cgi?id=4846)
387 // But this makes LyX crash on exit when LyX is compiled in release mode and if there
388 // is something in the clipboard.
389 QWindowsMimeMetafile wmf_mime_;
394 GuiApplication * guiApp;
396 GuiApplication::~GuiApplication()
399 closeAllLinkBackLinks();
405 GuiApplication::GuiApplication(int & argc, char ** argv)
406 : QApplication(argc, argv), current_view_(0), d(new GuiApplication::Private)
408 QString app_name = "LyX";
409 QCoreApplication::setOrganizationName(app_name);
410 QCoreApplication::setOrganizationDomain("lyx.org");
411 QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
413 // FIXME: quitOnLastWindowClosed is true by default. We should have a
414 // lyxrc setting for this in order to let the application stay resident.
415 // But then we need some kind of dock icon, at least on Windows.
417 if (lyxrc.quit_on_last_window_closed)
418 setQuitOnLastWindowClosed(false);
421 // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
422 // seems to be the default case for applications like LyX.
423 setQuitOnLastWindowClosed(false);
427 // doubleClickInterval() is 400 ms on X11 which is just too long.
428 // On Windows and Mac OS X, the operating system's value is used.
429 // On Microsoft Windows, calling this function sets the double
430 // click interval for all applications. So we don't!
431 QApplication::setDoubleClickInterval(300);
434 // install translation file for Qt built-in dialogs
435 QString language_name = QString("qt_") + QLocale::system().name();
437 // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
438 // Short-named translator can be loaded from a long name, but not the
439 // opposite. Therefore, long name should be used without truncation.
440 // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
441 if (d->qt_trans_.load(language_name,
442 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
444 installTranslator(&d->qt_trans_);
445 // even if the language calls for RtL, don't do that
446 setLayoutDirection(Qt::LeftToRight);
447 LYXERR(Debug::GUI, "Successfully installed Qt translations for locale "
450 LYXERR(Debug::GUI, "Could not find Qt translations for locale "
454 // This allows to translate the strings that appear in the LyX menu.
455 /// A translator suitable for the entries in the LyX menu.
456 /// Only needed with Qt/Mac.
457 installTranslator(new MenuTranslator(this));
459 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
461 using namespace lyx::graphics;
463 Image::newImage = boost::bind(&GuiImage::newImage);
464 Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
466 // needs to be done before reading lyxrc
468 lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
472 // Set the cache to 5120 kilobytes which corresponds to screen size of
473 // 1280 by 1024 pixels with a color depth of 32 bits.
474 QPixmapCache::setCacheLimit(5120);
476 // Initialize RC Fonts
477 if (lyxrc.roman_font_name.empty())
478 lyxrc.roman_font_name = fromqstr(romanFontName());
480 if (lyxrc.sans_font_name.empty())
481 lyxrc.sans_font_name = fromqstr(sansFontName());
483 if (lyxrc.typewriter_font_name.empty())
484 lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
486 d->general_timer_.setInterval(500);
487 connect(&d->general_timer_, SIGNAL(timeout()),
488 this, SLOT(handleRegularEvents()));
489 d->general_timer_.start();
493 bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
499 case LFUN_WINDOW_CLOSE:
500 enable = d->views_.size() > 0;
503 case LFUN_BUFFER_NEW:
504 case LFUN_BUFFER_NEW_TEMPLATE:
506 case LFUN_SCREEN_FONT_UPDATE:
508 case LFUN_WINDOW_NEW:
524 bool GuiApplication::dispatch(FuncRequest const & cmd)
526 switch (cmd.action) {
528 case LFUN_WINDOW_NEW:
529 createView(toqstr(cmd.argument()));
532 case LFUN_WINDOW_CLOSE:
533 // update bookmark pit of the current buffer before window close
534 for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
535 theLyXFunc().gotoBookmark(i+1, false, false);
536 current_view_->close();
540 // quitting is triggered by the gui code
541 // (leaving the event loop).
543 current_view_->message(from_utf8(N_("Exiting.")));
548 case LFUN_SCREEN_FONT_UPDATE: {
549 // handle the screen font changes.
550 d->font_loader_.update();
551 // Backup current_view_
552 GuiView * view = current_view_;
553 // Set current_view_ to zero to forbid GuiWorkArea::redraw()
554 // to skip the refresh.
556 BufferList::iterator it = theBufferList().begin();
557 BufferList::iterator const end = theBufferList().end();
558 for (; it != end; ++it)
560 // Restore current_view_
561 current_view_ = view;
565 case LFUN_BUFFER_NEW:
566 if (d->views_.empty()
567 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
568 createView(QString(), false); // keep hidden
569 current_view_->newDocument(to_utf8(cmd.argument()), false);
570 current_view_->show();
571 setActiveWindow(current_view_);
573 current_view_->newDocument(to_utf8(cmd.argument()), false);
577 case LFUN_BUFFER_NEW_TEMPLATE:
578 if (d->views_.empty()
579 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
581 current_view_->newDocument(to_utf8(cmd.argument()), true);
582 if (!current_view_->buffer())
583 current_view_->close();
585 current_view_->newDocument(to_utf8(cmd.argument()), true);
590 if (d->views_.empty()
591 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
593 current_view_->openDocument(to_utf8(cmd.argument()));
594 if (!current_view_->buffer())
595 current_view_->close();
597 current_view_->openDocument(to_utf8(cmd.argument()));
600 case LFUN_SET_COLOR: {
602 string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' ');
603 if (lyx_name.empty() || x11_name.empty()) {
604 current_view_->message(
605 _("Syntax: set-color <lyx_name> <x11_name>"));
609 string const graphicsbg = lcolor.getLyXName(Color_graphicsbg);
610 bool const graphicsbg_changed = lyx_name == graphicsbg
611 && x11_name != graphicsbg;
612 if (graphicsbg_changed) {
613 // FIXME: The graphics cache no longer has a changeDisplay method.
615 graphics::GCache::get().changeDisplay(true);
619 if (!lcolor.setColor(lyx_name, x11_name)) {
620 current_view_->message(
621 bformat(_("Set-color \"%1$s\" failed "
622 "- color is undefined or "
623 "may not be redefined"),
624 from_utf8(lyx_name)));
627 // Make sure we don't keep old colors in cache.
628 d->color_cache_.clear();
633 // Notify the caller that the action has not been dispatched.
637 // The action has been dispatched.
642 void GuiApplication::resetGui()
644 QHash<int, GuiView *>::iterator it;
645 for (it = d->views_.begin(); it != d->views_.end(); ++it)
646 (*it)->resetDialogs();
648 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
652 void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
654 // release the keyboard which might have been grabed by the global
655 // menubar on Mac to catch shortcuts even without any GuiView.
656 if (d->global_menubar_)
657 d->global_menubar_->releaseKeyboard();
661 while (d->views_.find(id) != d->views_.end())
663 GuiView * view = new GuiView(id);
665 // copy the icon size from old view
667 view->setIconSize(current_view_->iconSize());
670 d->views_[id] = view;
674 setActiveWindow(view);
677 if (!geometry_arg.isEmpty()) {
681 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
682 re.indexIn(geometry_arg);
683 w = re.cap(1).toInt();
684 h = re.cap(2).toInt();
685 x = re.cap(3).toInt();
686 y = re.cap(4).toInt();
687 view->setGeometry(x, y, w, h);
691 setCurrentView(view);
695 Clipboard & GuiApplication::clipboard()
697 return d->clipboard_;
701 Selection & GuiApplication::selection()
703 return d->selection_;
707 FontLoader & GuiApplication::fontLoader()
709 return d->font_loader_;
713 Menus const & GuiApplication::menus() const
719 Menus & GuiApplication::menus()
725 QList<int> GuiApplication::viewIds() const
727 return d->views_.keys();
731 ColorCache & GuiApplication::colorCache()
733 return d->color_cache_;
737 int GuiApplication::exec()
739 QTimer::singleShot(1, this, SLOT(execBatchCommands()));
740 return QApplication::exec();
744 void GuiApplication::exit(int status)
746 QApplication::exit(status);
750 void GuiApplication::execBatchCommands()
752 // init the global menubar on Mac. This must be done after the session
753 // was recovered to know the "last files".
754 if (d->global_menubar_)
755 d->menus_.fillMenuBar(d->global_menubar_, 0, true);
757 LyX::ref().execBatchCommands();
760 QAbstractItemModel * GuiApplication::languageModel()
762 if (d->language_model_)
763 return d->language_model_;
765 QStandardItemModel * lang_model = new QStandardItemModel(this);
766 lang_model->insertColumns(0, 1);
768 Languages::const_iterator it = languages.begin();
769 Languages::const_iterator end = languages.end();
770 for (; it != end; ++it) {
771 current_row = lang_model->rowCount();
772 lang_model->insertRows(current_row, 1);
773 QModelIndex item = lang_model->index(current_row, 0);
774 lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
775 lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
777 d->language_model_ = new QSortFilterProxyModel(this);
778 d->language_model_->setSourceModel(lang_model);
779 #if QT_VERSION >= 0x040300
780 d->language_model_->setSortLocaleAware(true);
782 return d->language_model_;
786 void GuiApplication::restoreGuiSession()
788 if (!lyxrc.load_session)
791 Session & session = LyX::ref().session();
792 vector<FileName> const & lastopened = session.lastOpened().getfiles();
793 // do not add to the lastfile list since these files are restored from
794 // last session, and should be already there (regular files), or should
795 // not be added at all (help files).
796 for_each(lastopened.begin(), lastopened.end(),
797 bind(&GuiView::loadDocument, current_view_, _1, false));
799 // clear this list to save a few bytes of RAM
800 session.lastOpened().clear();
804 QString const GuiApplication::romanFontName()
807 font.setKerning(false);
808 font.setStyleHint(QFont::Serif);
809 font.setFamily("serif");
811 return QFontInfo(font).family();
815 QString const GuiApplication::sansFontName()
818 font.setKerning(false);
819 font.setStyleHint(QFont::SansSerif);
820 font.setFamily("sans");
822 return QFontInfo(font).family();
826 QString const GuiApplication::typewriterFontName()
829 font.setKerning(false);
830 font.setStyleHint(QFont::TypeWriter);
831 font.setFamily("monospace");
833 return QFontInfo(font).family();
837 void GuiApplication::handleRegularEvents()
839 ForkedCallsController::handleCompletedProcesses();
843 bool GuiApplication::event(QEvent * e)
846 case QEvent::FileOpen: {
847 // Open a file; this happens only on Mac OS X for now
848 QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
850 if (!current_view_ || !current_view_->view())
851 // The application is not properly initialized yet.
852 // So we acknowledge the event and delay the file opening
853 // until LyX is ready.
854 // FIXME UNICODE: FileName accept an utf8 encoded string.
855 LyX::ref().addFileToLoad(fromqstr(foe->file()));
857 lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
858 qstring_to_ucs4(foe->file())));
864 return QApplication::event(e);
869 bool GuiApplication::notify(QObject * receiver, QEvent * event)
872 return QApplication::notify(receiver, event);
874 catch (ExceptionMessage const & e) {
877 LyX::cref().emergencyCleanup();
878 setQuitOnLastWindowClosed(false);
880 Alert::error(e.title_, e.details_);
882 // Properly crash in debug mode in order to get a useful backtrace.
885 // In release mode, try to exit gracefully.
888 case BufferException: {
889 Buffer * buf = current_view_->buffer();
890 docstring details = e.details_ + '\n';
891 details += theBufferList().emergencyWrite(buf);
892 theBufferList().release(buf);
893 details += "\n" + _("The current document was closed.");
894 Alert::error(e.title_, details);
897 case WarningException:
898 Alert::warning(e.title_, e.details_);
902 catch (exception const & e) {
903 docstring s = _("LyX has caught an exception, it will now "
904 "attempt to save all unsaved documents and exit."
906 s += from_ascii(e.what());
907 Alert::error(_("Software exception Detected"), s);
911 docstring s = _("LyX has caught some really weird exception, it will "
912 "now attempt to save all unsaved documents and exit.");
913 Alert::error(_("Software exception Detected"), s);
921 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
923 QColor const & qcol = d->color_cache_.get(col);
924 if (!qcol.isValid()) {
930 rgbcol.r = qcol.red();
931 rgbcol.g = qcol.green();
932 rgbcol.b = qcol.blue();
937 string const GuiApplication::hexName(ColorCode col)
939 return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
943 void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
945 SocketNotifier * sn = new SocketNotifier(this, fd, func);
946 d->socket_notifiers_[fd] = sn;
947 connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
951 void GuiApplication::socketDataReceived(int fd)
953 d->socket_notifiers_[fd]->func_();
957 void GuiApplication::unregisterSocketCallback(int fd)
959 d->socket_notifiers_.take(fd)->setEnabled(false);
963 void GuiApplication::commitData(QSessionManager & sm)
965 /// The implementation is required to avoid an application exit
966 /// when session state save is triggered by session manager.
967 /// The default implementation sends a close event to all
968 /// visible top level widgets when session managment allows
970 /// We are changing that to close all wiew one by one.
971 /// FIXME: verify if the default implementation is enough now.
972 if (sm.allowsInteraction() && !closeAllViews())
977 void GuiApplication::unregisterView(GuiView * gv)
979 LASSERT(d->views_[gv->id()] == gv, /**/);
980 d->views_.remove(gv->id());
981 if (current_view_ == gv) {
983 theLyXFunc().setLyXView(0);
988 bool GuiApplication::closeAllViews()
990 if (d->views_.empty())
993 QList<GuiView *> views = d->views_.values();
994 foreach (GuiView * view, views) {
1004 GuiView & GuiApplication::view(int id) const
1006 LASSERT(d->views_.contains(id), /**/);
1007 return *d->views_.value(id);
1011 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
1013 QList<GuiView *> views = d->views_.values();
1014 foreach (GuiView * view, views)
1015 view->hideDialog(name, inset);
1019 Buffer const * GuiApplication::updateInset(Inset const * inset) const
1021 Buffer const * buffer_ = 0;
1022 QHash<int, GuiView *>::iterator end = d->views_.end();
1023 for (QHash<int, GuiView *>::iterator it = d->views_.begin(); it != end; ++it) {
1024 if (Buffer const * ptr = (*it)->updateInset(inset))
1031 void GuiApplication::readMenus(Lexer & lex)
1037 bool GuiApplication::searchMenu(FuncRequest const & func,
1038 vector<docstring> & names) const
1040 return menus().searchMenu(func, names);
1044 void GuiApplication::onLastWindowClosed()
1046 if (d->global_menubar_)
1047 d->global_menubar_->grabKeyboard();
1051 ////////////////////////////////////////////////////////////////////////
1053 // X11 specific stuff goes here...
1056 bool GuiApplication::x11EventFilter(XEvent * xev)
1061 switch (xev->type) {
1062 case SelectionRequest: {
1063 if (xev->xselectionrequest.selection != XA_PRIMARY)
1065 LYXERR(Debug::GUI, "X requested selection.");
1066 BufferView * bv = current_view_->view();
1068 docstring const sel = bv->requestSelection();
1070 d->selection_.put(sel);
1074 case SelectionClear: {
1075 if (xev->xselectionclear.selection != XA_PRIMARY)
1077 LYXERR(Debug::GUI, "Lost selection.");
1078 BufferView * bv = current_view_->view();
1080 bv->clearSelection();
1088 } // namespace frontend
1091 void hideDialogs(std::string const & name, Inset * inset)
1094 theApp()->hideDialogs(name, inset);
1098 ////////////////////////////////////////////////////////////////////
1102 ////////////////////////////////////////////////////////////////////
1104 frontend::FontLoader & theFontLoader()
1106 LASSERT(frontend::guiApp, /**/);
1107 return frontend::guiApp->fontLoader();
1111 frontend::FontMetrics const & theFontMetrics(Font const & f)
1113 return theFontMetrics(f.fontInfo());
1117 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
1119 LASSERT(frontend::guiApp, /**/);
1120 return frontend::guiApp->fontLoader().metrics(f);
1124 ////////////////////////////////////////////////////////////////////
1128 ////////////////////////////////////////////////////////////////////
1130 frontend::Clipboard & theClipboard()
1132 LASSERT(frontend::guiApp, /**/);
1133 return frontend::guiApp->clipboard();
1137 frontend::Selection & theSelection()
1139 LASSERT(frontend::guiApp, /**/);
1140 return frontend::guiApp->selection();
1145 #include "GuiApplication_moc.cpp"