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/ForkedCalls.h"
50 #include "support/gettext.h"
51 #include "support/lstrings.h"
52 #include "support/os.h"
53 #include "support/Package.h"
56 #include "support/linkback/LinkBackProxy.h"
61 #include <QFileOpenEvent>
63 #include <QLibraryInfo>
64 #include <QMacPasteboardMime>
67 #include <QPixmapCache>
69 #include <QSessionManager>
70 #include <QSocketNotifier>
71 #include <QSortFilterProxyModel>
72 #include <QStandardItemModel>
75 #include <QTranslator>
79 #include <X11/Xatom.h>
87 #include <QWindowsMime>
88 #if defined(Q_CYGWIN_WIN) || defined(Q_CC_MINGW)
94 #include <boost/bind.hpp>
100 using namespace lyx::support;
102 // FIXME: These strings are also used in GuiClipboard.cpp.
103 static char const * const lyx_mime_type = "application/x-lyx";
104 static char const * const pdf_mime_type = "application/pdf";
105 static char const * const emf_mime_type = "image/x-emf";
106 static char const * const wmf_mime_type = "image/x-wmf";
110 frontend::Application * createApplication(int & argc, char * argv[])
112 return new frontend::GuiApplication(argc, argv);
118 class SocketNotifier : public QSocketNotifier
121 /// connect a connection notification from the LyXServerSocket
122 SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
123 : QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
127 /// The callback function
128 Application::SocketCallback func_;
132 ////////////////////////////////////////////////////////////////////////
133 // Mac specific stuff goes here...
135 class MenuTranslator : public QTranslator
138 MenuTranslator(QObject * parent)
139 : QTranslator(parent)
142 QString translate(const char * /*context*/,
143 const char * sourceText,
144 const char * /*comment*/ = 0)
146 string const s = sourceText;
147 if (s == N_("About %1") || s == N_("Preferences")
148 || s == N_("Reconfigure") || s == N_("Quit %1"))
155 class GlobalMenuBar : public QMenuBar
159 GlobalMenuBar() : QMenuBar(0) {}
162 bool event(QEvent * e)
164 if (e->type() == QEvent::ShortcutOverride) {
165 // && activeWindow() == 0) {
166 QKeyEvent * ke = static_cast<QKeyEvent*>(e);
168 setKeySymbol(&sym, ke);
169 theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
178 // QMacPasteboardMimeGraphics can only be compiled on Mac.
180 class QMacPasteboardMimeGraphics : public QMacPasteboardMime
183 QMacPasteboardMimeGraphics()
184 : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL)
187 QString convertorName() { return "Graphics"; }
189 QString flavorFor(QString const & mime)
191 LYXERR(Debug::ACTION, "flavorFor " << mime);
192 if (mime == QLatin1String(pdf_mime_type))
193 return QLatin1String("com.adobe.pdf");
197 QString mimeFor(QString flav)
199 LYXERR(Debug::ACTION, "mimeFor " << flav);
200 if (flav == QLatin1String("com.adobe.pdf"))
201 return QLatin1String(pdf_mime_type);
205 bool canConvert(QString const & mime, QString flav)
206 { return mimeFor(flav) == mime; }
208 QVariant convertToMime(QString const & mime, QList<QByteArray> data, QString flav)
211 qWarning("QMacPasteboardMimeGraphics: Cannot handle multiple member data");
215 QList<QByteArray> convertFromMime(QString const & mime, QVariant data, QString flav)
217 QList<QByteArray> ret;
218 ret.append(data.toByteArray());
224 ///////////////////////////////////////////////////////////////
225 // You can find more platform specific stuff
226 // at the end of this file...
227 ///////////////////////////////////////////////////////////////
229 ////////////////////////////////////////////////////////////////////////
230 // Windows specific stuff goes here...
233 // QWindowsMimeMetafile can only be compiled on Windows.
235 static FORMATETC cfFromMime(QString const & mimetype)
238 if (mimetype == emf_mime_type) {
239 formatetc.cfFormat = CF_ENHMETAFILE;
240 formatetc.tymed = TYMED_ENHMF;
241 } else if (mimetype == wmf_mime_type) {
242 formatetc.cfFormat = CF_METAFILEPICT;
243 formatetc.tymed = TYMED_MFPICT;
246 formatetc.dwAspect = DVASPECT_CONTENT;
247 formatetc.lindex = -1;
252 class QWindowsMimeMetafile : public QWindowsMime {
254 QWindowsMimeMetafile() {}
256 bool canConvertFromMime(FORMATETC const & formatetc,
257 QMimeData const * mimedata) const
262 bool canConvertToMime(QString const & mimetype,
263 IDataObject * pDataObj) const
265 if (mimetype != emf_mime_type && mimetype != wmf_mime_type)
267 FORMATETC formatetc = cfFromMime(mimetype);
268 return pDataObj->QueryGetData(&formatetc) == S_OK;
271 bool convertFromMime(FORMATETC const & formatetc,
272 const QMimeData * mimedata, STGMEDIUM * pmedium) const
277 QVariant convertToMime(QString const & mimetype, IDataObject * pDataObj,
278 QVariant::Type preferredType) const
281 if (!canConvertToMime(mimetype, pDataObj))
284 FORMATETC formatetc = cfFromMime(mimetype);
286 if (pDataObj->GetData(&formatetc, &s) != S_OK)
290 if (s.tymed == TYMED_ENHMF) {
291 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, 0, 0);
292 data.resize(dataSize);
293 dataSize = GetEnhMetaFileBits(s.hEnhMetaFile, dataSize,
294 (LPBYTE)data.data());
295 } else if (s.tymed == TYMED_MFPICT) {
296 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, 0, 0);
297 data.resize(dataSize);
298 dataSize = GetMetaFileBitsEx((HMETAFILE)s.hMetaFilePict, dataSize,
299 (LPBYTE)data.data());
302 ReleaseStgMedium(&s);
308 QVector<FORMATETC> formatsForMime(QString const & mimeType,
309 QMimeData const * mimeData) const
311 QVector<FORMATETC> formats;
312 formats += cfFromMime(mimeType);
316 QString mimeForFormat(FORMATETC const & formatetc) const
318 switch (formatetc.cfFormat) {
320 return emf_mime_type;
321 case CF_METAFILEPICT:
322 return wmf_mime_type;
330 ////////////////////////////////////////////////////////////////////////
331 // GuiApplication::Private definition and implementation.
332 ////////////////////////////////////////////////////////////////////////
334 struct GuiApplication::Private
336 Private(): language_model_(0), global_menubar_(0)
339 // Create the global default menubar which is shown for the dialogs
340 // and if no GuiView is visible.
341 global_menubar_ = new GlobalMenuBar();
346 QSortFilterProxyModel * language_model_;
348 GuiClipboard clipboard_;
350 GuiSelection selection_;
352 FontLoader font_loader_;
354 ColorCache color_cache_;
356 QTranslator qt_trans_;
358 std::map<int, SocketNotifier *> socket_notifiers_;
361 /// this timer is used for any regular events one wants to
362 /// perform. at present it is used to check if forked processes
364 QTimer general_timer_;
366 /// Multiple views container.
368 * Warning: This must not be a smart pointer as the destruction of the
369 * object is handled by Qt when the view is closed
370 * \sa Qt::WA_DeleteOnClose attribute.
372 map<int, GuiView *> views_;
374 /// Only used on mac.
375 GlobalMenuBar * global_menubar_;
378 /// Linkback mime handler for MacOSX.
379 QMacPasteboardMimeGraphics mac_pasteboard_mime_;
383 /// WMF Mime handler for Windows clipboard.
384 // FIXME for Windows Vista and Qt4 (see http://bugzilla.lyx.org/show_bug.cgi?id=4846)
385 // But this makes LyX crash on exit when LyX is compiled in release mode and if there
386 // is something in the clipboard.
387 QWindowsMimeMetafile wmf_mime_;
392 GuiApplication * guiApp;
394 GuiApplication::~GuiApplication()
397 closeAllLinkBackLinks();
403 GuiApplication::GuiApplication(int & argc, char ** argv)
404 : QApplication(argc, argv), current_view_(0), d(new GuiApplication::Private)
406 QString app_name = "LyX";
407 QCoreApplication::setOrganizationName(app_name);
408 QCoreApplication::setOrganizationDomain("lyx.org");
409 QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
411 // FIXME: quitOnLastWindowClosed is true by default. We should have a
412 // lyxrc setting for this in order to let the application stay resident.
413 // But then we need some kind of dock icon, at least on Windows.
415 if (lyxrc.quit_on_last_window_closed)
416 setQuitOnLastWindowClosed(false);
419 // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
420 // seems to be the default case for applications like LyX.
421 setQuitOnLastWindowClosed(false);
425 // doubleClickInterval() is 400 ms on X11 which is just too long.
426 // On Windows and Mac OS X, the operating system's value is used.
427 // On Microsoft Windows, calling this function sets the double
428 // click interval for all applications. So we don't!
429 QApplication::setDoubleClickInterval(300);
432 // install translation file for Qt built-in dialogs
433 QString language_name = QString("qt_") + QLocale::system().name();
435 // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN).
436 // Short-named translator can be loaded from a long name, but not the
437 // opposite. Therefore, long name should be used without truncation.
438 // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
439 if (d->qt_trans_.load(language_name,
440 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
442 installTranslator(&d->qt_trans_);
443 // even if the language calls for RtL, don't do that
444 setLayoutDirection(Qt::LeftToRight);
445 LYXERR(Debug::GUI, "Successfully installed Qt translations for locale "
448 LYXERR(Debug::GUI, "Could not find Qt translations for locale "
452 // This allows to translate the strings that appear in the LyX menu.
453 /// A translator suitable for the entries in the LyX menu.
454 /// Only needed with Qt/Mac.
455 installTranslator(new MenuTranslator(this));
457 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
459 using namespace lyx::graphics;
461 Image::newImage = boost::bind(&GuiImage::newImage);
462 Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
464 // needs to be done before reading lyxrc
466 lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
470 // Set the cache to 5120 kilobytes which corresponds to screen size of
471 // 1280 by 1024 pixels with a color depth of 32 bits.
472 QPixmapCache::setCacheLimit(5120);
474 // Initialize RC Fonts
475 if (lyxrc.roman_font_name.empty())
476 lyxrc.roman_font_name = fromqstr(romanFontName());
478 if (lyxrc.sans_font_name.empty())
479 lyxrc.sans_font_name = fromqstr(sansFontName());
481 if (lyxrc.typewriter_font_name.empty())
482 lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
484 d->general_timer_.setInterval(500);
485 connect(&d->general_timer_, SIGNAL(timeout()),
486 this, SLOT(handleRegularEvents()));
487 d->general_timer_.start();
491 bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
497 case LFUN_WINDOW_CLOSE:
498 enable = d->views_.size() > 0;
501 case LFUN_BUFFER_NEW:
502 case LFUN_BUFFER_NEW_TEMPLATE:
504 case LFUN_SCREEN_FONT_UPDATE:
506 case LFUN_WINDOW_NEW:
522 bool GuiApplication::dispatch(FuncRequest const & cmd)
526 case LFUN_WINDOW_NEW:
527 createView(toqstr(cmd.argument()));
530 case LFUN_WINDOW_CLOSE:
531 // update bookmark pit of the current buffer before window close
532 for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
533 theLyXFunc().gotoBookmark(i+1, false, false);
534 current_view_->close();
538 // quitting is triggered by the gui code
539 // (leaving the event loop).
541 current_view_->message(from_utf8(N_("Exiting.")));
546 case LFUN_SCREEN_FONT_UPDATE: {
547 // handle the screen font changes.
548 d->font_loader_.update();
549 // Backup current_view_
550 GuiView * view = current_view_;
551 // Set current_view_ to zero to forbid GuiWorkArea::redraw()
552 // to skip the refresh.
554 BufferList::iterator it = theBufferList().begin();
555 BufferList::iterator const end = theBufferList().end();
556 for (; it != end; ++it)
558 // Restore current_view_
559 current_view_ = view;
563 case LFUN_BUFFER_NEW:
565 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
566 createView(QString(), false); // keep hidden
567 current_view_->newDocument(to_utf8(cmd.argument()), false);
568 current_view_->show();
569 setActiveWindow(current_view_);
571 current_view_->newDocument(to_utf8(cmd.argument()), false);
574 case LFUN_BUFFER_NEW_TEMPLATE:
576 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
578 current_view_->newDocument(to_utf8(cmd.argument()), true);
579 if (!current_view_->buffer())
580 current_view_->close();
582 current_view_->newDocument(to_utf8(cmd.argument()), true);
587 || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
589 current_view_->openDocument(to_utf8(cmd.argument()));
590 if (!current_view_->buffer())
591 current_view_->close();
593 current_view_->openDocument(to_utf8(cmd.argument()));
596 case LFUN_SET_COLOR: {
598 string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' ');
599 if (lyx_name.empty() || x11_name.empty()) {
600 current_view_->message(
601 _("Syntax: set-color <lyx_name> <x11_name>"));
605 string const graphicsbg = lcolor.getLyXName(Color_graphicsbg);
606 bool const graphicsbg_changed = lyx_name == graphicsbg
607 && x11_name != graphicsbg;
608 if (graphicsbg_changed) {
609 // FIXME: The graphics cache no longer has a changeDisplay method.
611 graphics::GCache::get().changeDisplay(true);
615 if (!lcolor.setColor(lyx_name, x11_name)) {
616 current_view_->message(
617 bformat(_("Set-color \"%1$s\" failed "
618 "- color is undefined or "
619 "may not be redefined"),
620 from_utf8(lyx_name)));
623 // Make sure we don't keep old colors in cache.
624 d->color_cache_.clear();
629 // Notify the caller that the action has not been dispatched.
633 // The action has been dispatched.
638 void GuiApplication::resetGui()
640 map<int, GuiView *>::iterator it;
641 for (it = d->views_.begin(); it != d->views_.end(); ++it)
642 it->second->resetDialogs();
644 dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
648 void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
650 // release the keyboard which might have been grabed by the global
651 // menubar on Mac to catch shortcuts even without any GuiView.
652 if (d->global_menubar_)
653 d->global_menubar_->releaseKeyboard();
657 while (d->views_.find(id) != d->views_.end())
659 GuiView * view = new GuiView(id);
661 // copy the icon size from old view
663 view->setIconSize(current_view_->iconSize());
666 d->views_[id] = view;
670 setActiveWindow(view);
673 if (!geometry_arg.isEmpty()) {
677 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
678 re.indexIn(geometry_arg);
679 w = re.cap(1).toInt();
680 h = re.cap(2).toInt();
681 x = re.cap(3).toInt();
682 y = re.cap(4).toInt();
683 view->setGeometry(x, y, w, h);
687 setCurrentView(view);
691 Clipboard & GuiApplication::clipboard()
693 return d->clipboard_;
697 Selection & GuiApplication::selection()
699 return d->selection_;
703 FontLoader & GuiApplication::fontLoader()
705 return d->font_loader_;
709 Menus const & GuiApplication::menus() const
715 Menus & GuiApplication::menus()
721 size_t GuiApplication::viewCount() const
723 return d->views_.size();
727 QVector<int> GuiApplication::viewIds()
730 map<int, GuiView *>::const_iterator end = d->views_.end();
731 map<int, GuiView *>::const_iterator it = d->views_.begin();
732 for (; it != end; ++it)
733 ids.push_back(it->first);
738 ColorCache & GuiApplication::colorCache()
740 return d->color_cache_;
744 int GuiApplication::exec()
746 QTimer::singleShot(1, this, SLOT(execBatchCommands()));
747 return QApplication::exec();
751 void GuiApplication::exit(int status)
753 QApplication::exit(status);
757 void GuiApplication::execBatchCommands()
759 // init the global menubar on Mac. This must be done after the session
760 // was recovered to know the "last files".
761 if (d->global_menubar_)
762 d->menus_.fillMenuBar(d->global_menubar_, 0, true);
764 LyX::ref().execBatchCommands();
767 QAbstractItemModel * GuiApplication::languageModel()
769 if (d->language_model_)
770 return d->language_model_;
772 QStandardItemModel * lang_model = new QStandardItemModel(this);
773 lang_model->insertColumns(0, 1);
775 Languages::const_iterator it = languages.begin();
776 Languages::const_iterator end = languages.end();
777 for (; it != end; ++it) {
778 current_row = lang_model->rowCount();
779 lang_model->insertRows(current_row, 1);
780 QModelIndex item = lang_model->index(current_row, 0);
781 lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
782 lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
784 d->language_model_ = new QSortFilterProxyModel(this);
785 d->language_model_->setSourceModel(lang_model);
786 #if QT_VERSION >= 0x040300
787 d->language_model_->setSortLocaleAware(true);
789 return d->language_model_;
793 void GuiApplication::restoreGuiSession()
795 if (!lyxrc.load_session)
798 Session & session = LyX::ref().session();
799 vector<FileName> const & lastopened = session.lastOpened().getfiles();
800 // do not add to the lastfile list since these files are restored from
801 // last session, and should be already there (regular files), or should
802 // not be added at all (help files).
803 for_each(lastopened.begin(), lastopened.end(),
804 bind(&GuiView::loadDocument, current_view_, _1, false));
806 // clear this list to save a few bytes of RAM
807 session.lastOpened().clear();
811 QString const GuiApplication::romanFontName()
814 font.setKerning(false);
815 font.setStyleHint(QFont::Serif);
816 font.setFamily("serif");
818 return QFontInfo(font).family();
822 QString const GuiApplication::sansFontName()
825 font.setKerning(false);
826 font.setStyleHint(QFont::SansSerif);
827 font.setFamily("sans");
829 return QFontInfo(font).family();
833 QString const GuiApplication::typewriterFontName()
836 font.setKerning(false);
837 font.setStyleHint(QFont::TypeWriter);
838 font.setFamily("monospace");
840 return QFontInfo(font).family();
844 void GuiApplication::handleRegularEvents()
846 ForkedCallsController::handleCompletedProcesses();
850 bool GuiApplication::event(QEvent * e)
853 case QEvent::FileOpen: {
854 // Open a file; this happens only on Mac OS X for now
855 QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
857 if (!current_view_ || !current_view_->view())
858 // The application is not properly initialized yet.
859 // So we acknowledge the event and delay the file opening
860 // until LyX is ready.
861 // FIXME UNICODE: FileName accept an utf8 encoded string.
862 LyX::ref().addFileToLoad(fromqstr(foe->file()));
864 lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
865 qstring_to_ucs4(foe->file())));
871 return QApplication::event(e);
876 bool GuiApplication::notify(QObject * receiver, QEvent * event)
879 return QApplication::notify(receiver, event);
881 catch (ExceptionMessage const & e) {
884 LyX::cref().emergencyCleanup();
885 setQuitOnLastWindowClosed(false);
887 Alert::error(e.title_, e.details_);
889 // Properly crash in debug mode in order to get a useful backtrace.
892 // In release mode, try to exit gracefully.
895 case BufferException: {
896 Buffer * buf = current_view_->buffer();
897 docstring details = e.details_ + '\n';
898 details += theBufferList().emergencyWrite(buf);
899 theBufferList().release(buf);
900 details += "\n" + _("The current document was closed.");
901 Alert::error(e.title_, details);
904 case WarningException:
905 Alert::warning(e.title_, e.details_);
909 catch (exception const & e) {
910 docstring s = _("LyX has caught an exception, it will now "
911 "attempt to save all unsaved documents and exit."
913 s += from_ascii(e.what());
914 Alert::error(_("Software exception Detected"), s);
918 docstring s = _("LyX has caught some really weird exception, it will "
919 "now attempt to save all unsaved documents and exit.");
920 Alert::error(_("Software exception Detected"), s);
928 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
930 QColor const & qcol = d->color_cache_.get(col);
931 if (!qcol.isValid()) {
937 rgbcol.r = qcol.red();
938 rgbcol.g = qcol.green();
939 rgbcol.b = qcol.blue();
944 string const GuiApplication::hexName(ColorCode col)
946 return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
950 void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
952 SocketNotifier * sn = new SocketNotifier(this, fd, func);
953 d->socket_notifiers_[fd] = sn;
954 connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
958 void GuiApplication::socketDataReceived(int fd)
960 d->socket_notifiers_[fd]->func_();
964 void GuiApplication::unregisterSocketCallback(int fd)
966 d->socket_notifiers_[fd]->setEnabled(false);
967 d->socket_notifiers_.erase(fd);
971 void GuiApplication::commitData(QSessionManager & sm)
973 /// The implementation is required to avoid an application exit
974 /// when session state save is triggered by session manager.
975 /// The default implementation sends a close event to all
976 /// visible top level widgets when session managment allows
978 /// We are changing that to close all wiew one by one.
979 /// FIXME: verify if the default implementation is enough now.
980 if (sm.allowsInteraction() && !closeAllViews())
985 void GuiApplication::unregisterView(GuiView * gv)
987 LASSERT(d->views_[gv->id()] == gv, /**/);
988 d->views_.erase(gv->id());
992 bool GuiApplication::closeAllViews()
994 if (d->views_.empty())
997 map<int, GuiView*> const cmap = d->views_;
998 map<int, GuiView*>::const_iterator it;
999 for (it = cmap.begin(); it != cmap.end(); ++it) {
1000 if (!it->second->close())
1009 GuiView & GuiApplication::view(int id) const
1011 LASSERT(d->views_.find(id) != d->views_.end(), /**/);
1012 return *d->views_.find(id)->second;
1016 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
1018 map<int, GuiView *>::iterator end = d->views_.end();
1019 for (map<int, GuiView *>::iterator it = d->views_.begin(); it != end; ++it)
1020 it->second->hideDialog(name, inset);
1024 Buffer const * GuiApplication::updateInset(Inset const * inset) const
1026 Buffer const * buffer_ = 0;
1027 map<int, GuiView *>::iterator end = d->views_.end();
1028 for (map<int, GuiView *>::iterator it = d->views_.begin(); it != end; ++it) {
1029 if (Buffer const * ptr = it->second->updateInset(inset))
1036 void GuiApplication::readMenus(Lexer & lex)
1042 bool GuiApplication::searchMenu(FuncRequest const & func,
1043 vector<docstring> & names) const
1045 return menus().searchMenu(func, names);
1049 void GuiApplication::onLastWindowClosed()
1051 if (d->global_menubar_)
1052 d->global_menubar_->grabKeyboard();
1056 ////////////////////////////////////////////////////////////////////////
1058 // X11 specific stuff goes here...
1061 bool GuiApplication::x11EventFilter(XEvent * xev)
1066 switch (xev->type) {
1067 case SelectionRequest: {
1068 if (xev->xselectionrequest.selection != XA_PRIMARY)
1070 LYXERR(Debug::GUI, "X requested selection.");
1071 BufferView * bv = current_view_->view();
1073 docstring const sel = bv->requestSelection();
1075 d->selection_.put(sel);
1079 case SelectionClear: {
1080 if (xev->xselectionclear.selection != XA_PRIMARY)
1082 LYXERR(Debug::GUI, "Lost selection.");
1083 BufferView * bv = current_view_->view();
1085 bv->clearSelection();
1093 } // namespace frontend
1096 void hideDialogs(std::string const & name, Inset * inset)
1099 theApp()->hideDialogs(name, inset);
1103 ////////////////////////////////////////////////////////////////////
1107 ////////////////////////////////////////////////////////////////////
1109 frontend::FontLoader & theFontLoader()
1111 LASSERT(frontend::guiApp, /**/);
1112 return frontend::guiApp->fontLoader();
1116 frontend::FontMetrics const & theFontMetrics(Font const & f)
1118 return theFontMetrics(f.fontInfo());
1122 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
1124 LASSERT(frontend::guiApp, /**/);
1125 return frontend::guiApp->fontLoader().metrics(f);
1129 ////////////////////////////////////////////////////////////////////
1133 ////////////////////////////////////////////////////////////////////
1135 frontend::Clipboard & theClipboard()
1137 LASSERT(frontend::guiApp, /**/);
1138 return frontend::guiApp->clipboard();
1142 frontend::Selection & theSelection()
1144 LASSERT(frontend::guiApp, /**/);
1145 return frontend::guiApp->selection();
1150 #include "GuiApplication_moc.cpp"