Solved

Drag/Drop in a TListWindow

Posted on 1997-04-07
7
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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