Basic Univers
; Problème :
;	Je souhaite programmer une serie de stringgadgets qui se remplissent
;	avec des nombres et pour gagner du temps à la saisie,
;	je veux que la touche "entrée" remplace la touche Tab pour sauter au gadget suivant
;	(pour cette série de gadget uniquement). Avez vous une idée ?

; Auteur : Flype
; voici une méthode un peu particulière.
; elle a le mérite d'automatiser complètement la gestion du passage au gadget suivant. tu n'a pas besoin de gérer dans ta boucle d'évenements classique l'état du clavier et tout ce qui en résulte.
; tu créé juste un StringGadget2() dans lequel tu indiques quel gadget tu veux activer si RETURN est saisie par l'utilisateur.
; la procédure callback du StringGadget2() fera le travail de façon transparente pour toi.

;-
;- EXTENSION STRINGGADGET2
;-

Procedure.l StringGadget2_Callback(hwnd.l, msg.l, wParam.l, lParam.l)
 
  Protected result.l
 
  result = CallWindowProc_(GetProp_(hwnd, "USER_OLDPROC"), hwnd, msg, wParam, lParam)
 
  If msg = #WM_CHAR
    If wParam = #VK_RETURN
      SetActiveGadget(GetProp_(hwnd, "USER_NEXTGAD"))
    EndIf
  EndIf
 
  ProcedureReturn result
 
EndProcedure
Procedure.l StringGadget2(gadget.l, x.l, y.l, w.l, h.l, string.s, flags.l = #Null, nextgadget.l = - 1)
 
  Protected hGadget.l, result.l
 
  result = StringGadget(gadget, x, y, w, h, string, flags)
 
  If nextgadget <> - 1
    hGadget = GadgetID(gadget)
    SetGadgetData(gadget, nextgadget)
    SetProp_(hGadget, "USER_NEXTGAD", nextgadget)
    SetProp_(hGadget, "USER_OLDPROC", SetWindowLong_(hGadget, #GWL_WNDPROC, @StringGadget2_Callback()))
  EndIf
 
  ProcedureReturn result
 
EndProcedure

;-
;- EXAMPLE D'UTILISATION
;-

Enumeration
  #Win0
  #Frame0
  #Str0
  #Str1
  #Str2
  #Str3
  #Str4
EndEnumeration

If OpenWindow(#Win0, 339, 296, 210, 263, "test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  If CreateGadgetList(WindowID(#Win0))
    Frame3DGadget(#Frame0, 10,  10, 190, 150, "Formulaire")
    StringGadget2(#Str0,   25,  35, 160,  20, "", #PB_String_Numeric, #Str1) ; ici, on passera au gadget #Str1 si RETURN
    StringGadget2(#Str1,   25,  65, 160,  20, "", #PB_String_Numeric, #Str2) ; ici, on passera au gadget #Str2 si RETURN
    StringGadget2(#Str2,   25,  95, 160,  20, "", #PB_String_Numeric, #Str3) ; ici, on passera au gadget #Str3 si RETURN
    StringGadget2(#Str3,   25, 125, 160,  20, "", #PB_String_Numeric, #Str0) ; ici, on passera au gadget #Str0 si RETURN
    StringGadget2(#Str4,   25, 210, 160,  20, "") ; ici, pas de gadget suivant
    SetActiveGadget(#Str0)
  EndIf
EndIf

Repeat
Until  WaitWindowEvent() = #PB_Event_CloseWindow

End

;-
;- FIN
;-