Create a mask for the icon if it doesn't already have one

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29548 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-09-29 20:39:25 +00:00
parent 3444e4a8f9
commit e768548a12

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: taskbar.cpp // Name: taskbar.cpp
// Purpose: wxTaskBarIcon OSX Implementation // Purpose: wxTaskBarIcon OSX Implementation
// Author: Ryan Norton // Author: Ryan Norton
// Modified by: // Modified by:
@@ -29,8 +29,8 @@
//TODO: //TODO:
IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler)
pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void* pData) EventRef inEvent, void* pData)
{ {
wxTaskBarIcon*& pTB = (wxTaskBarIcon*&) pData; wxTaskBarIcon*& pTB = (wxTaskBarIcon*&) pData;
@@ -40,11 +40,11 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess) if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess)
{ {
//TODO: //TODO:
//TODO: This is a complete copy of //TODO: This is a complete copy of
//static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) //static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
//FIND A WAY TO EXTERN THIS AND USE THAT HERE INSTEAD!! //FIND A WAY TO EXTERN THIS AND USE THAT HERE INSTEAD!!
//TODO: //TODO:
MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu()); MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu());
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
HICommand command ; HICommand command ;
@@ -78,22 +78,22 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
if ( item ) if ( item )
{ {
if (item->IsCheckable()) if (item->IsCheckable())
{ {
item->Check( !item->IsChecked() ) ; item->Check( !item->IsChecked() ) ;
} }
item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
result = noErr ; result = noErr ;
} }
return result ; return result ;
} }
wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu); wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu);
//process the right click event //process the right click event
wxTaskBarIconEvent evt(wxEVT_TASKBAR_RIGHT_UP,NULL); wxTaskBarIconEvent evt(wxEVT_TASKBAR_RIGHT_UP,NULL);
pTB->ProcessEvent(evt); pTB->ProcessEvent(evt);
//create popup menu //create popup menu
wxMenu* menu = pTB->DoCreatePopupMenu(); wxMenu* menu = pTB->DoCreatePopupMenu();
@@ -112,12 +112,12 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
//set the actual dock menu //set the actual dock menu
err = SetEventParameter((EventRef) inEvent, kEventParamMenuRef, err = SetEventParameter((EventRef) inEvent, kEventParamMenuRef,
typeMenuRef, sizeof(MenuRef), typeMenuRef, sizeof(MenuRef),
&hMenu); &hMenu);
wxASSERT(err == 0); wxASSERT(err == 0);
} }
return err; return err;
} }
DEFINE_ONE_SHOT_HANDLER_GETTER( wxDockEventHandler ); DEFINE_ONE_SHOT_HANDLER_GETTER( wxDockEventHandler );
@@ -126,18 +126,18 @@ wxTaskBarIcon::wxTaskBarIcon(const wxTaskBarIconType& nType)
: m_nType(nType), m_pEventHandlerRef(NULL), m_pMenu(NULL), m_iconAdded(false) : m_nType(nType), m_pEventHandlerRef(NULL), m_pMenu(NULL), 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[] = { { kEventClassCommand, kEventProcessCommand },
{ kEventClassApplication, kEventAppGetDockTileMenu } }; { kEventClassApplication, kEventAppGetDockTileMenu } };
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
OSStatus err = OSStatus err =
#endif #endif
InstallApplicationEventHandler( InstallApplicationEventHandler(
GetwxDockEventHandlerUPP(), GetwxDockEventHandlerUPP(),
GetEventTypeCount(tbEventList), tbEventList, GetEventTypeCount(tbEventList), tbEventList,
this, (&(EventHandlerRef&)m_pEventHandlerRef)); this, (&(EventHandlerRef&)m_pEventHandlerRef));
wxASSERT(err == noErr); wxASSERT(err == noErr);
} }
wxTaskBarIcon::~wxTaskBarIcon() wxTaskBarIcon::~wxTaskBarIcon()
@@ -166,36 +166,49 @@ wxMenu* wxTaskBarIcon::DoCreatePopupMenu()
// Operations: // Operations:
bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
{ {
//TODO: (IT WORKS!) Make work without mask - mayby by using a wxDC? wxMask* mask = icon.GetMask();
if (!mask)
{
// Make a mask with no transparent pixels
wxBitmap bmp(icon.GetWidth(), icon.GetHeight());
wxMemoryDC dc;
dc.SelectObject(bmp);
dc.SetBackground(*wxBLACK_BRUSH);
dc.Clear();
dc.SelectObject(wxNullBitmap);
mask = new wxMask(bmp, *wxWHITE);
}
wxASSERT(icon.GetMask() != NULL); CGImageRef pImage;
CGImageRef pImage; //create the icon from the bitmap and mask bitmap contained within
//create the icon from the bitmap and mask bitmap contained within OSStatus err = CreateCGImageFromPixMaps(
OSStatus err = CreateCGImageFromPixMaps( GetGWorldPixMap(MAC_WXHBITMAP(icon.GetHBITMAP())),
GetGWorldPixMap(MAC_WXHBITMAP(icon.GetHBITMAP())), GetGWorldPixMap(MAC_WXHBITMAP(mask->GetMaskBitmap())),
GetGWorldPixMap(MAC_WXHBITMAP(icon.GetMask()->GetMaskBitmap())), &pImage
&pImage );
);
wxASSERT(err == 0); wxASSERT(err == 0);
err = SetApplicationDockTileImage(pImage); err = SetApplicationDockTileImage(pImage);
wxASSERT(err == 0); wxASSERT(err == 0);
if (pImage != NULL) if (pImage != NULL)
CGImageRelease(pImage); CGImageRelease(pImage);
return m_iconAdded = err == noErr; if (!icon.GetMask())
delete mask;
return m_iconAdded = err == noErr;
} }
bool wxTaskBarIcon::RemoveIcon() bool wxTaskBarIcon::RemoveIcon()
{ {
OSStatus err = RestoreApplicationDockTileImage(); OSStatus err = RestoreApplicationDockTileImage();
wxASSERT(err == 0); wxASSERT(err == 0);
return !(m_iconAdded = !(err == noErr)); return !(m_iconAdded = !(err == noErr));
} }
bool wxTaskBarIcon::PopupMenu(wxMenu *menu) bool wxTaskBarIcon::PopupMenu(wxMenu *menu)