xBRowser drag & drop question

xBRowser drag & drop question

Postby Otto » Mon Jan 07, 2008 6:30 pm

Is there somewhere an example how to drag&drop inside a xBrowser.
Thanks in advance
Otto
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby nageswaragunupudi » Tue Jan 08, 2008 3:03 am

Mr Otto
Please test this program
Code: Select all  Expand view
#include 'fivewin.ch'

FUNCTION Main()

LOCAL oWnd, oBrw, oCur, i, aData := {}

   FOR i := 1 TO 6
      AAdd( aData, { str(i,2), "Description " + Str( i ), Replicate( Chr( 64 + i ), 5 ) } )
   NEXT i

   DEFINE CURSOR oCur DRAG
   DEFINE WINDOW oWnd
   oBrw      := TXBrowse():New( oWnd )
   oBrw:SetArray( aData )
   oBrw:CreateFromCode()
   oWnd:oClient := oBrw
   //
   oBrw:oDragCursor   := oCur
   oBrw:bDragBegin   := { |nRow,nCol,nFlags| DragBegin( nRow, nCol, nFlags, oBrw ) }
   oBrw:bDropOver      := { |uDropInfo, nRow, nCol, nFlags| DropOver( uDropInfo, nRow, nCol, nFlags, oBrw ) }
   //
   ACTIVATE WINDOW oWnd
   oCur:End()

RETURN NIL

STATIC FUNCTION DragBegin( nRow, nCol, nFlags, oBrw )

   SetDropInfo( EVAL( oBrw:SelectedCol():bStrData ) )

RETURN NIL

STATIC FUNCTION DropOver( uDropInfo, nRow, nCol, nFlags, oBrw )

   oBrw:lButtonDown( nRow, nCol, nFlags)
   oBrw:lButtonUp(   nRow, nCol, nFlags)

   MsgInfo( uDropInfo + CRLF + 'dropped on' + CRLF + ;
            EVAL( oBrw:SelectedCol():bStrData ) )

RETURN NIL
Regards

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

Postby Enrico Maria Giordano » Tue Jan 08, 2008 7:56 am

Nice sample, thank you!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Otto » Tue Jan 08, 2008 5:30 pm

NageswaraRao, thank you very much.
I was so free to put it on www.fwcodesnips.com
Best regards,
Otto
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby Otto » Thu Jan 10, 2008 5:48 pm

Hello NageswaraRao,

I filled your example with real data and inserted a function to scroll during drag.
Dragbegin gives me the record which I drag.
Dropover the record where I drop.

But now I am a little uncertain how to change the position of the records in the browser and refresh the browser.
Maybe you have an advice for me.

www.atzwanger.com/lexikon/lexikon.zip
is what I have so far.

Best regards
Otto

Image
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby nageswaragunupudi » Fri Jan 11, 2008 2:20 pm

Do you want that if the cursor goes above browse area it should page up and if it goes below browse area if should page down?

If so please try the following code
Code: Select all  Expand view
function CheckListbox( nRow, nCol, oBrw, oLbx, nKeyFlags,oChild )

   if nRow < oBrw:HeaderHeight()
      oBrw:PageUp()
   elseif nRow > ( oBrw:BrwHeight() - oBrw:FooterHeight() )
      oBrw:PageDown()
   endif

return nil

Please let me know if this is what you were looking for.
Regards

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

Postby Otto » Fri Jan 11, 2008 3:02 pm

NageswaraRao,
thank you for your help. Your code is better than that I had.
Scrolling is working.
But what is the best way to change the record position. Sure I have to use an index.
But then?
Best regards,
Otto
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby nageswaragunupudi » Fri Jan 11, 2008 3:03 pm

Even with indexes this code works fine. What more do you want to do ?
Regards

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

Postby Otto » Fri Jan 11, 2008 4:43 pm

Hello NageswaraRao,

Peach
Fillet of perch
Swiss sautéed turkey
Smoked salmon
Mushrooms on toast
Bacon


For example: I drag <Fillet of perch> and drop it over <Bacon> then the new order
should be:

Peach
Swiss sautéed turkey
Smoked salmon
Mushrooms on toast
Fillet of perch
Bacon

Best regards,
Otto
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Postby Enrico Maria Giordano » Fri Jan 11, 2008 4:47 pm

You must swap the content of the two records or swap just the content of an indexed field.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby nageswaragunupudi » Fri Jan 11, 2008 4:50 pm

Obviously if we want to achieve what he wants, we need to have a separate order column and play with the order serial numbers there. I am working on it
Regards

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

Postby nageswaragunupudi » Fri Jan 11, 2008 4:55 pm

Ofcourse with arrays it is very easy and simple. Just delete the dragged row and insert before the row on which it is dropped.
Regards

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

Postby nageswaragunupudi » Fri Jan 11, 2008 5:36 pm

Mr Otto,

Here is the solution. First you restructure the dbf like this.

1) Change the NUMMER field as NUMERIC with Width 18 and Decimals 13. ( NUMMER, 'N', 18, 13 ).
2) Create Index on NUMMER field. I have used DBFCDX and created a TAG with name NUMMER.

Having done upto this please make the following changes in your code:
Code: Select all  Expand view
before function Main:
REQUEST DBFCDX

// change the dbf open code like this:

    USE  C:\FWH\samples\LEXIKON.DBF  NEW ALIAS LEX EXCLUSIVE VIA 'DBFCDX'
    DBEVAL( {|| LEX->NUMMER := RECNO() } )
    SET ORDER TO TAG NUMMER
    GO TOP

// replace the new drag and drop functions given below

STATIC FUNCTION DragBegin( nRow, nCol, nFlags, oBrw )

   SetDropInfo( (oBrw:cAlias)->( recno() ) )

RETURN NIL

STATIC FUNCTION DropOver( uDropInfo, nRow, nCol, nFlags, oBrw )

   LOCAL nDragRec := uDropInfo
   LOCAL nThisRec
   LOCAL nThisKey
   LOCAL nPrevKey := 0

   oBrw:lButtonDown( nRow, nCol, nFlags )
   oBrw:lButtonUp(   nRow, nCol, nFlags )

   nThisRec       := (oBrw:cAlias)->( RECNO() )
   nThisKey       := (oBrw:cAlias)->NUMMER

   ( oBrw:cAlias )->( dbSKIP( -1 ) )
   IF !(oBrw:cAlias)->( bof() )
      nPrevKey      := ( oBrw:cAlias )->NUMMER
   ENDIF
   ( oBrw:cAlias )->( dbGOTO( nDragRec ) )
   ( oBrw:cAlias )->NUMMER   := ( nThisKey + nPrevKey ) / 2
   ( oBrw:cAlias )->( dbGOTO( nThisRec ) )
   oBrw:Refresh()

RETURN NIL


Now you will get the effect you are looking for.
I shall send revised prg and dbf to your personal email
Regards

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

Postby James Bott » Fri Jan 11, 2008 6:08 pm

NageswaraRao,

I am curious, why 13 decimal places for your nummer field? Recno()'s are integers.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Fri Jan 11, 2008 6:31 pm

All is working. Thank you very much.
Best regards,
Otto
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests