Page 1 of 1

Stopping Scintilla from deleting certain styles...

Posted: Tue Mar 23, 2010 6:08 pm
by DoubleDutch
In ElementaryReports and ReportPlus I needed a way of stopping the user deleting the subject titles. So I set them to a style then block deletion of that style with SCI_STYLESETCHANGEABLE, but this (for some unknown reason) doesn't block backspace deletes!!!! So I needed to trap the backspace key and check for the style.

Anyhow, this seems to do the trick...

Code: Select all

Global OldScintillaProc

Procedure ScintillaCharCallback(hwnd,uMsg,wParam,lParam)
	If uMsg=#WM_KEYDOWN
		If wParam=#VK_BACK
			pos=ScintillaSendMessage(#Scintilla,#SCI_GETCURRENTPOS)-1
			If pos>=0
	  		style=ScintillaSendMessage(#Scintilla,#SCI_GETSTYLEAT,pos)&$ff
	  		If style&$80
	  			Select style&$7f
	  				Case	#Style_Title
	  					Beep_(600,100)
	  					ProcedureReturn 0
	  				Case	#Style_Grid
	  					Beep_(600,200)
	  					ProcedureReturn 0
	  			EndSelect
				EndIf
			EndIf
		EndIf
	EndIf
	ProcedureReturn CallWindowProc_(OldScintillaProc,hwnd,uMsg,wParam,lParam)
EndProcedure

Procedure SetupScintilla(gadget,readonly=#True)
	result=ScintillaGadget(gadget,0,0,400,300,@ScintillaCallback())
	If result
	
		OldScintillaProc=SetWindowLongPtr_(result,#GWL_WNDPROC,@ScintillaCharCallback())
.
.

		style=#Style_Title|$80
		ScintillaSendMessage(gadget,#SCI_STYLESETSIZE,style,11)
		ScintillaSendMessage(gadget,#SCI_STYLESETBOLD,style,#True)
		ScintillaSendMessage(gadget,#SCI_STYLESETITALIC,style,#False)
		ScintillaSendMessage(gadget,#SCI_STYLESETUNDERLINE,style,#False)
		;ScintillaSendMessage(gadget,#SCI_STYLESETHOTSPOT,style,#True)
		ScintillaSendMessage(gadget,#SCI_STYLESETCHANGEABLE,style,#False)   ; <--- also important
		ScintillaSendMessage(gadget,#SCI_STYLESETEOLFILLED,style,#True)
.
.
Note: This is just a small section of code, it doesn't work on its own - you should adapt it to your particular case.