* create global menubar on Mac without a parent. It will be shown if no GuiView exists.

* fill global menubar with the normal actions
* capture the keyboard on the menubar if no GuiView exists. This
  enables the shortcuts on Mac in those cases.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23731 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-14 23:25:11 +00:00
parent fda541d46a
commit d63821939c
4 changed files with 68 additions and 7 deletions

View File

@ -877,7 +877,12 @@ bool LyX::init()
// This must happen after package initialization and after lyxrc is
// read, therefore it can't be done by a static object.
ConverterCache::init();
// init the global menubar on Mac. This must be done after the session
// was recovered to know the "last files".
if (use_gui)
theApp()->initGlobalMenu();
return true;
}

View File

@ -219,6 +219,11 @@ public:
*/
virtual void readMenus(Lexer & lex) = 0;
/**
* initialize the global menubar on Mac
*/
virtual void initGlobalMenu() = 0;
/**
* add a callback for socket read notification
* @param fd socket descriptor (file/socket/etc)

View File

@ -16,6 +16,7 @@
#include "qt_helpers.h"
#include "GuiImage.h"
#include "GuiKeySymbol.h"
#include "GuiView.h"
#include "frontends/alert.h"
@ -121,6 +122,27 @@ public:
}
};
class GlobalMenuBar : public QMenuBar
{
public:
///
GlobalMenuBar() : QMenuBar(0) {}
///
bool event(QEvent * e)
{
if (e->type() == QEvent::ShortcutOverride) {
// && activeWindow() == 0) {
QKeyEvent * ke = static_cast<QKeyEvent*>(e);
KeySymbol sym;
setKeySymbol(&sym, ke);
theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
e->accept();
return true;
}
return false;
}
};
///////////////////////////////////////////////////////////////
// You can find more platform specific stuff
@ -132,7 +154,7 @@ GuiApplication * guiApp;
GuiApplication::GuiApplication(int & argc, char ** argv)
: QApplication(argc, argv), Application(), current_view_(0)
: QApplication(argc, argv), Application(), current_view_(0), global_menubar_(0)
{
QString app_name = "LyX";
QCoreApplication::setOrganizationName(app_name);
@ -146,7 +168,10 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
if (lyxrc.quit_on_last_window_closed)
setQuitOnLastWindowClosed(false);
*/
#ifdef Q_WS_MAC
setQuitOnLastWindowClosed(false);
#endif
#ifdef Q_WS_X11
// doubleClickInterval() is 400 ms on X11 which is just too long.
// On Windows and Mac OS X, the operating system's value is used.
@ -175,11 +200,10 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
<< fromqstr(language_name));
#ifdef Q_WS_MACX
// all windows in a Mac application share the same menu bar.
QMenuBar *menuBar = new QMenuBar(0);
// This allows to translate the strings that appear in the LyX menu.
addMenuTranslator();
#endif
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
using namespace lyx::graphics;
@ -210,6 +234,14 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
connect(&general_timer_, SIGNAL(timeout()),
this, SLOT(handleRegularEvents()));
general_timer_.start();
#ifdef Q_WS_MACX
if (global_menubar_ == 0) {
// Create the global default menubar which is shown for the dialogs
// and if no GuiView is visible.
global_menubar_ = new GlobalMenuBar();
}
#endif
}
@ -697,6 +729,19 @@ bool GuiApplication::searchMenu(FuncRequest const & func,
}
void GuiApplication::initGlobalMenu()
{
if (global_menubar_)
menus().fillMenuBar(global_menubar_, 0);
}
void GuiApplication::onLastWindowClosed()
{
if (global_menubar_)
global_menubar_->grabKeyboard();
}
////////////////////////////////////////////////////////////////////////
// X11 specific stuff goes here...
#ifdef Q_WS_X11

View File

@ -39,6 +39,7 @@ namespace frontend {
class GuiView;
class LyXView;
class GlobalMenuBar;
class GuiWorkArea;
class SocketNotifier;
@ -72,6 +73,7 @@ public:
virtual std::string const hexName(ColorCode col);
virtual void updateColor(ColorCode col);
virtual void readMenus(Lexer & lex);
virtual void initGlobalMenu();
virtual void registerSocketCallback(int fd, SocketCallback func);
void unregisterSocketCallback(int fd);
bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
@ -87,7 +89,7 @@ public:
/// Create the main window with given geometry settings.
/// \param geometry_arg: only for Windows platform.
void createView(QString const & geometry_arg);
void createView(QString const & geometry_arg = QString());
///
GuiView const * currentView() const { return current_view_; }
///
@ -128,7 +130,9 @@ private Q_SLOTS:
void socketDataReceived(int fd);
/// events to be triggered by general_timer_ should go here
void handleRegularEvents();
///
void onLastWindowClosed();
private:
///
bool closeAllViews();
@ -171,6 +175,8 @@ public:
/// This LyXView is the one receiving Clipboard and Selection
/// events
GuiView * current_view_;
/// only used on mac
GlobalMenuBar * global_menubar_;
}; // GuiApplication
extern GuiApplication * guiApp;