mark changes. Mac OSX taskbar implementation

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton 2004-09-25 13:36:07 +00:00
parent 0fdc1ca11e
commit 607667fde8
5 changed files with 234 additions and 9 deletions

View File

@ -2192,10 +2192,12 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
<set var="ADVANCED_MAC_SRC" hints="files">
src/mac/carbon/joystick.cpp
src/mac/carbon/sound.cpp
src/mac/carbon/taskbar.cpp
</set>
<set var="ADVANCED_MAC_HDR" hints="files">
wx/mac/carbon/joystick.h
wx/mac/carbon/sound.h
wx/mac/carbon/taskbarosx.h
</set>
<set var="ADVANCED_OS2_SRC" hints="files">

View File

@ -215,8 +215,8 @@ All:
All (GUI):
- added wxWindow::MoveBefore/AfterInTabOrder() to change tab navigation order
- added wxTaskBarIcon::CreatePopupMenu which is now recommended way
of showing popup menu; calling wxTaskBarIcon::PopupMenu directly
- added wxTaskBarIcon::CreatePopupMenu which is now the recommended way
of showing a popup menu; calling wxTaskBarIcon::PopupMenu directly
is discouraged
- added ..._CMD_...(id) variants for wxGrid event table entry macros
- added wxWindow::Navigate for programmatic navigation to the next control
@ -245,6 +245,11 @@ Unix:
builds of wxWidgets and to return flags/libs for selected libraries only
- wx-config has new --version-full option
wxMAC:
- Fixed MLTE text control GetLineText and GetLineLength on OSX (RN)
- Added OSX wxTaskBarIcon implementation for the OSX Dock (RN)
wxGTK:
- wxGTK uses GTK+ 2.x by default now, you have to pass --disable-gtk2 to

View File

@ -29,9 +29,9 @@
#undef wxHAS_RAW_KEY_CODES
#endif
/* taskbar is only implemented in wxMSW and X11 ports */
/* taskbar is only implemented in the major ports */
#if defined(__WXMSW__) || \
defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__)
defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXX11__) || defined(__DARWIN__)
#define wxHAS_TASK_BAR_ICON
#else
#undef wxHAS_TASK_BAR_ICON

View File

@ -22,7 +22,8 @@ class WXDLLEXPORT wxMenu;
class WXDLLEXPORT wxTaskBarIcon : public wxTaskBarIconBase
{
public:
//type of taskbar item to create (currently only DOCK is implemented)
//type of taskbar item to create
//TODO: currently only DOCK is implemented
enum wxTaskBarIconType
{
DOCK,
@ -33,16 +34,24 @@ public:
wxTaskBarIcon(const wxTaskBarIconType& nType = DOCK);
virtual ~wxTaskBarIcon();
// Operations:
//TODO: not tested extensively
bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString);
bool RemoveIcon();
//TODO: end not tested extensively
//pops up the menu
bool PopupMenu(wxMenu *menu);
//internal functions - don't call
void SetInternalEvent(void* pEvent);
wxMenu* GetCurrentMenu();
protected:
wxTaskBarIconType m_nType;
wxTaskBarIconType m_nType;
void* m_pEvent;
wxMenu* m_pMenu;
DECLARE_DYNAMIC_CLASS(wxTaskBarIcon)
};
#endif
// _TASKBAR_H_

209
src/mac/carbon/taskbar.cpp Normal file
View File

@ -0,0 +1,209 @@
/////////////////////////////////////////////////////////////////////////////
// Name: taskbar.cpp
// Purpose: wxTaskBarIcon OSX Implementation
// Author: Ryan Norton
// Modified by:
// Created: 09/25/2004
// RCS-ID: $Id$
// Copyright: (c) 2004 Ryan Norton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#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"
#if 0
#include "wx/frame.h"
#include "wx/dialog.h"
#endif
IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon, wxEvtHandler)
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;
}
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);
}
wxTaskBarIcon::~wxTaskBarIcon()
{
//TODO:uninstall event handler
}
void wxTaskBarIcon::SetInternalEvent(void* pEvent)
{
m_pEvent = pEvent;
}
wxMenu* wxTaskBarIcon::GetCurrentMenu()
{
return m_pMenu;
}
// 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);
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