Page 1 of 2

SpinGadget and Focus

Posted: Thu Oct 10, 2013 12:48 pm
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?

Re: SpinGadget and Focus

Posted: Thu Oct 10, 2013 3:43 pm
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.

Re: SpinGadget and Focus

Posted: Thu Oct 10, 2013 5:04 pm
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.

Re: SpinGadget and Focus

Posted: Thu Oct 10, 2013 5:22 pm
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.

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 8:26 am
by Lord
USCode wrote:Shouldn't Get/Lost Focus events be supported for all gadgets?
...
Yes!

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 2:42 pm
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.

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 3:30 pm
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:

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 5:05 pm
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.

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 6:56 pm
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)

Re: SpinGadget and Focus

Posted: Fri Oct 11, 2013 9:31 pm
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.

Re: SpinGadget and Focus

Posted: Sat Oct 12, 2013 10:46 am
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.

Re: SpinGadget and Focus

Posted: Sat Oct 12, 2013 10:55 am
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.

Re: SpinGadget and Focus

Posted: Sun Oct 13, 2013 10:51 am
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.

Re: SpinGadget and Focus

Posted: Sun Oct 13, 2013 11:24 am
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.

Re: SpinGadget and Focus

Posted: Sun Oct 13, 2013 3:43 pm
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.