Modify KeyDown in xBrowse sub-classing

Modify KeyDown in xBrowse sub-classing

Postby Rick Lipkin » Thu Aug 02, 2012 10:06 pm

To All

I am re-visiting modifying the KeyDown method in xBrowse to include the use of the TAB key to be able to move right one cell ..

I can modify xBrowse with this change :

Code: Select all  Expand view

case nKey == VK_TAB        // added  rick lipkin

      if GetKeyState( VK_CONTROL )
         ::GoRightMost()
      else
         ::GoRight()
      endif

 


But I do not want to make the same change as I upgrade from one FWH to another. I have looked at the Sub-Classing example ( xBrChild.prg ).. but I do not seem to be able to adapt the above code.

I would appreciate any suggestions on how to modify the entire KeyDown method and apply the above modification to my code.

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modify KeyDown in xBrowse sub-classing

Postby carlos vargas » Fri Aug 03, 2012 2:29 am

Rick
if you use xharbour or harbour you can use :
override method
example:

Code: Select all  Expand view

...
   OVERRIDE METHOD GetDlgCode IN CLASS TButton WITH KGetDlgCode

RETURN

/*-------------------------------------------------------------------------------------------------*/
/**/
FUNCTION KGetDlgCode( nLastKey )
   LOCAL Self := HB_QSelf()

   ::oWnd:nLastKey := nLastKey

   DO CASE
   CASE ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TFOLDER"   ) .or. ::oWnd:oWnd:IsKindOf( "TFOLDEREX" )      )
      RETURN DLGC_WANTALLKEYS
   CASE nLastKey == VK_ESCAPE .and. ::oWnd:oWnd != NIL .and. ( ::oWnd:oWnd:IsKindOf( "TWINDOW"   ) .and. ::oWnd:IsKindOf( "TDIALOG" ) )
      RETURN DLGC_WANTALLKEYS
   ENDCASE

RETURN NIL
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1720
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Modify KeyDown in xBrowse sub-classing

Postby Rick Lipkin » Fri Aug 03, 2012 5:46 pm

Carols

Thank you for your kind example .. I have added

Code: Select all  Expand view

OVERRIDE METHOD KeyDown IN CLASS TXBrowse WITH RKeyDown
 


At the top of my program and added the over-ride method in my code ( and that works fine ) .. I seem to be having problems with defining the parameters for the RKeyDown function parameters ..

I inserted xbrowse.prg into my program and was able to get the value of nFlags ( 983041 ) but can not figure out to trap the nKey value ...Here is the error and picture of the code.

Any help would be greatly appreciated

Rick

Code: Select all  Expand view

Application
===========
   Path and name: C:\Fox\Sa\Saw32.Exe (32 bits)
   Size: 3,779,584 bytes
   Compiler version: xHarbour build 1.2.1 Intl. (SimpLex) (Rev. 9444)
   FiveWin  Version: FWHX 12.03
   Windows version: 5.1, Build 2600 Service Pack 3

   Time from start: 0 hours 0 mins 9 secs
   Error occurred at: 08/03/2012, 09:00:54
   Error description: Warning BASE/1005  Message not found: TDIALOG:_NKEY

Stack Calls
===========
   Called from: source\rtl\tobject.prg => TDIALOG:ERROR( 0 )
   Called from: source\rtl\tobject.prg => TDIALOG:MSGNOTFOUND( 0 )
   Called from: source\rtl\tobject.prg => TDIALOG:_NKEY( 0 )
   Called from: FUNC_LIB.PRG => TXBROWSE:RKEYDOWN( 493 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1700 )
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11630 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3159 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 980 )
   Called from: Main.prg => MAIN( 234 )
 


Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modify KeyDown in xBrowse sub-classing

Postby carlos vargas » Fri Aug 03, 2012 6:23 pm

please post the full method redefined

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1720
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Modify KeyDown in xBrowse sub-classing

Postby Rick Lipkin » Fri Aug 03, 2012 6:29 pm

Carlos

This is the same Keydown method used in txbrowse .. I have only added the VK_TAB case.

