Page 2 of 9

Posted: Thu Apr 13, 2006 2:22 pm
by srod
Works okay here.

The cursor is hidden as soon as the drag operation is initiated.

Strange...

Posted: Sat Apr 22, 2006 2:55 pm
by srod
*Possible memory leak fixed* 22/04/2006.

Posted: Sun Apr 23, 2006 7:21 pm
by 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

Posted: Sun Apr 23, 2006 8:17 pm
by akj
On running General demo.pb or Treegadget demo.pb, I get an error "Invalid memory access" from line 563 of EasyVENT.pbi

Code: Select all

result = CallWindowProc_(GetProp_(hwnd, @text$), hWnd, uMsg, wParam, lParam)
within 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.

Posted: Sun Apr 23, 2006 10:27 pm
by srod
Fixed. I think! :D I need someone to test this out on Win ME.
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
Done. Excellent suggestions, thanks akj.

Posted: Wed May 03, 2006 11:29 pm
by srod
Update: 3rd May 2006.

Have added drag and drop which should ( :lol: ) 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! :D ) 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.

Posted: Sat May 06, 2006 2:09 am
by srod
**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.

Posted: Mon May 15, 2006 8:24 pm
by srod
15th May 2006 - Small update + huge memory leak fixed!

This is definitely the last update! :D

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.

Posted: Wed May 24, 2006 5:25 pm
by ts-soft
thanks for sharing this good lib :D

Posted: Wed May 24, 2006 6:05 pm
by srod
You're welcome ts-soft.

Posted: Wed May 24, 2006 11:09 pm
by storck
Thank you srod!

You have made my life so much easier. :D

// Storck

Posted: Wed May 24, 2006 11:13 pm
by srod
You're welcome storck.

Posted: Wed May 24, 2006 11:23 pm
by josku_x
Really nice stuff. If I have some time, I can test it out with WinME.
srod wrote:Apologies for having to upload yet another new version.
The more, the better :D

Posted: Wed May 24, 2006 11:30 pm
by srod
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! :D

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!

Posted: Fri May 26, 2006 2:40 pm
by schic
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

Code: Select all

        If EVENT_globals\gCursorCount=0
          ShowCursor_(1)
          EVENT_globals\gCursorCount=1
        EndIf
to

Code: Select all

        If EVENT_globals\gCursorCount=0
          EVENT_globals\gCursorCount=1
          EVENT_globals\gCursor=SetCursor_(oldCursor) ;## changed
          ShowCursor_(1) 
        EndIf
and removed (line 327)

Code: Select all

SetCursor_(EVENT_globals\gCursor)
and added

Code: Select all

oldCursor=GetCursor_()
before

Code: Select all

LoadCursor_(0,#IDC_NO)
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:

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
The only fix I could find for this, is using a ListIconGadget instead :roll: .
Maybe you know a better solution...

schic