Problem with Escape key and dialog on MDI child

Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 3:37 pm

I am having trouble fixing a problem when a user presses escape key on a MDI child window with dialog.
Either the dialog box closes and leaves and empty MDI child or I have problems with valid or disappearing menu.

I went back to basics and looked at sample testmdi4.prg
I found another reference in this forum about using GETKEYSTATE( VK_ESCAPE ) on the valid clause of activate dialog.
After some trial and error i have the following issue.
If I use a counter it seems the valid is called multiple times with 1 escape key press.
I wanted to try setting the valid to .t. if the escape key is pressed 2 times but remain if the escape key is pressed only 1 time.
I added the following valid clause with the counter checked for < 2 escape key pressed to return .f.. Unfortunately with 1 escape key press the dialog is closed code and the mdi child remains.
Code: Select all  Expand view

  local nCounter := 0 // Added to top of function child()

   ACTIVATE DIALOG oDlg NOWAIT ;  // It has to be NonModal --> NOWAIT clause
      ON INIT oDlg:Move( 0, 0 ) ;
      VALID  ( if( GETKEYSTATE( VK_ESCAPE ), nCounter++, nil ), ;
         tracelog( GETKEYSTATE( VK_ESCAPE ), nCounter ), ;
         if( GETKEYSTATE( VK_ESCAPE ) .and. nCounter < 2, .f. , .t. ) )
 


If I change the counter to return .f. if counter < 3. Now 1 escape key press and the dialog stays, The 2nd escape key press and the dialog closes with mdi window remaining.
The tracelog shows nCounter reached a total of 3. Somehow the valid clause is evaluated twice during the 1st escape key press.
Code: Select all  Expand view

  local nCounter := 0 // Added to top of function child()

   ACTIVATE DIALOG oDlg NOWAIT ;  // It has to be NonModal --> NOWAIT clause
      ON INIT oDlg:Move( 0, 0 ) ;
      VALID  ( if( GETKEYSTATE( VK_ESCAPE ), nCounter++, nil ), ;
         tracelog( GETKEYSTATE( VK_ESCAPE ), nCounter ), ;
         if( GETKEYSTATE( VK_ESCAPE ) .and. nCounter < 3, .f. , .t. ) )    // Changed to check for 3 times
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Problem with Escape key and dialog on MDI child

Postby Rick Lipkin » Tue Sep 19, 2017 4:22 pm

Gale

You are close ... add this to your ON INIT move ....

Code: Select all  Expand view

ON INIT ( oDlg:Move( 0,0, oWndChildA:nWidth, oWndChildA:nHeight, .T. ), ;
 


This ties the Dialog to the child ..

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

Re: Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 6:01 pm

i will try that but how does that relate to problem pressing escape key?
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 6:19 pm

That did not work at all. In the sample testmdi4.prg there was code after the activate dialog that sizes the window to match the dialog.
Still the escape problem persists.
I have included the full modified testmdi4.prg
You will need the testmdi4.rc from the samples folder to run.

If you press the escape key 1 time the dialog goes away but the child window remains.
With the valid code it should at least stop the 1st time escape key press.

Code: Select all  Expand view

// This is an example of how to place controls inside a MDIChild
// from resources
// 5/9/2005 1:28PM: Updated by James Bott, jbott@compuserve.com

#include "FiveWin.ch"

static oWnd

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

function Main()

   local oBar

   SET _3DLOOK ON

   DEFINE WINDOW oWnd TITLE "MDIChilds from resources" MDI

   DEFINE BUTTONBAR oBar _3D OF oWnd

   DEFINE BUTTON OF oBar ACTION child() //( Child(), MsgInfo( oWnd:oWndClient:aWnd[ 1 ]:cCaption ) )

   ACTIVATE WINDOW oWnd maximized

return nil

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

function Child()

   local oWndChild, oDlg, oBtn, n
   local cName := "Testing..."
   local lExit := .f., nCounter := 0

   DEFINE WINDOW oWndChild MDICHILD OF oWnd ;
      FROM 5,5 TO 6,6;
      COLOR "N/W" ;
      border none  nomaximize nominimize // prevent resizing

   oWndChild:bGotFocus  = { || oDlg:SetFocus() }

   DEFINE DIALOG oDlg RESOURCE "Child1" OF oWndChild

   REDEFINE GET cName ID 110 OF oDlg

   REDEFINE BUTTON oBtn ID 120 OF oDlg ;
      ACTION ( MsgInfo( "First" ), oBtn:SetFocus() )


   REDEFINE BUTTON ID 130 OF oDlg ACTION MsgInfo( "Second" )

   for n = 1 to Len( oDlg:aControls )
      oDlg:aControls[ n ]:bLClicked = GenBlock( oWndChild, oDlg:aControls[ n ] )
   next

   ACTIVATE DIALOG oDlg NOWAIT ;  // It has to be NonModal --> NOWAIT clause
      ON INIT oDlg:Move( 0,0 ) ;
      VALID  ( if( GETKEYSTATE( VK_ESCAPE ), nCounter++, nil ), ;
         tracelog( GETKEYSTATE( VK_ESCAPE ), nCounter ), ;
         if( GETKEYSTATE( VK_ESCAPE ) .and. nCounter < 2, .f. , .t. ) )    // Changed to check for 3 times

   //  ON INIT oDlg:Move( 0,0, oWndChild:nWidth, oWndChild:nHeight, .T. )  ;  // this did not work because of the code below.

   // Correct window size to match dialog
   oWndChild:nWidth := oDlg:nWidth+7
   oWndChild:nHeight := oDlg:nHeight+32

   ACTIVATE WINDOW oWndChild ON INIT oWnd:paint()

return nil

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

function GenBlock( oWndChild, oControl )

return { || oWndChild:SetFocus(), oControl:SetFocus() }

//----------------------------------------------------------------------------//
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Problem with Escape key and dialog on MDI child

Postby Rick Lipkin » Tue Sep 19, 2017 8:25 pm

Gale

This is my code for MdiChild
Code: Select all  Expand view




      ACTIVATE DIALOG oInvt NOMODAL ;
                ON INIT( If( lViewQuery = .t., oQuery:Show(),oQuery:Hide() ),;
                         _Hidum( cMode,oBtn2,oBtn3,oBtn4),oVnum:SetFocus() );
                VALID(!GETKEYSTATE( 27 ))

ACTIVATE WINDOW oWndChildA ;
   ON INIT ( oInvt:Move( 0,0, oWndChildA:nWidth, oWndChildA:nHeight, .T. ), ;
           oWndChildA:bResized := {|| _ReSizeUm1( oInvt,oWndChildA ) }, ;
           oInvt:refresh(.t.));
   VALID ( IIF( !lOK3, _ExitPgm3(.T.,oWndChildA,oRsVeh,oLbx,@lOk3,oFontB), .F. ))


//-----------------------------------
Static Func _ReSizeUm1( oInvt,oWndChild )

// for inventory find

oInvt:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) // <----------------frame and dialog link

// dialog controls
oInvt:bResized = { | nSizeType, nWidth, nHeight | _ResizeControls1( nSizeType, nWidth, nHeight, oInvt )  }

Return(nil)

//---------------------------------------
Static Func _ResizeControls1( nSizeType, nWidth, nHeight, oDlg )

// for inventory find

if nSizeType = 0 //SIZE_MAXIMIZED         //37              //277
   oDlg:aControls[ 1  ]:SetSize( nWidth - 37, nHeight - 185 ) //txbrowse
endif

Return(nil)


 


My Error ... see this code in _ReSizeUm1() ...
Code: Select all  Expand view

oInvt:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. )
 


Place the above in your ON INIT code


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

Re: Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 9:05 pm

Sure but you cannot use escape key to close window.
I was just hoping that there was a fix for the escape key problem.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 9:36 pm

Is there something about changing the size of the dialog you think will fix the escape key problem?
You keep referring to setsize() as the fix but I don't see where that relates to my problem, unless i am missing something.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Problem with Escape key and dialog on MDI child

Postby Rick Lipkin » Tue Sep 19, 2017 9:56 pm

Gale

Code: Select all  Expand view

oInvt:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) // <----------------frame and dialog link
 

This code links the dialog to the mdi frame .. this will keep ESC from closing and leaving the mdi frame visible .. I add

Code: Select all  Expand view

VALID(!GETKEYSTATE( 27 ))
 

On the dialog to keep ESC from firing ..

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

Re: Problem with Escape key and dialog on MDI child

Postby Gale FORd » Tue Sep 19, 2017 10:09 pm

I have no problem keeping dialog from closing.
I was just trying to incorporate the escape key and fix some bugs that crop up as a result.

I guess there is no way to make MDI child with dialog work reliably with escape key.
Oh well.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 25 guests