Solved

Drag/Drop in a TListWindow

Posted on 1997-04-07
7
289 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

813 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

13 Experts available now in Live!

Get 1:1 Help Now