ListView/ListIcon and correct using of Drag'n'Drop (move)?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

ListView/ListIcon and correct using of Drag'n'Drop (move)?

Post by Andre »

Hello everyone,

I'm loosing my hair to find out, why the following use of EnableGadgetDrop() doesn't fire the needed #PB_EventType_DragStart event, when using it in my larger project source.

So anyone knows about restrictions / needed circumstances to have the Drag'n'Drop (move mode) to be supported in Listview / ListIcon gadgets?

The following code example works as expected, but in my large project it doesn't... :x See below!

Code: Select all

; English forum: http://www.purebasic.fr/english/viewtopic.php?f=13&t=49510
; Author: RASHAD (extended and reworked by Andre)
; Date: 21. March 2012
; OS: Windows, MacOS
; Demo: Yes


; Drag and Drop to the same ListIcon() as per the ques.
; Code by infratec (Berned)

Procedure ListIconGadgetColumns(GadgetNo)
  i = 0
  While GetGadgetItemAttribute(GadgetNo, 0, #PB_ListIcon_ColumnWidth, i) > 0
    i + 1
  Wend
  ProcedureReturn i
EndProcedure

Procedure ListIconGadgetMove(GadgetNo.i, Source.i, Dest.i)
  Columns = ListIconGadgetColumns(GadgetNo) - 1
  For j = 0 To Columns
    Source$ = GetGadgetItemText(GadgetNo, Source, j)
    If Source < Dest
      For i = Source To Dest - 1
        Help$ = GetGadgetItemText(GadgetNo, i + 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    Else
      For i = Source To Dest + 1 Step - 1
        Help$ = GetGadgetItemText(GadgetNo, i - 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    EndIf
    SetGadgetItemText(GadgetNo, i, Source$, j)
  Next j
EndProcedure

Procedure ListViewGadgetMove(gad.i, Source.i, Dest.i)
  Protected i, Help$, Source$
  Source$ = GetGadgetItemText(gad, Source)
  If Source < Dest
    For i = Source To Dest - 1
      Help$ = GetGadgetItemText(gad, i + 1)
      SetGadgetItemText(gad, i, Help$)
    Next
  Else
    For i = Source To Dest + 1 Step - 1
      Help$ = GetGadgetItemText(gad, i - 1)
      SetGadgetItemText(gad, i, Help$)
    Next
  EndIf
  SetGadgetItemText(gad, i, Source$)
EndProcedure

OpenWindow(0, 0, 0, 600, 600, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

; ContainerGadget is more for testing only (if the Drag'n'Drop also works, if the related gadgets are placed inside)
gad = ContainerGadget(#PB_Any, 5, 5, 590, 590, #PB_Container_Double)
      
listicon = ListIconGadget(#PB_Any, 10, 10, 570, 380, "Test 1", 150 , #PB_ListIcon_FullRowSelect|#PB_ListIcon_HeaderDragDrop)
AddGadgetColumn(listicon, 1, "Test 2", 150)
AddGadgetColumn(listicon, 2, "Test 3", 120)
AddGadgetColumn(listicon, 3, "Test 4", 120)
For i = 1 To 10
  AddGadgetItem(listicon, -1, "Line " + Str(i) + " Col 1" + Chr(10) + "Line " + Str(i) + " Col 2"+  Chr(10) + "Line " + Str(i) + " Col 3" + Chr(10) + "Line " + Str(i) + " Col 4")
Next i
EnableGadgetDrop(Listicon, #PB_Drop_Private, #PB_Drag_Move, 1)

listview = ListViewGadget(#PB_Any, 10, 400, 570, 170)
For i = 1 To 10
  AddGadgetItem(listview, -1, "Line " + Str(i))
Next i
EnableGadgetDrop(listview, #PB_Drop_Private, #PB_Drag_Move, 1)

Exit = #False
DragItem = -1

Repeat
  Event = WaitWindowEvent()
  EventType = EventType()
  EventGadget = EventGadget()
  
  Select Event
    Case #PB_Event_Gadget
      Select EventType
        Case #PB_EventType_DragStart
          DragItem = GetGadgetState(EventGadget)
          DragPrivate(1, #PB_Drag_Move)
      EndSelect
    Case #PB_Event_GadgetDrop
      If EventDropPrivate() = 1
        TargetItem = GetGadgetState(EventGadget)
        ; Debug "Target: " + Str(TargetItem)
        If EventGadget = listicon
          ListIconGadgetMove(EventGadget, DragItem, TargetItem)
        ElseIf EventGadget = listview
          ListViewGadgetMove(EventGadget, DragItem, TargetItem)
        EndIf
      EndIf
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
  
Until Exit

Here are some code snippets taken from my source...

Gadget definition (the gadget items are added/removed on the fly during the program flow):

Code: Select all

        gad = ListViewGadget(#PB_Any, x, y, 200, fontheight*8, #PB_ListView_ClickSelect)    
        EnableGadgetDrop(gad, #PB_Drop_Private, #PB_Drag_Move, 1)
Part of the Main event loop, where the related EventType is already checked directly after WindowEvent() for testing. But the requested EventType #PB_EventType_DragStart neither happens.... (not here, and not a bit later in the "regular" Select : Case : EndSelect block for processing all window+gadget events:

Code: Select all

Repeat
  Event = WindowEvent()   ; WaitWindowEvent()
  EventGadget	= EventGadget()
  EventMenu	  = EventMenu()
  EventWindow = EventWindow()
  EventType   = EventType()
  
  If Event = #PB_Event_Gadget And Eventtype = #PB_EventType_DragStart  
    Debug "Drag'n'Drop started..."
          DragItem = GetGadgetState(EventGadget)
          DragPrivate(1, #PB_Drag_Move)
  EndIf

  ....
Did anyone of noticed similar effects?
(I'm currently coding on MacOS 10.5.8 - but it should be the same on Windows too...)

Thanks a lot for advice!
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by infratec »

Hi Andre,

what happend if you remove #PB_ListView_ClickSelect from the ListviewGadget() :?:

Because when I add it in the working example, it results in a strange behaviour.

Bernd

Btw.: In the german help it is not written that the ListViewGadget() reacts on a DragStart event.
Only
#PB_EventType_LeftClick
#PB_EventType_LeftDoubleClick
are listed.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

Hi Bernd, thanks for your answer!
infratec wrote:what happend if you remove #PB_ListView_ClickSelect from the ListviewGadget() :?:

Because when I add it in the working example, it results in a strange behaviour.
Yes, I tried removing this flag. It doesn't change anything in my project source.

But adding it to the example above work without any problems for me (MacOS 10.5.8).

infratec wrote: Btw.: In the german help it is not written that the ListViewGadget() reacts on a DragStart event.
Only
#PB_EventType_LeftClick
#PB_EventType_LeftDoubleClick
are listed.
Yes, I noticed this too.
But as there are several example using a listview are flying around on the PB forums, I thought it's supported (like the example above proofs) and just not documented yet.... !?

I also tried deactivating the complete listicon-related code in the example above. But then the drag'n'drop in the listview still works. So in general there seems to be no limit of Drag'n'Drop using a listview gadget.

Edit: I have also tried to replace my currently used listview with a listicon gadget, and also calling the EnableGadgetDrop() command after each AddGadgetItem(), just in case the change of listview items changes anything to the (already enabled) Drag'n'Drop support.... no matter what I do, there isn't fired the needed EventType of a started Drag operation :?

In general I'm lost with the not fired "Drag event" in my project, while all example codes work without any problem.
I just don't know, where the problem is and don't find any mistake made by me (as you can see in the code snippets).
So I'm now asking, if there are any circumstances known, when/why some events are catched/lost? Or if any code-related action "overwrites" the enabled Drag'n'Drop support....
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

This problem is driving me crazy.... :cry:

Today I tried adding the Drag'n'Drop support to another gadget in the main window, which is handled with a fixed gadget number (instead of #PB_Any created ones like for all gadgets in the other windows of the program). But this doesn't change anything - also for this gadget the dragging event isn't recognized by the event loop.

The related code snippets are:

Code: Select all

  ListIconGadget(#Gadget_ContinentList, #Left, y, #PanelWidth, PanelHeight*0.12, Language("ContinentList"), #PanelWidth-23+#GUI_ListIconColumnAdjust, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  EnableGadgetDrop(#Gadget_ContinentList, #PB_Drop_Private, #PB_Drag_Move, 1)
(using this ListIcon gadget flags I tried with the example code above - there they work successfully. So it could be no problem of them)

And this are the related parts of the main event loop in my project source:

Code: Select all

;- MAIN event loop
Repeat
  Event = WindowEvent() 
  EventGadget	= EventGadget()
  EventMenu	  = EventMenu()
  EventWindow = EventWindow()
  EventType   = EventType()
  
  If Eventtype = #PB_EventType_DragStart  
    Debug "Drag'n'Drop started..."
          DragItem = GetGadgetState(EventGadget)
          DragPrivate(1, #PB_Drag_Move)
  EndIf
    
  Select Event
    Case 0
      Delay(1)
      
    Case #PB_Event_CloseWindow 
      ....

    Case #PB_Event_Gadget
    
        Debug "We now pass the EventType check for Drag'n'Drop support..."
        Debug "Eventtype: " + Str(EventType)
      If Eventtype = #PB_EventType_DragStart  
        Debug "Drag'n'Drop started..."
        DragItem = GetGadgetState(EventGadget)
        DragPrivate(1, #PB_Drag_Move)
      EndIf
        
      Select EventGadget
         
        Case #Gadget_Quit
          ....

        Case #Gadget_ContinentList
          ....

  EndSelect
ForEver
Furthermore I tried replacing the "Event = WindowEvent()" with "Event = WaitWindowEvent()", but this make no change.
In both cases of the "If Eventtype = #PB_EventType_DragStart" check there is never the needed event for a started Drag operation catched.

How could this be?
Do you know any circumstances, when and why gadget events are getting lost during program flow?

I even checked the whole program code for

Code: Select all

  While WindowEvent() : Wend
snippets.
But they only appear in some special cases, when the program should wait for gadget refresh while filling gadget items, etc. But it never affects the main event loop of the program.

So I have no idea anymore how to solve this problem :?
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by idle »

Is this only happening on Mac?
I've got no idea why it's not working only thing I could think of trying is changing the drag n drops group number
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

idle wrote:Is this only happening on Mac?
At the moment I'm only developing on MacOS, so haven't tried the project source on Windows yet...
idle wrote:I've got no idea why it's not working only thing I could think of trying is changing the drag n drops group number
I've tried changing the number at EnableGadgetDrop() and DragPrivate() from 1 to 2 for the gadget #Gadget_ContinentList, but that doesn't change anything.
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by idle »

ok but did you try it so the number isn't conflicting with any of your gadget constants or enumerations?
I doubt it'll make any difference but who knows!
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by ts-soft »

I use always WaitWindowEvent(100) on linux and Mac.
And you should remove the delay in eventloop, that is not
a good idea :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Demivec »

@Andre: I am getting some problems with your first code sample (the one that should work), with windows (x86). I can drag a few times from the ListIconGadget to the ListViewGadget without a problem. If I then try to drag things in the opposite direction the drag isn't completed and everything stops responding. This doesn't happen right at the first and it may not be allowed intentionally by the code.

I haven't debugged it enough to find the cause yet.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by RASHAD »

Hi Andre
PB 4.6 x86 Win 7 x64
It works fine with the listicon inside a container and with with the listicon created
during run and with Items added or removed on the fly
I did not check with what Demevic mentioned

Code: Select all

Procedure ListIconGadgetColumns(GadgetNo)
  i = 0
  While GetGadgetItemAttribute(GadgetNo, 0, #PB_ListIcon_ColumnWidth, i) > 0
    i + 1
  Wend
  ProcedureReturn i
EndProcedure

Procedure ListIconGadgetMove(GadgetNo.i, Source.i, Dest.i)
  Columns = ListIconGadgetColumns(GadgetNo) - 1
  For j = 0 To Columns
    Source$ = GetGadgetItemText(GadgetNo, Source, j)
    If Source < Dest
      For i = Source To Dest - 1
        Help$ = GetGadgetItemText(GadgetNo, i + 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    Else
      For i = Source To Dest + 1 Step - 1
        Help$ = GetGadgetItemText(GadgetNo, i - 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    EndIf
    SetGadgetItemText(GadgetNo, i, Source$, j)
  Next j
EndProcedure

Procedure ListViewGadgetMove(gad.i, Source.i, Dest.i)
  Protected i, Help$, Source$
  Source$ = GetGadgetItemText(gad, Source)
  If Source < Dest
    For i = Source To Dest - 1
      Help$ = GetGadgetItemText(gad, i + 1)
      SetGadgetItemText(gad, i, Help$)
    Next
  Else
    For i = Source To Dest + 1 Step - 1
      Help$ = GetGadgetItemText(gad, i - 1)
      SetGadgetItemText(gad, i, Help$)
    Next
  EndIf
  SetGadgetItemText(gad, i, Source$)
EndProcedure

OpenWindow(0, 0, 0, 600, 600, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

; ContainerGadget is more for testing only (if the Drag'n'Drop also works, if the related gadgets are placed inside)
gad = ContainerGadget(#PB_Any, 5, 5, 460, 265, #PB_Container_Double)
     
listicon = ListIconGadget(#PB_Any, 10, 10, 440, 240, "Test 1", 100 , #PB_ListIcon_FullRowSelect|#PB_ListIcon_HeaderDragDrop)
AddGadgetColumn(listicon, 1, "Test 2", 100)
AddGadgetColumn(listicon, 2, "Test 3", 100)
AddGadgetColumn(listicon, 3, "Test 4", 100)
For i = 1 To 10
  AddGadgetItem(listicon, -1, "Line " + Str(i) + " Col 1" + Chr(10) + "Line " + Str(i) + " Col 2"+  Chr(10) + "Line " + Str(i) + " Col 3" + Chr(10) + "Line " + Str(i) + " Col 4")
Next i
CloseGadgetList()  ;Remember to close the GadgetList()
EnableGadgetDrop(Listicon, #PB_Drop_Private, #PB_Drag_Move, 1)

button = ButtonGadget(#PB_Any, 520, 15, 50, 24,"TEST")

Exit = #False
DragItem = -1

Repeat
  Event = WaitWindowEvent()
  EventType = EventType()
  EventGadget = EventGadget()
 
  Select Event
    Case #PB_Event_Gadget
     Select EventGadget()
       Case button
        listicon2 = ListIconGadget(#PB_Any, 10, 340, 440, 240, "Test 1", 100 , #PB_ListIcon_FullRowSelect|#PB_ListIcon_HeaderDragDrop)
        AddGadgetColumn(listicon2, 1, "Test 2", 100)
        AddGadgetColumn(listicon2, 2, "Test 3", 100)
        AddGadgetColumn(listicon2, 3, "Test 4", 100)
        For i = 1 To 10
          AddGadgetItem(listicon2, -1, "Line " + Str(i) + " Col 1" + Chr(10) + "Line " + Str(i) + " Col 2"+  Chr(10) + "Line " + Str(i) + " Col 3" + Chr(10) + "Line " + Str(i) + " Col 4")
        Next i 
        EnableGadgetDrop(Listicon2, #PB_Drop_Private, #PB_Drag_Move, 1)


       Case listicon,listicon2
        Select EventType
          Case #PB_EventType_DragStart
            DragItem = GetGadgetState(EventGadget)
            DragPrivate(1, #PB_Drag_Move)
        EndSelect
     EndSelect
        
    Case #PB_Event_GadgetDrop
      EventGadget = GetActiveGadget()
      If EventDropPrivate() = 1
        TargetItem = GetGadgetState(EventGadget)
        ; Debug "Target: " + Str(TargetItem)
        If EventGadget = listicon Or EventGadget = listicon2
          ListIconGadgetMove(EventGadget, DragItem, TargetItem)
        EndIf
      EndIf
          
          
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
 
Until Exit

Egypt my love
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

Sorry for the longer delay... yesterday I finished the Drag'n'Drop implementation in my GeoWorld project, using the code shown here with some further enhancements. :)

The good one is: all is working fine on MS Windows (using several listview gadgets, in which the items can be moved by drag'n'drop), so I'm sure my code is working how it should! :D
The bad one is: nothing happens on MacOS, there seems any Drag event missing, so no further processing is possible.

The following example with 2 listicons and 2 listviews is hacked together on my MacBook now, based on code from the forum and additions done in my project source (Windows).

It should run as expected on MS Windows (couldn't test it now), but nothing happens on MacOS.... :(
So the question is: Drag'n'Drop not supported for listviews and listicons on MacOS? ... a bug in PB? .... a bug in my code?

Code: Select all

; Code example for moving gadget items inside the "own" listview/listicon by Drag'n'Drop
; works on Windows for both listicon and listviews, on MacOS not.
; by Andre on 6th May 2012

EnableExplicit

Define listview1, listview2, listicon1, listicon2
Define i, Exit
Define Event, EventType, EventGadget
Global DragGadget, DragItem, TargetItem

Enumeration 
  #Drag_Listview1
  #Drag_Listview2
  #Drag_Listicon1
  #Drag_Listicon2
EndEnumeration

Procedure ListIconGadgetColumns(GadgetNo)
  Protected i
  i = 0
  While GetGadgetItemAttribute(GadgetNo, 0, #PB_ListIcon_ColumnWidth, i) > 0
    i + 1
  Wend
  ProcedureReturn i
EndProcedure

Procedure ListIconGadgetMove(GadgetNo.i, Source.i, Dest.i)
  Protected Columns, i, j, Help$, Source$
  Columns = ListIconGadgetColumns(GadgetNo) - 1
  For j = 0 To Columns
    Source$ = GetGadgetItemText(GadgetNo, Source, j)
    If Source < Dest
      For i = Source To Dest - 1
        Help$ = GetGadgetItemText(GadgetNo, i + 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    Else
      For i = Source To Dest + 1 Step - 1
        Help$ = GetGadgetItemText(GadgetNo, i - 1, j)
        SetGadgetItemText(GadgetNo, i, Help$, j)
      Next i
    EndIf
    SetGadgetItemText(GadgetNo, i, Source$, j)
  Next j
EndProcedure

Procedure ListViewGadgetMove(gad.i, Source.i, Dest.i)
  ; This procedure is written by Andre on the base of the ListIconGadgetMove() function found on the PB forum.
  ; It was enhanced to support also moving of listview item text and data, and to take care when the dropping
  ; is finished after the current displayed items (then use the last item as destination for the move operation).
  Protected i, ItemText$, ItemData, Source$, SourceData
  Source$ = GetGadgetItemText(gad, Source)
  SourceData = GetGadgetItemData(gad, Source)
  ;Debug "Dragged item (Source) = " + Str(Source) + ", Dropped at (Dest) = " + Str(Dest)
  ;If Source = -1 Or Dest = -1
  ;  Debug "Warning: Source = " + Str(Source) + ", Dest = " + Str(Dest)
  ;EndIf
  If Source = -1
    ; Sometimes it happens, that dragging an item (especially the first one) and dropping 
    ; it at the same place cause a "DragStart" event, but the 'Source' parameter is -1.
    ; In this case don't make any chances and return to main event loop!
    ProcedureReturn 
  EndIf
  If Dest = -1   
    ; The dragged item was dropped after the last item (giving -1 as result of GetGadgetState(),
    ; so we make the dragged one the last one now...
    Dest = CountGadgetItems(gad) - 1
  EndIf  
  If Source < Dest
    For i = Source To Dest - 1
      ItemText$ = GetGadgetItemText(gad, i + 1)
      ItemData  = GetGadgetItemData(gad, i + 1)
      SetGadgetItemText(gad, i, ItemText$)
      SetGadgetItemData(gad, i, ItemData)
    Next
  Else
    For i = Source To Dest + 1 Step - 1
      ItemText$ = GetGadgetItemText(gad, i - 1)
      ItemData  = GetGadgetItemData(gad, i - 1)
      SetGadgetItemText(gad, i, ItemText$)
      SetGadgetItemData(gad, i, ItemData)
    Next
  EndIf
  SetGadgetItemText(gad, i, Source$)
  SetGadgetItemData(gad, i, SourceData)
EndProcedure

OpenWindow(0, 0, 0, 600, 600, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)

; 1st LISTVIEW for testing drag'n'drop:
TextGadget(0, 10, 10, 200, 20, "Listview 1:")
listview1 = ListViewGadget(#PB_Any, 10, 35, 200, 230)
For i = 1 To 10
  AddGadgetItem(listview1, -1, "Line " + Str(i))
Next i
EnableGadgetDrop(listview1, #PB_Drop_Private, #PB_Drag_Move, #Drag_Listview1)

; 2nd LISTVIEW for testing drag'n'drop:
TextGadget(1, 10, 280, 200, 20, "Listview 2:")
listview2 = ListViewGadget(#PB_Any, 10, 305, 200, 230)
For i = 1 To 10
  AddGadgetItem(listview2, -1, "Line " + Str(i))
Next i
EnableGadgetDrop(listview2, #PB_Drop_Private, #PB_Drag_Move, #Drag_Listview2)

; 1st LISTICON for testing drag'n'drop:
TextGadget(2, 230, 10, 200, 20, "Listicon 1:")
listicon1 = ListIconGadget(#PB_Any, 230, 35, 340, 230, "Column 1", 100, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(listicon1, 1, "Column 2", 100)
AddGadgetColumn(listicon1, 2, "Column 3", 100)
For i = 1 To 10
  AddGadgetItem(listicon1, -1, "Line " + Str(i) + Chr(10) + "col. 2 (" + Str(i) + ")" + Chr(10) + "col. 3 (" + Str(i) + ")")
Next i
EnableGadgetDrop(listicon1, #PB_Drop_Private, #PB_Drag_Move, #Drag_Listicon1)

; 2nd LISTICON for testing drag'n'drop:
TextGadget(3, 230, 280, 200, 20, "Listicon 2:")
listicon2 = ListIconGadget(#PB_Any, 230, 305, 340, 230, "Column 1", 100, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(listicon2, 1, "Column 2", 100)
AddGadgetColumn(listicon2, 2, "Column 3", 100)
For i = 1 To 10
  AddGadgetItem(listicon2, -1, "Line " + Str(i) + Chr(10) + "col. 2 (" + Str(i) + ")" + Chr(10) + "col. 3 (" + Str(i) + ")")
Next i
EnableGadgetDrop(listicon2, #PB_Drop_Private, #PB_Drag_Move, #Drag_Listicon2)

; Note
TextGadget(4, 10, 550, 580, 20, "Note: Drag'n'Drop is only supported inside the same gadget (move of items only)!")


Exit = #False
DragItem = -1

;- Event loop
Repeat
  Event = WaitWindowEvent()
  EventType = EventType()
  EventGadget = EventGadget()
  
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget
          
        Case listview1, listview2, listicon1, listicon2
          Select EventType
            Case #PB_EventType_DragStart
              DragGadget = EventGadget   ; here we save the GadgetID of the listview, in which the drag operation started
              DragItem = GetGadgetState(DragGadget)
              ;Debug "DragGadget: " + Str(DragGadget)
              If DragGadget = listview1
                DragPrivate(#Drag_Listview1, #PB_Drag_Move)
              ElseIf DragGadget = listview2
                DragPrivate(#Drag_Listview2, #PB_Drag_Move)
              ElseIf DragGadget = listicon1
                DragPrivate(#Drag_Listicon1, #PB_Drag_Move)
              ElseIf DragGadget = listicon2
                DragPrivate(#Drag_Listicon2, #PB_Drag_Move)
              EndIf
          EndSelect
      EndSelect
      
    Case #PB_Event_GadgetDrop
      EventGadget = GetActiveGadget()
      TargetItem = GetGadgetState(EventGadget)
      ;Debug "DropGadget: " + Str(EventGadget) + ", TargetItem: " + Str(TargetItem)
      If EventDropPrivate() = #Drag_Listview1 Or EventDropPrivate() = #Drag_Listview2
        ListViewGadgetMove(EventGadget, DragItem, TargetItem)
      ElseIf EventDropPrivate() = #Drag_Listicon1 Or EventDropPrivate() = #Drag_Listicon2
        ListIconGadgetMove(EventGadget, DragItem, TargetItem)
      EndIf
      
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
  
Until Exit
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

I was able to test the code posted yesterday on MS Windows (XP SP 3) with PB 4.60 just now. And all works as expected (the listview item movement like implemented in my project, the listicon too with some less comfort - see the shorter ListIconGadgetMove() procedure).

So the problem must have something to do with MacOS and/or PB for Mac.... could anyone test it on his Mac too? Thank you.

(made a MacOS bug-report here, so this topic is also checked by the devs 8))
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Shardik »

Andre wrote:So the question is: Drag'n'Drop not supported for listviews and listicons on MacOS? ... a bug in PB? .... a bug in my code?
It seems to be a bug in the Mac's PB version: if you comment out
the 5 TextGadgets, Drag'n'Drop will work. But Drag'n'Drop seems
to be inhibited by the use of the TextGadgets, even if you replace
the Gadget# of the TextGadgets by #PB_ANY and correct a small
error in your code by replacing

Code: Select all

Select EventGadget()
with

Code: Select all

Select EventGadget
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by Andre »

@Shardik: thanks for testing! Good to know, that I've found a bug and I'm not the bug myself... :wink:
(The small mistake with EventGadget() is corrected in the source now.)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: ListView/ListIcon and correct using of Drag'n'Drop (move

Post by electrochrisso »

Thanks Andre, nice example. :)
PureBasic! Purely the best 8)
Post Reply