1. Win32lib focus problem

Try this piece of code:

without warning
include win32lib.ew
integer main, mle, msgedit

main = create(Window, "Click in the one-line text-edit and press enter", 0, 200,
200, 500, 300, 0)

mle = create(MleText, "", main, 0, 0, 450, 100, 0)
msgedit = create(EditText, "", main, 0, 150, 450, 23, 0)

WinMain(main, Normal)


Pressing enter in the EditText will automatically give focus to the MleText!
Why?
I tried to do a work-around by setting the focus to the EditText when
receiving a VK_ENTER keypress. Didn't work. The focus was still set to
the MleText. Then I tried setting focus to the MleText. And that gave focus
to the EditText! Win32lib seems to mix them up. And this work-around
will stop working when this bug is fixed :(

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

new topic     » topic index » view message » categorize

2. Re: Win32lib focus problem

> }}}
<eucode>
> 
> without warning
> include win32lib.ew
> integer main, mle, msgedit
> 
> main = create(Window, "Click in the one-line text-edit and press enter", 0,
> 200, 200, 500, 300, 0)
> 
> mle = create(MleText, "", main, 0, 0, 450, 100, 0)
> msgedit = create(EditText, "", main, 0, 150, 450, 23, 0)

I'm not sure why this happens, but add this, I tested it and it works.

procedure msgedit_keypress( integer self, integer event, sequence params )

    if params[1] = VK_RETURN then
        -- ignore the Enter key
        returnValue(-1)
    end if

end procedure
setHandler( msgedit, w32HKeyPress, routine_id("msgedit_keypress") )