Rick

Code: Select all  Expand view

// placed at the top of my program Main()

OVERRIDE METHOD KeyDown IN CLASS TXBrowse WITH RKeyDown
...
...
...



//----------------------------------
FUNCTION RKeyDown( nKey,nFlags )

   LOCAL Self := HB_QSelf()  // Rick Added
   local oCol

   nFlags := 983041             // rick added
   ::oWnd:nKey := nKey       // rick added

   do case
   case nKey == VK_ESCAPE
        if ::lEditMode
           oCol := ::SelectedCol()
           if oCol:oEditLbx != nil
              oCol:oEditLbx:nLastKey = VK_ESCAPE
           endif
           if oCol:oEditGet != nil
              oCol:oEditGet:nLastKey := VK_ESCAPE
           endif
           ::CancelEdit()
           return 0
        else
           return Super:KeyDown( nKey, nFlags )
        endif

   case nKey == VK_LEFT  .and. GetKeyState( VK_SHIFT ) .or. ;
        nKey == VK_RIGHT .and. GetKeyState( VK_SHIFT )
        return Super:KeyDown( nKey, nFlags )

     case nKey == VK_UP .and. GetKeyState( VK_SHIFT )
        ::Select( 5 )
        ::GoUp()
        ::Select( 5 )

     case nKey == VK_DOWN .and. GetKeyState( VK_SHIFT )
        ::Select( 5 )
        ::GoDown()
        ::Select( 5 )

   case nKey == VK_UP
      ::Select( 0 )
      ::GoUp()
      ::Select( 1 )

   case nKey == VK_DOWN
      ::Select( 0 )
      ::GoDown()
      ::Select( 1 )

   case nKey == VK_LEFT

      if GetKeyState( VK_CONTROL )
         ::GoLeftMost()
      else
         ::GoLeft()
      endif

   case nKey == VK_RIGHT

      if GetKeyState( VK_CONTROL )
         ::GoRightMost()
      else
         ::GoRight()
      endif

   case nKey == VK_TAB        // added  rick lipkin

      if GetKeyState( VK_CONTROL )
         ::GoRightMost()
      else
         ::GoRight()
      endif


   case nKey == VK_HOME
         ::Select( 0 )
         ::GoTop()
         ::Select( 1 )

   case nKey == VK_END
         ::Select( 0 )
         ::GoBottom()
         ::Select( 1 )

   case nKey == VK_PRIOR
         ::Select( 0 )
         if GetKeyState( VK_CONTROL )
            ::GoTop()
         else
            ::PageUp()
         endif
         ::Select( 1 )

   case nKey == VK_NEXT
         ::Select( 0 )
         if GetKeyState( VK_CONTROL )
            ::GoBottom()
         else
            ::PageDown()
         endif
         ::Select( 1 )

   case nKey == VK_ADD .and. GetKeyState( VK_CONTROL )
         ::FontSize( +1 )
         ::Refresh()

   case nKey == VK_SUBTRACT .and. GetKeyState( VK_CONTROL )
         ::FontSize( -1 )
         ::Refresh()

   case ::lAllowCopy .and. nKey == ASC( 'C' ) .and. GetKeyState( VK_CONTROL )
         ::Copy()

   case nKey == VK_F2 .and. ::lF2KeyToEdit
        if ! ::lEditMode
            ::SelectedCol():Edit()
        endif

   otherwise

      return Super:KeyDown( nKey, nFlags )

   endcase

return 0

 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Modify KeyDown in xBrowse sub-classing

Postby carlos vargas » Fri Aug 03, 2012 7:22 pm

rick, the error is correct

in my source the data nKey no exist in tdialog or twindow class.

