FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Combobox scroll (function PopupBrowse())
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Combobox scroll (function PopupBrowse())
Posted: Tue Dec 22, 2015 12:48 PM
Antonio, he probado con oGet: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 (fw): Select all Collapse
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Combobox scroll (function PopupBrowse())
Posted: Wed Dec 23, 2015 06:57 AM
Horacio,

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

Code (fw): Select all Collapse
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
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Combobox scroll (function PopupBrowse())
Posted: Wed Dec 23, 2015 02: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 (fw): Select all Collapse
#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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Combobox scroll (function PopupBrowse())
Posted: Wed Dec 23, 2015 07: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
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 AM
Re: Combobox scroll (function PopupBrowse())
Posted: 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 (fw): Select all Collapse
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

Continue the discussion