FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xbrowse drag / drop (to Mr. Rao)
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
xbrowse drag / drop (to Mr. Rao)
Posted: 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 (fw): Select all Collapse
#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 (fw): Select all Collapse
    // 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 8.x, BCC 7.3
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Tue Nov 05, 2024 01: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 (fw): Select all Collapse
#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
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Tue Nov 05, 2024 04: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.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Tue Nov 05, 2024 05:21 PM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Tue Nov 05, 2024 07: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.08 with Harbour
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Tue Nov 05, 2024 08:16 PM
I found a sample from Maurizio :
https://forums.fivetechsupport.com/viewtopic.php?f=3&t=39249
Code (fw): Select all Collapse
#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.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Wed Nov 06, 2024 03:32 AM
This also works
Btw
Code (fw): Select all Collapse
oBrw:SetPos( r, c, .t. )
is a short-cut for
Code (fw): Select all Collapse
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
Posts: 92
Joined: Fri Nov 18, 2005 11:15 PM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Wed Nov 06, 2024 03:57 AM

Thanks! Mr Rao. It works perfect!.

Ralph del Castillo

Lima PERU

Fwh 24.07, xHb123_10193, MySQL 8.x, BCC 7.3
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Wed Nov 06, 2024 09: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.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xbrowse drag / drop (to Mr. Rao)
Posted: Thu Nov 07, 2024 04: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

Continue the discussion