EDITOR GADGET and TAB key

Windows specific forum
Jan2004
Enthusiast
Enthusiast
Posts: 165
Joined: Fri Jan 07, 2005 7:17 pm

EDITOR GADGET and TAB key

Post by Jan2004 »

I have build the window which has a few editor gadgets.

How to move between editor gadgets with keyboard ? (TAB makes own moves inside the editor gadget). Reverse move is possible: TAB + SHIFT.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Its very easy.
You've to make a key-request in your mainloop or in your callback which inserts a TAB ( chr(9) ) in reaction of pressing the TAB-Key.


(Please, excuse my english)
Jan2004
Enthusiast
Enthusiast
Posts: 165
Joined: Fri Jan 07, 2005 7:17 pm

Post by Jan2004 »

Yes Hrudtwolf. Here is the simple code, impleament please:

Code: Select all

;-Window Constants
Enumeration 1
  #Window_Form1
EndEnumeration
;-Gadget Constants
Enumeration 1
#Gadget_Form1_Text0
#Gadget_Form1_Editor1  
#Gadget_Form1_Editor2  
#Gadget_Form1_Option3 
#Gadget_Form1_Option4  
#Gadget_Form1_String5  
#Gadget_Form1_String6  
#Gadget_Form1_String7  

#Gadget_Form1_Button8  
EndEnumeration

Procedure.l Window_Form1()
  If OpenWindow(#Window_Form1,176,92,400,300,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible,"How to use TAB key with editor")
    If CreateGadgetList(WindowID(#Window_Form1))
       TextGadget(#Gadget_Form1_Text0,0,7,395,15,"Move the cursor wit TAB key between gadgets",#PB_Text_Center)

      EditorGadget(#Gadget_Form1_Editor1,50,25,300,75)
      EditorGadget(#Gadget_Form1_Editor2,50,110,300,60)
      
      OptionGadget(#Gadget_Form1_Option3,55,180,80,15,"Option9")
      OptionGadget(#Gadget_Form1_Option4,270,180,80,15,"Option10")
      
      StringGadget(#Gadget_Form1_String5,55,210,80,25,"")
      StringGadget(#Gadget_Form1_String6,160,210,80,25,"")
      StringGadget(#Gadget_Form1_String7,270,210,80,25,"")

      ButtonGadget(#Gadget_Form1_Button8,175,265,60,25,"EXIT")
      HideWindow(#Window_Form1,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure


;-Main Loop
If Window_Form1()

  quitForm1=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenuID()
    GadgetID =EventGadgetID()
    WindowID =EventWindowID()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_Form1
          quitForm1=1
        EndIf


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Form1_Editor1  
          Case #Gadget_Form1_Editor2
          Case #Gadget_Form1_Option3  
          Case #Gadget_Form1_Option4 
          Case #Gadget_Form1_String5  
          Case #Gadget_Form1_String6  
          Case #Gadget_Form1_String7  
          Case #Gadget_Form1_Button8  
        EndSelect

    EndSelect
  Until quitForm1
  CloseWindow(#Window_Form1)
EndIf
End
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Coded for PB4 Beta7 so you'll need to change the OpenWindow() parameters for use in PB3.94. ;)

Code: Select all

;-Window Constants 
Enumeration 1 
  #Window_Form1 
EndEnumeration 
;-Gadget Constants 
Enumeration 1 
  #Gadget_Form1_Text0 
  #Gadget_Form1_Editor1  
  #Gadget_Form1_Editor2  
  #Gadget_Form1_Option3 
  #Gadget_Form1_Option4  
  #Gadget_Form1_String5  
  #Gadget_Form1_String6  
  #Gadget_Form1_String7  
  
  #Gadget_Form1_Button8  
EndEnumeration 

Procedure WinCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pnmhdr.NMHDR = lParam 
      Select *pnmhdr\code
        Case #EN_MSGFILTER
          *pMSGFILTER.MSGFILTER = lParam 
          If *pMSGFILTER\wParam = #VK_TAB And *pMSGFILTER\msg <> #WM_KEYUP 
            Select *pnmhdr\hwndFrom
              Case GadgetID(#Gadget_Form1_Editor1)  
                SetActiveGadget(#Gadget_Form1_Editor2)
                ; --> Return non-zero to ignore the Tab key 
                result = 1 
              Case GadgetID(#Gadget_Form1_Editor2)  
                SetActiveGadget(#Gadget_Form1_Option3)
                ; --> Return non-zero to ignore the Tab key 
                result = 1 
            EndSelect
          EndIf 
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

Procedure.l Window_Form1() 
  If OpenWindow(#Window_Form1,176,92,400,300,"How to use TAB key with editor",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible) 
    If CreateGadgetList(WindowID(#Window_Form1)) 
      TextGadget(#Gadget_Form1_Text0,0,7,395,15,"Move the cursor wit TAB key between gadgets",#PB_Text_Center) 
      
      EditorGadget(#Gadget_Form1_Editor1,50,25,300,75) 
      EditorGadget(#Gadget_Form1_Editor2,50,110,300,60) 
      
      ;...Tell the EditorGadgets we want ot filter keyboard messages 
      ;...We catch the events in the #WM_NOTIFY msg in our CallBack procedure 
      SendMessage_(GadgetID(#Gadget_Form1_Editor1), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS) 
      SendMessage_(GadgetID(#Gadget_Form1_Editor2), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS) 
      
      OptionGadget(#Gadget_Form1_Option3,55,180,80,15,"Option9") 
      OptionGadget(#Gadget_Form1_Option4,270,180,80,15,"Option10") 
      
      StringGadget(#Gadget_Form1_String5,55,210,80,25,"") 
      StringGadget(#Gadget_Form1_String6,160,210,80,25,"") 
      StringGadget(#Gadget_Form1_String7,270,210,80,25,"") 
      
      ButtonGadget(#Gadget_Form1_Button8,175,265,60,25,"EXIT") 
      HideWindow(#Window_Form1,0) 
      
      ;...Window callback is where we catch tab key events from our EditorGadget
      SetWindowCallback(@WinCallback())
      ProcedureReturn WindowID(#Window_Form1) 
    EndIf 
  EndIf 
EndProcedure 


;-Main Loop 
If Window_Form1() 
  
  quitForm1=0 
  Repeat 
    EventID  =WaitWindowEvent() 
    MenuID   =EventMenu() 
    GadgetID =EventGadget() 
    WindowID =EventWindow() 
    
    Select EventID 
      Case #PB_Event_CloseWindow 
        If WindowID=#Window_Form1 
          quitForm1=1 
        EndIf 
        
        
      Case #PB_Event_Gadget 
        Select GadgetID 
          Case #Gadget_Form1_Editor1  
          Case #Gadget_Form1_Editor2 
          Case #Gadget_Form1_Option3  
          Case #Gadget_Form1_Option4 
          Case #Gadget_Form1_String5  
          Case #Gadget_Form1_String6  
          Case #Gadget_Form1_String7  
          Case #Gadget_Form1_Button8  
        EndSelect 
        
    EndSelect 
  Until quitForm1 
  CloseWindow(#Window_Form1) 
EndIf 
End 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Jan2004
Enthusiast
Enthusiast
Posts: 165
Joined: Fri Jan 07, 2005 7:17 pm

Post by Jan2004 »

Thanks. The code works very well.
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

A function (or an attribute) to enable or disable Tab key for EditorGadget (even if it is not read only) would be very nice. What do you think about that ?
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
Jan2004
Enthusiast
Enthusiast
Posts: 165
Joined: Fri Jan 07, 2005 7:17 pm

Post by Jan2004 »

I agree with Gangsta93. It would be very usefull feature.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

yeah, it's on my wishlist as well, and i've been struggling with this subject as well (do a search on the forum :-))
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> it's on my wishlist as well

In the past, a lot of people were asking for the EditorGadget to actually act
this way, instead of TAB switching to the next gadget. For example:

http://www.purebasic.fr/english/viewtop ... 9&start=15

So then Fred happily changed it in v3.93 according to all the wishes:

Fixed: TAB in an EditorGadget() doesn't give the focus to others gadgets anymore but insert a Tab

And now people want it to work the old way again? :roll: Give Fred a break.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

PB wrote:And now people want it to work the old way again? :roll: Give Fred a break.
I guess folks really want an option so they can have it work 1 way or the other ... they want it all! ;-)
User avatar
Michael Vogel
Addict
Addict
Posts: 2821
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Ua - why people don't accept (sometimes bad) standards?

#WS_TABSTOP has been defined in windows for sich things. Again a lot of work to simulate a windows like behaviour with PureBasic (and I thought, the keyboard handling for shortcuts - "Ok" - within dialogs is the only difference to real windows programs)

Also in windows it is/was possible to enter a tab (and even a crlf) within an edit field - so what users asked for going away from the (windows) standard?

__________________

So one additional pull-up to get more windows-like behaviour...

Code: Select all

If *pMSGFILTER\wParam = #VK_TAB And *pMSGFILTER\msg <> #WM_KEYUP And (GetKeyState_(#VK_CONTROL)&$80)=0
Post Reply