Base sample with scintilla

Base sample with scintilla

Postby AntoninoP » Thu Mar 08, 2018 1:28 pm

Hello,
I am trying to use scintilla in my program to syntax highlight, but it have no lucky...
Code: Select all  Expand view
#include "FiveWin.ch"
#include "Scintilla.ch"

function Main()
   LOCAL cIni, oWnd, nBits
   DEFINE WINDOW oWnd TITLE "TLPosWin - EtiW"
   
   cIni := MemoRead("test.ini")
   oWnd:oClient := TScintilla():New( 0, 0, 10,10,oWnd,RGB(0,0,0), RGB(255,255,255),SCLEX_PROPERTIES)
   oWnd:oClient:AddText(cIni)
   //oWnd:oClient:Setup()
   nBits  := oWnd:oClient:Send( SCI_GETSTYLEBITSNEEDED, 0, 0 )  // 8
   oWnd:oClient:Send( SCI_SETSTYLEBITS, Max( 5, nBits ) )
   oWnd:oClient:Send( SCI_SETLEXER, SCLEX_PROPERTIES,0 )
   oWnd:oClient:AddText(cIni)
   oWnd:oClient:StyleSetFont( "Lucida Console" )
   oWnd:oClient:Send( SCI_STYLESETFONT,STYLE_DEFAULT, "Lucida Console" )
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_DEFAULT   , RGB(0, 0, 0))
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_COMMENT   , RGB(128, 128, 128))
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_SECTION   , RGB(0, 0, 255))
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_ASSIGNMENT, RGB(0, 128, 0))
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_DEFVAL    , RGB(0, 0, 128))
   oWnd:oClient:Send(SCI_STYLESETFORE, SCE_PROPS_KEY       , RGB(255, 0, 0))
   oWnd:oClient:SetColourise()
   //*/
   
   ACTIVATE WINDOW oWnd
return 0


Help?
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Base sample with scintilla

Postby cnavarro » Thu Mar 08, 2018 3:01 pm

Look Function SourceEdit() in MEMOEDIT.PRG
With this function, you already have an editor using Scintilla

Sample of use

viewtopic.php?f=3&t=35301&p=210187&hilit=sourceedit#p210177

viewtopic.php?f=3&t=35301&p=210187&hilit=sourceedit#p210185
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Base sample with scintilla

Postby marzio » Thu Mar 15, 2018 8:24 am

i use the function SourceEdit() and the class fivedit0.prg from fivewin\samples to edit sql texts.
is it possible to change the list of key words sensitive to colors?
i want to add some SQL statements.
thanks
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: Base sample with scintilla

Postby AntoninoP » Thu Mar 15, 2018 8:43 am

You should use
Code: Select all  Expand view
oScintilla:SetKeyWords( 0, "keyword1 keyword2 keyword3" )

the first parameter is the index of keyword list
the second parameter is the list of keywords separated by space
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Base sample with scintilla

Postby Antonio Linares » Thu Mar 15, 2018 9:32 am

function SourceEdit() documentation:

http://wiki.fivetechsoft.com/doku.php?id=fivewin_function_sourceedit

This is a very powerful FWH function. Don't miss it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41404
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Base sample with scintilla

Postby cnavarro » Fri Mar 16, 2018 11:46 am

marzio wrote:i use the function SourceEdit() and the class fivedit0.prg from fivewin\samples to edit sql texts.
is it possible to change the list of key words sensitive to colors?
i want to add some SQL statements.
thanks


You must configure the lexer to use, before call to setup method

oEditor:cLexer := 7
oEditor:SetLexer( 7 ) // SCLEX_SQL
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Base sample with scintilla

Postby marzio » Mon Mar 19, 2018 10:36 am

oScintilla:SetKeyWords( 0, "keyword1 keyword2 keyword3" )
works fine.

i have tried this:
::oEditor = TScintilla():New( 0, 0 , 943, 400,, ::nTextColor, ::nBackColor, 519 )
::oEditor:cLexer := 7
::oEditor:SetLexer( 7 ) // SCLEX_SQL
::oEditor:Setup()

but i receive an error: Error BASE/1004 Message not found: TSCINTILLA:SETLEXER
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: Base sample with scintilla

Postby cnavarro » Mon Mar 19, 2018 10:45 am

marzio wrote:oScintilla:SetKeyWords( 0, "keyword1 keyword2 keyword3" )
works fine.

