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
|
||||
@@ -71,25 +61,36 @@ wxDataFormat::wxDataFormat( NativeFormat 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)
|
||||
{
|
||||
case wxDF_TEXT:
|
||||
m_format = kScrapFlavorTypeText;
|
||||
break;
|
||||
|
||||
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") );
|
||||
|
||||
// this is '????' but it can't be used in the code because ??' is
|
||||
// parsed as a trigraph!
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,21 +106,31 @@ 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 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,14 +144,10 @@ void wxDataFormat::SetId( const wxChar* zId )
|
||||
bool wxDataFormat::operator==(const wxDataFormat& format) const
|
||||
{
|
||||
if (IsStandard() || format.IsStandard())
|
||||
{
|
||||
return (format.m_type == m_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (m_id == format.m_id);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// wxDataObject
|
||||
@@ -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 );
|
||||
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;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -193,17 +196,17 @@ void wxTextDataObject::GetAllFormats(wxDataFormat *formats, wxDataObjectBase::Di
|
||||
*formats++ = wxDataFormat( wxDF_TEXT );
|
||||
*formats = wxDataFormat( wxDF_UNICODETEXT );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFileDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFileDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
bool wxFileDataObject::GetDataHere( void *pBuf ) const
|
||||
{
|
||||
if (pBuf == NULL)
|
||||
return false;
|
||||
|
||||
wxString sFilenames;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
@@ -213,7 +216,8 @@ bool wxFileDataObject::GetDataHere(
|
||||
}
|
||||
|
||||
memcpy( pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1 );
|
||||
return TRUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxFileDataObject::GetDataSize() const
|
||||
@@ -229,24 +233,19 @@ 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 )
|
||||
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 );
|
||||
}
|
||||
@@ -260,12 +259,11 @@ wxBitmapDataObject::wxBitmapDataObject()
|
||||
Init();
|
||||
}
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap )
|
||||
: wxBitmapDataObjectBase( rBitmap )
|
||||
{
|
||||
Init();
|
||||
|
||||
if (m_bitmap.Ok())
|
||||
{
|
||||
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
|
||||
@@ -278,9 +276,7 @@ wxBitmapDataObject::~wxBitmapDataObject()
|
||||
Clear();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetBitmap(
|
||||
const wxBitmap& rBitmap
|
||||
)
|
||||
void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
|
||||
{
|
||||
Clear();
|
||||
wxBitmapDataObjectBase::SetBitmap( rBitmap );
|
||||
@@ -299,40 +295,51 @@ void wxBitmapDataObject::Init()
|
||||
|
||||
void wxBitmapDataObject::Clear()
|
||||
{
|
||||
if ( m_pictCreated && m_pictHandle )
|
||||
if (m_pictHandle != NULL)
|
||||
{
|
||||
if (m_pictCreated)
|
||||
KillPicture( (PicHandle)m_pictHandle );
|
||||
}
|
||||
m_pictHandle = NULL;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere(
|
||||
void* pBuf
|
||||
) const
|
||||
m_pictCreated = false;
|
||||
}
|
||||
|
||||
bool wxBitmapDataObject::GetDataHere( void *pBuf ) const
|
||||
{
|
||||
if (!m_pictHandle)
|
||||
if (m_pictHandle == NULL)
|
||||
{
|
||||
wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") );
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pBuf == NULL)
|
||||
return false;
|
||||
|
||||
memcpy( pBuf, *(Handle)m_pictHandle, GetHandleSize( (Handle)m_pictHandle ) );
|
||||
return TRUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wxBitmapDataObject::GetDataSize() const
|
||||
{
|
||||
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();
|
||||
|
||||
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;
|
||||
|
@@ -51,8 +51,8 @@ wxDropTarget::wxDropTarget( wxDataObject *data )
|
||||
wxMacEnsureTrackingHandlersInstalled();
|
||||
}
|
||||
|
||||
wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
|
||||
wxCoord WXUNUSED(y),
|
||||
wxDragResult wxDropTarget::OnDragOver(
|
||||
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
{
|
||||
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
|
||||
@@ -66,7 +66,8 @@ bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
|
||||
return CurrentDragHasSupportedFormat();
|
||||
}
|
||||
|
||||
wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult wxDropTarget::OnData(
|
||||
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
{
|
||||
if (m_dataObject == NULL)
|
||||
@@ -243,20 +244,22 @@ bool wxDropTarget::GetData()
|
||||
theData = NULL;
|
||||
|
||||
GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L );
|
||||
if ( theType == kScrapFlavorTypeText )
|
||||
switch (theType)
|
||||
{
|
||||
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 );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
else if ( theType == kDragFlavorTypeHFS )
|
||||
|
||||
case kDragFlavorTypeHFS:
|
||||
{
|
||||
wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
|
||||
wxASSERT( fdo != NULL );
|
||||
@@ -277,9 +280,11 @@ bool wxDropTarget::GetData()
|
||||
fdo->AddFile( name );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
||||
default:
|
||||
m_dataObject->SetData( format, dataSize, theData );
|
||||
break;
|
||||
}
|
||||
|
||||
delete [] theData;
|
||||
@@ -434,13 +439,15 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||
const short dragRegionInnerBoundary = 9;
|
||||
|
||||
SetRectRgn(
|
||||
dragRegion , ev->where.h - dragRegionOuterBoundary ,
|
||||
dragRegion,
|
||||
ev->where.h - dragRegionOuterBoundary,
|
||||
ev->where.v - dragRegionOuterBoundary,
|
||||
ev->where.h + dragRegionOuterBoundary,
|
||||
ev->where.v + dragRegionOuterBoundary );
|
||||
|
||||
SetRectRgn(
|
||||
tempRgn , ev->where.h - dragRegionInnerBoundary ,
|
||||
tempRgn,
|
||||
ev->where.h - dragRegionInnerBoundary,
|
||||
ev->where.v - dragRegionInnerBoundary,
|
||||
ev->where.h + dragRegionInnerBoundary,
|
||||
ev->where.v + dragRegionInnerBoundary );
|
||||
|
Reference in New Issue
Block a user