Fresh IDE . Artifact [9047bee253]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Artifact 9047bee253771ca3262acb087c4af84b477f8c1a:


; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "Fresh artistic license."         |
;|_______________________________________________________________________________________|
;                                                                                        |
;   Description: Test program for TFreshEdit control.                                    |
;                                                                                        |
;   Target OS: All/Linux/Win32 - depending on current test needs.                        |
;                                                                                        |
;   Dependencies:                                                                        |
;                                                                                        |
;   Notes: The main test program calls "PrepareDemo" procedure.                          |
;________________________________________________________________________________________|


__TestGround:

; Global data...
iglobal

__TestData:

frmMainForm:
        ObjTemplate  tfParent or tfEnd, Form, frmMain, \
                     x, 100,        \
                     y, 50,         \
                     width, 640,    \
                     height, 480,   \
                     borderKind, borderFull,    \
                     Visible, TRUE, \
                     Caption, 'FreshEdit test application.'

        ObjTemplate  tfParent, Form, Toolbar,           \
                     x, 0, y, 0,                        \
                     width, 100, height, 20,            \
                     Align, waBottom,                   \
                     borderKind, borderNone,         \
                     Visible, TRUE

        ObjTemplate  tfChild, Button, btnOpen,  \
                     x, 112, y, 2,                        \
                     width, 64, height, 21,            \
                     Align, waLeft,                     \
                     Caption, 'Open',                   \
                     TextAlign, dtfAlignCenter or dtfAlignMiddle,       \
                     OnClick, OnOpenFile,         \
                     Visible, TRUE

        ObjTemplate  tfChild, Button, btnSave,  \
                     x, 180, y, 2,                     \
                     width, 64, height, 21,            \
                     Align, waLeft,                     \
                     Caption, 'Save',                   \
                     TextAlign, dtfAlignCenter or dtfAlignMiddle,       \
                     OnClick, OnSaveFile,         \
                     Visible, TRUE

        ObjTemplate  tfChild, Button, btnNumbers,  \
                     x, 180, y, 2,                     \
                     width, 21, height, 21,            \
                     Align, waLeft,                     \
                     Caption, '#',                  \
                     TextAlign, dtfAlignCenter or dtfAlignMiddle,       \
                     OnClick, OnNumbers,         \
                     Visible, TRUE

        ObjTemplate  tfChild, Button, btnZebra,  \
                     x, 180, y, 2,                     \
                     width, 21, height, 21,            \
                     Align, waLeft,                     \
                     Caption, 'Z',                  \
                     TextAlign, dtfAlignCenter or dtfAlignMiddle,       \
                     OnClick, OnZebra,         \
                     Visible, TRUE

        ObjTemplate  tfChild, Button, btnTheme,  \
                     x, 180, y, 2,                     \
                     width, 21, height, 21,            \
                     Align, waLeft,                     \
                     Caption, 'T',                  \
                     TextAlign, dtfAlignCenter or dtfAlignMiddle,       \
                     OnClick, OnTheme,         \
                     Visible, TRUE

        ObjTemplate  tfEnd, Edit, FilenameEdit,         \
                     x, 2, y, 2,                        \
                     width, 100, height, 21,            \
                     Align, waClient,                     \
\;                     Text, 'test_utf8.asm',             \
                     Visible, TRUE

        ObjTemplate tfEnd, FreshEdit, Editor,   \
                    x, 8, y, 8,                 \
                    width, 624, height, 464,    \
                    _Theme.WrapPos, 60,         \
                    Align, waClient,            \
                    Visible, TRUE


  SampleText file 'unicode_test.txt'
             dd   0

__TestDataSize = $ - __TestData
endg


cTestTextFile text 'test_utf8.asm'


uglobal
  Timer1 dd ?
endg

iglobal
  ThemeSet dd TFETheme.SetDefaultThemeWindows
endg

proc OnTheme, .self, .mousebtn
begin
        mov     eax, [Editor]
        lea     eax, [eax+TFreshEdit._Theme]
        stdcall [ThemeSet], eax
        xor     [ThemeSet], TFETheme.SetDefaultThemeWindows xor TFETheme.SetDefaultThemeClassic
        xor     [SynTheme], fasm_colors_classic xor fasm_colors_windows
        execute [Editor], TFreshEdit.Refresh
        return
endp


proc OnZebra, .self, .mousebtn
begin
        mov     eax, [Editor]
        xor     [eax+TFreshEdit._Theme.Options], eoStripedBackground
        execute eax, TFreshEdit.Refresh
        return
endp


proc OnNumbers, .self, .mousebtn
begin
        mov     eax, [Editor]
        xor     [eax+TFreshEdit._Theme.Options], eoLineNumbers
        execute eax, TFreshEdit.Refresh
        return
endp



proc OnSaveFile, .self, .mousebtn
begin

        return
endp


proc OnOpenFile, .self, .mousebtn
begin
; Load test file
        stdcall Get, [FilenameEdit], TEdit.Text
        push    eax

        stdcall StrPtr, eax
        stdcall LoadBinaryFile, eax
        jc      .exit

        push    eax
        stdcall Set, [Editor], TFreshEdit.Text, eax
        stdcall FreeMem ; from the stack

