ScintillaGadget best event for hightlighting same words selected [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

ScintillaGadget best event for hightlighting same words selected [Resolved]

Post by Kwai chang caine »

Hello at all

Thanks to Danilo/Zebuddhi, I was able to adapt (I don't know by what miracle :shock: ) an external PB tool code for highlighting identical words, to code for the same function, but for an internal SyntillaGadget 8)
But after...i don't know where i must put this code ? :oops: on what event ?
After several try, i have put it in the #SCN_Painted of the SyntillaCallback()
That works, bit did i do well? or as usual, i'm way off base ? :mrgreen:

Code: Select all

; Code de départ de Zebuddhi pour outil IDE externe en EXE => https://www.purebasic.fr/english/viewtopic.php?p=381547#p381547
; Modifié par KCC pour ScintillaGadget interne le 30/7/2024

#INDIC_STRAIGHTBOX = 8
#SCI_INDICSETALPHA          = 2523
#SCI_INDICSETOUTLINEALPHA   = 2558

Procedure ScintillaCallBack(ScintillaGadget.l, *scinotify.SCNotification)
 
 Static MemSelectionTexte.s
 
 Select *scinotify\nmhdr\code
   
  Case #SCN_PAINTED
   
   ; Détection du texte sélectionné
   SelectionStart = ScintillaSendMessage(ScintillaGadget,#SCI_GETSELECTIONSTART,0,0)
   SelectionEnd = ScintillaSendMessage(ScintillaGadget,#SCI_GETSELECTIONEND  ,0, 0)
   buffer$ = Space(LongueurSelection)
   ScintillaSendMessage(ScintillaGadget, #SCI_GETSELTEXT, LongueurSelection, @buffer$)
   SelectionTexte$ = PeekS(@buffer$, -1, #PB_UTF8)
   
   If SelectionTexte$ <> MemSelectionTexte
    
    MemSelectionTexte = SelectionTexte$
    Length = ScintillaSendMessage(ScintillaGadget,#SCI_GETTEXTLENGTH , 0, 0)
    ScintillaSendMessage(ScintillaGadget,#SCI_INDICATORCLEARRANGE, 0, length)
    wordlen = Len(SelectionTexte$)
    
    ; Retourner tout le texte
    MaxTexte = ScintillaSendMessage(ScintillaGadget, #SCI_GETLENGTH) + 1
    buffer$ = Space(MaxTexte)
    ScintillaSendMessage(ScintillaGadget, #SCI_GETTEXT, MaxTexte, @buffer$)
    Texte$ = PeekS(@buffer$, -1, #PB_UTF8)
    
    If Texte$ <> ""
     
     pos = 1
     
     Repeat
      
      Pos = FindString(LCase(Texte$), LCase(SelectionTexte$), pos)
      
      If Pos
       
       ScintillaSendMessage(ScintillaGadget,#SCI_INDICATORFILLRANGE, Pos - 1, wordlen)
       Pos + wordlen
       
      EndIf
      
     Until pos = 0
     
    EndIf
    
   EndIf
      
 EndSelect   
   
EndProcedure

style = #INDIC_STRAIGHTBOX
color = RGB($00,$FF,$FF)
InnerAlpha  =  50
BorderAlpha = 200

InitScintilla("Scintilla.dll")

OpenWindow(0,10,150,650,500,"Test",#PB_Window_SystemMenu)
Scintilla = ScintillaGadget(#PB_Any, 0, 0, 650, 500, @ScintillaCallBack())
Text$ = "Hello Hello !!! i'm KCC and KCC say the best Hello" + #CRLF$ + "of all the Hello of the world"
*PtrText = UTF8(Text$)
ScintillaSendMessage(Scintilla, #SCI_SETTEXT, 0, *PtrText)
FreeMemory(*PtrText)
RedrawWindow_(GadgetID(Scintilla), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)

ScintillaSendMessage(Scintilla,#SCI_SETINDICATORCURRENT  ,9, 0          )
ScintillaSendMessage(Scintilla,#SCI_INDICSETSTYLE        ,9, style      )
ScintillaSendMessage(Scintilla,#SCI_INDICSETFORE         ,9, color      )
ScintillaSendMessage(Scintilla,#SCI_INDICSETALPHA        ,9, InnerAlpha )
ScintillaSendMessage(Scintilla,#SCI_INDICSETOUTLINEALPHA ,9, BorderAlpha)
ScintillaSendMessage(Scintilla,#SCI_INDICSETUNDER        ,9, #False     )

Repeat  
 Evenement = WaitWindowEvent()
Until Evenement = #PB_Event_CloseWindow
Have a good day
Last edited by Kwai chang caine on Wed Jul 31, 2024 5:17 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: ScintillaGadget best event for hightlighting same words selected

Post by skywalk »

ScintillaSendMessage(Scintilla,#SCI_INDICSETUNDER ,9, #False)

What does the constant 9 do?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: ScintillaGadget best event for hightlighting same words selected

Post by spikey »

Kwai chang caine wrote: Tue Jul 30, 2024 6:45 pm But after...i don't know where i must put this code ? :oops: on what event ?
After several try, i have put it in the #SCN_Painted of the SyntillaCallback()
#SCN_Painted occurs quite a lot, for example every time the cursor flashes. I wonder if this might become noticeable in larger texts. You could try #SCN_UpdateUI which doesn't occur quite so often. It's just an opinion though.
skywalk wrote: Tue Jul 30, 2024 7:25 pm ScintillaSendMessage(Scintilla,#SCI_INDICSETUNDER ,9, #False)

What does the constant 9 do?

Scintilla defines a number of indicator styles, 9 is the second indicator in the "container" group which is intended for the purposes of the application containing the gadget.
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: ScintillaGadget best event for hightlighting same words selected

Post by skywalk »

Thanks, I searched a lot for where this is defined.
Do you have a link?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: ScintillaGadget best event for hightlighting same words selected

Post by spikey »

skywalk wrote: Tue Jul 30, 2024 9:41 pm Do you have a link?
https://www.scintilla.org/ScintillaDoc.html#Indicators
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: ScintillaGadget best event for hightlighting same words selected

Post by AZJIO »

See Grub2-generator or My_Notepad_Sci.

Code: Select all

			Case #SCN_UPDATEUI
				If \updated & #SC_UPDATE_SELECTION ; если происходит выделение текста и перемещение текстового курсора
					If ScintillaSendMessage(#Edit, #SCI_GETSELECTIONEMPTY) ; Если 0, то выделен 1 и более символов, если 1 то ничего не выделено
						If flgHSel
							ScintillaSendMessage(#Edit, #SCI_INDICATORCLEARRANGE, 0, ScintillaSendMessage(#Edit, #SCI_GETTEXTLENGTH))
						EndIf
					Else
						HighlightSelection()
					EndIf
				EndIf

Code: Select all

Procedure HighlightSelection()
	Protected length, Cursor, Anchor, *pos ; , Selected$
	Protected length2, StartPos, EndPos, firstMatchPos, *Search
	Protected inSrt, inEnd
	Cursor = ScintillaSendMessage(#Edit, #SCI_GETCURRENTPOS)
	Anchor = ScintillaSendMessage(#Edit, #SCI_GETANCHOR)
	If Anchor < Cursor
		Swap Cursor, Anchor
	EndIf
	length = Anchor - Cursor
	If Cursor <> ScintillaSendMessage(#Edit, #SCI_WORDSTARTPOSITION, Cursor, 1) Or Anchor <> ScintillaSendMessage(#Edit, #SCI_WORDENDPOSITION, Anchor, 1)
		ProcedureReturn
	EndIf


	*pos = ScintillaSendMessage(#Edit, #SCI_GETCHARACTERPOINTER) ; прямой доступ
; 	Selected$ = PeekS(*pos + Cursor, length, #PB_UTF8 | #PB_ByteLength)




	*Search = *pos + Cursor
	ScintillaSendMessage(#Edit, #SCI_INDICATORCLEARRANGE, 0, ScintillaSendMessage(#Edit, #SCI_GETTEXTLENGTH))
	; Устанавливает целевой диапазон поиска
	inSrt = 0
	inEnd = ScintillaSendMessage(#Edit, #SCI_GETTEXTLENGTH) ; получает длину текста
	ScintillaSendMessage(#Edit, #SCI_SETTARGETSTART, inSrt)    ; от начала (задаём область поиска) используя позицию конца предыдущего поиска
	ScintillaSendMessage(#Edit, #SCI_SETTARGETEND, inEnd)	   ; до конца по длине текста

	ScintillaSendMessage(#Edit, #SCI_SETSEARCHFLAGS, #SCFIND_MATCHCASE)
; 	lengthStr = Len(SearchTxt$)

	ScintillaSendMessage(#Edit, #SCI_BEGINUNDOACTION)
	Repeat
		; 		нашли
		firstMatchPos = ScintillaSendMessage(#Edit, #SCI_SEARCHINTARGET, length, *Search)
		; 		Debug firstMatchPos
		If firstMatchPos = -1
			; выпрыг если не найдено
			Break
		EndIf

		flgHSel = 1
		StartPos = ScintillaSendMessage(#Edit, #SCI_GETTARGETSTART)        ; получает позицию начала найденного
		EndPos = ScintillaSendMessage(#Edit, #SCI_GETTARGETEND)			   ; получает позицию конца найденного
		length2 = EndPos - StartPos
; 		чтобы не подсвечивать само выделяемое слово
		If StartPos <> Cursor
; 			Count + 1 ; здесь можно осуществить подсчёт выделенных не затрачивая особых ресурсов
; 			Continue
			ScintillaSendMessage(#Edit, #SCI_INDICATORFILLRANGE, StartPos, length2)  ; выделяет текст используя текущий индикатор
		EndIf

		inSrt = firstMatchPos + length2 ; задать диапазон поиска
										; Устанавливает целевой диапазон поиска
		inEnd = ScintillaSendMessage(#Edit, #SCI_GETTEXTLENGTH) ; получает длину текста
																	; 	ScintillaSendMessage(#Edit, #SCI_SETTARGETRANGE, inSrt, inEnd) ; задать диапазон поиска
		ScintillaSendMessage(#Edit, #SCI_SETTARGETSTART, inSrt)	; от начала (задаём область поиска) используя позицию конца предыдущего поиска
		ScintillaSendMessage(#Edit, #SCI_SETTARGETEND, inEnd)	; до конца по длине текста

	ForEver
EndProcedure
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: ScintillaGadget best event for hightlighting same words selected

Post by skywalk »

spikey wrote: Tue Jul 30, 2024 10:12 pm
skywalk wrote: Tue Jul 30, 2024 9:41 pm Do you have a link?
https://www.scintilla.org/ScintillaDoc.html#Indicators
Ha! I was reading that when I asked my question. I need to review this in the Scite editor source code. I can't understand code without enumerated constants.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5500
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ScintillaGadget best event for hightlighting same words selected

Post by Kwai chang caine »

Hello at all and thanks for your quick and precious helps 8)

@Spikey
Effectively #SCN_UPDATEUI works perfectly :D

Code: Select all

#SCN_Painted occurs quite a lot, for example every time the cursor flashes
You have surely right, perhaps it's a little bit too much
It's the problem in this style of case, sometime we surely call too much a procedure, but it is not visible and we believe that we have worked well, while the processor pedals like crazy :lol:

Image

I'm sure several softwares in the world, have this problem without the programmer know or do something, and the processor want fuck it all up for say stop :mrgreen:

Image

@AZJIO
Thanks a lot for sharing a new time your code 8)

I have see your nice program Grub, but i say to me : "KCC you are already bad enough with WINDOWS, so no need to stick your snout in LINUX. :oops:
LINUX can easily exist, without KCC .... !!!" :mrgreen:
And like an idiot, I did not look at your code for once. :oops:

And for your nice "My_Notepad_Sci", it's worst again, you create and sharing so much wonderfull works 8) , than i have forgotten you had create something like i search :oops:
In fact, i wanted to create a little NotePad++ but the simplest possible, because the real one becomes, like most software now, for me a plane and in addition I still had problems with my worst enemy that is to say UNICODE :twisted:

So I said to myself : "It seems that this Scintilla is powerful and great, so it's time to me, to try it, I should only have 2 to 3 days!!!" :D
And indeed the numbers was good, but it was in weeks and :mrgreen: , i am still far from finished. :mrgreen:

And yet, before starting a new program (That I would never finish like usually due to lack of time :oops: ) I looked to see if there was something already well advanced among my friends, and I didn't find much :|
So like an idiot, I almost started from nothing or nearly, because I started with the Falsam code (Which I thank by the way :wink: )
https://www.purebasic.fr/french/viewtop ... 31#p182031

The only functions that I mainly want are:


1/ Folding
2/ Highlighting identical words
3/ Syntax color
4/ Search
5/ FTP for HTML/PHP/JS coding

And all that in PB, like that i can customize it :idea:

And I forgot your little jewel "My_Notepad_Sci ", which may already do all that...I'll take a look now :wink:
Besides, I take advantage of this message to thank you again for all this shared work and your many helps all the days for the familly PB 8)

@ALL
Again thanks for your precious help my friends 8)

No need to say to you all another time, than i love you :wink:
ImageThe happiness is a road...
Not a destination
Post Reply