::oWnd -> object content the xbrowse object, in this case is a tdialog, how tdialog derivate from twindow,
i search the nkey data in both class and not found. sorry. :-(

if you extend the tdialog class
with

EXTEND CLASS TDIALOG WITH DATA nKey

work, but error in line with

return Super:KeyDown( nKey, nFlags )

i search for a solution....


salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1720
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Modify KeyDown in xBrowse sub-classing

Postby carlos vargas » Fri Aug 03, 2012 7:34 pm

i think what

return Super:KeyDown( nKey, nFlags )

is

return TDialog():KeyDown( nKey, nFlags )


alguien con conocimientos en objetos, puede confirmar esto?
Code: Select all  Expand view

   OVERRIDE METHOD KeyDown    IN CLASS TXBrowse WITH RKeyDown
   EXTEND CLASS TDIALOG WITH DATA nKey
RETURN

/*-------------------------------------------------------------------------------------------------*/
/**/
FUNCTION RKeyDown( nKey, nFlags )

   LOCAL Self := HB_QSelf()  // Rick Added
   local oCol

   nFlags := 983041             // rick added

   ::oWnd:nKey := nKey       // rick added

   do case
   case nKey == VK_ESCAPE
        if ::lEditMode
           oCol := ::SelectedCol()
           if oCol:oEditLbx != nil
              oCol:oEditLbx:nLastKey = VK_ESCAPE
           endif
           if oCol:oEditGet != nil
              oCol:oEditGet:nLastKey := VK_ESCAPE
           endif
           ::CancelEdit()
           return 0
        else
           return Super:KeyDown( nKey, nFlags )
        endif

   case nKey == VK_LEFT  .and. GetKeyState( VK_SHIFT ) .or. ;
        nKey == VK_RIGHT .and. GetKeyState( VK_SHIFT )
        return Super:KeyDown( nKey, nFlags )

     case nKey == VK_UP .and. GetKeyState( VK_SHIFT )
        ::Select( 5 )
        ::GoUp()
        ::Select( 5 )

     case nKey == VK_DOWN .and. GetKeyState( VK_SHIFT )
        ::Select( 5 )
        ::GoDown()
        ::Select( 5 )

   case nKey == VK_UP
      ::Select( 0 )
      ::GoUp()
      ::Select( 1 )

   case nKey == VK_DOWN
      ::Select( 0 )
      ::GoDown()
      ::Select( 1 )

   case nKey == VK_LEFT

      if GetKeyState( VK_CONTROL )
         ::GoLeftMost()
      else
         ::GoLeft()
      endif

   case nKey == VK_RIGHT

      if GetKeyState( VK_CONTROL )
         ::GoRightMost()
      else
         ::GoRight()
      endif

   case nKey == VK_TAB        // added  rick lipkin

      if GetKeyState( VK_CONTROL )
         ::GoRightMost()
      else
         ::GoRight()
      endif


   case nKey == VK_HOME
         ::Select( 0 )
         ::GoTop()
         ::Select( 1 )

   case nKey == VK_END
         ::Select( 0 )
         ::GoBottom()
         ::Select( 1 )

   case nKey == VK_PRIOR
         ::Select( 0 )
         if GetKeyState( VK_CONTROL )
            ::GoTop()
         else
            ::PageUp()
         endif
         ::Select( 1 )

   case nKey == VK_NEXT
         ::Select( 0 )
         if GetKeyState( VK_CONTROL )
            ::GoBottom()
         else
            ::PageDown()
         endif
         ::Select( 1 )

   case nKey == VK_ADD .and. GetKeyState( VK_CONTROL )
         ::FontSize( +1 )
         ::Refresh()

   case nKey == VK_SUBTRACT .and. GetKeyState( VK_CONTROL )
         ::FontSize( -1 )
         ::Refresh()

   case ::lAllowCopy .and. nKey == ASC( 'C' ) .and. GetKeyState( VK_CONTROL )
         ::Copy()

   case nKey == VK_F2 .and. ::lF2KeyToEdit
        if ! ::lEditMode
            ::SelectedCol():Edit()
        endif

   OTHERWISE

      return TDialog():KeyDown( nKey, nFlags )

   endcase

return 0
 

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1720
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Modify KeyDown in xBrowse sub-classing

Postby Rick Lipkin » Fri Aug 03, 2012 7:53 pm

Carlos

Thank You!! your suggestions WORKED GREAT.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA



Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 111 guests