Readonly Textarea

BlitzPlus Forums/BlitzPlus Programming/Readonly Textarea

Todd(Posted 2003) [#1]
Is it possible to make a read-only TextArea gadget? I know that you can get this using DisableGadget(), but this also disables the scrollbars. If not, can it be done with userlibs? Thanks in advance.


Darkuni(Posted 2003) [#2]
Actually, just use the GetFocus code ( found at http://www.blitzbasic.com/bbs/posts.php?topic=24521 ) to see if the textarea has focus, and if it does, in your main loop, move the focus somewhere else :)

That's probably the easiest way to do it.


Todd(Posted 2003) [#3]
Ok, I tried that out, but it still does not work like I'd like. It moves the focus like it should, but in between getting and setting the focus the user can still edit it if they try hard enough. I would like to use the ES_READONLY flag with the SetWindowLong() function in user32.dll, but for some reason I haven't been able to get that to work yet. Thanks for your reply though :)


Darkuni(Posted 2003) [#4]
The other option .. anytime that field loses focus, reset the text back to its original value (presummably in a variable). That way while it appears they can edit it, they really can't.

I understand where you're trying to go, though ... Hopefully that can be incoporated in future versions as read only is important.


EOF(Posted 2003) [#5]
; TextArea - ReadOnly
; Syntax Error

; userlib
; ************************
; .lib "user32.dll"
; SendMessage%(hwnd,msg,wParam,mParam):"SendMessageA"
; ************************


Const EM_SETREADONLY=$CF

win=CreateWindow("Read-Only Text Area",50,150,407,184,Desktop(),1)
textarea = CreateTextArea(18,26,361,96,win,1)
SetTextAreaFont textarea,LoadFont ("Tahoma",24,1)
AddTextAreaText textarea,"Edit me if you think your 'ard enough!"
lock=CreateButton("Locked (Read-Only)",100,130,120,20,win,2)
SetButtonState lock,True

SendMessage QueryObject(textarea,1),EM_SETREADONLY,1,0 ; lockdown

Repeat
	ev=WaitEvent()
	If ev=$401
		If EventSource()=lock
			SendMessage QueryObject(textarea,1),EM_SETREADONLY,ButtonState(lock),0
		EndIf
	EndIf
Until ev=$803
End



Todd(Posted 2003) [#6]
Syntax Error: Thanks! Thats exactly what I was looking for, I could swear I'd already tried that. But thanks for the help! This really needs to be added into Blitz, I think I'll post a feature request for this.


MagicalTux(Posted 2003) [#7]
I think it would be great to have 1 or 2 additionnal commands..

GadgetLock(gadget) : makes gadget readonly
GadgetUnlock(gadget) : enable write

it's just an idea, but it would be lots easier than SendMessage() :p