How to detect when an icon is dragging over a window

This forum is for general developer support questions.
zzd10h
Posts: 546
Joined: Sun Sep 16, 2012 5:40 am
Location: France

How to detect when an icon is dragging over a window

Post 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 ;
}  
http://apps.amistore.net/zTools
X1000 - AmigaOS 4.1.6 / 4.1 FE
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

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

Post 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.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 530
Joined: Sat Jun 18, 2011 3:12 pm
Location: Finland
Contact:

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

Post 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...
zzd10h
Posts: 546
Joined: Sun Sep 16, 2012 5:40 am
Location: France

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

Post 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
http://apps.amistore.net/zTools
X1000 - AmigaOS 4.1.6 / 4.1 FE
zzd10h
Posts: 546
Joined: Sun Sep 16, 2012 5:40 am
Location: France

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

Post by zzd10h »

@Salass0

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

Thank you (again)
http://apps.amistore.net/zTools
X1000 - AmigaOS 4.1.6 / 4.1 FE
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

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

Post 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.
zzd10h
Posts: 546
Joined: Sun Sep 16, 2012 5:40 am
Location: France

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

Post 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
http://apps.amistore.net/zTools
X1000 - AmigaOS 4.1.6 / 4.1 FE
User avatar
gazelle
Posts: 102
Joined: Sun Mar 04, 2012 12:49 pm
Location: Frohnleiten, Austria

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

Post 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?
zzd10h
Posts: 546
Joined: Sun Sep 16, 2012 5:40 am
Location: France

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

Post 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
http://apps.amistore.net/zTools
X1000 - AmigaOS 4.1.6 / 4.1 FE
chris
Posts: 562
Joined: Sat Jun 18, 2011 11:05 am
Contact:

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

Post 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.
Post Reply