Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Drag and Drop between instances [FEATURE REQUEST]
Re: Drag and Drop between instances [FEATURE REQUEST] [message #30140 is a reply to message #30009] |
Sat, 11 December 2010 10:34 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
I have added reference/DragAndDrop example:
#include "CtrlLib/CtrlLib.h"
using namespace Upp;
const char *MyDnDName = "MyReferenceDragAndDropExample";
struct MyApp : TopWindow {
TreeCtrl tree;
typedef MyApp CLASSNAME;
void DropInsert(int parent, int ii, PasteClip& d)
{
tree.AdjustAction(parent, d);
if(d.Accept(MyDnDName)) {
tree.SetCursor(tree.Insert(parent, ii, Image(), ~d));
tree.SetFocus();
}
}
void Drag()
{
if(!tree.IsCursor())
return;
int id = tree.GetCursor();
String text = tree.Get();
Size isz = GetTextSize(text.ToWString(), StdFont());
ImageDraw iw(isz);
iw.DrawRect(isz, White);
iw.DrawText(0, 0, text);
VectorMap<String, ClipData> clip;
clip.Add(MyDnDName, text);
if(DoDragAndDrop(clip, iw) == DND_MOVE)
tree.Remove(id);
}
MyApp() {
Add(tree.SizePos());
Vector<int> parent, parent2;
parent.Add(0);
tree.SetRoot(Image(), "The Tree");
for(int i = 1; i < 10000; i++) {
parent.Add(tree.Add(parent[rand() % parent.GetCount()], Image(),
FormatIntRoman(i, true)));
if((rand() & 3) == 0)
tree.Open(parent.Top());
}
tree.Open(0);
tree.WhenDropInsert = THISBACK(DropInsert);
tree.WhenDrag = THISBACK(Drag);
Sizeable();
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
Frankly, there are more details to care about, so we might want yet another example with even more low-level D&D (and some fine dics about D&D would be fine as well, right?), but as first iteration this might be helpful.
Mirek
|
|
|
Goto Forum:
Current Time: Mon May 06 00:33:58 CEST 2024
Total time taken to generate the page: 0.02104 seconds
|