JBoolean TestWidget::WillAcceptDrop ( const JArray<Atom>& typeList, Atom* action, const Time time, const JXWidget* source ) { JXDNDManager* dndMgr = GetDNDManager(); if (typeList.GetFirstElement() == (GetSelectionManager())->GetURLXAtom()) { cout << endl; cout << "Accepting the drop of type text/uri-list" << endl; cout << endl; *action = dndMgr->GetDNDActionPrivateXAtom(); return kJTrue; } else if (*action == dndMgr->GetDNDActionCopyXAtom()) { cout << endl; cout << "Accepting the drop" << endl; cout << endl; PrintSelectionText(dndMgr->GetDNDSelectionName(), time, (GetSelectionManager())->GetMimePlainTextXAtom()); return kJTrue; } else { JXDisplay* display = GetDisplay(); cout << endl; cout << "Not accepting the drop because the action isn't copy" << endl; cout << "Action: " << XGetAtomName(*display, *action) << endl; cout << endl; cout << "Data types available from DND source:" << endl; cout << endl; const JSize typeCount = typeList.GetElementCount(); for (JIndex i=1; i<=typeCount; i++) { const Atom type = typeList.GetElement(i); cout << XGetAtomName(*display, type) << endl; } cout << endl; PrintSelectionText(dndMgr->GetDNDSelectionName(), time, (GetSelectionManager())->GetMimePlainTextXAtom()); return kJFalse; } }
void CBCommandTable::HandleDNDDrop ( const JPoint& pt, const JArray<Atom>& typeList, const Atom action, const Time time, const JXWidget* source ) { JXSelectionManager* selMgr = GetSelectionManager(); JXDNDManager* dndMgr = GetDNDManager(); const Atom selName = dndMgr->GetDNDSelectionName(); if (source == this && action == dndMgr->GetDNDActionMoveXAtom()) { JPoint cell; if ((GetTableSelection()).GetSingleSelectedCell(&cell) && itsDNDRowIndex != JIndex(cell.y) && itsDNDRowIndex != JIndex(cell.y)+1) { JIndex newIndex = itsDNDRowIndex; if (newIndex > JIndex(cell.y)) { newIndex--; } newIndex = JMin(newIndex, GetRowCount()); itsCmdList->MoveElementToIndex(cell.y, newIndex); MoveRow(cell.y, newIndex); SelectSingleCell(JPoint(1, newIndex)); } } else if (source == this) { JPoint cell; if ((GetTableSelection()).GetSingleSelectedCell(&cell)) { itsCmdList->InsertElementAtIndex( itsDNDRowIndex, (itsCmdList->GetElement(cell.y)).Copy()); InsertRows(itsDNDRowIndex, 1); SelectSingleCell(JPoint(1, itsDNDRowIndex)); } } else { Atom returnType; unsigned char* data; JSize dataLength; JXSelectionManager::DeleteMethod delMethod; if (selMgr->GetData(selName, time, itsCommandXAtom, &returnType, &data, &dataLength, &delMethod)) { if (returnType == itsCommandXAtom) { const std::string s((char*) data, dataLength); std::istringstream input(s); CBCommandManager::CmdInfo cmdInfo = CBCommandManager::ReadCmdInfo(input, CBCommandManager::GetCurrentCmdInfoFileVersion()); if (!input.fail()) { const JIndex newIndex = JMax(JIndex(1), itsDNDRowIndex); itsCmdList->InsertElementAtIndex(newIndex, cmdInfo); InsertRows(newIndex, 1); SelectSingleCell(JPoint(1, newIndex)); if (action == dndMgr->GetDNDActionMoveXAtom()) { selMgr->SendDeleteRequest(selName, time); } } } selMgr->DeleteData(&data, delMethod); } } HandleDNDLeave(); }