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