Disable "CTRL-C" for certain textareas?

BlitzMax Forums/MaxGUI Module/Disable "CTRL-C" for certain textareas?

Grisu(Posted 2008) [#1]
Hi there!

Refering to a read-only textarea:

My problem is that the user can still use the Windows builtin "CTRL-C" functionality, i.e. copy a selected text to the windows clipboard. I'd like to disable that only for a certain textarea. - Is that possible?

The ugly workaround is setting the CTRL-C hotkey to a main menu entry. But this also disables the hotkey for all other textareas.

Thanks in advance, Grisu


jsp(Posted 2008) [#2]
When you use
DisableGadget( TextArea:TGadget )

it is not possible to use CTRL-C
Don't know if that's an option in your case, because the TextArea is also greyed out.


Grisu(Posted 2008) [#3]
Sadly, the user needs to have full access to the textarea without being able to copy out the text inside...


jsp(Posted 2008) [#4]
Ok, can still be done, but is a bit more complex by using a TextFilter.
Try the example below and change it to your needs...

SetGadgetFilter( TextArea1:TGadget, TextArea1_Filter )


Function TextArea1_Filter:Int( event:TEvent,context:Object )
	DebugLog "TextArea TextArea1 filtering text input: "+Chr(Event.data)+"="+Event.Data+","+Event.Mods
	Select Event.ID
	    Case EVENT_KEYDOWN
	        If Event.Data = KEY_BACKSPACE Then Return True
	        If Event.Data = KEY_DELETE Then Return True
	    Case EVENT_KEYCHAR
	        If Event.Data => KEY_0 And Event.Data <= KEY_9 Then Return True
	        If Event.Data => KEY_A And Event.Data <= KEY_Z Then Return True
	        If Event.Data => 97 And Event.Data <= 122 Then Return True
	        If Event.Data = KEY_BACKSPACE Then Return True
	End Select
	Return False
End Function




Grisu(Posted 2008) [#5]
Hey, the code does the job fine... Thanks!

Full example app source code:
Strict 

Local window:TGadget
Local textarea:TGadget

window=CreateWindow("My Window",130,20,400,400,,15|WINDOW_ACCEPTFILES)

textarea=CreateTextArea(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout textarea,1,1,1,1
SetGadgetText textarea,"a textarea gadget~none line~nandanother~n~n~nYou can't copy out my text via CTRL+C or X! :P"
ActivateGadget textarea
SetGadgetFilter( TextArea:TGadget, TextArea1_Filter )

SelectTextAreaText textarea,1,1,TEXTAREA_LINES

While WaitEvent()
	Print CurrentEvent.ToString()+" "+EventSourceHandle()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_APPTERMINATE
			End
	End Select
Wend

Function TextArea1_Filter:Int( event:TEvent,context:Object )
	DebugLog "TextArea TextArea1 filtering text input: "+Chr(Event.data)+"="+Event.Data+","+Event.Mods
	Select Event.ID
	    Case EVENT_KEYDOWN
	        If Event.Data = KEY_BACKSPACE Then Return True
	        If Event.Data = KEY_DELETE Then Return True
	    Case EVENT_KEYCHAR
	        If Event.Data => KEY_0 And Event.Data <= KEY_9 Then Return True
	        If Event.Data => KEY_A And Event.Data <= KEY_Z Then Return True
	        If Event.Data => 97 And Event.Data <= 122 Then Return True
	        If Event.Data = KEY_BACKSPACE Then Return True
	End Select
	Return False
End Function