FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Base sample with scintilla
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Base sample with scintilla
Posted: Thu Mar 08, 2018 01:28 PM
Hello,
I am trying to use scintilla in my program to syntax highlight, but it have no lucky...
Code (fw): Select all Collapse
#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: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?
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Base sample with scintilla
Posted: Thu Mar 08, 2018 03:01 PM

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

Sample of use

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

viewtopic.php?f=3t=35301p=210187hilit=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
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Base sample with scintilla
Posted: Thu Mar 15, 2018 08: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

Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Base sample with scintilla
Posted: Thu Mar 15, 2018 08:43 AM
You should use
Code (fw): Select all Collapse
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Base sample with scintilla
Posted: Thu Mar 15, 2018 09: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Base sample with scintilla
Posted: 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
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Base sample with scintilla
Posted: 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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Base sample with scintilla
Posted: 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 )
::cLexer := 7
::SetLexer( 7 ) // SCLEX_SQL
::Setup()

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


Try with

::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
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Base sample with scintilla
Posted: 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.

Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Base sample with scintilla
Posted: Mon Mar 19, 2018 01:37 PM
have you tryied to setup some colors?
Code (fw): Select all Collapse
::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 (fw): Select all Collapse
 ::oEditor:SetKeyWords(0, "select from declare left right join merge where")
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Base sample with scintilla
Posted: Tue Mar 20, 2018 01:25 AM
Sample for SQL syntax



Code (fw): Select all Collapse
#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
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Base sample with scintilla
Posted: Tue Mar 20, 2018 08:42 AM

many thanks to AntoninoP and Cristobal,
i have tried both the examples and them work fine!

Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Base sample with scintilla
Posted: Wed Mar 21, 2018 10:29 AM

Days trying to make .ini highlight works and now, after build the dll, it works 8)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Base sample with scintilla
Posted: 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
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Base sample with scintilla
Posted: Wed Mar 21, 2018 02:49 PM
I recompiled SciLexer.dll
Here a screenshot of test program

And here the code:
Code (fw): Select all Collapse
#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 :-)