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