cleanup - reformat
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36670 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
b10ca83467
commit
6eae1f7d48
@ -1,7 +1,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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$
|
||||
@ -20,15 +20,15 @@
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
|
||||
|
||||
// composite combobox implementation by Dan "Bud" Keith bud@otsys.com
|
||||
|
||||
|
||||
static int nextPopUpMenuId = 1000 ;
|
||||
|
||||
MenuHandle NewUniqueMenu()
|
||||
{
|
||||
MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
|
||||
nextPopUpMenuId++ ;
|
||||
return handle ;
|
||||
MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
|
||||
nextPopUpMenuId++ ;
|
||||
|
||||
return handle ;
|
||||
}
|
||||
|
||||
|
||||
@ -93,22 +93,20 @@ protected:
|
||||
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();
|
||||
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
|
||||
while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
|
||||
parent = parent->GetParent() ;
|
||||
}
|
||||
|
||||
if ( parent && parent->GetDefaultItem() )
|
||||
{
|
||||
wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
|
||||
wxButton);
|
||||
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton);
|
||||
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);
|
||||
}
|
||||
@ -152,20 +150,21 @@ private:
|
||||
};
|
||||
|
||||
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:
|
||||
wxComboBoxChoice(wxComboBox *cb, int style)
|
||||
wxComboBoxChoice( wxComboBox *cb, int style )
|
||||
: wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
|
||||
{
|
||||
m_cb = cb;
|
||||
}
|
||||
|
||||
int GetPopupWidth() const
|
||||
{
|
||||
switch ( GetWindowVariant() )
|
||||
@ -173,6 +172,7 @@ public:
|
||||
case wxWINDOW_VARIANT_NORMAL :
|
||||
case wxWINDOW_VARIANT_LARGE :
|
||||
return 24 ;
|
||||
|
||||
default :
|
||||
return 21 ;
|
||||
}
|
||||
@ -197,11 +197,13 @@ protected:
|
||||
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() ;
|
||||
|
||||
return sz ;
|
||||
}
|
||||
|
||||
@ -223,17 +225,19 @@ wxComboBox::~wxComboBox()
|
||||
// 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) {
|
||||
if (m_text != NULL)
|
||||
{
|
||||
delete m_text;
|
||||
m_text = NULL;
|
||||
}
|
||||
if (m_choice != NULL) {
|
||||
|
||||
if (m_choice != NULL)
|
||||
{
|
||||
delete m_choice;
|
||||
m_choice = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// geometry
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -242,6 +246,7 @@ wxSize wxComboBox::DoGetBestSize() const
|
||||
{
|
||||
if (!m_choice && !m_text)
|
||||
return GetSize();
|
||||
|
||||
wxSize size = m_choice->GetBestSize();
|
||||
|
||||
if ( m_text != NULL )
|
||||
@ -249,6 +254,7 @@ wxSize wxComboBox::DoGetBestSize() const
|
||||
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 ;
|
||||
@ -258,12 +264,13 @@ wxSize wxComboBox::DoGetBestSize() const
|
||||
// clipping is too tight
|
||||
size.y += 1 ;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
if ( m_text == NULL )
|
||||
{
|
||||
@ -274,14 +281,13 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// operations forwarded to the subcontrols
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -307,32 +313,29 @@ bool wxComboBox::Show(bool show)
|
||||
|
||||
void wxComboBox::SetFocus()
|
||||
{
|
||||
if ( m_text != NULL) {
|
||||
if ( m_text != NULL)
|
||||
m_text->SetFocus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxComboBox::DelegateTextChanged( 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 );
|
||||
|
||||
@ -340,15 +343,16 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
||||
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) )
|
||||
@ -379,7 +383,8 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
||||
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;
|
||||
@ -390,13 +395,9 @@ wxString wxComboBox::GetValue() const
|
||||
wxString result;
|
||||
|
||||
if ( m_text == NULL )
|
||||
{
|
||||
result = m_choice->GetString( m_choice->GetSelection() );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = m_text->GetValue();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -415,28 +416,23 @@ void wxComboBox::SetValue(const wxString& value)
|
||||
}
|
||||
|
||||
// Clipboard operations
|
||||
|
||||
void wxComboBox::Copy()
|
||||
{
|
||||
if ( m_text != NULL )
|
||||
{
|
||||
m_text->Copy();
|
||||
}
|
||||
}
|
||||
|
||||
void wxComboBox::Cut()
|
||||
{
|
||||
if ( m_text != NULL )
|
||||
{
|
||||
m_text->Cut();
|
||||
}
|
||||
}
|
||||
|
||||
void wxComboBox::Paste()
|
||||
{
|
||||
if ( m_text != NULL )
|
||||
{
|
||||
m_text->Paste();
|
||||
}
|
||||
}
|
||||
|
||||
void wxComboBox::SetEditable(bool editable)
|
||||
@ -563,9 +559,7 @@ void wxComboBox::SetSelection(int n)
|
||||
m_choice->SetSelection( n );
|
||||
|
||||
if ( m_text != NULL )
|
||||
{
|
||||
m_text->SetValue( GetString( n ) );
|
||||
}
|
||||
}
|
||||
|
||||
int wxComboBox::FindString(const wxString& s, bool bCase) const
|
||||
@ -580,7 +574,7 @@ wxString wxComboBox::GetString(int n) const
|
||||
|
||||
wxString wxComboBox::GetStringSelection() const
|
||||
{
|
||||
int sel = GetSelection ();
|
||||
int sel = GetSelection();
|
||||
if (sel > -1)
|
||||
return wxString(this->GetString (sel));
|
||||
else
|
||||
@ -655,14 +649,17 @@ bool wxComboBox::CanRedo() const
|
||||
return false;
|
||||
}
|
||||
|
||||
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());
|
||||
ProcessCommand(event);*/
|
||||
ProcessCommand(event);
|
||||
*/
|
||||
|
||||
return noErr ;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: dnd.cpp
|
||||
// Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
|
||||
// Purpose: wxDropTarget, wxDropSource implementations
|
||||
// Author: Stefan Csomor
|
||||
// Modified by:
|
||||
// Created: 1998-01-01
|
||||
@ -25,19 +25,20 @@
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global
|
||||
// globals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxMacEnsureTrackingHandlersInstalled() ;
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
wxWindow* m_currentTargetWindow ;
|
||||
wxDropTarget* m_currentTarget ;
|
||||
wxDropSource* m_currentSource ;
|
||||
} MacTrackingGlobals ;
|
||||
}
|
||||
MacTrackingGlobals ;
|
||||
|
||||
MacTrackingGlobals gTrackingGlobals ;
|
||||
MacTrackingGlobals gTrackingGlobals ;
|
||||
|
||||
void wxMacEnsureTrackingHandlersInstalled() ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxDropTarget
|
||||
@ -53,14 +54,13 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
|
||||
wxCoord WXUNUSED(y),
|
||||
wxDragResult def )
|
||||
{
|
||||
|
||||
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
|
||||
}
|
||||
|
||||
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
|
||||
{
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
return false;
|
||||
|
||||
return CurrentDragHasSupportedFormat() ;
|
||||
}
|
||||
@ -77,13 +77,13 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
||||
return GetData() ? def : wxDragNone;
|
||||
}
|
||||
|
||||
bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||
bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||
{
|
||||
bool supported = false ;
|
||||
if ( gTrackingGlobals.m_currentSource != NULL )
|
||||
{
|
||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
||||
|
||||
|
||||
if ( data )
|
||||
{
|
||||
size_t formatcount = data->GetFormatCount() ;
|
||||
@ -92,27 +92,32 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
delete[] array ;
|
||||
|
||||
delete [] array ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !supported )
|
||||
{
|
||||
UInt16 items ;
|
||||
OSErr result;
|
||||
ItemReference theItem;
|
||||
FlavorType theType ;
|
||||
UInt16 flavors = 0 ;
|
||||
|
||||
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 ;
|
||||
flavors = 0 ;
|
||||
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);
|
||||
@ -124,36 +129,37 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||
}
|
||||
}
|
||||
}
|
||||
return supported ;
|
||||
|
||||
return supported ;
|
||||
}
|
||||
|
||||
bool wxDropTarget::GetData()
|
||||
{
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
return false;
|
||||
|
||||
if ( !CurrentDragHasSupportedFormat() )
|
||||
return FALSE ;
|
||||
|
||||
bool transferred = false ;
|
||||
return false ;
|
||||
|
||||
bool transferred = false ;
|
||||
if ( gTrackingGlobals.m_currentSource != NULL )
|
||||
{
|
||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
||||
|
||||
|
||||
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] ;
|
||||
if ( m_dataObject->IsSupported( format ) )
|
||||
if ( m_dataObject->IsSupported( format ) )
|
||||
{
|
||||
int size = data->GetDataSize( format );
|
||||
transferred = true ;
|
||||
|
||||
if (size == 0)
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
m_dataObject->SetData(format , 0 , 0 ) ;
|
||||
}
|
||||
@ -162,29 +168,34 @@ bool wxDropTarget::GetData()
|
||||
char *d = new char[size];
|
||||
data->GetDataHere( format , (void*) d );
|
||||
m_dataObject->SetData( format , size , d ) ;
|
||||
delete[] d ;
|
||||
delete [] d ;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] array ;
|
||||
|
||||
delete [] array ;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !transferred )
|
||||
{
|
||||
UInt16 items ;
|
||||
OSErr result;
|
||||
ItemReference theItem;
|
||||
FlavorType theType ;
|
||||
FlavorFlags theFlags;
|
||||
UInt16 flavors ;
|
||||
bool firstFileAdded = false ;
|
||||
|
||||
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 ;
|
||||
flavors = 0 ;
|
||||
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);
|
||||
@ -195,19 +206,19 @@ bool wxDropTarget::GetData()
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 )))
|
||||
{
|
||||
FlavorFlags theFlags;
|
||||
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
|
||||
if (result == noErr)
|
||||
if (result == noErr)
|
||||
{
|
||||
Size dataSize ;
|
||||
Ptr theData ;
|
||||
|
||||
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
|
||||
if ( theType == kScrapFlavorTypeText )
|
||||
{
|
||||
@ -222,18 +233,19 @@ bool wxDropTarget::GetData()
|
||||
dataSize++ ;
|
||||
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 ;
|
||||
theData[dataSize] = 0 ;
|
||||
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
|
||||
@ -245,22 +257,25 @@ bool wxDropTarget::GetData()
|
||||
{
|
||||
// reset file list
|
||||
((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
|
||||
firstFileAdded = true ;
|
||||
firstFileAdded = true ;
|
||||
}
|
||||
|
||||
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dataObject->SetData( format, dataSize, theData );
|
||||
}
|
||||
delete[] theData;
|
||||
|
||||
delete [] theData;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -296,29 +311,27 @@ wxDropSource::~wxDropSource()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||
{
|
||||
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
||||
|
||||
|
||||
if (!m_data)
|
||||
return (wxDragResult) wxDragNone;
|
||||
|
||||
if (m_data->GetFormatCount() == 0)
|
||||
return (wxDragResult) wxDragNone;
|
||||
|
||||
|
||||
OSErr result;
|
||||
DragReference theDrag;
|
||||
RgnHandle dragRegion;
|
||||
if ((result = NewDrag(&theDrag)))
|
||||
{
|
||||
if ((result = NewDrag(&theDrag)) != noErr)
|
||||
return wxDragNone ;
|
||||
}
|
||||
|
||||
// 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] ) ;
|
||||
@ -336,104 +349,115 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||
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;
|
||||
|
||||
|
||||
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);
|
||||
if (err == noErr )
|
||||
if (err == noErr)
|
||||
{
|
||||
theFlavor.fdFlags = cat.hFileInfo.ioFlFndrInfo.fdFlags;
|
||||
if (theFlavor.fileSpec.parID == fsRtParID) {
|
||||
if (theFlavor.fileSpec.parID == fsRtParID)
|
||||
{
|
||||
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';
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
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() ;
|
||||
|
||||
|
||||
EventRecord* ev = NULL ;
|
||||
|
||||
#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 ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
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.h + dragRegionOuterBoundary ,
|
||||
ev->where.h + dragRegionOuterBoundary ,
|
||||
ev->where.v + dragRegionOuterBoundary ) ;
|
||||
|
||||
SetRectRgn( tempRgn , ev->where.h - dragRegionInnerBoundary ,
|
||||
|
||||
SetRectRgn(
|
||||
tempRgn , ev->where.h - dragRegionInnerBoundary ,
|
||||
ev->where.v - dragRegionInnerBoundary ,
|
||||
ev->where.h + dragRegionInnerBoundary ,
|
||||
ev->where.h + dragRegionInnerBoundary ,
|
||||
ev->where.v + dragRegionInnerBoundary ) ;
|
||||
|
||||
|
||||
DiffRgn( dragRegion , tempRgn , dragRegion ) ;
|
||||
DisposeRgn( tempRgn ) ;
|
||||
|
||||
DisposeRgn( tempRgn ) ;
|
||||
|
||||
// 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 ;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return dndresult;
|
||||
}
|
||||
|
||||
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
|
||||
{
|
||||
const wxCursor& cursor = GetCursor(effect);
|
||||
if ( cursor.Ok() )
|
||||
{
|
||||
bool result = cursor.Ok();
|
||||
|
||||
if ( result )
|
||||
cursor.MacInstall() ;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool gTrackingGlobalsInstalled = false ;
|
||||
@ -441,19 +465,22 @@ 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...
|
||||
|
||||
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()
|
||||
{
|
||||
if( !gTrackingGlobalsInstalled )
|
||||
if ( !gTrackingGlobalsInstalled )
|
||||
{
|
||||
OSErr result;
|
||||
|
||||
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
|
||||
wxASSERT( result == noErr ) ;
|
||||
|
||||
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
|
||||
wxASSERT( result == noErr ) ;
|
||||
|
||||
@ -461,28 +488,30 @@ void wxMacEnsureTrackingHandlersInstalled()
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
|
||||
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
|
||||
|
||||
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
||||
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
||||
|
||||
switch(theMessage)
|
||||
switch (theMessage)
|
||||
{
|
||||
case kDragTrackingEnterHandler:
|
||||
break;
|
||||
case kDragTrackingLeaveHandler:
|
||||
break;
|
||||
|
||||
case kDragTrackingEnterWindow:
|
||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||
trackingGlobals->m_currentTarget = NULL ;
|
||||
break;
|
||||
|
||||
case kDragTrackingInWindow:
|
||||
if (toplevel == NULL)
|
||||
break;
|
||||
@ -491,18 +520,17 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
localMouse = mouse;
|
||||
GlobalToLocal(&localMouse);
|
||||
|
||||
|
||||
|
||||
{
|
||||
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 ;
|
||||
|
||||
|
||||
int localx , localy ;
|
||||
localx = localMouse.h ;
|
||||
localy = localMouse.v ;
|
||||
@ -516,35 +544,34 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
// 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 ;
|
||||
}
|
||||
}
|
||||
|
||||
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 ;
|
||||
|
||||
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 ) ;
|
||||
@ -554,20 +581,19 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
}
|
||||
else
|
||||
{
|
||||
if( trackingGlobals->m_currentTarget )
|
||||
if ( trackingGlobals->m_currentTarget )
|
||||
{
|
||||
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
|
||||
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 ) )
|
||||
{
|
||||
switch( result )
|
||||
switch ( result )
|
||||
{
|
||||
case wxDragCopy :
|
||||
{
|
||||
@ -575,12 +601,14 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
cursor.MacInstall() ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case wxDragMove :
|
||||
{
|
||||
wxCursor cursor(wxCURSOR_ARROW) ;
|
||||
cursor.MacInstall() ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case wxDragNone :
|
||||
{
|
||||
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
|
||||
@ -591,16 +619,17 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
case wxDragError:
|
||||
case wxDragLink:
|
||||
case wxDragCancel:
|
||||
default:
|
||||
// put these here to make gcc happy
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case kDragTrackingLeaveWindow:
|
||||
if (trackingGlobals->m_currentTarget)
|
||||
if (trackingGlobals->m_currentTarget)
|
||||
{
|
||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||
trackingGlobals->m_currentTarget->OnLeave() ;
|
||||
@ -609,27 +638,33 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
||||
}
|
||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return(noErr);
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
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 ;
|
||||
//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 ) )
|
||||
@ -639,6 +674,8 @@ pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow,
|
||||
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
|
||||
}
|
||||
}
|
||||
return(noErr);
|
||||
|
||||
return noErr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user