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"
35 #include "FuncRequest.h"
36 #include "FuncStatus.h"
44 #include "support/lassert.h"
45 #include "support/debug.h"
46 #include "support/ExceptionMessage.h"
47 #include "support/FileName.h"
48 #include "support/ForkedCalls.h"
49 #include "support/gettext.h"
50 #include "support/lstrings.h"
51 #include "support/os.h"
52 #include "support/Package.h"
55 #include "support/linkback/LinkBackProxy.h"
60 #include <QFileOpenEvent>
62 #include <QLibraryInfo>
63 #include <QMacPasteboardMime>
66 #include <QPixmapCache>
68 #include <QSessionManager>
69 #include <QSocketNotifier>
70 #include <QSortFilterProxyModel>
71 #include <QStandardItemModel>
74 #include <QTranslator>
78 #include <X11/Xatom.h>
86 #include <QWindowsMime>
87 #if defined(Q_CYGWIN_WIN) || defined(Q_CC_MINGW)
93 #include <boost/bind.hpp>
99 using namespace lyx::support;
101 // FIXME: These strings are also used in GuiClipboard.cpp.
102 static char const * const lyx_mime_type = "application/x-lyx";
103 static char const * const pdf_mime_type = "application/pdf";
104 static char const * const emf_mime_type = "image/x-emf";
105 static char const * const wmf_mime_type = "image/x-wmf";
109 frontend::Application * createApplication(int & argc, char * argv[])
111 return new frontend::GuiApplication(argc, argv);
117 class SocketNotifier : public QSocketNotifier
120 /// connect a connection notification from the LyXServerSocket
121 SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
122 : QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
126 /// The callback function
127 Application::SocketCallback func_;
131 ////////////////////////////////////////////////////////////////////////
132 // Mac specific stuff goes here...
134 class MenuTranslator : public QTranslator
137 MenuTranslator(QObject * parent)
138 : QTranslator(parent)
141 QString translate(const char * /*context*/,
142 const char * sourceText,
143 const char * /*comment*/ = 0)
145 string const s = sourceText;
146 if (s == N_("About %1") || s == N_("Preferences")
147 || s == N_("Reconfigure") || s == N_("Quit %1"))
154 class GlobalMenuBar : public QMenuBar
158 GlobalMenuBar() : QMenuBar(0) {}
161 bool event(QEvent * e)
163 if (e->type() == QEvent::ShortcutOverride) {
164 // && activeWindow() == 0) {
165 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
167 setKeySymbol(&sym, ke);
168 theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
177 // QMacPasteboardMimeGraphics can only be compiled on Mac.
179 class QMacPasteboardMimeGraphics : public QMacPasteboardMime
182 QMacPasteboardMimeGraphics()
183 : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL)
186 QString convertorName() { return "Graphics"; }
188 QString flavorFor(QString const & mime)
190 LYXERR(Debug::ACTION, "flavorFor " << mime);
191 if (mime == QLatin1String(pdf_mime_type))
192 return QLatin1String("com.adobe.pdf");
196 QString mimeFor(QString flav)
198 LYXERR(Debug::ACTION, "mimeFor " << flav);
199 if (flav == QLatin1String("com.adobe.pdf"))
200 return QLatin1String(pdf_mime_type);
204 bool canConvert(QString const & mime, QString flav)
205 { return mimeFor(flav) == mime; }
207 QVariant convertToMime(QString const & mime, QList<QByteArray> data, QString flav)
210 qWarning("QMacPasteboardMimeGraphics: Cannot handle multiple member data");
214 QList<QByteArray> convertFromMime(QString const & mime, QVariant data, QString flav)
216 QList<QByteArray> ret;
217 ret.append(data.toByteArray());
223 ///////////////////////////////////////////////////////////////
224 // You can find more platform specific stuff
225 // at the end of this file...
226 ///////////////////////////////////////////////////////////////
228 ////////////////////////////////////////////////////////////////////////
229 // Windows specific stuff goes here...
232 // QWindowsMimeMetafile can only be compiled on Windows.
234 static FORMATETC cfFromMime(QString const & mimetype)
237 if (mimetype == emf_mime_type) {
238 formatetc.cfFormat = CF_ENHMETAFILE;
239 formatetc.tymed = TYMED_ENHMF;
240 } else if (mimetype == wmf_mime_type) {
241 formatetc.cfFormat = CF_METAFILEPICT;
242 formatetc.tymed = TYMED_MFPICT;
245 formatetc.dwAspect = DVASPECT_CONTENT;
246 formatetc.lindex = -1;
251 class QWindowsMimeMetafile : public QWindowsMime {
253 QWindowsMimeMetafile() {}
255 bool canConvertFromMime(FORMATETC const & formatetc,
256 QMimeData const * mimedata) const
261 bool canConvertToMime(QString const & mimetype,
262 IDataObject * pDataObj) const
264 if (mimetype != emf_mime_type && mimetype != wmf_mime_type)
266 FORMATETC formatetc = cfFromMime(mimetype);
267 return pDataObj->QueryGetData(&formatetc) == S_OK;
270 bool convertFromMime(FORMATETC const & formatetc,
271 const QMimeData * mimedata, STGMEDIUM * pmedium) const
276 QVariant convertToMime(QString const & mimetype, IDataObject * pDataObj,
277 QVariant::Type preferredType) const
280 if (!canConvertToMime(mimetype, pDataObj))
283 FORMATETC formatetc = cfFromMime(mimetype);
285 if (pDataObj->GetData(&formatetc, &s) != S_OK)
289 if (s.tymed == TYMED_ENHMF) {
290 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, 0, 0);
291 data.resize(dataSize);
292 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, dataSize,
293 (LPBYTE)data.data());
294 } else if (s.tymed == TYMED_MFPICT) {
295 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, 0, 0);
296 data.resize(dataSize);
297 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, dataSize,
298 (LPBYTE)data.data());
301 ReleaseStgMedium(&s);
307 QVector<FORMATETC> formatsForMime(QString const & mimeType,
308 QMimeData const * mimeData) const
310 QVector<FORMATETC> formats;
311 formats += cfFromMime(mimeType);
315 QString mimeForFormat(FORMATETC const & formatetc) const
317 switch (formatetc.cfFormat) {
319 return emf_mime_type;
320 case CF_METAFILEPICT:
321 return wmf_mime_type;
329 ////////////////////////////////////////////////////////////////////////
330 // GuiApplication::Private definition and implementation.
331 ////////////////////////////////////////////////////////////////////////
333 struct GuiApplication::Private
335 Private(): language_model_(0), global_menubar_(0)
338 // Create the global default menubar which is shown for the dialogs
339 // and if no GuiView is visible.
340 global_menubar_ = new GlobalMenuBar();
345 QSortFilterProxyModel * language_model_;
347 GuiClipboard clipboard_;
349 GuiSelection selection_;
351 FontLoader font_loader_;
353 ColorCache color_cache_;
355 QTranslator qt_trans_;
357 std::map<int, SocketNotifier *> socket_notifiers_;
360 /// this timer is used for any regular events one wants to
361 /// perform. at present it is used to check if forked processes
363 QTimer general_timer_;
365 /// Multiple views container.
367 * Warning: This must not be a smart pointer as the destruction of the
368 * object is handled by Qt when the view is closed
369 * \sa Qt::WA_DeleteOnClose attribute.
371 std::map<int, GuiView *> views_;
373 std::vector<int> view_ids_;
375 /// Only used on mac.
376 GlobalMenuBar * global_menubar_;
379 /// Linkback mime handler for MacOSX.
380 QMacPasteboardMimeGraphics mac_pasteboard_mime_;
384 /// WMF Mime handler for Windows clipboard.
385 // FIXME for Windows Vista and Qt4 (see http://bugzilla.lyx.org/show_bug.cgi?id=4846)
386 // But this makes LyX crash on exit when LyX is compiled in release mode and if there
387 // is something in the clipboard.
388 QWindowsMimeMetafile wmf_mime_;
393 GuiApplication * guiApp;
395 GuiApplication::~GuiApplication()
398 closeAllLinkBackLinks();
404 GuiApplication::GuiApplication(int & argc, char ** argv)
405 : QApplication(argc, argv), current_view_(0), d(new GuiApplication::Private)
407 QString app_name = "LyX";
408 QCoreApplication::setOrganizationName(app_name);
409 QCoreApplication::setOrganizationDomain("lyx.org");
410 QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
412 // FIXME: quitOnLastWindowClosed is true by default. We should have a
413 // lyxrc setting for this in order to let the application stay resident.
414 // But then we need some kind of dock icon, at least on Windows.
416 if (lyxrc.quit_on_last_window_closed)
417 setQuitOnLastWindowClosed(false);
420 // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
421 // seems to be the default case for applications like LyX.
422 setQuitOnLastWindowClosed(false);
426 // doubleClickInterval() is 400 ms on X11 which is just too long.
427 // On Windows and Mac OS X, the operating system's value is used.
428 // On Microsoft Windows, calling this function sets the double
429 // click interval for all applications. So we don't!
430 QApplication::setDoubleClickInterval(300);
433 // install translation file for Qt built-in dialogs
434 QString language_name = QString("qt_") + QLocale::system().name();
436 // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
437 // Short-named translator can be loaded from a long name, but not the
438 // opposite. Therefore, long name should be used without truncation.
439 // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
440 if (d->qt_trans_.load(language_name,
441 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
443 installTranslator(&d->qt_trans_);
444 // even if the language calls for RtL, don't do that
445 setLayoutDirection(Qt::LeftToRight);
446 LYXERR(Debug::GUI, "Successfully installed Qt translations for locale "
449 LYXERR(Debug::GUI, "Could not find Qt translations for locale "
453 // This allows to translate the strings that appear in the LyX menu.
454 /// A translator suitable for the entries in the LyX menu.
455 /// Only needed with Qt/Mac.
456 installTranslator(new MenuTranslator(this));
458 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
460 using namespace lyx::graphics;
462 Image::newImage = boost::bind(&GuiImage::newImage);
463 Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
465 // needs to be done before reading lyxrc
467 lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
471 // Set the cache to 5120 kilobytes which corresponds to screen size of
472 // 1280 by 1024 pixels with a color depth of 32 bits.
473 QPixmapCache::setCacheLimit(5120);
475 // Initialize RC Fonts
476 if (lyxrc.roman_font_name.empty())
477 lyxrc.roman_font_name = fromqstr(romanFontName());
479 if (lyxrc.sans_font_name.empty())
480 lyxrc.sans_font_name = fromqstr(sansFontName());
482 if (lyxrc.typewriter_font_name.empty())
483 lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
485 d->general_timer_.setInterval(500);
486 connect(&d->general_timer_, SIGNAL(timeout()),
487 this, SLOT(handleRegularEvents()));
488 d->general_timer_.start();
492 FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
499 case LFUN_WINDOW_CLOSE:
500 enable = d->view_ids_.size() > 0;
504 if (!current_view_) {
517 bool GuiApplication::dispatch(FuncRequest const & cmd)
521 case LFUN_WINDOW_NEW:
522 createView(toqstr(cmd.argument()));
525 case LFUN_WINDOW_CLOSE:
526 // update bookmark pit of the current buffer before window close
527 for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
528 theLyXFunc().gotoBookmark(i+1, false, false);
529 current_view_->close();
533 // quitting is triggered by the gui code
534 // (leaving the event loop).
536 current_view_->message(from_utf8(N_("Exiting.")));
541 case LFUN_SCREEN_FONT_UPDATE: {
542 // handle the screen font changes.
543 d->font_loader_.update();
544 // Backup current_view_
545 GuiView * view = current_view_;
546 // Set current_view_ to zero to forbid GuiWorkArea::redraw()
547 // to skip the refresh.
549 BufferList::iterator it = theBufferList().begin();
550 BufferList::iterator const end = theBufferList().end();
551 for (; it != end; ++it)
553 // Restore current_view_
554 current_view_ = view;
558 case LFUN_BUFFER_NEW:
560 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
561 createView(QString(), false); // keep hidden
562 current_view_->newDocument(to_utf8(cmd.argument()), false);
563 current_view_->show();
564 setActiveWindow(current_view_);
566 current_view_->newDocument(to_utf8(cmd.argument()), false);
569 case LFUN_BUFFER_NEW_TEMPLATE:
571 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
573 current_view_->newDocument(to_utf8(cmd.argument()), true);
574 if (!current_view_->buffer())
575 current_view_->close();
577 current_view_->newDocument(to_utf8(cmd.argument()), true);
582 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
584 current_view_->openDocument(to_utf8(cmd.argument()));
585 if (!current_view_->buffer())
586 current_view_->close();
588 current_view_->openDocument(to_utf8(cmd.argument()));
592 // Notify the caller that the action has not been dispatched.
596 // The action has been dispatched.
601 void GuiApplication::resetGui()
603 map<int, GuiView *>::iterator it;
604 for (it = d->views_.begin(); it != d->views_.end(); ++it)
605 it->second->resetDialogs();
607 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
611 static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
614 map<int, GuiView *>::const_iterator it;
615 for (it = stdmap.begin(); it != stdmap.end(); ++it)
616 ids.push_back(it->first);
620 void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
622 // release the keyboard which might have been grabed by the global
623 // menubar on Mac to catch shortcuts even without any GuiView.
624 if (d->global_menubar_)
625 d->global_menubar_->releaseKeyboard();
628 updateIds(d->views_, d->view_ids_);
630 while (d->views_.find(id) != d->views_.end())
632 GuiView * view = new GuiView(id);
634 // copy the icon size from old view
636 view->setIconSize(current_view_->iconSize());
639 d->views_[id] = view;
640 updateIds(d->views_, d->view_ids_);
644 setActiveWindow(view);
647 if (!geometry_arg.isEmpty()) {
651 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
652 re.indexIn(geometry_arg);
653 w = re.cap(1).toInt();
654 h = re.cap(2).toInt();
655 x = re.cap(3).toInt();
656 y = re.cap(4).toInt();
657 view->setGeometry(x, y, w, h);
661 setCurrentView(view);
665 Clipboard & GuiApplication::clipboard()
667 return d->clipboard_;
671 Selection & GuiApplication::selection()
673 return d->selection_;
677 FontLoader & GuiApplication::fontLoader()
679 return d->font_loader_;
683 Menus const & GuiApplication::menus() const
689 Menus & GuiApplication::menus()
695 size_t GuiApplication::viewCount() const
697 return d->view_ids_.size();
701 vector<int> const & GuiApplication::viewIds()
706 ColorCache & GuiApplication::colorCache()
708 return d->color_cache_;
712 int GuiApplication::exec()
714 QTimer::singleShot(1, this, SLOT(execBatchCommands()));
715 return QApplication::exec();
719 void GuiApplication::exit(int status)
721 QApplication::exit(status);
725 void GuiApplication::execBatchCommands()
727 LyX::ref().execBatchCommands();
730 QAbstractItemModel * GuiApplication::languageModel()
732 if (d->language_model_)
733 return d->language_model_;
735 QStandardItemModel * lang_model = new QStandardItemModel(this);
736 lang_model->insertColumns(0, 1);
738 Languages::const_iterator it = languages.begin();
739 Languages::const_iterator end = languages.end();
740 for (; it != end; ++it) {
741 current_row = lang_model->rowCount();
742 lang_model->insertRows(current_row, 1);
743 QModelIndex item = lang_model->index(current_row, 0);
744 lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
745 lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
747 d->language_model_ = new QSortFilterProxyModel(this);
748 d->language_model_->setSourceModel(lang_model);
749 #if QT_VERSION >= 0x040300
750 d->language_model_->setSortLocaleAware(true);
752 return d->language_model_;
756 void GuiApplication::restoreGuiSession()
758 if (!lyxrc.load_session)
761 Session & session = LyX::ref().session();
762 vector<FileName> const & lastopened = session.lastOpened().getfiles();
763 // do not add to the lastfile list since these files are restored from
764 // last session, and should be already there (regular files), or should
765 // not be added at all (help files).
766 for_each(lastopened.begin(), lastopened.end(),
767 bind(&GuiView::loadDocument, current_view_, _1, false));
769 // clear this list to save a few bytes of RAM
770 session.lastOpened().clear();
774 QString const GuiApplication::romanFontName()
777 font.setKerning(false);
778 font.setStyleHint(QFont::Serif);
779 font.setFamily("serif");
781 return QFontInfo(font).family();
785 QString const GuiApplication::sansFontName()
788 font.setKerning(false);
789 font.setStyleHint(QFont::SansSerif);
790 font.setFamily("sans");
792 return QFontInfo(font).family();
796 QString const GuiApplication::typewriterFontName()
799 font.setKerning(false);
800 font.setStyleHint(QFont::TypeWriter);
801 font.setFamily("monospace");
803 return QFontInfo(font).family();
807 void GuiApplication::handleRegularEvents()
809 ForkedCallsController::handleCompletedProcesses();
813 bool GuiApplication::event(QEvent * e)
816 case QEvent::FileOpen: {
817 // Open a file; this happens only on Mac OS X for now
818 QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
820 if (!current_view_ || !current_view_->view())
821 // The application is not properly initialized yet.
822 // So we acknowledge the event and delay the file opening
823 // until LyX is ready.
824 // FIXME UNICODE: FileName accept an utf8 encoded string.
825 LyX::ref().addFileToLoad(fromqstr(foe->file()));
827 lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
828 qstring_to_ucs4(foe->file())));
834 return QApplication::event(e);
839 bool GuiApplication::notify(QObject * receiver, QEvent * event)
842 return QApplication::notify(receiver, event);
844 catch (ExceptionMessage const & e) {
847 LyX::cref().emergencyCleanup();
848 setQuitOnLastWindowClosed(false);
850 Alert::error(e.title_, e.details_);
852 // Properly crash in debug mode in order to get a useful backtrace.
855 // In release mode, try to exit gracefully.
858 case BufferException: {
859 Buffer * buf = current_view_->buffer();
860 docstring details = e.details_ + '\n';
861 details += theBufferList().emergencyWrite(buf);
862 theBufferList().release(buf);
863 details += "\n" + _("The current document was closed.");
864 Alert::error(e.title_, details);
867 case WarningException:
868 Alert::warning(e.title_, e.details_);
872 catch (exception const & e) {
873 docstring s = _("LyX has caught an exception, it will now "
874 "attempt to save all unsaved documents and exit."
876 s += from_ascii(e.what());
877 Alert::error(_("Software exception Detected"), s);
881 docstring s = _("LyX has caught some really weird exception, it will "
882 "now attempt to save all unsaved documents and exit.");
883 Alert::error(_("Software exception Detected"), s);
891 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
893 QColor const & qcol = d->color_cache_.get(col);
894 if (!qcol.isValid()) {
900 rgbcol.r = qcol.red();
901 rgbcol.g = qcol.green();
902 rgbcol.b = qcol.blue();
907 string const GuiApplication::hexName(ColorCode col)
909 return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
913 void GuiApplication::updateColor(ColorCode)
915 // FIXME: Bleh, can't we just clear them all at once ?
916 d->color_cache_.clear();
920 void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
922 SocketNotifier * sn = new SocketNotifier(this, fd, func);
923 d->socket_notifiers_[fd] = sn;
924 connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
928 void GuiApplication::socketDataReceived(int fd)
930 d->socket_notifiers_[fd]->func_();
934 void GuiApplication::unregisterSocketCallback(int fd)
936 d->socket_notifiers_[fd]->setEnabled(false);
937 d->socket_notifiers_.erase(fd);
941 void GuiApplication::commitData(QSessionManager & sm)
943 /// The implementation is required to avoid an application exit
944 /// when session state save is triggered by session manager.
945 /// The default implementation sends a close event to all
946 /// visible top level widgets when session managment allows
948 /// We are changing that to close all wiew one by one.
949 /// FIXME: verify if the default implementation is enough now.
950 if (sm.allowsInteraction() && !closeAllViews())
955 bool GuiApplication::unregisterView(int id)
957 updateIds(d->views_, d->view_ids_);
958 LASSERT(d->views_.find(id) != d->views_.end(), /**/);
959 LASSERT(d->views_[id], /**/);
961 map<int, GuiView *>::iterator it;
962 for (it = d->views_.begin(); it != d->views_.end(); ++it) {
963 if (it->first == id) {
968 updateIds(d->views_, d->view_ids_);
973 bool GuiApplication::closeAllViews()
975 updateIds(d->views_, d->view_ids_);
976 if (d->views_.empty())
979 map<int, GuiView*> const cmap = d->views_;
980 map<int, GuiView*>::const_iterator it;
981 for (it = cmap.begin(); it != cmap.end(); ++it) {
982 if (!it->second->close())
987 d->view_ids_.clear();
992 GuiView & GuiApplication::view(int id) const
994 LASSERT(d->views_.find(id) != d->views_.end(), /**/);
995 return *d->views_.find(id)->second;
999 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
1001 vector<int>::const_iterator it = d->view_ids_.begin();
1002 vector<int>::const_iterator const end = d->view_ids_.end();
1003 for (; it != end; ++it)
1004 view(*it).hideDialog(name, inset);
1008 Buffer const * GuiApplication::updateInset(Inset const * inset) const
1010 Buffer const * buffer_ = 0;
1011 vector<int>::const_iterator it = d->view_ids_.begin();
1012 vector<int>::const_iterator const end = d->view_ids_.end();
1013 for (; it != end; ++it) {
1014 Buffer const * ptr = view(*it).updateInset(inset);
1022 void GuiApplication::readMenus(Lexer & lex)
1028 bool GuiApplication::searchMenu(FuncRequest const & func,
1029 vector<docstring> & names) const
1031 return menus().searchMenu(func, names);
1035 void GuiApplication::initGlobalMenu()
1037 if (d->global_menubar_)
1038 menus().fillMenuBar(d->global_menubar_, 0, true);
1042 void GuiApplication::onLastWindowClosed()
1044 if (d->global_menubar_)
1045 d->global_menubar_->grabKeyboard();
1049 ////////////////////////////////////////////////////////////////////////
1051 // X11 specific stuff goes here...
1054 bool GuiApplication::x11EventFilter(XEvent * xev)
1059 switch (xev->type) {
1060 case SelectionRequest: {
1061 if (xev->xselectionrequest.selection != XA_PRIMARY)
1063 LYXERR(Debug::GUI, "X requested selection.");
1064 BufferView * bv = current_view_->view();
1066 docstring const sel = bv->requestSelection();
1068 selection_.put(sel);
1072 case SelectionClear: {
1073 if (xev->xselectionclear.selection != XA_PRIMARY)
1075 LYXERR(Debug::GUI, "Lost selection.");
1076 BufferView * bv = current_view_->view();
1078 bv->clearSelection();
1086 } // namespace frontend
1089 void hideDialogs(std::string const & name, Inset * inset)
1092 theApp()->hideDialogs(name, inset);
1096 ////////////////////////////////////////////////////////////////////
1100 ////////////////////////////////////////////////////////////////////
1102 frontend::FontLoader & theFontLoader()
1104 LASSERT(frontend::guiApp, /**/);
1105 return frontend::guiApp->fontLoader();
1109 frontend::FontMetrics const & theFontMetrics(Font const & f)
1111 return theFontMetrics(f.fontInfo());
1115 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
1117 LASSERT(frontend::guiApp, /**/);
1118 return frontend::guiApp->fontLoader().metrics(f);
1122 ////////////////////////////////////////////////////////////////////
1126 ////////////////////////////////////////////////////////////////////
1128 frontend::Clipboard & theClipboard()
1130 LASSERT(frontend::guiApp, /**/);
1131 return frontend::guiApp->clipboard();
1135 frontend::Selection & theSelection()
1137 LASSERT(frontend::guiApp, /**/);
1138 return frontend::guiApp->selection();
1143 #include "GuiApplication_moc.cpp"