i have tried this:
::oEditor = TScintilla():New( 0, 0 , 943, 400,, ::nTextColor, ::nBackColor, 519 )
::oEditor:cLexer := 7
::oEditor:SetLexer( 7 ) // SCLEX_SQL
::oEditor:Setup()

but i receive an error: Error BASE/1004 Message not found: TSCINTILLA:SETLEXER


Try with

::oEditor:Send( 4001, 7, 0 )
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Base sample with scintilla

Postby marzio » Mon Mar 19, 2018 10:55 am

::oEditor:cLexer := 7
::oEditor:Send( 4001, 7, 0 )
::oEditor:Setup()

i have no difference in colors of SQL sintax.
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: Base sample with scintilla

Postby AntoninoP » Mon Mar 19, 2018 1:37 pm

have you tryied to setup some colors?
Code: Select all  Expand view
::oEditor:SetAStyle(SCE_SQL_COMMENTLINE ,RGB(128, 128, 128))
::oEditor:SetAStyle(SCE_SQL_NUMBER,RGB(64, 64, 255))
::oEditor:SetAStyle(SCE_SQL_WORD,RGB(255, 64, 0))
 

unfortunately you need to specify the keyword with
Code: Select all  Expand view
::oEditor:SetKeyWords(0, "select from declare left right join merge where")
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Base sample with scintilla

Postby cnavarro » Tue Mar 20, 2018 1:25 am

Sample for SQL syntax

Image

Code: Select all  Expand view


#include "fivewin.ch"

Static oDlg, oFont, oBold
Static cFileName    := "timezone_posix.sql"
Static cText      := ""
Static oMemo

Function Main()

   local oBtn1
   local bInit      := { | o | MySetup( o ) }
   
   SET DATE BRITISH
   SET DATE FORMAT TO "DD/MM/YYYY"
   SET CENTURY ON
   cText   := MemoRead( cFileName )
   DEFINE FONT oFont NAME "Arial" SIZE 0,-14
   
   DEFINE DIALOG oDlg FROM 30, 30 TO 24, 55   SIZE 1265, 730 PIXEL TRUEPIXEL FONT oFont ;
   TITLE "SAMPLE SOURCEEDIT SQL LEXER - " + FWVERSION

   @ 649, 1130 BTNBMP oBtn1 OF oDlg SIZE 95, 40 PIXEL ;
      PROMPT " &Exit " ACTION oDlg:End()
   
   ACTIVATE DIALOG oDlg ;
      ON INIT SourceEdit( cText, , , 2, 2, 600, 1200, , , , , ;
                          oDlg, , , 7, , , , bInit )
   RELEASE FONT oFont
   
RETURN NIL

//----------------------------------------------------------------------------//

#define SCE_SQL_DEFAULT 0
#define SCE_SQL_COMMENT 1
#define SCE_SQL_COMMENTLINE 2
#define SCE_SQL_COMMENTDOC 3
#define SCE_SQL_NUMBER 4
#define SCE_SQL_WORD 5
#define SCE_SQL_STRING 6
#define SCE_SQL_CHARACTER 7
#define SCE_SQL_SQLPLUS 8
#define SCE_SQL_SQLPLUS_PROMPT 9
#define SCE_SQL_OPERATOR 10
#define SCE_SQL_IDENTIFIER 11
#define SCE_SQL_SQLPLUS_COMMENT 13
#define SCE_SQL_COMMENTLINEDOC 15
#define SCE_SQL_WORD2 16
#define SCE_SQL_COMMENTDOCKEYWORD 17
#define SCE_SQL_COMMENTDOCKEYWORDERROR 18
#define SCE_SQL_USER1 19
#define SCE_SQL_USER2 20
#define SCE_SQL_USER3 21
#define SCE_SQL_USER4 22
#define SCE_SQL_QUOTEDIDENTIFIER 23
#define SCE_SQL_QOPERATOR 24

//----------------------------------------------------------------------------//

