2 * \file GuiApplication.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
13 #ifndef GUIAPPLICATION_H
14 #define GUIAPPLICATION_H
16 #include "ColorCache.h"
17 #include "GuiFontLoader.h"
18 #include "GuiClipboard.h"
19 #include "GuiSelection.h"
22 #include "frontends/Application.h"
25 #include <QApplication>
26 #include <QTranslator>
31 class QSessionManager;
44 /// The Qt main application class
46 There should be only one instance of this class. No Qt object
47 initialisation should be done before the instanciation of this class.
49 class GuiApplication : public QApplication, public Application
54 GuiApplication(int & argc, char ** argv);
56 virtual ~GuiApplication();
58 /// Method inherited from \c Application class
60 virtual FuncStatus getStatus(FuncRequest const &);
61 virtual bool dispatch(FuncRequest const &);
62 virtual void resetGui();
63 virtual Clipboard & clipboard();
64 virtual Selection & selection();
65 virtual FontLoader & fontLoader() { return font_loader_; }
66 MenuBackend const & menuBackend() const { return menus_; }
67 MenuBackend & menuBackend() { return menus_; }
69 virtual void exit(int status);
70 virtual bool event(QEvent * e);
71 virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
72 virtual std::string const hexName(ColorCode col);
73 virtual void updateColor(ColorCode col);
74 virtual void registerSocketCallback(int fd, SocketCallback func);
75 void unregisterSocketCallback(int fd);
78 Menus const & menus() const { return menus_; }
79 Menus & menus() { return menus_; }
80 /// Methods inherited from \c QApplication class
82 bool notify(QObject * receiver, QEvent * event);
83 void commitData(QSessionManager & sm);
86 /// Create the main window with given geometry settings.
87 /// \param geometry_arg: only for Windows platform.
88 void createView(QString const & geometry_arg);
90 GuiView const * currentView() const { return current_view_; }
92 GuiView * currentView() { return current_view_; }
94 void setCurrentView(GuiView & view) { current_view_ = &view; }
96 virtual size_t viewCount() const { return view_ids_.size(); }
98 std::vector<int> const & viewIds() { return view_ids_; }
101 ColorCache & colorCache() { return color_cache_; }
103 GuiFontLoader & guiFontLoader() { return font_loader_; }
105 /// return a suitable serif font name.
106 virtual QString const romanFontName();
108 /// return a suitable sans serif font name.
109 virtual QString const sansFontName();
111 /// return a suitable monospaced font name.
112 virtual QString const typewriterFontName();
114 virtual bool unregisterView(int id);
116 virtual GuiView & view(int id) const;
118 virtual void hideDialogs(std::string const & name, Inset * inset) const;
120 virtual Buffer const * updateInset(Inset const * inset) const;
124 void execBatchCommands();
126 void socketDataReceived(int fd);
130 bool closeAllViews();
132 GuiClipboard clipboard_;
134 GuiSelection selection_;
136 GuiFontLoader font_loader_;
138 ColorCache color_cache_;
140 QTranslator qt_trans_;
142 std::map<int, SocketNotifier *> socket_notifiers_;
148 bool x11EventFilter(XEvent * ev);
150 /// A translator suitable for the entries in the LyX menu.
151 /// Only needed with Qt/Mac.
152 void addMenuTranslator();
154 /// Multiple views container.
156 * Warning: This must not be a smart pointer as the destruction of the
157 * object is handled by Qt when the view is closed
158 * \sa Qt::WA_DeleteOnClose attribute.
160 std::map<int, GuiView *> views_;
162 std::vector<int> view_ids_;
163 /// This LyXView is the one receiving Clipboard and Selection
165 GuiView * current_view_;
168 extern GuiApplication * guiApp;
170 } // namespace frontend
173 #endif // GUIAPPLICATION_H