Using event handlers - (obsolete version)
Could two of the event names please be changed?
Change #OnEndDragItem to #OnDragItemEnd
Change #OnStartDragItem to #OnDragItemStart
This will help in two ways: It will keep all the #OnDrag... events together in alphabetical order (making it simpler to select the correct event to use) and it is also more consistent with event names:
#OnDragItemOver
#OnMenuItemSelect
I also think that #OnSelectItem should be changed to #OnItemSelect for consistency with #OnMenuItemSelect
Change #OnEndDragItem to #OnDragItemEnd
Change #OnStartDragItem to #OnDragItemStart
This will help in two ways: It will keep all the #OnDrag... events together in alphabetical order (making it simpler to select the correct event to use) and it is also more consistent with event names:
#OnDragItemOver
#OnMenuItemSelect
I also think that #OnSelectItem should be changed to #OnItemSelect for consistency with #OnMenuItemSelect
Anthony Jordan
On running General demo.pb or Treegadget demo.pb, I get an error "Invalid memory access" from line 563 of EasyVENT.pbiwithin the defprocessing: section.
This happened when I clicked the 'OK' button in the dialogue box that resulted from clicking the window close button.
I have not yet tried any of the other demo programs.
In case it is relevant, I am running Windows ME and PB4 beta 11.
Code: Select all
result = CallWindowProc_(GetProp_(hwnd, @text$), hWnd, uMsg, wParam, lParam)
This happened when I clicked the 'OK' button in the dialogue box that resulted from clicking the window close button.
I have not yet tried any of the other demo programs.
In case it is relevant, I am running Windows ME and PB4 beta 11.
Anthony Jordan
Fixed. I think!
I need someone to test this out on Win ME.