Function MySetup( o )

   local x
   local aStyle := { "000000", "007F00", "0F0F0F", "007F7F", "00007F", "7F007F", "7F007F", ;
            "07F000", "007F00", "E0FFE0", "FF0000", "000000", "E0C0E0", "007F00", ;
            "007F00", "B00040", "3060A0", "804020", "4B0082", "B00040", "8B0000", ;
            "800080", "0000FF", "00FF00", "FF0000" }

   o:nClrText     := CLR_BLUE
   o:nClrPane     := CLR_WHITE
   o:cLexer := 7
   o:Send( 4001, 7, 0 )

   o:lFolding  := .T.
   PonFold( o:hWnd, "fold" , "1" )
   PonFold( o:hWnd, "fold.sql.at.else", "1" )
   PonFold( o:hWnd, "fold.comment", "1" )
   PonFold( o:hWnd, "fold.compact", "1" )
   PonFold( o:hWnd, "fold.sql.only.begin", "1" )
   PonFold( o:hWnd, "lexer.sql.backticks.identifier", "1" )
   PonFold( o:hWnd, "lexer.sql.numbersign.comment", "1" )
   PonFold( o:hWnd, "sql.backslash.escapes", "1" )
   PonFold( o:hWnd, "lexer.sql.allow.dotted.word", "1" ) //(recommended for Oracle PL/SQL objects)
   o:SetAutomaticFold( 2 )

   o:SetColourise( .T. )
   o:SetCharsDefault()
   o:SetWordChars( o:cChars )
   o:SetKeywords( 0, "add alter as asc authorization backup begin break browse bulk by cascade case " + ;
      "check checkpoint close clustered column commit compute constraint containstable continue create current current_date " + ;
      "cursor database dbcc deallocate declare default delete deny desc disk distinct distributed double drop dump else end " + ;
      "errlvl escape except exec execute exit external fetch file fillfactor for foreign freetext freetexttable from full " + ;
      "function goto grant group having holdlock identity identity_insert identitycol if index insert intersect into key " + ;
      "kill lineno load merge national nocheck nonclustered of off offsets on open opendatasource openquery openrowset " + ;
      "openxml option order over percent plan precision primary print proc procedure public raiserror read readtext " + ;
      "reconfigure references replication restore restrict return revert revoke rollback rowcount rowguidcol rule save " + ;
      "schema securityaudit select semantickeyphrasetable semanticsimilaritydetailstable semanticsimilaritytable set " + ;
      "setuser shutdown statistics table tablesample textsize then to top tran transaction trigger truncate union unique " + ;
      "updatetext use user values varying view waitfor when where while with within group writetext" )
   o:SetKeywords( 1, "coalesce collate contains convert current_time current_timestamp current_user " + ;
      "nullif session_user system_user try_convert tsequal update" )
   o:SetKeywords( 2, "all and any between cross exists in inner is join left like not null or outer pivot " + ;
      "right some unpivot" )
   o:SetColorCaret( CLR_HGRAY, .T. )
   o:SetPunctuationChars( o:cPuntChars )
   For x = 0 to 255 //24
      if x <= 24
         if x != 14
            o:StyleSet( x )
            o:StyleSetColor( HexToDec( aStyle[ x + 1 ] ), o:nClrPane )
         endif
      else
            o:StyleSet( x )
            o:StyleSetColor( o:nClrText, o:nClrPane )
      endif
   Next x
   o:Send( 2051, 32, o:nClrText )
   o:Send( 2052, 32, o:nClrPane )
   o:Send( 2051, 34, CLR_GREEN )
   o:Send( 2052, 34, o:nClrPane )
   o:Send( 2051, 35, CLR_RED )
   o:Send( 2052, 35, o:nClrPane )
   o:SetSavePoint()

Return nil

//----------------------------------------------------------------------------//
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Base sample with scintilla

Postby marzio » Tue Mar 20, 2018 8:42 am

many thanks to AntoninoP and Cristobal,
i have tried both the examples and them work fine!
marzio
 
Posts: 129
Joined: Wed Apr 04, 2007 6:54 am

Re: Base sample with scintilla

Postby AntoninoP » Wed Mar 21, 2018 10:29 am

Days trying to make .ini highlight works and now, after build the dll, it works 8)
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Base sample with scintilla

Postby Antonio Linares » Wed Mar 21, 2018 11:30 am

Antonino,

What DLL ? :-)

A screenshot of your INI highlighting surely will be appreciated
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41404
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Base sample with scintilla

Postby AntoninoP » Wed Mar 21, 2018 2:49 pm

I recompiled SciLexer.dll
Here a screenshot of test program
Image
And here the code:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "Scintilla.ch"

