bool wxGxContentView::OnDropObjects(wxCoord x, wxCoord y, const wxArrayString& GxObjects, bool bIsControlOn) { bool bMove = !bIsControlOn; SetItemState(m_HighLightItem, 0, wxGISLIST_STATE_DROPHILITED); //SetItemState(m_HighLightItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); wxPoint pt(x, y); unsigned long nFlags(0); long nItemId = HitTest(pt, (int &)nFlags); long nObjectID(m_nParentGxObjectID); if(nItemId != wxNOT_FOUND && (nFlags & wxLIST_HITTEST_ONITEM)) { LPITEMDATA pItemData = (LPITEMDATA)GetItemData(nItemId); nObjectID = pItemData->nObjectID; } wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(nObjectID); IGxDropTarget* pTarget = dynamic_cast<IGxDropTarget*>(pGxObject); if(pTarget) { wxDragResult res(bMove == true ? wxDragMove : wxDragCopy); if(wxIsDragResultOk(pTarget->CanDrop(res))) return pTarget->Drop(GxObjects, bMove); } return false; }
bool wxGxTreeView::OnDropObjects(wxCoord x, wxCoord y, const wxArrayString& GxObjects) { bool bMove = !wxGetKeyState(WXK_CONTROL); wxPoint pt(x, y); int flag = wxTREE_HITTEST_ONITEMINDENT; wxTreeItemId ItemId = wxTreeCtrl::HitTest(pt, flag); if(ItemId.IsOk()) { SetItemDropHighlight(ItemId, false); wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(ItemId); if(pData == NULL) return wxDragNone; wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); IGxDropTarget* pTarget = dynamic_cast<IGxDropTarget*>(pGxObject); if(pTarget) { wxDragResult res(bMove == true ? wxDragMove : wxDragCopy); if(wxIsDragResultOk(pTarget->CanDrop(res))) return pTarget->Drop(GxObjects, bMove); } } return false; }
static void target_drag_data_received( GtkWidget *WXUNUSED(widget), GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint WXUNUSED(info), guint time, wxDropTarget *drop_target ) { if (g_isIdle) wxapp_install_idle_handler(); /* Owen Taylor: "call gtk_drag_finish() with success == TRUE" */ if ((data->length <= 0) || (data->format != 8)) { /* negative data length and non 8-bit data format qualifies for junk */ gtk_drag_finish (context, FALSE, FALSE, time); return; } #ifdef __WXDEBUG__ wxLogTrace(TRACE_DND, wxT( "Drop target: data received event") ); #endif /* inform the wxDropTarget about the current GtkSelectionData. this is only valid for the duration of this call */ drop_target->SetDragData( data ); wxDragResult result = ConvertFromGTK(context->action); if ( wxIsDragResultOk( drop_target->OnData( x, y, result ) ) ) { #ifdef __WXDEBUG__ wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned true") ); #endif /* tell GTK that data transfer was successful */ gtk_drag_finish( context, TRUE, FALSE, time ); } else { #ifdef __WXDEBUG__ wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned FALSE") ); #endif /* tell GTK that data transfer was not successful */ gtk_drag_finish( context, FALSE, FALSE, time ); } /* after this, invalidate the drop_target's drag data */ drop_target->SetDragData( (GtkSelectionData*) NULL ); }
static void target_drag_data_received( GtkWidget *WXUNUSED(widget), GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint WXUNUSED(info), guint time, wxDropTarget *drop_target ) { /* Owen Taylor: "call gtk_drag_finish() with success == TRUE" */ if (gtk_selection_data_get_length(data) <= 0 || gtk_selection_data_get_format(data) != 8) { /* negative data length and non 8-bit data format qualifies for junk */ gtk_drag_finish (context, FALSE, FALSE, time); return; } wxLogTrace(TRACE_DND, wxT( "Drop target: data received event") ); /* inform the wxDropTarget about the current GtkSelectionData. this is only valid for the duration of this call */ drop_target->GTKSetDragData( data ); wxDragResult result = ConvertFromGTK(gdk_drag_context_get_selected_action(context)); if ( wxIsDragResultOk( drop_target->OnData( x, y, result ) ) ) { wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned true") ); /* tell GTK that data transfer was successful */ gtk_drag_finish( context, TRUE, FALSE, time ); } else { wxLogTrace(TRACE_DND, wxT( "Drop target: OnData returned FALSE") ); /* tell GTK that data transfer was not successful */ gtk_drag_finish( context, FALSE, FALSE, time ); } /* after this, invalidate the drop_target's drag data */ drop_target->GTKSetDragData( NULL ); }
// Name : wxIDropTarget::Drop // Purpose : Instructs the drop target to paste data that was just now // dropped on it. // Returns : S_OK // Params : [in] IDataObject *pIDataSource the data to paste // [in] DWORD grfKeyState kbd & mouse state // [in] POINTL pt where the drop occurred? // [in/out]DWORD *pdwEffect operation effect // Notes : STDMETHODIMP wxIDropTarget::Drop(IDataObject *pIDataSource, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) { wxLogTrace(wxTRACE_OleCalls, wxT("IDropTarget::Drop")); // TODO I don't know why there is this parameter, but so far I assume // that it's the same we've already got in DragEnter wxASSERT( m_pIDataObject == pIDataSource ); // we need client coordinates to pass to wxWin functions if ( !ScreenToClient(m_hwnd, (POINT *)&pt) ) { wxLogLastError(wxT("ScreenToClient")); } // first ask the drop target if it wants data if ( m_pTarget->OnDrop(pt.x, pt.y) ) { // it does, so give it the data source m_pTarget->MSWSetDataSource(pIDataSource); // and now it has the data wxDragResult rc = ConvertDragEffectToResult( GetDropEffect(grfKeyState, m_pTarget->GetDefaultAction(), *pdwEffect)); rc = m_pTarget->OnData(pt.x, pt.y, rc); if ( wxIsDragResultOk(rc) ) { // operation succeeded *pdwEffect = ConvertDragResultToEffect(rc); } else { *pdwEffect = DROPEFFECT_NONE; } } else { // OnDrop() returned false, no need to copy data *pdwEffect = DROPEFFECT_NONE; } // release the held object RELEASE_AND_NULL(m_pIDataObject); return S_OK; }
static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), GdkDragContext *context, gint x, gint y, guint time, wxDropTarget *drop_target ) { if (g_isIdle) wxapp_install_idle_handler(); /* Owen Taylor: "if the coordinates not in a drop zone, return FALSE, otherwise call gtk_drag_status() and return TRUE" */ /* inform the wxDropTarget about the current GdkDragContext. this is only valid for the duration of this call */ drop_target->SetDragContext( context ); // GTK+ always supposes that we want to copy the data by default while we // might want to move it, so examine not only suggested_action - which is // only good if we don't have our own preferences - but also the actions // field wxDragResult result; if (drop_target->GetDefaultAction() == wxDragNone) { // use default action set by wxDropSource::DoDragDrop() if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove && (context->actions & GDK_ACTION_MOVE ) ) { // move is requested by the program and allowed by GTK+ - do it, even // though suggested_action may be currently wxDragCopy result = wxDragMove; } else // use whatever GTK+ says we should { result = ConvertFromGTK(context->suggested_action); if ( (result == wxDragMove) && !(gs_flagsForDrag & wxDrag_AllowMove) ) { // we're requested to move but we can't result = wxDragCopy; } } } else if (drop_target->GetDefaultAction() == wxDragMove && (context->actions & GDK_ACTION_MOVE)) { result = wxDragMove; } else { if (context->actions & GDK_ACTION_COPY) result = wxDragCopy; else if (context->actions & GDK_ACTION_MOVE) result = wxDragMove; else result = wxDragNone; } if (drop_target->m_firstMotion) { /* the first "drag_motion" event substitutes a "drag_enter" event */ result = drop_target->OnEnter( x, y, result ); } else { /* give program a chance to react (i.e. to say no by returning FALSE) */ result = drop_target->OnDragOver( x, y, result ); } bool ret = wxIsDragResultOk( result ); if (ret) { GdkDragAction action; if (result == wxDragCopy) action = GDK_ACTION_COPY; else if (result == wxDragLink) action = GDK_ACTION_LINK; else action = GDK_ACTION_MOVE; gdk_drag_status( context, action, time ); } /* after this, invalidate the drop_target's GdkDragContext */ drop_target->SetDragContext( (GdkDragContext*) NULL ); /* this has to be done because GDK has no "drag_enter" event */ drop_target->m_firstMotion = false; return ret; }
bool wxGISCatalogMainCmd::GetEnabled(void) { wxCHECK_MSG(m_pGxApp, false, wxT("Application pointer is null")); wxGxSelection* pSel = m_pGxApp->GetGxSelection(); wxGxCatalogBase* pCat = GetGxCatalog(); switch(m_subtype) { case 0://Up One Level if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); return pGxObject != NULL && pGxObject->GetParent(); } return false; case 1: return true; case 2: //check if wxGxDiscConnection if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); return pGxObject != NULL && pGxObject->IsKindOf(wxCLASSINFO(wxGxDiscConnection)); } return false; case 3: return true; case 4://delete if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanDelete()) return true; } } return false; case 5: if(pSel) return pSel->CanUndo(); return false; case 6: if(pSel) return pSel->CanRedo(); return false; case 7: if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); wxGxObjectContainer* pCont = wxDynamicCast(pGxObject, wxGxObjectContainer); if(pCont) return pCont->CanCreate(enumGISContainer, enumContFolder); } return false; case 8://Rename if(pCat && pSel) { size_t nCounter(0); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanRename()) nCounter++; } return nCounter == 1 ? true : false; } return false; case 9://Refresh if(pSel) return pSel->GetCount() > 0; return false; case 10://Properties //check if IGxObjectEditUI if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); return dynamic_cast<IGxObjectEditUI*>(pGxObject); } return false; case 11://Copy if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanCopy("")) return true; } } return false; case 12://Cut if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanMove("")) return true; } } return false; case 13://Paste { IViewDropTarget* pViewDropTarget = dynamic_cast<IViewDropTarget*>(wxWindow::FindFocus()); if(pViewDropTarget) { if( pViewDropTarget->CanPaste() ) { wxClipboardLocker locker; bool bMove(false); if(!locker) { // } else { wxTextDataObject data; if(wxTheClipboard->GetData( data )) { if(data.GetText() == wxString(wxT("cut"))) bMove = true; } } for(size_t i = 0; i < pSel->GetCount(); ++i) { IGxDropTarget* pGxDropTarget = dynamic_cast<IGxDropTarget*>(pCat->GetRegisterObject(pSel->GetSelectedObjectId(i))); if(pGxDropTarget && wxIsDragResultOk(pGxDropTarget->CanDrop(bMove == true ? wxDragMove : wxDragCopy))) return true; } } } } return false; default: return false; } }