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
|
// Name: taskbar.cpp
|
||||||
// Purpose: wxTaskBarIcon OSX Implementation
|
// Purpose: wxTaskBarIcon - OSX implementation
|
||||||
// Author: Ryan Norton
|
// Author: Ryan Norton
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 09/25/2004
|
// Created: 09/25/2004
|
||||||
@@ -103,10 +103,10 @@ public:
|
|||||||
|
|
||||||
EventHandlerRef m_eventHandlerRef;
|
EventHandlerRef m_eventHandlerRef;
|
||||||
EventHandlerUPP m_eventupp;
|
EventHandlerUPP m_eventupp;
|
||||||
|
wxWindow* m_eventWindow;
|
||||||
wxMenu* m_pMenu;
|
wxMenu* m_pMenu;
|
||||||
MenuRef m_theLastMenu;
|
MenuRef m_theLastMenu;
|
||||||
bool m_iconAdded;
|
bool m_iconAdded;
|
||||||
wxWindow* m_eventWindow;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward declarations for utility functions for dock implementation
|
// Forward declarations for utility functions for dock implementation
|
||||||
@@ -170,17 +170,14 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
|||||||
const UInt32 eventClass = GetEventClass(inEvent);
|
const UInt32 eventClass = GetEventClass(inEvent);
|
||||||
const UInt32 eventKind = GetEventKind(inEvent);
|
const UInt32 eventKind = GetEventKind(inEvent);
|
||||||
|
|
||||||
//
|
|
||||||
// Handle wxTaskBar menu events (note that this is a global event handler
|
// Handle wxTaskBar menu events (note that this is a global event handler
|
||||||
// so it will actually get called by all commands/menus)
|
// 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 we have no taskbar menu quickly pass it back to wxApp
|
||||||
if (! pTB->m_pMenu )
|
if (pTB->m_pMenu == NULL)
|
||||||
{
|
|
||||||
return eventNotHandledErr;
|
return eventNotHandledErr;
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is the real reason why we need this. Normally menus
|
// This is the real reason why we need this. Normally menus
|
||||||
@@ -204,7 +201,6 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
|||||||
sizeof(HICommand), NULL, &command);
|
sizeof(HICommand), NULL, &command);
|
||||||
if (err == noErr)
|
if (err == noErr)
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Obtain the REAL menuRef and the menuItemIndex in the real menuRef
|
// Obtain the REAL menuRef and the menuItemIndex in the real menuRef
|
||||||
//
|
//
|
||||||
// NOTE: menuRef is generally used here for submenus, as
|
// 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
|
} //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,
|
// We better have a kEventClassApplication/kEventAppGetDockTileMenu combo here,
|
||||||
@@ -262,14 +259,14 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
|||||||
// create popup menu
|
// create popup menu
|
||||||
wxMenu* menu = pTB->DoCreatePopupMenu();
|
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());
|
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
|
// the reference count of the menu - we need to make
|
||||||
// sure it stays around in the wxMenu class here
|
// sure it stays around in the wxMenu class here
|
||||||
RetainMenu(hMenu);
|
RetainMenu(hMenu);
|
||||||
@@ -278,12 +275,10 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
|
|||||||
err = SetEventParameter(inEvent, kEventParamMenuRef,
|
err = SetEventParameter(inEvent, kEventParamMenuRef,
|
||||||
typeMenuRef, sizeof(MenuRef), &hMenu);
|
typeMenuRef, sizeof(MenuRef), &hMenu);
|
||||||
wxASSERT(err == noErr);
|
wxASSERT(err == noErr);
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return eventNotHandledErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
// wxDeepCopyMenu
|
// wxDeepCopyMenu
|
||||||
@@ -326,7 +321,9 @@ wxMenu* wxDeepCopyMenu(wxMenu* menu)
|
|||||||
while (theNode != NULL)
|
while (theNode != NULL)
|
||||||
{
|
{
|
||||||
wxMenuItem* theItem = theNode->GetData();
|
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->GetId(), // id
|
||||||
theItem->GetText(), // text label
|
theItem->GetText(), // text label
|
||||||
theItem->GetHelp(), // status bar help string
|
theItem->GetHelp(), // status bar help string
|
||||||
@@ -340,7 +337,7 @@ wxMenu* wxDeepCopyMenu(wxMenu* menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDockTaskBarIcon Constructor
|
// wxDockTaskBarIcon ctor
|
||||||
//
|
//
|
||||||
// Initializes the dock implementation of wxTaskBarIcon.
|
// Initializes the dock implementation of wxTaskBarIcon.
|
||||||
//
|
//
|
||||||
@@ -352,8 +349,11 @@ wxDockTaskBarIcon::wxDockTaskBarIcon(wxTaskBarIcon* parent)
|
|||||||
m_theLastMenu(GetApplicationDockTileMenu()), m_iconAdded(false)
|
m_theLastMenu(GetApplicationDockTileMenu()), m_iconAdded(false)
|
||||||
{
|
{
|
||||||
// register the events that will return the dock menu
|
// register the events that will return the dock menu
|
||||||
EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand },
|
EventTypeSpec tbEventList[] =
|
||||||
{ kEventClassApplication, kEventAppGetDockTileMenu } };
|
{
|
||||||
|
{ kEventClassCommand, kEventProcessCommand },
|
||||||
|
{ kEventClassApplication, kEventAppGetDockTileMenu }
|
||||||
|
};
|
||||||
|
|
||||||
m_eventupp = NewEventHandlerUPP(wxDockEventHandler);
|
m_eventupp = NewEventHandlerUPP(wxDockEventHandler);
|
||||||
wxASSERT(m_eventupp != NULL);
|
wxASSERT(m_eventupp != NULL);
|
||||||
@@ -428,49 +428,25 @@ bool wxDockTaskBarIcon::IsIconInstalled() const
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool wxDockTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
|
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 ) ;
|
wxBitmap bmp( icon ) ;
|
||||||
OSStatus err = noErr ;
|
wxASSERT( bmp.IsOK() );
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
// 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 );
|
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)
|
if (pImage != NULL)
|
||||||
CGImageRelease( pImage );
|
CGImageRelease( pImage );
|
||||||
|
|
||||||
return m_iconAdded = err == noErr;
|
return m_iconAdded = (err == noErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user