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