Petr Schreiber
18-08-2016, 18:15
Hi,
thinBasic unicode support is an area which could be expanded a lot.
But to give you a start, have a look at the following functions to see, if their help you achieve what you need:
IsUnicode
Ascii2Unicode
Unicode2Ascii
WideCharToUTF8$
UTF8ToWideChar$
UTF8ToAnsi$
AnsiToUTF8$
I remember talking with Eros regarding UTF8. I think thinAir does not support it in current build, but thinBasic interpreter can use UTF8 files to execute.
Regarding code page in console, I think the following function is very helpful:
Console_SetCP
You can check the information about these in Help file, which you can launch by pressing F1 key in thinAir.
Petr
Petr Schreiber
21-08-2016, 10:53
It is often the case to store the string literals in some kind of string table, separate from the main program.
In the program, you then reference the literals by names.
Cookbook
- create a data file with strings, for example in format:
programName,"Čučoriedka"
okButton,"Tak třeba jó"
cancelButton,"Tak spíš teda né"
- create a wrapper user defined type to handle the loading and referencing
- use wrapper user defined type in your program
Petr
Saluton, ĉiuj // Hello, everyone,
Just in case somebody — kcvinu, for instance — is still interested in how Unicode can be used with ThinBASIC: there is a small example below.
A very short summary:
in order to display Unicode correctly in buttons and messageboxes we can use
(a) the functions Petr kindly indicated above, i. e. UTF8ToWideChar$ and others; actually, for my programme UTF8ToWideChar$ was sufficient (the encoding was UTF-8 throughout);
(b) WinAPI functions, Unicode versions (their declarations are in the text of the programme): SendMessageW, SetWindowTextW, MessageBoxW.
Strings are declared as AsciiZ, specified in the programme directly (UTF-8) and converted to WideChar, then pointed to by ThinBASIC's STRPTR().
'
' =======================================
' FASADO. Provo uzi kodoprezenton UTF-8
' =======================================
'
uses "UI"
declare function SendMessageW lib "user32.dll" _
alias "SendMessageW" _
(ByVal t as DWord, ByVal m as DWord, _
ByVal wp as DWord, ByVal adrL as Long) _
as Long
declare function SetWindowTextW lib "user32.dll" _
alias "SetWindowTextW" _
(ByVal t as DWord, ByVal adrL as Long) _
as Long
declare function MessageBoxW lib "user32.dll" _
alias "MessageBoxW" _
(ByVal t as DWord, ByVal adrLt as Long, _
ByVal adrLcx as Long, ByVal n as DWord) _
as Long
Begin ControlID
%butEn
%butEo
%butRu
%butFa
%butKr
%butYi
%butAr
%butHi
%butJa
%knvP
End ControlID
%UTF8 = 65001
%DlgL = 600
%DlgAt = 300
%DlgA = 400
%CxL = %DlgL \ 3
%CxA = %DlgAt \ 3
%d = 10
%bL = %CxL - %d - %d
%bA = %CxA - %d - %d
%LtrA = 12
$Ttl = "Unicode-text buttons; each changes the colour of the canvas below."
$nButEn = "Well... Close!"
$LtrN = "Arial Unicode MS"
dim DlgH, DlgV, r as Long
dim tDlg, _
tButEo, tButRu, tButFa, tButKr, tButYi, tButAr, tButHi, tButJa, tKnv _
as DWord
dim nButEo, nButRu, nButFa, nButKr, nButYi, nButAr, nButHi, nButJa, _
mFaCx, mFaT _
as AsciiZ
' ================
' CXEFA PROGRAMO
' ================
FUNCTION TbMain()
nButEo = "Ŝanĝiĝu... Ĝis!"
nButRu = "Что ж, закроем!"
nButFa = "!ﺪﯿﻨﻜﺑ ﻪﺘﺴﺑ"
nButKr = "창문을 닫기!"
nButYi = "!ןכאַמוצ רעטצנעפֿ"
nButAr = "Պատուհան փակել"
nButHi = "खिड़की बंद करे ।"
nButJa = "まど を 閉じる。"
mFaCx = UTF8ToWideChar$("Ĉapo de mesaĝ-panelo:")
mFaT = UTF8ToWideChar$(nButRu & $CRLF & nButFa)
desktop get client to DlgH, DlgV
DlgH = (DlgH - %DlgL) \ 2: DlgV = (DlgV - %DlgA) \ 2
dialog font $LtrN, %LtrA
tDlg = Dialog_New (Pixels, 0, $Ttl, _
DlgH, DlgV, %DlgL, %DlgA, _
%WS_DLGFRAME | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW , 0)
dialog set client tDlg, %DlgL, %DlgA
control add button, tDlg, %butEn, $nButEn, %d, %d, %bL, %bA
control add button, tDlg, %butEo, $SPC, %d+%CxL, %d, %bL, %bA
control handle tDlg, %butEo to tButEo
nButEo = UTF8ToWideChar$(nButEo)
SendMessageW (tButEo, 12, 0, strptr(nButEo))
control add button, tDlg, %butRu, $SPC, %d+%CxL+%CxL, %d, %bL, %bA
control handle tDlg, %butRu to tButRu
nButRu = UTF8ToWideChar$(nButRu)
SendMessageW (tButRu, 12, 0, strptr(nButRu))
control add button, tDlg, %butFa, $SPC, %d, %d+%CxA, %bL, %bA
control handle tDlg, %butFa to tButFa
nButFa = UTF8ToWideChar$(nButFa)
' SendMessageW (tButFa, 12, 0, strptr(nButFa))
SetWindowTextW (tButFa, strptr(nButFa))
control add button, tDlg, %butKr, $SPC, %d+%CxL, %d+%CxA, %bL, %bA
control handle tDlg, %butKr to tButKr
nButKr = UTF8ToWideChar$(nButKr)
SendMessageW (tButKr, 12, 0, strptr(nButKr))
control add button, tDlg, %butYi, $SPC, %d+%CxL+%CxL, %d+%CxA, %bL, %bA
control handle tDlg, %butYi to tButYi
nButYi = UTF8ToWideChar$(nButYi)
SendMessageW (tButYi, 12, 0, strptr(nButYi))
control add button, tDlg, %butAr, $SPC, %d, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butAr to tButAr
nButAr = UTF8ToWideChar$(nButAr)
SendMessageW (tButAr, 12, 0, strptr(nButAr))
control add button, tDlg, %butHi, $SPC, %d+%CxL, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butHi to tButHi
nButHi = UTF8ToWideChar$(nButHi)
SendMessageW (tButHi, 12, 0, strptr(nButHi))
control add button, tDlg, %butJa, $SPC, %d+%CxL+%CxL, %d+%CxA+%CxA, %bL, %bA
control handle tDlg, %butJa to tButJa
nButJa = UTF8ToWideChar$(nButJa)
SendMessageW (tButJa, 12, 0, strptr(nButJa))
tKnv = control add canvas, tDlg, %knvP, "", _
%d, %d+%CxA+%CxA+%CxA, %DlgL - %d - %d, %bA, , %WS_EX_STATICEDGE
Canvas_Attach (tDlg, %knvP, %FALSE)
Canvas_Clear (%RGB_BLACK)
dialog show modal tDlg, call trFENESTRO
END FUNCTION
' =========================
' PROCEDUROJ KAJ FUNKCIOJ
' =========================
Callback Function trFENESTRO() as Long
SELECT CASE cbMsg
CASE %WM_COMMAND
select case cbCtl
case %butEn
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_BLUE)
case %butEo
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_RED)
case %butRu
if cbCtlMsg = %BN_CLICKED then
Canvas_Clear (%RGB_GREEN)
MsgBox (tDlg, "=m=", %MB_OK, "=t=")
end if
case %butFa
if cbCtlMsg = %BN_CLICKED then
Canvas_Clear (%RGB_CYAN)
MessageBoxW (tDlg, strptr(mFaT), strptr(mFaCx), %MB_OK)
end if
case %butKr
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_MAGENTA)
case %butYi
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_YELLOW)
case %butAr
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_BROWN)
case %butHi
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_GRAY)
case %butJa
if cbCtlMsg = %BN_CLICKED then Canvas_Clear (%RGB_POWDERBLUE)
end select
END SELECT
End Function
Ĝis // Regards,
Uzulo
Hi ErosOlmi,
Yeah, i saw it. It can insert code blocks. But you can easily add the automatic feature in scintilla. When a user presses enter key, check for the current line and get the starting keyword. Add a new line and a tab space and again a new line. Insert the appropriate end keyword there. And move the cursor to upward so that user can start typing. When checking for current line, please check if there is "()" for a function and "Then" for an "If".
You can add a feature to arrange the code when each enter key press. For example, fixing the unnecessary spaces, adding proper spaces, fixing capital letters. These features make thinAir a state of the art IDE.
ReneMiner
28-08-2016, 22:13
kcvinu, guess you want a functionality of some auto-complete-feature as my thinICE-project (http://www.thinbasic.com/community/showthread.php?12611-preview-thinICE) has.
If you type "End " it will automatically suggest
Const, ControlID, Function, If, Select, Sub, Type, Union, With...
depending on what is actually to end.
Also I vote for some more project-oriented makeover of the thinAir-codebrowser...
It still prefixes functions below "End Type" with the type-name of the type above and a dot.
ReneMiner
29-08-2016, 14:57
just run thinICE.tBasic.
Either from Explorer, from thinAir - or even from command prompt if you like to tuck it in.
The executeable in there is just to request screen-resolution and keyboard-layout. It get's started only the first time you run thinICE.tBasic and saves the settings to current APP_Inifile which is thinICE.ini in that case.
It's an "IDE" for thinBasic written in thinBasic but i called it "ICE" since its not an
"Integrated Developing Environment" but some "Inconvenient Coding Environment"
- it has no visual designer for UI-module but a lot of detailed code- and variable-overview, autocomplete and other features.
- it's unlike thinAir - which allows to load any tBasic, tBasicU, tBasicI, tBasicC-scriptunit - more project-oriented so you can load a tBasic-file and it will load all included files by itself so it knows all the variables, udts etc.
- currently thinICE is a source of ideas how i would improve thinAir - nevertheless it's meant to type scripts as fast and as free of bugs as possible :)