]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.cpp
Change strings.
[lyx.git] / src / frontends / qt4 / GuiApplication.cpp
1 /**
2  * \file GuiApplication.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiApplication.h"
16
17 #include "qt_helpers.h"
18 #include "GuiImage.h"
19 #include "GuiKeySymbol.h"
20 #include "GuiView.h"
21
22 #include "frontends/alert.h"
23 #include "frontends/Application.h"
24 #include "frontends/FontLoader.h"
25 #include "frontends/FontMetrics.h"
26
27 #include "Buffer.h"
28 #include "BufferList.h"
29 #include "BufferView.h"
30 #include "Font.h"
31 #include "FuncRequest.h"
32 #include "FuncStatus.h"
33 #include "LyX.h"
34 #include "LyXFunc.h"
35 #include "LyXRC.h"
36 #include "Session.h"
37 #include "version.h"
38
39 #include "support/debug.h"
40 #include "support/ExceptionMessage.h"
41 #include "support/FileName.h"
42 #include "support/ForkedCalls.h"
43 #include "support/gettext.h"
44 #include "support/lstrings.h"
45 #include "support/os.h"
46 #include "support/Package.h"
47
48 #include <QApplication>
49 #include <QClipboard>
50 #include <QEventLoop>
51 #include <QFileOpenEvent>
52 #include <QLocale>
53 #include <QLibraryInfo>
54 #include <QMenuBar>
55 #include <QPixmapCache>
56 #include <QRegExp>
57 #include <QSessionManager>
58 #include <QSocketNotifier>
59 #include <QTextCodec>
60 #include <QTimer>
61 #include <QTranslator>
62 #include <QWidget>
63
64 #ifdef Q_WS_X11
65 #include <X11/Xatom.h>
66 #include <X11/Xlib.h>
67 #undef CursorShape
68 #undef None
69 #endif
70
71 #include <boost/bind.hpp>
72
73 #include <exception>
74
75 using namespace std;
76 using namespace lyx::support;
77
78 namespace lyx {
79
80 frontend::Application * createApplication(int & argc, char * argv[])
81 {
82         return new frontend::GuiApplication(argc, argv);
83 }
84
85
86 namespace frontend {
87
88 class SocketNotifier : public QSocketNotifier
89 {
90 public:
91         /// connect a connection notification from the LyXServerSocket
92         SocketNotifier(QObject * parent, int fd, Application::SocketCallback func)
93                 : QSocketNotifier(fd, QSocketNotifier::Read, parent), func_(func)
94         {}
95
96 public:
97         /// The callback function
98         Application::SocketCallback func_;
99 };
100
101
102 ////////////////////////////////////////////////////////////////////////
103 // Mac specific stuff goes here...
104
105 class MenuTranslator : public QTranslator
106 {
107 public:
108         MenuTranslator(QObject * parent)
109                 : QTranslator(parent)
110         {}
111
112         QString translate(const char * /*context*/, 
113           const char * sourceText, 
114           const char * /*comment*/ = 0) 
115         {
116                 string const s = sourceText;
117                 if (s == N_("About %1") || s == N_("Preferences") 
118                                 || s == N_("Reconfigure") || s == N_("Quit %1"))
119                         return qt_(s);
120                 else 
121                         return QString();
122         }
123 };
124
125 class GlobalMenuBar : public QMenuBar
126 {
127 public:
128         ///
129         GlobalMenuBar() : QMenuBar(0) {}
130         
131         ///
132         bool event(QEvent * e)
133         {
134                 if (e->type() == QEvent::ShortcutOverride) {
135                         //          && activeWindow() == 0) {
136                         QKeyEvent * ke = static_cast<QKeyEvent*>(e);
137                         KeySymbol sym;
138                         setKeySymbol(&sym, ke);
139                         theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
140                         e->accept();
141                         return true;
142                 }
143                 return false;
144         }
145 };
146
147 ///////////////////////////////////////////////////////////////
148 // You can find more platform specific stuff
149 // at the end of this file...
150 ///////////////////////////////////////////////////////////////
151
152
153 GuiApplication * guiApp;
154
155
156 GuiApplication::GuiApplication(int & argc, char ** argv)
157         : QApplication(argc, argv), Application(), current_view_(0), global_menubar_(0)
158 {
159         QString app_name = "LyX";
160         QCoreApplication::setOrganizationName(app_name);
161         QCoreApplication::setOrganizationDomain("lyx.org");
162         QCoreApplication::setApplicationName(app_name + "-" + lyx_version);
163
164         // FIXME: quitOnLastWindowClosed is true by default. We should have a
165         // lyxrc setting for this in order to let the application stay resident.
166         // But then we need some kind of dock icon, at least on Windows.
167         /*
168         if (lyxrc.quit_on_last_window_closed)
169                 setQuitOnLastWindowClosed(false);
170         */
171 #ifdef Q_WS_MAC
172         // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
173         // seems to be the default case for applications like LyX.
174         setQuitOnLastWindowClosed(false);
175 #endif
176         
177 #ifdef Q_WS_X11
178         // doubleClickInterval() is 400 ms on X11 which is just too long.
179         // On Windows and Mac OS X, the operating system's value is used.
180         // On Microsoft Windows, calling this function sets the double
181         // click interval for all applications. So we don't!
182         QApplication::setDoubleClickInterval(300);
183 #endif
184
185         // install translation file for Qt built-in dialogs
186         QString language_name = QString("qt_") + QLocale::system().name();
187         
188         // language_name can be short (e.g. qt_zh) or long (e.g. qt_zh_CN). 
189         // Short-named translator can be loaded from a long name, but not the
190         // opposite. Therefore, long name should be used without truncation.
191         // c.f. http://doc.trolltech.com/4.1/qtranslator.html#load
192         if (qt_trans_.load(language_name,
193                 QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
194         {
195                 installTranslator(&qt_trans_);
196                 // even if the language calls for RtL, don't do that
197                 setLayoutDirection(Qt::LeftToRight);
198                 LYXERR(Debug::GUI, "Successfully installed Qt translations for locale "
199                         << fromqstr(language_name));
200         } else
201                 LYXERR(Debug::GUI, "Could not find  Qt translations for locale "
202                         << fromqstr(language_name));
203
204 #ifdef Q_WS_MACX
205         // This allows to translate the strings that appear in the LyX menu.
206         addMenuTranslator();
207 #endif
208         connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
209
210         using namespace lyx::graphics;
211
212         Image::newImage = boost::bind(&GuiImage::newImage);
213         Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
214
215         // needs to be done before reading lyxrc
216         QWidget w;
217         lyxrc.dpi = (w.logicalDpiX() + w.logicalDpiY()) / 2;
218
219         guiApp = this;
220
221         // Set the cache to 5120 kilobytes which corresponds to screen size of
222         // 1280 by 1024 pixels with a color depth of 32 bits.
223         QPixmapCache::setCacheLimit(5120);
224
225         // Initialize RC Fonts
226         if (lyxrc.roman_font_name.empty())
227                 lyxrc.roman_font_name = fromqstr(romanFontName());
228
229         if (lyxrc.sans_font_name.empty())
230                 lyxrc.sans_font_name = fromqstr(sansFontName());
231
232         if (lyxrc.typewriter_font_name.empty())
233                 lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
234
235         general_timer_.setInterval(500);
236         connect(&general_timer_, SIGNAL(timeout()),
237                 this, SLOT(handleRegularEvents()));
238         general_timer_.start();
239         
240 #ifdef Q_WS_MACX
241         if (global_menubar_ == 0) {
242                 // Create the global default menubar which is shown for the dialogs
243                 // and if no GuiView is visible.
244                 global_menubar_ = new GlobalMenuBar();
245         }
246 #endif  
247 }
248
249
250 GuiApplication::~GuiApplication()
251 {
252         socket_notifiers_.clear();
253 }
254
255
256 FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
257 {
258         FuncStatus flag;
259         bool enable = true;
260
261         switch(cmd.action) {
262
263         case LFUN_WINDOW_CLOSE:
264                 enable = view_ids_.size() > 0;
265                 break;
266
267         default:
268                 if (!current_view_) {
269                         enable = false;
270                         break;
271                 }
272         }
273
274         if (!enable)
275                 flag.enabled(false);
276
277         return flag;
278 }
279
280         
281 bool GuiApplication::dispatch(FuncRequest const & cmd)
282 {
283         switch(cmd.action) {
284
285         case LFUN_WINDOW_NEW:
286                 createView(toqstr(cmd.argument()));
287                 break;
288
289         case LFUN_WINDOW_CLOSE:
290                 // update bookmark pit of the current buffer before window close
291                 for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i)
292                         theLyXFunc().gotoBookmark(i+1, false, false);
293                 current_view_->close();
294                 break;
295
296         case LFUN_LYX_QUIT:
297                 // quitting is triggered by the gui code
298                 // (leaving the event loop).
299                 if (current_view_)
300                         current_view_->message(from_utf8(N_("Exiting.")));
301                 if (closeAllViews())
302                         quit();
303                 break;
304
305         case LFUN_SCREEN_FONT_UPDATE: {
306                 // handle the screen font changes.
307                 font_loader_.update();
308                 // Backup current_view_
309                 GuiView * view = current_view_;
310                 // Set current_view_ to zero to forbid GuiWorkArea::redraw()
311                 // to skip the refresh.
312                 current_view_ = 0;
313                 BufferList::iterator it = theBufferList().begin();
314                 BufferList::iterator const end = theBufferList().end();
315                 for (; it != end; ++it)
316                         (*it)->changed();
317                 // Restore current_view_
318                 current_view_ = view;
319                 break;
320         }
321
322         case LFUN_BUFFER_NEW:
323                 if (viewCount() == 0
324                     || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
325                         createView(QString(), false); // keep hidden
326                         current_view_->newDocument(to_utf8(cmd.argument()), false);
327                         current_view_->show();
328                         setActiveWindow(current_view_);
329                 } else
330                         current_view_->newDocument(to_utf8(cmd.argument()), false);
331                 break;
332
333         case LFUN_BUFFER_NEW_TEMPLATE:
334                 if (viewCount() == 0 
335                     || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
336                         createView();
337                         current_view_->newDocument(to_utf8(cmd.argument()), true);
338                         if (!current_view_->buffer())
339                                 current_view_->close();
340                 } else
341                         current_view_->newDocument(to_utf8(cmd.argument()), true);
342                 break;
343
344         case LFUN_FILE_OPEN:
345                 if (viewCount() == 0
346                     || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
347                         createView();
348                         current_view_->openDocument(to_utf8(cmd.argument()));
349                         if (!current_view_->buffer())
350                                 current_view_->close();
351                 } else
352                         current_view_->openDocument(to_utf8(cmd.argument()));
353                 break;
354
355         default:
356                 // Notify the caller that the action has not been dispatched.
357                 return false;
358         }
359
360         // The action has been dispatched.
361         return true;
362 }
363
364
365 void GuiApplication::resetGui()
366 {
367         map<int, GuiView *>::iterator it;
368         for (it = views_.begin(); it != views_.end(); ++it)
369                 it->second->resetDialogs();
370
371         dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
372 }
373
374
375 static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
376 {
377         ids.clear();
378         map<int, GuiView *>::const_iterator it;
379         for (it = stdmap.begin(); it != stdmap.end(); ++it)
380                 ids.push_back(it->first);
381 }
382
383
384 void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
385 {
386         // release the keyboard which might have been grabed by the global
387         // menubar on Mac to catch shortcuts even without any GuiView.
388         if (global_menubar_)
389                 global_menubar_->releaseKeyboard();
390
391         // create new view
392         updateIds(views_, view_ids_);
393         int id = 0;
394         while (views_.find(id) != views_.end())
395                 id++;
396         GuiView * view = new GuiView(id);
397         
398         // copy the icon size from old view
399         if (viewCount() > 0)
400                 view->setIconSize(current_view_->iconSize());
401
402         // register view
403         views_[id] = view;
404         updateIds(views_, view_ids_);
405
406         if (autoShow) {
407                 view->show();
408                 setActiveWindow(view);
409         }
410
411         if (!geometry_arg.isEmpty()) {
412 #ifdef Q_WS_WIN
413                 int x, y;
414                 int w, h;
415                 QRegExp re( "[=]*(?:([0-9]+)[xX]([0-9]+)){0,1}[ ]*(?:([+-][0-9]*)([+-][0-9]*)){0,1}" );
416                 re.indexIn(geometry_arg);
417                 w = re.cap(1).toInt();
418                 h = re.cap(2).toInt();
419                 x = re.cap(3).toInt();
420                 y = re.cap(4).toInt();
421                 view->setGeometry(x, y, w, h);
422 #endif
423         }
424         view->setFocus();
425         setCurrentView(view);
426 }
427
428
429
430
431 Clipboard & GuiApplication::clipboard()
432 {
433         return clipboard_;
434 }
435
436
437 Selection & GuiApplication::selection()
438 {
439         return selection_;
440 }
441
442
443 int GuiApplication::exec()
444 {
445         QTimer::singleShot(1, this, SLOT(execBatchCommands()));
446         return QApplication::exec();
447 }
448
449
450 void GuiApplication::exit(int status)
451 {
452         QApplication::exit(status);
453 }
454
455
456 void GuiApplication::execBatchCommands()
457 {
458         LyX::ref().execBatchCommands();
459 }
460
461
462 void GuiApplication::restoreGuiSession()
463 {
464         if (!lyxrc.load_session)
465                 return;
466
467         Session & session = LyX::ref().session();
468         vector<FileName> const & lastopened = session.lastOpened().getfiles();
469         // do not add to the lastfile list since these files are restored from
470         // last session, and should be already there (regular files), or should
471         // not be added at all (help files).
472         for_each(lastopened.begin(), lastopened.end(),
473                 bind(&GuiView::loadDocument, current_view_, _1, false));
474
475         // clear this list to save a few bytes of RAM
476         session.lastOpened().clear();
477 }
478
479
480 QString const GuiApplication::romanFontName()
481 {
482         QFont font;
483         font.setKerning(false);
484         font.setStyleHint(QFont::Serif);
485         font.setFamily("serif");
486
487         return QFontInfo(font).family();
488 }
489
490
491 QString const GuiApplication::sansFontName()
492 {
493         QFont font;
494         font.setKerning(false);
495         font.setStyleHint(QFont::SansSerif);
496         font.setFamily("sans");
497
498         return QFontInfo(font).family();
499 }
500
501
502 QString const GuiApplication::typewriterFontName()
503 {
504         QFont font;
505         font.setKerning(false);
506         font.setStyleHint(QFont::TypeWriter);
507         font.setFamily("monospace");
508
509         return QFontInfo(font).family();
510 }
511
512
513 void GuiApplication::handleRegularEvents()
514 {
515         ForkedCallsController::handleCompletedProcesses();
516 }
517
518
519 bool GuiApplication::event(QEvent * e)
520 {
521         switch(e->type()) {
522         case QEvent::FileOpen: {
523                 // Open a file; this happens only on Mac OS X for now
524                 QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
525
526                 if (!current_view_ || !current_view_->view())
527                         // The application is not properly initialized yet.
528                         // So we acknowledge the event and delay the file opening
529                         // until LyX is ready.
530                         // FIXME UNICODE: FileName accept an utf8 encoded string.
531                         LyX::ref().addFileToLoad(fromqstr(foe->file()));
532                 else
533                         lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
534                                 qstring_to_ucs4(foe->file())));
535
536                 e->accept();
537                 return true;
538         }
539         default:
540                 return QApplication::event(e);
541         }
542 }
543
544
545 bool GuiApplication::notify(QObject * receiver, QEvent * event)
546 {
547         try {
548                 return QApplication::notify(receiver, event);
549         }
550         catch (ExceptionMessage const & e) {
551                 switch(e.type_) { 
552                 case ErrorException:
553                         LyX::cref().emergencyCleanup();
554                         setQuitOnLastWindowClosed(false);
555                         closeAllViews();
556                         Alert::error(e.title_, e.details_);
557 #ifndef NDEBUG
558                         // Properly crash in debug mode in order to get a useful backtrace.
559                         abort();
560 #endif
561                         // In release mode, try to exit gracefully.
562                         this->exit(1);
563
564                 case BufferException: {
565                         Buffer * buf = current_view_->buffer();
566                         docstring details = e.details_ + '\n';
567                         details += theBufferList().emergencyWrite(buf);
568                         theBufferList().release(buf);
569                         details += "\n" + _("The current document was closed.");
570                         Alert::error(e.title_, details);
571                         return false;
572                 }
573                 case WarningException:
574                         Alert::warning(e.title_, e.details_);
575                         return false;
576                 };
577         }
578         catch (exception const & e) {
579                 docstring s = _("LyX has caught an exception, it will now "
580                         "attempt to save all unsaved documents and exit."
581                         "\n\nException: ");
582                 s += from_ascii(e.what());
583                 Alert::error(_("Software exception Detected"), s);
584                 LyX::cref().exit(1);
585         }
586         catch (...) {
587                 docstring s = _("LyX has caught some really weird exception, it will "
588                         "now attempt to save all unsaved documents and exit.");
589                 Alert::error(_("Software exception Detected"), s);
590                 LyX::cref().exit(1);
591         }
592
593         return false;
594 }
595
596
597 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
598 {
599         QColor const & qcol = color_cache_.get(col);
600         if (!qcol.isValid()) {
601                 rgbcol.r = 0;
602                 rgbcol.g = 0;
603                 rgbcol.b = 0;
604                 return false;
605         }
606         rgbcol.r = qcol.red();
607         rgbcol.g = qcol.green();
608         rgbcol.b = qcol.blue();
609         return true;
610 }
611
612
613 string const GuiApplication::hexName(ColorCode col)
614 {
615         return ltrim(fromqstr(color_cache_.get(col).name()), "#");
616 }
617
618
619 void GuiApplication::updateColor(ColorCode)
620 {
621         // FIXME: Bleh, can't we just clear them all at once ?
622         color_cache_.clear();
623 }
624
625
626 void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
627 {
628         SocketNotifier * sn = new SocketNotifier(this, fd, func);
629         socket_notifiers_[fd] = sn;
630         connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
631 }
632
633
634 void GuiApplication::socketDataReceived(int fd)
635 {
636         socket_notifiers_[fd]->func_();
637 }
638
639
640 void GuiApplication::unregisterSocketCallback(int fd)
641 {
642         socket_notifiers_.erase(fd);
643 }
644
645
646 void GuiApplication::commitData(QSessionManager & sm)
647 {
648         /// The implementation is required to avoid an application exit
649         /// when session state save is triggered by session manager.
650         /// The default implementation sends a close event to all
651         /// visible top level widgets when session managment allows
652         /// interaction.
653         /// We are changing that to close all wiew one by one.
654         /// FIXME: verify if the default implementation is enough now.
655         if (sm.allowsInteraction() && !closeAllViews())
656                 sm.cancel();
657 }
658
659
660 void GuiApplication::addMenuTranslator()
661 {
662         installTranslator(new MenuTranslator(this));
663 }
664
665
666 bool GuiApplication::unregisterView(int id)
667 {
668         updateIds(views_, view_ids_);
669         BOOST_ASSERT(views_.find(id) != views_.end());
670         BOOST_ASSERT(views_[id]);
671
672         map<int, GuiView *>::iterator it;
673         for (it = views_.begin(); it != views_.end(); ++it) {
674                 if (it->first == id) {
675                         views_.erase(id);
676                         break;
677                 }
678         }
679         updateIds(views_, view_ids_);
680         return true;
681 }
682
683
684 bool GuiApplication::closeAllViews()
685 {
686         updateIds(views_, view_ids_);
687         if (views_.empty())
688                 return true;
689
690         map<int, GuiView*> const cmap = views_;
691         map<int, GuiView*>::const_iterator it;
692         for (it = cmap.begin(); it != cmap.end(); ++it) {
693                 if (!it->second->close())
694                         return false;
695         }
696
697         views_.clear();
698         view_ids_.clear();
699         return true;
700 }
701
702
703 GuiView & GuiApplication::view(int id) const
704 {
705         BOOST_ASSERT(views_.find(id) != views_.end());
706         return *views_.find(id)->second;
707 }
708
709
710 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
711 {
712         vector<int>::const_iterator it = view_ids_.begin();
713         vector<int>::const_iterator const end = view_ids_.end();
714         for (; it != end; ++it)
715                 view(*it).hideDialog(name, inset);
716 }
717
718
719 Buffer const * GuiApplication::updateInset(Inset const * inset) const
720 {
721         Buffer const * buffer_ = 0;
722         vector<int>::const_iterator it = view_ids_.begin();
723         vector<int>::const_iterator const end = view_ids_.end();
724         for (; it != end; ++it) {
725                 Buffer const * ptr = view(*it).updateInset(inset);
726                 if (ptr)
727                         buffer_ = ptr;
728         }
729         return buffer_;
730 }
731
732
733 void GuiApplication::readMenus(Lexer & lex)
734 {
735         menus().read(lex);
736 }
737
738
739 bool GuiApplication::searchMenu(FuncRequest const & func,
740         vector<docstring> & names) const
741 {
742         return menus().searchMenu(func, names);
743 }
744
745
746 void GuiApplication::initGlobalMenu()
747 {
748         if (global_menubar_)
749                 menus().fillMenuBar(global_menubar_, 0, true);
750 }
751
752
753 void GuiApplication::onLastWindowClosed()
754 {
755         if (global_menubar_)
756                 global_menubar_->grabKeyboard();
757 }
758
759 ////////////////////////////////////////////////////////////////////////
760 // X11 specific stuff goes here...
761 #ifdef Q_WS_X11
762 bool GuiApplication::x11EventFilter(XEvent * xev)
763 {
764         if (!current_view_)
765                 return false;
766
767         switch (xev->type) {
768         case SelectionRequest: {
769                 if (xev->xselectionrequest.selection != XA_PRIMARY)
770                         break;
771                 LYXERR(Debug::GUI, "X requested selection.");
772                 BufferView * bv = current_view_->view();
773                 if (bv) {
774                         docstring const sel = bv->requestSelection();
775                         if (!sel.empty())
776                                 selection_.put(sel);
777                 }
778                 break;
779         }
780         case SelectionClear: {
781                 if (xev->xselectionclear.selection != XA_PRIMARY)
782                         break;
783                 LYXERR(Debug::GUI, "Lost selection.");
784                 BufferView * bv = current_view_->view();
785                 if (bv)
786                         bv->clearSelection();
787                 break;
788         }
789         }
790         return false;
791 }
792 #endif
793
794 } // namespace frontend
795
796
797 ////////////////////////////////////////////////////////////////////
798 //
799 // Font stuff
800 //
801 ////////////////////////////////////////////////////////////////////
802
803 frontend::FontLoader & theFontLoader()
804 {
805         BOOST_ASSERT(frontend::guiApp);
806         return frontend::guiApp->fontLoader();
807 }
808
809
810 frontend::FontMetrics const & theFontMetrics(Font const & f)
811 {
812         return theFontMetrics(f.fontInfo());
813 }
814
815
816 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
817 {
818         BOOST_ASSERT(frontend::guiApp);
819         return frontend::guiApp->fontLoader().metrics(f);
820 }
821
822
823 frontend::Clipboard & theClipboard()
824 {
825         BOOST_ASSERT(frontend::guiApp);
826         return frontend::guiApp->clipboard();
827 }
828
829
830 frontend::Selection & theSelection()
831 {
832         BOOST_ASSERT(frontend::guiApp);
833         return frontend::guiApp->selection();
834 }
835
836 } // namespace lyx
837
838 #include "GuiApplication_moc.cpp"