Silverfrost Forums

Welcome to our forums

Drag and Drop callback behavior

25 Apr 2021 2:39 #27625

I use Drap-and-drop in several areas, and it works great, allowing me to drag large numbers of files for processing. I 'ingest' the files and add them to a list, then rebuild the list-view. No problems

I ran across this as I added a functionality. In this new application, I want to take a dropped file, add it to an internal list, then rebuild the display using the rebuilt list. I do this because it will be rare for the user to be using this feature, so be building the display window with the updated list is not a big deal.

But I can't do it. When I attempt to return a negative value for the callback, it is 'ignored' (more later). The code below illustrates this. Two variables, one counting the number of 'drops', the other counting the rebuilds. On every third drop, it attempts to return a -1. It does not rebuild the window, and more oddly, the window is not updated. Click the 'X' to close the window, and it gets rebuilt using the proper return value!

So, attempting to return from a drag-and-drop callback with the return value to also closes the parent window fails. But a manual closing of that window returns the previous attempts callback value, and the window is rebuilt.

This occurs both in 32 and 64 bit

	winapp
        program main
        use mswin
        integer,external:: dropped_here
	integer:: i,count_rebuild,count_dropped
        common/dr/count_rebuild,count_dropped
        count_dropped = 0
        count_rebuild = 0
1000	continue
	i = winio@('%ww%ca[DropTest]&')
        i = winio@('%dr&',dropped_here)
        i = winio@('Num rebuild %`rd&',count_rebuild)
        i = winio@('Num FOund %`rd&',count_dropped)
        i = winio@(' ')
        if(i.eq.1)then
          count_rebuild = count_rebuild + 1
          go to 1000
        endif
        end
        integer function dropped_here()
	use mswin
	integer:: count_rebuild,count_dropped
        common/dr/count_rebuild,count_dropped
	character*260:: dropped_file
        dropped_file = clearwin_string@('dropped_file')
        dropped_here = 1
        count_dropped = count_dropped + 1
        if(mod(count_dropped,3).eq.0)dropped_here = -1
        return
        end
26 Apr 2021 6:43 #27626

Bill

I am not sure what you are aiming for but this might help...

        program main
        use mswin
        integer,external:: dropped_here
        integer:: i,count_rebuild,count_dropped,ictrl
        integer(7) hwnd
        common/dr/count_rebuild,count_dropped,hwnd,ictrl
        count_dropped = 0
        count_rebuild = 0
1000    continue
        ictrl = 0
        i = winio@('%ww%ca[DropTest]&')
        i = winio@('%dr&',dropped_here)
        i = winio@('Num rebuild %`rd&',count_rebuild)
        i = winio@('Num Found %`rd&',count_dropped)
        i = winio@('%es&')
        i = winio@('%hw',hwnd)
        if(ictrl == 1) go to 1000
        end
        
        integer function dropped_here()
        use mswin
        integer:: count_rebuild,count_dropped,ictrl
        integer(7) hwnd
        common/dr/count_rebuild,count_dropped,hwnd,ictrl
        character*260:: dropped_file
        logical L
        dropped_file = clearwin_string@('dropped_file')
        dropped_here = 1
        count_dropped = count_dropped + 1
        icurrent = clearwin_info@('DROPPED_CURRENT')
        icount   = clearwin_info@('DROPPED_COUNT')
        print*, icurrent, icount, '    ', trim(dropped_file)
        if(icurrent == icount) then
          ictrl = 1
          L = DestroyWindow(hwnd)
        endif  
        end function
26 Apr 2021 3:03 #27630

Paul, thanks for the suggestion.

I implemented it into my production code. It does work as I had intended.

Perhaps the documentation could be altered to indicate that closing the parent window by returning a negative value is not available?

Again, thanks for the solution! Bill

26 Apr 2021 4:44 #27631

Bill

On reflection, I need to check that DestroyWindow does everything that needs doing when closing a ClearWin+ window.

The documentation will need ammending but only in the context of a %dr callback function.

26 Apr 2021 6:13 #27632

Paul, thanks for the confirmation re: documentation. Sometimes, the hardest part o keep concise, yet complete.

It is amazing that before I saw your message, I was sitting here thinking about what happens to stacks, etc. if the parent window is closed BEFORE the callback is actually complete. If there is an issue, I have an alternative method that doesn't require the closing of the parent window. It is not as intuitive as what I have working right now, but it can work well (I already use this technique elsewhere). I'll keep my ears open for what you discover.

Thanks, Bill

27 Apr 2021 6:19 #27633

Bill

Here is my revised sample. SendMessage with WM_CLOSE is better than DestroyWindow. I haven't used count_rebuild. Any processing based on the file name could be carried out within the callback function.

        program main
        integer,external::dropped_here
        integer:: i,count_rebuild,count_dropped,ictrl
        common count_dropped,ictrl
        count_dropped = 0
        count_rebuild = 0
        do
         ictrl = 0
         i = winio@('%ww%ca[DropTest]&')
         i = winio@('%dr&',dropped_here)
         i = winio@('Num rebuild %`rd&',count_rebuild)
         i = winio@('Num Found %`rd&',count_dropped)
         i = winio@(' ')
         if(ictrl == 0) exit
        end do  
        end
        
        integer function dropped_here()
        use mswin
        integer(7) hwnd
        character*260::dropped_file
        integer count_dropped,ictrl
        common count_dropped,ictrl
        dropped_file  = clearwin_string@('DROPPED_FILE')
        icurrent      = clearwin_info@('DROPPED_CURRENT')
        count_dropped = clearwin_info@('DROPPED_COUNT')
        hwnd          = clearwin_info@('CALL_BACK_WINDOW')
        print*, icurrent, '    ', trim(dropped_file)
        if(icurrent == count_dropped) then
          ictrl = 1
          i = SendMessage(hwnd,WM_CLOSE,0,0)
        endif  
        dropped_here = 2
        end function
27 Apr 2021 5:47 #27641

Thanks, Paul, this is most helpful!!

Please login to reply.