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>
27 #include <QTranslator>
32 class QSessionManager;
46 /// The Qt main application class
48 There should be only one instance of this class. No Qt object
49 initialisation should be done before the instanciation of this class.
51 class GuiApplication : public QApplication, public Application
56 GuiApplication(int & argc, char ** argv);
58 virtual ~GuiApplication();
60 /// Method inherited from \c Application class
62 virtual FuncStatus getStatus(FuncRequest const &);
63 virtual bool dispatch(FuncRequest const &);
64 virtual void resetGui();
65 void restoreGuiSession();
66 virtual Clipboard & clipboard();
67 virtual Selection & selection();
68 virtual FontLoader & fontLoader() { return font_loader_; }
70 virtual void exit(int status);
71 virtual bool event(QEvent * e);
72 virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
73 virtual std::string const hexName(ColorCode col);
74 virtual void updateColor(ColorCode col);
75 virtual void readMenus(Lexer & lex);
76 virtual void initGlobalMenu();
77 virtual void registerSocketCallback(int fd, SocketCallback func);
78 void unregisterSocketCallback(int fd);
79 bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
82 Menus const & menus() const { return menus_; }
83 Menus & menus() { return menus_; }
84 /// Methods inherited from \c QApplication class
86 bool notify(QObject * receiver, QEvent * event);
87 void commitData(QSessionManager & sm);
90 /// Create the main window with given geometry settings.
91 /// \param geometry_arg: only for Windows platform.
92 void createView(QString const & geometry_arg = QString(),
93 bool autoShow = true);
95 GuiView const * currentView() const { return current_view_; }
97 GuiView * currentView() { return current_view_; }
99 void setCurrentView(GuiView & view) { current_view_ = &view; }
101 virtual size_t viewCount() const { return view_ids_.size(); }
103 std::vector<int> const & viewIds() { return view_ids_; }
106 ColorCache & colorCache() { return color_cache_; }
108 GuiFontLoader & guiFontLoader() { return font_loader_; }
110 /// return a suitable serif font name.
111 virtual QString const romanFontName();
113 /// return a suitable sans serif font name.
114 virtual QString const sansFontName();
116 /// return a suitable monospaced font name.
117 virtual QString const typewriterFontName();
119 virtual bool unregisterView(int id);
121 virtual GuiView & view(int id) const;
123 virtual void hideDialogs(std::string const & name, Inset * inset) const;
125 virtual Buffer const * updateInset(Inset const * inset) const;
129 void execBatchCommands();
131 void socketDataReceived(int fd);
132 /// events to be triggered by general_timer_ should go here
133 void handleRegularEvents();
135 void onLastWindowClosed();
139 bool closeAllViews();
141 GuiClipboard clipboard_;
143 GuiSelection selection_;
145 GuiFontLoader font_loader_;
147 ColorCache color_cache_;
149 QTranslator qt_trans_;
151 std::map<int, SocketNotifier *> socket_notifiers_;
154 /// this timer is used for any regular events one wants to
155 /// perform. at present it is used to check if forked processes
157 QTimer general_timer_;
161 bool x11EventFilter(XEvent * ev);
163 /// A translator suitable for the entries in the LyX menu.
164 /// Only needed with Qt/Mac.
165 void addMenuTranslator();
167 /// Multiple views container.
169 * Warning: This must not be a smart pointer as the destruction of the
170 * object is handled by Qt when the view is closed
171 * \sa Qt::WA_DeleteOnClose attribute.
173 std::map<int, GuiView *> views_;
175 std::vector<int> view_ids_;
176 /// This LyXView is the one receiving Clipboard and Selection
178 GuiView * current_view_;
180 GlobalMenuBar * global_menubar_;
183 extern GuiApplication * guiApp;
185 } // namespace frontend
188 #endif // GUIAPPLICATION_H