mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
reference: low-level Drag & Drop examples
git-svn-id: svn://ultimatepp.org/upp/trunk@4025 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dc1dacb9ad
commit
d12bcd2d97
6 changed files with 218 additions and 0 deletions
11
reference/DragAndDrop1/DragAndDrop1.upp
Normal file
11
reference/DragAndDrop1/DragAndDrop1.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Low-level drag and drop operation\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SSE2";
|
||||
|
||||
4
reference/DragAndDrop1/init
Normal file
4
reference/DragAndDrop1/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _DragAndDrop1_icpp_init_stub
|
||||
#define _DragAndDrop1_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
91
reference/DragAndDrop1/main.cpp
Normal file
91
reference/DragAndDrop1/main.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct MyAppData {
|
||||
String text;
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct MyApp : TopWindow {
|
||||
Point pos;
|
||||
MyAppData data;
|
||||
Point dragpos;
|
||||
|
||||
virtual void CancelMode();
|
||||
virtual void Paint(Draw& w);
|
||||
virtual void DragAndDrop(Point p, PasteClip& clip);
|
||||
virtual void DragLeave();
|
||||
virtual void LeftDrag(Point p, dword keyflags);
|
||||
|
||||
MyApp();
|
||||
};
|
||||
|
||||
void MyApp::CancelMode()
|
||||
{
|
||||
dragpos = Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MyApp::DragAndDrop(Point p, PasteClip& clip)
|
||||
{
|
||||
if(clip.Accept("MyAppData")) {
|
||||
String bin = clip;
|
||||
if(bin.GetLength() > sizeof(Color)) { // prudent check
|
||||
pos = p;
|
||||
memcpy(&data.color, ~bin, sizeof(Color));
|
||||
data.text = bin.Mid(sizeof(Color));
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
if(AcceptText(clip)) {
|
||||
pos = p;
|
||||
data.text = GetString(clip);
|
||||
}
|
||||
dragpos = clip.IsAccepted() ? p : Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MyApp::DragLeave()
|
||||
{
|
||||
dragpos = Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MyApp::LeftDrag(Point p, dword keyflags)
|
||||
{
|
||||
String bin;
|
||||
bin.Cat((byte *)&data.color, sizeof(data.color));
|
||||
bin.Cat(data.text);
|
||||
VectorMap<String, ClipData> d;
|
||||
d.Add("MyAppData", bin);
|
||||
Append(d, data.text);
|
||||
Size sz(128, 64);
|
||||
ImageDraw iw(sz);
|
||||
iw.DrawRect(sz, Black());
|
||||
iw.Alpha().DrawRect(sz, Black());
|
||||
iw.Alpha().DrawText(0, 0, data.text, Courier(14), White());
|
||||
DoDragAndDrop(d, iw);
|
||||
}
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
w.DrawText(pos.x, pos.y, data.text, StdFont(), data.color);
|
||||
if(!IsNull(dragpos))
|
||||
w.DrawRect(RectC(dragpos.x - 1, dragpos.y - 1, 3, 3), LtBlue);
|
||||
}
|
||||
|
||||
MyApp::MyApp()
|
||||
{
|
||||
data.text = FormatIntRoman(Random(2000));
|
||||
data.color = Color(Random() & 127, Random() & 127, Random() & 127);
|
||||
pos = Point(10, 10);
|
||||
SetRect(0, 0, 500, 100);
|
||||
dragpos = Null;
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Run();
|
||||
}
|
||||
11
reference/DragAndDrop2/DragAndDrop2.upp
Normal file
11
reference/DragAndDrop2/DragAndDrop2.upp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
description "Low-level drag and drop operation, late rendering using GetSelectionData\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI SSE2";
|
||||
|
||||
4
reference/DragAndDrop2/init
Normal file
4
reference/DragAndDrop2/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _DragAndDrop2_icpp_init_stub
|
||||
#define _DragAndDrop2_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
97
reference/DragAndDrop2/main.cpp
Normal file
97
reference/DragAndDrop2/main.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct MyAppData {
|
||||
String text;
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct MyApp : TopWindow {
|
||||
Point pos;
|
||||
MyAppData data;
|
||||
Point dragpos;
|
||||
|
||||
virtual void CancelMode();
|
||||
virtual void Paint(Draw& w);
|
||||
virtual void DragAndDrop(Point p, PasteClip& clip);
|
||||
virtual void DragLeave();
|
||||
virtual void LeftDrag(Point p, dword keyflags);
|
||||
virtual String GetSelectionData(const String& fmt) const;
|
||||
|
||||
MyApp();
|
||||
};
|
||||
|
||||
void MyApp::CancelMode()
|
||||
{
|
||||
dragpos = Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MyApp::DragAndDrop(Point p, PasteClip& clip)
|
||||
{
|
||||
if(clip.Accept("MyAppData")) {
|
||||
String bin = clip;
|
||||
if(bin.GetLength() > sizeof(Color)) { // prudent check
|
||||
pos = p;
|
||||
memcpy(&data.color, ~bin, sizeof(Color));
|
||||
data.text = bin.Mid(sizeof(Color));
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
if(AcceptText(clip)) {
|
||||
pos = p;
|
||||
data.text = GetString(clip);
|
||||
}
|
||||
dragpos = clip.IsAccepted() ? p : Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void MyApp::DragLeave()
|
||||
{
|
||||
dragpos = Null;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
String MyApp::GetSelectionData(const String& fmt) const
|
||||
{
|
||||
if(fmt == "MyAppData") {
|
||||
String bin;
|
||||
bin.Cat((byte *)&data.color, sizeof(data.color));
|
||||
bin.Cat(data.text);
|
||||
return bin;
|
||||
}
|
||||
return GetTextClip(data.text, fmt);
|
||||
}
|
||||
|
||||
void MyApp::LeftDrag(Point p, dword keyflags)
|
||||
{
|
||||
Size sz(128, 64);
|
||||
ImageDraw iw(sz);
|
||||
iw.DrawRect(sz, Black());
|
||||
iw.Alpha().DrawRect(sz, Black());
|
||||
iw.Alpha().DrawText(0, 0, data.text, Courier(14), White());
|
||||
DoDragAndDrop(String("MyAppData;") + ClipFmtsText(), iw);
|
||||
}
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
w.DrawText(pos.x, pos.y, data.text, StdFont(), data.color);
|
||||
if(!IsNull(dragpos))
|
||||
w.DrawRect(RectC(dragpos.x - 1, dragpos.y - 1, 3, 3), LtBlue);
|
||||
}
|
||||
|
||||
MyApp::MyApp()
|
||||
{
|
||||
data.text = FormatIntRoman(Random(2000));
|
||||
data.color = Color(Random() & 127, Random() & 127, Random() & 127);
|
||||
pos = Point(10, 10);
|
||||
SetRect(0, 0, 500, 100);
|
||||
dragpos = Null;
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue