PureBasic Forum
https://www.purebasic.fr/english/

Drag'n'Drop on Container inside Frame doesn't work
https://www.purebasic.fr/english/viewtopic.php?f=4&t=44377
Page 1 of 1

Author:  c4s [ Mon Nov 22, 2010 3:20 pm ]
Post subject:  Drag'n'Drop on Container inside Frame doesn't work

It took me a while to figure this out and in my eyes it's a pretty strange bug. The following code explains best I guess:
Code:
Enumeration
   #Window
   #Frame
   #Container
   #ContainerString
   #Button
EndEnumeration


If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 90, "Drag'n'Drop Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   Frame3DGadget(#Frame, 0, 0, 400, 90, "")  ; 1) Comment this and drag'n'drop works, frame isn't visible

   ContainerGadget(#Container, 0, 0, 400, 60)
      StringGadget(#ContainerString, 10, 10, 380, 40, "Drag a file (or folder) to display its path")
       EnableGadgetDrop(#ContainerString, #PB_Drop_Files, #PB_Drag_Move)
   CloseGadgetList()

   ButtonGadget(#Button, 10, 60, 380, 20, "Button")
   ; EnableGadgetDrop(#Button, #PB_Drop_Files, #PB_Drag_Move)  ; 2) Uncomment this while "1)" is still uncommented, frame gets visible + position is shifted a little & drag'n'drop works now


   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_GadgetDrop
            SetGadgetText(EventGadget(), EventDropFiles())
         Case #PB_Event_CloseWindow
            Break
      EndSelect
   ForEver
EndIf


If someone has a good understandable workaround for this, please let me know.

Author:  IdeasVacuum [ Mon Nov 22, 2010 3:53 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

It's because the 3DFrameGadget is in the GadgetList. Define it outside of the list, just as the button is, then drag n drop of the StringGadget works fine.

Author:  Kiffi [ Mon Nov 22, 2010 4:48 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

this one works for me:
Code:
[...]
ContainerGadget(#Container, 0, 0, 400, 60)
EnableGadgetDrop(#Container, #PB_Drop_Files, #PB_Drag_Move)
[...]


Greetings ... Kiffi

Author:  c4s [ Mon Nov 22, 2010 5:10 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

IdeasVacuum wrote:
It's because the 3DFrameGadget is in the GadgetList. Define it outside of the list, just as the button is, then drag n drop of the StringGadget works fine.
Sorry, I don't understand you. OpenWindow() creates the standard gadget list where I put my frame, button and container. The string is in the container gadget list and doesn't get drag'n'drop events when I define the frame before the container. This doesn't make any sense to me.

Why does drag'n'drop magically work when I:
  • Remove the Frame3DGadget()
  • Enable drag'n'drop for the button


I edited the code a little:
Code:
Enumeration
   #Window
   #Frame
   #Container
   #ContainerString
   #Button
EndEnumeration


If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 400, 90, "Drag'n'Drop Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   Frame3DGadget(#Frame, 0, 0, 400, 90, "", #PB_Frame3D_Flat)  ; 1) Comment this and drag'n'drop works, frame isn't visible

   ContainerGadget(#Container, 10, 10, 380, 40)
      StringGadget(#ContainerString, 0, 0, 380, 40, "Drag a file (or folder) to display its path")
       EnableGadgetDrop(#ContainerString, #PB_Drop_Files, #PB_Drag_Move)
   CloseGadgetList()

   ButtonGadget(#Button, 10, 60, 380, 20, "Button")
   ; EnableGadgetDrop(#Button, #PB_Drop_Files, #PB_Drag_Move)  ; 2) Uncomment this while "1)" is still uncommented, drag'n'drop works now


   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_GadgetDrop
            SetGadgetText(EventGadget(), EventDropFiles())
         Case #PB_Event_CloseWindow
            Break
      EndSelect
   ForEver
EndIf

Author:  IdeasVacuum [ Mon Nov 22, 2010 7:44 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

All the gadgets in the list before CloseGadgetList() are in that list. So, list the Frame3DGadget after CloseGadgetList(). That's it :wink:

Author:  c4s [ Mon Nov 22, 2010 8:51 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

@IdeasVacuum
Well, thanks. That might be a workaround but it doesn't explain what it all has to do with this Frame3DGadget(). See, every other gadget seems to work, just the frame makes trouble.
Also I don't get why all gadgets before closelist should be in the container list. I mean OpenWindow() creates a list and the container a sub list that is closed with that function.

@Kiffi
Do you get the same effects as I do with my sample code?

Author:  IdeasVacuum [ Mon Nov 22, 2010 10:00 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

OpenWindow does not create a gadget list per say, it's the CloseGadgetList() function which declares "all gadgets listed above are members of this list", thus defining them as a related group.

Frame3DGadget() "is decorative only" but it's the first gadget in the list found by drag n drop because it is the outer perimeter of those gadgets. So to me, it's perfectly logical that the Frame3DGadget() does not belong in that specific list. It is fair to say that, given it's only decorative, one would not expect it to get in the way of anything but the gadgets seem have a Z order - if that is true, it's more likely to be an API thing than a PB thing no?

Author:  netmaestro [ Mon Nov 22, 2010 10:38 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

This presents as a bug. The Frame3D gadget is documented as not receiving any events, yet this is apparently not the case. I cut a region out of the frame3d gadget and this allowed the dragdrop to work, which led me to believe that its event-processing is conflicting with the gadgets inside it. So then I left its clipping region untouched and disabled it. This also allowed the dragdrop to work. A fix is needed on the Frame3D imho. One possible approach could be that PB automatically removes the region inside the lines on creation, this way it truly would be "decorative only" as it doesn't exist beyond it's drawn lines.

Code:
Enumeration
   #Window
   #Frame
   #Container
   #ContainerString
   #Button
EndEnumeration


If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 420, 110, "Drag'n'Drop Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   StickyWindow(#window, 1)
   Frame3DGadget(#Frame, 10, 10, 400, 90, "")

   DisableGadget(#frame, 1) ;<-------- Allows the dragdrop to work; Shouldn't be necessary
   
   ContainerGadget(#Container, 20, 20, 380, 60)
      StringGadget(#ContainerString, 10, 10, 360, 40, "Drag a file (or folder) to display its path")
       EnableGadgetDrop(#ContainerString, #PB_Drop_Files, #PB_Drag_Move)
   CloseGadgetList()

   ButtonGadget(#Button, 20, 70, 360, 20, "Button")

   Repeat
      Select WaitWindowEvent()
         Case #PB_Event_GadgetDrop
            SetGadgetText(EventGadget(), EventDropFiles())
         Case #PB_Event_CloseWindow
            Break
      EndSelect
   ForEver
EndIf

Author:  c4s [ Mon Nov 22, 2010 11:11 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

@IdeasVacuum
Not a long time ago we had to use CreateGadgetList() along with OpenWindow() and now the gadget list is automatically created. The #PB_Window_NoGadgets flag was added to prevent this behavior.

@netmaestro
Thanks. That's a fix I can live with for now.

By the way, do you understand why adding EnableGadgetDrop() for the following button also works?

Author:  IdeasVacuum [ Tue Nov 23, 2010 11:25 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

Yeah, it is a bug then. A work-around would be to draw your own lines.

EnableGadgetDrop() for the following button didn't exactly work on my machine, I could only drag and drop to the button itself.

Author:  Fred [ Mon Jul 29, 2013 4:30 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

Fixed. Now the framegadget() is disabled by default to avoid any events.

Author:  User_Russian [ Wed Aug 07, 2013 3:07 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

Fred wrote:
Fixed. Now the framegadget() is disabled by default to avoid any events.
I am against this fix!
Now FrameGadget() looks ugly!
Image
You have to insert a string.
Code:
DisableGadget(0, 0)

Author:  USCode [ Wed Aug 07, 2013 3:29 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

User_Russian wrote:
Fred wrote:
Fixed. Now the framegadget() is disabled by default to avoid any events.
I am against this fix!
Now FrameGadget() looks ugly!
Image
You have to insert a string.
Code:
DisableGadget(0, 0)

Not sure I undestand this fix either, why would we want any gadget to appear disabled by default?
There must be another solution to this issue?

Author:  Fred [ Wed Aug 07, 2013 4:57 pm ]
Post subject:  Re: [Done] Drag'n'Drop on Container inside Frame doesn't wor

I had tested only with skin on, so i didn't notice this. Back to the drawing board !

Author:  breeze4me [ Wed Aug 07, 2013 7:07 pm ]
Post subject:  Re: Drag'n'Drop on Container inside Frame doesn't work

It seems to be due to the Z-order.
Here is a workaround.
All the gadgets except the panel and frame gadgets need the SetWindowPos_() line, or at least the parent gadget(if any).

Code:
If OpenWindow(0, 0, 0, 620, 550, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  FrameGadget(0, 10,  5, 600, 500, "FrameGadget Standard")
  DisableGadget(0, 0)
 
  FrameGadget(1, 20,  20, 550, 450, "", #PB_Frame_Single)
  DisableGadget(1, 0)
 
  FrameGadget(2, 30, 30, 500, 400, "", #PB_Frame_Double)
  DisableGadget(2, 0)
 
  h = ContainerGadget(4, 45, 45, 400, 60, #PB_Container_Single)
    SetWindowPos_(h, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE) ;it must be added.
   
    h = StringGadget(5, 10, 10, 380, 40, "Drag a file (or folder) to display its path")
    ;SetWindowPos_(h, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE)
   
    EnableGadgetDrop(5, #PB_Drop_Files, #PB_Drag_Move)
  CloseGadgetList()
 
 
  h = ButtonGadget(6, 45, 150, 380, 20, "Button 6")
  SetWindowPos_(h, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE) ;it must be added.
  EnableGadgetDrop(6, #PB_Drop_Files, #PB_Drag_Move)
 
 
  h = SpinGadget(7, 45, 180, 380, 30, 0, 100)
  hUpDown = GetWindow_(h, #GW_HWNDNEXT)
  Debug hUpDown
  SetWindowPos_(hUpDown, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE)
  SetWindowPos_(h, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE) ;it must be added.
  EnableGadgetDrop(7, #PB_Drop_Files, #PB_Drag_Move)
  Debug GetWindow_(h, #GW_HWNDNEXT)
 
  h = ScrollAreaGadget(8, 45, 220, 380, 50, 500, 100)
    SetWindowPos_(h, #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE) ;it must be added.
    h = ButtonGadget(13, 10, 15, 80, 24, "Button 13")
  CloseGadgetList()
  EnableGadgetDrop(13, #PB_Drop_Files, #PB_Drag_Move)
 
 
  PanelGadget(9, 45, 280, 300, 100)    ; it seems to have no need to add the SetWindowPos_() line.
    AddGadgetItem(9, -1, "Panel 1")
    h = ButtonGadget(10, 10, 15, 80, 24,"Button 10")
   
    h = ButtonGadget(11, 95, 15, 80, 24,"Button 11")
   
    AddGadgetItem(9, -1, "Panel 2")
    h = ButtonGadget(12, 10, 15, 80, 24,"Button 12")
   
  CloseGadgetList()
  EnableGadgetDrop(10, #PB_Drop_Files, #PB_Drag_Move)
  EnableGadgetDrop(11, #PB_Drop_Files, #PB_Drag_Move)
  EnableGadgetDrop(12, #PB_Drop_Files, #PB_Drag_Move)
 
 
  h = FrameGadget(3, 40, 40, 450, 350, "", #PB_Frame_Flat)
  DisableGadget(3, 0)
 
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_GadgetDrop
        Debug Str(EventGadget()) + " " + EventDropFiles()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/