Row/Col coordinates in oBrowse

This forum is for eXpress++ general support.
Post Reply
Message
Author
Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Row/Col coordinates in oBrowse

#1 Post by Zdeno Bielik »

Hi Roger,

please, how is it possible to get/retrieve number of column in oBrowse, where is mouse’s cursor just positioned/moved?
I need to know Row/Col coordinates not (only) for correct displaying in oStatusBar object, but for some next/associated tasks in one my app.

TIA & Regards
Zdeno

Code: Select all

#include "dcdialog.ch"
#include "appevent.ch"

**************
Procedure Main()
**************

LOCAL GetList[0], aDir := Directory(), oStatusCursor, oStatusMouse

Private pnRow := 0, pnCol := 0

@ 0,0 DCBROWSE oBrowse SIZE 45,20 DATA aDir ID 'BROWSER' FIT ;
        EVAL {|o|o:ItemMarked := {||oStatusCursor:SetCaption("You are in (cursor is into) ROW:" + alltrim(str(oBrowse:RowPos)) + ", COLUMN:" + alltrim(str(oBrowse:ColPos)))}}

*         EVAL {|o|o:ItemMarked := {||oStatusCursor:SetCaption("You are in (cursor is into) ROW:" + alltrim(str(oBrowse:RowPos)) + ", COLUMN:" + alltrim(str(oBrowse:ColPos))), ;
*         oStatusMouse:SetCaption("You are in (mouse is over) ROW:" + alltrim(str(M->pnRow)) + ", COLUMN:" + alltrim(str(M->pnCol)))} } ;

DCBROWSECOL ELEMENT 1 HEADER 'File Name' PARENT oBrowse
DCBROWSECOL ELEMENT 2 HEADER 'File Size' PARENT oBrowse
DCBROWSECOL ELEMENT 3 HEADER 'File Date' PARENT oBrowse
DCBROWSECOL ELEMENT 4 HEADER 'File Time' PARENT oBrowse

@ 22, 1 DCSAY '' SAYSIZE 50 SAYOBJECT oStatusCursor ID 'STATUSCURSOR'
@ 23, 1 DCSAY '' SAYSIZE 50 SAYOBJECT oStatusMouse  ID 'STATUSMOUSE'

DCREAD GUI FIT MODAL ;
       HANDLER MyHandler REFERENCE GetList ;
       EVAL { |o| SetAppWindow(o), ;
                  SetAppFocus( oBrowse ) ;
            }

RETURN

*

******************
FUNCTION MyHandler( nEvent, mp1, mp2, oXbp, oDialog, GetList )
******************

Local oBrowse       := DC_GetObject( GetList, 'BROWSER' )
Local nCurrentRow   := oBrowse:RowPos
Local nCurrentCol   := oBrowse:ColPos
Local oStatusCursor := DC_GetObject( GetList, 'STATUSCURSOR' )
Local oStatusMouse  := DC_GetObject( GetList, 'STATUSMOUSE'  )

M->pnRow := 0
M->pnCol := 0
oStatusMouse:SetCaption("You are in (mouse is over) ROW:" + alltrim(str(M->pnRow)) + ", COLUMN:" + alltrim(str(M->pnCol)))

If ( nEvent == xbeP_Keyboard )

*    oStatusCursor:SetCaption("You are in (cursor is into) ROW:" + alltrim(str(nCurrentRow)) + ", COLUMN:" + alltrim(str(nCurrentCol)) )

   IF mp1 == xbeK_ESC
        RETURN DCGUI_EXIT_ABORT
   ELSE
        RETURN DCGUI_NONE
   ENDIF


Else        && mouse events


    If ( nEvent == xbeP_Close )
       RETURN DCGUI_EXIT_ABORT


    ElseIf ( nEvent == xbeM_Motion ) .and. ( oXbp:className() == 'XbpCellGroup' )

       M->pnRow := oXbp:CellFromPos(mp1)
       M->pnCol := 0   && ???

       oStatusMouse:SetCaption("You are in (mouse is over) ROW:" + alltrim(str(M->pnRow)) + ", COLUMN:" + alltrim(str(M->pnCol)))


