]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.cpp
use GuiApplication::languageModel() in GuiDocument.cpp
[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 }
476
477
478 void GuiApplication::restoreGuiSession()
479 {
480         if (!lyxrc.load_session)
481                 return;
482
483         Session & session = LyX::ref().session();
484         vector<FileName> const & lastopened = session.lastOpened().getfiles();
485         // do not add to the lastfile list since these files are restored from
486         // last session, and should be already there (regular files), or should
487         // not be added at all (help files).
488         for_each(lastopened.begin(), lastopened.end(),
489                 bind(&GuiView::loadDocument, current_view_, _1, false));
490
491         // clear this list to save a few bytes of RAM
492         session.lastOpened().clear();
493 }
494
495
496 QString const GuiApplication::romanFontName()
497 {
498         QFont font;
499         font.setKerning(false);
500         font.setStyleHint(QFont::Serif);
501         font.setFamily("serif");
502
503         return QFontInfo(font).family();
504 }
505
506
507 QString const GuiApplication::sansFontName()
508 {
509         QFont font;
510         font.setKerning(false);
511         font.setStyleHint(QFont::SansSerif);
512         font.setFamily("sans");
513
514         return QFontInfo(font).family();
515 }
516
517
518 QString const GuiApplication::typewriterFontName()
519 {
520         QFont font;
521         font.setKerning(false);
522         font.setStyleHint(QFont::TypeWriter);
523         font.setFamily("monospace");
524
525         return QFontInfo(font).family();
526 }
527
528
529 void GuiApplication::handleRegularEvents()
530 {
531         ForkedCallsController::handleCompletedProcesses();
532 }
533
534
535 bool GuiApplication::event(QEvent * e)
536 {
537         switch(e->type()) {
538         case QEvent::FileOpen: {
539                 // Open a file; this happens only on Mac OS X for now
540                 QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
541
542                 if (!current_view_ || !current_view_->view())
543                         // The application is not properly initialized yet.
544                         // So we acknowledge the event and delay the file opening
545                         // until LyX is ready.
546                         // FIXME UNICODE: FileName accept an utf8 encoded string.
547                         LyX::ref().addFileToLoad(fromqstr(foe->file()));
548                 else
549                         lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
550                                 qstring_to_ucs4(foe->file())));
551
552                 e->accept();
553                 return true;
554         }
555         default:
556                 return QApplication::event(e);
557         }
558 }
559
560
561 bool GuiApplication::notify(QObject * receiver, QEvent * event)
562 {
563         try {
564                 return QApplication::notify(receiver, event);
565         }
566         catch (ExceptionMessage const & e) {
567                 switch(e.type_) { 
568                 case ErrorException:
569                         LyX::cref().emergencyCleanup();
570                         setQuitOnLastWindowClosed(false);
571                         closeAllViews();
572                         Alert::error(e.title_, e.details_);
573 #ifndef NDEBUG
574                         // Properly crash in debug mode in order to get a useful backtrace.
575                         abort();
576 #endif
577                         // In release mode, try to exit gracefully.
578                         this->exit(1);
579
580                 case BufferException: {
581                         Buffer * buf = current_view_->buffer();
582                         docstring details = e.details_ + '\n';
583                         details += theBufferList().emergencyWrite(buf);
584                         theBufferList().release(buf);
585                         details += "\n" + _("The current document was closed.");
586                         Alert::error(e.title_, details);
587                         return false;
588                 }
589                 case WarningException:
590                         Alert::warning(e.title_, e.details_);
591                         return false;
592                 }
593         }
594         catch (exception const & e) {
595                 docstring s = _("LyX has caught an exception, it will now "
596                         "attempt to save all unsaved documents and exit."
597                         "\n\nException: ");
598                 s += from_ascii(e.what());
599                 Alert::error(_("Software exception Detected"), s);
600                 LyX::cref().exit(1);
601         }
602         catch (...) {
603                 docstring s = _("LyX has caught some really weird exception, it will "
604                         "now attempt to save all unsaved documents and exit.");
605                 Alert::error(_("Software exception Detected"), s);
606                 LyX::cref().exit(1);
607         }
608
609         return false;
610 }
611
612
613 bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
614 {
615         QColor const & qcol = color_cache_.get(col);
616         if (!qcol.isValid()) {
617                 rgbcol.r = 0;
618                 rgbcol.g = 0;
619                 rgbcol.b = 0;
620                 return false;
621         }
622         rgbcol.r = qcol.red();
623         rgbcol.g = qcol.green();
624         rgbcol.b = qcol.blue();
625         return true;
626 }
627
628
629 string const GuiApplication::hexName(ColorCode col)
630 {
631         return ltrim(fromqstr(color_cache_.get(col).name()), "#");
632 }
633
634
635 void GuiApplication::updateColor(ColorCode)
636 {
637         // FIXME: Bleh, can't we just clear them all at once ?
638         color_cache_.clear();
639 }
640
641
642 void GuiApplication::registerSocketCallback(int fd, SocketCallback func)
643 {
644         SocketNotifier * sn = new SocketNotifier(this, fd, func);
645         socket_notifiers_[fd] = sn;
646         connect(sn, SIGNAL(activated(int)), this, SLOT(socketDataReceived(int)));
647 }
648
649
650 void GuiApplication::socketDataReceived(int fd)
651 {
652         socket_notifiers_[fd]->func_();
653 }
654
655
656 void GuiApplication::unregisterSocketCallback(int fd)
657 {
658         socket_notifiers_.erase(fd);
659 }
660
661
662 void GuiApplication::commitData(QSessionManager & sm)
663 {
664         /// The implementation is required to avoid an application exit
665         /// when session state save is triggered by session manager.
666         /// The default implementation sends a close event to all
667         /// visible top level widgets when session managment allows
668         /// interaction.
669         /// We are changing that to close all wiew one by one.
670         /// FIXME: verify if the default implementation is enough now.
671         if (sm.allowsInteraction() && !closeAllViews())
672                 sm.cancel();
673 }
674
675
676 void GuiApplication::addMenuTranslator()
677 {
678         installTranslator(new MenuTranslator(this));
679 }
680
681
682 bool GuiApplication::unregisterView(int id)
683 {
684         updateIds(views_, view_ids_);
685         LASSERT(views_.find(id) != views_.end(), /**/);
686         LASSERT(views_[id], /**/);
687
688         map<int, GuiView *>::iterator it;
689         for (it = views_.begin(); it != views_.end(); ++it) {
690                 if (it->first == id) {
691                         views_.erase(id);
692                         break;
693                 }
694         }
695         updateIds(views_, view_ids_);
696         return true;
697 }
698
699
700 bool GuiApplication::closeAllViews()
701 {
702         updateIds(views_, view_ids_);
703         if (views_.empty())
704                 return true;
705
706         map<int, GuiView*> const cmap = views_;
707         map<int, GuiView*>::const_iterator it;
708         for (it = cmap.begin(); it != cmap.end(); ++it) {
709                 if (!it->second->close())
710                         return false;
711         }
712
713         views_.clear();
714         view_ids_.clear();
715         return true;
716 }
717
718
719 GuiView & GuiApplication::view(int id) const
720 {
721         LASSERT(views_.find(id) != views_.end(), /**/);
722         return *views_.find(id)->second;
723 }
724
725
726 void GuiApplication::hideDialogs(string const & name, Inset * inset) const
727 {
728         vector<int>::const_iterator it = view_ids_.begin();
729         vector<int>::const_iterator const end = view_ids_.end();
730         for (; it != end; ++it)
731                 view(*it).hideDialog(name, inset);
732 }
733
734
735 Buffer const * GuiApplication::updateInset(Inset const * inset) const
736 {
737         Buffer const * buffer_ = 0;
738         vector<int>::const_iterator it = view_ids_.begin();
739         vector<int>::const_iterator const end = view_ids_.end();
740         for (; it != end; ++it) {
741                 Buffer const * ptr = view(*it).updateInset(inset);
742                 if (ptr)
743                         buffer_ = ptr;
744         }
745         return buffer_;
746 }
747
748
749 void GuiApplication::readMenus(Lexer & lex)
750 {
751         menus().read(lex);
752 }
753
754
755 bool GuiApplication::searchMenu(FuncRequest const & func,
756         vector<docstring> & names) const
757 {
758         return menus().searchMenu(func, names);
759 }
760
761
762 void GuiApplication::initGlobalMenu()
763 {
764         if (global_menubar_)
765                 menus().fillMenuBar(global_menubar_, 0, true);
766 }
767
768
769 void GuiApplication::onLastWindowClosed()
770 {
771         if (global_menubar_)
772                 global_menubar_->grabKeyboard();
773 }
774
775
776 ////////////////////////////////////////////////////////////////////////
777 //
778 // X11 specific stuff goes here...
779
780 #ifdef Q_WS_X11
781 bool GuiApplication::x11EventFilter(XEvent * xev)
782 {
783         if (!current_view_)
784                 return false;
785
786         switch (xev->type) {
787         case SelectionRequest: {
788                 if (xev->xselectionrequest.selection != XA_PRIMARY)
789                         break;
790                 LYXERR(Debug::GUI, "X requested selection.");
791                 BufferView * bv = current_view_->view();
792                 if (bv) {
793                         docstring const sel = bv->requestSelection();
794                         if (!sel.empty())
795                                 selection_.put(sel);
796                 }
797                 break;
798         }
799         case SelectionClear: {
800                 if (xev->xselectionclear.selection != XA_PRIMARY)
801                         break;
802                 LYXERR(Debug::GUI, "Lost selection.");
803                 BufferView * bv = current_view_->view();
804                 if (bv)
805                         bv->clearSelection();
806                 break;
807         }
808         }
809         return false;
810 }
811 #endif
812
813 } // namespace frontend
814
815
816 void hideDialogs(std::string const & name, Inset * inset)
817 {
818         if (theApp())
819                 theApp()->hideDialogs(name, inset);
820 }
821
822
823 ////////////////////////////////////////////////////////////////////
824 //
825 // Font stuff
826 //
827 ////////////////////////////////////////////////////////////////////
828
829 frontend::FontLoader & theFontLoader()
830 {
831         LASSERT(frontend::guiApp, /**/);
832         return frontend::guiApp->fontLoader();
833 }
834
835
836 frontend::FontMetrics const & theFontMetrics(Font const & f)
837 {
838         return theFontMetrics(f.fontInfo());
839 }
840
841
842 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
843 {
844         LASSERT(frontend::guiApp, /**/);
845         return frontend::guiApp->fontLoader().metrics(f);
846 }
847
848
849 ////////////////////////////////////////////////////////////////////
850 //
851 // Misc stuff
852 //
853 ////////////////////////////////////////////////////////////////////
854
855 frontend::Clipboard & theClipboard()
856 {
857         LASSERT(frontend::guiApp, /**/);
858         return frontend::guiApp->clipboard();
859 }
860
861
862 frontend::Selection & theSelection()
863 {
864         LASSERT(frontend::guiApp, /**/);
865         return frontend::guiApp->selection();
866 }
867
868 } // namespace lyx
869
870 #include "GuiApplication_moc.cpp"