Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Treeview drag and drop

 Post Reply Post Reply
Author
Message
eldiren View Drop Down
Member
Member


Joined: 2014 Sep 18
Online Status: Offline
Posts: 46
Post Options Post Options   Quote eldiren Quote  Post ReplyReply Direct Link To This Post Topic: Treeview drag and drop
    Posted: 2017 Nov 12 at 2:44pm

User Information:

Cinema 4D Version:   R18 
Platform:   Windows  ;   Mac OSX  ; 
Language(s):     C++  ;   

---------

I've been going down the rabbit hole of trying to make my treeview act more like the object manager and I've run into an understanding block. I've seen in other forum posts AcceptDragObject as one of the functions I need to implement. Implementing that does give me gold lines in my Treeview to insert objects in. My specific treeview is static though, I need that functionality where you drag a Meterial from the Materials palette over to an object in the Object Manager and it gives a plus icon. I'd also like to drag tags the same way. 

My question is how to enable these and check that the objects inside the dragobject are what I want?
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1540
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Nov 13 at 10:01am
Hi,

first of all, I need to mention that the Object Manager is actually not a TreeView CustomGUI. There's quite some stuff hard coded internally, so you may not completely succeed in imitating it completely.

But for the drag and drop part (with one small exception) there shouldn't be an issue.

You are already looking at the correct function: AcceptDragObject()
With the return value, you can not only specify, that you will accept or refuse a (or multiple) dragged entities, but also the type of mouse pointer Cinema 4D will display.
By returning one or multiple of the INSERT flags, you will get the "golden lines" to insert objects. But there is another flag, which may be returned additionally or also alone: ACCEPT_DRAG_OBJECT_FORCE_COPY. This will add the "plus" to the mouse pointer. If not combined with any INSERT flags, it's only possible to append to the list.)

So for example, when a material is dragged onto an object, you'd have a combination of INSERT_UNDER and ACCEPT_DRAG_OBJECT_FORCE_COPY. And here's the drawback, the golden line does still appear, and it doesn't in OM.

Then you also want to react to the type of the dragged entities. The dragdata is also passed to AcceptDragObject(). Depending on parameter type, you can inspect the drag data, before returning any of the above flags. For example, all C4DAtom derived entities (objects, materials, tags,...) get dragged as an AtomArray (DRAGTYPE_ATOMARRAY).

So you can do something like this:
Int32 MyTreeViewFuncs::AcceptDragObject(void* root, void* ud, void* obj, Int32 type, void* dragData, Bool& allowCopy)
{
switch (type)
{
case DRAGTYPE_ATOMARRAY:
{
AtomArray* const arr = static_cast<AtomArray*>(dragData);
if (!arr)
return 0;

const Int32 count = arr->GetCount();
for (Int32 i = 0; i < count; ++i)
{
C4DAtom* const atom = arr->GetIndex(i);
if (!atom || !atom->IsInstanceOf(Obase))
return 0; // do not accept objects
}
return INSERT_UNDER | ACCEPT_DRAG_OBJECT_FORCE_COPY;
}

default:
break;
}
return 0;
}



Edited by Andreas Block - 2017 Nov 13 at 10:03am
Cheers,
Andreas
SDK Support Engineer
Back to Top
eldiren View Drop Down
Member
Member


Joined: 2014 Sep 18
Online Status: Offline
Posts: 46
Post Options Post Options   Quote eldiren Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Nov 14 at 10:57pm
That works thanks. A related question, I have two columns in this treeview(plus the name of the item itself). When I drag I'd like a piece of data to occupy one of the two columns. Preferably the user would drag and drop to the column they want but that'd involve a lot of drag and drop position checking I imagine. My idea was on drop a context popup(kinda like a right click menu) would ask them what type of column data it was that they were dropping. 

Is it possible to have a context pop up like that with the treeview?
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1540
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Nov 15 at 9:10am
Sure, that's actually quite easy. Just take a look at ShowPopupMenu() and use it in InsertObject().
Cheers,
Andreas
SDK Support Engineer
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.