2006-06-26 17:18:28 +00:00
|
|
|
/**
|
2007-08-31 22:16:11 +00:00
|
|
|
* \file GuiApplication.h
|
2006-06-26 17:18:28 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author unknown
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#ifndef GUIAPPLICATION_H
|
|
|
|
#define GUIAPPLICATION_H
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
#include "frontends/Application.h"
|
2014-10-18 13:50:22 +00:00
|
|
|
#include "support/filetools.h"
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
#include <QApplication>
|
2008-05-23 18:09:40 +00:00
|
|
|
#include <QList>
|
2015-04-07 10:59:41 +00:00
|
|
|
#ifdef QPA_XCB
|
|
|
|
#include <QAbstractNativeEventFilter>
|
|
|
|
#endif
|
2007-11-17 20:47:50 +00:00
|
|
|
|
2008-05-14 10:34:19 +00:00
|
|
|
class QAbstractItemModel;
|
2014-08-24 19:40:40 +00:00
|
|
|
class QIcon;
|
|
|
|
class QSessionManager;
|
2007-08-27 06:35:24 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
class BufferView;
|
2008-05-23 08:43:07 +00:00
|
|
|
class ColorCache;
|
2009-10-04 20:58:20 +00:00
|
|
|
class KeySymbol;
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2011-01-16 20:38:08 +00:00
|
|
|
namespace support {
|
|
|
|
class FileName;
|
|
|
|
}
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-17 20:47:50 +00:00
|
|
|
class GuiView;
|
2006-06-26 17:18:28 +00:00
|
|
|
class GuiWorkArea;
|
2008-05-23 08:43:07 +00:00
|
|
|
class Menus;
|
2007-09-15 20:31:50 +00:00
|
|
|
class SocketNotifier;
|
2008-05-25 08:30:06 +00:00
|
|
|
class Toolbars;
|
2006-06-26 17:18:28 +00:00
|
|
|
|
|
|
|
/// The Qt main application class
|
|
|
|
/**
|
|
|
|
There should be only one instance of this class. No Qt object
|
2010-11-04 15:35:12 +00:00
|
|
|
initialisation should be done before the instantiation of this class.
|
2006-06-26 17:18:28 +00:00
|
|
|
*/
|
2006-09-22 09:47:39 +00:00
|
|
|
class GuiApplication : public QApplication, public Application
|
2015-04-07 10:59:41 +00:00
|
|
|
#ifdef QPA_XCB
|
|
|
|
, public QAbstractNativeEventFilter
|
|
|
|
#endif
|
2006-06-26 17:18:28 +00:00
|
|
|
{
|
2006-10-23 16:29:24 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
public:
|
2006-09-22 09:47:39 +00:00
|
|
|
GuiApplication(int & argc, char ** argv);
|
2008-05-23 07:52:39 +00:00
|
|
|
~GuiApplication();
|
2006-09-22 09:47:39 +00:00
|
|
|
|
2010-01-27 18:10:33 +00:00
|
|
|
/// \name Methods inherited from Application class
|
2006-09-22 09:47:39 +00:00
|
|
|
//@{
|
2010-02-09 16:11:13 +00:00
|
|
|
void dispatch(FuncRequest const &);
|
2009-10-04 20:58:20 +00:00
|
|
|
void dispatch(FuncRequest const &, DispatchResult & dr);
|
2010-02-09 16:11:13 +00:00
|
|
|
FuncStatus getStatus(FuncRequest const & cmd) const;
|
2008-02-06 23:02:57 +00:00
|
|
|
void restoreGuiSession();
|
2010-10-22 17:53:09 +00:00
|
|
|
Buffer const * updateInset(Inset const * inset) const;
|
2008-05-23 08:43:07 +00:00
|
|
|
int exec();
|
|
|
|
void exit(int status);
|
|
|
|
bool event(QEvent * e);
|
|
|
|
bool getRgbColor(ColorCode col, RGBColor & rgbcol);
|
|
|
|
std::string const hexName(ColorCode col);
|
|
|
|
void registerSocketCallback(int fd, SocketCallback func);
|
2006-12-02 17:39:31 +00:00
|
|
|
void unregisterSocketCallback(int fd);
|
2008-05-24 10:15:52 +00:00
|
|
|
bool searchMenu(FuncRequest const & func, docstring_list & names) const;
|
2009-10-04 20:58:20 +00:00
|
|
|
void handleKeyFunc(FuncCode action);
|
2006-09-22 09:47:39 +00:00
|
|
|
//@}
|
2010-10-22 17:53:09 +00:00
|
|
|
|
2010-02-09 17:25:44 +00:00
|
|
|
///
|
Refactor GuiApplication::getStatus().
* I didn't like the fact that the heart of the dispatch/status machinery is in the default clause of a long switch statement. Now, it is clear that we enter the app in getStatus, which then asks the GuiApplication itself, the GuiView, the current BufferView, the current Buffer, the document BufferView, the document Buffer,
* Shouldn't we let BufferView call the Buffer getStatus() functions ?,
* This also makes sure that if a command is not handled, it is turned off. Before r34164 this was caused by the default clause in BufferView,
* Now it is prevented that if the document BufferView is the same as the current BufferView, that the getStatus() functions are called twice,
* A warning can be outputted if the LFUN is not handled.
PS I want to do the same for the dispatch function.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34165 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-16 16:04:35 +00:00
|
|
|
bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
|
|
|
|
///
|
2010-02-09 17:25:44 +00:00
|
|
|
void hideDialogs(std::string const & name, Inset * inset) const;
|
|
|
|
///
|
|
|
|
void resetGui();
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
|
|
|
Clipboard & clipboard();
|
|
|
|
///
|
|
|
|
Selection & selection();
|
|
|
|
///
|
|
|
|
FontLoader & fontLoader();
|
|
|
|
|
|
|
|
///
|
2008-05-25 08:30:06 +00:00
|
|
|
Toolbars const & toolbars() const;
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
2008-05-25 08:30:06 +00:00
|
|
|
Toolbars & toolbars();
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
2008-05-23 08:43:07 +00:00
|
|
|
Menus const & menus() const;
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
2008-05-23 08:43:07 +00:00
|
|
|
Menus & menus();
|
2010-01-27 18:10:33 +00:00
|
|
|
|
|
|
|
/// \name Methods inherited from QApplication class
|
2007-04-01 16:06:43 +00:00
|
|
|
//@{
|
2007-08-27 06:35:24 +00:00
|
|
|
bool notify(QObject * receiver, QEvent * event);
|
|
|
|
void commitData(QSessionManager & sm);
|
2008-05-23 07:52:39 +00:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
bool x11EventFilter(XEvent * ev);
|
2015-04-07 10:59:41 +00:00
|
|
|
#elif defined(QPA_XCB)
|
|
|
|
virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
|
2008-05-23 07:52:39 +00:00
|
|
|
#endif
|
2007-04-01 16:06:43 +00:00
|
|
|
//@}
|
|
|
|
|
2007-11-24 08:51:11 +00:00
|
|
|
/// Create the main window with given geometry settings.
|
|
|
|
/// \param geometry_arg: only for Windows platform.
|
2008-06-19 11:28:11 +00:00
|
|
|
/// \param optional id identifier.
|
2008-03-14 23:33:05 +00:00
|
|
|
void createView(QString const & geometry_arg = QString(),
|
2008-06-19 11:28:11 +00:00
|
|
|
bool autoShow = true, int id = 0);
|
|
|
|
/// FIXME: this method and the one above are quite ugly.
|
|
|
|
void createView(int id);
|
2007-11-18 20:36:52 +00:00
|
|
|
///
|
|
|
|
GuiView const * currentView() const { return current_view_; }
|
|
|
|
///
|
|
|
|
GuiView * currentView() { return current_view_; }
|
|
|
|
///
|
2008-03-15 02:42:59 +00:00
|
|
|
void setCurrentView(GuiView * view) { current_view_ = view; }
|
2007-11-18 20:36:52 +00:00
|
|
|
///
|
2008-05-23 18:09:40 +00:00
|
|
|
QList<int> viewIds() const;
|
2011-01-16 20:38:08 +00:00
|
|
|
|
2010-10-22 17:53:09 +00:00
|
|
|
/// Clear all session information.
|
|
|
|
void clearSession();
|
2007-11-17 22:25:42 +00:00
|
|
|
|
2006-09-26 09:57:47 +00:00
|
|
|
///
|
2008-05-23 08:43:07 +00:00
|
|
|
ColorCache & colorCache();
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
2008-05-14 10:34:19 +00:00
|
|
|
QAbstractItemModel * languageModel();
|
2008-05-08 09:03:38 +00:00
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
/// return a suitable serif font name.
|
2008-05-23 08:43:07 +00:00
|
|
|
QString const romanFontName();
|
2007-11-17 20:47:50 +00:00
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
/// return a suitable sans serif font name.
|
2008-05-23 08:43:07 +00:00
|
|
|
QString const sansFontName();
|
2007-11-18 20:36:52 +00:00
|
|
|
|
|
|
|
/// return a suitable monospaced font name.
|
2008-05-23 08:43:07 +00:00
|
|
|
QString const typewriterFontName();
|
2007-11-17 20:47:50 +00:00
|
|
|
///
|
2008-05-23 10:54:34 +00:00
|
|
|
void unregisterView(GuiView * gv);
|
2007-11-17 20:47:50 +00:00
|
|
|
///
|
2008-05-23 08:43:07 +00:00
|
|
|
GuiView & view(int id) const;
|
2014-10-12 17:23:13 +00:00
|
|
|
|
|
|
|
/// Current ratio between physical pixels and device-independent pixels
|
|
|
|
double pixelRatio() const;
|
2014-10-18 13:50:22 +00:00
|
|
|
|
|
|
|
/// How to load image files
|
|
|
|
support::search_mode imageSearchMode() const {
|
|
|
|
#if QT_VERSION >= 0x050000
|
2014-10-20 15:15:23 +00:00
|
|
|
return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
|
2014-10-18 13:50:22 +00:00
|
|
|
#else
|
|
|
|
return support::must_exist;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-10-04 20:58:20 +00:00
|
|
|
void processKeySym(KeySymbol const & key, KeyModifier state);
|
|
|
|
/// return the status bar state string
|
|
|
|
docstring viewStatusMessage();
|
2007-11-17 20:47:50 +00:00
|
|
|
|
2010-10-22 18:08:21 +00:00
|
|
|
/// \name Methods to process FuncRequests
|
|
|
|
//@{
|
|
|
|
/// process the func request
|
|
|
|
void processFuncRequest(FuncRequest const &);
|
|
|
|
/// add a func request to the queue and process it asynchronously
|
|
|
|
/// \note As a side-effect this will also process the
|
|
|
|
/// func requests that were added to the queue before.
|
|
|
|
void processFuncRequestAsync(FuncRequest const &);
|
|
|
|
/// process the func requests in the queue
|
|
|
|
void processFuncRequestQueue();
|
|
|
|
/// process the func requests in the queue asynchronously
|
2010-10-22 15:46:46 +00:00
|
|
|
void processFuncRequestQueueAsync();
|
2010-10-22 18:08:21 +00:00
|
|
|
/// add a func request to the queue for later processing
|
|
|
|
void addToFuncRequestQueue(FuncRequest const &);
|
|
|
|
//@}
|
2010-10-22 15:46:46 +00:00
|
|
|
|
2010-02-09 16:11:13 +00:00
|
|
|
/// goto a bookmark
|
|
|
|
/// openFile: whether or not open a file if the file is not opened
|
|
|
|
/// switchToBuffer: whether or not switch to buffer if the buffer is
|
|
|
|
/// not the current buffer
|
|
|
|
void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
|
|
|
|
|
2012-03-06 23:21:12 +00:00
|
|
|
/// Start a long operation with some cancel possibility (button or ESC)
|
|
|
|
void startLongOperation();
|
|
|
|
/// This needs to be periodically called to avoid freezing the GUI
|
|
|
|
bool longOperationCancelled();
|
|
|
|
/// Stop the long operation mode (i.e., release the GUI)
|
|
|
|
void stopLongOperation();
|
2012-07-01 07:27:11 +00:00
|
|
|
/// A started long operation is still in progress ?
|
|
|
|
bool longOperationStarted();
|
2006-11-26 02:18:32 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
///
|
|
|
|
void execBatchCommands();
|
2007-09-15 20:31:50 +00:00
|
|
|
///
|
|
|
|
void socketDataReceived(int fd);
|
2010-10-22 17:53:09 +00:00
|
|
|
/// events to be triggered by Private::general_timer_ should go here
|
2008-02-05 13:10:42 +00:00
|
|
|
void handleRegularEvents();
|
2008-03-14 23:25:11 +00:00
|
|
|
///
|
|
|
|
void onLastWindowClosed();
|
2008-11-15 16:29:58 +00:00
|
|
|
///
|
2010-10-22 18:08:21 +00:00
|
|
|
void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
|
2008-11-15 16:29:58 +00:00
|
|
|
|
2006-09-22 09:47:39 +00:00
|
|
|
private:
|
2011-01-18 15:22:10 +00:00
|
|
|
///
|
|
|
|
void validateCurrentView();
|
2007-11-25 18:18:23 +00:00
|
|
|
///
|
2012-04-13 00:57:25 +00:00
|
|
|
void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
|
|
|
|
///
|
2007-11-25 18:18:23 +00:00
|
|
|
bool closeAllViews();
|
2015-04-06 11:50:32 +00:00
|
|
|
/// Things that need to be done when the OSes session manager
|
|
|
|
/// requests a log out.
|
|
|
|
bool prepareAllViewsForLogout();
|
2008-05-24 09:28:05 +00:00
|
|
|
/// read the given ui (menu/toolbar) file
|
2008-05-24 09:51:17 +00:00
|
|
|
bool readUIFile(QString const & name, bool include = false);
|
2008-07-28 11:26:46 +00:00
|
|
|
///
|
2011-01-16 20:38:08 +00:00
|
|
|
enum ReturnValues {
|
|
|
|
ReadOK,
|
|
|
|
ReadError,
|
|
|
|
FormatMismatch
|
|
|
|
};
|
|
|
|
///
|
|
|
|
ReturnValues readUIFile(support::FileName);
|
|
|
|
///
|
2008-07-28 11:26:46 +00:00
|
|
|
void setGuiLanguage();
|
2010-04-07 12:50:47 +00:00
|
|
|
///
|
|
|
|
void reconfigure(std::string const & option);
|
2008-05-24 09:28:05 +00:00
|
|
|
|
2010-02-09 17:06:40 +00:00
|
|
|
/// This GuiView is the one receiving Clipboard and Selection
|
2007-11-18 20:36:52 +00:00
|
|
|
/// events
|
|
|
|
GuiView * current_view_;
|
2010-02-09 16:11:13 +00:00
|
|
|
|
2008-05-23 07:52:39 +00:00
|
|
|
///
|
|
|
|
struct Private;
|
|
|
|
Private * const d;
|
2006-09-22 09:47:39 +00:00
|
|
|
}; // GuiApplication
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
extern GuiApplication * guiApp;
|
|
|
|
|
2008-06-05 08:31:22 +00:00
|
|
|
/// \return the icon file name for the given action.
|
|
|
|
QString iconName(FuncRequest const & f, bool unknown);
|
|
|
|
|
2009-04-03 17:00:09 +00:00
|
|
|
/// \return the pixmap for the given path, name and extension.
|
|
|
|
QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
|
|
|
|
|
2008-06-05 08:31:22 +00:00
|
|
|
/// \return an icon for the given action.
|
|
|
|
QIcon getIcon(FuncRequest const & f, bool unknown);
|
|
|
|
|
2010-10-22 17:53:09 +00:00
|
|
|
///
|
2008-11-16 12:22:54 +00:00
|
|
|
GuiApplication * theGuiApp();
|
2008-11-16 01:20:34 +00:00
|
|
|
|
2006-06-26 17:18:28 +00:00
|
|
|
} // namespace frontend
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
2006-06-26 17:18:28 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#endif // GUIAPPLICATION_H
|