]> git.saurik.com Git - wxWidgets.git/commitdiff
mark changes. Mac OSX taskbar implementation
authorRyan Norton <wxprojects@comcast.net>
Sat, 25 Sep 2004 13:36:07 +0000 (13:36 +0000)
committerRyan Norton <wxprojects@comcast.net>
Sat, 25 Sep 2004 13:36:07 +0000 (13:36 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

build/bakefiles/files.bkl
docs/changes.txt
include/wx/features.h
include/wx/mac/carbon/taskbarosx.h
src/mac/carbon/taskbar.cpp [new file with mode: 0644]

index 883ce7d0dec08b4058c60e73cfd659ba54cca3e5..981f8c45506de8ee88ad2561f18bd36d3d8aa9a5 100644 (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">
index c1e38051b6262813c98ac6649370588b47030ef2..539ef9f7a075bb7026fd5d25b14c3ae11e067f0e 100644 (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 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
index 67ca4cfc8b75c0f4a53e762ccd25e6874a4bc4cd..5add1f43b42b757e97e708e07ceb413ea9964703 100644 (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
index 9c921c063de2b03e6d1418758dfa48774fe59858..c68e386f8381e2f3554e5d8b6d79ba0beea1eb6d 100644 (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_
diff --git a/src/mac/carbon/taskbar.cpp b/src/mac/carbon/taskbar.cpp
new file mode 100644 (file)
index 0000000..12a2e14
--- /dev/null
@@ -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
\ No newline at end of file