Solved

Drag/Drop in a TListWindow

Posted on 1997-04-07
7
291 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
White board coding practice 3 90
Android development question 2 53
Are the two lines the same? If not what is the difference? 2 22
C++ Code Issue 4 23
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

809 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