fox
Junior Member
Posts: 66
|
Post by fox on Apr 14, 2024 9:03:21 GMT -5
Excuse me, emy, for my carelessness. Thanks a lot for the code you propose. fox
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 14, 2024 9:22:54 GMT -5
Thanks a lot again, xxgeek. However my problem is to avoid storing characters exceeding the maximum allowed by the "!copy" ; command Bye fox
|
|
|
Post by Rod on Apr 14, 2024 9:39:07 GMT -5
Try this, it has quirks but it will limit input even from the clipboard. It is set at 22 characters for testing and you need to remember there are hidden control characters that will seem to spoil the character count. You will need to think how you advise users the limit has been exceeded.
nomainwin texteditor #main.te 0, 0, 200, 200 open "Text" for window as #main #main "trapclose [quit]" #main.te "012345" timer 100,[check] wait
[check] #main.te "!contents? string$" if len(string$)>22 then string$=left$(string$,20) 'lose the trailing CrLf pair #main.te "!contents string$" '#main.te "!setfocus" string$="" end if wait
[quit] timer 0 close #main end
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 14, 2024 11:13:26 GMT -5
Rod, I think your last code hits completely my target. I will study it with great interest. Thanks a lot again and bye. fox
|
|
|
Post by tsh73 on Apr 15, 2024 5:02:16 GMT -5
Interesting, not perfect but very usable. Texteditor loses cursor after event. But event should change state so it is not fired any more - or we'll not be able to put cursor back to fix our edit!
I tried add a message about "limit" * in a kind of status bar below * or as a groupbox around texteditor which does show/hide. (** actually, another option is to have group box visible but change text)
EDIT just found source of inconsistency (why limit fired one character before actual, but then allowed to type one more character) #main.te "12345" ends text with DOUBLE CrLF
Changed it to #main.te "12345";
maxLen=10
nomainwin statictext #main.StatusBar "status", 0, 275, 350, 300 texteditor #main.te 25, 25, 200, 200 GROUPBOX #main.grp, "String length limit reached ", 0, 0, 250, 250 open "Text" for window as #main #main "trapclose [quit]" #main.te "12345"; #main.grp "!hide" timer 100,[check] wait
[check] #main.te "!contents? string$" #main.StatusBar showString$(string$) if len(string$)>maxLen+2 then string$=left$(string$,maxLen) 'lose the trailing CrLf pair 'Should make condition FALSE, or you'll lose cursor #main.te "!contents string$" '#main.te "!setfocus" string$="" ttl=10 'ticks to show message #main.grp "!show" end if
if ttl=0 then #main.grp "!hide"
if ttl>0 then #main.StatusBar "String length limit reached "';ttl
ttl=ttl-1 wait
[quit] timer 0 close #main end
function showString$(s$) showString$=len(s$);" " for i = 1 to len(s$) c$=mid$(s$,i,1) if asc(c$)>32 then showString$=showString$+c$ else showString$=showString$+"[";asc(c$);"]" end if next end function
|
|
|
Post by xxgeek on Apr 15, 2024 7:50:07 GMT -5
Good day Anatoly. A couple of questions and some observations to run by you... In this thread we talked about texteditor limits libertybasiccom.proboards.com/thread/2389/string-big-fit-clipboardand found that #of empty lines, spaces, and CRLF play a role in total allowed characters in a texteditor. Your code only tested mainwin at the time, and not a texteditor. After testing a bit, I found that the mainwin, and the texeditor are not equal in their limits. The texteditor can accept more than the mainwin when a selectall/copy is done. Try for yourself with this adapted code. 'run this program and press Ctrl-A in the mainwindow 'it works for 66 (66000 characters) 'but produces error message for 67 (67000 characters) ' "String is too big to fit into the clipboard. Do you wish to continue anyway" 'nomainwin WindowWidth = 360 : WindowHeight = 360 UpperLeftX = 100 : UpperLeftY = 10 texteditor #w.te1, 30, 10, 290, 225 Button #w.spaces, "Spaces", [spaces], UL, 80, 240, 60, 40 Button #w.text, "Text", [text], UL, 150, 240, 60, 40 Button #w.copy, "Copy All", [copy], UL, 250, 240, 60, 40 statictext #w..st "Print Spaces or Text",100,285,150,15 '......................... open "Texteditor Character Limit" for window as #w #w "trapclose [quitw]" wait
[spaces] 'print "cls" for i = 1 to 33'32'66'67 'single line. 32000 OK, 33000 - "String is too big to fit into the clipboard. Do you wish to continue anyway" a$=space$(100) for j = 1 to 10 print a$; #w.te1 a$ next next wait
[copy] #w.te1 "!selectall" #w.te1 "!copy" wait
[text] #w.te1 "!cls" for i = 1 to 67'66'32'33 c$=chr$(asc("a")-1+i) a$="" for k = 1 to 97 a$=a$+c$ next for j = 1 to 10 print a$ #w.te1 a$ next print using("########",i) '8*# and CRLF, with this line, total 1000 chars next wait
[quitw] close #w end
First try [Spaces] button then [Copy All] button- it works ok using 33k and copies all. then go to mainwin, Edit>selectall>copy - "String Too Big" Second try [Text] button then [Copy All] button- it works ok using 67k and copies all. then go to mainwin, Edit>selectall>copy - "String Too Big" Question #1 Can you figure out how to know if the texeditor will be able to copyALL prior to actually trying to copyALL Question #2 emy posted a great piece of code that works to limit text in a textbox, so I tried swapping the textbox for a texteditor, but no luck. Is there a way to make it work using _EM_SETLIMITTEXT? As quoted by Rod in libertybasiccom.proboards.com/thread/2389/string-big-fit-clipboardRod's last post. There must be a way we can use the info of how many CRLF's and spaces there are, and adjust our limit size in order to avoid the "String Too Big" message. [EDIT] Another observation... If I paste what's in the texteditor into mainwin and then selectall and copy, there is no "String too big" message - go figure. It only gets too big when done with code.
|
|
|
Post by tsh73 on Apr 15, 2024 16:25:19 GMT -5
Question #1 no Question #2 I've read elsewhere on forum, that textEditor is custom control made by Carl So API magic does not work with it so - no (I wonder if one could somehow create multiline edit control via API and use that (and limit it too) But I'm not versed in this. This thread looks promising. libertybasiccom.proboards.com/thread/574/word-wrap-text-editor-control
Just tested API created texteditor by metro (second last post) Adding call tbLimit hT,11 (function earlier in this thread) just after hT=CreateTextEdit(hwnd(#Tedit), 1, 1, 800, 500) limits this texteditor (look really like 11 characters). )
|
|
|
Post by xxgeek on Apr 16, 2024 9:16:33 GMT -5
Thanks Anatoly.
Edited code with limit of 11 characters for texteditor (can be changed)
For anyone who wants it
nomainwin WindowWidth=900:WindowHeight=600 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2
Menu #Tedit, "&File", "&Open", [open],_ "&Save", [save], "E&xit", [quit] Menu #Tedit, "&Edit", "&Cut", [cut],_ "C&opy", [copy], "&Paste", [paste],_ "&Undo", [undo] Menu #Tedit, "&Font", "&Arial 14", [arial14],_ "A&rial 18", [arial18],_ "&Courier New 14", [courier14],_ "Courier &New 18",[courier18]
open "Barebones Texteditor" for window as #Tedit print #Tedit, "trapclose [quit]" print #Tedit, "resizehandler [resizeIt]"
hT=CreateTextEdit(hwnd(#Tedit), 50, 20, 800, 500) call SetTextLimit hT,11 'set the texteditor character limit here call SetFocus hT
wait
[quit] if hFont<>0 then call DeleteObject hFont close #Tedit
[resizeIt] ww=WindowWidth:wh=WindowHeight call MoveWindow hT, 1, 1, ww-2, wh-2 wait
[open] filedialog "Open","*.txt",file$ if file$="" then wait open file$ for input as #f txt$=input$(#f, lof(#f)) close #f call SetWindowText hT, txt$ wait
[save] filedialog "Save","*.txt",sfile$ if sfile$="" then wait if right$(sfile$,4)<>".txt" then sfile$=sfile$+".txt" end if open sfile$ for output as #f txt$=GetWindowText$(hT) print #f, txt$ close #f wait
[cut] ret = SendMessageLong(hT,_WM_CUT,0,0) wait
[copy] ret = SendMessageLong(hT,_WM_COPY,0,0) wait
[paste] ret = SendMessageLong(hT,_WM_PASTE,0,0) wait
[undo] ret = SendMessageLong(hT,_WM_UNDO,0,0) wait
[arial14] if hFont<>0 then call DeleteObject hFont hFont=CreateFont("arial",14) ret = SendMessageLong(hT,_WM_SETFONT,hFont,1) wait
[arial18] if hFont<>0 then call DeleteObject hFont hFont=CreateFont("arial",18) ret = SendMessageLong(hT,_WM_SETFONT,hFont,1) wait
[courier14] if hFont<>0 then call DeleteObject hFont hFont=CreateFont("courier new",14) ret = SendMessageLong(hT,_WM_SETFONT,hFont,1) wait
[courier18] if hFont<>0 then call DeleteObject hFont hFont=CreateFont("courier new",18) ret = SendMessageLong(hT,_WM_SETFONT,hFont,1) wait
Function SendMessagePtr(hWnd,msg,w,p$) calldll #user32, "SendMessageA", hWnd as ulong, _ msg as long, w as long, p$ as ptr,_ SendMessagePtr as long end function
function SendMessageLong(hWnd,msg,w,l) calldll #user32, "SendMessageA", hWnd as ulong, _ msg as long, w as long, l as long,_ SendMessageLong as long end function
sub SetTextLimit TextBoxHwnd, Limit CallDll #user32, "SendMessageA",_ TextBoxHwnd as ulong,_ _EM_SETLIMITTEXT as long,_ Limit as long,_ 0 as long,_ SetTextLimit as long end sub
sub SetFocus hWnd calldll #user32, "SetFocus", hWnd as ulong,_ result as ulong end sub
sub SetWindowText hWnd, txt$ calldll #user32, "SetWindowTextA", hWnd as ulong,_ txt$ as ptr, result as void end sub
function GetWindowText$(hWnd) total = GetWindowTextLength(hWnd) Title$=space$(total)+Chr$(0):l= Len(Title$)
calldll #user32, "GetWindowTextA", hWnd as ulong,_ Title$ as ptr, l as long, result as long GetWindowText$=trim$(Title$) end function
function GetWindowTextLength(hW) calldll #user32, "GetWindowTextLengthA",_ hW as ulong,_ GetWindowTextLength as long end function
Function CreateTextEdit(hW, x, y, w, h) style = _WS_CHILDWINDOW OR _WS_BORDER _ OR _WS_VISIBLE or _ES_MULTILINE or _WS_VSCROLL hInst=GetWindowLong(hW, _GWL_HINSTANCE)
calldll #user32, "CreateWindowExA",_ 0 as long,"EDIT" as ptr,_ "" as ptr, style as long,_ x as long,y as long,w as long,h as long,_ hW as ulong, 0 as long, hInst as ulong,_ 0 as long, CreateTextEdit as ulong end function
Function GetWindowLong(hW, type) calldll #user32, "GetWindowLongA", _ hW as ulong, type as long,_ GetWindowLong as ulong End Function
Function CreateFont(fontname$, fontheight) fontname$ = fontname$ + chr$(0) Calldll #gdi32, "CreateFontA",_ fontheight as long,_ 0 as long,0 as long,0 as long,_ 0 as long,0 as long,0 as long,_ 0 as long,0 as long,0 as long,_ 0 as long,0 as long,0 as long,_ fontname$ as PTR,_ CreateFont as ulong end function
sub DeleteObject hObject calldll #gdi32,"DeleteObject",_ hObject as ulong,_ r as long end sub
sub MoveWindow hW, x, y, w, h calldll #user32, "MoveWindow",_ hW as ulong, x as long, y as long,_ w as long, h as long,_ 1 as boolean, result as long end sub
My needs are with 'knowing' the texteditor's limit before a !selectall/!cut, and or !copy of an entire file's text, each file presents differing numbers of spaces, CR LFs, and characters, not to 'set' a limit.
In my CodeTank program files get loaded into a texteditor and I use !cut when deleting a Title from the list and !cut it's text from the texteditor. Some files are too big and cause the message "Too big for clipboard, do you want to continue" to appear. That's what I need a workaround for.
I'll figure it out eventually. Lots to play with in the mean time.
|
|
|
Post by tsh73 on Apr 16, 2024 10:07:03 GMT -5
Well, "limit" is this thread theme.
So do you use "!cut" only to delete stuff from texteditor? How about "!cls" instead?
|
|
|
Post by xxgeek on Apr 16, 2024 10:41:05 GMT -5
Yes, it works very well LOL on me. Man, I thought I tried that long ago. There must have been a second issue back when I tried I suppose. Thanks again my friend. For anyone else with problems with !copy and !cut after a !selectall on a texteditor, if you keep the text below 32k there shouldn't be an issue. If you want to figure out the 'actual' limit on a specific long file the limit could be near 64k, but not an easy task getting an exact code that will work on any long file.
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 16, 2024 12:10:01 GMT -5
Thanks to all for the suggestions. I am studying carefully all possibilities. Thanks to all again and bye fox
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 18, 2024 4:55:25 GMT -5
Hi all. Another problem with texteditor. I created a little texteditor with LB 4.5.1:
nomainwin texteditor #1.ext, 10, 10, 200, 600 open "Test" for window as #1 print #1.ext, "!setfocus" print #1, "trapclose [quit]" string$ = "" for a = 1 to 10 string$ = string$ + "TEST OF TEXTEDITOR no ";a;chr$(10) next #1.ext, "!contents string$"; wait [quit] close #1 end wait
and if I use it as a .bas file, mouse scrolling works well, but if I use it as .exe file mouse scrolling does not work. And I don't understand why. Bye fox
|
|