Focus rectangle initially not shown (modern theme support)

Windows specific forum
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Focus rectangle initially not shown (modern theme support)

Post by Little John »

Hi,

I tested with PB 5.72 LTS and 5.73 beta 3 on Windows 10.
The problem only exists here when the compiler option
[v] Enable modern theme support (for Windows XP and above)
is checked.

Code: Select all

OpenWindow(0, 100, 100, 150, 150, "Focus test")
ButtonGadget(0, 30,  20, 80, 30, "Button 0")
ButtonGadget(1, 30,  60, 80, 30, "Button 1")
ButtonGadget(2, 30, 100, 80, 30, "Button 2")
SetActiveGadget(0)

Repeat
   event = WaitWindowEvent()
   Select event
      Case #PB_Event_Gadget
         Debug "Button #" + GetActiveGadget()
   EndSelect     
Until event = #PB_Event_CloseWindow
After pressing the TAB key (repeatedly), I see the focus rectangle on Button 1 (Button 2 etc.). OK.

But since it reads in the code

Code: Select all

SetActiveGadget(0)
the focus rectangle should be on Button 0 right after the program start. However, it is not visible at all.

Is this a bug?
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Focus rectangle initially not shown (modern theme suppor

Post by chi »

Et cetera is my worst enemy
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Focus rectangle initially not shown (modern theme suppor

Post by Little John »

Dooh! This old issue?
I almost had forgotten about that. Thanks for reminding me!
This bug was marked [Done] in 2009, but was only partially fixed or reoccurred partially. :shock:
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Focus rectangle initially not shown (modern theme suppor

Post by Fred »

It's not a bug, the focus rectangle should appears only after use TAB at least once. You can check this behaviour in the Print Preview panel of Notepad for example.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Focus rectangle initially not shown (modern theme suppor

Post by Little John »

Thanks for looking into this issue, Fred.
Fred wrote:It's not a bug, the focus rectangle should appears only after use TAB at least once.
Sorry, that doesn't make sense to me.
The focus rectangle should show which gadget the focus has, no?
Immediately after running the above code snippet, Button0 has the focus.
This can be demonstrated by pressing [Space] right after the start of the program.
And since in that situation Button0 has the focus, the focus rectangle should be visible on Button0.
This is pure logic (no pun intended), and this is required for flawless usability,
and this is independent from what Notepad does do or does not do.

And when Modern Theme Support is switched OFF, the focus rectangle IS shown on Button0!
So are you saying that there is a bug without Modern Theme Support?
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Focus rectangle initially not shown (modern theme suppor

Post by Fred »

It's not a bug, it's a guide line for modern theme, which is to hide the focus rectangle unless keyboard is involved (may be for touch screen etc). It's the default behaviour of Windows app, so we follow it.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Focus rectangle initially not shown (modern theme suppor

Post by Little John »

Fred wrote:It's not a bug, the focus rectangle should appears only after use TAB at least once.
I searched on the internet, and found this:
[u]Raymond Chen[/u] wrote:The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE­UI­STATE message with UIS_INITIALIZE after the dialog has been initialized, which turns off the indicators if the last input event was a mouse event. This is its way of inferring whether the dialog box was triggered by a mouse or keyboard action and setting the initial indicators accordingly. (Note that if the user checked Underline keyboard shortcuts and access keys, then the dialog manager leaves the indicators enabled regardless of the last input event.)

That special WM_UPDATE­UI­STATE message is what gives dialog boxes the extra special feature of hiding the keyboard accelerators until you use the keyboard.

But notice that only the dialog manager does this. If you want this behavior in your own non-dialog windows, you will need to send the message yourself.
No, I don't want this behavior in my own non-dialog windows, so there is no need for PB to send this message. :-)
Fred wrote:You can check this behaviour in the Print Preview panel of Notepad for example.
On my system (Windows 10), it depends. The behaviour is as Raymond Chen wrote: When I open that dialog by using the mouse, no focus indicator is shown. But when I open that dialog by using the keyboard, then a focus indicator is shown on the topmost combobox, immediately when the dialog is shown! (And I never pressed the TAB key in that situation.)

I also found this:
[u]Microsoft Guidelines for Keyboard User Interface Design[/u] wrote:When designing a keyboard UI, use the following guidelines for input focus:
  • Make the input focus obvious.
    Make input focus visually distinguishable in a way that is obvious, intuitive, and easily seen.
    [...]
  • Display an input focus indicator.
    Display an input focus indicator when the window first opens or becomes active.
    For exceptions to this guideline, see Input Focus Exceptions.
So yes, there are exceptions, but the rule is: "Display an input focus indicator when the window first opens or becomes active.".
Post Reply