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:
David Surovell
2006-03-15 19:22:01 +00:00
parent 05fd6a8b82
commit 51d4293d68
2 changed files with 321 additions and 307 deletions

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Name: mac/dataobj.cpp // Name: src/mac/carbon/dataobj.cpp
// Purpose: implementation of wxDataObject class // Purpose: implementation of wxDataObject class
// Author: Stefan Csomor // Author: Stefan Csomor
// Modified by: // Modified by:
@@ -9,14 +9,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -33,13 +25,11 @@
#include "wx/image.h" #include "wx/image.h"
#include "wx/metafile.h" #include "wx/metafile.h"
#include "wx/mac/private.h" #include "wx/mac/private.h"
#ifndef __DARWIN__ #ifndef __DARWIN__
#include <Scrap.h> #include <Scrap.h>
#endif #endif
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
@@ -71,25 +61,36 @@ 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 ) switch (m_type)
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
{ {
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") ); wxFAIL_MSG( wxT("invalid data format") );
// this is '????' but it can't be used in the code because ??' is // NB: this translates to '????' ASCII but it can't be used in the code
// parsed as a trigraph! // because '??' will get parsed as a trigraph!
m_format = 0x3f3f3f3f; m_format = 0x3f3f3f3f;
break;
} }
} }
@@ -105,21 +106,31 @@ void wxDataFormat::SetId( NativeFormat format )
{ {
m_format = format; m_format = format;
if (m_format == kScrapFlavorTypeText) switch (m_format)
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
{ {
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; m_type = wxDF_PRIVATE;
char text[5]; char text[5];
strncpy( text, (char*)&format, 4 ); strncpy( text, (char*)&format, 4 );
text[4] = 0; text[4] = 0;
m_id = wxString::FromAscii( text ); m_id = wxString::FromAscii( text );
break;
} }
} }
@@ -133,14 +144,10 @@ void wxDataFormat::SetId( const wxChar* zId )
bool wxDataFormat::operator==(const wxDataFormat& format) const bool wxDataFormat::operator==(const wxDataFormat& format) const
{ {
if (IsStandard() || format.IsStandard()) if (IsStandard() || format.IsStandard())
{
return (format.m_type == m_type); return (format.m_type == m_type);
}
else else
{
return (m_id == format.m_id); return (m_id == format.m_id);
} }
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataObject // wxDataObject
@@ -150,37 +157,33 @@ wxDataObject::wxDataObject()
{ {
} }
bool wxDataObject::IsSupportedFormat( bool wxDataObject::IsSupportedFormat( const wxDataFormat& rFormat, Direction vDir ) const
const wxDataFormat& rFormat
, Direction vDir
) const
{ {
size_t nFormatCount = GetFormatCount( vDir ); size_t nFormatCount = GetFormatCount( vDir );
bool found = false;
if (nFormatCount == 1) if (nFormatCount == 1)
{ {
return rFormat == GetPreferredFormat(); found = (rFormat == GetPreferredFormat());
} }
else else
{ {
wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; wxDataFormat* pFormats = new wxDataFormat[nFormatCount];
GetAllFormats( pFormats GetAllFormats( pFormats, vDir );
,vDir
);
size_t n; for (size_t n = 0; n < nFormatCount; n++)
for (n = 0; n < nFormatCount; n++)
{ {
if (pFormats[n] == rFormat) if (pFormats[n] == rFormat)
{
found = true;
break; break;
} }
}
delete [] pFormats; 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_TEXT );
*formats = wxDataFormat( wxDF_UNICODETEXT ); *formats = wxDataFormat( wxDF_UNICODETEXT );
} }
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFileDataObject // wxFileDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxFileDataObject::GetDataHere( bool wxFileDataObject::GetDataHere( void *pBuf ) const
void* pBuf
) const
{ {
if (pBuf == NULL)
return false;
wxString sFilenames; wxString sFilenames;
for (size_t i = 0; i < m_filenames.GetCount(); i++) 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 ); memcpy( pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1 );
return TRUE;
return true;
} }
size_t wxFileDataObject::GetDataSize() const size_t wxFileDataObject::GetDataSize() const
@@ -229,24 +233,19 @@ size_t wxFileDataObject::GetDataSize() const
return nRes + 1; return nRes + 1;
} }
bool wxFileDataObject::SetData( bool wxFileDataObject::SetData( size_t WXUNUSED(nSize), const void *pBuf )
size_t WXUNUSED(nSize)
, const void* pBuf
)
{ {
m_filenames.Empty(); m_filenames.Empty();
// only add if this is not an empty string // only add if this is not an empty string
// we can therefore clear the list by just setting 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) ); AddFile( wxString::FromAscii( (char*)pBuf) );
return TRUE; return true;
} }
void wxFileDataObject::AddFile( void wxFileDataObject::AddFile( const wxString& rFilename )
const wxString& rFilename
)
{ {
m_filenames.Add( rFilename ); m_filenames.Add( rFilename );
} }
@@ -260,12 +259,11 @@ wxBitmapDataObject::wxBitmapDataObject()
Init(); Init();
} }
wxBitmapDataObject::wxBitmapDataObject( wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& rBitmap )
const wxBitmap& rBitmap
)
: wxBitmapDataObjectBase( rBitmap ) : wxBitmapDataObjectBase( rBitmap )
{ {
Init(); Init();
if (m_bitmap.Ok()) if (m_bitmap.Ok())
{ {
m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle(); m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
@@ -278,9 +276,7 @@ wxBitmapDataObject::~wxBitmapDataObject()
Clear(); Clear();
} }
void wxBitmapDataObject::SetBitmap( void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
const wxBitmap& rBitmap
)
{ {
Clear(); Clear();
wxBitmapDataObjectBase::SetBitmap( rBitmap ); wxBitmapDataObjectBase::SetBitmap( rBitmap );
@@ -299,40 +295,51 @@ void wxBitmapDataObject::Init()
void wxBitmapDataObject::Clear() void wxBitmapDataObject::Clear()
{ {
if ( m_pictCreated && m_pictHandle ) if (m_pictHandle != NULL)
{ {
if (m_pictCreated)
KillPicture( (PicHandle)m_pictHandle ); KillPicture( (PicHandle)m_pictHandle );
}
m_pictHandle = NULL; m_pictHandle = NULL;
} }
bool wxBitmapDataObject::GetDataHere( m_pictCreated = false;
void* pBuf }
) const
bool wxBitmapDataObject::GetDataHere( void *pBuf ) const
{ {
if (!m_pictHandle) if (m_pictHandle == NULL)
{ {
wxFAIL_MSG( wxT("attempt to copy empty bitmap failed") ); 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 ) ); memcpy( pBuf, *(Handle)m_pictHandle, GetHandleSize( (Handle)m_pictHandle ) );
return TRUE;
return true;
} }
size_t wxBitmapDataObject::GetDataSize() const size_t wxBitmapDataObject::GetDataSize() const
{ {
if (m_pictHandle != NULL)
return GetHandleSize( (Handle)m_pictHandle ); return GetHandleSize( (Handle)m_pictHandle );
else
return 0;
} }
bool wxBitmapDataObject::SetData( bool wxBitmapDataObject::SetData( size_t nSize, const void *pBuf )
size_t nSize
, const void* pBuf
)
{ {
Clear(); Clear();
if ((pBuf == NULL) || (nSize == 0))
return false;
PicHandle picHandle = (PicHandle)NewHandle( nSize ); PicHandle picHandle = (PicHandle)NewHandle( nSize );
memcpy( *picHandle, pBuf, nSize ); memcpy( *picHandle, pBuf, nSize );
m_pictHandle = picHandle; m_pictHandle = picHandle;
// ownership is transferred to the bitmap // ownership is transferred to the bitmap
m_pictCreated = false; m_pictCreated = false;
Rect frame = (**picHandle).picFrame; Rect frame = (**picHandle).picFrame;

View File

@@ -51,8 +51,8 @@ wxDropTarget::wxDropTarget( wxDataObject *data )
wxMacEnsureTrackingHandlersInstalled(); wxMacEnsureTrackingHandlersInstalled();
} }
wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x), wxDragResult wxDropTarget::OnDragOver(
wxCoord WXUNUSED(y), wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def ) wxDragResult def )
{ {
return CurrentDragHasSupportedFormat() ? def : wxDragNone; return CurrentDragHasSupportedFormat() ? def : wxDragNone;
@@ -66,7 +66,8 @@ bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
return CurrentDragHasSupportedFormat(); return CurrentDragHasSupportedFormat();
} }
wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult wxDropTarget::OnData(
wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
wxDragResult def ) wxDragResult def )
{ {
if (m_dataObject == NULL) if (m_dataObject == NULL)
@@ -243,20 +244,22 @@ bool wxDropTarget::GetData()
theData = NULL; theData = NULL;
GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L ); GetFlavorData( (DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L );
if ( theType == kScrapFlavorTypeText ) switch (theType)
{ {
case kScrapFlavorTypeText:
theData[dataSize] = 0; theData[dataSize] = 0;
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize, theData ); m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize, theData );
} break;
#if wxUSE_UNICODE #if wxUSE_UNICODE
else if ( theType == kScrapFlavorTypeUnicode ) case kScrapFlavorTypeUnicode:
{
theData[dataSize + 0] = theData[dataSize + 0] =
theData[dataSize + 1] = 0; theData[dataSize + 1] = 0;
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize, theData ); m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize, theData );
} break;
#endif #endif
else if ( theType == kDragFlavorTypeHFS )
case kDragFlavorTypeHFS:
{ {
wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject); wxFileDataObject *fdo = dynamic_cast<wxFileDataObject*>(m_dataObject);
wxASSERT( fdo != NULL ); wxASSERT( fdo != NULL );
@@ -277,9 +280,11 @@ bool wxDropTarget::GetData()
fdo->AddFile( name ); fdo->AddFile( name );
} }
} }
else break;
{
default:
m_dataObject->SetData( format, dataSize, theData ); m_dataObject->SetData( format, dataSize, theData );
break;
} }
delete [] theData; delete [] theData;
@@ -434,13 +439,15 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
const short dragRegionInnerBoundary = 9; const short dragRegionInnerBoundary = 9;
SetRectRgn( SetRectRgn(
dragRegion , ev->where.h - dragRegionOuterBoundary , dragRegion,
ev->where.h - dragRegionOuterBoundary,
ev->where.v - dragRegionOuterBoundary, ev->where.v - dragRegionOuterBoundary,
ev->where.h + dragRegionOuterBoundary, ev->where.h + dragRegionOuterBoundary,
ev->where.v + dragRegionOuterBoundary ); ev->where.v + dragRegionOuterBoundary );
SetRectRgn( SetRectRgn(
tempRgn , ev->where.h - dragRegionInnerBoundary , tempRgn,
ev->where.h - dragRegionInnerBoundary,
ev->where.v - dragRegionInnerBoundary, ev->where.v - dragRegionInnerBoundary,
ev->where.h + dragRegionInnerBoundary, ev->where.h + dragRegionInnerBoundary,
ev->where.v + dragRegionInnerBoundary ); ev->where.v + dragRegionInnerBoundary );