[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Drag/Drop in a TListWindow

Posted on 1997-04-07
7
Medium Priority
?
299 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 200 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
Technology Partners: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

649 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