REM OPL code for multi-line text input on Series 60 with mulit-tap of numerical keys REM REM Created by Martin Dehler 12/2004 - martin.dehler@gmx.de - www.martin-dehler.de REM Version 0.10 - www.martin-dehler.de/opl/multitap.htm REM REM Feel free to use and modify the code as you need. REM Please don't expect the code to be bug free, but as a basis to work on ;-) REM REM The code demonstrates a very basic way of entering an up to 255 charcters long string REM in up to ten lines. Characters are entered by single or multiple taps on the numerical REM keypad. The #-key switches between lower- and uppercase charcters. The C-key deletes REM the last character. REM REM Main backdraws are the lack of cursor navigation, the lack of more sophisticated REM upper- and lowercase handling (e.g. automatic switch to uppercase after a period) and REM that the speed decreases with longer strings. REM REM Known Bugs REM - when the end of the last line is reached before maximum characters the last charcters REM are not handled correct REM modify to point to point to S60 constants file INCLUDE "const_series60.oph" CONST KKeySoftLeft32&=63554 CONST KKeySoftRight32&=63555 CONST KKeyClear32&=8 REM constants for text input CONST KMaxLines%=10 REM minmum 2, maximum 10 CONST KMaxChar%=255 REM up to 255 CONST KMargin%=5 REM in pixels, used for left and right margin CONST KCapitalLow%=1 REM don't modify CONST KCapitalAll%=2 REM don't modify PROC TextInput: GLOBAL Event&(16),MenuKey%,Key&,PrevKey&,KeyCount% GLOBAL TimeStamp&,TimeStamp$(255),TimeAct&,TimePrev&,TimeDiff& GLOBAL Char$(20,30),Text$(255),TextWidth%,Capital%,Line%,Line$(KMaxLines%,60) REM lowercase characters Char$(1)=".,?!1@'-_():;&/%*#+<=>"+CHR$(34)+"$"+CHR$(163)+"§"+CHR$(165) Char$(2)="abc2ä" Char$(3)="def3" Char$(4)="ghi4" Char$(5)="jkl5"+CHR$(163) Char$(6)="mno6ö" Char$(7)="pqrs7ß$" Char$(8)="tuv8ü" Char$(9)="wxyz9" Char$(10)=" 0" REM capitalized characters Char$(11)=".,?!1@'-_():;&/%*#+<=>"+CHR$(34)+"$"+CHR$(163)+"§"+CHR$(165) Char$(12)="ABC2Ä" Char$(13)="DEF3" Char$(14)="GHI4" Char$(15)="JKL5"+CHR$(163) Char$(16)="MNO6Ö" Char$(17)="PQRS7$" Char$(18)="TUV8Ü" Char$(19)="WXYZ9" Char$(20)=" 0" REM initialisation Capital%=KCapitalLow% TextWidth%=gWIDTH-(2*KMargin%) DrawMainBackground: Line%=1 DrawMainVariabel: REM main loop DO GETEVENT32 Event&() IF (Event&(1) AND &400)=0 REM key event Key&=Event&(1) REM processing key presses IF Key&=KKeySoftLeft32& REM menu mINIT mCARD "","Exit",%e MenuKey%=MENU ELSEIF Key&=KKeySoftRight32& Shutdown: ELSEIF Key&=48 OR Key&=49 OR Key&=50 OR Key&=51 OR Key&=52 OR Key&=53 OR Key&=54 OR Key&=55 OR Key&=56 OR Key&=57 REM text input REM determine actual time TimeStamp&=Event&(2) TimeStamp$=GEN$(TimeStamp&,255) REM delete leading '-' IF LEFT$(TimeStamp$,1)="-" TimeStamp$=MID$(TimeStamp$,2,LEN(TimeStamp$)-1) ENDIF REM truncate time stamp TimeStamp$=MID$(TimeStamp$,1,LEN(TimeStamp$)-4) TimeAct&=VAL(TimeStamp$) REM calculate time since previous key press TimeDiff&=IABS(TimeAct&-TimePrev&) REM if time to long, reset to first character in charcter string IF TimeDiff&>100 OR PrevKey&<>Key& KeyCount%=0 ENDIF TimePrev&=TimeAct& IF LEN(Text$)0 REM C key, Backspace Text$=LEFT$(Text$,LEN(Text$)-1) DrawMainVariabel: ELSEIF Key&=35 REM #-key switches between lower and uppercase characters IF Capital%=KCapitalLow% Capital%=KCapitalAll% ELSEIF Capital%=KCapitalAll% Capital%=KCapitalLow% ENDIF DrawMainVariabel: ENDIF REM processing menu IF MenuKey%=%e REM exit Shutdown: ENDIF ELSEIF Event&(1)=&404 REM exit event IF LEFT$(GETCMD$,1)="X" OR LEFT$(GETCMD$,1)="B" Shutdown: ENDIF ENDIF UNTIL 0 ENDP PROC String:(SelectedChar%,ActKey%) REM builds the string LOCAL Char% KeyCount%=KeyCount%+1 REM check if capitalized characters are currently selected IF Capital%=KCapitalAll% Char%=SelectedChar%+10 ELSE Char%=SelectedChar% ENDIF REM delete last charcater when it is a 'fast' repeated keypress IF TimeDiff&<=100 AND PrevKey&=ActKey% Text$=LEFT$(Text$,LEN(Text$)-1) ENDIF REM append selected character Text$=Text$+MID$(Char$(Char%),KeyCount%,1) REM reset to begin of charcater string when last charcater is reached in string IF KeyCount%=LEN(Char$(Char%)) KeyCount%=0 ENDIF ENDP PROC DrawMainBackground: REM draw softkey labels gUSE 1 gFONT KFontS60LatinBold17& gAT 2,204 :gPRINT "Menu" gAT 176-gTWIDTH("Exit"),204 :gPRINT "Exit" ENDP PROC DrawMainVariabel: REM splits the string in several lines REM draws the string and other variabel screen content LOCAL X%,Temp$(255),Space%,TempLine$(KMaxLines%,255),CharCount$(3),MaxChar$(3) gUSE 1 gFONT KFontS60LatinBold12& CURSOR OFF REM draw character size indicator gAT KMargin%,15 IF Capital%=KCapitalLow% gPRINTB "abc",30 ELSEIF Capital%=KCapitalAll% gPRINTB "ABC",30 ENDIF REM draw character count CharCount$=GEN$(LEN(Text$),3) MaxChar$=GEN$(KMaxChar%,3) gAT gWIDTH-(gTWIDTH("000("+MaxChar$+")")+KMargin%),15 REM the triple 0 is a 'placeholder' for max 3 digit numbers gPRINTB CharCount$+"("+MaxChar$+")",gTWIDTH("000("+MaxChar$+")"),1 REM clear lines Line%=1 DO Line$(Line%)="" Line%=Line%+1 UNTIL Line%>KMaxLines% REM split text in lines IF gTWIDTH(Text$)<=TextWidth% REM one line is enough Line$(1)=Text$ ELSE REM more than one line needed Line%=1 TempLine$(1)=Text$ DO X%=1 :Temp$="" DO X%=X%+1 REM start with second charcter that a leading space is handeld IF MID$(TempLine$(Line%),X%,1)=" " IF gTWIDTH(LEFT$(TempLine$(Line%),X%-1))<=TextWidth% Temp$=LEFT$(TempLine$(Line%),X%-1) Space%=X% REM store position of space ENDIF ENDIF UNTIL X%>LEN(TempLine$(Line%)) Line$(Line%)=Temp$ REM next line TempLine$(Line%+1)=RIGHT$(TempLine$(Line%),LEN(TempLine$(Line%))-Space%) IF gTWIDTH(TempLine$(Line%+1))<=TextWidth% REM rest of string is small enough to fit in 'second' line Line$(Line%+1)=TempLine$(Line%+1) BREAK ENDIF IF Line%+1=KMaxLines% AND gTWIDTH(TempLine$(Line%+1))>=TextWidth% REM string doesn't fit in last line Text$=LEFT$(Text$,LEN(Text$)-1) REM cut off last character that doesn't fit in last line Line$(Line%+1)=LEFT$(TempLine$(Line%+1),LEN(TempLine$(Line%+1))) BREAK ENDIF Line%=Line%+1 UNTIL Line%>KMaxLines% ENDIF REM draw text lines Line%=1 DO gAT KMargin%,20+(Line%*15) gPRINTB Line$(Line%),TextWidth% Line%=Line%+1 UNTIL Line%>KMaxLines% REM draw cursor Line%=1 DO IF Line$(Line%)="" Line%=Line%+1 ELSE gAT KMargin%+gTWIDTH(Line$(Line%)),20+((Line%)*15) CURSOR 1,10,1,13 Line%=Line%+1 ENDIF UNTIL Line%>KMaxLines% ENDP PROC Shutdown: STOP ENDP