cleanup - minor restructuring, reformatting
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: mac/dataobj.cpp
|
||||
// Name: src/mac/carbon/dataobj.cpp
|
||||
// Purpose: implementation of wxDataObject class
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
@@ -9,14 +9,6 @@
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
@@ -33,13 +25,11 @@
|
||||
#include "wx/image.h"
|
||||
#include "wx/metafile.h"
|
||||
#include "wx/mac/private.h"
|
||||
|
||||
#ifndef __DARWIN__
|
||||
#include <Scrap.h>
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxDataFormat
|
||||
@@ -51,45 +41,56 @@ wxDataFormat::wxDataFormat()
|
||||
m_format = 0;
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( wxDataFormatId vType )
|
||||
wxDataFormat::wxDataFormat( wxDataFormatId vType )
|
||||
{
|
||||
SetType(vType);
|
||||
SetType( vType );
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( const wxChar* zId)
|
||||
wxDataFormat::wxDataFormat( const wxChar *zId )
|
||||
{
|
||||
SetId(zId);
|
||||
SetId( zId );
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( const wxString& rId)
|
||||
wxDataFormat::wxDataFormat( const wxString& rId )
|
||||
{
|
||||
SetId(rId);
|
||||
SetId( rId );
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( NativeFormat vFormat)
|
||||
wxDataFormat::wxDataFormat( NativeFormat vFormat )
|
||||
{
|
||||
SetId(vFormat);
|
||||
SetId( vFormat );
|
||||
}
|
||||
|
||||
void wxDataFormat::SetType( wxDataFormatId Type )
|
||||
void wxDataFormat::SetType( wxDataFormatId dataType )
|
||||
{
|
||||
m_type = Type;
|
||||
m_type = dataType;
|
||||
|
||||
if (m_type == wxDF_TEXT )
|
||||
m_format = kScrapFlavorTypeText;
|
||||
else if (m_type == wxDF_UNICODETEXT )
|
||||
m_format = kScrapFlavorTypeUnicode ;
|
||||
else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE )
|
||||
m_format = kScrapFlavorTypePicture;
|
||||
else if (m_type == wxDF_FILENAME)
|
||||
m_format = kDragFlavorTypeHFS ;
|
||||
else
|
||||
switch (m_type)
|
||||
{
|
||||
wxFAIL_MSG( wxT("invalid dataformat") );
|
||||
case wxDF_TEXT:
|
||||
m_format = kScrapFlavorTypeText;
|
||||
break;
|
||||
|
||||
// this is '????' but it can't be used in the code because ??' is
|
||||
// parsed as a trigraph!
|
||||
case wxDF_UNICODETEXT:
|
||||
m_format = kScrapFlavorTypeUnicode;
|
||||
break;
|
||||
|
||||
case wxDF_BITMAP:
|
||||
case wxDF_METAFILE:
|
||||
m_format = kScrapFlavorTypePicture;
|
||||
break;
|
||||
|
||||
case wxDF_FILENAME:
|
||||
m_format = kDragFlavorTypeHFS;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( wxT("invalid data format") );
|
||||
|
||||
// NB: this translates to '????' ASCII but it can't be used in the code
|
||||
// because '??' will get parsed as a trigraph!
|
||||
m_format = 0x3f3f3f3f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,48 +99,54 @@ wxString wxDataFormat::GetId() const
|
||||
wxCHECK_MSG( !IsStandard(), wxEmptyString ,
|
||||
wxT("name of predefined format cannot be retrieved") );
|
||||
|
||||
return m_id ;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId( NativeFormat format )
|
||||
void wxDataFormat::SetId( NativeFormat format )
|
||||
{
|
||||
m_format = format;
|
||||
|
||||
if (m_format == kScrapFlavorTypeText)
|
||||
m_type = wxDF_TEXT;
|
||||
else if (m_format == kScrapFlavorTypeUnicode )
|
||||
m_type = wxDF_UNICODETEXT;
|
||||
else if (m_format == kScrapFlavorTypePicture)
|
||||
m_type = wxDF_BITMAP;
|
||||
else if (m_format == kDragFlavorTypeHFS )
|
||||
m_type = wxDF_FILENAME;
|
||||
else
|
||||
switch (m_format)
|
||||
{
|
||||
case kScrapFlavorTypeText:
|
||||
m_type = wxDF_TEXT;
|
||||
break;
|
||||
|
||||
case kScrapFlavorTypeUnicode:
|
||||
m_type = wxDF_UNICODETEXT;
|
||||
break;
|
||||
|
||||
case kScrapFlavorTypePicture:
|
||||
m_type = wxDF_BITMAP;
|
||||
break;
|
||||
|
||||
case kDragFlavorTypeHFS:
|
||||
m_type = wxDF_FILENAME;
|
||||
break;
|
||||
|
||||
default:
|
||||
m_type = wxDF_PRIVATE;
|
||||
char text[5] ;
|
||||
strncpy( text , (char*) &format , 4 ) ;
|
||||
text[4] = 0 ;
|
||||
m_id = wxString::FromAscii( text ) ;
|
||||
char text[5];
|
||||
strncpy( text, (char*)&format, 4 );
|
||||
text[4] = 0;
|
||||
m_id = wxString::FromAscii( text );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId( const wxChar* zId )
|
||||
{
|
||||
m_type = wxDF_PRIVATE;
|
||||
m_id = zId ;
|
||||
m_format = 'WXPR' ;
|
||||
m_id = zId;
|
||||
m_format = 'WXPR';
|
||||
}
|
||||
|
||||
bool wxDataFormat::operator==(const wxDataFormat& format) const
|
||||
bool wxDataFormat::operator==(const wxDataFormat& format) const
|
||||
{
|
||||
if ( IsStandard() || format.IsStandard() )
|
||||
{
|
||||
return ( format.m_type == m_type ) ;
|
||||
}
|
||||
if (IsStandard() || format.IsStandard())
|
||||
return (format.m_type == m_type);
|
||||
else
|
||||
{
|
||||
return ( m_id == format.m_id ) ;
|
||||
}
|
||||
return (m_id == format.m_id);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -150,37 +157,33 @@ wxDataObject::wxDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDataObject::IsSupportedFormat(
|
||||
const wxDataFormat& rFormat
|
||||
, Direction vDir
|
||||
) const
|
||||
bool wxDataObject::IsSupportedFormat( const wxDataFormat& rFormat, Direction vDir ) const
|
||||
{
|
||||
size_t nFormatCount = GetFormatCount(vDir);
|
||||
size_t nFormatCount = GetFormatCount( vDir );
|
||||
bool found = false;
|
||||
|
||||
if (nFormatCount == 1)
|
||||
{
|
||||
return rFormat == GetPreferredFormat();
|
||||
found = (rFormat == GetPreferredFormat());
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataFormat* pFormats = new wxDataFormat[nFormatCount];
|
||||
GetAllFormats( pFormats
|
||||
,vDir
|
||||
);
|
||||
GetAllFormats( pFormats, vDir );
|
||||
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < nFormatCount; n++)
|
||||
for (size_t n = 0; n < nFormatCount; n++)
|
||||
{
|
||||
if (pFormats[n] == rFormat)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] pFormats;
|
||||
|
||||
// found?
|
||||
return n < nFormatCount;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -188,23 +191,23 @@ bool wxDataObject::IsSupportedFormat(
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Direction dir) const
|
||||
void wxTextDataObject::GetAllFormats( wxDataFormat *formats, wxDataObjectBase::Direction dir ) const
|
||||
{
|
||||
*formats++ = wxDataFormat( wxDF_TEXT );
|
||||
*formats = wxDataFormat( wxDF_UNICODETEXT );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
bool wxFileDataObject::GetDataHere( void *pBuf ) const
|
||||
{
|
||||
wxString sFilenames;
|
||||
if (pBuf == NULL)
|
||||
return false;
|
||||
|
||||
wxString sFilenames;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
@@ -212,8 +215,9 @@ bool wxFileDataObject::GetDataHere(
|
||||
sFilenames += (wxChar)0;
|
||||
}
|
||||
|
||||
memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1);
|
||||
return TRUE;
|
||||
memcpy( pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxFileDataObject::GetDataSize() const
|
||||
@@ -229,26 +233,21 @@ size_t wxFileDataObject::GetDataSize() const
|
||||
return nRes + 1;
|
||||
}
|
||||
|
||||
bool wxFileDataObject::SetData(
|
||||
size_t WXUNUSED(nSize)
|
||||
, const void* pBuf
|
||||
)
|
||||
bool wxFileDataObject::SetData( size_t WXUNUSED(nSize), const void *pBuf )
|
||||
{
|
||||
m_filenames.Empty();
|
||||
|
||||
// only add if this is not an empty string
|
||||
// we can therefore clear the list by just setting an empty string
|
||||
if ( (*(char*)pBuf) != 0 )
|
||||
AddFile(wxString::FromAscii((char*)pBuf));
|
||||
if ((*(const char*)pBuf) != 0)
|
||||
AddFile( wxString::FromAscii( (char*)pBuf) );
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxFileDataObject::AddFile(
|
||||
const wxString& rFilename
|
||||
)
|
||||
void wxFileDataObject::AddFile( const wxString& rFilename )
|
||||
{
|
||||
m_filenames.Add(rFilename);
|
||||
m_filenames.Add( rFilename );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -260,16 +259,15 @@ wxBitmapDataObject::wxBitmapDataObject()
|
||||
Init();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
: wxBitmapDataObjectBase(rBitmap)
|
||||
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap )
|
||||
: wxBitmapDataObjectBase( rBitmap )
|
||||
{
|
||||
Init();
|
||||
if ( m_bitmap.Ok() )
|
||||
|
||||
if (m_bitmap.Ok())
|
||||
{
|
||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ;
|
||||
m_pictCreated = false ;
|
||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
||||
m_pictCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,74 +276,83 @@ wxBitmapDataObject::~wxBitmapDataObject()
|
||||
Clear();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetBitmap(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
|
||||
{
|
||||
Clear();
|
||||
wxBitmapDataObjectBase::SetBitmap(rBitmap);
|
||||
if ( m_bitmap.Ok() )
|
||||
wxBitmapDataObjectBase::SetBitmap( rBitmap );
|
||||
if (m_bitmap.Ok())
|
||||
{
|
||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle() ;
|
||||
m_pictCreated = false ;
|
||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
||||
m_pictCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::Init()
|
||||
{
|
||||
m_pictHandle = NULL ;
|
||||
m_pictCreated = false ;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::Clear()
|
||||
void wxBitmapDataObject::Init()
|
||||
{
|
||||
if ( m_pictCreated && m_pictHandle )
|
||||
{
|
||||
KillPicture( (PicHandle) m_pictHandle ) ;
|
||||
}
|
||||
m_pictHandle = NULL ;
|
||||
m_pictHandle = NULL;
|
||||
m_pictCreated = false;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
void wxBitmapDataObject::Clear()
|
||||
{
|
||||
if (!m_pictHandle)
|
||||
if (m_pictHandle != NULL)
|
||||
{
|
||||
wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
|
||||
return FALSE;
|
||||
if (m_pictCreated)
|
||||
KillPicture( (PicHandle)m_pictHandle );
|
||||
m_pictHandle = NULL;
|
||||
}
|
||||
memcpy(pBuf, *(Handle)m_pictHandle, GetHandleSize((Handle)m_pictHandle));
|
||||
return TRUE;
|
||||
|
||||
m_pictCreated = false;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere( void *pBuf ) const
|
||||
{
|
||||
if (m_pictHandle == NULL)
|
||||
{
|
||||
wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") );
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pBuf == NULL)
|
||||
return false;
|
||||
|
||||
memcpy( pBuf, *(Handle)m_pictHandle, GetHandleSize( (Handle)m_pictHandle ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxBitmapDataObject::GetDataSize() const
|
||||
{
|
||||
return GetHandleSize((Handle)m_pictHandle) ;
|
||||
if (m_pictHandle != NULL)
|
||||
return GetHandleSize( (Handle)m_pictHandle );
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::SetData(
|
||||
size_t nSize
|
||||
, const void* pBuf
|
||||
)
|
||||
bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
|
||||
{
|
||||
Clear();
|
||||
PicHandle picHandle = (PicHandle) NewHandle( nSize ) ;
|
||||
memcpy( *picHandle , pBuf , nSize ) ;
|
||||
m_pictHandle = picHandle ;
|
||||
|
||||
if ((pBuf == NULL) || (nSize == 0))
|
||||
return false;
|
||||
|
||||
PicHandle picHandle = (PicHandle)NewHandle( nSize );
|
||||
memcpy( *picHandle, pBuf, nSize );
|
||||
m_pictHandle = picHandle;
|
||||
|
||||
// ownership is transferred to the bitmap
|
||||
m_pictCreated = false ;
|
||||
Rect frame = (**picHandle).picFrame ;
|
||||
|
||||
wxMetafile mf ;
|
||||
mf.SetHMETAFILE( (WXHMETAFILE) m_pictHandle ) ;
|
||||
wxMemoryDC mdc ;
|
||||
m_bitmap.Create( frame.right - frame.left ,frame.bottom - frame.top ) ;
|
||||
mdc.SelectObject(m_bitmap ) ;
|
||||
mf.Play( &mdc ) ;
|
||||
mdc.SelectObject( wxNullBitmap ) ;
|
||||
|
||||
m_pictCreated = false;
|
||||
Rect frame = (**picHandle).picFrame;
|
||||
|
||||
wxMetafile mf;
|
||||
mf.SetHMETAFILE( (WXHMETAFILE)m_pictHandle );
|
||||
wxMemoryDC mdc;
|
||||
m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top );
|
||||
mdc.SelectObject( m_bitmap );
|
||||
mf.Play( &mdc );
|
||||
mdc.SelectObject( wxNullBitmap );
|
||||
|
||||
return m_bitmap.Ok();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -31,15 +31,15 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wxWindow* m_currentTargetWindow;
|
||||
wxDropTarget* m_currentTarget;
|
||||
wxDropSource* m_currentSource;
|
||||
wxWindow *m_currentTargetWindow;
|
||||
wxDropTarget *m_currentTarget;
|
||||
wxDropSource *m_currentSource;
|
||||
}
|
||||
MacTrackingGlobals;
|
||||
|
||||
MacTrackingGlobals gTrackingGlobals;
|
||||
|
||||
void wxMacEnsureTrackingHandlersInstalled() ;
|
||||
void wxMacEnsureTrackingHandlersInstalled();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDropTarget
|
||||
@@ -48,12 +48,12 @@ void wxMacEnsureTrackingHandlersInstalled() ;
|
||||
wxDropTarget::wxDropTarget( wxDataObject *data )
|
||||
: wxDropTargetBase( data )
|
||||
{
|
||||
wxMacEnsureTrackingHandlersInstalled() ;
|
||||
wxMacEnsureTrackingHandlersInstalled();
|
||||
}
|
||||
|
||||
wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
|
||||
wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
wxDragResult wxDropTarget::OnDragOver(
|
||||
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
{
|
||||
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
|
||||
}
|
||||
@@ -63,11 +63,12 @@ bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
|
||||
if (m_dataObject == NULL)
|
||||
return false;
|
||||
|
||||
return CurrentDragHasSupportedFormat() ;
|
||||
return CurrentDragHasSupportedFormat();
|
||||
}
|
||||
|
||||
wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
wxDragResult wxDropTarget::OnData(
|
||||
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
{
|
||||
if (m_dataObject == NULL)
|
||||
return wxDragNone;
|
||||
@@ -80,59 +81,59 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
|
||||
bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||
{
|
||||
bool supported = false ;
|
||||
bool supported = false;
|
||||
|
||||
if ( gTrackingGlobals.m_currentSource != NULL )
|
||||
{
|
||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject();
|
||||
|
||||
if ( data )
|
||||
{
|
||||
size_t formatcount = data->GetFormatCount() ;
|
||||
size_t formatcount = data->GetFormatCount();
|
||||
wxDataFormat *array = new wxDataFormat[formatcount];
|
||||
data->GetAllFormats( array );
|
||||
for (size_t i = 0; !supported && i < formatcount ; i++)
|
||||
for (size_t i = 0; !supported && i < formatcount; i++)
|
||||
{
|
||||
wxDataFormat format = array[i] ;
|
||||
wxDataFormat format = array[i];
|
||||
if ( m_dataObject->IsSupported( format ) )
|
||||
{
|
||||
supported = true ;
|
||||
break ;
|
||||
supported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] array ;
|
||||
delete [] array;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !supported )
|
||||
{
|
||||
UInt16 items ;
|
||||
UInt16 items;
|
||||
OSErr result;
|
||||
ItemReference theItem;
|
||||
FlavorType theType ;
|
||||
UInt16 flavors = 0 ;
|
||||
FlavorType theType;
|
||||
UInt16 flavors = 0;
|
||||
|
||||
CountDragItems( (DragReference)m_currentDrag, &items );
|
||||
for (UInt16 index = 1; index <= items && !supported; ++index)
|
||||
{
|
||||
flavors = 0 ;
|
||||
flavors = 0;
|
||||
GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
|
||||
CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors );
|
||||
|
||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||
for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
|
||||
{
|
||||
result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
|
||||
if ( m_dataObject->IsSupportedFormat( wxDataFormat( theType ) ) )
|
||||
{
|
||||
supported = true ;
|
||||
break ;
|
||||
supported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return supported ;
|
||||
return supported;
|
||||
}
|
||||
|
||||
bool wxDropTarget::GetData()
|
||||
@@ -181,60 +182,60 @@ bool wxDropTarget::GetData()
|
||||
|
||||
if ( !transferred )
|
||||
{
|
||||
UInt16 items ;
|
||||
UInt16 items;
|
||||
OSErr result;
|
||||
ItemReference theItem;
|
||||
FlavorType theType ;
|
||||
FlavorType theType;
|
||||
FlavorFlags theFlags;
|
||||
UInt16 flavors ;
|
||||
bool firstFileAdded = false ;
|
||||
UInt16 flavors;
|
||||
bool firstFileAdded = false;
|
||||
|
||||
CountDragItems( (DragReference)m_currentDrag, &items );
|
||||
for (UInt16 index = 1; index <= items; ++index)
|
||||
{
|
||||
flavors = 0 ;
|
||||
flavors = 0;
|
||||
GetDragItemReferenceNumber( (DragReference)m_currentDrag, index, &theItem );
|
||||
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors );
|
||||
CountDragItemFlavors( (DragReference)m_currentDrag, theItem, &flavors );
|
||||
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set );
|
||||
bool hasPreferredFormat = false ;
|
||||
bool hasPreferredFormat = false;
|
||||
|
||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||
for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
|
||||
{
|
||||
result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
|
||||
wxDataFormat format( theType );
|
||||
if ( preferredFormat == format )
|
||||
{
|
||||
hasPreferredFormat = true ;
|
||||
break ;
|
||||
hasPreferredFormat = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||
for ( UInt16 flavor = 1; flavor <= flavors; ++flavor )
|
||||
{
|
||||
result = GetFlavorType( (DragReference)m_currentDrag, theItem, flavor, &theType );
|
||||
wxDataFormat format( theType ) ;
|
||||
wxDataFormat format( theType );
|
||||
if ( (hasPreferredFormat && format == preferredFormat)
|
||||
|| (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
|
||||
{
|
||||
result = GetFlavorFlags( (DragReference)m_currentDrag, theItem, theType, &theFlags );
|
||||
if (result == noErr)
|
||||
{
|
||||
Size dataSize ;
|
||||
Ptr theData ;
|
||||
Size dataSize;
|
||||
Ptr theData;
|
||||
|
||||
GetFlavorDataSize( (DragReference)m_currentDrag, theItem, theType, &dataSize );
|
||||
if ( theType == kScrapFlavorTypeText )
|
||||
{
|
||||
// this increment is only valid for allocating:
|
||||
// on the next GetFlavorData call it is reset again to the original value
|
||||
dataSize++ ;
|
||||
dataSize++;
|
||||
}
|
||||
else if ( theType == kScrapFlavorTypeUnicode )
|
||||
{
|
||||
// this increment is only valid for allocating:
|
||||
// on the next GetFlavorData call it is reset again to the original value
|
||||
dataSize++ ;
|
||||
dataSize++ ;
|
||||
dataSize++;
|
||||
dataSize++;
|
||||
}
|
||||
|
||||
if (dataSize > 0)
|
||||
@@ -243,54 +244,58 @@ bool wxDropTarget::GetData()
|
||||
theData = NULL;
|
||||
|
||||
GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L );
|
||||
if ( theType == kScrapFlavorTypeText )
|
||||
switch (theType)
|
||||
{
|
||||
theData[dataSize] = 0 ;
|
||||
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
|
||||
}
|
||||
case kScrapFlavorTypeText:
|
||||
theData[dataSize] = 0;
|
||||
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize, theData );
|
||||
break;
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
else if ( theType == kScrapFlavorTypeUnicode )
|
||||
{
|
||||
case kScrapFlavorTypeUnicode:
|
||||
theData[dataSize + 0] =
|
||||
theData[dataSize + 1] = 0 ;
|
||||
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData );
|
||||
}
|
||||
theData[dataSize + 1] = 0;
|
||||
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize, theData );
|
||||
break;
|
||||
#endif
|
||||
else if ( theType == kDragFlavorTypeHFS )
|
||||
{
|
||||
wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
|
||||
wxASSERT( fdo != NULL );
|
||||
|
||||
if ((theData != NULL) && (fdo != NULL))
|
||||
case kDragFlavorTypeHFS:
|
||||
{
|
||||
HFSFlavor* theFile = (HFSFlavor*) theData ;
|
||||
wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec ) ;
|
||||
wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
|
||||
wxASSERT( fdo != NULL );
|
||||
|
||||
if ( !firstFileAdded )
|
||||
if ((theData != NULL) && (fdo != NULL))
|
||||
{
|
||||
// reset file list
|
||||
fdo->SetData( 0 , "" ) ;
|
||||
firstFileAdded = true ;
|
||||
}
|
||||
HFSFlavor* theFile = (HFSFlavor*) theData;
|
||||
wxString name = wxMacFSSpec2MacFilename( &theFile->fileSpec );
|
||||
|
||||
if (!name.IsEmpty())
|
||||
fdo->AddFile( name ) ;
|
||||
if ( !firstFileAdded )
|
||||
{
|
||||
// reset file list
|
||||
fdo->SetData( 0, "" );
|
||||
firstFileAdded = true;
|
||||
}
|
||||
|
||||
if (!name.IsEmpty())
|
||||
fdo->AddFile( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
||||
default:
|
||||
m_dataObject->SetData( format, dataSize, theData );
|
||||
break;
|
||||
}
|
||||
|
||||
delete [] theData;
|
||||
}
|
||||
break ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -306,7 +311,7 @@ wxDropSource::wxDropSource(wxWindow *win,
|
||||
const wxCursor &cursorStop)
|
||||
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
|
||||
{
|
||||
wxMacEnsureTrackingHandlersInstalled() ;
|
||||
wxMacEnsureTrackingHandlersInstalled();
|
||||
|
||||
m_window = win;
|
||||
}
|
||||
@@ -318,7 +323,7 @@ wxDropSource::wxDropSource(wxDataObject& data,
|
||||
const wxCursor &cursorStop)
|
||||
: wxDropSourceBase(cursorCopy, cursorMove, cursorStop)
|
||||
{
|
||||
wxMacEnsureTrackingHandlersInstalled() ;
|
||||
wxMacEnsureTrackingHandlersInstalled();
|
||||
|
||||
SetData( data );
|
||||
m_window = win;
|
||||
@@ -341,41 +346,41 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||
DragReference theDrag;
|
||||
RgnHandle dragRegion;
|
||||
if ((result = NewDrag(&theDrag)) != noErr)
|
||||
return wxDragNone ;
|
||||
return wxDragNone;
|
||||
|
||||
// add data to drag
|
||||
size_t formatCount = m_data->GetFormatCount() ;
|
||||
wxDataFormat *formats = new wxDataFormat[formatCount] ;
|
||||
m_data->GetAllFormats( formats ) ;
|
||||
ItemReference theItem = 1 ;
|
||||
size_t formatCount = m_data->GetFormatCount();
|
||||
wxDataFormat *formats = new wxDataFormat[formatCount];
|
||||
m_data->GetAllFormats( formats );
|
||||
ItemReference theItem = 1;
|
||||
|
||||
for ( size_t i = 0 ; i < formatCount ; ++i )
|
||||
for ( size_t i = 0; i < formatCount; ++i )
|
||||
{
|
||||
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
|
||||
Ptr dataPtr = new char[dataSize] ;
|
||||
m_data->GetDataHere( formats[i] , dataPtr ) ;
|
||||
OSType type = formats[i].GetFormatId() ;
|
||||
size_t dataSize = m_data->GetDataSize( formats[i] );
|
||||
Ptr dataPtr = new char[dataSize];
|
||||
m_data->GetDataHere( formats[i], dataPtr );
|
||||
OSType type = formats[i].GetFormatId();
|
||||
if ( type == 'TEXT' || type == 'utxt' )
|
||||
{
|
||||
if ( dataSize > 0 )
|
||||
dataSize-- ;
|
||||
dataPtr[ dataSize ] = 0 ;
|
||||
dataSize--;
|
||||
dataPtr[ dataSize ] = 0;
|
||||
if ( type == 'utxt' )
|
||||
{
|
||||
if ( dataSize > 0 )
|
||||
dataSize-- ;
|
||||
dataPtr[ dataSize ] = 0 ;
|
||||
dataSize--;
|
||||
dataPtr[ dataSize ] = 0;
|
||||
}
|
||||
|
||||
AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
|
||||
AddDragItemFlavor( theDrag, theItem, type, dataPtr, dataSize, 0 );
|
||||
}
|
||||
else if (type == kDragFlavorTypeHFS )
|
||||
{
|
||||
HFSFlavor theFlavor ;
|
||||
HFSFlavor theFlavor;
|
||||
OSErr err = noErr;
|
||||
CInfoPBRec cat;
|
||||
|
||||
wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec ) ;
|
||||
wxMacFilename2FSSpec( wxString( dataPtr, *wxConvCurrent ), &theFlavor.fileSpec );
|
||||
|
||||
memset( &cat, 0, sizeof(cat) );
|
||||
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
|
||||
@@ -402,51 +407,53 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
|
||||
}
|
||||
|
||||
AddDragItemFlavor( theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0 );
|
||||
AddDragItemFlavor( theDrag, theItem, type, &theFlavor, sizeof(theFlavor), 0 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddDragItemFlavor( theDrag, theItem, type , dataPtr, dataSize, 0 );
|
||||
AddDragItemFlavor( theDrag, theItem, type, dataPtr, dataSize, 0 );
|
||||
}
|
||||
|
||||
delete [] dataPtr ;
|
||||
delete [] dataPtr;
|
||||
}
|
||||
|
||||
delete [] formats ;
|
||||
delete [] formats;
|
||||
|
||||
dragRegion = NewRgn();
|
||||
RgnHandle tempRgn = NewRgn() ;
|
||||
RgnHandle tempRgn = NewRgn();
|
||||
|
||||
EventRecord* ev = NULL ;
|
||||
EventRecord* ev = NULL;
|
||||
|
||||
#if !TARGET_CARBON // TODO
|
||||
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
|
||||
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
|
||||
#else
|
||||
{
|
||||
EventRecord rec ;
|
||||
ev = &rec ;
|
||||
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
|
||||
EventRecord rec;
|
||||
ev = &rec;
|
||||
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent(), &rec );
|
||||
}
|
||||
#endif
|
||||
|
||||
const short dragRegionOuterBoundary = 10 ;
|
||||
const short dragRegionInnerBoundary = 9 ;
|
||||
const short dragRegionOuterBoundary = 10;
|
||||
const short dragRegionInnerBoundary = 9;
|
||||
|
||||
SetRectRgn(
|
||||
dragRegion , ev->where.h - dragRegionOuterBoundary ,
|
||||
ev->where.v - dragRegionOuterBoundary ,
|
||||
ev->where.h + dragRegionOuterBoundary ,
|
||||
ev->where.v + dragRegionOuterBoundary ) ;
|
||||
dragRegion,
|
||||
ev->where.h - dragRegionOuterBoundary,
|
||||
ev->where.v - dragRegionOuterBoundary,
|
||||
ev->where.h + dragRegionOuterBoundary,
|
||||
ev->where.v + dragRegionOuterBoundary );
|
||||
|
||||
SetRectRgn(
|
||||
tempRgn , ev->where.h - dragRegionInnerBoundary ,
|
||||
ev->where.v - dragRegionInnerBoundary ,
|
||||
ev->where.h + dragRegionInnerBoundary ,
|
||||
ev->where.v + dragRegionInnerBoundary ) ;
|
||||
tempRgn,
|
||||
ev->where.h - dragRegionInnerBoundary,
|
||||
ev->where.v - dragRegionInnerBoundary,
|
||||
ev->where.h + dragRegionInnerBoundary,
|
||||
ev->where.v + dragRegionInnerBoundary );
|
||||
|
||||
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
|
||||
DisposeRgn( tempRgn ) ;
|
||||
DiffRgn( dragRegion, tempRgn, dragRegion );
|
||||
DisposeRgn( tempRgn );
|
||||
|
||||
// TODO: work with promises in order to return data
|
||||
// only when drag was successfully completed
|
||||
@@ -477,7 +484,7 @@ bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool gTrackingGlobalsInstalled = false ;
|
||||
bool gTrackingGlobalsInstalled = false;
|
||||
|
||||
// passing the globals via refcon is not needed by the CFM and later architectures anymore
|
||||
// but I'll leave it in there, just in case...
|
||||
@@ -516,9 +523,9 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
|
||||
GetDragAttributes( theDrag, &attributes );
|
||||
|
||||
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
|
||||
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow );
|
||||
|
||||
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
||||
bool optionDown = GetCurrentKeyModifiers() & optionKey;
|
||||
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
||||
|
||||
switch (theMessage)
|
||||
@@ -530,8 +537,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
case kDragTrackingEnterWindow:
|
||||
if (trackingGlobals != NULL)
|
||||
{
|
||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||
trackingGlobals->m_currentTarget = NULL ;
|
||||
trackingGlobals->m_currentTargetWindow = NULL;
|
||||
trackingGlobals->m_currentTarget = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -546,21 +553,21 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
GlobalToLocal( &localMouse );
|
||||
|
||||
{
|
||||
wxWindow *win = NULL ;
|
||||
ControlPartCode controlPart ;
|
||||
wxWindow *win = NULL;
|
||||
ControlPartCode controlPart;
|
||||
ControlRef control = wxMacFindControlUnderMouse(
|
||||
toplevel , localMouse , theWindow , &controlPart ) ;
|
||||
toplevel, localMouse, theWindow, &controlPart );
|
||||
if ( control )
|
||||
win = wxFindControlFromMacControl( control ) ;
|
||||
win = wxFindControlFromMacControl( control );
|
||||
else
|
||||
win = toplevel ;
|
||||
win = toplevel;
|
||||
|
||||
int localx , localy ;
|
||||
localx = localMouse.h ;
|
||||
localy = localMouse.v ;
|
||||
int localx, localy;
|
||||
localx = localMouse.h;
|
||||
localy = localMouse.v;
|
||||
|
||||
if ( win )
|
||||
win->MacRootWindowToWindow( &localx , &localy ) ;
|
||||
win->MacRootWindowToWindow( &localx, &localy );
|
||||
if ( win != trackingGlobals->m_currentTargetWindow )
|
||||
{
|
||||
if ( trackingGlobals->m_currentTargetWindow )
|
||||
@@ -579,26 +586,26 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
if ( win )
|
||||
{
|
||||
// this window is entered
|
||||
trackingGlobals->m_currentTargetWindow = win ;
|
||||
trackingGlobals->m_currentTarget = win->GetDropTarget() ;
|
||||
trackingGlobals->m_currentTargetWindow = win;
|
||||
trackingGlobals->m_currentTarget = win->GetDropTarget();
|
||||
{
|
||||
if ( trackingGlobals->m_currentTarget )
|
||||
{
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||
result = trackingGlobals->m_currentTarget->OnEnter( localx , localy , result ) ;
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
|
||||
result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
|
||||
}
|
||||
|
||||
if ( result != wxDragNone )
|
||||
{
|
||||
int x , y ;
|
||||
int x, y;
|
||||
|
||||
x = y = 0 ;
|
||||
win->MacWindowToRootWindow( &x , &y ) ;
|
||||
RgnHandle hiliteRgn = NewRgn() ;
|
||||
Rect r = { y , x , y + win->GetSize().y , x + win->GetSize().x } ;
|
||||
RectRgn( hiliteRgn , &r ) ;
|
||||
x = y = 0;
|
||||
win->MacWindowToRootWindow( &x, &y );
|
||||
RgnHandle hiliteRgn = NewRgn();
|
||||
Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
|
||||
RectRgn( hiliteRgn, &r );
|
||||
ShowDragHilite( theDrag, hiliteRgn, true );
|
||||
DisposeRgn( hiliteRgn ) ;
|
||||
DisposeRgn( hiliteRgn );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -607,8 +614,8 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
{
|
||||
if ( trackingGlobals->m_currentTarget )
|
||||
{
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||
trackingGlobals->m_currentTarget->OnDragOver( localx , localy , result ) ;
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
|
||||
trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,24 +628,24 @@ pascal OSErr wxMacWindowDragTrackingHandler(
|
||||
{
|
||||
case wxDragCopy:
|
||||
{
|
||||
wxCursor cursor(wxCURSOR_COPY_ARROW) ;
|
||||
cursor.MacInstall() ;
|
||||
wxCursor cursor(wxCURSOR_COPY_ARROW);
|
||||
cursor.MacInstall();
|
||||
}
|
||||
break ;
|
||||
break;
|
||||
|
||||
case wxDragMove:
|
||||
{
|
||||
wxCursor cursor(wxCURSOR_ARROW) ;
|
||||
cursor.MacInstall() ;
|
||||
wxCursor cursor(wxCURSOR_ARROW);
|
||||
cursor.MacInstall();
|
||||
}
|
||||
break ;
|
||||
break;
|
||||
|
||||
case wxDragNone:
|
||||
{
|
||||
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
|
||||
cursor.MacInstall() ;
|
||||
wxCursor cursor(wxCURSOR_NO_ENTRY);
|
||||
cursor.MacInstall();
|
||||
}
|
||||
break ;
|
||||
break;
|
||||
|
||||
case wxDragError:
|
||||
case wxDragLink:
|
||||
@@ -681,24 +688,24 @@ pascal OSErr wxMacWindowDragReceiveHandler(
|
||||
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
|
||||
if ( trackingGlobals->m_currentTarget )
|
||||
{
|
||||
Point mouse, localMouse ;
|
||||
int localx, localy ;
|
||||
Point mouse, localMouse;
|
||||
int localx, localy;
|
||||
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||
GetDragMouse(theDrag, &mouse, 0L);
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
|
||||
GetDragMouse( theDrag, &mouse, 0L );
|
||||
localMouse = mouse;
|
||||
GlobalToLocal(&localMouse);
|
||||
localx = localMouse.h ;
|
||||
localy = localMouse.v ;
|
||||
GlobalToLocal( &localMouse );
|
||||
localx = localMouse.h;
|
||||
localy = localMouse.v;
|
||||
|
||||
// TODO : should we use client coordinates?
|
||||
if ( trackingGlobals->m_currentTargetWindow )
|
||||
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
|
||||
if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) )
|
||||
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx, &localy );
|
||||
if ( trackingGlobals->m_currentTarget->OnDrop( localx, localy ) )
|
||||
{
|
||||
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
||||
bool optionDown = GetCurrentKeyModifiers() & optionKey;
|
||||
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
||||
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
|
||||
trackingGlobals->m_currentTarget->OnData( localx, localy, result );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user