GoScintilla - 2.7 (Purebasic 4.5 onwards)

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by ts-soft »

Here my simple search version without regex:

Code: Select all

Procedure GoSCI_Search(id, search.s, direction, flags)
  Protected *mem, pos, result
  Protected selstart, selend

  If search
    *mem = AllocateMemory(StringByteLength(search, #PB_UTF8) + 1)
    If *mem
      PokeS(*mem, search, -1, #PB_UTF8)
     
      If direction = 0
        pos = ScintillaSendMessage(id, #SCI_GETSELECTIONSTART) - 1
      Else
        pos = ScintillaSendMessage(id, #SCI_GETSELECTIONEND) + 1
      EndIf
      ScintillaSendMessage(id, #SCI_SETSEL, pos, pos)
      ScintillaSendMessage(id, #SCI_SEARCHANCHOR)
      If direction
        result = ScintillaSendMessage(id, #SCI_SEARCHNEXT, flags, *mem)
      Else
        result = ScintillaSendMessage(id, #SCI_SEARCHPREV, flags, *mem)
      EndIf
      If result <> -1
        selstart = ScintillaSendMessage(id, #SCI_GETSELECTIONSTART)
        selend = ScintillaSendMessage(id, #SCI_GETSELECTIONEND)
        GOSCI_SetState(id, #GOSCI_CURRENTLINE, ScintillaSendMessage(id, #SCI_LINEFROMPOSITION, result))
        ScintillaSendMessage(id, #SCI_SETSELECTIONSTART, selstart)
        ScintillaSendMessage(id, #SCI_SETSELECTIONEND, selend)
        ScintillaSendMessage(id, #SCI_SCROLLCARET)
      EndIf
      FreeMemory(*mem)
    EndIf
    
    ProcedureReturn result
  EndIf

EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by srod »

The problem with that method Thomas is that the control can be scrolled even when no match is found because you are using the #SCI_SETSEL message regardless.

You're best off, inmo, using a targeted search.

Here's my version which I will add to the next update of GoScintilla.

Code: Select all

Procedure GOSCI_Search(id, search.s, direction=#GOSCI_SEARCHFORWARDS, flags=0)
  Protected result, *mem, pos, numBytes, byteLen
  Protected selstart, selend
  If IsGadget(id) And GadgetType(id) = #PB_GadgetType_Scintilla And search
    numBytes = ScintillaSendMessage(id, #SCI_GETLENGTH)
    If numBytes
      byteLen = StringByteLength(search, #PB_UTF8)
      *mem = AllocateMemory(byteLen+1)
      If *mem
        PokeS(*mem, search, -1, #PB_UTF8)
        ScintillaSendMessage(id, #SCI_SETSEARCHFLAGS, flags)
        If direction = #GOSCI_SEARCHBACKWARDS
          pos = ScintillaSendMessage(id, #SCI_GETSELECTIONSTART)
          ScintillaSendMessage(id, #SCI_SETTARGETSTART, pos)
          ScintillaSendMessage(id, #SCI_SETTARGETEND, 0)
          result = ScintillaSendMessage(id, #SCI_SEARCHINTARGET, byteLen, *mem)
          If result <> -1
            ScintillaSendMessage(id, #SCI_SETSEL, ScintillaSendMessage(id, #SCI_GETTARGETSTART), ScintillaSendMessage(id, #SCI_GETTARGETEND))
          EndIf
        Else
          pos = ScintillaSendMessage(id, #SCI_GETSELECTIONEND)
          ScintillaSendMessage(id, #SCI_SETTARGETSTART, pos)
          ScintillaSendMessage(id, #SCI_SETTARGETEND, numBytes)
          result = ScintillaSendMessage(id, #SCI_SEARCHINTARGET, byteLen, *mem)
          If result <> -1
            ScintillaSendMessage(id, #SCI_SETSEL, ScintillaSendMessage(id, #SCI_GETTARGETSTART), ScintillaSendMessage(id, #SCI_GETTARGETEND))
          EndIf
        EndIf
        FreeMemory(*mem)
      EndIf
    EndIf
    ProcedureReturn result
  EndIf
EndProcedure
You will need to add the following to the header file :

Code: Select all

;Search direction.
  Enumeration
    #GOSCI_SEARCHBACKWARDS
    #GOSCI_SEARCHFORWARDS
  EndEnumeration
Last edited by srod on Mon Jul 02, 2012 2:31 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by ts-soft »

Hello Stephen,
byteLen doesn't include place for the stringterminator, i think it is better to add a byte for this.
Have you made a test with purifier?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by srod »

The null terminator is not required for the #SCI_SEARCHINTARGET message. :wink:

**EDIT : ah yes, for the PokeS()!

I shall edit the code. Thanks.

Why would I run the purifier?
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by ts-soft »

srod wrote:Why would I run the purifier?
The should say you, there is to small memory allocation for PokeS :wink:
I have not tested your code with purifier, i am to lazy to write a example,
but i test most time my allocations with purifier!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by srod »

Not required as I see it. The memory allocation is now correct.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by srod »

GoScintilla 2.7 - 11th Aug 2012

GoScintilla 2.7 adds a targeted search facility as well as a facility for highlighting error lines (typically those which generate compiler errors etc).

The history.txt file lists the detailed changes as of course does the .chm help manual.

In terms of error markers; GoScintilla can highlight any lines deemed to contain errors in much the same way that the PB IDE highlights lines which generate compiler errors.

Please note that error markers are implemented by means of a suitable Scintilla marker and share the same margin as GoScintilla bookmarks. For this reason, it is very important that you read the relevant parts of the GoScintilla user manual if using both bookmarks and error markers with the same document etc.

There is a demo showing the error markers in use.

Please see the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GoScintilla - 2.6 (Purebasic 4.5 onwards)

Post by ts-soft »

Image for the update
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by LCD »

Update to 5.10 final made GoSci not working anymore because of "disallow native type for pointers"... (because beginners were "confused" by this). I'm confused by this.
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by srod »

Just remove the .i or .q etc. from which ever statements cause the compiler to fail.

On beta 4 (haven't upgraded to the final version yet) I only had to alter 1 such line.

Change

Code: Select all

*bytePointer.i
to

Code: Select all

*bytePointer
I may look like a mule, but I'm not a complete ass.
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by LCD »

srod wrote:Just remove the .i or .q etc. from which ever statements cause the compiler to fail.

On beta 4 (haven't upgraded to the final version yet) I only had to alter 1 such line.

Change

Code: Select all

*bytePointer.i
to

Code: Select all

*bytePointer
Thanks, this works now...
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
User avatar
venom27
User
User
Posts: 10
Joined: Mon Sep 14, 2009 5:30 pm
Location: . <------ ici
Contact:

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by venom27 »

Hello,

Thank you for this superb LIB. 8)
I do not speak much English, but can change the background color?
Sorry if the question was already asked. :?


EDIT :
I found my answer :wink:

Code: Select all

GOSCI_SetColor(id, #GOSCI_BACKCOLOR, Color)








@++
Windows 10 x64, PureBasic 5.71 Beta 1 x86 & x64
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by uwekel »

Hi,

i wasn't able to change the line number back and fore colors. I wanted to change them to black background and white text color.
Example:

Code: Select all

GOSCI_SetColor(1, #GOSCI_LINENUMBERBACKCOLOR, $000000)
GOSCI_SetColor(1, #GOSCI_LINENUMBERFORECOLOR, $FFFFFF)
This has no effect :-(
Any ideas?

Btw, line 40 and 41 of the header file seems to have a bug, the letter "O" is missing:

Code: Select all

      #GSCI_CALLTIPBACKCOLOR              ;Get/Set.
      #GSCI_CALLTIPFORECOLOR              ;Get/Set.
Best regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by srod »

GOSCI_SetFont() and GOSCI_SETCOLOR() with #GOSCI_BACKCOLOR or #GOSCI_FORECOLOR resets the various styles.

Hence, you should place all line-number color changes after any of these statements.
I may look like a mule, but I'm not a complete ass.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: GoScintilla - 2.7 (Purebasic 4.5 onwards)

Post by uwekel »

srod wrote:GOSCI_SetFont() ... resets the various styles.
That's it :-)
Thx a lot, srod!
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Post Reply