Combobox scroll (function PopupBrowse())

Re: Combobox scroll (function PopupBrowse())

Postby horacio » Tue Dec 22, 2015 12:48 pm

Antonio, he probado con oGet:oWnd:bMoved = { || oGet:Cargo := nil, oDlg:End() } tal cual me sugeriste, si bien cierra el combo al picar sobre la barra de título no funciona al seleccionar con el ratón y deja de funcionar la rueda del mismo. Adjunto un ejemplo autocontenido

Code: Select all  Expand view

#include 'Fivewin.ch'

//----------------------------------------------------------------------------//
Function Main()

    Local oDlg
    Local oGet := Array( 2, 0 )
    Local cVar := { Space( 20 ), Space( 20 ) }
   
    Define Dialog oDlg
   
        @ 10, 10 Get oGet[ 1 ] Var cVar[ 1 ] Size 100, 10 Of oDlg Action PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 1 ], { || .t. } ) Pixel
        @ 35, 10 Get oGet[ 2 ] Var cVar[ 2 ] Size 100, 10 Of oDlg Action PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 2 ], { || .t. } ) Pixel

    Activate Dialog oDlg On Init oDlg : lHelpIcon := .f. Centered
    Return 0

//----------------------------------------------------------------------------//
Function PopupBrowse( aValue, oGet, bInit )

   Local oDlg
    Local oBrw
   Local aPoint := { oGet : nTop + oGet : nHeight, oGet : nLeft }

   If( oGet : Cargo == nil )
      aPoint = ClientToScreen( oGet : oWnd : hWnd, aPoint )
      Define Dialog oDlg Of oGet : oWnd Style WS_POPUP Size 250, 180
      Activate Dialog oDlg NoWait On Init oDlg : SetPos( aPoint[ 1 ], aPoint[ 2 ] )
      @ 0, 0 xBrowse oBrw Array aValue Size oDlg : nWidth, oDlg : nHeight Of oDlg Pixel
      oBrw : CreateFromCode()
        If( bInit # Nil )
        Eval( bInit, oBrw )
      End   
      oBrw : PostMsg( WM_SETFOCUS )
      oBrw : bKeyDown   := { | nKey | If( nKey == VK_RETURN, oDlg : End(), ) }
      oBrw : bChange    := { || oGet:VarPut( oBrw:aCols[ 1 ]:Value ), oGet:Refresh() }
      oBrw : bLButtonUp := { | nRow, nCol | If( nRow > oBrw : nHeaderHeight,;
                                     ( Eval( oBrw : bChange ), oDlg : End(),;
                                         oGet : oWnd : GoNextCtrl( oGet : hWnd ),;
                                         oGet : Cargo := nil ), ) }
      oGet : bLostFocus       := { || oGet : Cargo := nil, oDlg : End() }
      oGet : oWnd : bGotFocus := { || oGet : Cargo := nil, oDlg : End() }
      //oGet : oWnd : bMMoved   := { || oGet : Cargo := nil, oDlg : End() }
      oGet : oWnd : bMoved   := { || oGet : Cargo := nil, oDlg : End() }
      oBrw : Seek( oGet : GetText() )
      oGet : Cargo := oDlg
      oGet : bKeyDown := { | nKey | If( nKey == VK_DOWN, oBrw : GoDown(), ),;
                                    If( nKey == VK_UP, oBrw : GoUp(), ),;
                                    If( nKey == VK_DELETE, ( oGet : VarPut( 0 ), oGet : Refresh(), oDlg : End() ), ),;
                                    If( nKey == VK_RETURN, oDlg : End(), ), 0 }
      oGet : oWnd : bLClicked   := { || oDlg:End(), oGet:Cargo := nil }
      oGet : oWnd : bMouseWheel := { || oDlg : SetFocus() }
   Else
      oGet : Cargo : End()
      oGet : Cargo = nil
   End
    Return nil
 


Muchas gracias.
Saludos
horacio
 
Posts: 1358
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Combobox scroll (function PopupBrowse())

Postby Antonio Linares » Wed Dec 23, 2015 6:57 am

Horacio,

Gracias por tus pruebas. Esta versión parece funcionar bien:

Code: Select all  Expand view
function PopupBrowse( aValue, oGet, bInit )

   local oDlg, oBrw
   local aPoint := { oGet:nTop + oGet:nHeight, oGet:nLeft }

   if oGet:Cargo == nil
      aPoint = ClientToScreen( oGet:oWnd:hWnd, aPoint )

      DEFINE DIALOG oDlg OF oGet:oWnd STYLE WS_POPUP ;
         SIZE 500, 180

      ACTIVATE DIALOG oDlg NOWAIT ;
         ON INIT oDlg:SetPos( aPoint[ 1 ], aPoint[ 2 ] )

      @ 0, 0 XBROWSE oBrw DATASOURCE aValue AUTOSORT ;
         SIZE oDlg:nWidth, oDlg:nHeight OF oDlg PIXEL

      oBrw:CreateFromCode()

      Eval( bInit, oBrw )

      oBrw:PostMsg( WM_SETFOCUS )
      oBrw:bKeyDown = { | nKey | If( nKey == VK_RETURN, oDlg:End(), ) }
      oBrw:bChange = { || oGet:VarPut( oBrw:aCols[ 1 ]:Value ), oGet:Refresh() }
      oBrw:bLButtonUp = { | nRow, nCol | If( nRow > oBrw:nHeaderHeight,;
                          ( Eval( oBrw:bChange ), oDlg:End(),;
                            oGet:oWnd:GoNextCtrl( oGet:hWnd ),;
                            oGet:Cargo := nil ),) }
      oGet:bLostFocus = { || If( GetFocus() != oDlg:hWnd, ( oGet:Cargo := nil, oDlg:End() ),) }
      oGet:oWnd:bGotFocus = { || oGet:Cargo := nil, oDlg:End() }
      oGet:oWnd:bMoved = { || oGet:Cargo := nil, oDlg:End() }

      oBrw:Seek( oGet:GetText() )

      oGet:Cargo = oDlg
      oGet:bKeyDown = { | nKey | If( nKey == VK_DOWN, oBrw:GoDown(),),;
                                 If( nKey == VK_UP, oBrw:GoUp(),),;
                                 If( nKey == VK_DELETE, ( oGet:VarPut(0), oGet:Refresh(), oDlg:End()),),;
                                 If( nKey == VK_RETURN, oDlg:End(),), 0 }

      oGet:oWnd:bLClicked = { || oDlg:End(), oGet:Cargo := nil }
      oGet:oWnd:bMouseWheel = { || oDlg:SetFocus() }
   else
      oGet:Cargo:End()
      oGet:Cargo = nil
   endif

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Combobox scroll (function PopupBrowse())

Postby horacio » Wed Dec 23, 2015 2:41 pm

Antonio, ahora funciona bien. Solo quedaría un detalle, me gustaría poder abrir el combo mediante el teclado tal cual lo hace el combo ordinario presionando F4. El problema que se presenta es que si bien en el get configuro la tecla para que esto suceda, el xbrowse no llega a tener foco y no puedo seleccionar, salvo que sea con el ratón. Mando un ejemplo.

Code: Select all  Expand view

#include 'Fivewin.ch'

//----------------------------------------------------------------------------//
Function Main()

    Local oDlg
    Local oGet := Array( 2, 0 )
    Local cVar := { Space( 20 ), Space( 20 ) }
   
    Define Dialog oDlg
   
        @ 10, 10 Get oGet[ 1 ] Var cVar[ 1 ] Size 100, 10 Of oDlg Action PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 1 ], { || .t. } ) Pixel
        oGet[ 1 ] : bKeyDown := { | nKey | If( nKey == VK_F4, PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 1 ], { || .t. } ), ) }
        @ 35, 10 Get oGet[ 2 ] Var cVar[ 2 ] Size 100, 10 Of oDlg Action PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 2 ], { || .t. } ) Pixel

    Activate Dialog oDlg On Init oDlg : lHelpIcon := .f. Centered
    Return 0

