View previous topic :: View next topic |
Author |
Message |
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Jan 09, 2002 11:18 am Post subject: Autocomplete Edit Box - NO DLL |
|
|
Here's another "NO DLL" version of an "autocomplete"
edit box. I added a simulated flashing cursor, and
some code to make sure it "autocompletes" the right
words (instead of grabbing any letter combination
that matches from the list). It checks words from
the list both typing and backspacing.
You can't highlight and copy (unless you copy from
E2 with a menu, menu hot keys, etc.). You might also
fake highlighting by removing E2 and adding it again
with a STYLE to simulate the highlighting if you were
determined to use a menu option such as "select text".
Have fun with it... :)
_________________________________________________________________________________________________________________________________________________________
Code: |
rem -- Auto complete edit box with simulated flashing cursor --
rem -- IMPORTANT: Use a substring of @dlgtext(E2) to avoid the
rem -- cursor: @substr(@dlgtext(E2),1,@pred(@len(@dlgtext(E2))))
rem -- Don't use @dlgtext(E1), you won't get autocompleted text.
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test prog,-1,0,300,50
DIALOG ADD,BUTTON,Enter,0,0,0,0,,,DEFAULT
DIALOG ADD,EDIT,E1,0,0,0,0
DIALOG ADD,EDIT,E2,5,5,290,20
DIALOG ADD,TEXT,T1,30,5,,,"Words in List 1: apple aardvark banana bark cat cards"
DIALOG SHOW
LIST CREATE, 1
LIST LOADTEXT,1,
"apple
"aardvark
"banana
"bark
"cat
"cards
:EVLOOP
%x = 0
REPEAT
rem -- Focus on the hidden edit box E1 --
DIALOG FOCUS, E1
rem -- Check if E1 shows we typed something --
if @not(@equal(@dlgtext(E1), @substr(@dlgtext(E2), 1, @len(@dlgtext(E2)))))
rem -- If text matches a list item --
LIST SEEK, 1, 0
if @match(1, @dlgtext(E1))
rem -- Make sure it matches from the beginning --
if @equal(@dlgtext(E1), @substr(@item(1), 1, @len(@dlgtext(E1))))
rem -- Complete the word --
DIALOG SET, E2, @item(1)%%cursor
else
rem -- Otherwise, show what we typed --
DIALOG SET, E2, @dlgtext(E1)%%cursor
end
else
rem -- Otherwise, show what we typed --
DIALOG SET, E2, @dlgtext(E1)%%cursor
end
end
rem -- Flash cursor. WAIT ".01" still allows
rem -- user to type 100 chars per second...
WAIT ".01"
if @greater(10, %x)
%%cursor = "|"
else
%%cursor = " "
if @greater(%x, 20)
%x = 0
end
end
rem -- If no text, flash cursor --
if @not(@dlgtext(E2))
DIALOG SET, E2, %%cursor
end
%x = @succ(%x)
%e = @event()
UNTIL %e
goto %e
:EnterBUTTON
rem -- Make sure we typed something...
rem -- Don't use "if @dlgtext(E2)" here,
rem -- 'cause the cursor is always there.
if @dlgtext(E1)
INFO @substr(@dlgtext(E2),1,@pred(@len(@dlgtext(E2))))
end
goto EVLOOP
:CLOSE
EXIT
|
EDIT - Added code to flash cursor when edit box is empty.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Skit3000 Admin Team
Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Mon Jul 29, 2002 7:55 pm Post subject: |
|
|
Here is another version which auto-completes not only the first, but also the rest of the words... (Eeeh... the first word doesnt work, the rest does...)
Known bugs:
- First word isn't auto-completeble
- Enters don't work (So I turned this of with the help of :Entermenu)
- If you change the window when you pressed TAB there is a change
that the window will be hidden, and then a second later just appears...
Code: |
list create,1
rem first line must be empty
rem first character must be a | so the script will search only the begin of a
rem character
list loadtext,1
"|
"|hey
"|today
"|hello
"|vdsworld.com
"|fine
"|sade
"|http://
"|http://www.
"|http://www.vdsworld.com/
"|http://www.vdsworld.com/forum/
"|auto
"|complete
"|rem You can also use stuff with more then 1 word, but they dont work
"|rem if there is another word that starts with the same...
"|how are you
"|dialogscript
"|visual dialog script
DIALOG CREATE,Auto-complete...,-1,0,369,160
DIALOG ADD,EDIT,EDIT1,0,0,368,128,,MULTI,WRAP,SCROLL
DIALOG ADD,EDIT,EDIT2,136,128,240,16,,READONLY
DIALOG ADD,MENU,-,Complete|Tab,Enter|Enter
DIALOG ADD,TEXT,TEXT1,136,0,,,Press TAB to complete to:
DIALOG SHOW
%%edit1text = @dlgtext(edit1)
:evloop
%%event = @event()
if @not(@null(%%event))
goto %%event
end
%%edit1text = @dlgtext(edit1)
if @not(@equal(%%edit1text,%%edit1textold))
%%edit1textold = %%edit1text
%%text = %%edit1textold
%z = @item(1,0)
if @equal(@pos(@chr(32),%%text),)
%%text = %%edit1text
else
repeat
%%text = @strdel(%%text,1,@diff(@pos(@chr(32),%%text),1))
%%space = @pos(@chr(32),%%text)
until @equal(%%space,0)
rem ---------------------------------------------------------
if @equal(@pos(@chr(10),%%text),)
repeat
%%text = @strdel(%%text,1,@diff(@pos(@chr(10),%%text),1))
%%return = @pos(@chr(10),%%text)
until @equal(%%return,0)
end
rem ---------------------------------------------------------
end
if @match(1,|%%text)
if @greater(@len(%%text),0)
dialog set,edit2,@substr(@item(1),2,999)
else
dialog set,edit2,
end
end
end
goto evloop
:Completemenu
%%textlenght = @len(%%text)
if @match(1,|%%text)
if @greater(@len(%%text),0)
dialog set,edit1,@substr(@dlgtext(edit1),1,@diff(@len(@dlgtext(edit1)),%%textlenght))@substr(@item(1),2,999)
dialog focus,edit1
window send,@winexists(Auto-complete...),@key(end)
end
end
end
goto evloop
:Entermenu
warn No enters allowed...
goto evloop
:Close
exit
| [/list][/list] |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|