X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/607667fde84b689ea5b47dce93a9e467d6bae010..d109c5849ed117966311a44875c97ae3d77b44e5:/src/mac/carbon/taskbar.cpp diff --git a/src/mac/carbon/taskbar.cpp b/src/mac/carbon/taskbar.cpp index 12a2e14164..523bd62524 100644 --- a/src/mac/carbon/taskbar.cpp +++ b/src/mac/carbon/taskbar.cpp @@ -21,13 +21,12 @@ #include "wx/menu.h" #include "wx/icon.h" -#if 0 - -#include "wx/frame.h" -#include "wx/dialog.h" - -#endif - +// +//TODO: Implement Apple Software Guidelines - show the top window it it's not shown, +//and force it to be unminimized - and all unminimized windows should be brought to +//the front +// +//TODO: IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler) pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, @@ -40,6 +39,11 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess) { + //TODO: + //TODO: This is a complete copy of + //static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) + //FIND A WAY TO EXTERN THIS AND USE THAT HERE INSTEAD!! + //TODO: MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu()); OSStatus result = eventNotHandledErr ; @@ -86,71 +90,85 @@ pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef, } wxASSERT(eventClass == kEventClassApplication && eventKind == kEventAppGetDockTileMenu); - - //set the internal event - pTB->SetInternalEvent(inEvent); - + //process the right click event wxTaskBarIconEvent evt(wxEVT_TASKBAR_RIGHT_UP,NULL); pTB->ProcessEvent(evt); - //set the internal event - pTB->SetInternalEvent(NULL); + //create popup menu + wxMenu* menu = pTB->DoCreatePopupMenu(); + + OSStatus err = noErr; + + if(menu) + { + //note to self - a MenuRef IS A MenuHandle + MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); - return noErr; + //When we call SetEventParameter it will decrement + //the reference count of the menu - we need to make + //sure it stays around in the wxMenu class here + RetainMenu(hMenu); + + //set the actual dock menu + err = SetEventParameter((EventRef) inEvent, kEventParamMenuRef, + typeMenuRef, sizeof(MenuRef), + &hMenu); + wxASSERT(err == 0); + } + + return err; } DEFINE_ONE_SHOT_HANDLER_GETTER( wxDockEventHandler ); wxTaskBarIcon::wxTaskBarIcon(const wxTaskBarIconType& nType) - : m_nType(nType), m_pEvent(NULL), m_pMenu(NULL) + : m_nType(nType), m_pEventHandlerRef(NULL), m_pMenu(NULL), m_iconAdded(false) { //Register the events that will return the dock menu EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand }, { kEventClassApplication, kEventAppGetDockTileMenu } }; - OSStatus err = InstallApplicationEventHandler( +#ifdef __WXDEBUG__ + OSStatus err = +#endif + InstallApplicationEventHandler( GetwxDockEventHandlerUPP(), GetEventTypeCount(tbEventList), tbEventList, - this, NULL); + this, (&(EventHandlerRef&)m_pEventHandlerRef)); wxASSERT(err == noErr); } + wxTaskBarIcon::~wxTaskBarIcon() { - //TODO:uninstall event handler + RemoveEventHandler((EventHandlerRef&)m_pEventHandlerRef); } -void wxTaskBarIcon::SetInternalEvent(void* pEvent) +wxMenu* wxTaskBarIcon::GetCurrentMenu() { - m_pEvent = pEvent; + return m_pMenu; } -wxMenu* wxTaskBarIcon::GetCurrentMenu() +wxMenu* wxTaskBarIcon::DoCreatePopupMenu() { + if (m_pMenu) + delete m_pMenu; + + m_pMenu = CreatePopupMenu(); + + if (m_pMenu) + m_pMenu->SetEventHandler(this); + return m_pMenu; } // Operations: bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) { - #if 0 - wxASSERT(wxTheApp); - wxWindow* pTopWindow = wxTheApp->GetTopWindow(); + //TODO: (IT WORKS!) Make work without mask - mayby by using a wxDC? - wxASSERT(pTopWindow); - - if(pTopWindow->IsKindOf(CLASSINFO(wxDialog))) - ((wxDialog*)pTopWindow)->SetIcon(icon); - else - { - wxASSERT(pTopWindow->IsKindOf(CLASSINFO(wxFrame))); - ((wxFrame*)pTopWindow)->SetIcon(icon); - } - - return true; - #else - //TODO: Educated guess + wxASSERT(icon.GetMask() != NULL); CGImageRef pImage; //create the icon from the bitmap and mask bitmap contained within @@ -165,45 +183,32 @@ bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip) err = SetApplicationDockTileImage(pImage); wxASSERT(err == 0); + + if (pImage != NULL) + CGImageRelease(pImage); - return true; - #endif + return m_iconAdded = err == noErr; } bool wxTaskBarIcon::RemoveIcon() { - //TODO: Not tested OSStatus err = RestoreApplicationDockTileImage(); wxASSERT(err == 0); - return true; + return !(m_iconAdded = !(err == noErr)); } bool wxTaskBarIcon::PopupMenu(wxMenu *menu) { - wxASSERT(m_pEvent != NULL); - if (m_pMenu) delete m_pMenu; - + m_pMenu = menu; - menu->SetEventHandler(this); - - //note to self - a MenuRef IS A MenuHandle - MenuRef hMenu = MAC_WXHMENU(menu->GetHMenu()); - - //When we call SetEventParameter it will decrement - //the reference count of the menu - we need to make - //sure it stays around in the wxMenu class here - RetainMenu(hMenu); - - //set the actual dock menu - OSStatus err = SetEventParameter((EventRef) m_pEvent, kEventParamMenuRef, - typeMenuRef, sizeof(MenuRef), - &hMenu); - wxASSERT(err == 0); - - return true; + + wxASSERT(menu); + m_pMenu->SetEventHandler(this); + + return SetApplicationDockTileMenu(MAC_WXHMENU(menu->GetHMenu())); } -#endif //wxHAS_TASK_BAR_ICON \ No newline at end of file +#endif //wxHAS_TASK_BAR_ICON