-/////////////////////////////////////////////////////////////////////////
-// File: taskbar.cpp
-// Purpose: Implements wxTaskBarIcon class for manipulating icons on
-// the task bar. Optional.
-// Author: Stefan Csomor
+/////////////////////////////////////////////////////////////////////////////
+// Name: taskbar.cpp
+// Purpose: wxTaskBarIcon OSX Implementation
+// Author: Ryan Norton
// Modified by:
-// Created: 1998-01-01
+// Created: 09/25/2004
// RCS-ID: $Id$
-// Copyright: (c)
-// Licence: wxWindows licence
-/////////////////////////////////////////////////////////////////////////
+// Copyright: (c) 2004 Ryan Norton
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#pragma implementation "taskbar.h"
-#endif
+#include "wx/wxprec.h"
+
+#include "wx/defs.h"
+
+#ifdef wxHAS_TASK_BAR_ICON
+
+#include "wx/mac/private.h"
#include "wx/taskbar.h"
+#include "wx/menu.h"
+#include "wx/icon.h"
-wxTaskBarIcon::wxTaskBarIcon()
-{
- // TODO
-}
+#if 0
-wxTaskBarIcon::~wxTaskBarIcon()
-{
- // TODO
-}
+#include "wx/frame.h"
+#include "wx/dialog.h"
-// Operations
-bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
-{
- // TODO
- return FALSE;
-}
+#endif
-bool wxTaskBarIcon::RemoveIcon()
-{
- // TODO
- return FALSE;
-}
+IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler)
-// Overridables
-void wxTaskBarIcon::OnMouseMove()
+pascal OSStatus wxDockEventHandler( EventHandlerCallRef inHandlerCallRef,
+ EventRef inEvent, void* pData)
{
+ wxTaskBarIcon*& pTB = (wxTaskBarIcon*&) pData;
+
+ const UInt32 eventClass = GetEventClass(inEvent);
+ const UInt32 eventKind = GetEventKind(inEvent);
+
+ if (eventClass == kEventClassCommand && eventKind == kEventCommandProcess)
+ {
+ MenuRef hMenu = MAC_WXHMENU(pTB->GetCurrentMenu()->GetHMenu());
+ OSStatus result = eventNotHandledErr ;
+
+ HICommand command ;
+ OSErr err;
+
+ err = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand,
+ NULL, sizeof(HICommand), NULL, &command);
+ wxASSERT(err == noErr);
+
+ MenuItemIndex menuItemIndex;
+ err = GetIndMenuItemWithCommandID(hMenu, command.commandID, 1, NULL, &menuItemIndex);
+ wxASSERT(err == noErr);
+
+
+ MenuCommand id = command.commandID ;
+ wxMenuItem* item = NULL;
+ // for items we don't really control
+ if ( id == kHICommandPreferences )
+ {
+ id = wxApp::s_macPreferencesMenuItemId ;
+
+ wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
+ if ( mbar )
+ {
+ wxMenu* menu = NULL ;
+ item = mbar->FindItem( id , &menu ) ;
+ }
+ }
+ else if (id != 0)
+ GetMenuItemRefCon( hMenu , menuItemIndex , (UInt32*) &item ) ;
+
+ if ( item )
+ {
+ if (item->IsCheckable())
+ {
+ item->Check( !item->IsChecked() ) ;
+ }
+
+ item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
+ result = noErr ;
+ }
+ return result ;
+ }
+
+ 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);
+
+ return noErr;
}
-void wxTaskBarIcon::OnLButtonDown()
+DEFINE_ONE_SHOT_HANDLER_GETTER( wxDockEventHandler );
+
+wxTaskBarIcon::wxTaskBarIcon(const wxTaskBarIconType& nType)
+ : m_nType(nType), m_pEvent(NULL), m_pMenu(NULL)
{
+ //Register the events that will return the dock menu
+ EventTypeSpec tbEventList[] = { { kEventClassCommand, kEventProcessCommand },
+ { kEventClassApplication, kEventAppGetDockTileMenu } };
+
+ OSStatus err = InstallApplicationEventHandler(
+ GetwxDockEventHandlerUPP(),
+ GetEventTypeCount(tbEventList), tbEventList,
+ this, NULL);
+
+ wxASSERT(err == noErr);
}
-
-void wxTaskBarIcon::OnLButtonUp()
+wxTaskBarIcon::~wxTaskBarIcon()
{
+ //TODO:uninstall event handler
}
-void wxTaskBarIcon::OnRButtonDown()
+void wxTaskBarIcon::SetInternalEvent(void* pEvent)
{
+ m_pEvent = pEvent;
}
-void wxTaskBarIcon::OnRButtonUp()
+wxMenu* wxTaskBarIcon::GetCurrentMenu()
{
+ return m_pMenu;
}
-void wxTaskBarIcon::OnLButtonDClick()
+// Operations:
+bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
{
+ #if 0
+ wxASSERT(wxTheApp);
+ wxWindow* pTopWindow = wxTheApp->GetTopWindow();
+
+ 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
+
+ CGImageRef pImage;
+ //create the icon from the bitmap and mask bitmap contained within
+ OSStatus err = CreateCGImageFromPixMaps(
+ GetGWorldPixMap(MAC_WXHBITMAP(icon.GetHBITMAP())),
+ GetGWorldPixMap(MAC_WXHBITMAP(icon.GetMask()->GetMaskBitmap())),
+ &pImage
+ );
+
+ wxASSERT(err == 0);
+
+ err = SetApplicationDockTileImage(pImage);
+
+ wxASSERT(err == 0);
+
+ return true;
+ #endif
}
+
+bool wxTaskBarIcon::RemoveIcon()
+{
+ //TODO: Not tested
+ OSStatus err = RestoreApplicationDockTileImage();
+ wxASSERT(err == 0);
-void wxTaskBarIcon::OnRButtonDClick()
+ return true;
+}
+
+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;
}
+#endif //wxHAS_TASK_BAR_ICON
\ No newline at end of file