From 43ccb47f20c8533670a55247fe0a121e5f6d9087 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 7 Feb 2011 17:03:32 +0200 Subject: [PATCH] [Windows] Added About and Preferences into System menu --- qt/mainwindow.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ qt/mainwindow.hpp | 4 ++++ 2 files changed, 50 insertions(+) diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index 2bc55c585d..f110c9bc1b 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -24,6 +24,9 @@ #include "../base/start_mem_debug.hpp" +#define IDM_ABOUT_DIALOG 1001 +#define IDM_PREFERENCES_DIALOG 1002 + namespace qt { @@ -45,11 +48,54 @@ MainWindow::MainWindow() : m_updateDialog(0) menuBar()->addMenu(helpMenu); helpMenu->addAction(tr("About"), this, SLOT(OnAbout())); helpMenu->addAction(tr("Preferences"), this, SLOT(OnPreferences())); +#else + { // create items in the system menu + QByteArray const aboutStr = tr("About MapsWithMe...").toLocal8Bit(); + QByteArray const prefsStr = tr("Preferences...").toLocal8Bit(); + // we use system menu for our items + HMENU menu = ::GetSystemMenu(winId(), FALSE); + MENUITEMINFOA item; + item.cbSize = sizeof(MENUITEMINFOA); + item.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING; + item.fType = MFT_STRING; + item.wID = IDM_PREFERENCES_DIALOG; + item.dwTypeData = const_cast(prefsStr.data()); + item.cch = prefsStr.size(); + ::InsertMenuItemA(menu, ::GetMenuItemCount(menu) - 1, TRUE, &item); + item.wID = IDM_ABOUT_DIALOG; + item.dwTypeData = const_cast(aboutStr.data()); + item.cch = aboutStr.size(); + ::InsertMenuItemA(menu, ::GetMenuItemCount(menu) - 1, TRUE, &item); + item.fType = MFT_SEPARATOR; + ::InsertMenuItemA(menu, ::GetMenuItemCount(menu) - 1, TRUE, &item); + } #endif LoadState(); } +#if defined(Q_WS_WIN) +bool MainWindow::winEvent(MSG * msg, long * result) +{ + if (msg->message == WM_SYSCOMMAND) + { + if (msg->wParam == IDM_PREFERENCES_DIALOG) + { + OnPreferences(); + *result = 0; + return true; + } + else if (msg->wParam == IDM_ABOUT_DIALOG) + { + OnAbout(); + *result = 0; + return true; + } + } + return false; +} +#endif + MainWindow::~MainWindow() { SaveState(); diff --git a/qt/mainwindow.hpp b/qt/mainwindow.hpp index 8c41f0eaeb..3ba37d0ed4 100644 --- a/qt/mainwindow.hpp +++ b/qt/mainwindow.hpp @@ -38,6 +38,10 @@ namespace qt void CreateClassifPanel(); void CreateNavigationBar(); //void CreateFindTable(QLayout * pLayout); + #if defined(Q_WS_WIN) + /// to handle menu messages + virtual bool winEvent(MSG * msg, long * result); + #endif protected Q_SLOTS: //void OnFeatureEntered(int row, int col);