It is currently Mon Nov 30, 2020 6:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 4:33 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
In the Help of PB 5.72 concerning FrameGadget(), it reads
Quote:
This kind of gadget is decorative only.
This is currently not quite true.

Calling the FrameGadget() function can defeat Drag and Drop, depending on the exact place in the source code where it is used (tested on Windows). This is demonstrated by the following examples:

  • In the first example, FrameGadget() comes before StringGadget()
    --> Drag and Drop does not work with StringGadget().
    //edit: As BarryG pointed out, this example would work without the flag #PB_Frame_Flat.
  • In the second example, FrameGadget() comes after StringGadget()
    --> Drag and Drop does work with StringGadget().

Code:
; PB 5.72

EnableExplicit

; Windows
#WinMain = 0

; Gadgets
Enumeration
   #Frame1
   #Text1
   #String1
   #Frame2
   #Text2
   #String2
   #BtnQuit
EndEnumeration

#WinWidth  = 400
#WinHeight = 280
#Frame1X   =  10
#Frame1Y   =  20
#Frame2X   =  10
#Frame2Y   = 120


Define event.i, dropped$

If OpenWindow(#WinMain, 0,0, #WinWidth,#WinHeight, "Drag and Drop files",
              #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget) = 0
   MessageRequester("Fatal error",
                    "Can't open main window.",
                    #PB_MessageRequester_Error)
   End
EndIf

FrameGadget(#Frame1,   #Frame1X,    #Frame1Y,    #WinWidth-20,75, "", #PB_Frame_Flat)
TextGadget(#Text1,     #Frame1X+10, #Frame1Y+15, 260,20, "Does not work")
StringGadget(#String1, #Frame1X+10, #Frame1Y+35, #WinWidth-40,20, "")

TextGadget(#Text2,     #Frame2X+10,#Frame2Y+15, 100,20, "Works")
StringGadget(#String2, #Frame2X+10,#Frame2Y+35, #WinWidth-40,20, "")
FrameGadget(#Frame2,   #Frame2X,   #Frame2Y,    #WinWidth-20,75, "", #PB_Frame_Flat)

ButtonGadget(#BtnQuit, #WinWidth-90,#WinHeight-50, 80,25, "Quit")

EnableGadgetDrop(#String1, #PB_Drop_Files, #PB_Drag_Copy)
EnableGadgetDrop(#String2, #PB_Drop_Files, #PB_Drag_Copy)

SetActiveGadget(#String1)

Repeat
   event = WaitWindowEvent()

   Select event
      Case #PB_Event_Gadget
         If EventGadget() = #BtnQuit
            Break
         EndIf

      Case #PB_Event_GadgetDrop
         dropped$ = StringField(EventDropFiles(), 1, #LF$)
         SetGadgetText(EventGadget(), dropped$)
         SetActiveGadget(EventGadget())
   EndSelect
Until event = #PB_Event_CloseWindow

CloseWindow(#WinMain)

This is either a bug in PureBasic itself or in the documentation.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Last edited by Little John on Sat Oct 03, 2020 7:56 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 6:03 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1090
Confirmed, but remove #PB_Frame_Flat and it works for the first example. So #PB_Frame_Flat is causing the problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 6:27 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 769
Location: Linz, Austria
Not a bug! Windows draws its controls from top to bottom. When you create the Frame first and then the Stringgadget, the Frame is on top of the Stringgadget... Thus, the Frame is blocking Drag/Drop.
If you have a Framegadget with other Gadget "in it", always create the Frame last! (like in your second example).

quick test
Code:
;replace
  EnableGadgetDrop(#String1, #PB_Drop_Files, #PB_Drag_Copy)
;with
  EnableGadgetDrop(#Frame1, #PB_Drop_Files, #PB_Drag_Copy)
;and the frame will respond to DnD


you could also use
Code:
BringWindowToTop_(GadgetID(#String1))
afterwards, if you don't want to restructure your code.

If you remove #PB_Frame_Flat from the Frame, Windows will create the Frame as a Button Control instead of a Static Control and it will also work...

_________________
Et cetera is my worst enemy


Last edited by chi on Sat Oct 03, 2020 6:35 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 6:34 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1090
chi wrote:
Not a bug!

You missed my #PB_Frame_Flat comment. It is a bug because the command should work the same whether the #PB_Frame_Flat is used or not.


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 6:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 769
Location: Linz, Austria
BarryG wrote:
chi wrote:
Not a bug!

You missed my #PB_Frame_Flat comment. It is a bug because the command should work the same whether the #PB_Frame_Flat is used or not.
Yeah, I missed it... But PB creates two different controls depending on whether you have specified #PB_Frame_Flat or not. Without you get a Button Control that doesn't block the underlying controls, with #PB_Frame_Flat you get a Static Control that blocks.

_________________
Et cetera is my worst enemy


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 7:49 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
chi wrote:
quick test
Code:
;replace
  EnableGadgetDrop(#String1, #PB_Drop_Files, #PB_Drag_Copy)
;with
  EnableGadgetDrop(#Frame1, #PB_Drop_Files, #PB_Drag_Copy)
;and the frame will respond to DnD

I know that this is technically possible, but that's not how I want my program to work.
And using the FrameGadget() as target for Drag and Drop would also be a contradiction to the statement in the Help:
Quote:
This kind of gadget is decorative only.

As I already wrote: If all this is the intended behaviour, then it should be documented properly.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget() can defeat Drag and Drop
PostPosted: Sat Oct 03, 2020 7:49 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
BarryG wrote:
Confirmed, but remove #PB_Frame_Flat and it works for the first example. So #PB_Frame_Flat is causing the problem.

Good catch, thank you!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Shield, wombats and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye