applied patch 1372567, with some minor mods and cleanup
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: taskbar.cpp
|
||||
// Purpose: wxTaskBarIcon OSX Implementation
|
||||
// Purpose: wxTaskBarIcon - OSX implementation
|
||||
// Author: Ryan Norton
|
||||
// Modified by:
|
||||
// Created: 09/25/2004
|
||||
@@ -103,10 +103,10 @@ public:
|
||||
|
||||
EventHandlerRef m_eventHandlerRef;
|
||||
EventHandlerUPP m_eventupp;
|
||||
wxWindow* m_eventWindow;
|
||||
wxMenu* m_pMenu;
|
||||
MenuRef m_theLastMenu;
|
||||
bool m_iconAdded;
|
||||
wxWindow* m_eventWindow;
|
||||
};
|
||||
|
||||
// Forward declarations for utility functions for dock implementation
|
||||
@@ -170,17 +170,14 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
||||
const UInt32 eventClass = GetEventClass(inEvent);
|
||||
const UInt32 eventKind = GetEventKind(inEvent);
|
||||
|
||||
//
|
||||
// Handle wxTaskBar menu events (note that this is a global event handler
|
||||
// so it will actually get called by all commands/menus)
|
||||
//
|
||||
if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess)
|
||||
if ((eventClass == kEventClassCommand) && (eventKind == kEventCommandProcess))
|
||||
{
|
||||
// if we have no taskbar menu quickly pass it back to wxApp
|
||||
if (! pTB->m_pMenu )
|
||||
{
|
||||
if (pTB->m_pMenu == NULL)
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
|
||||
//
|
||||
// This is the real reason why we need this. Normally menus
|
||||
@@ -204,7 +201,6 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
||||
sizeof(HICommand), NULL, &command);
|
||||
if (err == noErr)
|
||||
{
|
||||
//
|
||||
// Obtain the REAL menuRef and the menuItemIndex in the real menuRef
|
||||
//
|
||||
// NOTE: menuRef is generally used here for submenus, as
|
||||
@@ -242,7 +238,8 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
||||
}
|
||||
} //end if noErr on getting HICommand from event
|
||||
|
||||
return err; // return whether we handled the event or not
|
||||
// return whether we handled the event or not
|
||||
return err;
|
||||
}
|
||||
|
||||
// We better have a kEventClassApplication/kEventAppGetDockTileMenu combo here,
|
||||
@@ -262,14 +259,14 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
||||
// create popup menu
|
||||
wxMenu* menu = pTB->DoCreatePopupMenu();
|
||||
|
||||
OSStatus err = noErr;
|
||||
OSStatus err = eventNotHandledErr;
|
||||
|
||||
if (menu)
|
||||
if (menu != NULL)
|
||||
{
|
||||
//note to self - a MenuRef IS A MenuHandle
|
||||
// note to self - a MenuRef *is* a MenuHandle
|
||||
MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu());
|
||||
|
||||
// When we call SetEventParameter it will decrement
|
||||
// When SetEventParameter is called it will decrement
|
||||
// the reference count of the menu - we need to make
|
||||
// sure it stays around in the wxMenu class here
|
||||
RetainMenu(hMenu);
|
||||
@@ -278,12 +275,10 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
||||
err = SetEventParameter(inEvent, kEventParamMenuRef,
|
||||
typeMenuRef, sizeof(MenuRef), &hMenu);
|
||||
wxASSERT(err == noErr);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
else
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
// wxDeepCopyMenu
|
||||
@@ -326,7 +321,9 @@ wxMenu* wxDeepCopyMenu(wxMenu* menu)
|
||||
while (theNode != NULL)
|
||||
{
|
||||
wxMenuItem* theItem = theNode->GetData();
|
||||
m_pMenu->Append(new wxMenuItem(m_pMenu, // parent menu
|
||||
m_pMenu->Append(
|
||||
new wxMenuItem(
|
||||
m_pMenu, // parent menu
|
||||
theItem->GetId(), // id
|
||||
theItem->GetText(), // text label
|
||||
theItem->GetHelp(), // status bar help string
|
||||
@@ -340,7 +337,7 @@ wxMenu* wxDeepCopyMenu(wxMenu* menu)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDockTaskBarIcon Constructor
|
||||
// wxDockTaskBarIcon ctor
|
||||
//
|
||||
// Initializes the dock implementation of wxTaskBarIcon.
|
||||
//
|
||||
@@ -352,8 +349,11 @@ wxDockTaskBarIcon::wxDockTaskBarIcon(wxTaskBarIcon* parent)
|
||||
m_theLastMenu(GetApplicationDockTileMenu()), m_iconAdded(false)
|
||||
{
|
||||
// register the events that will return the dock menu
|
||||
EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand },
|
||||
{ kEventClassApplication, kEventAppGetDockTileMenu } };
|
||||
EventTypeSpec tbEventList[] =
|
||||
{
|
||||
{ kEventClassCommand, kEventProcessCommand },
|
||||
{ kEventClassApplication, kEventAppGetDockTileMenu }
|
||||
};
|
||||
|
||||
m_eventupp = NewEventHandlerUPP(wxDockEventHandler);
|
||||
wxASSERT(m_eventupp != NULL);
|
||||
@@ -428,49 +428,25 @@ bool wxDockTaskBarIcon::IsIconInstalled() const
|
||||
//-----------------------------------------------------------------------------
|
||||
bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
|
||||
{
|
||||
// convert the wxIcon into a wxBitmap so we can perform some
|
||||
// wxBitmap operations with it
|
||||
wxBitmap bmp( icon ) ;
|
||||
OSStatus err = noErr ;
|
||||
|
||||
CGImageRef pImage;
|
||||
|
||||
#if 0 // is always available under OSX now -- crashes on 10.2 in CFRetain() - RN
|
||||
pImage = (CGImageRef) bmp.CGImageCreate() ;
|
||||
#else
|
||||
WXHBITMAP iconport ;
|
||||
WXHBITMAP maskport ;
|
||||
iconport = bmp.GetHBITMAP( &maskport ) ;
|
||||
|
||||
if (!maskport)
|
||||
{
|
||||
// Make a mask with no transparent pixels
|
||||
wxBitmap mbmp(icon.GetWidth(), icon.GetHeight());
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(mbmp);
|
||||
dc.SetBackground(*wxBLACK_BRUSH);
|
||||
dc.Clear();
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
bmp.SetMask( new wxMask(mbmp, *wxWHITE) ) ;
|
||||
iconport = bmp.GetHBITMAP( &maskport ) ;
|
||||
}
|
||||
|
||||
//create the icon from the bitmap and mask bitmap contained within
|
||||
err = CreateCGImageFromPixMaps(
|
||||
GetGWorldPixMap(MAC_WXHBITMAP(iconport)),
|
||||
GetGWorldPixMap(MAC_WXHBITMAP(maskport)),
|
||||
&pImage
|
||||
);
|
||||
wxASSERT(err == 0);
|
||||
#endif
|
||||
wxASSERT( bmp.IsOK() );
|
||||
|
||||
// get the CGImageRef for the wxBitmap:
|
||||
// OSX builds only, but then the dock only exists in OSX
|
||||
CGImageRef pImage = (CGImageRef) bmp.CGImageCreate();
|
||||
wxASSERT( pImage != NULL );
|
||||
err = SetApplicationDockTileImage(pImage);
|
||||
|
||||
wxASSERT(err == 0);
|
||||
// actually set the dock image
|
||||
OSStatus err = SetApplicationDockTileImage( pImage );
|
||||
wxASSERT( err == noErr );
|
||||
|
||||
// free the CGImage, now that it's referenced by the dock
|
||||
if (pImage != NULL)
|
||||
CGImageRelease( pImage );
|
||||
|
||||
return m_iconAdded = err == noErr;
|
||||
return m_iconAdded = (err == noErr);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user