EditorGadget - catch insert event

Just starting out? Need help? Post your questions and find answers here.
ZX80
Enthusiast
Enthusiast
Posts: 365
Joined: Mon Dec 12, 2016 1:37 pm

EditorGadget - catch insert event

Post by ZX80 »

Hi, all.

I don't know, maybe this question has already been discussed, but I couldn't find it. So...
I have an editor gadget and I need to catch the #WM_PASTE event ? This doesn't work in a callback function. I need to check the paste text for correctness before it is added to the editor gadget. Otherwise, issue an error warning. I think the validation loop is too long for a callback, so is it possible to send this event to the main loop ?

Here is the basic code from here, that I would like to use.

Code: Select all

Global old
Global En_layout, hKL

Enumeration #PB_Event_FirstCustomValue
  #APP_Event_KBDLayoutChanged
EndEnumeration

Macro force_change_to_En
  If GetKeyboardLayout_(0) <> En_layout ; En
    ActivateKeyboardLayout_(hKL, #KLF_REORDER)
  EndIf
EndMacro

Procedure MakeLong(low, high)
  ProcedureReturn low | (high<<16)
EndProcedure

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  If uMsg = #WM_INPUTLANGCHANGE
    If lParam <> En_layout
      Debug "diff"
      PostEvent(#APP_Event_KBDLayoutChanged)
    EndIf
  EndIf
  
  ProcedureReturn CallWindowProc_(old, hWnd, uMsg, wParam, lParam)
EndProcedure

En_layout = MakeLong(1033, 1033) ; En

If OpenWindow(0, 0, 0, 322, 250, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  hWnd = WindowID(0)
  EditorGadget(0, 8, 8, 306, 133)
  ButtonGadget(1, 10, 145, 80, 30, "ok")
  StringGadget(2, 100, 145, 200, 30, "try to change kbd layout here")
  StringGadget(3, 0, 0, 0, 0, "") ; phantom gadget. Don't use -1 !
                                  ; otherwise the system icon for changing keyboard layout will disappear from the tray when you click on it
  
  For a = 0 To 5
    AddGadgetItem(0, a, "Line "+Str(a))
  Next
  
  ;hKL = LoadKeyboardLayout_("00000401",#KLF_REORDER)   ;For Arabic
  hKL = LoadKeyboardLayout_("00000409",#KLF_REORDER)  ;For English
  If hKL
    ActivateKeyboardLayout_(hKL,#KLF_REORDER)
  Else
    MessageRequester("INFO","The required Language not found",#MB_OK|#MB_ICONINFORMATION)
  EndIf
  SetActiveGadget(0)   
  
  old = SetWindowLongPtr_(GadgetID(0), #GWLP_WNDPROC, @WndProc())
  
  Repeat
    Select  WaitWindowEvent(1)
      Case #APP_Event_KBDLayoutChanged
        force_change_to_En
        
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Gadget
        If EventGadget() = 0
          If EventType() = #PB_EventType_LostFocus
            Debug "Lost Focus"
          ElseIf EventType() = #PB_EventType_Focus
            Debug "Got Focus"
            force_change_to_En
          EndIf
        EndIf
    EndSelect
  Until Quit = 1
EndIf
Thanks in advance
- - - - - - - - - - - - - -

I found this code, but it uses hotkeys and there is no way to prevent the text from being pasted until verified. Only the fact of the insertion event.

P.S. I wouldn't want to ban insertion altogether.