ultimatepp/reference/DragAndDrop/main.cpp
cxl 206f1e5c71 reference: DragAndDrop - d&d between two instances
git-svn-id: svn://ultimatepp.org/upp/trunk@2903 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2010-12-11 09:43:47 +00:00

60 lines
1.3 KiB
C++

#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();
}