PDA

View Full Version : textshrinking editor (project)



Lionheart008
06-07-2010, 12:59
hello,

I've played around with text and textbox and here's a good approach to make a little textspace shrinking editor (first issue). more to come. thanks to petr for little help belongs to MCase$ statement that's better to handle than LCase/UCase$.

you can make input like:

"this IS a VERY beautiful DAY today in GERMANY or italy or ENGLAND or usa."

(then copy this line for example with: right click mouse on text, context menu: copy text, insert new lines in textbox)

if you have added some text lines push "shrink" button :)


' Empty GUI script created on 07-05-2010 20:58:57 by frank (ThinAIR)

Uses "console", "ui"

Begin ControlID
%textboxy = %WM_USER
%ButtonClose
%chary
%message
%ButtonShrink
%buttony
End ControlID

Function TBMain() As Long
Local hDlg As Long
Local mytxt As String 'Value = rgb(100,200,255)

mytxt = ""

Dialog New 0, "Shrink Textspace Editor",-1,-1,260,260, %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX, 0 To hDlg
Dialog Set Color hdlg, Rgb(100,100,50),Rgb(100,100,255)

'Control Set Color, hdlg, %textboxy, mytxt, Rgb(100,100,255)'
Control Set Color hdlg, %textboxy, %BLUE, %BLUE
Control Add Textbox, hDlg, %textboxy, mytxt, 10, 25, 220, 185, %ES_MULTILINE Or %ES_WANTRETURN , %WS_EX_CLIENTEDGE, Call textControl
Control Add Label, hDlg, %chary, "Characters:", 40,10,80,8 ',-1
Control Add Label, hDlg, %message, "Messages: ", 160,10,60,8, '-2
Control Add Button, hDlg, %buttony, "Shrink TextSpace", 100,220,90,20 Call Shrink
Control Add Button, hDlg, %ButtonClose, "close", 20,220,40,20 Call cBDialog

Dialog Show Modal hDlg, Call cbDialog

End Function

'---------------------------------------

CallBack Function textControl() As Long
Local txt As String
Local msgLen As String

Control Get Text CBHNDL, %textboxy To txt
Control Set Text CBHNDL, %chary,"Characters:"+Str$(Len(txt))

Select Case Len(txt)
Case <=160
MsgLen = "1"
Case <=320
MsgLen = "2"
Case <=460
MsgLen = "3"
Case Else
MsgLen = "too big"
End Select

Control Set Text CBHNDL, %message,"Messages:" + MsgLen

End Function

'------> callback for textspace shrinking -----------------------------------------

CallBack Function Shrink() As Long
Local txt, txt2, msglen As String

If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED Then
Control Get Text CBHNDL, %textboxy To txt

Control Set Color CBHNDL, %textboxy, %BLACK, %YELLOW
Control Redraw CBHNDL, %textboxy

Dim words() As String
Dim nWords As Long = Parse(txt, words, " ")

Dim i As Long

For i = 1 To nWords
words(i) = MCase$(words(i))
Next

txt2 = Join$(words, "")

Control Set Text CBHNDL, %textboxy,txt2

Control Set Text CBHNDL, %chary,"Characters: "+Trim$(Str$(Len(txt2)))

Select Case Len(txt2)
Case <=160
MsgLen = "1"
Case <=320
MsgLen = "2"
Case <=460
MsgLen = "3"
Case Else
MsgLen = "too big"
End Select

Control Set Text CBHNDL, %message,"Messages:" + MsgLen
End If
End Function


'-----> close --------------------------------------------------------
CallBack Function cbDialog()

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Case %WM_DESTROY
MsgBox 0, "window closed"

End Select

End Function

2) a) question: how to sign a text with other colour from beginning input by user ?


mytxt = ""

should be have for example blue colour?

b)
Control Add Label, hDlg, %chary, "Characters:", 40,10,80,8 ',-1

if I have a label and a coloured dialog, I can use at the end of code line "-1" to hide the grey label colour but the label text will disappear too. how I can avoid this one?

thanks, nice day, frank