2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-03-25 12:23:30 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-03-25 12:23:30 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-03-25 12:23:30 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-03-25 12:23:30 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "MacSysMenu.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
2006-10-21 10:58:22 +00:00
|
|
|
#include "BOINCBaseFrame.h"
|
2011-07-07 13:28:50 +00:00
|
|
|
#include "MainDocument.h"
|
2005-03-25 12:23:30 +00:00
|
|
|
#include "MacSysMenu.h"
|
|
|
|
#include "DlgAbout.h"
|
|
|
|
#include "Events.h"
|
2006-10-30 15:12:12 +00:00
|
|
|
#include "miofile.h"
|
|
|
|
#include "SkinManager.h"
|
2005-04-26 15:03:51 +00:00
|
|
|
#include "wx/mac/private.h" // for wxBitmapRefData::GetPictHandle
|
2005-06-23 11:58:09 +00:00
|
|
|
|
2005-03-25 12:23:30 +00:00
|
|
|
pascal OSStatus SysMenuEventHandler( EventHandlerCallRef inHandlerCallRef,
|
|
|
|
EventRef inEvent, void* pData);
|
|
|
|
|
|
|
|
EventTypeSpec myEvents[] = { {kEventClassCommand, kEventCommandProcess},
|
2005-07-06 05:16:53 +00:00
|
|
|
{ kEventClassApplication, kEventAppHidden},
|
|
|
|
{ kEventClassApplication, kEventAppShown},
|
2005-03-25 12:23:30 +00:00
|
|
|
{kEventClassMenu, kEventMenuOpening} };
|
|
|
|
|
2006-10-30 15:12:12 +00:00
|
|
|
|
2007-01-18 12:30:49 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
|
|
|
|
2007-01-18 12:48:09 +00:00
|
|
|
// Class declarations copied from wxMac-2.8.0/src/mac/carbon/taskbar.cpp
|
|
|
|
// We had to copy these because they are not in a header file.
|
|
|
|
|
2007-01-18 12:30:49 +00:00
|
|
|
class wxTaskBarIconImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTaskBarIconImpl(wxTaskBarIcon* parent);
|
|
|
|
virtual ~wxTaskBarIconImpl();
|
|
|
|
|
|
|
|
virtual bool IsIconInstalled() const = 0;
|
2008-06-24 01:09:09 +00:00
|
|
|
virtual bool SetIcon(const wxIcon& icon) = 0;
|
2007-01-18 12:30:49 +00:00
|
|
|
virtual bool RemoveIcon() = 0;
|
|
|
|
virtual bool PopupMenu(wxMenu *menu) = 0;
|
|
|
|
|
|
|
|
wxMenu * CreatePopupMenu()
|
|
|
|
{ return m_parent->CreatePopupMenu(); }
|
|
|
|
|
|
|
|
wxTaskBarIcon *m_parent;
|
|
|
|
class wxTaskBarIconWindow *m_menuEventWindow;
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxTaskBarIconImpl)
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// wxTaskBarIconWindow
|
|
|
|
//
|
|
|
|
// Event handler for menus
|
|
|
|
// NB: Since wxWindows in Mac HAVE to have parents we need this to be
|
|
|
|
// a top level window...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxTaskBarIconWindow : public wxTopLevelWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxTaskBarIconWindow(wxTaskBarIconImpl *impl)
|
|
|
|
: wxTopLevelWindow(NULL, wxID_ANY, wxEmptyString), m_impl(impl)
|
|
|
|
{
|
|
|
|
Connect(
|
|
|
|
-1, wxEVT_COMMAND_MENU_SELECTED,
|
|
|
|
wxCommandEventHandler(wxTaskBarIconWindow::OnMenuEvent) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnMenuEvent(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_impl->m_parent->ProcessEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxTaskBarIconImpl *m_impl;
|
|
|
|
};
|
|
|
|
|
|
|
|
class wxDockTaskBarIcon : public wxTaskBarIconImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDockTaskBarIcon(wxTaskBarIcon* parent);
|
|
|
|
virtual ~wxDockTaskBarIcon();
|
|
|
|
|
|
|
|
virtual bool IsIconInstalled() const;
|
2008-06-24 01:09:09 +00:00
|
|
|
virtual bool SetIcon(const wxIcon& icon);
|
2007-01-18 12:30:49 +00:00
|
|
|
virtual bool RemoveIcon();
|
|
|
|
virtual bool PopupMenu(wxMenu *menu);
|
|
|
|
|
|
|
|
wxMenu* DoCreatePopupMenu();
|
|
|
|
|
|
|
|
EventHandlerRef m_eventHandlerRef;
|
|
|
|
EventHandlerUPP m_eventupp;
|
|
|
|
wxWindow *m_eventWindow;
|
|
|
|
wxMenu *m_pMenu;
|
|
|
|
MenuRef m_theLastMenu;
|
|
|
|
bool m_iconAdded;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-01-19 14:30:18 +00:00
|
|
|
|
2006-07-06 10:52:57 +00:00
|
|
|
CMacSystemMenu::CMacSystemMenu(wxString title, wxIcon* icon, wxIcon* iconDisconnected, wxIcon* iconSnooze)
|
|
|
|
: CTaskBarIcon(title, icon, iconDisconnected, iconSnooze) {
|
2007-01-19 14:30:18 +00:00
|
|
|
CFBundleRef SysMenuBundle = NULL;
|
2005-03-25 12:23:30 +00:00
|
|
|
|
2011-07-08 08:26:11 +00:00
|
|
|
m_bOpeningAboutDlg = false;
|
|
|
|
m_bNeedRebuildMenu = false;
|
2005-07-06 05:16:53 +00:00
|
|
|
|
2005-03-25 12:23:30 +00:00
|
|
|
LoadPrivateFrameworkBundle( CFSTR("SystemMenu.bundle"), &SysMenuBundle );
|
|
|
|
if ( SysMenuBundle != NULL )
|
|
|
|
{
|
|
|
|
SetUpSystemMenu = (SetUpSystemMenuProc)
|
|
|
|
CFBundleGetFunctionPointerForName( SysMenuBundle, CFSTR("SetUpSystemMenu") );
|
|
|
|
SetSystemMenuIcon = (SetSystemMenuIconProc)
|
|
|
|
CFBundleGetFunctionPointerForName( SysMenuBundle, CFSTR("SetSystemMenuIcon") );
|
2006-10-30 15:12:12 +00:00
|
|
|
|
|
|
|
BuildMenu();
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
// The base class wxTaskBarIcon will install the wxDockEventHandler for
|
|
|
|
// each instance of the derived classes CTaskBarIcon and CMacSystemMenu.
|
2005-07-21 11:23:06 +00:00
|
|
|
// We remove that handler and substitute our own.
|
2007-01-18 12:30:49 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
|
|
|
RemoveEventHandler((EventHandlerRef&)(((wxDockTaskBarIcon*)m_impl)->m_eventHandlerRef));
|
2007-01-19 14:30:18 +00:00
|
|
|
|
2007-01-18 12:30:49 +00:00
|
|
|
InstallApplicationEventHandler(NewEventHandlerUPP(SysMenuEventHandler),
|
|
|
|
sizeof(myEvents) / sizeof(EventTypeSpec), myEvents,
|
|
|
|
this, (EventHandlerRef*)&(((wxDockTaskBarIcon*)m_impl)->m_eventHandlerRef));
|
|
|
|
#else
|
2005-07-21 11:23:06 +00:00
|
|
|
RemoveEventHandler((EventHandlerRef&)m_pEventHandlerRef);
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
InstallApplicationEventHandler(NewEventHandlerUPP(SysMenuEventHandler),
|
|
|
|
sizeof(myEvents) / sizeof(EventTypeSpec), myEvents,
|
2005-11-04 03:14:33 +00:00
|
|
|
this, (EventHandlerRef*)&m_pEventHandlerRef);
|
2007-01-18 12:30:49 +00:00
|
|
|
#endif
|
2005-03-25 12:23:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-21 11:23:06 +00:00
|
|
|
CMacSystemMenu::~CMacSystemMenu() {
|
2006-10-30 14:12:22 +00:00
|
|
|
// Remove the System Menu (StatusItem) from menu bar
|
|
|
|
if (SetSystemMenuIcon != NULL )
|
|
|
|
SetSystemMenuIcon(NULL);
|
2005-03-25 12:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the System Menu Icon from XPM data
|
2008-06-24 01:09:09 +00:00
|
|
|
bool CMacSystemMenu::SetIcon(const wxIcon& icon) {
|
2006-01-12 03:32:15 +00:00
|
|
|
wxBitmap theBits;
|
2006-07-06 11:44:47 +00:00
|
|
|
|
2011-07-08 08:26:11 +00:00
|
|
|
// For unknown reasons, menus won't work if we call BuildMenu() directly
|
|
|
|
// from CTaskBarIcon::OnReloadSkin(), so it sets a flag to call it here
|
|
|
|
if (m_bNeedRebuildMenu) {
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
if (pDoc->IsConnected() && m_bNeedRebuildMenu) {
|
2011-07-07 13:28:50 +00:00
|
|
|
// For unknown reasons, Menubar Icon menu doesn't work without this
|
|
|
|
BuildMenu();
|
|
|
|
}
|
2011-07-08 08:26:11 +00:00
|
|
|
}
|
|
|
|
m_bNeedRebuildMenu = false;
|
|
|
|
|
|
|
|
theBits.CopyFromIcon(icon);
|
|
|
|
CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate();
|
|
|
|
if ( (SetSystemMenuIcon != NULL) && (imageRef != NULL) ) {
|
2007-12-19 11:38:05 +00:00
|
|
|
SetSystemMenuIcon(imageRef);
|
|
|
|
CGImageRelease( imageRef );
|
2006-01-12 03:32:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-12-19 11:38:05 +00:00
|
|
|
|
|
|
|
if(imageRef != NULL) CGImageRelease( imageRef );
|
|
|
|
|
2006-01-12 03:32:15 +00:00
|
|
|
return false;
|
2005-03-25 12:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-30 15:12:12 +00:00
|
|
|
void CMacSystemMenu::BuildMenu() {
|
|
|
|
wxBitmap theBits;
|
2007-01-18 12:30:49 +00:00
|
|
|
wxMenu *themenu;
|
2006-10-30 15:12:12 +00:00
|
|
|
CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
|
|
|
|
|
|
|
|
wxASSERT(pSkinAdvanced);
|
|
|
|
wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
|
|
|
|
|
|
|
|
m_iconTaskBarNormal = *pSkinAdvanced->GetApplicationIcon();
|
|
|
|
m_iconTaskBarDisconnected = *pSkinAdvanced->GetApplicationDisconnectedIcon();
|
|
|
|
m_iconTaskBarSnooze = *pSkinAdvanced->GetApplicationSnoozeIcon();
|
|
|
|
|
|
|
|
theBits.CopyFromIcon(m_iconTaskBarNormal);
|
2007-12-19 11:38:05 +00:00
|
|
|
CGImageRef imageRef = (CGImageRef)theBits.CGImageCreate();
|
|
|
|
if ( (SetUpSystemMenu != NULL ) && (imageRef != NULL) ) {
|
2006-10-30 15:12:12 +00:00
|
|
|
// Currently, the system menu is the same as the Dock menu with the addition of
|
|
|
|
// the Quit menu item. If in the future you wish to make the system menu different
|
|
|
|
// from the Dock menu, override CTaskBarIcon::BuildContextMenu() and
|
|
|
|
// CTaskBarIcon::AdjustMenuItems().
|
2007-01-18 12:30:49 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
|
|
|
delete ((wxDockTaskBarIcon*)m_impl)->m_pMenu;
|
|
|
|
((wxDockTaskBarIcon*)m_impl)->m_pMenu = BuildContextMenu();
|
|
|
|
themenu = ((wxDockTaskBarIcon*)m_impl)->m_pMenu;
|
|
|
|
#else
|
2006-10-30 15:12:12 +00:00
|
|
|
delete m_pMenu;
|
|
|
|
m_pMenu = BuildContextMenu();
|
2007-01-18 12:30:49 +00:00
|
|
|
themenu = m_pMenu;
|
|
|
|
#endif
|
|
|
|
|
2006-10-30 15:12:12 +00:00
|
|
|
// These should appear in the Mac System Menu but not the Dock
|
2007-01-18 12:30:49 +00:00
|
|
|
themenu->AppendSeparator();
|
|
|
|
themenu->Append( wxID_EXIT, _("E&xit"), wxEmptyString );
|
2006-10-30 15:12:12 +00:00
|
|
|
|
2007-01-18 12:30:49 +00:00
|
|
|
themenu->SetEventHandler(this);
|
2006-10-30 15:12:12 +00:00
|
|
|
|
2007-12-19 11:38:05 +00:00
|
|
|
SetUpSystemMenu((MenuRef)(themenu->GetHMenu()), imageRef);
|
2006-10-30 15:12:12 +00:00
|
|
|
}
|
2007-12-19 11:38:05 +00:00
|
|
|
if(imageRef != NULL) CGImageRelease( imageRef );
|
2006-10-30 15:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-19 14:30:18 +00:00
|
|
|
#if wxCHECK_VERSION(2,8,0)
|
|
|
|
|
|
|
|
wxMenu* CMacSystemMenu::GetCurrentMenu() {
|
|
|
|
return ((wxDockTaskBarIcon*)m_impl)->m_pMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-03-25 12:23:30 +00:00
|
|
|
// Utility routine to load a bundle from the application's Frameworks folder.
|
|
|
|
// i.e. : "BOINC.app/Contents/Frameworks/SystemMenu.bundle"
|
2005-07-21 11:23:06 +00:00
|
|
|
void CMacSystemMenu::LoadPrivateFrameworkBundle( CFStringRef framework, CFBundleRef *bundlePtr ) {
|
2005-03-25 12:23:30 +00:00
|
|
|
CFURLRef baseURL = NULL;
|
|
|
|
CFURLRef bundleURL = NULL;
|
|
|
|
CFBundleRef myAppsBundle = NULL;
|
|
|
|
|
|
|
|
if ( bundlePtr == NULL ) goto Bail;
|
|
|
|
*bundlePtr = NULL;
|
|
|
|
|
|
|
|
myAppsBundle = CFBundleGetMainBundle(); // Get our application's main bundle from Core Foundation
|
|
|
|
if ( myAppsBundle == NULL ) goto Bail;
|
|
|
|
|
|
|
|
baseURL = CFBundleCopyPrivateFrameworksURL( myAppsBundle );
|
|
|
|
if ( baseURL == NULL ) goto Bail;
|
|
|
|
|
|
|
|
bundleURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, baseURL, framework, false );
|
|
|
|
if ( bundleURL == NULL ) goto Bail;
|
|
|
|
|
|
|
|
*bundlePtr = CFBundleCreate( kCFAllocatorSystemDefault, bundleURL );
|
|
|
|
if ( *bundlePtr == NULL ) goto Bail;
|
|
|
|
|
|
|
|
if ( ! CFBundleLoadExecutable( *bundlePtr ) )
|
|
|
|
{
|
|
|
|
CFRelease( *bundlePtr );
|
|
|
|
*bundlePtr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bail: // Clean up.
|
|
|
|
if ( bundleURL != NULL ) CFRelease( bundleURL );
|
|
|
|
if ( baseURL != NULL ) CFRelease( baseURL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pascal OSStatus SysMenuEventHandler( EventHandlerCallRef inHandlerCallRef,
|
2005-07-21 11:23:06 +00:00
|
|
|
EventRef inEvent, void* pData) {
|
2005-03-25 12:23:30 +00:00
|
|
|
HICommand command;
|
|
|
|
MenuRef baseMenuRef, sysMenuRef;
|
|
|
|
Str255 theMenuTitle;
|
|
|
|
short i, n, m;
|
|
|
|
CharParameter markChar;
|
|
|
|
const UInt32 eventClass = GetEventClass(inEvent);
|
|
|
|
const UInt32 eventKind = GetEventKind(inEvent);
|
|
|
|
CMacSystemMenu* pMSM;
|
|
|
|
wxMenu* baseMenu;
|
|
|
|
MenuCommand commandID;
|
2005-07-21 11:23:06 +00:00
|
|
|
MenuItemIndex menuItemIndex;
|
|
|
|
wxMenuItem* item = NULL;
|
|
|
|
OSStatus err;
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
switch (eventClass) {
|
|
|
|
case kEventClassCommand:
|
|
|
|
if (eventKind != kEventCommandProcess)
|
|
|
|
return eventNotHandledErr;
|
|
|
|
|
|
|
|
GetEventParameter (inEvent, kEventParamDirectObject,
|
|
|
|
typeHICommand, NULL, sizeof(HICommand), NULL, &command);
|
|
|
|
|
2005-07-21 11:23:06 +00:00
|
|
|
commandID = command.commandID;
|
|
|
|
if (commandID == 0)
|
2005-03-25 12:23:30 +00:00
|
|
|
return eventNotHandledErr;
|
2005-07-06 05:16:53 +00:00
|
|
|
|
2007-01-18 12:30:49 +00:00
|
|
|
pMSM = wxGetApp().GetMacSystemMenu();
|
2008-11-18 13:28:26 +00:00
|
|
|
if (!pMSM) break;
|
2005-07-06 05:16:53 +00:00
|
|
|
|
2007-01-19 14:30:18 +00:00
|
|
|
// wxMac "helpfully" converts wxID_ABOUT to kHICommandAbout, wxID_EXIT to kHICommandQuit,
|
2006-05-01 23:35:27 +00:00
|
|
|
// wxID_PREFERENCES to kHICommandPreferences
|
|
|
|
switch (commandID) {
|
|
|
|
case kHICommandAbout:
|
|
|
|
commandID = wxID_ABOUT;
|
|
|
|
break;
|
|
|
|
case kHICommandPreferences:
|
2009-04-01 11:14:16 +00:00
|
|
|
{
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2009-10-16 21:29:25 +00:00
|
|
|
wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, ID_PREFERENCES);
|
2009-04-01 11:14:16 +00:00
|
|
|
pFrame->AddPendingEvent(evt);
|
|
|
|
return noErr ;
|
|
|
|
}
|
2006-05-01 23:35:27 +00:00
|
|
|
case kHICommandQuit:
|
2007-06-24 09:24:52 +00:00
|
|
|
if (wxGetApp().ConfirmExit()) {
|
|
|
|
commandID = wxID_EXIT;
|
|
|
|
} else {
|
|
|
|
commandID = 0;
|
|
|
|
return noErr;
|
|
|
|
}
|
2006-05-01 23:35:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-21 11:23:06 +00:00
|
|
|
if (commandID == wxID_ABOUT)
|
2005-07-06 05:16:53 +00:00
|
|
|
pMSM->SetOpeningAboutDlg(true);
|
|
|
|
|
2005-03-25 12:23:30 +00:00
|
|
|
// If not our system menu, pass event on to next event handler
|
2007-10-31 10:40:19 +00:00
|
|
|
if (command.menu.menuRef != (MenuRef)'BNC!') { // Used only in OS 10.5
|
|
|
|
if (PLstrcmp("\pBOINC!", (GetMenuTitle((command.menu.menuRef), theMenuTitle) ))) {
|
|
|
|
return eventNotHandledErr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-21 11:23:06 +00:00
|
|
|
// The following code is adapted from wxTaskBarIcon's wxDockEventHandler().
|
|
|
|
// Work with our base menu instead of the cloned System Menu
|
2005-03-25 12:23:30 +00:00
|
|
|
baseMenu = (pMSM->GetCurrentMenu());
|
|
|
|
baseMenuRef = (MenuRef)(baseMenu->GetHMenu());
|
2005-07-21 11:23:06 +00:00
|
|
|
|
2006-05-01 23:35:27 +00:00
|
|
|
err = GetIndMenuItemWithCommandID(baseMenuRef, command.commandID, 1, NULL, &menuItemIndex);
|
2005-07-21 11:23:06 +00:00
|
|
|
if (err)
|
|
|
|
return eventNotHandledErr; // Command not found in our menu
|
|
|
|
|
|
|
|
GetMenuItemRefCon( baseMenuRef, menuItemIndex, (UInt32*) &item ) ;
|
|
|
|
|
|
|
|
if ( item )
|
|
|
|
{
|
|
|
|
if (item->IsCheckable())
|
|
|
|
item->Check( !item->IsChecked() );
|
|
|
|
|
|
|
|
item->GetMenu()->SendEvent( commandID , item->IsCheckable() ? item->IsChecked() : -1 );
|
2007-01-19 14:30:18 +00:00
|
|
|
|
|
|
|
// Under wxWidgets 2.8.0, the task bar icons must be deleted for app to
|
|
|
|
// exit its main loop
|
|
|
|
// Note that if the main window is open, CBOINCBaseFrame::OnExit() will be
|
|
|
|
// called and SysMenuEventHandler() (i.e., this code) will not be called.
|
|
|
|
if (commandID == wxID_EXIT) {
|
2008-11-18 13:28:26 +00:00
|
|
|
wxGetApp().DeleteTaskBarIcon();
|
2007-01-19 14:30:18 +00:00
|
|
|
}
|
2005-07-21 11:23:06 +00:00
|
|
|
return noErr ;
|
|
|
|
}
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
return eventNotHandledErr;
|
|
|
|
|
|
|
|
case kEventClassMenu:
|
|
|
|
if (eventKind != kEventMenuOpening)
|
|
|
|
return eventNotHandledErr;
|
|
|
|
|
|
|
|
GetEventParameter (inEvent, kEventParamDirectObject,
|
|
|
|
typeMenuRef, NULL, sizeof(sysMenuRef), NULL, &sysMenuRef);
|
|
|
|
|
|
|
|
// If not our system menu, pass event on to next event handler
|
|
|
|
if (PLstrcmp("\pBOINC!", (GetMenuTitle((sysMenuRef), theMenuTitle) )))
|
|
|
|
return eventNotHandledErr;
|
|
|
|
|
2005-07-06 05:16:53 +00:00
|
|
|
pMSM = wxGetApp().GetMacSystemMenu();
|
2005-03-25 12:23:30 +00:00
|
|
|
baseMenu = (pMSM->GetCurrentMenu());
|
|
|
|
pMSM->AdjustMenuItems(baseMenu);
|
|
|
|
|
|
|
|
// Copy checkmark and enabled status of each item from Dock menu
|
|
|
|
baseMenuRef = (MenuRef)(baseMenu->GetHMenu());
|
|
|
|
n = CountMenuItems(sysMenuRef);
|
|
|
|
m = CountMenuItems(baseMenuRef);
|
|
|
|
if (m < n)
|
|
|
|
n = m;
|
|
|
|
for (i=1; i<=n; i++)
|
|
|
|
{
|
|
|
|
GetMenuItemCommandID(baseMenuRef, i, &commandID);
|
|
|
|
SetMenuItemCommandID(sysMenuRef, i, commandID);
|
2012-01-27 13:02:35 +00:00
|
|
|
GetMenuItemText(baseMenuRef, i, theMenuTitle);
|
|
|
|
SetMenuItemText(sysMenuRef, i, theMenuTitle);
|
2005-03-25 12:23:30 +00:00
|
|
|
GetItemMark(baseMenuRef, i, &markChar);
|
|
|
|
SetItemMark(sysMenuRef, i, markChar);
|
|
|
|
if( IsMenuItemEnabled(baseMenuRef, i) )
|
|
|
|
EnableMenuItem(sysMenuRef, i);
|
|
|
|
else
|
|
|
|
DisableMenuItem(sysMenuRef, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return noErr;
|
2005-07-06 05:16:53 +00:00
|
|
|
|
2005-07-21 11:23:06 +00:00
|
|
|
// Event handling to open or close our main window when applicaiton
|
|
|
|
// is shown or hidden. This probably should go in BOINCGUIApp.cpp
|
|
|
|
// or MainFrame.cpp, but it is more eficient to put it here since
|
|
|
|
// we already have this Mac Event Handler installed.
|
2005-07-06 05:16:53 +00:00
|
|
|
case kEventClassApplication:
|
2006-06-28 02:43:01 +00:00
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
2005-07-06 05:16:53 +00:00
|
|
|
pMSM = wxGetApp().GetMacSystemMenu();
|
|
|
|
switch (eventKind) {
|
|
|
|
case kEventAppHidden:
|
|
|
|
if (pFrame)
|
|
|
|
pFrame->Hide();
|
|
|
|
pMSM->SetOpeningAboutDlg(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kEventAppShown:
|
|
|
|
// Don't open main window if "About" Dialog from task bar menu.
|
|
|
|
if (pMSM->IsOpeningAboutDlg()) {
|
|
|
|
pMSM->SetOpeningAboutDlg(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ActiveNonFloatingWindow()) // Prevent infinite loop
|
|
|
|
break;
|
|
|
|
if (pFrame) {
|
|
|
|
pFrame->Show();
|
|
|
|
pFrame->SendSizeEvent();
|
|
|
|
}
|
2005-07-06 06:41:27 +00:00
|
|
|
// If a modal dialog was open, make sure it remains in front
|
|
|
|
WindowRef win = GetWindowList();
|
|
|
|
WindowModality modality = kWindowModalityNone;
|
|
|
|
while (win) {
|
|
|
|
GetWindowModality(win, &modality, NULL);
|
|
|
|
if (modality == kWindowModalityAppModal)
|
|
|
|
BringToFront(win);
|
|
|
|
win = GetNextWindow(win);
|
|
|
|
}
|
2005-07-06 05:16:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eventNotHandledErr;
|
2005-03-25 12:23:30 +00:00
|
|
|
|
|
|
|
} // End switch (eventClass)
|
|
|
|
|
|
|
|
return eventNotHandledErr;
|
|
|
|
}
|