An issue with EditorGadget and StringGadget.
- Clicking window title/borders (or moving/resizing the window) makes the blue focus-border disappear and the gadgets lose Focus: #PB_EventType_LostFocus is triggered.
- However, releasing the mouse button we can still continue typing into the gadgets, no need to click into them first, but hitting the Return key won't be recognised as a Shortcut.
- Running the same code in PureBasic works as expected: focus is kept during Window move/size, Return key works as Shortcut programmed
As a workaround for some cases, focus can be regained by adding SetActiveGadget(...) when #PB_EventType_Change is caught.
Thanks
Code: Select all
; Editor and StringGadgets lose Focus when Window area is clicked
;
; -Clicking window title/borders (or moving/resizing the window) makes the blue focus-border disappear
; and the gadgets lose Focus: #PB_EventType_LostFocus is triggered.
; -However, releasing the mouse button we can still continue typing into the gadgets, no need to click into them first,
; but hitting the Return key won't be recognised as a Shortcut.
;
; -Running the same code in PB works as expected: focus is kept during Window move/size, Return key works as Shortcut programmed
#String_ReturnKeyPressed = 777
#Editor_ReturnKeyPressed = 888
Enumeration Windows
#win
EndEnumeration
Enumeration Gadgets
#Editor
#String
EndEnumeration
Procedure GadgetEvent()
Select EventGadget()
Case #String
Debug " #String"
Select EventType()
Case #PB_EventType_Change
;SetActiveGadget(#String) ; as a wokaround... sort of
Case #PB_EventType_Focus
Debug " AddKeyboardShortcut(#win, #PB_Shortcut_Return, #String_ReturnKeyPressed)"
AddKeyboardShortcut(#win, #PB_Shortcut_Return, #String_ReturnKeyPressed)
Case #PB_EventType_LostFocus
Debug " RemoveKeyboardShortcut(#win, #PB_Shortcut_Return)"
RemoveKeyboardShortcut(#win, #PB_Shortcut_Return)
Default
Debug " EventType(): " + EventType()
EndSelect
Case #Editor
Debug " #Editor"
Select EventType()
Case #PB_EventType_Change
;SetActiveGadget(#Editor) ; as a wokaround... sort of
Case #PB_EventType_Focus
Debug " AddKeyboardShortcut(#win, #PB_Shortcut_Return, #Editor_ReturnKeyPressed)"
AddKeyboardShortcut(#win, #PB_Shortcut_Return, #Editor_ReturnKeyPressed)
Case #PB_EventType_LostFocus
Debug " RemoveKeyboardShortcut(#win, #PB_Shortcut_Return)"
RemoveKeyboardShortcut(#win, #PB_Shortcut_Return)
Default
Debug " EventType(): " + EventType()
EndSelect
Default
Debug " EventGadget(): " + EventGadget()
EndSelect
EndProcedure
Procedure MenuEvent()
Debug EventMenu()
Select EventMenu()
Case #String_ReturnKeyPressed
Debug " #String: " +#DQUOTE$+ GetGadgetText(#String) +#DQUOTE$
Case #Editor_ReturnKeyPressed
Debug " #Editor: " +#DQUOTE$+ GetGadgetText(#Editor) +#DQUOTE$
EndSelect
EndProcedure
Procedure SizeWindowEvent()
ResizeGadget(#String, #PB_Ignore, #PB_Ignore, WindowWidth(#win)-10, #PB_Ignore)
ResizeGadget(#Editor, #PB_Ignore, #PB_Ignore, WindowWidth(#win)-10, WindowHeight(#win)-40)
EndProcedure
CompilerIf #PB_Compiler_OS <> #PB_OS_Web
#PB_String_PlaceHolder = 0
CompilerEndIf
BindEvent(#PB_Event_Gadget, @GadgetEvent())
BindEvent(#PB_Event_Menu, @MenuEvent())
BindEvent(#PB_Event_SizeWindow, @SizeWindowEvent())
If OpenWindow(#win, 0, 0, 400, 250, "String/EditorGadget loses Focus on window-click", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
StringGadget(#String, 5, 5, WindowWidth(#win)-10, 25, "Clicking Window title/boder triggers RemoveKeyboardShortcut()", #PB_String_PlaceHolder)
EditorGadget(#Editor, 5, 35, WindowWidth(#win)-10, WindowHeight(#win)-40)
SetActiveGadget(#String)
CompilerIf #PB_Compiler_OS <> #PB_OS_Web
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow ; uncomment this to make code work in PureBasic
CompilerEndIf
EndIf