FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse Drag & Drop Question
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
xBrowse Drag & Drop Question
Posted: Tue Nov 23, 2010 03:24 PM

Hi,

I have an MDI window that can open up multiple child windows that contain transactions sorted by a sequence number.

I want to have the ability to drag one or more records from one browse to either another point in the same browse or to another point in another browse.

I can get the system to work fine if you are dragging and dropping in the same browse, but if i try to drop on another browse, the system does not reposition itself to where i release the mouse button. I've tried to do a ::oBrw:lButtonDown, ::oBrw:lButtonUp but it doesnt seem to work, the system just inserts the transactions at the current browse position instead of the mouse position. If i could reproduce the act of pressing the mouse button at the release point, the insert would work fine I think. For reference each window is a class object which i store a reference to the window and browse used.

FW 06.10 & xHarbour commercial

Thanks in advance

Pete

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse Drag & Drop Question
Posted: Tue Nov 23, 2010 03:50 PM

It is possible to have drag and drop on the same browse or a different browse. There is a recent post on this subject by Mr Otto with a nice example.

Regards



G. N. Rao.

Hyderabad, India
Posts: 363
Joined: Wed Feb 15, 2006 02:06 PM
Re: xBrowse Drag & Drop Question
Posted: Tue Nov 23, 2010 04:05 PM

Couldnt find the post - only could find where the drag would start even though you are not dragging!

Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: xBrowse Drag & Drop Question
Posted: Thu Nov 25, 2010 05:16 PM

Pete:

I had a similar situation dragging/dropping between two browses. In this case I'm browsing two arrays. I refer to browse 1 as a "Time" browse and browse 2 as a "Timeless" browse.

Here are the drag/drop definitions for each browse:

oBrw:bDragBegin := { |nRow,nCol,nKeyFlags| ;
SetDropInfo( {oBrw:nColSel, oBrw:nArrayAt, "B1"} ), oWnd:SetMsg("Dragging") }

oBrw:bDropOver := { |uDropInfo, nRow, nCol, nKeyFlags | ;
DragDrop(uDropInfo,nRow,nCol,nKeyFlags,oBrw,oBrw2) }

oBrw2:bDragBegin := { |nRow,nCol,nKeyFlags| ;
SetDropInfo( {oBrw2:nColSel, oBrw2:nArrayAt, "B2"} ), oWnd:SetMsg("Dragging") }

oBrw2:bDropOver := { |uDropInfo, nRow, nCol, nKeyFlags | ;
DragDrop2(uDropInfo,nRow,nCol,nKeyFlags,oBrw,oBrw2) }

As you can see I'm saving a value (B1,B2) so I can later determine which browse they are dropping to.

Here is the drag/drop functions for each browse. I hope this is not too convoluted as I've tried to cut out my code that is not applicable to your question.

STATIC FUNCTION DragDrop(uDropInfo,nRow,nCol,nKeyFlags,oBrw,oBrw2)

LOCAL nColPos
LOCAL x,i
LOCAL nRowFrom, nColFrom
LOCAL nRowTo, nColTo
LOCAL uButtonDown
LOCAL aPoint

// Dragging from time browse and dropping on time browse.
IF uDropInfo[3] == "B1"
// Reposition browse cursor to drop location
oBrw:lButtonDown(nRow, nCol, nKeyFlags)
oBrw:lButtonUp(nRow, nCol, nKeyFlags)
// Get the drop to row and column
nRowTo := oBrw:Cargo
nColTo := oBrw:nColSel
// Dragging from timeless browse & dropping on time browse
ELSE
// Reposition browse cursor to drop location
if nRow > 32000
nRow = - ( 65535 - nRow )
endif

  if nCol > 32000 
     nCol = - ( 65535 - nCol ) 
  endif

  aPoint = { nRow, nCol }

  aPoint = ClientToScreen( GetFocus(), aPoint ) 
  ScreenToClient( oBrw:hWnd, aPoint )

  nRow := aPoint[1]
  nCol := aPoint[2]

  uButtonDown := oBrw:lButtonDown(nRow, nCol, nKeyFlags)
  oBrw:lButtonUp(nRow, nCol, nKeyFlags)
  // Unable to set row,col on browse. Must have dropped somewhere outside valid cell
  IF uButtonDown = nil
     RETURN NIL
  ENDIF 
  // Get the drop to row and column
  nRowTo := oBrw:Cargo
  nColTo := oBrw:nColSel

ENDIF

// Initialize the drop FROM row and column variables
nColFrom := uDropInfo[1]
nRowFrom := uDropInfo[2]

i := nRowFrom

// Set column we are dragging from
nColPos := nColFrom

IF uDropInfo[3] == "B1"

  // Do some of my own stuff..

  // Set column we are dragging to
  nColPos := nColTo

  // Get subscript for new date/time
  IF nColPos == 1

.. Do some things here

     oBrw:Refresh()

  ENDIF

ELSE

  ... Do some things


  // Set column we are dragging to
  nColPos := nColTo

  oBrw:Refresh()

ENDIF

oBrw2:Refresh()

RETURN NIL

STATIC FUNCTION DragDrop2(uDropInfo,nRow,nCol,nKeyFlags,oBrw,oBrw2)

LOCAL nColPos
LOCAL x,y,i
LOCAL nRowFrom, nColFrom
LOCAL nRowTo, nColTo
LOCAL uButtonDown

local aPoint

// Dragging from time browse and dropping on timeless browse.
IF uDropInfo[3] == "B1"
// Reposition browse cursor to drop location
if nRow > 32000
nRow = - ( 65535 - nRow )
endif

  if nCol > 32000 
     nCol = - ( 65535 - nCol ) 
  endif

  aPoint = { nRow, nCol }

  aPoint = ClientToScreen( GetFocus(), aPoint ) 
  ScreenToClient( oBrw2:hWnd, aPoint )


  nRow := aPoint[1]
  nCol := aPoint[2]
  uButtonDown := oBrw2:lButtonDown(nRow, nCol, nKeyFlags)  
  oBrw2:lButtonUp(nRow, nCol, nKeyFlags)
  // Unable to set row,col on browse.  Must have dropped somewhere outside valid cell.
  IF uButtonDown = nil
     RETURN NIL
  ENDIF 
  // Get the drop to row and column
  nRowTo := oBrw2:Cargo
  nColTo := oBrw2:nColSel

// Dragging & dropping on timeless browse
ELSE
// Reposition browse cursor to drop location
oBrw2:lButtonDown(nRow, nCol, nKeyFlags)
oBrw2:lButtonUp(nRow, nCol, nKeyFlags)
// Get the drop to row and column
nRowTo := oBrw2:Cargo
nColTo := oBrw2:nColSel
ENDIF

nColFrom := uDropInfo[1]
nRowFrom := uDropInfo[2]

i := nRowFrom

// Set column we are dragging from
nColPos := nColFrom

IF uDropInfo[3] == "B1"

  ... Do some things here

  // Set column we are dragging to
  nColPos := nColTo

ELSE

  ... Do some things here

  // Set subscript into array based on column position
  IF nColPos == 2

     ... Do some checking here

  ELSE
     // Couldn't determine, i.e. must be invalid
     RETURN NIL
  ENDIF

  // Set column we are dragging to
  nColPos := nColTo

ENDIF

... Do some things

RETURN NIL

Posts: 284
Joined: Mon Oct 24, 2005 08:04 PM
Re: xBrowse Drag & Drop Question
Posted: Thu Nov 25, 2010 05:20 PM

Pete:

Also, I saved the row in the browse cargo:

oBrw:bSkip := { | nSkip, nOld | ;
iif(nSkip == nil, nSkip := 1, ),;
nOld := oBrw:nArrayAt,;
oBrw:nArrayAt += nSkip,;
oBrw:nArrayAt := Min( Max( oBrw:nArrayAt, 1 ), len( oBrw:aArrayData ) ),;
oBrw:cargo := oBrw:nArrayAt, oBrw:nArrayAt - nOld }

Regards,
Randal

Continue the discussion