function Main()
   LOCAL cIni, oWnd, nBits
   DEFINE WINDOW oWnd TITLE "TLPosWin - EtiE"

   //cIni := MemoRead("C:\TL\Utility\TLEtiW\test\Pos\Mag1\Eti\0_pelllicano_scaffale_pdf.ini")
   cIni := MemoRead("C:\pos\config\tlposwin.ini")
   //cIni := MemoRead("C:\fwh32\samples\scintilla\src\SciTE.properties")
   nBits := SCLEX_PROPERTIES

   oWnd:oClient := MyScintilla():New( 0, 0, 10,10,oWnd,RGB(0,0,0), RGB(255,255,255),SCLEX_PROPERTIES)
   oWnd:oClient:SetText(cIni)
   oWnd:oClient:Refresh()
   ACTIVATE WINDOW oWnd
return 0

class MyScintilla FROM TScintilla
   METHOD Setup
endclass

METHOD Setup( nMark, lInit ) CLASS MyScintilla
   ::SendMsg( SCI_SETLEXER, SCLEX_PROPERTIES, 0 )
   ::SendMsg( SCI_SETSTYLEBITS, 5 )
   ::SendMsg(SCI_STYLECLEARALL)

   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_DEFAULT   , CLR_BLACK)
   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_COMMENT   , CLR_GRAY)
   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_SECTION   , CLR_BLUE)
   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_ASSIGNMENT, RGB(255, 128, 0))
   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_DEFVAL    , RGB(0, 0, 128))
   ::SendMsg(SCI_STYLESETFORE, SCE_PROPS_KEY       , CLR_RED)
   ::SendMsg(SCI_STYLESETBOLD, SCE_PROPS_KEY, 1)
   ::SendMsg(SCI_STYLESETEOLFILLED,  SCE_PROPS_SECTION, 1)
   PonFold( ::hWnd , "lexer.props.allow.initial.spaces" , "1" )
   PonFold( ::hWnd , "fold" , "1" )
   PonFold( ::hWnd , "fold.compact" , "0" )
   
   ::SendMsg( SCI_STYLESETFONT,STYLE_DEFAULT, "Lucida Console" )
   ::SendMsg( SCI_SETMARGINTYPEN, 1, SC_MARGIN_NUMBER )
   ::SendMsg( SCI_SETMARGINWIDTHN, 1, 40 )
   ::SendMsg( SCI_SETMARGINSENSITIVEN, 1, 1)
   //::Send( SCI_STYLESETBACK , STYLE_LINENUMBER , RGB(0,255,255) ) //CLR_VSBAR )
   //::Send( SCI_STYLESETFORE , STYLE_LINENUMBER , RGB(0,255,255)) //CLR_BLUE )
     
   ::SendMsg(SCI_SETAUTOMATICFOLD, SC_AUTOMATICFOLD_CLICK,0)
   ::SendMsg( SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL )
   ::SendMsg( SCI_SETMARGINWIDTHN, 2, 15 )
   ::SendMsg( SCI_SETMARGINMASKN , 2, SC_MASK_FOLDERS )
   ::SendMsg( SCI_SETMARGINSENSITIVEN, 2, 1 )
   ::SendMsg( SCI_SETFOLDMARGINCOLOUR, 2, RGB(0,255,255) ) //CLR_VSBAR )
   ::SendMsg( SCI_MARKERDEFINE,SC_MARKNUM_FOLDEROPEN,SC_MARK_BOXMINUS)
   ::SendMsg( SCI_MARKERDEFINE,SC_MARKNUM_FOLDER,SC_MARK_BOXPLUS)
   ::SendMsg( SCI_MARKERDEFINE,SC_MARKNUM_FOLDERSUB,SC_MARK_VLINE)
   ::SendMsg( SCI_MARKERDEFINE,SC_MARKNUM_FOLDERTAIL,SC_MARK_LCORNERCURVE)
   ::SendMsg( SCI_MARKERSETFORE,SC_MARKNUM_FOLDER, CLR_WHITE)
   ::SendMsg( SCI_MARKERSETBACK,SC_MARKNUM_FOLDER, CLR_BLACK)
   ::SendMsg( SCI_MARKERSETFORE,SC_MARKNUM_FOLDEROPEN,CLR_WHITE)
   ::SendMsg( SCI_MARKERSETBACK,SC_MARKNUM_FOLDEROPEN,CLR_BLACK)
   ::SendMsg( SCI_MARKERSETBACK,SC_MARKNUM_FOLDERSUB,CLR_BLACK)
   ::SendMsg( SCI_MARKERSETBACK,SC_MARKNUM_FOLDERTAIL,CLR_BLACK)  
   ::SetSavePoint()
return nil

I had to overwrite Setup method of TScintilla because it changes all setting every refresh :shock:
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 20 guests