SpinGadget and Focus

Everything else that doesn't fall into one of the other PB categories.
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

SpinGadget and Focus

Post by Lord »

Hi!

I searched the forum and the structure list for some EventTypes generated
by an SpinGadget but didn't find it.
The EventTypes are 256 and 512.
It turned out, that these are genereted only if a SpinGadget gets / losts
focus:

Code: Select all

OpenWindow(1, 10, 10, 100, 100,"")
SpinGadget(1, 20, 20, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(1, 1)
SpinGadget(2, 20, 54, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(2, 1)

quit=#False
Repeat
  Event=WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget=EventGadget()
      Select EventGadget
        Case 1
          EventType=EventType()
          Debug "Gadget 1: "+Str(EventType)
        Case 2
          EventType=EventType()
          Debug "Gadget 2: "+Str(EventType)
      EndSelect
    Case #PB_Event_CloseWindow
      quit=#True
  EndSelect
Until quit
The documentation doesn't mention any EvenType regarding focus:
Help File wrote:Die folgenden Ereignisse werden durch EventType() unterstützt:
#PB_EventType_Change: Der Text im Eingabebereich wurde durch den Anwender geändert.
#PB_EventType_Up : Die 'Nach oben'-Taste wurde gedrückt.
#PB_EventType_Down : Die 'Nach unten'-Taste wurde gedrückt.
Are the observed EventTypes not offical support and will be removed at any time
or are these Eventtypes missing in documentation
or is there an error regarding EventTypes in my above posted code?
Image
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SpinGadget and Focus

Post by netmaestro »

PB doc for SpinGadget wrote:The following events are supported through EventType():
#PB_EventType_Change: The text in the edit area has been modified by the user.
#PB_EventType_Up : The 'Up' button was pressed.
#PB_EventType_Down : The 'Down' button was pressed.
Up and down were changed in 5.20 LTS from the previous -1 and 1. 256 and 512 are not currently-supported event types of any kind for anything, not sure where they're coming from but just look for the documented ones and all will be well.
BERESHEIT
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: SpinGadget and Focus

Post by Lord »

Hi netmaestro!

Thank you for answering.
netmaestro wrote:...
256 and 512 are not currently-supported event types of any kind for anything, not sure where they're coming from but just look for the documented ones and all will be well.
Thats a pity. These two serve pretty good as a get/lost focus event type for SpinGadget.
It would be well, if get/lost focus event type for Spingadget would be supported.
Image
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: SpinGadget and Focus

Post by USCode »

Shouldn't Get/Lost Focus events be supported for all gadgets?
Maybe it's not because it isn't supported cross-platform... ?
Seems like those and maybe some other event types would be supported universally for all gadgets.
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: SpinGadget and Focus

Post by Lord »

USCode wrote:Shouldn't Get/Lost Focus events be supported for all gadgets?
...
Yes!
Image
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: SpinGadget and Focus

Post by BorisTheOld »

To get around missing events, we've written our own Spin gadget based on the Canvas gadget.

In order to give us more control over the mouse and keyboard, we've created our own gadget classes to replace most of the PB gadgets. We needed to do this because the lack of certain events and functionality was affecting our ability to convert our code to PB. However, the benefits of PB's library and cross-platform support far outweighed the extra work.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: SpinGadget and Focus

Post by PB »

> These two serve pretty good as a get/lost focus event type for SpinGadget

True, but EventGadget() returns the current focussed gadget anyway,
so just keep track of it yourself, and you'll always know which gadget
is getting or losing the focus at all times. Observe:

Code: Select all

OpenWindow(1, 210, 210, 100, 100,"")
SpinGadget(1, 20, 20, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(1, 1)
SpinGadget(2, 20, 54, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(2, 1)

quit=#False

Repeat
  Event=WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget=EventGadget()
      If EventGadget<>OldEventGadget
        Debug "Gadget "+Str(OldEventGadget)+" lost focus"
        Debug "Gadget "+Str(EventGadget)+" gained focus"
        OldEventGadget=EventGadget
      EndIf
    Case #PB_Event_CloseWindow
      quit=#True
  EndSelect
Until quit
Are we coders or not? :twisted:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: SpinGadget and Focus

Post by BorisTheOld »

PB wrote:Are we coders or not? :twisted:
Yes, but we're not insane. :)

Finding the gadget with focus is the easy part. Tracking "LostFocus" in user code is far more complex, especially when working with hundreds of gadgets, all of different types and spread across many modules.

Been there, done that. The housekeeping is horrendous.

That's why I decided to take the easy route and write custom gadgets based on the Canvas gadget. It's easy to do and takes just two or three hours per gadget. Custom gadgets are written once and can be implemented as modules or classes. Manual tracking needs unique housekeeping code for each situation, which makes the code more complex and prone to errors.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: SpinGadget and Focus

Post by USCode »

BorisTheOld wrote:... That's why I decided to take the easy route and write custom gadgets based on the Canvas gadget. ...
Care to share? 8)
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: SpinGadget and Focus

Post by BorisTheOld »

USCode wrote:Care to share? 8)
Yes, in the spirit of our Canadian Thanksgiving weekend. :)

Give me a few days to recover from over-indulging in Poutine, Nanaimo Bars, and Rickard's Red, and I'll post a simple example in Tips & Tricks.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: SpinGadget and Focus

Post by Lord »

PB wrote:> These two serve pretty good as a get/lost focus event type for SpinGadget

True, but EventGadget() returns the current focussed gadget anyway,
so just keep track of it yourself, and you'll always know which gadget
is getting or losing the focus at all times. Observe:

Code: Select all

OpenWindow(1, 210, 210, 100, 100,"")
SpinGadget(1, 20, 20, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(1, 1)
SpinGadget(2, 20, 54, 80, 20, 1, 100, #PB_Spin_Numeric):SetGadgetState(2, 1)

quit=#False

Repeat
  Event=WaitWindowEvent()
  Select Event
    Case #PB_Event_Gadget
      EventGadget=EventGadget()
      If EventGadget<>OldEventGadget
        Debug "Gadget "+Str(OldEventGadget)+" lost focus"
        Debug "Gadget "+Str(EventGadget)+" gained focus"
        OldEventGadget=EventGadget
      EndIf
    Case #PB_Event_CloseWindow
      quit=#True
  EndSelect
Until quit
Are we coders or not? :twisted:
Of course, you can "simulate" a LostFocus and GetFocus event.
But that was not the answer of any of my three questions posted above.
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: SpinGadget and Focus

Post by PB »

> Of course, you can "simulate" a LostFocus and GetFocus event

Detecting when one gadget loses focus and another gains it,
is not "simulating" anything. It's the same end result.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: SpinGadget and Focus

Post by Lord »

PB wrote:> Of course, you can "simulate" a LostFocus and GetFocus event

Detecting when one gadget loses focus and another gains it,
is not "simulating" anything. It's the same end result.
Still no answer to my questions.
Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: SpinGadget and Focus

Post by PB »

> Still no answer to my questions

Until the team answers, the best approach is to use whatever
the manual says is supported at the current time. It's safest.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: SpinGadget and Focus

Post by BorisTheOld »

PB wrote:> Of course, you can "simulate" a LostFocus and GetFocus event

Detecting when one gadget loses focus and another gains it,
is not "simulating" anything. It's the same end result.
I think the point being made is that, in the absence of actual PB "getfocus" and "lostfocus" events, the only way of doing focus related things is to find other ways of "simulating" the events. This usually requires lots of housekeeping code and the use of custom events.

For example, in our code we need to do lots of processing whenever a button gains or loses focus, and the only practical way of doing this is with real PB "gotfocus" and "lostfocus" events. That's why we use the Canvas gadget to create custom gadgets. It's a far easier solution than the alternatives.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply