Page 1 of 1
EDITOR GADGET and TAB key
Posted: Sun Mar 19, 2006 10:49 am
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.
Posted: Sun Mar 19, 2006 3:09 pm
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)
Posted: Sun Mar 19, 2006 5:17 pm
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
Posted: Sun Mar 19, 2006 5:58 pm
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
Posted: Sun Mar 19, 2006 6:21 pm
by Jan2004
Thanks. The code works very well.
Posted: Sun Mar 19, 2006 7:47 pm
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 ?
Posted: Sun Mar 19, 2006 8:13 pm
by Jan2004
I agree with Gangsta93. It would be very usefull feature.
Posted: Sun Mar 19, 2006 9:24 pm
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

)
Posted: Mon Mar 20, 2006 12:44 am
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.
Posted: Mon Mar 20, 2006 12:57 am
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!

Posted: Mon Mar 20, 2006 9:55 am
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