* nCurrentPos := oXbp:CurrentPos()
* nCurrentRow := oXbp:CellFromPos(mp1)
* aCellPos := oXbp:CellRect(nCurrentRow)
* dcdebug nCurrentRow, nCurrentCol, aCellPos, nCurrentPos


* cContent := oXbp:GetCell(nCurrentRow /*oXbp:CellFromPos(mp1)*/ )
* dcdebug cContent


* x:=DC_GetColArray(2,oBrowse)
* x:=oBrowse:arrayElement
* x:=oBrowse:colpos
* x:=Int((oXbp:currentSize()[2]-mp1[2]) / (oXbp:CellRect(1)[4]-oXbp:CellRect(1)[2]))

* dcdebug x

*           oBrowse:refreshCurrent()


          SetAppFocus( oBrowse )
          RETURN DCGUI_IGNORE


    ElseIf ( nEvent == xbeM_LbDown ) .and. ( oXbp:className() == 'XbpCellGroup' )
           lLbDown := .T.
* dcdebug 'LbDown', lLbDown

           RETURN DCGUI_IGNORE



    ElseIf ( nEvent == xbeM_LbUp ) .and. ( oXbp:className() == 'XbpCellGroup' )
           lLbDown := .F.
* dcdebug 'LbUp', lLbDown

           RETURN DCGUI_IGNORE



    ElseIf ( nEvent == xbeM_LbDblClick ) .and. ( oXbp:className() == 'XbpCellGroup' )

          RETURN DCGUI_IGNORE



  ElseIf ( nEvent == xbeP_KillInputFocus )

         RETURN DCGUI_IGNORE

  EndIf

EndIf

RETURN DCGUI_NONE

*

* EOF

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Row/Col coordinates in oBrowse

#2 Post by rdonnay »

Zdeno -

I don't understand your question.
I compiled and ran your sample program and it appears to be doing exactly what you want.
Please clarify your question.

Roger
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: Row/Col coordinates in oBrowse

#3 Post by Zdeno Bielik »

Hi Roger,

in this example I want display in oStatusMouse object actual Row and Col position of mouse’s cursor when mouse is moved over on cells in oBrowse object.
With Row number is not problem, only with Column number is problem, because now it is still 0 – I don’t know how to get correct value.

Zdeno

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Row/Col coordinates in oBrowse

#4 Post by rdonnay »

Are you saying that you want the mouse position relative to :
(1) 0,0 within each cell
(2) 0,0 within the browse
(3) 0,0 with the application window
(4) 0,0 within the desktop

????
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Row/Col coordinates in oBrowse

#5 Post by Auge_Ohr »

Zdeno Bielik wrote:

Code: Select all

FUNCTION MyHandler( nEvent, mp1, mp2, oXbp, oDialog, GetList )
Local oBrowse       := DC_GetObject( GetList, 'BROWSER' )

Local nCurrentRow   := oBrowse:RowPos
Local nCurrentCol   := oBrowse:ColPos
these Position are from hilite Cell
Zdeno Bielik wrote:

Code: Select all

If ( nEvent == xbeP_Keyboard )
keyboard action will move hilite Cell
Zdeno Bielik wrote:

Code: Select all

Else        && mouse events

    ElseIf ( nEvent == xbeM_Motion ) .and. ( oXbp:className() == 'XbpCellGroup' )

       M->pnRow := oXbp:CellFromPos(mp1)
       M->pnCol := 0   && ???
hm ... xbeM_Motion is from XbpWindow() ... not shure if a Browse have a o:motion :think:

a Browse:datarea or Columne is more that one XbpCellGroup -> XbpMultiCellGroup()

when Dragdrop i have to "calculate" my Mouse Position with API Function "GetCursorPos" this Way

Code: Select all

