Solved

Drag/Drop in a TListWindow

Posted on 1997-04-07
7
284 Views
Last Modified: 2012-06-27
I have 2 TListWindows in a dialog, one from which items should be dragged, and the 2nd into which the items would be dropped.  How do I setup the controls, the response table entries, and the actual drag code as well as the drop code to make this work!  I'm using BC++5.01 and OWL in a 32 bit environment.  Thanks!
0
Comment
Question by:rlayton
  • 5
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 100 total points
ID: 1162630
Look at the 'draglist' example in the directory:
bc5\examples\owl\classes\draglist
There you will find everything you need.
0
 

Author Comment

by:rlayton
ID: 1162631
You're not going to get off that easy!  I've seen the examples, but I was hoping for something a little more explanatory, as well as a quick-n-dirty explanation of how it all works and interacts.  Any more suggestions?
0
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1162632
First, let me say that the draglist example is very simple for what it does. All the messy details are hidden in Borlands TDragList implementation.
But I shall explain you can make a drag and drop with two windows.
The windows would look something like this:

class DragDropBox : public TListBox
{
public:
//
// private data
//
    TWindow *parent;
    bool dragging;
    bool buttonDown;
    TPoint startPoint;// for checking on dragging in EvMouseMove
    TListBox *dragTarget; // should be initialised later
//
// is called when a drop is taken place in this window. Is called
// by the 'source'-DragDropBox
//
    void doTheDrop(/*all sorts of data*/) { /* your code */ }
//
// constructor, just initialising bool's
//
    DragDropWin(TWindow *p, /* other data */)
    : TListBox(/* other data */),
      dragging(false), buttonDown(false), parent(p)
    { /* your code */ }
//
// mouse functions:
//
    // checks where the mouse is:
    // -1: own window (dragSource)
    //  0: in nowhereland
    //  1: other window (dragTarget)  
    int mouseLocation(TPoint &p)
    {
       TPoint temp(p);
       // first map p to the parents clientArea
       MapWindowPoints(parent, &temp, 1);
       // second, look for the child that has the mouse
       void *handle = parent->ChildWindowFromPoint(temp);
       if (handle == HWindow) return -1;
       else if (handle == dragTarget) return 1;
       else return 0;
    }

    void EvLButtonDown(uint, TPoint &p)
    {
        TListBox::EvLButtonDown(); // let listbox make selection
        SetCapture(); // capture the mouse
        buttonDown = true; dragging = false;
        startPoint = p;
    }

    void EvLButtonUp(uint, TPoint &p)
    {
        ReleaseCapture();
        // restore cursor
        ::SetCursor(::LoadCursor(0, IDC_ARROW));
        if (mouseLocation(p) == 1)
            dragTarget->doTheDrop(/*??*/);
    }

    void EvMouseMove(uint, TPoint& p)
    {
        if (!buttonDown) return;
        if (!dragging)
        {
            if (startPoint == p) return;
            dragging = true;
        }
        int i = mouseLocation(p);
        // load appropiate cursor
        if (i == -1) // 'source' cursor
            ::SetCursor(GetModule()->LoadCursor("YOUR_CURSOR_0"))
        else if (i == 0) // 'invalid' cursor
            ::SetCursor(GetModule()->LoadCursor("YOUR_CURSOR_1"))
        else if (i == -1) // 'drop' cursor
            ::SetCursor(GetModule()->LoadCursor("YOUR_CURSOR_2"))
    }
   
    DECLARE_RESPONSE_TABLE(DragDropBox);
};

DEFINE_RESPONSE_TABLE1(DragDropBox, TListBox)
  EV_WM_LBUTTONDOWN,
  EV_WM_LBUTTONUP,
  EV_WM_MOUSEMOVE,
END_RESPONSE_TABLE;


You would use them in a parent window like this:

DragDropBox ddb0 = new DragDropBox(this, /* all kind of data */);
DragDropBox ddb1 = new DragDropBox(this, /* all kind of data */);
ddb0->dropTarget = ddb1;
ddb1->dropTarget = ddb0;

If a drop occurs the function doTheDrop is called. (You can do a
item-move or item-copy by using the TListBox functions)
If a drag is going on is detected by the mousefunctions.
EvMouseMove updates the cursor. It uses the private data 'dragging', 'buttonDown' and 'startPoint' for detecting the dragging.

We have to capture the mouse because we can't change all the windows that we fly over while dragging. (to set the mouse)
The function mouseLocation does the tricky job of seaching the child-window wich contains the mouse.

Finally: I didn't compile this code, so you may have to tamper a bit with it to get it working but it's basicaly correct.
This is as simple as it can get, you could expand this for multiple window's and dragging of items. Hopefully it gives you some insight in TDragList.
Still I must recommend TDragList, it's simple to use and quite powerfull.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:rlayton
ID: 1162633
Thanks, That's what I like to see!
0
 

Author Comment

by:rlayton
ID: 1162634
Thanks, That's what I like to see!
0
 

Author Comment

by:rlayton
ID: 1162635
Thanks, That's what I like to see!
0
 

Author Comment

by:rlayton
ID: 1162636
Thanks, That's what I like to see!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now