.exit:
        mov     eax, [Editor]
        mov     [eax+TFreshEdit._xCaret], 0
        mov     [eax+TFreshEdit._yCaret], 0
        mov     [eax+TFreshEdit._xSelection], 0
        mov     [eax+TFreshEdit._ySelection], 0
;        mov     [eax+TFreshEdit._fReadOnly], froReadOnlyNoCaret
        stdcall StrDel ; from the stack

        stdcall ParseFolding, [eax+TFreshEdit._pLines]


;        mov     esi, [Editor]
; test - set some flags on line 33
;        mov     eax, [esi+TFreshEdit._pLines]
;        or      [eax+TArray.array+sizeof.TEditorLine*26+TEditorLine.flags], lfBreakpoint

; test - set some flags on line 34
;        mov     eax, [esi+TFreshEdit._pLines]
;        or      [eax+TArray.array+sizeof.TEditorLine*27+TEditorLine.flags], lfBreakpoint
;        mov     [eax+TArray.array+sizeof.TEditorLine*27+TEditorLine.debugdata], $12345

        execute [Editor], TFreshEdit.Refresh
        execute [Editor], TFreshEdit.Focus
        return
endp



proc PrepareDemo
begin
        stdcall CreateFromTemplate, frmMainForm, 0
        mov     ecx, [Application]
        mov     [ecx+TApplication.MainWindow], frmMain

        stdcall Set, [Editor], TFreshEdit._procSyntax, SyntaxFASM
        stdcall Set, [Editor], TFreshEdit.OnControlKey, procKeyPress
        stdcall Set, [Editor], TFreshEdit.Text, SampleText

        mov     esi, [Editor]
; test - set some flags on line 33
        mov     eax, [esi+TFreshEdit._pLines]
        or      [eax+TArray.array+sizeof.TEditorLine*26+TEditorLine.flags], lfBreakpoint

; test - set some flags on line 34
        mov     eax, [esi+TFreshEdit._pLines]
        or      [eax+TArray.array+sizeof.TEditorLine*27+TEditorLine.flags], lfBreakpoint
        mov     [eax+TArray.array+sizeof.TEditorLine*27+TEditorLine.debugdata], $12345

        stdcall ParseFolding, eax
.exit:
        return
endp



proc procKeyPress, .self, .keyevent
begin
        mov     ebx, [.keyevent]

        mov     eax, [ebx+TKeyboardEvent.key]

        cmp     eax, 12 ; ctrl+L
        je      .length_list
        cmp     eax, 18 ; ctrl+R
        je      .clipright
        cmp     eax, 19 ; ctrl+S == save
        je      .save
        cmp     eax, 20 ; ctrl+T
        je      .test_something

        cmp     [ebx+TKeyboardEvent.scancode], keyF2
        je      .toggle_breakpoint

.finish:
        mov     eax, chgfNoClearSelection
        return


.save:
        stdcall Get, esi, TFreshEdit.Text
        push    eax
        stdcall StrPtr, eax
        stdcall SaveBinaryFile, cTestTextFile, eax, [eax+string.len]
        stdcall StrDel ; from the stack

.length_list:
        mov     eax, [esi+TFreshEdit._pLengths]
        mov     ecx, [eax+TArray.count]
        lea     ecx, [4*ecx+TArray.array]
        OutputMemory  eax, ecx

        mov     eax, 0
        return

.clipright:
        stdcall Get, esi, TFreshEdit.CurrentLine
        jc      .finish
        stdcall StrClipSpacesR, [eax+TEditorLine.Data]
        mov     eax, chgfNeedRefresh
        clc
        return

.test_something:
        mov     eax, [.self]
        xor     [eax+TFreshEdit._Theme.Options], eoLineSeparator

        mov     eax, chgfNeedRefresh
        return


.toggle_breakpoint:
        cmp     [esi+TFreshEdit._fReadOnly], froReadWrite
        jne     .finish

        stdcall Get, esi, TFreshEdit.CurrentLine
        jc      .finish

        xor     [eax+TEditorLine.flags], lfBreakpoint
        mov     eax, chgfNeedRefresh or chgfNoClearSelection
        clc
        return


;. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .



endp





proc ParseFolding, .pLines
begin
        pushad

        xor     ebx, ebx
        mov     esi, [.pLines]
        mov     ecx, [esi+TArray.count]
        lea     esi, [esi+TArray.array]

.loop:
        jecxz   .endparse

        stdcall StrPos, [esi+TEditorLine.Data], cProcSyntax
        test    eax, eax
        jz      @f
        inc     ebx
        or      [esi+TEditorLine.flags], lfFoldHeader
@@:
        mov     [esi+TEditorLine.fold_level], ebx

        stdcall StrPtr, [esi+TEditorLine.Data]
        cmp     dword [eax], 'endp'
        jne     @f
        test    ebx, ebx
        jz      @f
        dec     ebx
@@:
        add     esi, sizeof.TEditorLine
        dec     ecx
        jmp     .loop

.endparse:
        popad
        return
endp


cProcSyntax text 'proc '
cEndpSyntax text 'endp'





DispSize 'Test ground dummy code:', ($-__TestGround)+__TestDataSize

; without this, the application crashes in Linux with untraceable seg fault. Why???
; It seems it crashes during the load, before even one instruction executed.
; Maybe it is some kind of bug in the elf formater...
; IT CRASHES ONLY SOMETIMES?????
;rb 64

include 'FreshEdit/fasm_syntax.asm'