git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36670
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/carbon/combobox.cpp
// Purpose: wxComboBox class
/////////////////////////////////////////////////////////////////////////////
// Name: src/mac/carbon/combobox.cpp
// Purpose: wxComboBox class
-// Author: Stefan Csomor
+// Author: Stefan Csomor, Dan "Bud" Keith (composite combobox)
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id$
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
-// composite combobox implementation by Dan "Bud" Keith bud@otsys.com
-
static int nextPopUpMenuId = 1000 ;
static int nextPopUpMenuId = 1000 ;
MenuHandle NewUniqueMenu()
{
MenuHandle NewUniqueMenu()
{
- MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
- nextPopUpMenuId++ ;
- return handle ;
+ MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
+ nextPopUpMenuId++ ;
+
+ return handle ;
event.SetInt( m_cb->GetSelection() );
event.SetEventObject( m_cb );
event.SetInt( m_cb->GetSelection() );
event.SetEventObject( m_cb );
- // This will invoke the dialog default action, such
- // as the clicking the default button.
-
+ // This will invoke the dialog default action,
+ // such as the clicking the default button.
if (!m_cb->GetEventHandler()->ProcessEvent( event ))
{
wxWindow *parent = GetParent();
if (!m_cb->GetEventHandler()->ProcessEvent( event ))
{
wxWindow *parent = GetParent();
- while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
+ while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
parent = parent->GetParent() ;
parent = parent->GetParent() ;
if ( parent && parent->GetDefaultItem() )
{
if ( parent && parent->GetDefaultItem() )
{
- wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
- wxButton);
+ wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() )
{
if ( def && def->IsEnabled() )
{
- wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+ wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
event.SetEventObject(def);
def->Command(event);
}
event.SetEventObject(def);
def->Command(event);
}
};
BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
};
BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
- EVT_KEY_DOWN( wxComboBoxText::OnKeyDown)
- EVT_CHAR( wxComboBoxText::OnChar)
- EVT_KEY_UP( wxComboBoxText::OnKeyUp)
- EVT_TEXT( -1, wxComboBoxText::OnText)
+ EVT_KEY_DOWN(wxComboBoxText::OnKeyDown)
+ EVT_CHAR(wxComboBoxText::OnChar)
+ EVT_KEY_UP(wxComboBoxText::OnKeyUp)
+ EVT_TEXT(-1, wxComboBoxText::OnText)
END_EVENT_TABLE()
class wxComboBoxChoice : public wxChoice
{
public:
END_EVENT_TABLE()
class wxComboBoxChoice : public wxChoice
{
public:
- wxComboBoxChoice(wxComboBox *cb, int style)
+ wxComboBoxChoice( wxComboBox *cb, int style )
: wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
{
m_cb = cb;
}
: wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
{
m_cb = cb;
}
int GetPopupWidth() const
{
switch ( GetWindowVariant() )
int GetPopupWidth() const
{
switch ( GetWindowVariant() )
case wxWINDOW_VARIANT_NORMAL :
case wxWINDOW_VARIANT_LARGE :
return 24 ;
case wxWINDOW_VARIANT_NORMAL :
case wxWINDOW_VARIANT_LARGE :
return 24 ;
TextEvent.SetEventObject( m_cb );
m_cb->ProcessCommand( TextEvent );
}
TextEvent.SetEventObject( m_cb );
m_cb->ProcessCommand( TextEvent );
}
virtual wxSize DoGetBestSize() const
{
wxSize sz = wxChoice::DoGetBestSize() ;
if (! m_cb->HasFlag(wxCB_READONLY) )
sz.x = GetPopupWidth() ;
virtual wxSize DoGetBestSize() const
{
wxSize sz = wxChoice::DoGetBestSize() ;
if (! m_cb->HasFlag(wxCB_READONLY) )
sz.x = GetPopupWidth() ;
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
+ if (m_text != NULL)
+ {
delete m_text;
m_text = NULL;
}
delete m_text;
m_text = NULL;
}
- if (m_choice != NULL) {
+
+ if (m_choice != NULL)
+ {
delete m_choice;
m_choice = NULL;
}
}
delete m_choice;
m_choice = NULL;
}
}
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
{
if (!m_choice && !m_text)
return GetSize();
{
if (!m_choice && !m_text)
return GetSize();
wxSize size = m_choice->GetBestSize();
if ( m_text != NULL )
wxSize size = m_choice->GetBestSize();
if ( m_text != NULL )
wxSize sizeText = m_text->GetBestSize();
if (sizeText.y > size.y)
size.y = sizeText.y;
wxSize sizeText = m_text->GetBestSize();
if (sizeText.y > size.y)
size.y = sizeText.y;
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
size.x += TEXTFOCUSBORDER ;
size.y += 2 * TEXTFOCUSBORDER ;
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
size.x += TEXTFOCUSBORDER ;
size.y += 2 * TEXTFOCUSBORDER ;
// clipping is too tight
size.y += 1 ;
}
// clipping is too tight
size.y += 1 ;
}
return size;
}
void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
{
return size;
}
void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
{
- wxControl::DoMoveWindow(x, y, width , height );
+ wxControl::DoMoveWindow( x, y, width , height );
else
{
wxCoord wText = width - m_choice->GetPopupWidth() - MARGIN;
else
{
wxCoord wText = width - m_choice->GetPopupWidth() - MARGIN;
- m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1 );
+ m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1);
+
// put it at an inset of 1 to have outer area shadows drawn as well
m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1);
}
}
// put it at an inset of 1 to have outer area shadows drawn as well
m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1);
}
}
// ----------------------------------------------------------------------------
// operations forwarded to the subcontrols
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// operations forwarded to the subcontrols
// ----------------------------------------------------------------------------
void wxComboBox::SetFocus()
{
void wxComboBox::SetFocus()
{
void wxComboBox::DelegateTextChanged( const wxString& value )
{
SetStringSelection( value );
}
void wxComboBox::DelegateTextChanged( const wxString& value )
{
SetStringSelection( value );
}
void wxComboBox::DelegateChoice( const wxString& value )
{
SetStringSelection( value );
}
void wxComboBox::DelegateChoice( const wxString& value )
{
SetStringSelection( value );
}
-
-bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
- const wxString& value,
- const wxPoint& pos,
- const wxSize& size,
- const wxArrayString& choices,
- long style,
- const wxValidator& validator,
- const wxString& name)
+bool wxComboBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ const wxArrayString& choices,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
{
wxCArrayString chs( choices );
{
wxCArrayString chs( choices );
chs.GetStrings(), style, validator, name );
}
chs.GetStrings(), style, validator, name );
}
-
-bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
- const wxString& value,
- const wxPoint& pos,
- const wxSize& size,
- int n, const wxString choices[],
- long style,
- const wxValidator& validator,
- const wxString& name)
+bool wxComboBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ int n,
+ const wxString choices[],
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
{
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
validator, name) )
{
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
validator, name) )
m_choice->DoAppend( choices[ i ] );
}
m_choice->DoAppend( choices[ i ] );
}
- SetBestSize(size); // Needed because it is a wxControlWithItems
+ // Needed because it is a wxControlWithItems
+ SetBestSize(size);
SetStringSelection(value);
return true;
SetStringSelection(value);
return true;
wxString result;
if ( m_text == NULL )
wxString result;
if ( m_text == NULL )
result = m_choice->GetString( m_choice->GetSelection() );
result = m_choice->GetString( m_choice->GetSelection() );
result = m_text->GetValue();
result = m_text->GetValue();
}
// Clipboard operations
}
// Clipboard operations
void wxComboBox::Copy()
{
if ( m_text != NULL )
void wxComboBox::Copy()
{
if ( m_text != NULL )
}
void wxComboBox::Cut()
{
if ( m_text != NULL )
}
void wxComboBox::Cut()
{
if ( m_text != NULL )
}
void wxComboBox::Paste()
{
if ( m_text != NULL )
}
void wxComboBox::Paste()
{
if ( m_text != NULL )
}
void wxComboBox::SetEditable(bool editable)
}
void wxComboBox::SetEditable(bool editable)
m_choice->SetSelection( n );
if ( m_text != NULL )
m_choice->SetSelection( n );
if ( m_text != NULL )
m_text->SetValue( GetString( n ) );
m_text->SetValue( GetString( n ) );
}
int wxComboBox::FindString(const wxString& s, bool bCase) const
}
int wxComboBox::FindString(const wxString& s, bool bCase) const
wxString wxComboBox::GetStringSelection() const
{
wxString wxComboBox::GetStringSelection() const
{
- int sel = GetSelection ();
+ int sel = GetSelection();
if (sel > -1)
return wxString(this->GetString (sel));
else
if (sel > -1)
return wxString(this->GetString (sel));
else
-wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
+wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
- /* For consistency with other platforms, clicking in the text area does not constitute a selection
+/*
+ For consistency with other platforms, clicking in the text area does not constitute a selection
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());
- ProcessCommand(event);*/
+ ProcessCommand(event);
+*/
+
///////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
///////////////////////////////////////////////////////////////////////////////
// Name: dnd.cpp
-// Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
+// Purpose: wxDropTarget, wxDropSource implementations
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
#endif
// ----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-void wxMacEnsureTrackingHandlersInstalled() ;
-
-typedef struct
{
wxWindow* m_currentTargetWindow ;
wxDropTarget* m_currentTarget ;
wxDropSource* m_currentSource ;
{
wxWindow* m_currentTargetWindow ;
wxDropTarget* m_currentTarget ;
wxDropSource* m_currentSource ;
-MacTrackingGlobals gTrackingGlobals ;
+MacTrackingGlobals gTrackingGlobals ;
+
+void wxMacEnsureTrackingHandlersInstalled() ;
//----------------------------------------------------------------------------
// wxDropTarget
//----------------------------------------------------------------------------
// wxDropTarget
wxCoord WXUNUSED(y),
wxDragResult def )
{
wxCoord WXUNUSED(y),
wxDragResult def )
{
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
}
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
{
if (!m_dataObject)
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
}
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
{
if (!m_dataObject)
return CurrentDragHasSupportedFormat() ;
}
return CurrentDragHasSupportedFormat() ;
}
return GetData() ? def : wxDragNone;
}
return GetData() ? def : wxDragNone;
}
-bool wxDropTarget::CurrentDragHasSupportedFormat()
+bool wxDropTarget::CurrentDragHasSupportedFormat()
{
bool supported = false ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
{
bool supported = false ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
for (size_t i = 0; !supported && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
for (size_t i = 0; !supported && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
- if ( m_dataObject->IsSupported( format ) )
+ if ( m_dataObject->IsSupported( format ) )
{
supported = true ;
break ;
}
}
{
supported = true ;
break ;
}
}
if ( !supported )
{
UInt16 items ;
OSErr result;
if ( !supported )
{
UInt16 items ;
OSErr result;
+ ItemReference theItem;
+ FlavorType theType ;
+ UInt16 flavors = 0 ;
+
CountDragItems((DragReference)m_currentDrag, &items);
CountDragItems((DragReference)m_currentDrag, &items);
- for (UInt16 index = 1; index <= items && supported == false ; ++index)
+ for (UInt16 index = 1; index <= items && !supported ; ++index)
- ItemReference theItem;
- FlavorType theType ;
- UInt16 flavors = 0 ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
}
bool wxDropTarget::GetData()
{
if (!m_dataObject)
}
bool wxDropTarget::GetData()
{
if (!m_dataObject)
if ( !CurrentDragHasSupportedFormat() )
if ( !CurrentDragHasSupportedFormat() )
- return FALSE ;
-
- bool transferred = false ;
+ return false ;
+
+ bool transferred = false ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
if ( gTrackingGlobals.m_currentSource != NULL )
{
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
if ( data )
{
size_t formatcount = data->GetFormatCount() ;
- wxDataFormat *array = new wxDataFormat[ formatcount ];
+ wxDataFormat *array = new wxDataFormat[formatcount];
data->GetAllFormats( array );
for (size_t i = 0; !transferred && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
data->GetAllFormats( array );
for (size_t i = 0; !transferred && i < formatcount ; i++)
{
wxDataFormat format = array[i] ;
- if ( m_dataObject->IsSupported( format ) )
+ if ( m_dataObject->IsSupported( format ) )
{
int size = data->GetDataSize( format );
transferred = true ;
{
int size = data->GetDataSize( format );
transferred = true ;
{
m_dataObject->SetData(format , 0 , 0 ) ;
}
{
m_dataObject->SetData(format , 0 , 0 ) ;
}
char *d = new char[size];
data->GetDataHere( format , (void*) d );
m_dataObject->SetData( format , size , d ) ;
char *d = new char[size];
data->GetDataHere( format , (void*) d );
m_dataObject->SetData( format , size , d ) ;
if ( !transferred )
{
UInt16 items ;
OSErr result;
if ( !transferred )
{
UInt16 items ;
OSErr result;
+ ItemReference theItem;
+ FlavorType theType ;
+ FlavorFlags theFlags;
+ UInt16 flavors ;
bool firstFileAdded = false ;
bool firstFileAdded = false ;
CountDragItems((DragReference)m_currentDrag, &items);
CountDragItems((DragReference)m_currentDrag, &items);
- for (UInt16 index = 1; index <= items; ++index)
+ for (UInt16 index = 1; index <= items; ++index)
- ItemReference theItem;
- FlavorType theType ;
- UInt16 flavors = 0 ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
bool hasPreferredFormat = false ;
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
bool hasPreferredFormat = false ;
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
wxDataFormat format(theType) ;
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
{
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
wxDataFormat format(theType) ;
- if ( (hasPreferredFormat && format==preferredFormat) || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
+ if ( (hasPreferredFormat && format == preferredFormat) || (!hasPreferredFormat && m_dataObject->IsSupportedFormat( format )))
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
{
Size dataSize ;
Ptr theData ;
{
Size dataSize ;
Ptr theData ;
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
if ( theType == kScrapFlavorTypeText )
{
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
if ( theType == kScrapFlavorTypeText )
{
dataSize++ ;
dataSize++ ;
}
dataSize++ ;
dataSize++ ;
}
theData = new char[dataSize];
theData = new char[dataSize];
- GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
- if( theType == kScrapFlavorTypeText )
+ GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
+ if ( theType == kScrapFlavorTypeText )
+ theData[dataSize] = 0 ;
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
}
#if wxUSE_UNICODE
else if ( theType == kScrapFlavorTypeUnicode )
{
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
}
#if wxUSE_UNICODE
else if ( theType == kScrapFlavorTypeUnicode )
{
- theData[dataSize]=0 ;
- theData[dataSize+1]=0 ;
+ theData[dataSize] = 0 ;
+ theData[dataSize + 1] = 0 ;
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData );
}
#endif
m_dataObject->SetData( wxDataFormat(wxDF_UNICODETEXT), dataSize , theData );
}
#endif
{
// reset file list
((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
{
// reset file list
((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
- firstFileAdded = true ;
+ firstFileAdded = true ;
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
}
else
{
m_dataObject->SetData( format, dataSize, theData );
}
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
}
else
{
m_dataObject->SetData( format, dataSize, theData );
}
}
//-------------------------------------------------------------------------
}
//-------------------------------------------------------------------------
wxDragResult wxDropSource::DoDragDrop(int flags)
{
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
wxDragResult wxDropSource::DoDragDrop(int flags)
{
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
if (!m_data)
return (wxDragResult) wxDragNone;
if (!m_data)
return (wxDragResult) wxDragNone;
if (m_data->GetFormatCount() == 0)
return (wxDragResult) wxDragNone;
if (m_data->GetFormatCount() == 0)
return (wxDragResult) wxDragNone;
OSErr result;
DragReference theDrag;
RgnHandle dragRegion;
OSErr result;
DragReference theDrag;
RgnHandle dragRegion;
- if ((result = NewDrag(&theDrag)))
- {
+ if ((result = NewDrag(&theDrag)) != noErr)
// add data to drag
size_t formatCount = m_data->GetFormatCount() ;
wxDataFormat *formats = new wxDataFormat[formatCount] ;
m_data->GetAllFormats( formats ) ;
ItemReference theItem = 1 ;
// add data to drag
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 )
{
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
for ( size_t i = 0 ; i < formatCount ; ++i )
{
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
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 ;
OSErr err = noErr;
CInfoPBRec cat;
}
else if (type == kDragFlavorTypeHFS )
{
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;
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
cat.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&cat);
cat.hFileInfo.ioNamePtr = theFlavor.fileSpec.name;
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
cat.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&cat);
{
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
{
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
- if (theFlavor.fileSpec.parID == fsRtParID) {
+ if (theFlavor.fileSpec.parID == fsRtParID)
+ {
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'disk';
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'disk';
- } else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0) {
+ }
+ else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0)
+ {
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'fold';
theFlavor.fileCreator = 'MACS';
theFlavor.fileType = 'fold';
theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
}
theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
}
- AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
- }
+
+ AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
+ }
- AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
+ AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
+
+ delete [] formats ;
+
dragRegion = NewRgn();
RgnHandle tempRgn = NewRgn() ;
dragRegion = NewRgn();
RgnHandle tempRgn = NewRgn() ;
#if !TARGET_CARBON // TODO
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
#else
#if !TARGET_CARBON // TODO
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
#else
- EventRecord rec ;
- ev = &rec ;
- wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
+ {
+ EventRecord rec ;
+ ev = &rec ;
+ wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
+ }
const short dragRegionOuterBoundary = 10 ;
const short dragRegionInnerBoundary = 9 ;
const short dragRegionOuterBoundary = 10 ;
const short dragRegionInnerBoundary = 9 ;
-
- SetRectRgn( dragRegion , ev->where.h - dragRegionOuterBoundary ,
+
+ SetRectRgn(
+ 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( tempRgn , ev->where.h - dragRegionInnerBoundary ,
+
+ SetRectRgn(
+ 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 ) ;
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
- DisposeRgn( tempRgn ) ;
-
+ DisposeRgn( tempRgn ) ;
+
// TODO:work with promises in order to return data only when drag
// was successfully completed
// TODO:work with promises in order to return data only when drag
// was successfully completed
gTrackingGlobals.m_currentSource = this ;
result = TrackDrag(theDrag, ev , dragRegion);
DisposeRgn(dragRegion);
DisposeDrag(theDrag);
gTrackingGlobals.m_currentSource = NULL ;
gTrackingGlobals.m_currentSource = this ;
result = TrackDrag(theDrag, ev , dragRegion);
DisposeRgn(dragRegion);
DisposeDrag(theDrag);
gTrackingGlobals.m_currentSource = NULL ;
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
wxDragResult dndresult = wxDragCopy ;
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
wxDragResult dndresult = wxDragCopy ;
- if ( flags != wxDrag_CopyOnly )
- {
+ if ( flags != wxDrag_CopyOnly )
// on mac the option key is always the indication for copy
dndresult = optionDown ? wxDragCopy : wxDragMove;
// on mac the option key is always the indication for copy
dndresult = optionDown ? wxDragCopy : wxDragMove;
return dndresult;
}
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
{
const wxCursor& cursor = GetCursor(effect);
return dndresult;
}
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
{
const wxCursor& cursor = GetCursor(effect);
+ bool result = cursor.Ok();
+
+ if ( result )
- return TRUE;
- }
- else
- {
- return FALSE;
- }
}
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...
// 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...
-pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag) ;
-pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
-DragReference theDrag) ;
+pascal OSErr wxMacWindowDragTrackingHandler(
+ DragTrackingMessage theMessage, WindowPtr theWindow,
+ void *handlerRefCon, DragReference theDrag) ;
+pascal OSErr wxMacWindowDragReceiveHandler(
+ WindowPtr theWindow, void *handlerRefCon,
+ DragReference theDrag) ;
void wxMacEnsureTrackingHandlersInstalled()
{
void wxMacEnsureTrackingHandlersInstalled()
{
- if( !gTrackingGlobalsInstalled )
+ if ( !gTrackingGlobalsInstalled )
{
OSErr result;
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
wxASSERT( result == noErr ) ;
{
OSErr result;
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
wxASSERT( result == noErr ) ;
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
wxASSERT( result == noErr ) ;
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
wxASSERT( result == noErr ) ;
-pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag)
-{
+pascal OSErr wxMacWindowDragTrackingHandler(
+ DragTrackingMessage theMessage, WindowPtr theWindow,
+ void *handlerRefCon, DragReference theDrag)
+{
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
Point mouse, localMouse;
DragAttributes attributes;
GetDragAttributes(theDrag, &attributes);
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
Point mouse, localMouse;
DragAttributes attributes;
GetDragAttributes(theDrag, &attributes);
- wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
+ wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
{
case kDragTrackingEnterHandler:
{
case kDragTrackingEnterHandler:
case kDragTrackingLeaveHandler:
break;
case kDragTrackingLeaveHandler:
break;
case kDragTrackingEnterWindow:
trackingGlobals->m_currentTargetWindow = NULL ;
trackingGlobals->m_currentTarget = NULL ;
break;
case kDragTrackingEnterWindow:
trackingGlobals->m_currentTargetWindow = NULL ;
trackingGlobals->m_currentTarget = NULL ;
break;
case kDragTrackingInWindow:
if (toplevel == NULL)
break;
case kDragTrackingInWindow:
if (toplevel == NULL)
break;
localMouse = mouse;
GlobalToLocal(&localMouse);
localMouse = mouse;
GlobalToLocal(&localMouse);
{
wxWindow *win = NULL ;
ControlPartCode controlPart ;
{
wxWindow *win = NULL ;
ControlPartCode controlPart ;
- ControlRef control = wxMacFindControlUnderMouse( toplevel , localMouse ,
+ ControlRef control = wxMacFindControlUnderMouse(
+ toplevel , localMouse ,
theWindow , &controlPart ) ;
if ( control )
win = wxFindControlFromMacControl( control ) ;
else
win = toplevel ;
theWindow , &controlPart ) ;
if ( control )
win = wxFindControlFromMacControl( control ) ;
else
win = toplevel ;
int localx , localy ;
localx = localMouse.h ;
localy = localMouse.v ;
int localx , localy ;
localx = localMouse.h ;
localy = localMouse.v ;
// this window is left
if ( trackingGlobals->m_currentTarget )
{
// this window is left
if ( trackingGlobals->m_currentTarget )
{
- HideDragHilite(theDrag);
+ HideDragHilite( theDrag );
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
trackingGlobals->m_currentTarget = NULL;
trackingGlobals->m_currentTargetWindow = NULL ;
}
}
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
trackingGlobals->m_currentTarget = NULL;
trackingGlobals->m_currentTargetWindow = NULL ;
}
}
if ( win )
{
// this window is entered
trackingGlobals->m_currentTargetWindow = win ;
trackingGlobals->m_currentTarget = win->GetDropTarget() ;
{
if ( win )
{
// this window is entered
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 ) ;
+ if ( trackingGlobals->m_currentTarget )
+ {
+ trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
+ result = trackingGlobals->m_currentTarget->OnEnter( localx , localy , result ) ;
if ( result != wxDragNone )
{
int x , y ;
if ( result != wxDragNone )
{
int x , y ;
x = y = 0 ;
win->MacWindowToRootWindow( &x , &y ) ;
RgnHandle hiliteRgn = NewRgn() ;
x = y = 0 ;
win->MacWindowToRootWindow( &x , &y ) ;
RgnHandle hiliteRgn = NewRgn() ;
- Rect r = { y , x , y+win->GetSize().y , x+win->GetSize().x } ;
+ Rect r = { y , x , y + win->GetSize().y , x + win->GetSize().x } ;
RectRgn( hiliteRgn , &r ) ;
ShowDragHilite(theDrag, hiliteRgn, true);
DisposeRgn( hiliteRgn ) ;
RectRgn( hiliteRgn , &r ) ;
ShowDragHilite(theDrag, hiliteRgn, true);
DisposeRgn( hiliteRgn ) ;
- if( trackingGlobals->m_currentTarget )
+ if ( trackingGlobals->m_currentTarget )
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
- trackingGlobals->m_currentTarget->OnDragOver(
- localx , localy , result ) ;
+ trackingGlobals->m_currentTarget->OnDragOver( localx , localy , result ) ;
}
}
// set cursor for OnEnter and OnDragOver
}
}
// set cursor for OnEnter and OnDragOver
- if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE )
+ if ( !trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) )
- if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE )
+ if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
cursor.MacInstall() ;
}
break ;
cursor.MacInstall() ;
}
break ;
case wxDragMove :
{
wxCursor cursor(wxCURSOR_ARROW) ;
cursor.MacInstall() ;
}
break ;
case wxDragMove :
{
wxCursor cursor(wxCURSOR_ARROW) ;
cursor.MacInstall() ;
}
break ;
case wxDragNone :
{
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
case wxDragNone :
{
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
case wxDragError:
case wxDragLink:
case wxDragCancel:
case wxDragError:
case wxDragLink:
case wxDragCancel:
// put these here to make gcc happy
;
}
// put these here to make gcc happy
;
}
case kDragTrackingLeaveWindow:
case kDragTrackingLeaveWindow:
- if (trackingGlobals->m_currentTarget)
+ if (trackingGlobals->m_currentTarget)
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
{
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
trackingGlobals->m_currentTarget->OnLeave() ;
}
trackingGlobals->m_currentTargetWindow = NULL ;
break;
}
trackingGlobals->m_currentTargetWindow = NULL ;
break;
-pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow,
- void *handlerRefCon,
- DragReference theDrag)
-{
- MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
+pascal OSErr wxMacWindowDragReceiveHandler(
+ WindowPtr theWindow,
+ void *handlerRefCon,
+ DragReference theDrag)
+{
+ MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
if ( trackingGlobals->m_currentTarget )
{
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);
localMouse = mouse;
GlobalToLocal(&localMouse);
localx = localMouse.h ;
localy = localMouse.v ;
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
GetDragMouse(theDrag, &mouse, 0L);
localMouse = mouse;
GlobalToLocal(&localMouse);
localx = localMouse.h ;
localy = localMouse.v ;
- //TODO : should we use client coordinates
+
+ // TODO : should we use client coordinates?
if ( trackingGlobals->m_currentTargetWindow )
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) )
if ( trackingGlobals->m_currentTargetWindow )
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
if ( trackingGlobals->m_currentTarget->OnDrop( localx , localy ) )
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
}
}
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
}
}