THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/12/2006 at 10:52, xxxxxxxx wrote:
Can't remember the reference offhand, but you just want to forget about using 'dragarray' - not tenable. And I'm supporting multiple drag objects by selection flag and not an AtomArray (funky way around this, that is). RuntimeItem is my tree item class (placed under a tree root).
Here's a basic version of what I did:
//*---------------------------------------------------------------------------*
LONG GetDragType(void* root, void* userdata, void* obj)
//*---------------------------------------------------------------------------*
{
RuntimeItem* item = (RuntimeItem* )obj;
// Note here that:
// ITEMTYPE_RUNTIME is my own typing
// ID_RUNTIMEITEM is the plugin ID for the class (just needs to be unique, not even a properly registered plugin)
if (item->IsTypeOf(ITEMTYPE_RUNTIME)) return ID_RUNTIMEITEM;
return NOTOK;
}
//*---------------------------------------------------------------------------*
LONG AcceptDragObject(void* root, void* userdata, void* obj, LONG dragtype, void* dragobject, Bool& bAllowCopy)
//*---------------------------------------------------------------------------*
{
if (dragtype == ID_RUNTIMEITEM)
{
RuntimeItem* drag = (RuntimeItem* )dragobject;
if (drag->IsTypeOf(ITEMTYPE_RUNTIME))
{
if (((RuntimeItem* )obj)->IsTypeOf(ITEMTYPE_RUNTIME)) return INSERT_BEFORE|INSERT_AFTER;
}
}
return 0;
}
//*---------------------------------------------------------------------------*
void InsertObject(void* root, void* userdata, void* obj, LONG dragtype, void* dragobject, LONG insertmode, Bool bCopy)
//*---------------------------------------------------------------------------*
{
if (dragtype != ID_RUNTIMEITEM) return;
RuntimeItem* drag = (RuntimeItem* )dragobject;
// Supports multi-select via RTFLAGS_SELECTED since AtomArray cannot be used
// RUNTIME *******************************************************
// Rearrange Runtimes in TreeView only
if (drag->IsTypeOf(ITEMTYPE_RUNTIME))
{
if (insertmode == INSERT_BEFORE)
{
RuntimeItem* op = (RuntimeItem* )obj;
// Only allow target position wrt other Runtimes
if (!op->IsTypeOf(ITEMTYPE_RUNTIME)) return;
RuntimeItem* next;
troot = (TreeRoot* )root;
for (drag = troot->GetFirst(); drag; drag = next)
{
next = drag->GetNext();
if (!drag->GetBit(RTFLAGS_SELECTED)) continue;
if (drag == op) continue;
troot->InsertBefore(drag, op);
}
}
else if (insertmode == INSERT_AFTER)
{
RuntimeItem* op = (RuntimeItem* )obj;
// Only allow target position wrt other Runtimes
if (!op->IsTypeOf(ITEMTYPE_RUNTIME)) return;
RuntimeItem* next;
troot = (TreeRoot* )root;
for (drag = troot->GetFirst(); drag; drag = next)
{
next = drag->GetNext();
if (!drag->GetBit(RTFLAGS_SELECTED)) continue;
if (drag == op) continue;
troot->InsertAfter(drag, op);
}
}
}
}