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
|
// Name: src/mac/carbon/combobox.cpp
|
||||||
// Purpose: wxComboBox class
|
// Purpose: wxComboBox class
|
||||||
// Author: Stefan Csomor
|
// Author: Stefan Csomor, Dan "Bud" Keith (composite combobox)
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 1998-01-01
|
// Created: 1998-01-01
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
@ -20,15 +20,15 @@
|
|||||||
|
|
||||||
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" ) ;
|
MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
|
||||||
nextPopUpMenuId++ ;
|
nextPopUpMenuId++ ;
|
||||||
return handle ;
|
|
||||||
|
return handle ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,22 +93,20 @@ protected:
|
|||||||
event.SetInt( m_cb->GetSelection() );
|
event.SetInt( m_cb->GetSelection() );
|
||||||
event.SetEventObject( m_cb );
|
event.SetEventObject( m_cb );
|
||||||
|
|
||||||
// This will invoke the dialog default action, such
|
// This will invoke the dialog default action,
|
||||||
// as the clicking the default button.
|
// such as the clicking the default button.
|
||||||
|
|
||||||
if (!m_cb->GetEventHandler()->ProcessEvent( event ))
|
if (!m_cb->GetEventHandler()->ProcessEvent( event ))
|
||||||
{
|
{
|
||||||
wxWindow *parent = GetParent();
|
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 *def = wxDynamicCast(parent->GetDefaultItem(), wxButton);
|
||||||
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);
|
event.SetEventObject(def);
|
||||||
def->Command(event);
|
def->Command(event);
|
||||||
}
|
}
|
||||||
@ -152,20 +150,21 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
|
BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
|
||||||
EVT_KEY_DOWN( wxComboBoxText::OnKeyDown)
|
EVT_KEY_DOWN(wxComboBoxText::OnKeyDown)
|
||||||
EVT_CHAR( wxComboBoxText::OnChar)
|
EVT_CHAR(wxComboBoxText::OnChar)
|
||||||
EVT_KEY_UP( wxComboBoxText::OnKeyUp)
|
EVT_KEY_UP(wxComboBoxText::OnKeyUp)
|
||||||
EVT_TEXT( -1, wxComboBoxText::OnText)
|
EVT_TEXT(-1, wxComboBoxText::OnText)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
class wxComboBoxChoice : public wxChoice
|
class wxComboBoxChoice : public wxChoice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxComboBoxChoice(wxComboBox *cb, int style)
|
wxComboBoxChoice( wxComboBox *cb, int style )
|
||||||
: wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
|
: wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
|
||||||
{
|
{
|
||||||
m_cb = cb;
|
m_cb = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetPopupWidth() const
|
int GetPopupWidth() const
|
||||||
{
|
{
|
||||||
switch ( GetWindowVariant() )
|
switch ( GetWindowVariant() )
|
||||||
@ -173,6 +172,7 @@ public:
|
|||||||
case wxWINDOW_VARIANT_NORMAL :
|
case wxWINDOW_VARIANT_NORMAL :
|
||||||
case wxWINDOW_VARIANT_LARGE :
|
case wxWINDOW_VARIANT_LARGE :
|
||||||
return 24 ;
|
return 24 ;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
return 21 ;
|
return 21 ;
|
||||||
}
|
}
|
||||||
@ -197,11 +197,13 @@ protected:
|
|||||||
TextEvent.SetEventObject( m_cb );
|
TextEvent.SetEventObject( m_cb );
|
||||||
m_cb->ProcessCommand( TextEvent );
|
m_cb->ProcessCommand( TextEvent );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual wxSize DoGetBestSize() const
|
virtual wxSize DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize sz = wxChoice::DoGetBestSize() ;
|
wxSize sz = wxChoice::DoGetBestSize() ;
|
||||||
if (! m_cb->HasFlag(wxCB_READONLY) )
|
if (! m_cb->HasFlag(wxCB_READONLY) )
|
||||||
sz.x = GetPopupWidth() ;
|
sz.x = GetPopupWidth() ;
|
||||||
|
|
||||||
return sz ;
|
return sz ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,17 +225,19 @@ wxComboBox::~wxComboBox()
|
|||||||
// delete the controls now, don't leave them alive even though they would
|
// 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
|
// still be eventually deleted by our parent - but it will be too late, the
|
||||||
// user code expects them to be gone now
|
// user code expects them to be gone now
|
||||||
if (m_text != NULL) {
|
if (m_text != NULL)
|
||||||
|
{
|
||||||
delete m_text;
|
delete m_text;
|
||||||
m_text = NULL;
|
m_text = NULL;
|
||||||
}
|
}
|
||||||
if (m_choice != NULL) {
|
|
||||||
|
if (m_choice != NULL)
|
||||||
|
{
|
||||||
delete m_choice;
|
delete m_choice;
|
||||||
m_choice = NULL;
|
m_choice = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// geometry
|
// geometry
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -242,6 +246,7 @@ wxSize wxComboBox::DoGetBestSize() const
|
|||||||
{
|
{
|
||||||
if (!m_choice && !m_text)
|
if (!m_choice && !m_text)
|
||||||
return GetSize();
|
return GetSize();
|
||||||
|
|
||||||
wxSize size = m_choice->GetBestSize();
|
wxSize size = m_choice->GetBestSize();
|
||||||
|
|
||||||
if ( m_text != NULL )
|
if ( m_text != NULL )
|
||||||
@ -249,6 +254,7 @@ wxSize wxComboBox::DoGetBestSize() const
|
|||||||
wxSize sizeText = m_text->GetBestSize();
|
wxSize sizeText = m_text->GetBestSize();
|
||||||
if (sizeText.y > size.y)
|
if (sizeText.y > size.y)
|
||||||
size.y = sizeText.y;
|
size.y = sizeText.y;
|
||||||
|
|
||||||
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
|
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
|
||||||
size.x += TEXTFOCUSBORDER ;
|
size.x += TEXTFOCUSBORDER ;
|
||||||
size.y += 2 * TEXTFOCUSBORDER ;
|
size.y += 2 * TEXTFOCUSBORDER ;
|
||||||
@ -258,12 +264,13 @@ wxSize wxComboBox::DoGetBestSize() const
|
|||||||
// clipping is too tight
|
// clipping is too tight
|
||||||
size.y += 1 ;
|
size.y += 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
|
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 )
|
if ( m_text == NULL )
|
||||||
{
|
{
|
||||||
@ -274,14 +281,13 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxCoord wText = width - m_choice->GetPopupWidth() - MARGIN;
|
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
|
// 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);
|
m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// operations forwarded to the subcontrols
|
// operations forwarded to the subcontrols
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -307,32 +313,29 @@ bool wxComboBox::Show(bool show)
|
|||||||
|
|
||||||
void wxComboBox::SetFocus()
|
void wxComboBox::SetFocus()
|
||||||
{
|
{
|
||||||
if ( m_text != NULL) {
|
if ( m_text != NULL)
|
||||||
m_text->SetFocus();
|
m_text->SetFocus();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxComboBox::DelegateTextChanged( const wxString& value )
|
void wxComboBox::DelegateTextChanged( const wxString& value )
|
||||||
{
|
{
|
||||||
SetStringSelection( value );
|
SetStringSelection( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxComboBox::DelegateChoice( const wxString& value )
|
void wxComboBox::DelegateChoice( const wxString& value )
|
||||||
{
|
{
|
||||||
SetStringSelection( value );
|
SetStringSelection( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxComboBox::Create(wxWindow *parent,
|
||||||
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString& value,
|
const wxString& value,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
const wxArrayString& choices,
|
const wxArrayString& choices,
|
||||||
long style,
|
long style,
|
||||||
const wxValidator& validator,
|
const wxValidator& validator,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
wxCArrayString chs( choices );
|
wxCArrayString chs( choices );
|
||||||
|
|
||||||
@ -340,15 +343,16 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
|||||||
chs.GetStrings(), style, validator, name );
|
chs.GetStrings(), style, validator, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxComboBox::Create(wxWindow *parent,
|
||||||
bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString& value,
|
const wxString& value,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
int n, const wxString choices[],
|
int n,
|
||||||
long style,
|
const wxString choices[],
|
||||||
const wxValidator& validator,
|
long style,
|
||||||
const wxString& name)
|
const wxValidator& validator,
|
||||||
|
const wxString& name)
|
||||||
{
|
{
|
||||||
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
|
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
|
||||||
validator, name) )
|
validator, name) )
|
||||||
@ -379,7 +383,8 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
|
|||||||
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);
|
SetStringSelection(value);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -390,13 +395,9 @@ wxString wxComboBox::GetValue() const
|
|||||||
wxString result;
|
wxString result;
|
||||||
|
|
||||||
if ( m_text == NULL )
|
if ( m_text == NULL )
|
||||||
{
|
|
||||||
result = m_choice->GetString( m_choice->GetSelection() );
|
result = m_choice->GetString( m_choice->GetSelection() );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
result = m_text->GetValue();
|
result = m_text->GetValue();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -415,28 +416,23 @@ void wxComboBox::SetValue(const wxString& value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clipboard operations
|
// Clipboard operations
|
||||||
|
|
||||||
void wxComboBox::Copy()
|
void wxComboBox::Copy()
|
||||||
{
|
{
|
||||||
if ( m_text != NULL )
|
if ( m_text != NULL )
|
||||||
{
|
|
||||||
m_text->Copy();
|
m_text->Copy();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxComboBox::Cut()
|
void wxComboBox::Cut()
|
||||||
{
|
{
|
||||||
if ( m_text != NULL )
|
if ( m_text != NULL )
|
||||||
{
|
|
||||||
m_text->Cut();
|
m_text->Cut();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxComboBox::Paste()
|
void wxComboBox::Paste()
|
||||||
{
|
{
|
||||||
if ( m_text != NULL )
|
if ( m_text != NULL )
|
||||||
{
|
|
||||||
m_text->Paste();
|
m_text->Paste();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxComboBox::SetEditable(bool editable)
|
void wxComboBox::SetEditable(bool editable)
|
||||||
@ -563,9 +559,7 @@ void wxComboBox::SetSelection(int n)
|
|||||||
m_choice->SetSelection( n );
|
m_choice->SetSelection( n );
|
||||||
|
|
||||||
if ( m_text != NULL )
|
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
|
||||||
@ -580,7 +574,7 @@ wxString wxComboBox::GetString(int n) const
|
|||||||
|
|
||||||
wxString wxComboBox::GetStringSelection() const
|
wxString wxComboBox::GetStringSelection() const
|
||||||
{
|
{
|
||||||
int sel = GetSelection ();
|
int sel = GetSelection();
|
||||||
if (sel > -1)
|
if (sel > -1)
|
||||||
return wxString(this->GetString (sel));
|
return wxString(this->GetString (sel));
|
||||||
else
|
else
|
||||||
@ -655,14 +649,17 @@ bool wxComboBox::CanRedo() const
|
|||||||
return false;
|
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 );
|
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
|
||||||
event.SetInt(GetSelection());
|
event.SetInt(GetSelection());
|
||||||
event.SetEventObject(this);
|
event.SetEventObject(this);
|
||||||
event.SetString(GetStringSelection());
|
event.SetString(GetStringSelection());
|
||||||
ProcessCommand(event);*/
|
ProcessCommand(event);
|
||||||
|
*/
|
||||||
|
|
||||||
return noErr ;
|
return noErr ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: dnd.cpp
|
// Name: dnd.cpp
|
||||||
// Purpose: wxDropTarget, wxDropSource, wxDataObject implementation
|
// Purpose: wxDropTarget, wxDropSource implementations
|
||||||
// Author: Stefan Csomor
|
// Author: Stefan Csomor
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 1998-01-01
|
// Created: 1998-01-01
|
||||||
@ -25,19 +25,20 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// global
|
// globals
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxMacEnsureTrackingHandlersInstalled() ;
|
typedef struct
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
{
|
||||||
wxWindow* m_currentTargetWindow ;
|
wxWindow* m_currentTargetWindow ;
|
||||||
wxDropTarget* m_currentTarget ;
|
wxDropTarget* m_currentTarget ;
|
||||||
wxDropSource* m_currentSource ;
|
wxDropSource* m_currentSource ;
|
||||||
} MacTrackingGlobals ;
|
}
|
||||||
|
MacTrackingGlobals ;
|
||||||
|
|
||||||
MacTrackingGlobals gTrackingGlobals ;
|
MacTrackingGlobals gTrackingGlobals ;
|
||||||
|
|
||||||
|
void wxMacEnsureTrackingHandlersInstalled() ;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// wxDropTarget
|
// wxDropTarget
|
||||||
@ -53,14 +54,13 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x),
|
|||||||
wxCoord WXUNUSED(y),
|
wxCoord WXUNUSED(y),
|
||||||
wxDragResult def )
|
wxDragResult def )
|
||||||
{
|
{
|
||||||
|
|
||||||
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
|
return CurrentDragHasSupportedFormat() ? def : wxDragNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
|
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
|
||||||
{
|
{
|
||||||
if (!m_dataObject)
|
if (!m_dataObject)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
return CurrentDragHasSupportedFormat() ;
|
return CurrentDragHasSupportedFormat() ;
|
||||||
}
|
}
|
||||||
@ -77,13 +77,13 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
|
|||||||
return GetData() ? def : wxDragNone;
|
return GetData() ? def : wxDragNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDropTarget::CurrentDragHasSupportedFormat()
|
bool wxDropTarget::CurrentDragHasSupportedFormat()
|
||||||
{
|
{
|
||||||
bool supported = false ;
|
bool supported = false ;
|
||||||
if ( gTrackingGlobals.m_currentSource != NULL )
|
if ( gTrackingGlobals.m_currentSource != NULL )
|
||||||
{
|
{
|
||||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
||||||
|
|
||||||
if ( data )
|
if ( data )
|
||||||
{
|
{
|
||||||
size_t formatcount = data->GetFormatCount() ;
|
size_t formatcount = data->GetFormatCount() ;
|
||||||
@ -92,27 +92,32 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
|
|||||||
for (size_t i = 0; !supported && i < formatcount ; i++)
|
for (size_t i = 0; !supported && i < formatcount ; i++)
|
||||||
{
|
{
|
||||||
wxDataFormat format = array[i] ;
|
wxDataFormat format = array[i] ;
|
||||||
if ( m_dataObject->IsSupported( format ) )
|
if ( m_dataObject->IsSupported( format ) )
|
||||||
{
|
{
|
||||||
supported = true ;
|
supported = true ;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] array ;
|
|
||||||
|
delete [] array ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !supported )
|
if ( !supported )
|
||||||
{
|
{
|
||||||
UInt16 items ;
|
UInt16 items ;
|
||||||
OSErr result;
|
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;
|
flavors = 0 ;
|
||||||
FlavorType theType ;
|
|
||||||
UInt16 flavors = 0 ;
|
|
||||||
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
|
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
|
||||||
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
|
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
|
||||||
|
|
||||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||||
{
|
{
|
||||||
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
||||||
@ -124,36 +129,37 @@ bool wxDropTarget::CurrentDragHasSupportedFormat()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return supported ;
|
|
||||||
|
return supported ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDropTarget::GetData()
|
bool wxDropTarget::GetData()
|
||||||
{
|
{
|
||||||
if (!m_dataObject)
|
if (!m_dataObject)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
if ( !CurrentDragHasSupportedFormat() )
|
if ( !CurrentDragHasSupportedFormat() )
|
||||||
return FALSE ;
|
return false ;
|
||||||
|
|
||||||
bool transferred = false ;
|
bool transferred = false ;
|
||||||
if ( gTrackingGlobals.m_currentSource != NULL )
|
if ( gTrackingGlobals.m_currentSource != NULL )
|
||||||
{
|
{
|
||||||
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
wxDataObject* data = gTrackingGlobals.m_currentSource->GetDataObject() ;
|
||||||
|
|
||||||
if ( data )
|
if ( data )
|
||||||
{
|
{
|
||||||
size_t formatcount = data->GetFormatCount() ;
|
size_t formatcount = data->GetFormatCount() ;
|
||||||
wxDataFormat *array = new wxDataFormat[ formatcount ];
|
wxDataFormat *array = new wxDataFormat[formatcount];
|
||||||
data->GetAllFormats( array );
|
data->GetAllFormats( array );
|
||||||
for (size_t i = 0; !transferred && i < formatcount ; i++)
|
for (size_t i = 0; !transferred && i < formatcount ; i++)
|
||||||
{
|
{
|
||||||
wxDataFormat format = array[i] ;
|
wxDataFormat format = array[i] ;
|
||||||
if ( m_dataObject->IsSupported( format ) )
|
if ( m_dataObject->IsSupported( format ) )
|
||||||
{
|
{
|
||||||
int size = data->GetDataSize( format );
|
int size = data->GetDataSize( format );
|
||||||
transferred = true ;
|
transferred = true ;
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
m_dataObject->SetData(format , 0 , 0 ) ;
|
m_dataObject->SetData(format , 0 , 0 ) ;
|
||||||
}
|
}
|
||||||
@ -162,29 +168,34 @@ bool wxDropTarget::GetData()
|
|||||||
char *d = new char[size];
|
char *d = new char[size];
|
||||||
data->GetDataHere( format , (void*) d );
|
data->GetDataHere( format , (void*) d );
|
||||||
m_dataObject->SetData( format , size , d ) ;
|
m_dataObject->SetData( format , size , d ) ;
|
||||||
delete[] d ;
|
delete [] d ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] array ;
|
|
||||||
|
delete [] array ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !transferred )
|
if ( !transferred )
|
||||||
{
|
{
|
||||||
UInt16 items ;
|
UInt16 items ;
|
||||||
OSErr result;
|
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;
|
flavors = 0 ;
|
||||||
FlavorType theType ;
|
|
||||||
UInt16 flavors = 0 ;
|
|
||||||
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
|
GetDragItemReferenceNumber((DragReference)m_currentDrag, index, &theItem);
|
||||||
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
|
CountDragItemFlavors( (DragReference)m_currentDrag, theItem , &flavors ) ;
|
||||||
bool hasPreferredFormat = false ;
|
bool hasPreferredFormat = false ;
|
||||||
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
|
wxDataFormat preferredFormat = m_dataObject->GetPreferredFormat( wxDataObject::Set ) ;
|
||||||
|
|
||||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||||
{
|
{
|
||||||
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
||||||
@ -195,19 +206,19 @@ bool wxDropTarget::GetData()
|
|||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
for ( UInt16 flavor = 1 ; flavor <= flavors ; ++flavor )
|
||||||
{
|
{
|
||||||
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
result = GetFlavorType((DragReference)m_currentDrag, theItem, flavor , &theType);
|
||||||
wxDataFormat format(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);
|
result = GetFlavorFlags((DragReference)m_currentDrag, theItem, theType, &theFlags);
|
||||||
if (result == noErr)
|
if (result == noErr)
|
||||||
{
|
{
|
||||||
Size dataSize ;
|
Size dataSize ;
|
||||||
Ptr theData ;
|
Ptr theData ;
|
||||||
|
|
||||||
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
|
GetFlavorDataSize((DragReference)m_currentDrag, theItem, theType, &dataSize);
|
||||||
if ( theType == kScrapFlavorTypeText )
|
if ( theType == kScrapFlavorTypeText )
|
||||||
{
|
{
|
||||||
@ -222,18 +233,19 @@ bool wxDropTarget::GetData()
|
|||||||
dataSize++ ;
|
dataSize++ ;
|
||||||
dataSize++ ;
|
dataSize++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
theData = new char[dataSize];
|
theData = new char[dataSize];
|
||||||
GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
|
GetFlavorData((DragReference)m_currentDrag, theItem, theType, (void*) theData, &dataSize, 0L);
|
||||||
if( theType == kScrapFlavorTypeText )
|
if ( theType == kScrapFlavorTypeText )
|
||||||
{
|
{
|
||||||
theData[dataSize]=0 ;
|
theData[dataSize] = 0 ;
|
||||||
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
|
m_dataObject->SetData( wxDataFormat(wxDF_TEXT), dataSize , theData );
|
||||||
}
|
}
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
else if ( theType == kScrapFlavorTypeUnicode )
|
else if ( theType == 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 );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -245,22 +257,25 @@ bool wxDropTarget::GetData()
|
|||||||
{
|
{
|
||||||
// reset file list
|
// reset file list
|
||||||
((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
|
((wxFileDataObject*)m_dataObject)->SetData( 0 , "" ) ;
|
||||||
firstFileAdded = true ;
|
firstFileAdded = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
|
((wxFileDataObject*)m_dataObject)->AddFile( name ) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_dataObject->SetData( format, dataSize, theData );
|
m_dataObject->SetData( format, dataSize, theData );
|
||||||
}
|
}
|
||||||
delete[] theData;
|
|
||||||
|
delete [] theData;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE ;
|
|
||||||
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -296,29 +311,27 @@ wxDropSource::~wxDropSource()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxDragResult wxDropSource::DoDragDrop(int flags)
|
wxDragResult wxDropSource::DoDragDrop(int flags)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
wxASSERT_MSG( m_data, wxT("Drop source: no data") );
|
||||||
|
|
||||||
if (!m_data)
|
if (!m_data)
|
||||||
return (wxDragResult) wxDragNone;
|
return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
if (m_data->GetFormatCount() == 0)
|
if (m_data->GetFormatCount() == 0)
|
||||||
return (wxDragResult) wxDragNone;
|
return (wxDragResult) wxDragNone;
|
||||||
|
|
||||||
OSErr result;
|
OSErr result;
|
||||||
DragReference theDrag;
|
DragReference theDrag;
|
||||||
RgnHandle dragRegion;
|
RgnHandle dragRegion;
|
||||||
if ((result = NewDrag(&theDrag)))
|
if ((result = NewDrag(&theDrag)) != noErr)
|
||||||
{
|
|
||||||
return wxDragNone ;
|
return wxDragNone ;
|
||||||
}
|
|
||||||
// add data to drag
|
// add data to drag
|
||||||
size_t formatCount = m_data->GetFormatCount() ;
|
size_t formatCount = m_data->GetFormatCount() ;
|
||||||
wxDataFormat *formats = new wxDataFormat[formatCount] ;
|
wxDataFormat *formats = new wxDataFormat[formatCount] ;
|
||||||
m_data->GetAllFormats( formats ) ;
|
m_data->GetAllFormats( formats ) ;
|
||||||
ItemReference theItem = 1 ;
|
ItemReference theItem = 1 ;
|
||||||
|
|
||||||
for ( size_t i = 0 ; i < formatCount ; ++i )
|
for ( size_t i = 0 ; i < formatCount ; ++i )
|
||||||
{
|
{
|
||||||
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
|
size_t dataSize = m_data->GetDataSize( formats[i] ) ;
|
||||||
@ -336,104 +349,115 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
|
|||||||
dataSize-- ;
|
dataSize-- ;
|
||||||
dataPtr[ dataSize ] = 0 ;
|
dataPtr[ dataSize ] = 0 ;
|
||||||
}
|
}
|
||||||
AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
|
|
||||||
|
AddDragItemFlavor(theDrag, theItem, type , dataPtr, dataSize, 0);
|
||||||
}
|
}
|
||||||
else if (type == kDragFlavorTypeHFS )
|
else if (type == kDragFlavorTypeHFS )
|
||||||
{
|
{
|
||||||
HFSFlavor theFlavor ;
|
HFSFlavor theFlavor ;
|
||||||
OSErr err = noErr;
|
OSErr err = noErr;
|
||||||
CInfoPBRec cat;
|
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.ioNamePtr = theFlavor.fileSpec.name;
|
||||||
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
|
cat.hFileInfo.ioVRefNum = theFlavor.fileSpec.vRefNum;
|
||||||
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
|
cat.hFileInfo.ioDirID = theFlavor.fileSpec.parID;
|
||||||
cat.hFileInfo.ioFDirIndex = 0;
|
cat.hFileInfo.ioFDirIndex = 0;
|
||||||
err = PBGetCatInfoSync(&cat);
|
err = PBGetCatInfoSync(&cat);
|
||||||
if (err == noErr )
|
if (err == noErr)
|
||||||
{
|
{
|
||||||
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.fileCreator = 'MACS';
|
||||||
theFlavor.fileType = 'disk';
|
theFlavor.fileType = 'disk';
|
||||||
} else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0) {
|
}
|
||||||
|
else if ((cat.hFileInfo.ioFlAttrib & ioDirMask) != 0)
|
||||||
|
{
|
||||||
theFlavor.fileCreator = 'MACS';
|
theFlavor.fileCreator = 'MACS';
|
||||||
theFlavor.fileType = 'fold';
|
theFlavor.fileType = 'fold';
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
|
theFlavor.fileCreator = cat.hFileInfo.ioFlFndrInfo.fdCreator;
|
||||||
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
|
theFlavor.fileType = cat.hFileInfo.ioFlFndrInfo.fdType;
|
||||||
}
|
}
|
||||||
AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
|
|
||||||
}
|
AddDragItemFlavor(theDrag, theItem, type , &theFlavor, sizeof(theFlavor), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
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();
|
dragRegion = NewRgn();
|
||||||
RgnHandle tempRgn = NewRgn() ;
|
RgnHandle tempRgn = NewRgn() ;
|
||||||
|
|
||||||
EventRecord* ev = NULL ;
|
EventRecord* ev = NULL ;
|
||||||
|
|
||||||
#if !TARGET_CARBON // TODO
|
#if !TARGET_CARBON // TODO
|
||||||
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
|
ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
|
||||||
#else
|
#else
|
||||||
EventRecord rec ;
|
{
|
||||||
ev = &rec ;
|
EventRecord rec ;
|
||||||
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
|
ev = &rec ;
|
||||||
|
wxMacConvertEventToRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const short dragRegionOuterBoundary = 10 ;
|
const short dragRegionOuterBoundary = 10 ;
|
||||||
const short dragRegionInnerBoundary = 9 ;
|
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
|
// TODO:work with promises in order to return data only when drag
|
||||||
// was successfully completed
|
// was successfully completed
|
||||||
|
|
||||||
gTrackingGlobals.m_currentSource = this ;
|
gTrackingGlobals.m_currentSource = this ;
|
||||||
result = TrackDrag(theDrag, ev , dragRegion);
|
result = TrackDrag(theDrag, ev , dragRegion);
|
||||||
DisposeRgn(dragRegion);
|
DisposeRgn(dragRegion);
|
||||||
DisposeDrag(theDrag);
|
DisposeDrag(theDrag);
|
||||||
gTrackingGlobals.m_currentSource = NULL ;
|
gTrackingGlobals.m_currentSource = NULL ;
|
||||||
|
|
||||||
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
||||||
wxDragResult dndresult = wxDragCopy ;
|
wxDragResult dndresult = wxDragCopy ;
|
||||||
if ( flags != wxDrag_CopyOnly )
|
if ( flags != wxDrag_CopyOnly )
|
||||||
{
|
|
||||||
// on mac the option key is always the indication for copy
|
// on mac the option key is always the indication for copy
|
||||||
dndresult = optionDown ? wxDragCopy : wxDragMove;
|
dndresult = optionDown ? wxDragCopy : wxDragMove;
|
||||||
}
|
|
||||||
return dndresult;
|
return dndresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
|
bool wxDropSource::MacInstallDefaultCursor(wxDragResult effect)
|
||||||
{
|
{
|
||||||
const wxCursor& cursor = GetCursor(effect);
|
const wxCursor& cursor = GetCursor(effect);
|
||||||
if ( cursor.Ok() )
|
bool result = cursor.Ok();
|
||||||
{
|
|
||||||
|
if ( result )
|
||||||
cursor.MacInstall() ;
|
cursor.MacInstall() ;
|
||||||
|
|
||||||
return TRUE;
|
return result;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gTrackingGlobalsInstalled = false ;
|
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
|
// 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...
|
// but I'll leave it in there, just in case...
|
||||||
|
|
||||||
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
|
pascal OSErr wxMacWindowDragTrackingHandler(
|
||||||
void *handlerRefCon, DragReference theDrag) ;
|
DragTrackingMessage theMessage, WindowPtr theWindow,
|
||||||
pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
|
void *handlerRefCon, DragReference theDrag) ;
|
||||||
DragReference theDrag) ;
|
pascal OSErr wxMacWindowDragReceiveHandler(
|
||||||
|
WindowPtr theWindow, void *handlerRefCon,
|
||||||
|
DragReference theDrag) ;
|
||||||
|
|
||||||
void wxMacEnsureTrackingHandlersInstalled()
|
void wxMacEnsureTrackingHandlersInstalled()
|
||||||
{
|
{
|
||||||
if( !gTrackingGlobalsInstalled )
|
if ( !gTrackingGlobalsInstalled )
|
||||||
{
|
{
|
||||||
OSErr result;
|
OSErr result;
|
||||||
|
|
||||||
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
|
result = InstallTrackingHandler(NewDragTrackingHandlerUPP(wxMacWindowDragTrackingHandler), 0L,&gTrackingGlobals);
|
||||||
wxASSERT( result == noErr ) ;
|
wxASSERT( result == noErr ) ;
|
||||||
|
|
||||||
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
|
result = InstallReceiveHandler(NewDragReceiveHandlerUPP(wxMacWindowDragReceiveHandler), 0L, &gTrackingGlobals);
|
||||||
wxASSERT( result == noErr ) ;
|
wxASSERT( result == noErr ) ;
|
||||||
|
|
||||||
@ -461,28 +488,30 @@ void wxMacEnsureTrackingHandlersInstalled()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
|
pascal OSErr wxMacWindowDragTrackingHandler(
|
||||||
void *handlerRefCon, DragReference theDrag)
|
DragTrackingMessage theMessage, WindowPtr theWindow,
|
||||||
{
|
void *handlerRefCon, DragReference theDrag)
|
||||||
|
{
|
||||||
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
|
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
|
||||||
Point mouse, localMouse;
|
Point mouse, localMouse;
|
||||||
DragAttributes attributes;
|
DragAttributes attributes;
|
||||||
GetDragAttributes(theDrag, &attributes);
|
GetDragAttributes(theDrag, &attributes);
|
||||||
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
|
wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( theWindow ) ;
|
||||||
|
|
||||||
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
bool optionDown = GetCurrentKeyModifiers() & optionKey ;
|
||||||
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
wxDragResult result = optionDown ? wxDragCopy : wxDragMove;
|
||||||
|
|
||||||
switch(theMessage)
|
switch (theMessage)
|
||||||
{
|
{
|
||||||
case kDragTrackingEnterHandler:
|
case kDragTrackingEnterHandler:
|
||||||
break;
|
|
||||||
case kDragTrackingLeaveHandler:
|
case kDragTrackingLeaveHandler:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kDragTrackingEnterWindow:
|
case kDragTrackingEnterWindow:
|
||||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||||
trackingGlobals->m_currentTarget = NULL ;
|
trackingGlobals->m_currentTarget = NULL ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kDragTrackingInWindow:
|
case kDragTrackingInWindow:
|
||||||
if (toplevel == NULL)
|
if (toplevel == NULL)
|
||||||
break;
|
break;
|
||||||
@ -491,18 +520,17 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
localMouse = mouse;
|
localMouse = mouse;
|
||||||
GlobalToLocal(&localMouse);
|
GlobalToLocal(&localMouse);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
wxWindow *win = NULL ;
|
wxWindow *win = NULL ;
|
||||||
ControlPartCode controlPart ;
|
ControlPartCode controlPart ;
|
||||||
ControlRef control = wxMacFindControlUnderMouse( toplevel , localMouse ,
|
ControlRef control = wxMacFindControlUnderMouse(
|
||||||
|
toplevel , localMouse ,
|
||||||
theWindow , &controlPart ) ;
|
theWindow , &controlPart ) ;
|
||||||
if ( control )
|
if ( control )
|
||||||
win = wxFindControlFromMacControl( control ) ;
|
win = wxFindControlFromMacControl( control ) ;
|
||||||
else
|
else
|
||||||
win = toplevel ;
|
win = toplevel ;
|
||||||
|
|
||||||
int localx , localy ;
|
int localx , localy ;
|
||||||
localx = localMouse.h ;
|
localx = localMouse.h ;
|
||||||
localy = localMouse.v ;
|
localy = localMouse.v ;
|
||||||
@ -516,35 +544,34 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
// this window is left
|
// this window is left
|
||||||
if ( trackingGlobals->m_currentTarget )
|
if ( trackingGlobals->m_currentTarget )
|
||||||
{
|
{
|
||||||
HideDragHilite(theDrag);
|
HideDragHilite( theDrag );
|
||||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||||
trackingGlobals->m_currentTarget->OnLeave() ;
|
trackingGlobals->m_currentTarget->OnLeave() ;
|
||||||
trackingGlobals->m_currentTarget = NULL;
|
trackingGlobals->m_currentTarget = NULL;
|
||||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( win )
|
if ( win )
|
||||||
{
|
{
|
||||||
// this window is entered
|
// this window is entered
|
||||||
trackingGlobals->m_currentTargetWindow = win ;
|
trackingGlobals->m_currentTargetWindow = win ;
|
||||||
trackingGlobals->m_currentTarget = win->GetDropTarget() ;
|
trackingGlobals->m_currentTarget = win->GetDropTarget() ;
|
||||||
{
|
{
|
||||||
|
if ( trackingGlobals->m_currentTarget )
|
||||||
if ( trackingGlobals->m_currentTarget )
|
{
|
||||||
{
|
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
result = trackingGlobals->m_currentTarget->OnEnter( localx , localy , result ) ;
|
||||||
result = trackingGlobals->m_currentTarget->OnEnter(
|
|
||||||
localx , localy , result ) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( result != wxDragNone )
|
if ( result != wxDragNone )
|
||||||
{
|
{
|
||||||
int x , y ;
|
int x , y ;
|
||||||
|
|
||||||
x = y = 0 ;
|
x = y = 0 ;
|
||||||
win->MacWindowToRootWindow( &x , &y ) ;
|
win->MacWindowToRootWindow( &x , &y ) ;
|
||||||
RgnHandle hiliteRgn = NewRgn() ;
|
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 ) ;
|
RectRgn( hiliteRgn , &r ) ;
|
||||||
ShowDragHilite(theDrag, hiliteRgn, true);
|
ShowDragHilite(theDrag, hiliteRgn, true);
|
||||||
DisposeRgn( hiliteRgn ) ;
|
DisposeRgn( hiliteRgn ) ;
|
||||||
@ -554,20 +581,19 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( trackingGlobals->m_currentTarget )
|
if ( trackingGlobals->m_currentTarget )
|
||||||
{
|
{
|
||||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||||
trackingGlobals->m_currentTarget->OnDragOver(
|
trackingGlobals->m_currentTarget->OnDragOver( localx , localy , result ) ;
|
||||||
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 ) )
|
||||||
{
|
{
|
||||||
switch( result )
|
switch ( result )
|
||||||
{
|
{
|
||||||
case wxDragCopy :
|
case wxDragCopy :
|
||||||
{
|
{
|
||||||
@ -575,12 +601,14 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
cursor.MacInstall() ;
|
cursor.MacInstall() ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case wxDragMove :
|
case wxDragMove :
|
||||||
{
|
{
|
||||||
wxCursor cursor(wxCURSOR_ARROW) ;
|
wxCursor cursor(wxCURSOR_ARROW) ;
|
||||||
cursor.MacInstall() ;
|
cursor.MacInstall() ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case wxDragNone :
|
case wxDragNone :
|
||||||
{
|
{
|
||||||
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
|
wxCursor cursor(wxCURSOR_NO_ENTRY) ;
|
||||||
@ -591,16 +619,17 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
case wxDragError:
|
case wxDragError:
|
||||||
case wxDragLink:
|
case wxDragLink:
|
||||||
case wxDragCancel:
|
case wxDragCancel:
|
||||||
|
default:
|
||||||
// put these here to make gcc happy
|
// put these here to make gcc happy
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kDragTrackingLeaveWindow:
|
case kDragTrackingLeaveWindow:
|
||||||
if (trackingGlobals->m_currentTarget)
|
if (trackingGlobals->m_currentTarget)
|
||||||
{
|
{
|
||||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||||
trackingGlobals->m_currentTarget->OnLeave() ;
|
trackingGlobals->m_currentTarget->OnLeave() ;
|
||||||
@ -609,27 +638,33 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind
|
|||||||
}
|
}
|
||||||
trackingGlobals->m_currentTargetWindow = NULL ;
|
trackingGlobals->m_currentTargetWindow = NULL ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return(noErr);
|
|
||||||
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pascal OSErr wxMacWindowDragReceiveHandler(WindowPtr theWindow,
|
pascal OSErr wxMacWindowDragReceiveHandler(
|
||||||
void *handlerRefCon,
|
WindowPtr theWindow,
|
||||||
DragReference theDrag)
|
void *handlerRefCon,
|
||||||
{
|
DragReference theDrag)
|
||||||
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
|
{
|
||||||
|
MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*)handlerRefCon;
|
||||||
if ( trackingGlobals->m_currentTarget )
|
if ( trackingGlobals->m_currentTarget )
|
||||||
{
|
{
|
||||||
Point mouse,localMouse ;
|
Point mouse, localMouse ;
|
||||||
int localx,localy ;
|
int localx, localy ;
|
||||||
|
|
||||||
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
|
||||||
GetDragMouse(theDrag, &mouse, 0L);
|
GetDragMouse(theDrag, &mouse, 0L);
|
||||||
localMouse = mouse;
|
localMouse = mouse;
|
||||||
GlobalToLocal(&localMouse);
|
GlobalToLocal(&localMouse);
|
||||||
localx = localMouse.h ;
|
localx = localMouse.h ;
|
||||||
localy = localMouse.v ;
|
localy = localMouse.v ;
|
||||||
//TODO : should we use client coordinates
|
|
||||||
|
// TODO : should we use client coordinates?
|
||||||
if ( trackingGlobals->m_currentTargetWindow )
|
if ( trackingGlobals->m_currentTargetWindow )
|
||||||
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
|
trackingGlobals->m_currentTargetWindow->MacRootWindowToWindow( &localx , &localy ) ;
|
||||||
if ( trackingGlobals->m_currentTarget->OnDrop( 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 ) ;
|
trackingGlobals->m_currentTarget->OnData( localx , localy , result ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(noErr);
|
|
||||||
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user