Page 1 of 1

Bug in TControl

PostPosted: Thu Mar 02, 2006 10:29 pm
by Enrico Maria Giordano
The ESC key is disabled in the following sample (but it is not the only one) in the March build:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL oGet, cVar := SPACE( 30 )

    DEFINE DIALOG oDlg

    @ 1, 1 GET oGet VAR cVar MEMO

    @ 3, 1 BUTTON "&Close";
           ACTION oDlg:End()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


It seems that the cause is a change in TControl:

Code: Select all  Expand view
METHOD KeyDown( nKey, nFlags ) CLASS TControl

   if nKey == VK_ESCAPE
      ::oWnd:KeyDown( nKey, nFlags )
      return 0
   endif


This is the previous working version:

Code: Select all  Expand view
METHOD KeyDown( nKey, nFlags ) CLASS TControl

   if nKey == VK_ESCAPE
      ::oWnd:KeyChar( nKey, nFlags )
      return 0
   endif


EMG

PostPosted: Fri Mar 03, 2006 12:14 am
by Antonio Linares
Enrico,

This fix looks as the right one in Class TMultiGet:
Code: Select all  Expand view
   if nKey == VK_ESCAPE  // Windows API already sends it to dialogs!!!
      if ::oWnd:ChildLevel( TDialog() ) != 0 .and. ::oWnd:lModal
         return Super:KeyChar( nKey, nFlags ) // nil
      endif
      ...

PostPosted: Fri Mar 03, 2006 8:33 am
by Enrico Maria Giordano
It's not enough:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oBrw

    DEFINE DIALOG oDlg

    @ 1, 1 LISTBOX oBrw FIELDS SIZE 100, 30

    oBrw:bKeyChar = { || Tone( 440, 1 ) }

    @ 3, 1 BUTTON "&Close";
           ACTION oDlg:End()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


What was the reason why you changed bKeyChar to bKeyDown in TControl:KeyDown() method?

EMG

PostPosted: Fri Mar 03, 2006 9:08 am
by Antonio Linares
Enrico,

Because it had some wrong side effects

PostPosted: Fri Mar 03, 2006 9:15 am
by Antonio Linares
Enrico,

In dialog.prg copy Method KeyChar() to Method KeyDown() and it gets fixed.

Anyhow, we are curious to know why the ESC comes now by KeyDown() instead of KeyChar().

PostPosted: Fri Mar 03, 2006 9:21 am
by Enrico Maria Giordano
Please, can you show the exact fix?

EMG

PostPosted: Fri Mar 03, 2006 9:23 am
by Antonio Linares
Enrico,
Code: Select all  Expand view
METHOD KeyDown( nKey, nFlags ) CLASS TDialog

   if nKey == VK_ESCAPE
      if ::oWnd == nil
         ::End()
      else
         if ::oWnd:ChildLevel( TMdiChild() ) != 0
            ::End()
         else
            if ::oWnd:ChildLevel( TDialog() ) != 0
               ::End()
            #ifdef __HARBOUR__
            elseif Upper( ::oWnd:ClassName() ) == "TMDIFRAME" // To avoid ESC being ignored
               ::End()
            #endif
            else
               return Super:KeyDown( nKey, nFlags )
            endif
         endif
      endif
   else
      return Super:KeyDown( nKey, nFlags )
   endif

return nil

PostPosted: Fri Mar 03, 2006 9:42 am
by Enrico Maria Giordano
It seems to work, thank you. Do I have to leave KeyChar() method in place or do I have to remove it?

EMG

PostPosted: Fri Mar 03, 2006 9:57 am
by Enrico Maria Giordano
Antonio Linares wrote:Enrico,

This fix looks as the right one in Class TMultiGet:
Code: Select all  Expand view
   if nKey == VK_ESCAPE  // Windows API already sends it to dialogs!!!
      if ::oWnd:ChildLevel( TDialog() ) != 0 .and. ::oWnd:lModal
         return Super:KeyChar( nKey, nFlags ) // nil
      endif
      ...


This is no more needed.

EMG

PostPosted: Fri Mar 03, 2006 2:05 pm
by Antonio Linares
Enrico,

Thanks