FUNCTION GetCurAbsPos( oXbp )
LOCAL cBuffer    := SPACE( 8 )
LOCAL aLBDnAtPos := { 0, 0 }
LOCAL aPos       := oXbp:currentpos()  // Parent Position

   ***** Get the absolute position of cursor (relative to DeskTop)
   DllCall( "User32.DLL", DLL_STDCALL, "GetCursorPos", @cBuffer )

   // extract X,Y Windows Position
   aLBDnAtPos[ 1 ] := Bin2U( SUBSTR( cBuffer, 1, 4 ) )
   aLBDnAtPos[ 2 ] := Bin2U( SUBSTR( cBuffer, 5, 4 ) )

  // Top-Down
   aLBDnAtPos[ 2 ] := ( - 1 * aLBDnAtPos[ 2 ] ) + APPDESKTOP() :CURRENTSIZE() [2] - 1 

   // Xbase++ Position relative to oXbp Parent
   aLBDnAtPos[ 1 ] -= aPos[ 1 ]
   aLBDnAtPos[ 2 ] -= aPos[ 2 ]

RETURN aLBDnAtPos
while IMHO you can not use oBrowse:motion you have to use a Trick : 4th Parameter of AppEvent() -> Timeout
if you use ot4xb you can use delegated_eval() to run it in GUI Thread
greetings by OHR
Jimmy

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: Row/Col coordinates in oBrowse

#6 Post by Zdeno Bielik »

- To Roger:
as you can see in attached picture, when oBrowse hilite cursor is in cell with content 05/04/2012, row/col hilite info is ok,
but when mouse’s cursor is over this cell, I don’t know, how to get correct value for my pnCol variable – I need get number 3...

so, when mouse’s cursor is over any cell in oColumn with name FileName, I need get number 1,
for positions over oColumn FileSize I need get 2, FileDate=3, FileTime=4...



- To Jimmy:
as reference example to play we can use FBrowse.prg in alaska’s samples\basic\guibrow directory

// Width and heading for columns
aHeading[ F_NAME ] := { 15, "File name" }
aHeading[ F_SIZE ] := { 8, "Size" }
aHeading[ F_WRITE_DATE ] := { 8, "Date" }
aHeading[ F_WRITE_TIME ] := { 8, "Time" }
aHeading[ F_ATTR ] := { 8, "Attribute" }
aHeading[ F_EA_SIZE ] := { 8, "Size of attr." }
aHeading[ F_CREATION_DATE ] := { 8, "Creation date" }
aHeading[ F_CREATION_TIME ] := { 8, "Creation time" }
aHeading[ F_ACCESS_DATE ] := { 8, "Access date" }
aHeading[ F_ACCESS_TIME ] := { 8, "Access time" }

so for F_NAME I need get number 1
for F_SIZE number 2
for F_ACCESS_TIME number 10


TIA & Regards
Zdeno
Attachments
RowColInBrowse.png
RowColInBrowse.png (38.15 KiB) Viewed 11327 times

User avatar
Tom
Posts: 1171
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Row/Col coordinates in oBrowse

#7 Post by Tom »

Hi, Zdeno.

What "position" do you want to know? oBrowse:RowPos is a relative position, which means, row 1 is always the topmost line of the browse, no matter if page one or page onethousand is shown (scrolled).

To find out what column is "behind" the mouse, just compare oXbp in your handler with every oBrowse:GetColumn(x):DataArea (or :heading) from 1 to oBrowse:ColCount. The one matching is the right one.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: Row/Col coordinates in oBrowse

#8 Post by Zdeno Bielik »

Hi Tom,

Just done! It works now how I need/want!
Thanks for showing me one way using :heading :dance:
And I found also next solution via CARGO slot of DCBROWSECOL, so now I have 2 options for solve this.

Zdeno

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Row/Col coordinates in oBrowse

#9 Post by rdonnay »

Thanks again Tom.
The eXpress train is coming - and it has more cars.

Post Reply