> WinMain(main, Normal)
> 
> </eucode>
{{{


~Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: Win32lib focus problem

Greg Haberek wrote:
> 
> > }}}
<eucode>
> > 
> > without warning
> > include win32lib.ew
> > integer main, mle, msgedit
> > 
> > main = create(Window, "Click in the one-line text-edit and press enter", 0,
> > 200, 200, 500, 300, 0)
> > 
> > mle = create(MleText, "", main, 0, 0, 450, 100, 0)
> > msgedit = create(EditText, "", main, 0, 150, 450, 23, 0)
> 
> I'm not sure why this happens, but add this, I tested it and it works.
> 
> }}}
<eucode>
> procedure msgedit_keypress( integer self, integer event, sequence params )
> 
>     if params[1] = VK_RETURN then
>         -- ignore the Enter key
>         returnValue(-1)
>     end if
> 
> end procedure
> setHandler( msgedit, w32HKeyPress, routine_id("msgedit_keypress") )
> </eucode>
{{{

> 
> > WinMain(main, Normal)
> > 
> > </eucode>
{{{

> 
> ~Greg
> 

I tried using that technique. However, I was still setting the focus to
the msgedit after that, having the effect of activating the mle.
Your solution works wonderfully

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

new topic     » goto parent     » topic index » view message » categorize

4. Re: Win32lib focus problem

Alexander Toresson wrote:
> 
> Greg Haberek wrote:
> > 
> > > }}}
<eucode>
> > > 
> > > without warning
> > > include win32lib.ew
> > > integer main, mle, msgedit
> > > 
> > > main = create(Window, "Click in the one-line text-edit and press enter",
> > > 0, 200, 200, 500, 300, 0)
> > > 
> > > mle = create(MleText, "", main, 0, 0, 450, 100, 0)
> > > msgedit = create(EditText, "", main, 0, 150, 450, 23, 0)
> > 
> > I'm not sure why this happens, but add this, I tested it and it works.
> > 
> > }}}
<eucode>
> > procedure msgedit_keypress( integer self, integer event, sequence params )
> > 
> >     if params[1] = VK_RETURN then
> >         -- ignore the Enter key
> >         returnValue(-1)
> >     end if
> > 
> > end procedure
> > setHandler( msgedit, w32HKeyPress, routine_id("msgedit_keypress") )
> > </eucode>
{{{

> > 
> > > WinMain(main, Normal)
> > > 
> > > </eucode>
{{{

> > 
> > ~Greg
> > 
> 
> I tried using that technique. However, I was still setting the focus to
> the msgedit after that, having the effect of activating the mle.
> Your solution works wonderfully
> 

If you look up the documentation for EditText you will find ...

Note that when the user presses the Return Key, the focus will move to 
the next control in the focus order. To prevent this from happening, you
need to set a w32HKeyPress handler that sets the return value to -1 when
a VK_RETURN key without shifts is received.

procedure IgnoreReturn(integer self, integer event, sequence parms)
    if parms[1] = VK_RETURN and parms[2] = 0 then
        returnValue(-1)
    end if
end procedure
setHandler(myEditField, w32HKeyPress, routine_id("IgnoreReturn"))

--------------------

I put this in because the common thing that people do when pressing
Return in an Edit field is to think that they have finished with that
field and now wants to deal with the next field. It is in effect the
same as pressing Tab in the field.

But now that I can see that it could be awkward to change this behaviour
in some circumstances, I will add a new property to controls so that
you can use this behaviour (or not) on a per control basis.  


-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view message » categorize

5. Re: Win32lib focus problem

Derek Parnell wrote:
> 
> Alexander Toresson wrote:
> > 
> > Greg Haberek wrote:
> > > 
> > > > }}}
<eucode>
> > > > 
> > > > without warning
> > > > include win32lib.ew
> > > > integer main, mle, msgedit
> > > > 
> > > > main = create(Window, "Click in the one-line text-edit and press enter",
> > > > 0, 200, 200, 500, 300, 0)
> > > > 
> > > > mle = create(MleText, "", main, 0, 0, 450, 100, 0)
> > > > msgedit = create(EditText, "", main, 0, 150, 450, 23, 0)
> > > 
> > > I'm not sure why this happens, but add this, I tested it and it works.
> > > 
> > > }}}
<eucode>
> > > procedure msgedit_keypress( integer self, integer event, sequence params )
> > > 
> > >     if params[1] = VK_RETURN then
> > >         -- ignore the Enter key
> > >         returnValue(-1)
> > >     end if
> > > 
> > > end procedure
> > > setHandler( msgedit, w32HKeyPress, routine_id("msgedit_keypress") )
> > > </eucode>
{{{

> > > 
> > > > WinMain(main, Normal)
> > > > 
> > > > </eucode>
{{{

> > > 
> > > ~Greg
> > > 
> > 
> > I tried using that technique. However, I was still setting the focus to
> > the msgedit after that, having the effect of activating the mle.
> > Your solution works wonderfully
> > 
> 
> If you look up the documentation for EditText you will find ...
> 
> Note that when the user presses the Return Key, the focus will move to 
> the next control in the focus order. To prevent this from happening, you
> need to set a w32HKeyPress handler that sets the return value to -1 when
> a VK_RETURN key without shifts is received.
> 
> }}}
<eucode>
> procedure IgnoreReturn(integer self, integer event, sequence parms)
>     if parms[1] = VK_RETURN and parms[2] = 0 then
>         returnValue(-1)
>     end if
> end procedure
> setHandler(myEditField, w32HKeyPress, routine_id("IgnoreReturn"))
> </eucode>
{{{

> --------------------
> 
> I put this in because the common thing that people do when pressing
> Return in an Edit field is to think that they have finished with that
> field and now wants to deal with the next field. It is in effect the
> same as pressing Tab in the field.
> 
> But now that I can see that it could be awkward to change this behaviour
> in some circumstances, I will add a new property to controls so that
> you can use this behaviour (or not) on a per control basis.  
The current method shuold be the default since
some of my programs use it.

Also, why did this happen? "Then I tried setting focus
to the MleText. And that gave focus
to the EditText!"

> 
> 
> -- 
> Derek Parnell
> Melbourne, Australia
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: Win32lib focus problem

CoJaBo wrote:
> 
> Derek Parnell wrote:

[snip]
> > But now that I can see that it could be awkward to change this behaviour
> > in some circumstances, I will add a new property to controls so that
> > you can use this behaviour (or not) on a per control basis.  
> The current method shuold be the default since
> some of my programs use it.

Oh yes, that's what I meant. I'll just put in a way to make it easier to
change from the default behaviour.
 
> Also, why did this happen? "Then I tried setting focus
> to the MleText. And that gave focus
> to the EditText!"
> 

I can't tell unless I see your code. Can you create a tiny program that
demonstrates this effect?

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view message » categorize

7. Re: Win32lib focus problem

Derek Parnell wrote:
<big snip> 
> But now that I can see that it could be awkward to change this behaviour
> in some circumstances, I will add a new property to controls so that
> you can use this behaviour (or not) on a per control basis.  
> 

Yeah, I'm developing a chat app, and it's not good if the message display
mle is activated when a user sends a message.

Regards, Alexander Toresson

Shhh! Be vewy quiet! I'm hunting wuntime ewwows!

new topic     » goto parent     » topic index » view message » categorize

8. Re: Win32lib focus problem

Derek,

Is this the same focus problem?

I'm running 98SE and if I modify Generic.exw by adding a child window,
i.e. add the line

child = create( Window, "Untitled - " & App, Generic, 0.05, 0.05, 0.9, 0.9, 0 ),

after

Generic = create( Window, "Untitled - " & App, 0, 0.05, 0.05, 0.9, 0.9, 0 ),

and add the line

openWindow(child, 0)

before

WinMain( Generic, Normal )

then after a first successful attempt, subsequent clicks on save,
save as or open cause the dialog box to lose focus.

The mod. runs OK on V0.60 30/June/2004.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu