xbrowse drag / drop (to Mr. Rao)

xbrowse drag / drop (to Mr. Rao)

Postby ralph » Mon Nov 04, 2024 10:17 pm

I asked Copilot to build a program to allow reorder rows in a list using drag & drop and xBrowse
This is the result:

Code: Select all  Expand view

#include "FiveWin.ch"
function Main()
    local oDlg, oBrw, aData

    aData := { ;
        { "Item 1", "Codigo 1", "Producto 1", 10, "Uni 1", 100, 5, 95 }, ;
        { "Item 2", "Codigo 2", "Producto 2", 20, "Uni 2", 200, 10, 190 }, ;
        { "Item 3", "Codigo 3", "Producto 3", 30, "Uni 3", 300, 15, 285 } ;
    }

    DEFINE DIALOG oDlg TITLE "Reordenar filas con Drag & Drop" SIZE 800, 400

    @ 10, 10 XBROWSE oBrw ARRAY aData OF oDlg ;
        COLUMNS { 1, 2, 3, 4, 5, 6, 7, 8 } ;
        HEADERS { "Item", "Codigo", "Nombre del producto", "Cantid", "Uni", "Pr.Unit", "Dscto", "Importe" } ;
        COLSIZES { 100, 100, 200, 100, 50, 100, 100, 100 } ;
        CELL LINES NOBORDER

    oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW
    oBrw:nColDividerStyle := LINESTYLE_BLACK
    oBrw:nRowDividerStyle := LINESTYLE_BLACK
    oBrw:lAllowRowSizing := .F.
    oBrw:lAllowColSwapping := .F.

    // Habilitar Drag & Drop
    oBrw:lDragDrop := .T.
    oBrw:bDragBegin := { |nRow| oBrw:nDragRow := nRow }
    oBrw:bDragEnd := { |nRow| ReorderRows( oBrw, nRow ) }

    ACTIVATE DIALOG oDlg CENTERED

return nil

function ReorderRows( oBrw, nRow )
    local aTemp

    if oBrw:nDragRow != nRow
        aTemp := oBrw:aArrayData[ oBrw:nDragRow ]
        ADel( oBrw:aArrayData, oBrw:nDragRow )
        AIns( oBrw:aArrayData, nRow, aTemp )
        oBrw:Refresh()
    endif

return nil

 

It uses some methods that do not exist (unless the IA read the future)

Code: Select all  Expand view

    // Habilitar Drag & Drop
    oBrw:lDragDrop := .T.
    oBrw:bDragBegin := { |nRow| oBrw:nDragRow := nRow }
    oBrw:bDragEnd := { |nRow| ReorderRows( oBrw, nRow ) }
 

To Mr. Rao: Is there a way to get this functionality ?
Ralph del Castillo
Lima PERU
Fwh 24.07, xHb123_10193, MySQL 5.5, BCC 7.3
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: xbrowse drag / drop (to Mr. Rao)

Postby nageswaragunupudi » Tue Nov 05, 2024 1:53 pm

FWH already had full support for Drag and Drop feature, not only inside Xbrowse but across all controls.
This feature has been there from the time of creation of FiveWin.
So, nothing futuristic.

Simple sample:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local aData, oCur

   USE STATES SHARED NEW
   aData := FW_DbfToArray()
   CLOSE STATES

   DEFINE CURSOR oCur HAND
   XBROWSER aData SETUP xSetup1( oBrw, oCur )
   RELEASE CURSOR oCur

return nil

function xSetup1( oBrw, oCur )

   oBrw:oDragCursor  := oCur

   oBrw:bDragBegin   := { |r,c,f| SetDropInfo( oBrw:nArrayAt ) }

   oBrw:bDropOver    := < |u,r,c,f|
      oBrw:SetPos( r, c, .t. )
      StackPush( oBrw:aRow )
      oBrw:aArrayData[ oBrw:nArrayAt ] := oBrw:aArrayData[ u ]
      oBrw:aArrayData[ u ] := StackPop()
      oBrw:Refresh()
      return nil
      >

return nil


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xbrowse drag / drop (to Mr. Rao)

Postby Marc Venken » Tue Nov 05, 2024 4:24 pm

Mr. Rao,

To insert the dropped item between the 2 target items where you want to drop means that we have to sort the items again ?

1
2
3
4
5
6

drop 6 on 3

1
2
3
6
4
5

How to do that ?
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: xbrowse drag / drop (to Mr. Rao)

Postby nageswaragunupudi » Tue Nov 05, 2024 5:21 pm

In case of arrays, if we sort again the very purpose of dropping is lost. Right?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xbrowse drag / drop (to Mr. Rao)

Postby Marc Venken » Tue Nov 05, 2024 7:12 pm

I would think (because of less experience) that

If I take 4 and drop on 2, the position in 4 is empty so resort would put the empty cell on top and make a new array starting from pos 2.

But I know that you have a much more elegant solution
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: xbrowse drag / drop (to Mr. Rao)

Postby Marc Venken » Tue Nov 05, 2024 8:16 pm

I found a sample from Maurizio :
https://forums.fivetechsupport.com/viewtopic.php?f=3&t=39249

Code: Select all  Expand view

#include "fivewin.ch"
#include "xbrowse.ch"

function main()

   local oDlg, oBrw, oFont, oCur, aData[ 12 ]

   AEval( aData, { |u,i| aData[ i ] := NtoCMonth( i ) } )

   DEFINE CURSOR oCur DRAG
   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 250,500 PIXEL FONT oFont
   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      DATASOURCE aData COLUMNS 1 CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nStretchCol      := 1
      :oDragCursor      := oCur
      :bDragBegin       := { |r,c,f,o| SetDropInfo( { oBrw:nArrayAt, oBrw:aRow } ) }
      :bDropOver        := { |u,r,c,f| oBrw:LButtonDown( r,c ), ;
                                       oBrw:LButtonUp( r,c ), ;
                                       aDel( aData, u[ 1 ] ), ;
                                       AIns( aData, oBrw:nArrayAt, u[ 2 ] ), ;
                                       oBrw:Refresh() }
      //
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont
   RELEASE CURSOR oCur

return nil

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: xbrowse drag / drop (to Mr. Rao)

Postby nageswaragunupudi » Wed Nov 06, 2024 3:32 am

This also works
Btw
Code: Select all  Expand view
oBrw:SetPos( r, c, .t. )

is a short-cut for
Code: Select all  Expand view
oBrw:LButtonDown( r,c )
oBrw:LButtonUp( r,c )

This short-cut is more optimal.

Also swapping arrays (actually pointers) is more optimal than ADel() and AIns()
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xbrowse drag / drop (to Mr. Rao)

Postby ralph » Wed Nov 06, 2024 3:57 am

Thanks! Mr Rao. It works perfect!.
Ralph del Castillo
Lima PERU
Fwh 24.07, xHb123_10193, MySQL 5.5, BCC 7.3
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: xbrowse drag / drop (to Mr. Rao)

Postby Marc Venken » Wed Nov 06, 2024 9:10 am

Swapping Array .....

What I found looks like this :

@ 20,10 BTNBMP PROMPT "ToExcel" SIZE 100,30 FLAT PIXEL OF oDlg ;
ACTION ( aCols := {}, ;
AEval( oBrw:aArrayData, { |a| If( a[ 1 ], AAdd( aCols, oBrowse:aCols[ a[ 2 ] ] ), nil ) } ), ;
oBrowse:ToExcel( nil, nil, aCols ) ;
)
______
XBROWSER aData TITLE "Array : Ctrl-Up/Dn for Swap Up/Dn"

AEval( aData, { |a,i| a[ 4 ] := i } )
_______
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1434
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: xbrowse drag / drop (to Mr. Rao)

Postby nageswaragunupudi » Thu Nov 07, 2024 4:25 am

The response to the main post of Mr.Ralph is that Drag and Drop feature is fully supported by FWin and no further changes are required.
This drag and drop support is not only inside xbrowse but also in between different controls/dialogs/windows.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests

cron