//----------------------------------------------------------------------------//
function PopupBrowse( aValue, oGet, bInit )

   Local oDlg
    Local oBrw
   Local aPoint := { oGet:nTop + oGet:nHeight, oGet:nLeft }

   If( oGet : Cargo == Nil )
    aPoint := ClientToScreen( oGet : oWnd : hWnd, aPoint )
      Define Dialog oDlg OF oGet : oWnd Style WS_POPUP Size 500, 180

      Activate Dialog oDlg NoWait On Init oDlg : SetPos( aPoint[ 1 ], aPoint[ 2 ] )

      @ 0, 0 xBrowse oBrw DataSource aValue Size oDlg : nWidth, oDlg : nHeight Of oDlg Pixel
      oBrw : CreateFromCode()
        If( bInit # Nil )
        Eval( bInit, oBrw )
      End
        oBrw : PostMsg( WM_SETFOCUS )
      oBrw : bKeyDown := { | nKey | If( nKey == VK_RETURN, oDlg : End(), ) }
      oBrw : bChange  := { || oGet:VarPut( oBrw : aCols[ 1 ] : Value ), oGet : Refresh() }
      oBrw:bLButtonUp := { | nRow, nCol | If( nRow > oBrw : nHeaderHeight,;
                                          ( Eval( oBrw : bChange ), oDlg : End(),;
                                                oGet : oWnd : GoNextCtrl( oGet : hWnd ),;
                                            oGet : Cargo := Nil ), ) }
      oGet : bLostFocus       := { || If( GetFocus() != oDlg : hWnd, ( oGet : Cargo := Nil, oDlg : End() ), ) }
      oGet : oWnd : bGotFocus := { || oGet : Cargo := nil, oDlg : End() }
      oGet : oWnd : bMoved    := { || oGet : Cargo := Nil, oDlg : End() }
      oBrw : Seek( oGet : GetText() )
      oGet : Cargo               := oDlg
      oGet : bKeyDown            := { | nKey | If( nKey == VK_DOWN, oBrw : GoDown(), ),;
                                                If( nKey == VK_UP, oBrw:GoUp(), ),;
                                                If( nKey == VK_DELETE, ( oGet : VarPut( 0 ), oGet : Refresh(), oDlg : End() ), ),;
                                                If( nKey == VK_RETURN, oDlg : End(), ), 0 }
      oGet : oWnd : bLClicked   := { || oDlg : End(), oGet : Cargo := nil }
      oGet : oWnd : bMouseWheel := { || oDlg : SetFocus() }
   Else
      oGet:Cargo:End()
      oGet:Cargo = nil
   End
    Return Nil
 


Muchas gracias.

Saludos
horacio
 
Posts: 1358
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: Combobox scroll (function PopupBrowse())

Postby Antonio Linares » Wed Dec 23, 2015 7:39 pm

Horacio,

Cambia esta línea asi:

oGet[ 1 ] : bKeyDown := { | nKey | If( nKey == VK_F4, PopupBrowse( { 'UNO', 'DOS', 'TRES' }, oGet[ 1 ], { | oBrw | oBrw:SetFocus(), .t. } ), ) }
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Combobox scroll (function PopupBrowse())

Postby horacio » Wed Dec 23, 2015 10:38 pm

Antonio, ahora hace foco en el xBrowse. pero al querer abrir nuevamente el combo la tecla ya no responde. Eliminé la siguiente linea.

Code: Select all  Expand view

oGet : bKeyDown := { | nKey | If( nKey == VK_DOWN, oBrw : GoDown(), ),;
If( nKey == VK_UP, oBrw:GoUp(), ),;
If( nKey == VK_DELETE, ( oGet : VarPut( 0 ), oGet : Refresh(), oDlg : End() ), ),;
If( nKey == VK_RETURN, oDlg : End(), ), 0 }
 

Ahora la tecla funciona, la primera vez presionando una vez pero después presionando dos veces para que ejecute la acción.
Muchas gracias

Saludos
horacio
 
Posts: 1358
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests