Posted: Tue May 02, 2006 5:39 pm
Here's what I was trying to do, but was hoping to avoid the api in this case.
Drag and drop which avoids the problematic ImageList_ dragging functions which seem not to work properly on many setups.
It's very rough and ready at the moment.
Next step is to integrate this into EasyVENT.
Drag and drop which avoids the problematic ImageList_ dragging functions which seem not to work properly on many setups.
Code: Select all
;Drag and drop the contents of gadgets.
;This can be changed to accommodate just about any kind of gadget.
;By Stephen Rodriguez.
;Purebasic 4 beta 11. Tested on Win XP only.
#text1=1
#text2=2
#text3=3
dragfrom=-1
x=-1:y=-1
rc.rect
If OpenWindow(0, 0, 0, 600, 300,"Drag and drop between gadgets.", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If CreateGadgetList(WindowID(0))
TextGadget(#text1,25,20,180,20, "Drag between any of these gadgets")
StringGadget(#text2,25,50,180,20, "Drop on to any of these gadgets")
ListViewGadget(#text3, 25, 90, 250, 120)
For a = 0 To 3
AddGadgetItem (#text3, -1, "Item " + Str(a)) ; define listview content
Next
Repeat
ev=WaitWindowEvent()
Select ev
Case #WM_LBUTTONDOWN
dragfrom=GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0),WindowMouseY(0)))
If dragfrom>=#text1 And dragfrom<=#text3
SendMessage_(GadgetID(dragfrom),#WM_SETREDRAW,0,0)
text$=GetGadgetText(dragfrom)
;Create an image for the text.
;First calculate the required dimensions.
wdc=GetDC_(WindowID(0))
SetTextAlign_(wdc,#TA_LEFT|#TA_TOP|#TA_NOUPDATECP)
rc\right=1
rc\bottom=1
DrawText_(wdc,text$,Len(text$),rc.rect,#DT_CALCRECT)
im=CreateImage(#PB_Any,rc\right,rc\bottom)
hdc=StartDrawing(ImageOutput(im))
SetTextAlign_(hDC,#TA_LEFT|#TA_TOP|#TA_NOUPDATECP)
DrawText_(hdc,text$,Len(text$),rc.rect,#DT_WORDBREAK)
StopDrawing()
IsDragging=#True
SetCapture_(WindowID(0))
ShowCursor_(0)
EndIf
Case #WM_MOUSEMOVE
If IsDragging
;First restore any background.
hdc=StartDrawing(ImageOutput(im))
If x>-1 And y>-1
BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT)
x=-1:y=-1
EndIf
;Now redraw image.
tempx=WindowMouseX(0) : tempy=WindowMouseY(0)
If tempx>0 And tempy>0
;Debug "("+Str(x)+", "+Str(y)+")"
x=tempx:y=tempy
BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT)
EndIf
StopDrawing()
EndIf
Case #WM_LBUTTONUP
If IsDragging
If x>-1 And y>-1
hdc=StartDrawing(ImageOutput(im))
BitBlt_(wdc,x,y,ImageWidth(im),ImageHeight(im),hdc,0,0,#SRCINVERT)
StopDrawing()
EndIf
SendMessage_(GadgetID(dragfrom),#WM_SETREDRAW,1,0)
ReleaseCapture_()
ShowCursor_(#True)
ReleaseDC_(WindowID(0),wdc)
FreeImage(im)
; FreeGadget(templisticon)
IsDragging = #False
x=-1 : y=-1
;Check to see if the text was dropped onto another text gadget.
dragto=GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0),WindowMouseY(0)))
Select dragto
Case #text1, #text2
;Drop the text onto the targetted gadget.
SetGadgetText(dragto, GetGadgetText(dragfrom))
Case #text3 ;ListView gadget.
AddGadgetItem (dragto, -1, GetGadgetText(dragfrom))
EndSelect
EndIf
EndSelect
Until ev = #PB_Event_CloseWindow
EndIf
EndIf
End
Next step is to integrate this into EasyVENT.