]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/toplevel.cpp
fixed border calculation
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
index a794c8077a97fb7a70162569e2faee6c6221cf52..1ce8d60fdeac9b51676956e27aaf2e8c296f6240 100644 (file)
@@ -505,22 +505,12 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev
     } // if ( windowPart == inMenuBar )
     else if ( currentMouseWindow )
     {
+        wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent();
+
         currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ;
         
         wxevent.SetEventObject( currentMouseWindow ) ;
 
-        // update cursor
-        
-        wxWindow* cursorTarget = currentMouseWindow ;
-        wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
-
-        while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
-        {
-            cursorTarget = cursorTarget->GetParent() ;
-            if ( cursorTarget )
-                cursorPoint += cursorTarget->GetPosition() ;
-        }
-
         // make tooltips current
         
     #if wxUSE_TOOLTIPS
@@ -530,7 +520,13 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev
             wxToolTip::RelayEvent( currentMouseWindow , wxevent);
     #endif // wxUSE_TOOLTIPS                
         if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) )
+        {
+            if ((currentMouseWindowParent != NULL) && 
+                (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+                currentMouseWindow = NULL;
+                
             result = noErr;
+        }
         else
         {
             // if the user code did _not_ handle the event, then perform the
@@ -559,6 +555,10 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev
     #endif
                     HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation ,
                         modifiers , (ControlActionUPP ) -1 ) ;
+                        
+                    if ((currentMouseWindowParent != NULL) && 
+                        (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL))
+                        currentMouseWindow = NULL;
                 }
                 result = noErr ;
             }
@@ -568,6 +568,19 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev
             wxTheApp->s_captureWindow = NULL ;
             // update cursor ?
          }
+
+        // update cursor
+        
+        wxWindow* cursorTarget = currentMouseWindow ;
+        wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ;
+
+        while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) )
+        {
+            cursorTarget = cursorTarget->GetParent() ;
+            if ( cursorTarget )
+                cursorPoint += cursorTarget->GetPosition();
+        }
+
     } // else if ( currentMouseWindow )
     else
     {
@@ -741,6 +754,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler )
 
 // Find an item given the Macintosh Window Reference
 
+#if KEY_wxList_DEPRECATED
 wxList wxWinMacWindowList(wxKEY_INTEGER);
 wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
 {
@@ -766,7 +780,43 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
 {
     wxWinMacWindowList.DeleteObject(win);
 }
+#else
+
+WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap);
+
+static MacWindowMap wxWinMacWindowList;
+
+wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
+{
+    MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
+
+    return (node == wxWinMacWindowList.end()) ? NULL : node->second;
+}
 
+void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ;
+void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win)
+{
+    // adding NULL WindowRef is (first) surely a result of an error and
+    // nothing else :-)
+    wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
+
+    wxWinMacWindowList[inWindowRef] = win;
+}
+
+void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ;
+void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
+{
+    MacWindowMap::iterator it;
+    for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
+    {
+        if ( it->second == win )
+        {
+            wxWinMacWindowList.erase(it);
+            break;
+        }
+    }
+}
+#endif // deprecated wxList
 
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowMac creation
@@ -948,6 +998,14 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
 
     int x = (int)pos.x;
     int y = (int)pos.y;
+    
+    wxRect display = wxGetClientDisplayRect() ;
+
+    if ( x == wxDefaultPosition.x )
+        x = display.x ;
+    
+    if ( y == wxDefaultPosition.y )
+        y = display.y ;
 
     int w = WidthDefault(size.x);
     int h = HeightDefault(size.y);
@@ -958,6 +1016,7 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
 
     WindowClass wclass = 0;
     WindowAttributes attr = kWindowNoAttributes ;
+    WindowGroupRef group = NULL ;
 
     if ( HasFlag( wxFRAME_TOOL_WINDOW) )
     {
@@ -1028,8 +1087,10 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         attr |= kWindowLiveResizeAttribute;
     }
 
-    if (HasFlag(wxSTAY_ON_TOP))
-        wclass = kUtilityWindowClass;
+    if ( HasFlag(wxSTAY_ON_TOP) )
+    {
+        group = GetWindowGroupOfClass(kUtilityWindowClass) ;
+    }
 
 #if TARGET_API_MAC_OSX 
     attr |= kWindowCompositingAttribute;
@@ -1050,6 +1111,9 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
     }
 
+    if ( err == noErr && m_macWindow != NULL && group != NULL )
+        SetWindowGroup( (WindowRef) m_macWindow , group ) ;
+
     wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
 
     // the create commands are only for content rect, so we have to set the size again as
@@ -1321,6 +1385,31 @@ wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const
     return attr ;
 }
 
+// Attracts the users attention to this window if the application is
+// inactive (should be called when a background event occurs)
+
+static pascal void wxMacNMResponse( NMRecPtr ptr )
+{
+    NMRemove( ptr ) ;
+    DisposePtr( (Ptr) ptr ) ;
+}
+
+
+void wxTopLevelWindowMac::RequestUserAttention(int flags )
+{
+    NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ;
+    static wxMacNMUPP nmupp( wxMacNMResponse )
+     ;
+    memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ;
+    notificationRequest->qType = nmType ;
+    notificationRequest->nmMark = 1 ;
+    notificationRequest->nmIcon = 0 ;
+    notificationRequest->nmSound = 0 ;
+    notificationRequest->nmStr = NULL ;
+    notificationRequest->nmResp = nmupp ;
+    verify_noerr( NMInstall( notificationRequest ) ) ;
+}
+
 // ---------------------------------------------------------------------------
 // Shape implementation
 // ---------------------------------------------------------------------------