It is currently Thu Nov 23, 2017 12:04 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 10:15 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 11, 2004 11:54 am
Posts: 531
Location: UK
Good morning,
I'm not sure if this is a feature, or a bug (heaven forbid!), or I'm doing something stupid.

I have several StringGadget() in a row, created in a loop and the TAB key order lets me move back and fore between them.

If I write the program using the conventional PB EventMangement style all works well and I can skip some StringGadgets (In the real application the program completes them for me, but the user can edit them if wanted.) The cursor ends up where I want it.

If I write the program using BindGadgetEvent() to acheive the same effect I can still skip some StringGadgets but the cursor does not appear in the StringGadget I have jumped to even though keyboard input does go to the gadget.

Here are my simplified examples... I would much rather make the BindGadgetEvent() method work as a whole lot of other things become easier for me.

Any comments welcomed.
RichardL
Code:
; PB5.44LTS + Windows10

; Version 1 using normal event management
; =======================================

; Make display
OpenWindow(0, 0, 0, 500, 140, "Set StringGadget Test.     Use TAB key to progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
X = 5
For n = 1 To 8
  StringGadget  (n, X, 10, 50, 20, Str(n))
 X+55
Next

SetActiveGadget(4) ; Start at #4.... See CURSOR OK

; Event manager
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
     
    Case #PB_Event_Gadget
     
      Select EventGadget()
        Case 6
          If EventType() = #PB_EventType_LostFocus
            SetActiveGadget(2) ; Jumps to #2... See CURSOR OK
          EndIf
         
      EndSelect
     
  EndSelect
ForEver


Code:
; Version 2 using BindGadgetEvent()
; =================================
Declare Stringin()

OpenWindow(0, 0, 0, 500, 140, "Set StringGadget Test.     Use TAB key to progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
X = 5
For n = 1 To 8
  StringGadget  (n, X, 10, 50, 20, Str(n))
  BindGadgetEvent(n,@Stringin()) ; Disable this line and un-comment the event mangager stuff.
  X+55
Next

SetActiveGadget(4) ; Start at #4.... See CURSOR OK

; Event manager
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
     
    Case #PB_Event_Gadget
     
     
  EndSelect
ForEver

Procedure Stringin() ; Here when Get/Lost focus or content Changes
 
  ; When  we get to #6 jump back to #2 (#1,#7 and #8 filled in automatically)
  If EventGadget() = 6
    If EventType() = #PB_EventType_LostFocus
      SetActiveGadget(2)                        ; Jumps to #2... but NO CURSOR!
    EndIf
  EndIf
 
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 11:46 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2844
Hi RichardL
Adapt the next snippet for your needs
Use |#WS_TABSTOP to enable Tab key
Use &~ #WS_TABSTOP to disable Tab key
Code:
; Version 2 using BindGadgetEvent()
; =================================
Declare Stringin()

OpenWindow(0, 0, 0, 500, 140, "Set StringGadget Test.     Use TAB key to progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
X = 5
For n = 1 To 8
  StringGadget  (n, X, 10, 50, 20, Str(n))
  BindGadgetEvent(n,@Stringin()) ; Disable this line and un-comment the event mangager stuff.
  X+55
Next

SetWindowLongPtr_(GadgetID(1),#GWL_STYLE, GetWindowLongPtr_(GadgetID(1),#GWL_STYLE) &~ #WS_TABSTOP)
SetWindowLongPtr_(GadgetID(7),#GWL_STYLE, GetWindowLongPtr_(GadgetID(7),#GWL_STYLE) &~ #WS_TABSTOP)
SetWindowLongPtr_(GadgetID(8),#GWL_STYLE, GetWindowLongPtr_(GadgetID(8),#GWL_STYLE) &~ #WS_TABSTOP)

SetActiveGadget(4) ; Start at #4.... See CURSOR OK

; Event manager
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
     
    Case #PB_Event_Gadget
     
     
  EndSelect
ForEver

Procedure Stringin() ; Here when Get/Lost focus or content Changes
  ; When  we get to #6 jump back to #2 (#1,#7 and #8 filled in automatically)
  If EventGadget() = 6
    If EventType() = #PB_EventType_LostFocus
      SetActiveGadget(2)                        ; Jumps to #2... but NO CURSOR!
    EndIf
  EndIf
 
EndProcedure

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 11:56 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 871
I realized that some SendMessage_() don't work in a BindGadgetEvent procedure...
But PostMessage_() instead... works well. I think SetActiveGadget uses internally SendMessage_() so
this is a little "workaround" ;)

Code:
Procedure Stringin() ; Here when Get/Lost focus or content Changes
 
  ; When  we get to #6 jump back to #2 (#1,#7 and #8 filled in automatically)
  If EventGadget() = 6
    If EventType() = #PB_EventType_LostFocus
      ;SetActiveGadget(2)                        ; Jumps to #2... but NO CURSOR!
      PostMessage_(GadgetID(2), #WM_ACTIVATE, #WA_ACTIVE, 0)
    EndIf
  EndIf
 
EndProcedure

_________________
PureBasic 5.45 LTS / 5.61 (Windows x86/x64) | Windows10 Pro x64 | Z87-PLUS | i7 4770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language...


Top
 Profile  
Reply with quote  
 Post subject: Re: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 12:03 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5687
Location: Wales, UK
Hi Richard

I think you may have discovered a PB bug, or at least an undocumented limitation of BindGadgetEvent()

Without BindGadgetEvent() you can still have a tidy main loop like this:
Code:
; Version 3 not using BindGadgetEvent()
; =====================================
Declare Stringin()

OpenWindow(0, 0, 0, 500, 140, "Set StringGadget Test. Use TAB key to progress...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
X = 5
For n = 1 To 8
  StringGadget  (n, X, 10, 50, 20, Str(n))
  ;BindGadgetEvent(n,@Stringin()) ; Disable this line and un-comment the event mangager stuff.
  X+55
Next

SetActiveGadget(4) ; Start at #4.... See CURSOR OK

; Event manager
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
     
    Case #PB_Event_Gadget: Stringin()
     
     
  EndSelect
ForEver

Procedure Stringin() ; Here when Get/Lost focus or content Changes
 
  ; When  we get to #6 jump back to #2 (#1,#7 and #8 filled in automatically) ;This means #6 is never filled
  If EventGadget() = 6
    ;If EventType() = #PB_EventType_LostFocus
      SetActiveGadget(2)                        ; Jumps to #2... but NO CURSOR!
    ;EndIf
  EndIf
 
EndProcedure

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 12:19 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2844
Quote:
a window already has the #PB_Shortcut_Tab and #PB_Shortcut_Tab|#PB_Shortcut_Shift shortcuts to handle tab and shift-tab correctly trough the gadgets.


No PB bug
Windows has its own routine to handle using Tab key to rotate between objects
That is why PostMessage_() can work successfully and not SendMessage_()

Quote:
The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: TAB Order and BindGadgetEvent() problem
PostPosted: Mon Aug 21, 2017 2:57 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5687
Location: Wales, UK
Hi Rashad

... that is true, but should it be the case that BindGadgetEvent() has a detrimental effect on code that works fine without the binding?

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye