Platforms to show: All Mac Windows Linux Cross-Platform
/Mac/Drag and Drop/Drag and Drop with CGImage
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /Mac/Drag and Drop/Drag and Drop with CGImage
This example is the version from Sun, 21th Jul 2007.
Notes: Last modified: Sun, 21th Jul 2007
Feedback.
Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /Mac/Drag and Drop/Drag and Drop with CGImage
This example is the version from Sun, 21th Jul 2007.
Notes: Last modified: Sun, 21th Jul 2007
Class SourceWindow
Inherits Window
// Controls
ControlInstance
Sub Open() Handles Event
dim p as Picture
dim g as Graphics
p=NewPicture(100,100,32)
g=p.Graphics
g.ForeColor=rgb(255,0,0)
g.FillOval 0,0,100,100
g=p.mask.Graphics
g.ForeColor=rgb(255,255,255)
g.FillRect 0,0,100,100
g.ForeColor=rgb(0,0,0)
g.FillOval 0,0,100,100
g.ForeColor=rgb(255,255,255)
g.FillOval 30,30,40,40
me.Backdrop=p
End Sub
Sub MouseDrag(X As Integer, Y As Integer) Handles Event
dim d as DragItemMBS
dim ci as CGImageMBS
dim m,p as Picture // CGImage needs a mask
dim TextType as integer
dim xx,yy as integer
TextType=OSTypeFromStringMBS("TEXT")
d=new DragItemMBS
if d.Create then
m=NewPicture(100,100,32)
m.Graphics.ForeColor=rgb(0,0,0)
m.Graphics.FillOval 0,0,100,100
m.Graphics.ForeColor=rgb(255,255,255)
m.Graphics.FillOval 30,30,40,40
p=NewPicture(100,100,32)
p.Graphics.ForeColor=rgb(0,0,255)
p.Graphics.FillOval 0,0,100,100
ci=CGCreateImageMBS(p,m)
if ci=nil then
MsgBox "ci=nil!"
end if
// if private, the Finder will not accept it.
d.AddFlavorDataAsString(1,TextType,"Hello World!",CheckBox1.Value)
xx=me.Window.left+me.left
yy=me.Window.top+me.top
'Graphics.DrawCGImageXYMBS ci,200,200
'd.SetDragImage M,XX,YY,0
d.SetDragCGImage ci.Handle,-x,-y,0
d.StartDrag xx+x,yy+y,0,xx,yy,100,100
else
MsgBox "Failed to create drag item."
end if
End Sub
Function MouseDown(X As Integer, Y As Integer) As Boolean Handles Event
Return true
End Function
Sub Paint(g As Graphics) Handles Event
End Sub
End ControlInstance
ControlInstance
End ControlInstance
ControlInstance
End ControlInstance
// Event implementations
Sub MouseDrag(X As Integer, Y As Integer)
End Sub
Sub Close()
End Sub
Sub Open()
DestWindow.left=me.left+me.Width+50
DestWindow.top=me.top
DestWindow.Show
me.Show
End Sub
End Class
Class DestWindow
Inherits Window
// Controls
ControlInstance
Sub Open() Handles Event
End Sub
End ControlInstance
// Properties
Protected Dim re as myreceiver
Protected Dim tr as mytracking
// Event implementations
Sub Open()
tr=new MyTracking
tr.w=self
if not tr.AttachWindow(self) then
MsgBox "Failed to attach Tracker to the window."
end if
re=new MyReceiver
re.w=self
if not re.AttachWindow(self) then
MsgBox "Failed to attach Receiver to the window."
end if
End Sub
End Class
Class MyTracking
Inherits DragTrackerMBS
// Properties
Dim w as destwindow
// Event implementations
Function Dragging(message as integer, drag as DragItemMBS) As boolean
if message=2 then // Enter Window
w.HasBackColor=true
w.Refresh
elseif message=4 or message=5 then // Leave Window
w.HasBackColor=false
w.Refresh
end if
Return true
End Function
End Class
Class MyReceiver
Inherits DragReceiverMBS
// Properties
Dim w as destwindow
// Event implementations
Function Received(drag as DragItemMBS) As boolean
dim i,c,id as integer
dim flags,Text as integer
dim s as string
c=drag.ItemCount
for i=1 to c
id=drag.ItemID(i)
IF drag.FlavorTextAvailable(id) then
DestWindow.StaticText1.text=drag.FlavorText(id)
Return true
end if
if drag.FlavorPictureAvailable(id) then
DestWindow.Backdrop=drag.FlavorPicture(id)
return true
end if
next
Return false
End Function
End Class
Class App
Inherits Application
End Class
See also:
Links
MBS Realbasic tutorial videos - Christians Software aus Nickenich