From ed60b5022b9438672922d7879980ab7008c62fd6 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 14 Jan 2002 20:29:18 +0000 Subject: [PATCH] Fix wxClipboard. Fix enter and leave events. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13573 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/app.cpp | 15 +-- src/mac/carbon/app.cpp | 15 +-- src/mac/carbon/clipbrd.cpp | 210 ++++++++++++++++++------------------ src/mac/carbon/toplevel.cpp | 10 +- src/mac/carbon/window.cpp | 72 +++++++------ src/mac/clipbrd.cpp | 210 ++++++++++++++++++------------------ src/mac/toplevel.cpp | 10 +- src/mac/window.cpp | 72 +++++++------ 8 files changed, 318 insertions(+), 296 deletions(-) diff --git a/src/mac/app.cpp b/src/mac/app.cpp index dcd512fa87..77da32475c 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -1676,7 +1676,6 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , ¤tMouseWindow ) ; - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { wxMouseEvent event ; @@ -1695,17 +1694,21 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(this); - + if ( wxWindow::s_lastMouseWindow ) { - wxMouseEvent eventleave(event ) ; - eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ; + wxMouseEvent eventleave(event); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); } if ( currentMouseWindow ) { - wxMouseEvent evententer(event ) ; - evententer.SetEventType( wxEVT_ENTER_WINDOW ) ; + wxMouseEvent evententer(event); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); } wxWindow::s_lastMouseWindow = currentMouseWindow ; diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index dcd512fa87..77da32475c 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -1676,7 +1676,6 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , ¤tMouseWindow ) ; - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { wxMouseEvent event ; @@ -1695,17 +1694,21 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(this); - + if ( wxWindow::s_lastMouseWindow ) { - wxMouseEvent eventleave(event ) ; - eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ; + wxMouseEvent eventleave(event); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); } if ( currentMouseWindow ) { - wxMouseEvent evententer(event ) ; - evententer.SetEventType( wxEVT_ENTER_WINDOW ) ; + wxMouseEvent evententer(event); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); } wxWindow::s_lastMouseWindow = currentMouseWindow ; diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index 0aa8806e03..651f6f4722 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -6,7 +6,7 @@ // Created: ??/??/98 // RCS-ID: $Id$ // Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -39,12 +39,12 @@ static const wxChar *TRACE_CLIPBOARD = _T("clipboard"); void *wxGetClipboardData(wxDataFormat dataFormat, long *len) { #if !TARGET_CARBON - OSErr err = noErr ; + OSErr err = noErr ; #else - OSStatus err = noErr ; + OSStatus err = noErr ; #endif void * data = NULL ; - + switch (dataFormat.GetType()) { case wxDF_OEMTEXT: @@ -61,57 +61,57 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) } #if TARGET_CARBON - ScrapRef scrapRef; - - err = GetCurrentScrap( &scrapRef ); - if ( err != noTypeErr && err != memFullErr ) - { - ScrapFlavorFlags flavorFlags; - Size byteCount; - - if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) - { - if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) - { - if ( dataFormat.GetType() == wxDF_TEXT ) - byteCount++ ; - + ScrapRef scrapRef; + + err = GetCurrentScrap( &scrapRef ); + if ( err != noTypeErr && err != memFullErr ) + { + ScrapFlavorFlags flavorFlags; + Size byteCount; + + if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + if ( dataFormat.GetType() == wxDF_TEXT ) + byteCount++ ; + data = new char[ byteCount ] ; if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr ) { *len = byteCount ; - if ( dataFormat.GetType() == wxDF_TEXT ) - ((char*)data)[byteCount] = 0 ; + if ( dataFormat.GetType() == wxDF_TEXT ) + ((char*)data)[byteCount] = 0 ; } else { delete[] ((char *)data) ; data = NULL ; } - } - } - } - + } + } + } + #else - long offset ; - Handle datahandle = NewHandle(0) ; - HLock( datahandle ) ; - GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; - HUnlock( datahandle ) ; - if ( GetHandleSize( datahandle ) > 0 ) - { - long byteCount = GetHandleSize( datahandle ) ; - if ( dataFormat.GetType() == wxDF_TEXT ) - data = new char[ byteCount + 1] ; + long offset ; + Handle datahandle = NewHandle(0) ; + HLock( datahandle ) ; + GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; + HUnlock( datahandle ) ; + if ( GetHandleSize( datahandle ) > 0 ) + { + long byteCount = GetHandleSize( datahandle ) ; + if ( dataFormat.GetType() == wxDF_TEXT ) + data = new char[ byteCount + 1] ; else data = new char[ byteCount ] ; - memcpy( (char*) data , (char*) *datahandle , byteCount ) ; - if ( dataFormat.GetType() == wxDF_TEXT ) - ((char*)data)[byteCount] = 0 ; - * len = byteCount ; - } - DisposeHandle( datahandle ) ; + memcpy( (char*) data , (char*) *datahandle , byteCount ) ; + if ( dataFormat.GetType() == wxDF_TEXT ) + ((char*)data)[byteCount] = 0 ; + * len = byteCount ; + } + DisposeHandle( datahandle ) ; #endif if ( err ) { @@ -156,16 +156,16 @@ void wxClipboard::Clear() m_data = (wxDataObject*) NULL; } #if TARGET_CARBON - OSStatus err ; - err = ClearCurrentScrap( ); + OSStatus err ; + err = ClearCurrentScrap( ); #else - OSErr err ; - err = ZeroScrap( ); + OSErr err ; + err = ZeroScrap( ); #endif - if ( err ) - { + if ( err ) + { wxLogSysError(_("Failed to empty the clipboard.")); - } + } } bool wxClipboard::Flush() @@ -220,9 +220,9 @@ bool wxClipboard::AddData( wxDataObject *data ) array[i].GetId().c_str() ); #if !TARGET_CARBON - OSErr err = noErr ; + OSErr err = noErr ; #else - OSStatus err = noErr ; + OSStatus err = noErr ; #endif switch ( array[i].GetType() ) @@ -232,26 +232,27 @@ bool wxClipboard::AddData( wxDataObject *data ) { wxTextDataObject* textDataObject = (wxTextDataObject*) data; wxString str(textDataObject->GetText()); - wxString mac ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - mac = wxMacMakeMacStringFromPC(textDataObject->GetText()) ; - } - else - { - mac = textDataObject->GetText() ; - } + wxString mac ; + if ( wxApp::s_macDefaultEncodingIsPC ) + { + mac = wxMacMakeMacStringFromPC(textDataObject->GetText()) ; + } + else + { + mac = textDataObject->GetText() ; + } #if !TARGET_CARBON - err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; + err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; #else - ScrapRef scrap; - err = GetCurrentScrap (&scrap); - if ( !err ) - { - err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); - } + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); + } #endif } + break; #if wxUSE_DRAG_AND_DROP case wxDF_METAFILE: @@ -259,25 +260,26 @@ bool wxClipboard::AddData( wxDataObject *data ) wxMetafileDataObject* metaFileDataObject = (wxMetafileDataObject*) data; wxMetafile metaFile = metaFileDataObject->GetMetafile(); - PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; - HLock( (Handle) pict ) ; + PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; + HLock( (Handle) pict ) ; #if !TARGET_CARBON - err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; + err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; #else - ScrapRef scrap; - err = GetCurrentScrap (&scrap); - if ( !err ) - { - err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); - } + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); + } #endif - HUnlock( (Handle) pict ) ; + HUnlock( (Handle) pict ) ; } + break; #endif case wxDF_BITMAP: case wxDF_DIB: default: - break ; + break ; } } @@ -299,34 +301,34 @@ bool wxClipboard::IsSupported( const wxDataFormat &dataFormat ) return m_data->IsSupported( dataFormat ) ; } #if TARGET_CARBON - OSStatus err = noErr; - ScrapRef scrapRef; - - err = GetCurrentScrap( &scrapRef ); - if ( err != noTypeErr && err != memFullErr ) - { - ScrapFlavorFlags flavorFlags; - Size byteCount; - - if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) - { - if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) - { - return TRUE ; - } - } - } - return FALSE; - + OSStatus err = noErr; + ScrapRef scrapRef; + + err = GetCurrentScrap( &scrapRef ); + if ( err != noTypeErr && err != memFullErr ) + { + ScrapFlavorFlags flavorFlags; + Size byteCount; + + if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + return TRUE ; + } + } + } + return FALSE; + #else - long offset ; - Handle datahandle = NewHandle(0) ; - HLock( datahandle ) ; - GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; - HUnlock( datahandle ) ; - bool hasData = GetHandleSize( datahandle ) > 0 ; - DisposeHandle( datahandle ) ; - return hasData ; + long offset ; + Handle datahandle = NewHandle(0) ; + HLock( datahandle ) ; + GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; + HUnlock( datahandle ) ; + bool hasData = GetHandleSize( datahandle ) > 0 ; + DisposeHandle( datahandle ) ; + return hasData ; #endif } diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 12f077a7cd..1fc24445ba 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -179,7 +179,7 @@ void wxTopLevelWindowMac::Iconize(bool iconize) bool wxTopLevelWindowMac::IsIconized() const { - // mac dialogs cannot be iconized + // mac dialogs cannot be iconized return FALSE; } @@ -420,13 +420,6 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) event.m_x += m_x; event.m_y += m_y; -/* - wxPoint origin = GetClientAreaOrigin() ; - - event.m_x += origin.x ; - event.m_y += origin.y ; -*/ - event.m_timeStamp = ev->when; event.SetEventObject(this); if ( wxTheApp->s_captureWindow ) @@ -437,6 +430,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) event.m_x = x ; event.m_y = y ; wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; + if ( ev->what == mouseUp ) { wxTheApp->s_captureWindow = NULL ; diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 7462e3ab8e..834c2cdc04 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -352,9 +352,9 @@ void wxWindowMac::DoScreenToClient(int *x, int *y) const MacRootWindowToWindow( x , y ) ; if ( x ) - x -= MacGetLeftBorderSize() ; + x -= MacGetLeftBorderSize() ; if ( y ) - y -= MacGetTopBorderSize() ; + y -= MacGetTopBorderSize() ; } void wxWindowMac::DoClientToScreen(int *x, int *y) const @@ -362,10 +362,10 @@ void wxWindowMac::DoClientToScreen(int *x, int *y) const WindowRef window = (WindowRef) MacGetRootWindow() ; if ( x ) - x += MacGetLeftBorderSize() ; + x += MacGetLeftBorderSize() ; if ( y ) - y += MacGetTopBorderSize() ; - + y += MacGetTopBorderSize() ; + MacWindowToRootWindow( x , y ) ; Point localwhere = { 0,0 }; @@ -678,12 +678,12 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const void wxWindow::SetTitle(const wxString& title) { - m_label = title ; + m_label = title ; } wxString wxWindow::GetTitle() const { - return m_label ; + return m_label ; } bool wxWindowMac::Show(bool show) @@ -1023,17 +1023,17 @@ void wxWindowMac::MacPaintBorders( int left , int top ) if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { #if wxMAC_USE_THEME_BORDER - Rect rect = { top , left , m_height + top , m_width + left } ; - SInt32 border = 0 ; - /* - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; - InsetRect( &rect , border , border ); + Rect rect = { top , left , m_height + top , m_width + left } ; + SInt32 border = 0 ; + /* + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + InsetRect( &rect , border , border ); DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; */ DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; #else - bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; RGBForeColor( &face ); MoveTo( left + 0 , top + m_height - 2 ); LineTo( left + 0 , top + 0 ); @@ -1066,7 +1066,7 @@ void wxWindowMac::MacPaintBorders( int left , int top ) } else if (HasFlag(wxSIMPLE_BORDER)) { - Rect rect = { top , left , m_height + top , m_width + left } ; + Rect rect = { top , left , m_height + top , m_width + left } ; RGBForeColor( &black ) ; FrameRect( &rect ) ; } @@ -1350,15 +1350,25 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) { WindowRef window ; + Point pt = { screenpoint.y , screenpoint.x } ; if ( ::FindWindow( pt , &window ) == 3 ) { - wxPoint point( screenpoint ) ; + wxWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) { - point = win->ScreenToClient( point ) ; - point += win->GetClientAreaOrigin() ; + // No, this yields the CLIENT are, we need the whole frame. RR. + // point = win->ScreenToClient( point ) ; + + GrafPtr port; + ::GetPort( &port ) ; + ::SetPort( UMAGetWindowPort( window ) ) ; + ::GlobalToLocal( &pt ) ; + ::SetPort( port ) ; + + wxPoint point( pt.h, pt.v ) ; + return win->MacGetWindowFromPointSub( point , outWin ) ; } } @@ -1416,7 +1426,9 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) || event.GetEventType() == wxEVT_LEAVE_WINDOW ) wxToolTip::RelayEvent( this , event); #endif // wxUSE_TOOLTIPS + GetEventHandler()->ProcessEvent( event ) ; + return TRUE; } @@ -1435,11 +1447,11 @@ void wxWindowMac::Update() if ( win ) { win->MacUpdate( 0 ) ; - if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) - { - QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; - } - } + if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) + { + QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; + } + } } wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const @@ -1769,23 +1781,23 @@ long wxWindowMac::MacGetLeftBorderSize( ) const if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) { - SInt32 border = 3 ; + SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; +#if TARGET_CARBON + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; #endif #endif - return border ; + return border ; } else if ( m_windowStyle &wxDOUBLE_BORDER) { - SInt32 border = 3 ; + SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; +#if TARGET_CARBON + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; #endif #endif - return border ; + return border ; } else if (m_windowStyle &wxSIMPLE_BORDER) { diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp index 0aa8806e03..651f6f4722 100644 --- a/src/mac/clipbrd.cpp +++ b/src/mac/clipbrd.cpp @@ -6,7 +6,7 @@ // Created: ??/??/98 // RCS-ID: $Id$ // Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -39,12 +39,12 @@ static const wxChar *TRACE_CLIPBOARD = _T("clipboard"); void *wxGetClipboardData(wxDataFormat dataFormat, long *len) { #if !TARGET_CARBON - OSErr err = noErr ; + OSErr err = noErr ; #else - OSStatus err = noErr ; + OSStatus err = noErr ; #endif void * data = NULL ; - + switch (dataFormat.GetType()) { case wxDF_OEMTEXT: @@ -61,57 +61,57 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) } #if TARGET_CARBON - ScrapRef scrapRef; - - err = GetCurrentScrap( &scrapRef ); - if ( err != noTypeErr && err != memFullErr ) - { - ScrapFlavorFlags flavorFlags; - Size byteCount; - - if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) - { - if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) - { - if ( dataFormat.GetType() == wxDF_TEXT ) - byteCount++ ; - + ScrapRef scrapRef; + + err = GetCurrentScrap( &scrapRef ); + if ( err != noTypeErr && err != memFullErr ) + { + ScrapFlavorFlags flavorFlags; + Size byteCount; + + if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + if ( dataFormat.GetType() == wxDF_TEXT ) + byteCount++ ; + data = new char[ byteCount ] ; if (( err = GetScrapFlavorData( scrapRef, dataFormat.GetFormatId(), &byteCount , data )) == noErr ) { *len = byteCount ; - if ( dataFormat.GetType() == wxDF_TEXT ) - ((char*)data)[byteCount] = 0 ; + if ( dataFormat.GetType() == wxDF_TEXT ) + ((char*)data)[byteCount] = 0 ; } else { delete[] ((char *)data) ; data = NULL ; } - } - } - } - + } + } + } + #else - long offset ; - Handle datahandle = NewHandle(0) ; - HLock( datahandle ) ; - GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; - HUnlock( datahandle ) ; - if ( GetHandleSize( datahandle ) > 0 ) - { - long byteCount = GetHandleSize( datahandle ) ; - if ( dataFormat.GetType() == wxDF_TEXT ) - data = new char[ byteCount + 1] ; + long offset ; + Handle datahandle = NewHandle(0) ; + HLock( datahandle ) ; + GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; + HUnlock( datahandle ) ; + if ( GetHandleSize( datahandle ) > 0 ) + { + long byteCount = GetHandleSize( datahandle ) ; + if ( dataFormat.GetType() == wxDF_TEXT ) + data = new char[ byteCount + 1] ; else data = new char[ byteCount ] ; - memcpy( (char*) data , (char*) *datahandle , byteCount ) ; - if ( dataFormat.GetType() == wxDF_TEXT ) - ((char*)data)[byteCount] = 0 ; - * len = byteCount ; - } - DisposeHandle( datahandle ) ; + memcpy( (char*) data , (char*) *datahandle , byteCount ) ; + if ( dataFormat.GetType() == wxDF_TEXT ) + ((char*)data)[byteCount] = 0 ; + * len = byteCount ; + } + DisposeHandle( datahandle ) ; #endif if ( err ) { @@ -156,16 +156,16 @@ void wxClipboard::Clear() m_data = (wxDataObject*) NULL; } #if TARGET_CARBON - OSStatus err ; - err = ClearCurrentScrap( ); + OSStatus err ; + err = ClearCurrentScrap( ); #else - OSErr err ; - err = ZeroScrap( ); + OSErr err ; + err = ZeroScrap( ); #endif - if ( err ) - { + if ( err ) + { wxLogSysError(_("Failed to empty the clipboard.")); - } + } } bool wxClipboard::Flush() @@ -220,9 +220,9 @@ bool wxClipboard::AddData( wxDataObject *data ) array[i].GetId().c_str() ); #if !TARGET_CARBON - OSErr err = noErr ; + OSErr err = noErr ; #else - OSStatus err = noErr ; + OSStatus err = noErr ; #endif switch ( array[i].GetType() ) @@ -232,26 +232,27 @@ bool wxClipboard::AddData( wxDataObject *data ) { wxTextDataObject* textDataObject = (wxTextDataObject*) data; wxString str(textDataObject->GetText()); - wxString mac ; - if ( wxApp::s_macDefaultEncodingIsPC ) - { - mac = wxMacMakeMacStringFromPC(textDataObject->GetText()) ; - } - else - { - mac = textDataObject->GetText() ; - } + wxString mac ; + if ( wxApp::s_macDefaultEncodingIsPC ) + { + mac = wxMacMakeMacStringFromPC(textDataObject->GetText()) ; + } + else + { + mac = textDataObject->GetText() ; + } #if !TARGET_CARBON - err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; + err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; #else - ScrapRef scrap; - err = GetCurrentScrap (&scrap); - if ( !err ) - { - err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); - } + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); + } #endif } + break; #if wxUSE_DRAG_AND_DROP case wxDF_METAFILE: @@ -259,25 +260,26 @@ bool wxClipboard::AddData( wxDataObject *data ) wxMetafileDataObject* metaFileDataObject = (wxMetafileDataObject*) data; wxMetafile metaFile = metaFileDataObject->GetMetafile(); - PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; - HLock( (Handle) pict ) ; + PicHandle pict = (PicHandle) metaFile.GetHMETAFILE() ; + HLock( (Handle) pict ) ; #if !TARGET_CARBON - err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; + err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; #else - ScrapRef scrap; - err = GetCurrentScrap (&scrap); - if ( !err ) - { - err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); - } + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); + } #endif - HUnlock( (Handle) pict ) ; + HUnlock( (Handle) pict ) ; } + break; #endif case wxDF_BITMAP: case wxDF_DIB: default: - break ; + break ; } } @@ -299,34 +301,34 @@ bool wxClipboard::IsSupported( const wxDataFormat &dataFormat ) return m_data->IsSupported( dataFormat ) ; } #if TARGET_CARBON - OSStatus err = noErr; - ScrapRef scrapRef; - - err = GetCurrentScrap( &scrapRef ); - if ( err != noTypeErr && err != memFullErr ) - { - ScrapFlavorFlags flavorFlags; - Size byteCount; - - if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) - { - if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) - { - return TRUE ; - } - } - } - return FALSE; - + OSStatus err = noErr; + ScrapRef scrapRef; + + err = GetCurrentScrap( &scrapRef ); + if ( err != noTypeErr && err != memFullErr ) + { + ScrapFlavorFlags flavorFlags; + Size byteCount; + + if (( err = GetScrapFlavorFlags( scrapRef, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + return TRUE ; + } + } + } + return FALSE; + #else - long offset ; - Handle datahandle = NewHandle(0) ; - HLock( datahandle ) ; - GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; - HUnlock( datahandle ) ; - bool hasData = GetHandleSize( datahandle ) > 0 ; - DisposeHandle( datahandle ) ; - return hasData ; + long offset ; + Handle datahandle = NewHandle(0) ; + HLock( datahandle ) ; + GetScrap( datahandle , dataFormat.GetFormatId() , &offset ) ; + HUnlock( datahandle ) ; + bool hasData = GetHandleSize( datahandle ) > 0 ; + DisposeHandle( datahandle ) ; + return hasData ; #endif } diff --git a/src/mac/toplevel.cpp b/src/mac/toplevel.cpp index 12f077a7cd..1fc24445ba 100644 --- a/src/mac/toplevel.cpp +++ b/src/mac/toplevel.cpp @@ -179,7 +179,7 @@ void wxTopLevelWindowMac::Iconize(bool iconize) bool wxTopLevelWindowMac::IsIconized() const { - // mac dialogs cannot be iconized + // mac dialogs cannot be iconized return FALSE; } @@ -420,13 +420,6 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) event.m_x += m_x; event.m_y += m_y; -/* - wxPoint origin = GetClientAreaOrigin() ; - - event.m_x += origin.x ; - event.m_y += origin.y ; -*/ - event.m_timeStamp = ev->when; event.SetEventObject(this); if ( wxTheApp->s_captureWindow ) @@ -437,6 +430,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent( WXEVENTREF evr ) event.m_x = x ; event.m_y = y ; wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; + if ( ev->what == mouseUp ) { wxTheApp->s_captureWindow = NULL ; diff --git a/src/mac/window.cpp b/src/mac/window.cpp index 7462e3ab8e..834c2cdc04 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -352,9 +352,9 @@ void wxWindowMac::DoScreenToClient(int *x, int *y) const MacRootWindowToWindow( x , y ) ; if ( x ) - x -= MacGetLeftBorderSize() ; + x -= MacGetLeftBorderSize() ; if ( y ) - y -= MacGetTopBorderSize() ; + y -= MacGetTopBorderSize() ; } void wxWindowMac::DoClientToScreen(int *x, int *y) const @@ -362,10 +362,10 @@ void wxWindowMac::DoClientToScreen(int *x, int *y) const WindowRef window = (WindowRef) MacGetRootWindow() ; if ( x ) - x += MacGetLeftBorderSize() ; + x += MacGetLeftBorderSize() ; if ( y ) - y += MacGetTopBorderSize() ; - + y += MacGetTopBorderSize() ; + MacWindowToRootWindow( x , y ) ; Point localwhere = { 0,0 }; @@ -678,12 +678,12 @@ wxPoint wxWindowMac::GetClientAreaOrigin() const void wxWindow::SetTitle(const wxString& title) { - m_label = title ; + m_label = title ; } wxString wxWindow::GetTitle() const { - return m_label ; + return m_label ; } bool wxWindowMac::Show(bool show) @@ -1023,17 +1023,17 @@ void wxWindowMac::MacPaintBorders( int left , int top ) if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { #if wxMAC_USE_THEME_BORDER - Rect rect = { top , left , m_height + top , m_width + left } ; - SInt32 border = 0 ; - /* - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; - InsetRect( &rect , border , border ); + Rect rect = { top , left , m_height + top , m_width + left } ; + SInt32 border = 0 ; + /* + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + InsetRect( &rect , border , border ); DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; */ DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; #else - bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; RGBForeColor( &face ); MoveTo( left + 0 , top + m_height - 2 ); LineTo( left + 0 , top + 0 ); @@ -1066,7 +1066,7 @@ void wxWindowMac::MacPaintBorders( int left , int top ) } else if (HasFlag(wxSIMPLE_BORDER)) { - Rect rect = { top , left , m_height + top , m_width + left } ; + Rect rect = { top , left , m_height + top , m_width + left } ; RGBForeColor( &black ) ; FrameRect( &rect ) ; } @@ -1350,15 +1350,25 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) { WindowRef window ; + Point pt = { screenpoint.y , screenpoint.x } ; if ( ::FindWindow( pt , &window ) == 3 ) { - wxPoint point( screenpoint ) ; + wxWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) { - point = win->ScreenToClient( point ) ; - point += win->GetClientAreaOrigin() ; + // No, this yields the CLIENT are, we need the whole frame. RR. + // point = win->ScreenToClient( point ) ; + + GrafPtr port; + ::GetPort( &port ) ; + ::SetPort( UMAGetWindowPort( window ) ) ; + ::GlobalToLocal( &pt ) ; + ::SetPort( port ) ; + + wxPoint point( pt.h, pt.v ) ; + return win->MacGetWindowFromPointSub( point , outWin ) ; } } @@ -1416,7 +1426,9 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) || event.GetEventType() == wxEVT_LEAVE_WINDOW ) wxToolTip::RelayEvent( this , event); #endif // wxUSE_TOOLTIPS + GetEventHandler()->ProcessEvent( event ) ; + return TRUE; } @@ -1435,11 +1447,11 @@ void wxWindowMac::Update() if ( win ) { win->MacUpdate( 0 ) ; - if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) - { - QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; - } - } + if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) ) + { + QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ; + } + } } wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const @@ -1769,23 +1781,23 @@ long wxWindowMac::MacGetLeftBorderSize( ) const if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) { - SInt32 border = 3 ; + SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; +#if TARGET_CARBON + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; #endif #endif - return border ; + return border ; } else if ( m_windowStyle &wxDOUBLE_BORDER) { - SInt32 border = 3 ; + SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; +#if TARGET_CARBON + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; #endif #endif - return border ; + return border ; } else if (m_windowStyle &wxSIMPLE_BORDER) { -- 2.45.2