Page 2 of 2

Posted: Fri Jul 18, 2008 11:54 am
by Sparkie
I see no problem with your method at all PB. I just prefer mine as it only blocks #WM_PASTE in my target EditorGadget, letting other gadgets go on as usual with no code interruption. ;)

rsts now has at least 3 options to choose from and he can decide which one is best suited for his app. 8)

Code: Select all

Procedure ProtectEditor(editorGadget) 
  With editFormat.CHARFORMAT2 
    \cbSize = SizeOf(CHARFORMAT2) 
    \dwMask = #CFM_PROTECTED 
    \dwEffects = #CFE_PROTECTED 
  EndWith 
  SendMessage_(GadgetID(editorGadget), #EM_SETCHARFORMAT, #SCF_ALL, @editFormat) 
  SendMessage_(GadgetID(editorGadget), #EM_SETEVENTMASK, 0, #ENM_PROTECTED) 
EndProcedure 

Procedure WinCallback(hwnd, msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select msg 
    Case #WM_NOTIFY 
      *pNMHDR.NMHDR = lParam 
      Select *pNMHDR\code 
        Case #EN_PROTECTED 
          *enp.ENPROTECTED = lParam 
          If *enp\msg = #WM_PASTE 
            ;...Do your thing here and return nonzero to prevent paste 
            MessageRequester("Sorry", "Paste not allowed", #PB_MessageRequester_Ok | #MB_ICONERROR) 
            result = 1 
          Else 
            ;...Allow everything else 
            result = 0 
          EndIf 
      EndSelect 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
        
If OpenWindow(0, 0, 0, 500, 425, "ProtectEditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@WinCallback()) 
  EditorGadget (0, 10, 10, 480, 180) 
  EditorGadget (1, 10, 200, 480, 180) 
  StringGadget(2, 10, 390, 450, 25, "StringGadget")
  ProtectEditor(0) 
  For g = 0 To 1
    For i = 0 To 15 
      AddGadgetItem(g, i, "Line " + Str(i)) 
    Next i
  Next g 
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 
EndIf 

Posted: Fri Jul 18, 2008 2:37 pm
by Little John
Hi all,

I've read this interesting discussion. Now I've got a question out of curiosity:
When someone uses [Shift]+[Insert] instead of [Ctrl]+[V] for pasting, will the various solutions presented here still work?

Regards, Little John

Posted: Fri Jul 18, 2008 3:08 pm
by srod
Sparkie's code will work without any alterations. All other solutions presented above will require a little modification.

Posted: Sat Jul 19, 2008 8:26 am
by Little John
Thanks for the information.

Regards, Little John