PureBasic Forum
https://www.purebasic.fr/english/

[solved] Button focus or lack of it
https://www.purebasic.fr/english/viewtopic.php?f=19&t=65288
Page 1 of 1

Author:  Julian [ Wed Mar 23, 2016 11:53 pm ]
Post subject:  [solved] Button focus or lack of it

I'm sure there's a simple solution. How do I enable the blue highlighting of buttons (focus) when pressing tab, as happens with other mac apps including the PB editor?

It just works in windows, so I'm a bit confused.

Thanks

Code:
OpenWindow(0, 0, 0, 100, 100, "Test")
ButtonGadget(0, 0, 0, 100, 30, "Test1")
ButtonGadget(1, 0, 35, 100, 30, "Test2")

Repeat
 
Until WaitWindowEvent() = #PB_Event_CloseWindow

Author:  wilbert [ Thu Mar 24, 2016 5:56 am ]
Post subject:  Re: Button focus or lack of it

See this post
viewtopic.php?p=390031#p390031

Author:  Julian [ Thu Mar 24, 2016 1:28 pm ]
Post subject:  Re: Button focus or lack of it

Thanks Wilbert, but there's nothing in that post that turns this feature on. It would seem the the feature shows when a StringGadget (or list) is selected, the tab shows then and cycles through the controls, but it doesnt work when the window is opened and nothing is clicked.

Any ideas?

Author:  wilbert [ Thu Mar 24, 2016 1:40 pm ]
Post subject:  Re: Button focus or lack of it

Sorry, I misread your question; thought you were asking how to set the default button (which makes it blue).
From what I read online, a NSButton normally can't have keyboard focus. Maybe some sort of accessibility option can enable it :?

Author:  Julian [ Thu Mar 24, 2016 1:56 pm ]
Post subject:  Re: Button focus or lack of it

Hmm odd, purebasic does it on the debug window when you run a program and click the title of the debug window, the "Copy all" button is already selected with a blue border.

Thanks thought, I'll keep looking.

Author:  Shardik [ Thu Mar 24, 2016 3:58 pm ]
Post subject:  Re: Button focus or lack of it

The solution is very easy and doesn't require any API. You only need to use
Code:
SetActiveGadget(#ButtonGadget)
and voilĂ : your button displays the wanted blue border and you may change the focus by using the <Tab> key... :wink:
Code:
OpenWindow(0, 270, 100, 200, 145, "Highlighted button")
ButtonGadget(0, 40, 20, 120, 25, "Test 1")
ButtonGadget(1, 40, 60, 120, 25, "Test 2")
ButtonGadget(2, 40, 100, 120, 25, "Test 3")
SetActiveGadget(0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Author:  Julian [ Thu Mar 24, 2016 4:10 pm ]
Post subject:  Re: Button focus or lack of it

Ha! So simple I overlooked it, thanks Shardik

Author:  doctorized [ Mon Jul 08, 2019 6:51 pm ]
Post subject:  Re: [solved] Button focus or lack of it

Some windows apps, not writen in PB, gives you the opportunity to write something in a textbox, the active button remains active while typing and by pressing keyboard Enter the button is pressed and does the job it should do. Is there a way to achieve it?

Author:  mk-soft [ Mon Jul 08, 2019 8:21 pm ]
Post subject:  Re: [solved] Button focus or lack of it

Update...

Is better to add and remove shortcut key

Code:
;-TOP

Enumeration formMenu
  #Menu_Return
EndEnumeration

OpenWindow(0, 270, 100, 200, 145, "Highlighted button")
ButtonGadget(0, 40, 20, 120, 25, "Ok", #PB_Button_Default)
ButtonGadget(1, 40, 60, 120, 25, "Cancel")
StringGadget(2, 40, 100, 120, 25, "Text")
SetActiveGadget(0)


; AddKeyboardShortcut(0, #PB_Shortcut_Return, #Menu_Return)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Menu
      Select EventMenu()
        Case #Menu_Return
          ;Debug GetGadgetText(2)
          PostEvent(#PB_Event_Gadget, 0, 0, #PB_EventType_LeftClick)
         
      EndSelect
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "Button Ok - " + GetGadgetText(2)
        Case 1
          Debug "Button Cancel"
        Case 2
          If EventType() = #PB_EventType_Focus
            AddKeyboardShortcut(0, #PB_Shortcut_Return, #Menu_Return)
          ElseIf EventType() = #PB_EventType_LostFocus
            RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
          EndIf
           
      EndSelect
 
  EndSelect
ForEver

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/