Done. Excellent suggestions, thanks akj.Could two of the event names please be changed?
Change #OnEndDragItem to #OnDragItemEnd
Change #OnStartDragItem to #OnDragItemStart
This will help in two ways: It will keep all the #OnDrag... events together in alphabetical order (making it simpler to select the correct event to use) and it is also more consistent with event names:
#OnDragItemOver
#OnMenuItemSelect
I also think that #OnSelectItem should be changed to #OnItemSelect for consistency with #OnMenuItemSelect
I may look like a mule, but I'm not a complete ass.
Update: 3rd May 2006.
Have added drag and drop which should (
) work from most gadgets. You can drag multiple items, single items or the entire contents of gadgets (text only at the moment). No longer just for ListIcon gadgets.
Note that this does not use OLE (too complex!
) or the ImageList drag functions as these seem not to work properly on some setups.
4 drag and drop demo programs included.
Note also that because of the way I've set this up, dragging of images would be a trivial addition, but it's one for a later date if anyone needs such functionality later on.
The full list of supported events runs as follows:
**REMOVED - see post below.**
Regards.
Have added drag and drop which should (

Note that this does not use OLE (too complex!

4 drag and drop demo programs included.
Note also that because of the way I've set this up, dragging of images would be a trivial addition, but it's one for a later date if anyone needs such functionality later on.
The full list of supported events runs as follows:
**REMOVED - see post below.**
Regards.
I may look like a mule, but I'm not a complete ass.
**Ammendment + bug fix.** 6th May 2006.
Apologies for having to upload yet another new version.
A big application I am working on threw up a limitation of EasyVENT. The upshot is that the event #OnItemSelect has been removed and replaced with two separate events; #OnItemSelecting and #OnItemSelected.
The former event allows certain selections (tree gadgets, panel gadgets) to be refused etc. The latter fires after the selections have been processed by the system (this works for a lot of gadgets) and offers a little more freedom in certain circumstances.
The list of events now runs as follows:
REMOVED - see post below.
See first post for the download link.
Regards.
Apologies for having to upload yet another new version.
A big application I am working on threw up a limitation of EasyVENT. The upshot is that the event #OnItemSelect has been removed and replaced with two separate events; #OnItemSelecting and #OnItemSelected.
The former event allows certain selections (tree gadgets, panel gadgets) to be refused etc. The latter fires after the selections have been processed by the system (this works for a lot of gadgets) and offers a little more freedom in certain circumstances.
The list of events now runs as follows:
REMOVED - see post below.
See first post for the download link.
Regards.
Last edited by srod on Sun Jul 02, 2006 5:15 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
15th May 2006 - Small update + huge memory leak fixed!
This is definitely the last update!
Have added one more event; #OnSetCursor, because I needed a way of quickly changing the cursor for all windows/controls in an application etc. (see above post for full list of events).
I wouldn't have posted, but spotted a quite horrendous memory leak which is now plugged. My apologies. See the first post for the download link.
This is definitely the last update!

Have added one more event; #OnSetCursor, because I needed a way of quickly changing the cursor for all windows/controls in an application etc. (see above post for full list of events).
I wouldn't have posted, but spotted a quite horrendous memory leak which is now plugged. My apologies. See the first post for the download link.
I may look like a mule, but I'm not a complete ass.
thanks for sharing this good lib 

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Thanks josku_x.
The bug fix above re: win ME has been confirmed to be working okay, so touch wood there!
Any more bugs and I'll throw the whole job lot out the window!
Actually, the lib is getting quite a hammering in my current app (which is a big 'un) and it seems to be holding up very well - for the moment at least!
The bug fix above re: win ME has been confirmed to be working okay, so touch wood there!
Any more bugs and I'll throw the whole job lot out the window!

Actually, the lib is getting quite a hammering in my current app (which is a big 'un) and it seems to be holding up very well - for the moment at least!
I may look like a mule, but I'm not a complete ass.
thank you srod for sharing this great procs.
It´s perfect except two things:
One very little blemish is, the cursor getting the icon "forbidden" for
a moment, if drag-event is enabled and the mousebutton is coming up
(in TreeGadget and List-Gadgets).
I could fix this by changing EasyVENT.pbi to
and removed (line 327)
and added
before
oldCursor is set to static in the procedure (EventDespatcher...).
This should bring back the cursor, even if not the default one is used (didn´t test it).
The other thing is, EasyVENT is eating Events of a ListViewGadget
if enabling Drag-Events for it. Demo 5 with ListView instead of
ListIcon demonstrates this behavior:
The only fix I could find for this, is using a ListIconGadget instead :roll: .
Maybe you know a better solution...
schic
It´s perfect except two things:
One very little blemish is, the cursor getting the icon "forbidden" for
a moment, if drag-event is enabled and the mousebutton is coming up
(in TreeGadget and List-Gadgets).
I could fix this by changing EasyVENT.pbi
Code: Select all
If EVENT_globals\gCursorCount=0
ShowCursor_(1)
EVENT_globals\gCursorCount=1
EndIf
Code: Select all
If EVENT_globals\gCursorCount=0
EVENT_globals\gCursorCount=1
EVENT_globals\gCursor=SetCursor_(oldCursor) ;## changed
ShowCursor_(1)
EndIf
Code: Select all
SetCursor_(EVENT_globals\gCursor)
Code: Select all
oldCursor=GetCursor_()
Code: Select all
LoadCursor_(0,#IDC_NO)
This should bring back the cursor, even if not the default one is used (didn´t test it).
The other thing is, EasyVENT is eating Events of a ListViewGadget
if enabling Drag-Events for it. Demo 5 with ListView instead of
ListIcon demonstrates this behavior:
Code: Select all
; run in Debug-Mode
XIncludeFile "EasyVENT.pbi"
;*********************************************************************************
Declare.l DragOverWindow(*sender.PB_Sender)
Declare.l DragItem(*sender.PB_Sender)
Declare.l DropItem(*sender.PB_Sender)
Declare.l DragOver(*sender.PB_Sender)
Declare.l DragItemTree(*sender.PB_Sender)
Declare HighLightSelection(hwnd, state)
;Define Event.l, i, WindowID, GadgetID, GadgetEvent
Global gTargetitem ;Denotes which item we are dropping on.
Global DragSource
OpenWindow(0, 100, 100, 330, 200, "EasyVENT drag and drop items demo 4.", #PB_Window_SystemMenu |#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ListViewGadget(1, 0, 0, 150, 150)
ListIconGadget(2,170,10,150,150, "Drag to", 120)
For i = 1 To 10
AddGadgetItem(1, -1, "Gadget 1 - item " + Str(i))
; AddGadgetItem(0, -1, "Gadget 0 - item " + Str(i))
If i < 6
AddGadgetItem(2, -1, "Gadget 2 - item " + Str(i))
EndIf
Next
;Set event handlers.
SetEventHandler(GadgetID(1), #OnDragItemStart, @DragItem()) ; rem this line and debug message below does work otherwise not
SetEventHandler(GadgetID(2), #OnDragItemOver, @DragOver())
SetEventHandler(GadgetID(2), #OnDragItemEnd, @DropItem())
SetEventHandler(WindowID(0), #OnDragItemOver, @DragOverWindow())
SetActiveGadget(1)
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
GadgetEvent = EventType()
If Event = #PB_Event_Gadget
If GadgetID = 1
Debug GetGadgetState(1)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
End
;*********************************************************************************
; EVENT HANDLERS
;*********************************************************************************
;The following ensures that any highlighted item in the target control is removed
;whenever the cursor leaves the control.
Procedure.l DragOverWindow(*sender.PB_Sender)
;Remove any selection highlight already in place.
HighLightSelection(GadgetID(2), 0)
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
;Here we simply return #PB_ProcessPureBasicEvents to enable the drag.
Procedure.l DragItem(*sender.PB_Sender)
If GetActiveGadget()=1 And GetGadgetState(1)>=0
DragSource = 1
*sender\Text$=GetGadgetText(1)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
;Since the following handles only one gadget, we need not check which control etc.
Procedure.l DropItem(*sender.PB_Sender)
;First remove any selection highlight already in place.
HighLightSelection(*sender\hwnd, 0)
If DragSource = 1
AddGadgetItem(2,gTargetitem, GetGadgetText(1)) ;Copy item to ListView.
RemoveGadgetItem(1,*sender\item) ;Remove item from ListIcon.
ElseIf DragSource = 0
AddGadgetItem(2,gTargetitem, GetGadgetText(0)) ;Copy item to ListView.
RemoveGadgetItem(1,*sender\item) ;Remove item from ListIcon.
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure.l DragOver(*sender.PB_Sender)
Protected hittestinfo.LV_HITTESTINFO
;First remove any selection highlight already in place.
HighLightSelection(*sender\hwnd, 0)
;Find which item we are currently hovering over. We need an API call for this.
hittestinfo\pt\x = *sender\MouseX
hittestinfo\pt\y = *sender\MouseY
gTargetitem = SendMessage_(*sender\hwnd, #LVM_HITTEST, 0, @hittestinfo)
;Highlight the new item
If gTargetitem<>-1
HighLightSelection(*sender\hwnd, #LVIS_DROPHILITED)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
;*********************************************************************************
; END OF EVENT HANDLERS
;*********************************************************************************
;The following utility either highlights the target item or removes the highlight etc.
Procedure HighLightSelection(hwnd, state)
Protected pitem.LV_ITEM
pitem\mask = #LVIF_STATE
pitem\iItem = gTargetitem
pitem\state = state
pitem\stateMask = #LVIS_DROPHILITED
SendMessage_(hwnd, #LVM_SETITEM, 0, @pitem)
RedrawWindow_(hwnd, 0, 0, #RDW_UPDATENOW)
EndProcedure
Maybe you know a better solution...
schic