Spin gadget retains focus and is selected after value change

Just starting out? Need help? Post your questions and find answers here.
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Spin gadget retains focus and is selected after value change

Post by barryem »

With the spin gadget set to #PB_Spin_ReadOnly I would expect that when the number is changed using an arrow button the spin control wouldn't retain focus and show reverse text as being selected but it does. Is there a way to prevent that?

Here's the sample code from the help file with #PB_Spin_ReadOnly added, as an example:

Code: Select all

  If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SpinGadget     (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
    SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        If EventGadget() = 0
          SetGadgetText(0, Str(GetGadgetState(0)))
        EndIf
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf
I'm doing this in Windows 10 using PB 5.42 in case that matters.

Any suggestions appreciated, up to and including "because we felt like doing it that way." :)

Barry
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Spin gadget retains focus and is selected after value ch

Post by RASHAD »

Hi

# 1:

Code: Select all

  If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SpinGadget     (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
    Dummy = TextGadget(#PB_Any,0,0,0,0,"")
    SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        If EventGadget() = 0
          SetGadgetText(0, Str(GetGadgetState(0)))
          SetActiveGadget(Dummy)
        EndIf
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf
# 2:

Code: Select all

  If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SpinGadget     (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
    SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        If EventGadget() = 0
          SetGadgetText(0, Str(GetGadgetState(0)))
          SendMessage_(GadgetID(0),#WM_KILLFOCUS,0,0)
        EndIf
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf
Egypt my love
barryem
User
User
Posts: 19
Joined: Mon Jan 27, 2014 2:40 am

Re: Spin gadget retains focus and is selected after value ch

Post by barryem »

Both examples do just what I hoped for. I think I'll use the second one because it seems a little cleaner.

Thanks,

Barry
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Spin gadget retains focus and is selected after value ch

Post by Demivec »

@RASHAD: You don't have to create a dummy gadget in your example #1.

You can use SetActiveGadget(-1) instead.

Code: Select all

 If OpenWindow(0, 0, 0, 140, 70, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SpinGadget     (0, 20, 20, 100, 25, 0, 10, #PB_Spin_ReadOnly)
    SetGadgetState (0, 5) : SetGadgetText(0, "5")   ; set initial value
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        If EventGadget() = 0
          SetGadgetText(0, Str(GetGadgetState(0)))
          SetActiveGadget(-1)
        EndIf
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Spin gadget retains focus and is selected after value ch

Post by RASHAD »

Hi Demivec
I missed that one (it is since 5.4x only I think)
Thanks
Egypt my love
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: Spin gadget retains focus and is selected after value ch

Post by mestnyi »

You can use SetActiveGadget(-1) instead.
Note: This is not roll in Linux
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Spin gadget retains focus and is selected after value ch

Post by Demivec »

mestnyi wrote:
You can use SetActiveGadget(-1) instead.
Note: This is not roll in Linux
What does it do in Linux?
Post Reply