Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: scintilla (texteditor) example :)

  1. #1

    scintilla (texteditor) example :)

    hello. I have made a little scintilla example you can see as attachement (zip folder).

    question: only one question around that in my code example. I wanted to have a messagebox with buffer (text) feedback. other things are all ok! perhaps anybody can check this code example.

    for testing use: type in some words and push different buttons.

    sunny days, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by largo_winch; 23-05-2011 at 09:17.

  2. #2
    few progress I've done but I think nobody has big interests in scintilla (editor basis) example?
    the example works. but I am still looking for getting buffer (here text) in message box. perhaps somebody can help.

    %SCLEX_ThinBASIC doesn't exist so I have chosed %SCLEX_POWERBASIC.

       buffer=trimfull$(nLen+1)
    
    or

       buffer=iff$(nLen+1, %TRUE, %TRUE)
    
    doesn't work for my idea. any idea?
    zip folder I added.

    scintillal example:
                                      ' Empty GUI script created on 05-21-2011 19:54:23 by  (ThinAIR)
    
    ' Empty GUI script created on 05-19-2011 08:41:54 by largo_winch (ThinAIR)
    Uses "ui","console"
    
    '#INCLUDE "%APP_INCLUDEPATH%\scintillalw.inc"
    #INCLUDE "scintillalw.inc"
    
    %SCLEX_THINBASIC = 510
    %ID_Sci = 2000 : %ID_Sci2 = 2001
    %ID_Button = 2002 : %ID_Button2 = 2003
    %ID_TEXT = 2004 : %ID_TEXT2 = 2005
    
    Global hDlg, hSci, hSci2 As DWord
    
    Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (lpLibFileName As Asciiz) As Long
    Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long
    
    '-------------------------> Main Dialog -------------------------------------------->
    Function TBMain() As Long
       Local hLib As DWord
    
       hLib = LoadLibrary("SCILEXER.DLL")
       Dialog New Pixels, 0, "Scintilla GetText+SetText Example",200,200,600,440, %WS_OVERLAPPEDWINDOW To hDlg
       Control Add Button, hDlg, %ID_Button, "result1", 10,10,60,20
       Control Add Button, hDlg, %ID_Button2, "result2", 300,10,60,20
       Control Add "Scintilla", hDlg, %ID_Sci, "", 10,50,280,280, %WS_CHILD Or %WS_VISIBLE
       Control Add "Scintilla", hDlg, %ID_Sci2, "", 310,50,280,280, %WS_CHILD Or %WS_VISIBLE
       Control Handle hDlg, %ID_Sci To hSci     
       Control Handle hDlg, %ID_Sci2 To hSci2   
       Dialog Show Modal hDlg Call DlgProc
    
    End Function
    
    '---------------------------------> CALLBACK FUNCTIONS --------------------------->
    CallBack Function DlgProc() As Long
       Local txt As String, buffer As String 
       Local hLib As DWord, nLen As Long, v As Long   
    
       Select Case CBMSG 
       Case %WM_INITDIALOG
             StartSci
          Case %WM_COMMAND
             If CBCTL = %ID_Button Then
             nLen = SendMessage(hSci, %SCI_GETTEXTLENGTH, 0, 0)                   
             MsgBox 0, "characters lenght: "+Str$(nLen) 'ok :)
             '------------------------------------------------> ?        
             'Buffer = IIf$(nLen + 1,%TRUE,%TRUE)
             Buffer = TrimFull$(nLen+99999)',%TRUE,%TRUE)      
             '------------------------------------------------> ?
              'not ok: I need here a NUMERIC EXPRESSION         
             SendMessage(hSci, %SCI_GETTEXT, Len(Buffer), StrPtr(Buffer))         
             'SendMessage (hSci2, %SCI_SETTEXT, 0, StrPtr(Buffer))
             SendMessage (hSci, %SCI_SetMarginWidthN, 0, 20)                  
             MsgBox 0, buffer 'only for testpurpose to see the typed in text (in messagebox)!           
             End If
                                                          
    
             If CBCTL = %ID_Button2 Then                      
             nLen = SendMessage(hSci2, %SCI_GETTEXTLENGTH, 0, 0)
             MsgBox 0, "characters lenght: "+Str$(nLen) 'ok :)
             BUFFER = TrimFull$(nLen+9999999)'buffer
             'Buffer = IIf$(nLen + 1,%TRUE,%TRUE) '? 'not ok: I need here a NUMERIC EXPRESSION         
             SendMessage hSci2, %SCI_GETTEXT, Len(Buffer),StrPtr(buffer)
             SendMessage hSci2, %SCI_SetMarginWidthN, 0, 20
             MsgBox 0, buffer                               
             End If
    
          Case %WM_DESTROY
             If hSci2 Then FreeLibrary hSci2      
       End Select
    End Function
    
    
    Sub StartSci()
       Local bufferli, strKeyWords As String, iResult As Long
       strKeyWords = "case if else end select then msgbox thinbasic values vertex super euro"
       bufferli =" 'Enter some new values here"+$CRLF+_          
              ""+$CRLF+_
              " sin(25) + cos(24.25) + tan(22) if nothing else color "+$CRLF+_
              " case 20.0 if 34.0 else 255.25 "+$CRLF+_
              " end 56.30 select 40.2 then 88.24 vertex 1.0 " +$CRLF+_
              " case 24.0 + ""yes!"" and end 24.45 ""gone"", " +$CRLF+_
              "super oil petrol for 1.59 euro" + $NUL+$CRLF 
       
       SendMessage hSci, %SCI_STYLESETFORE, %SCE_B_KEYWORD, Rgb(0, 0, 255)  
       SendMessage hSci, %SCI_STYLESETFORE, %SCE_B_STRING, Rgb(255, 0, 255) 
       SendMessage hSci, %SCI_STYLESETFORE, %SCE_B_NUMBER,Rgb(192,100,0)
       SendMessage hSci, %SCI_SETLEXER,     %SCLEX_PowerBASIC, 0 '%SCLEX_ThinBASIC     
       SendMessage hSci, %SCI_SETKEYWORDS, 0, StrPtr(strKeyWords)     
       SendMessage hSci, %SCI_SetText, 0, StrPtr(bufferli)                 
       SendMessage hSci, %SCI_SetMarginWidthN, 0, 20                  
    End Sub
    
    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by ErosOlmi; 23-05-2011 at 20:07. Reason: substituted quote with code in order to have code syntax highlighted

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Hi largo,

    I changed your post in order to use CODE tags so source code is formatted and syntax highlight is used.

    In order to get back a buffer of text, you first need to allocate a string buffer big enough for Scintilla. So, use something like the following to create a buffer:
    Buffer = Repeat$(nLen+1, $SPC)
    
    or something like
    '---Repeat an equate (const $SPC that is const for space) for nLen + 1 times
    Buffer = $SPC(nLen+1)
    
    or even something like
    '---Repeat an equate (const $NUL that is like CHR$(0)) for nLen + 1 times
    Buffer = $NUL(nLen+1)
    
    so, any thinBasic way that allocate a string big enough to get your text back.

    TrimFull$ cannot be used here because it does a completely different job: it remove spaces from a string and does not allocate a string buffer.

    Let me know
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    curious question

    thank you eros. I was looking for "$Space" term but didn't found in thinbasic command list, very good! these three command works! I prefer

    Buffer = $SPC(nLen+1)
    


    another curious question just for personal interest:

    Can you please tell me if you are compiling (interpreting) a "file" or a "string" buffer (for example: by my simple scintilla text editor) to the specific (*module*)thinbasic.dll ? what's the right order to send data from thinair (editor) to the different module dll's? would be great to hear what's best working for it?

    bye, largo

  5. #5
    Hi largo...
    I'm interested of course...
    Also i have some experience with scintilla but i prefer to use scilexer as dll.
    And i use version 1.6.8.0 for my MagicSmall for thinBasic(need update...)....
    good work...

  6. #6
    And i use version 1.6.8.0 for my MagicSmall for thinBasic(need update...)....
    good work...
    hello aurel. thanks. Have you any link to magicSmall. source code included? Can you tell me what's the kind of compiling do you prefer (string, file) ? I wanted to understand how to compile a textfile like my little scintilla example above to an *.dll file.

    1) I am using with my last example "scilexer.dll". but I didn't know all content of functions there.
    2) found your "magicSmall" editor here at forum: good work too!

    bye, largo
    Last edited by largo_winch; 25-05-2011 at 09:56. Reason: forgotten something

  7. #7
    First my sci-based editor is not written in thinBasic then in EB.
    Ok i will try translate some parts to thinBasic code and you will see
    better how i do some things...

    Aurel

  8. #8
    It seems that some things not work very well with scintilla 1680.
    So for now i got this:
    'scintill thinBasic test1
    Uses "ui"
    'SCI CONSTANTS------------------------------------------------------------
    %SCE_IB_DEFAULT = 1
    %SCE_IB_LINECOMMENT = 2
    %SCE_IB_BLOCKCOMMENT = 3
    %SCE_IB_NUMBER = 4
    %SCE_IB_KEYWORD = 5
    %SCE_IB_TYPE = 6
    %SCE_IB_SETID = 7
    %SCE_IB_PREPROCESSOR = 8
    %SCE_IB_STRING = 9
    %SCE_IB_OPERATOR = 10
    %SCE_IB_IDENTIFIER = 11
    %SCE_IB_LABEL = 12
    %SCE_IB_ASM = 13
    '------------------------------
    %SCI_SETLEXER = 4001
    %SCI_STYLESETFORE = 2051
    %SCI_STYLESETBACK = 2052
    %SCI_STYLECLEARALL = 2050
    %SCI_SETKEYWORDS = 4005
    %SCI_STYLESETFONT = 2056
    %SCI_STYLESETSIZE = 2055
    %SCI_STYLESETBOLD = 2053
    %SCI_SETMARGINWIDTHN = 2242
    %SCI_SETMARGINTYPEN = 2240
    %SCI_SETMARGINSENSITIVEN = 2246
    %SCI_SETSELBACK = 2068
    %SCI_GOTOLINE = 2024
    %SCI_GETLINE = 2153
    %SCI_GETLINECOUNT = 2154
    %SCI_GETCURLINE= 2027
    %SCI_SCROLLCARET=2169
    %SCI_GOTOPOS=2025
    %SCI_GETTEXT = 2182
    %SCI_SETTEXT = 2181
    %SCI_GETTEXTLENGTH = 2183
    
    %SCI_CLEAR=2180
    %SCI_CLEARALL=2004
    %SCI_BRACEBADLIGHT=2352
    %SCI_BRACEHIGHLIGHT=2351
    %SCI_BRACEMATCH=2353
    %SCI_GETSELECTIONEND=2145
    %SCI_SETSELECTIONEND=2144
    %SCI_SETCARETLINEVISIBLE=2096
    %SCI_SETCARETFORE = 2069
    %SCI_SETCARETLINEBACK = 2098
    %SCI_UNDO = 2176
    %SCI_CUT = 2177
    %SCI_COPY = 2178
    %SCI_PASTE = 2179
    
    %ID_SCI = 24
    %ES_SUNKEN = &h4000
    '--------------------------------------------------------------------------
    dim sciblue as string
    'setkeywords
    '-------------------------------------------------------------------------- 
    Global hDlg As DWord
    GLOBAL hLib,hsci,i as Long
     
    Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (lpLibFileName As Asciiz) As Long
    Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long
     
    '-------------------------> Main Dialog -------------------------------------------->
    Function TBMain() As Long
       
     'open main window
    DIALOG NEW Pixels, 0, "Scintilla GetText+SetText Example",20,20,600,440, %WS_OVERLAPPEDWINDOW To hDlg
    
    'Control Add Button, hDlg, %ID_Button, "result1", 10,10,60,20
    'Control Add Button, hDlg, %ID_Button2, "result2", 300,10,60,20
    
    hLib = LoadLibrary("SciLexer.dll")    
    Control Add "Scintilla", hDlg, %ID_SCI, "",4,50,580,300, %WS_CHILD or %ES_SUNKEN or %WS_VISIBLE or %WS_EX_CLIENTEDGE or %WS_BORDER
    Control Handle hDlg, %ID_SCI To hSci
    
    'main setings
    SENDMESSAGE hsci,%SCI_SETLEXER,40,1
    SENDMESSAGE hsci,%SCI_STYLESETFORE,%SCE_IB_DEFAULT,100
    'SENDMESSAGE hsci,%SCI_STYLESETBACK,32,rgb(255,255,255)
    SENDMESSAGE hsci,%SCI_STYLECLEARALL, 0, 1
    'DIM hFont AS DWORD resource = Font_Create("Courier New", 10)
    'SendMessage hsci, %WM_SETFONT, hFont, 0
    dim fname as string
    fname="Courier New"
    
    For i = 1 to 13
        SENDMESSAGE hsci,%SCI_STYLESETFONT, i,strptr(fname)
        SENDMESSAGE hsci,%SCI_STYLESETSIZE, i,10
    Next 
    
    'set few keywords-not work
    'SENDMESSAGE hsci,%SCI_SETKEYWORDS, 0,"for next wend while dialog new function select case "
    
    'set marginsize   
    SendMessage hSci,%SCI_SETMARGINWIDTHN, 0, 40    
        
    Dialog Show Modal hDlg Call DlgProc
     
    End Function
     
    '---------------------------------> CALLBACK FUNCTIONS --------------------------->
    CALLBACK FUNCTION DlgProc() As Long
    
       
    SELECT Case CBMSG
    
       '*******************  
         
          Case %WM_COMMAND
            
     
          Case %WM_DESTROY
             If hSci<>0 Then FreeLibrary hSci 
        
       END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------ 
     
    SUB setkeywords()
    sciblue="for next wend while dialog new function select case "
    
    
    
    End sub
    

  9. #9
    You also need to replace IBlexer with PowerBasic lexer becose syntax is
    very similiar with thinBasic ,like this:
    Select the PB lexer, load the PB keyword list and set the different synax colors:
        SendScintillaMsg pSciWndData,%SCI_SETLEXER,%SCLEX_POWERBASIC,0                            'Set PowerBasic lexer
        SendScintillaMsg pSciWndData,%SCI_SETKEYWORDS,0,ByVal StrPtr(sPbKeyWords)         'Load the PB keyword list
        sPbKeyWords=""  'Not longer needed
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_DEFAULT,RGB(0  ,0,0)          'black
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_COMMENT,RGB(1  28,128,128)    'dark gray
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_NUMBER,RGB(12  8,0,0)         'dark red
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_KEYWORD,RGB(0  ,0,255)        'blue
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_STRING,RGB(0,  128,0)         'dark green
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_OPERATOR,RGB(  0,0,0)         'black
        SendScintillaMsg pSciWndData,%SCI_STYLESETFORE,%SCE_B_IDENTIFIER,RG  B(0,0,0)       'black
        'Usable other colors: violett=RGB(128,0,128), brown=RGB(128,64,0), red=RGB(255,0,0)
    

  10. #10

    How I can get all "thinbasic keywords"?

    thank you zlatko for example! I will check your example. I found powerbasic keywords data in scilexer too and try to adapt it for my next examples.

    important: does anybody know how I can get all "THINBASIC keywords"?

    regards, largo

Page 1 of 3 123 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •