xBrowse Drag & Drop Question

xBrowse Drag & Drop Question

Postby PeterHarmes » Tue Nov 23, 2010 3: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
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: xBrowse Drag & Drop Question

Postby nageswaragunupudi » Tue Nov 23, 2010 3: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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Drag & Drop Question

Postby PeterHarmes » Tue Nov 23, 2010 4:05 pm

Couldnt find the post - only could find where the drag would start even though you are not dragging!
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: xBrowse Drag & Drop Question

Postby Randal » Thu Nov 25, 2010 5: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: xBrowse Drag & Drop Question

Postby Randal » Thu Nov 25, 2010 5: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
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests