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"
21 #include "frontends/Application.h"
23 #include "MenuBackend.h"
26 #include <QApplication>
27 #include <QTranslator>
32 class QSessionManager;
45 /// The Qt main application class
47 There should be only one instance of this class. No Qt object
48 initialisation should be done before the instanciation of this class.
50 class GuiApplication : public QApplication, public Application
55 GuiApplication(int & argc, char ** argv);
57 virtual ~GuiApplication();
59 /// Method inherited from \c Application class
61 virtual FuncStatus getStatus(FuncRequest const &);
62 virtual bool dispatch(FuncRequest const &);
63 virtual void resetGui();
64 virtual Clipboard & clipboard();
65 virtual Selection & selection();
66 virtual FontLoader & fontLoader() { return font_loader_; }
67 MenuBackend const & menuBackend() const { return menu_backend_; }
68 MenuBackend & menuBackend() { return menu_backend_; }
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 registerSocketCallback(int fd, SocketCallback func);
76 void unregisterSocketCallback(int fd);
79 /// Methods inherited from \c QApplication class
81 bool notify(QObject * receiver, QEvent * event);
82 void commitData(QSessionManager & sm);
85 /// Create the main window with given geometry settings.
86 /// \param geometry_arg: only for Windows platform.
87 void createView(QString const & geometry_arg);
89 GuiView const * currentView() const { return current_view_; }
91 GuiView * currentView() { return current_view_; }
93 void setCurrentView(GuiView & view) { current_view_ = &view; }
95 virtual size_t viewCount() const { return view_ids_.size(); }
97 std::vector<int> const & viewIds() { return view_ids_; }
100 ColorCache & colorCache() { return color_cache_; }
102 GuiFontLoader & guiFontLoader() { return font_loader_; }
104 /// return a suitable serif font name.
105 virtual QString const romanFontName();
107 /// return a suitable sans serif font name.
108 virtual QString const sansFontName();
110 /// return a suitable monospaced font name.
111 virtual QString const typewriterFontName();
113 virtual bool unregisterView(int id);
115 virtual GuiView & view(int id) const;
117 virtual void hideDialogs(std::string const & name, Inset * inset) const;
119 virtual Buffer const * updateInset(Inset const * inset) const;
123 void execBatchCommands();
125 void socketDataReceived(int fd);
129 bool closeAllViews();
131 GuiClipboard clipboard_;
133 GuiSelection selection_;
135 GuiFontLoader font_loader_;
137 ColorCache color_cache_;
139 QTranslator qt_trans_;
141 std::map<int, SocketNotifier *> socket_notifiers_;
143 MenuBackend menu_backend_;
147 bool x11EventFilter(XEvent * ev);
149 /// A translator suitable for the entries in the LyX menu.
150 /// Only needed with Qt/Mac.
151 void addMenuTranslator();
153 /// Multiple views container.
155 * Warning: This must not be a smart pointer as the destruction of the
156 * object is handled by Qt when the view is closed
157 * \sa Qt::WA_DeleteOnClose attribute.
159 std::map<int, GuiView *> views_;
161 std::vector<int> view_ids_;
162 /// This LyXView is the one receiving Clipboard and Selection
164 GuiView * current_view_;
167 extern GuiApplication * guiApp;
169 } // namespace frontend
172 #endif // GUIAPPLICATION_H