Some modifications to tget/tcontrol/twindow

Post Reply
User avatar
AlexSchaft
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Some modifications to tget/tcontrol/twindow

Post by AlexSchaft »

Hi,

I've got some child dialogs that have single controls on them, in which case vk_tab does not do anything, but the class doesn't return it either.

I made these modifications:

tget.prg

Code: Select all

Method KeyChar

...
      case nKey == VK_TAB .and. GetKeyState( VK_SHIFT )
           // AS 23/07/2007 Changes as per 2007/01 FWH
           if ::bChange != nil .and. ( ::oGet:Changed .or. ( ::oGet:buffer != nil .and. ::oGet:UnTransform() != ::oGet:Original ) )
//           if ::bChange != nil
              lAccept = Eval( ::bChange, nKey, nFlags, Self )
              if ValType( lAccept ) == "L" .and. lAccept
                 if Upper( ::oWnd:ClassName() ) == "TCOMBOBOX"
                    ::oWnd:oWnd:GoPrevCtrl( ::hWnd )
                 else
                    IF !::oWnd:GoNextCtrl( ::hWnd )
                      return Super:KeyChar( nKey, nFlags )
                    endif
                 endif
              endif
           else
              if Upper( ::oWnd:ClassName() ) == "TCOMBOBOX"
                 ::oWnd:oWnd:GoPrevCtrl( ::hWnd )
              else
                 IF !::oWnd:GoNextCtrl( ::hWnd )
                  return Super:KeyChar( nKey, nFlags )
                endif
              endif
           endif
           return 0

      case nKey == VK_TAB .or. nKey == VK_RETURN
					 
           if ::bChange != nil .and. ( ::oGet:Changed .or. ( ::oGet:buffer != nil .and. ::oGet:UnTransform() != ::oGet:Original ) )
//           if ::bChange != nil
              lAccept = Eval( ::bChange, nKey, nFlags, Self )
              if ValType( lAccept ) == "L" .and. lAccept
                 IF !::oWnd:GoNextCtrl( ::hWnd )
                  return Super:KeyChar( nKey, nFlags )
                endif
              endif
           else
              if !::oWnd:GoNextCtrl( ::hWnd )
                return Super:KeyChar( nKey, nFlags )
              endif

           endif

           #ifndef __CLIPPER__
               if nKey == VK_RETURN  // Execute DEFPUSHBUTTON Action
                  Super:KeyChar( nKey, nFlags )
               endif
           #endif

           return 0

control.prg

Code: Select all

Method KeyChar

.
.
.
      case nKey == VK_TAB  .and. GetKeyState( VK_SHIFT ) .and. ::oWnd:GoPrevCtrl( ::hWnd )
           return 0    // We don't want API default behavior

      case nKey == VK_TAB .and. len(::oWnd:aControls) > 1 .and. ::oWnd:GoNextCtrl( ::hWnd )
           return 0    // We don't want API default behavior

window.prg

Code: Select all

METHOD KeyDown( nKey, nFlags ) CLASS TWindow

   local bKeyAction := SetKey( nKey )
   local nRetval := 0

   // AS 12/06/2007 Only process tab if there are controls to do it for
   // if nKey == VK_TAB .and. ::oWnd != nil .and. GetKeyState( VK_SHIFT )
   if nKey == VK_TAB .and. ::oWnd != nil .and. GetKeyState( VK_SHIFT ) .and. ::oWnd:GoPrevCtrl( ::hWnd )
      return 0
   endif

   // AS 12/06/2007 Only process tab if there are controls to do it for
//   if nKey == VK_TAB .and. ::oWnd != nil
   if nKey == VK_TAB .and. ::oWnd != nil .and. ::oWnd:GoNextCtrl( ::hWnd )
      return 0
   endif

METHOD GoNextCtrl( hCtrl ) CLASS TWindow

   local hCtlNext := NextDlgTab( ::hWnd, hCtrl )
   local lRetval := .f.
   ::hCtlFocus = hCtlNext


   if ! Empty( ::aControls ) .and. hCtrl == ::LastActiveCtrl():hWnd //ATail( ::aControls ):hWnd
      if ! Empty( ::oWnd ) .and. ;
         ( Upper( ::oWnd:ClassName() ) == "TFOLDER" .or. ;
           Upper( ::oWnd:ClassName() ) == "TPAGES" )
         hCtlNext = NextDlgTab( ::oWnd:oWnd:hWnd, ::oWnd:hWnd )
         ::hCtlFocus = hCtrl
      endif
   endif

   // Fix for Combobox with Dropdown by IOZ 12/06/00
   if hCtlNext == hCtrl .and. Upper(getclassname(hCtrl)) == "EDIT"
      hCtlNext := NextDlgTab( GetParent(::hWnd), hCtrl )
   endif

   if hCtlNext != hCtrl .and. hCtlNext != 0
      SetFocus( hCtlNext )
      lRetval := .t.
   endif

return lRetval

//----------------------------------------------------------------------------//

METHOD GoPrevCtrl( hCtrl ) CLASS TWindow

   local hCtlPrev := NextDlgTab( ::hWnd, hCtrl, .t. )
   local n, cFoldName
   local lRetval := .f.

   #ifdef __CLIPPER__
      cFoldName = "TFOLDER"
   #else
      cFoldName = "SYSTABCONTROL32"
   #endif

   ::hCtlFocus = hCtlPrev

   if ! Empty( ::aControls ) .and. hCtrl == ::FirstActiveCtrl():hWnd //::aControls[ 1 ]:hWnd
      if ! Empty( ::oWnd ) .and. ;
         ( Upper( ::oWnd:ClassName() ) == "TFOLDER" .or. ;
           Upper( ::oWnd:ClassName() ) == "TPAGES" )
         hCtlPrev = NextDlgTab( ::oWnd:oWnd:hWnd, ::oWnd:hWnd, .t. )
         ::hCtlFocus = hCtrl
      endif
   endif

   If hCtlPrev != hCtrl .and. hCtlPrev != 0
      If Upper( GetClassName( hCtlPrev ) ) == cFoldName .or. ;
         Upper( GetClassName( hCtlPrev ) ) == "TPAGES"
         n = AScan( ::aControls, { | o | o:hWnd == hCtlPrev } )
         if n > 0
            ::aControls[ n ]:aDialogs[ ::aControls[ n ]:nOption ]:LastActiveCtrl():SetFocus()
            lRetval := .t.
         endif
      else
         SetFocus( hCtlPrev )
         lRetval := .t.
      endif
   endif

return lRetval

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Alex,

Do you mean child windows instead of child dialogs ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
AlexSchaft
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Post by AlexSchaft »

No, child dialogs, as in

DEFINE DIALOG ::oDlg ;
OF ::oBrwMgr:oBrw ;
Color ::oBrwMgr:oBrw:nClrText, rgb(224,224,224) ;
FONT oApp():oFnt ;
PIXEL FROM anDim[1], anDim[2] TO anDim[1] + nHeight, anDim[2] + nWidth;
STYLE nor(WS_POPUP, WS_VISIBLE)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Alex,

Modal or Non modal ones ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
AlexSchaft
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Post by AlexSchaft »

Modal.

I'm busy building a line edit of custom controls on top of a browse with each control in a modal dialog. When the user presses up/down/tab/enter, etc in the control in the single control dialog, I need to catch it. That's why I made GoNextCtrl/GoPrevCtrl return a logical indicating focus was changed.

Alex
Post Reply