Page 1 of 2

How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 8:58 pm
by zzd10h
Hi,
Is somebody could give me advices about the following question ?

I don't have problem to detect a dropped icon on my window with WINDOW_AppMsgHook but I
would like to detect when a icon is dragging over my window (without to be dropped).

Is it possible ?

I tried to use a DropZone but as soon that I add a WBDZA_Hook, OS freezes when a icon is dragged in my window.
DropZone is well created but certainly that I misuse it...

Is a DropZone with WBDZA_Hook could help me ?


Thank you for your help (posted too on OS4-Coding forum)


Sample based on SDK:Examples/GUI/Window/AppWindow.c

http://www.indiego.rocks/file/download/ ... 1c0ad04cc6

Code: Select all

	if ( (appDropZoneHook = AllocSysObjectTags(ASOT_HOOK,
          ASOHOOK_Entry, appDropZone_hook,
          ASOHOOK_Data, NULL,
          TAG_END)) )         
  	{ 
	
 			GetAttr(WINDOW_AppWindowPtr,objects[OID_MAIN],(uint32 *)&windowZone) ;

			if ( (dropZone = AddAppWindowDropZone((struct AppWindow *)windowZone,1,0,
						WBDZA_Left,0,
						WBDZA_Top, 0, 
						WBDZA_Width, windows->Width,
						WBDZA_Height, windows->Height,						
						WBDZA_Hook, appDropZone_hook,
						TAG_END)) )
			{	    
	 			printf("dropZone OK \n");   
			}    						
			else
	 			printf("dropZone KO \n");  
	 	 						
 	}	//end if appMessageDropZoneHook 

LONG appDropZone_hook(struct Hook *hook, APTR reserved, struct AppWindowDropZoneMsg *adzm)
{
    printf("windows->MouseX (%d) windows->MouseY (%d) \n",windows->MouseX,windows->MouseY) ;
  
	return 0 ;
}  

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 9:11 pm
by salass00
zzd10h wrote: if ( (appDropZoneHook = AllocSysObjectTags(ASOT_HOOK,
ASOHOOK_Entry, appDropZone_hook,
ASOHOOK_Data, NULL,
TAG_END)) )
You've named your hook function the same as the pointer variable for your hook structure, so the pointer variable "shadows" your hook function.

I suggest renaming the hook function to something like appDropZone_hook_func() and sticking to a convention like that in the future.

Edit:

Never mind, I can see now that the names are slightly different (appDropZoneHook vs appDropZone_hook). My suggestion remains though.

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 9:27 pm
by salass00
From autodoc on WBDZA_Hook:
A final word of warning: when your hook code is called, you
must limit your rendering to simple drawing operations
from graphics.library; if you do anything complex that
involves Intuition locking and unlocking the display,
such as refreshing gadgets or locking IntuitionBase,
you will deadlock the operating system. You have been
warned!
I doubt that your call to printf() qualifies as a "simple drawing operation". Most likely this is what causes a deadlock and your system to hang...

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 9:39 pm
by zzd10h
Thank you for your replies.

"Have you checked the value returned in windowZone? Does it look like a valid pointer?"
I don't know if it's a valid pointer but following AddAppWindowDropZone() that uses windowZone pointer seems OK

"Also is your window object an app window and is it opened when you do this?"
Yes, the AddAppWindowDropZone() is called after "if...objects[OID_MAIN], WM_OPEN"

"To make your window an appwindow you have to set WINDOW_AppPort to a valid MsgPort to receive your AppMessages and set WINDOW_AppWindow to TRUE."
Yes, there are OK,

"I doubt that your call to printf() qualifies as a "simple drawing operation". Most likely this is what causes a deadlock and your system to hang..."
Yes, I read that but even by commenting the printf (only remaining return 0), same freeze.




Thank you for your help, if you have 5 minutes of free time, here is the source code (based on SDK AppWindow.c example)
http://www.indiego.rocks/file/download/ ... 1c0ad04cc6

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 9:46 pm
by zzd10h
@Salass0

But do you think that WBDZA_Hook could detect an icon dragging but not dropped ?

Thank you (again)

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 10:21 pm
by gazelle
Shouldn't that:

Code: Select all

WBDZA_Hook, appDropZone_hook,
be that:

Code: Select all

WBDZA_Hook, appDropZoneHook,
other than that, I can't be of help.

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 11:01 pm
by zzd10h
Yes you are right Gazelle,
by fixing the hook and by removing printf (salass0) inside

no more freeze, thank you :D

It's nice, but, unfortunately, it only give me the coordinate when a icon is DROPPED, not when an icon is dragging...

Is somebody know if it's the way to know how to grab if an icon is overing a window ?

Thank you again
Guillaume

Sources
http://www.indiego.rocks/file/download/ ... 1c0ad04cc6

to compile with
gcc -D__USE_INLINE__ -D__USE_BASETYPE__ AppWindow.c -o AppWindow -lauto -lamiga -gstabs

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 11:32 pm
by gazelle
zzd10h wrote:Is somebody know if it's the way to know how to grab if an icon is overing a window ?
Your hook will be called when the icon is over your dropzone with adzm->adzm_Action = ADZMACTION_Enter
Now you know the icon is over your dopzone (you may set a global var in the hook function).
When the icon is dragged out of the dropzone, the hook will be called again with adzm->adzm_Action = ADZMACTION_Leave

Isn't that what you want?

Re: How to detect when an icon is dragging over a window

Posted: Thu Dec 03, 2015 11:49 pm
by zzd10h
"Now you know the icon is over your dopzone"
Ah yes, but it inhibit totally the WINDOW_AppMsgHook() and overall, i know only the coordinate an icon is entering the dropzone (my whole window in my case), not the coordinates his icon is hovering inside the window.

Or maybe the only solution is to make a dropzone for each elements ?

Thank you

Re: How to detect when an icon is dragging over a window

Posted: Fri Dec 04, 2015 6:49 pm
by chris
zzd10h wrote:"Now you know the icon is over your dopzone"
Ah yes, but it inhibit totally the WINDOW_AppMsgHook() and overall, i know only the coordinate an icon is entering the dropzone (my whole window in my case), not the coordinates his icon is hovering inside the window.

Or maybe the only solution is to make a dropzone for each elements ?
You can read the mouse position from your window structure, and work it out.

If you have several distinct zones icons need to be dropped into, the correct method is to create a DropZone for each one. But this sometimes isn't practical, it depends what you're trying to do.