I have troubles with a Styled TextArea and tabs

It might work.
But it’s not necessarily going to work xplatform.
The text area is not a “rich text editor” - which is a ton more work to support tab rulers, font selections etc etc etc
Which is where a third party has actually provided an option - see Bkeeney’s FTC

I did test this on a standard TextArea by pasting in an RTF doc created from TextEdit and all the tabs were where they should be and were of the proper type (left, right, center, etc.). Admittedly not the same as programmatically setting the tab stops, but it does show that Xojo (for now and on a Mac, at least) respects a subset of the RTF specs. I would imagine Windows would do at least as well since that’s where RTF came from.

Still, will take your caution to heart. Thanks

Danny:
The rtf code I wrote were only to try to better explain - with my limited english - how the things are.
Yes, I know a lot about RTF (but not so much) have been used it since… ages (1988 or so) while I worked at Apple France.
At last, we can edit an Apple’s TextEdit rtf file (edit the rtf in the rtf file): marg __ 767 means a Tab width of (nearly) 1 cm instead of inch or twips…

RTFData in Xojo does not support Tab nor… Xojo support a very small subset of RTF.

Norman:
How am I supposed to display (tons of) data from a (billion number of) text file(s) in a single TextEdit (TextField / TextArea) who have less than one line of text, more than one line in the paragraph, one or two or x… tabs to get vertically aligned data ?

Remember what I wrote far above: only the first 12 tabs are significant in Cocoa and the 12th location is near the middle of the TextArea width.
I read what you wrote, I think I understand what I read (in this case), but I cannot believe you wrote that or you understand what my description of the trouble is.
I also understand you cannot takes days to “check what a potential trouble can be”.

Also:
Using tabs in my TextArea works ‘correctly’ until I am near the middle of the TextArea width (in Cocoa, but works fine on Carbon / Windows). Text without tab can be displayed until near the end of the TextArea line (and wrap around only if the last word cannot be displayed on that line).

RTF support in TextArea is far less than basic and so I do not use it. I only load raw text from files (unfortunately) because of that with one exception.
In that exception file, I have to create, edit and save the rtf (to date, I use only one font in Standard and Bold flavors) in a specially created project to avoid troubles.
Troubles (files created with Apple’s TextEdit) : the used font in the original document is not displayed, Encoding is not used too on diacritical characters (é = \zyx and so on), etc. And sometimes I have to correct more than one time a single file.

At last, yes, if I pay some third party work, I probably will be able to do what I want (probably). But in that case, I’d better stop with a software that needs the user to buy add-ons to replace its half working included Controls:

Replace the built-in ListBox with XYZ (I forgot what misses in ListBox some found),
Replace the built-in TextArea with Formated Text Control…,
Replace the built-in ProgressBar if you want to display correctly the waiting string,
Replace the Report tool with another *

And the list grows.

Yes, I am disappointed a little by Xojo and in anger almost with each time I use it. **

  • I do not used Xojo built-in Report because I do not had time to learn how it worked before giving my Pro Bono application to the client. I do not experiment it because of the bad “reports” I read later, once I could take time to learn how it works.

** Latest bug to date:

The example code below comes from
If Obj.PictureAvailable Then
Me.Image = obj.Picture
ElseIf Obj.FolderItemAvailable Then
Me.Image = Picture.Open(obj.FolderItem)
End If

In the line:
Me.Image = Picture.Open(obj.FolderItem)

Obj.FolderItem may refer to any file type (from a text file to a directory) ON COCOA.

On Carbon, Windows (and probably Linux: not tested), only an image file of the type passed with Me.AcceptFileDrop() goes there. You cannot have a reference of a text file or a Folder there.

I do not write about the lack of Focus Ring around the Canvas when the Cursor is above it, nor the Mouse Cursor change, etc. ON COCOA OS X. These occurs on Windows XP.
I stop here because these are not TextArea related.

Emile,

The RTF control codes you mention (\marg…) don’t have anything to do with tabs. “Margin” means the distance from the edge of the paper to where the text starts (or ends). So \margl refers to the left margin, \margr refers to the right margin, etc. The control codes to set the tab stops are the ones I indicated. Also, I think a cm would be about 567 twips.

Anyway, see what I mean by using TextEdit to make a new document. Use the “Show Ruler” command to get a ruler up where you can set a bunch of different tab stops. Go ahead and type in some text by tabbing to various tab stops to verify that it works. Then save the file and close it by clicking on the red close button. Now in TextEdit, go to preferences, click on the “open and save” tab and check “Display RTF file as RTF code instead of formatted text”. Now open the file you just created and you will see all the RTF control codes, including the tab control codes I indicated.

To prove this will work in Xojo, create a TextArea in a window, making sure multiline, styled text, and accept tabs are checked, and run it. Open the file you created earlier in TextEdit, but this time make sure “Display RTF file as RTF code instead of formatted text” is unchecked before you open it (otherwise the control codes will be interpreted as text). Do a command-A to select all the text and copy it to the clipboard. Paste this into your Xojo TextArea and you will find that all the tab stops are working as they should. Also, all formatting including fonts, bolding, italicizing, font sizes, and diacriticals are preserved. At least on a Mac. Haven’t tried on Windows or Linux. In those cases, you may have to specify a codepage to use, I don’t know

Theoretically, you should be able to set the tabs programmatically, I haven’t tried it. What I found won’t work is trying to paste in the RTF information as a “default value”. It will have to be set at runtime. Alternatively, you should be able to load an RTF file (at runtime, of course) with the appropriate tab stops and be good to go.

Given what Norman has said, I’m just suggesting that this could be used as a workaround for now.

Dan

Emile,

I don’t know yet how to write directly to the RTF control codes in a TextArea, though I think it must be possible. I was able to do the following. This was added to the open event of a TextArea control since I knew I could manually paste and do the same:

[code] dim st as string = “{\rtf1\ansi\ansicpg1252\cocoartf1265” + EndOfLine + “{\fonttbl\f0\fswiss\fcharset0 Helvetica;}” + EndOfLine + “{\colortbl;\red255\green255\blue255;}” _

  • EndOfLine +"\margl1440\margr1440\vieww25800\viewh16040\viewkind0" + EndOfLine + “\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\tx10864\tx14820\tx18331\tx20772\tx22950\tx25047\pardirnatural” _
  • EndOfLine + EndOfLine + “\f0\fs24 \cf0 \'e0 \'c2 \'f1 \'ed}”

Dim c As New Clipboard
c.AddRawData(st,“public.rtf”)
c.Close

me.paste
[/code]

Running this on a Mac gives you several extra tabs and a few diacritical characters. I did find that there has to be SOME text and not just the control codes, or the default 12 tabs will be what you get.

I hope this is useful.

Danny:
Thank you for your answers.

The RTF control codes you mention (\marg…) don’t have anything to do with tabs.
You are right !
That is why I had tx in my mind at writing time, but I used \marg because I checked with a rtf file. In that file, I set the margins to 1cm (more or less). I’ve made a mistake.

Sorry.

I don’t know yet how to write directly to the RTF control codes in a TextArea
http://documentation.xojo.com/index.php/StyledText.RTFData

You simply read the whole data from a rtf file with a TextInputStream and pass it to RTFData. Read the dos and you will better understand.

Before creating a new conversation, I checked what is in the RTFData (what Xojo put in RTFData) by making a copy in the Clipboard and pasting it elsewhere… There was no defined tabs (unless I’ve made another mistake ?).
So, I just checked and… no, no \tx in RTFData:

{\\rtf1\\ansi\\ansicpg1252{\\fonttbl{\\f0\\fnil Lucida Grande;}}{\\colortbl\\red76\\green78\\blue78;\\red0\\green0\\blue233;\\red0\\green0\\blue0;\\red64\\green128\\blue4;\\red0\\green22\\blue176;\\red108\\green6\\blue211;\\red0\\green4\\blue255;\\red74\\green30\\blue127;\\red38\\green18\\blue82;\\red68\\green21\\blue176;}\\uc0 \\ql\\f0\\cf0\\fs24

header of the RTFData with an empty line defined. The original document (copied from Apple’s TextEdit application) is an AppleScript’ Script, so you understand the defined colors in \colortbl.

rtf in Apple’s TextEdit application have:

\\deftab720
and, if a line have defined tab(s), something like: \tx followed by a value in twips to define each \tab location as in:

\\tx567\\tx1134\\tx1699\\tx2266\\tx2833\\tx3400\\tx3967\\tx4534\\tx5101\\tx5668\\tx6235\\tx6802\\tx7369\\tx7936\\tx8503\\tx9070\\tx9637\\tx10204\\tx10771\\tx11338\\tx11905\\pardeftab720
\\cf2 	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20\\

Remember: 1 cm = 566.333333… I rounded the value to 567 and it seems to be OK in Apple’s TextEdit rule bar (the tab interface triangle seems to be above each cm bar) running with French defaults (cm instead of inch)

But all of this does not exists in Xojo.

Have a look at my screen shot (from Xojo app) in the next entry…

I wake up earlier today with an idea in mind: what if my TextArea is 1,400 pixels wide ?
[understand: what Xojo will do if I set a TextArea with 1,400 pixel width ?]

I checked that immediately and here is what you can see once the application is running, with a bit of text:


I typed as many as 13 times in the Tab key, added some comments and here you are.

The project is new (virgin), I set the window to 1,400 x 900 (?), added a TextArea and set its size to window size - 20, set AcceptTabs to True and run it in the IDE. Nothing more.
Xojo 2013r4.1, OS X 10.8.5

Imagine you have to put data in a A3 paper and in these data you have aligned values (using Tab, one cannot do that differently excepted using mono spaced fonts).
These data can comes from a raw text file.

I forgot to note that line 1 is inside a paragraph of 3 lines without any LF, Return or anything from me that will force a wrap-around.
If I typed some text, it may have filled the whole TextArea width, continuing far away from where the tab wraparound happens.

Xojo’s RTF does not support a feature that was present in typewriters ? Astonishing…

Typewriter

I had typewriter courses as early as 1970…

The introduction of the Tab key dates from 1897 ?

[quote]You simply read the whole data from a rtf file with a TextInputStream and pass it to RTFData[/quote] What I mean is that there is no direct way to do something like TextArea1.StyledText.RTFControlString = “\tx567\tx1134”. Xojo does explicitly handle bolding, alignment, italicizing, colors, and a few others, but there is not an obvious way to insert a generic control string. So far for me, Xojo interprets what I try to put in literally (as in Xojo thinks the control strings are text to be displayed).

That’s why I used the paste method and it DOES work. Seriously, put the following in the open event handler for a text area:

[code] // This will set tab stops every centimeter for 21 cm

dim st as string = “{\rtf1\ansi\ansicpg1252\cocoartf1265” + EndOfLine + “{\fonttbl\f0\fswiss\fcharset0 Helvetica;}” + EndOfLine + “{\colortbl;\red255\green255\blue255;}” _

  • EndOfLine +"\margl1440\margr1440\vieww25800\viewh16040\viewkind0" + EndOfLine _
  • “\pard\tx567\tx1134\tx1699\tx2266\tx2833\tx3400\tx3967\tx4534\tx5101\tx5668\tx6235\tx6802\tx7369\tx7936\tx8503\tx9070\tx9637\tx10204\tx10771\tx11338\tx11905\pardeftab720\pardirnatural” _
  • EndOfLine + EndOfLine + “\f0\fs24 \cf0 a}”

Dim c As New Clipboard
c.AddRawData(st,“public.rtf”)
c.Close

me.paste
[/code]
You will see that you do indeed now have 21 tab stops on one line. You’ll have to expand your window to see them all. You REALLY need to try this.

Dan

Xojo has done a great job implementing rtf. If you’ve ever worked with xcode, rtf support is @!#$/!. And the RTF view for cocoa is 500 euros (do a Google search)… so FTC really isn’t that expensive… All languages require an add on of sorts in one situation or another. . Even if it’s a set of specialized classes. … Like Norman has mentioned before, cocoa is a beast of its own in comparison to carbon… everything comes with a price even if it’s not monetary. And usually the income you generate from a piece of software pays for the add ons you invest in, and builds your “code arsenal.” So the means justify the ends. :slight_smile: you say that you are loading the text? Will the text need editing by the user or just to be viewed? If viewing only by the user, there are classes already available to display rtf in an htmlviewer. Really should at least look at the demo of FTC and see if it suits your needs. Bkeeny also has another control that does the same thing as FTC (without code lines etc…basically a text area control) for $15.00 that can do what you are looking for. $15 really isn’t that much in the scope of the situation. There is a demo of that as well, and it supports rtf/html and images.

No question there, but after playing with this for a while, I do think what would really round things out would be methods to set and get generic RTF control codes. The RTF spec has a whole boatload of control codes, and Apple has added their own for OS X. This doesn’t hurt anything since the spec also calls for the viewer/editor to ignore unhandled control codes (and doesn’t call for throwing those away, although that’s probably not prohibited).

By having a way to easily set and get control codes that Xojo doesn’t handle, the programmer can provide his own methods to deal with those. In addition, a lot of those things should stay with the document, good examples being \author, \title, and , yes, tab stops. It’s totally fine if Xojo chooses not to deal with a lot of these, but shouldn’t make it difficult for the programmer to get to them.

It’s especially galling in this case where the viewer DOES handle tabs correctly - the only issue being it is damn near impossible to set them.

Just my $0.02 and probably not worth that.

Hence why I’ve said more than once “I would not use RTF for this and expect anything approaching consistent results across platforms”
Hence why I’ve said I would not rely on RTF for what Emile is relying on it to do.

Oh well.

Thanks, Norman. My comment above was meant to be in keeping with what you’ve stated. That is, things that Xojo explicitly supports, there are properties and methods for; things Xojo doesn’t support, there aren’t. My suggestion was only that access be made easier to generic RTF control codes - that’s all that Xojo would be guaranteeing. What use one made of that power would be on that person (think Spiderman here).

Correct. It was never intended to. Although it would make a good feature request. RTF support was added as a mechanism to save Styled Text from the TextArea, which only supports bold, italic, underline, font, size and color. Support for anything else is a byproduct of the underlying technologies and is a bonus, but not intended or supported.

This is not my opinion.

The first releases with rtf support was a shame; diacritical characters were… and I do not talk about…

Nota:
A Paste of styled text in TextArea display things that may not be saved at RTF saving time.
You have to be aware of that.
As an example, Copy an html table (in Safari or FireFox) and paste it into an application with TextArea: you will see a nice table that will disappears once saved to disk.

I spent too much time checking all of these. I even checked what Xojo put in the Clipboard when you copy styled data from the Xojo running application:
Copy styled text from Apple’s TextEdit,
Paste it into the Xojo running application’ TextArea,
copy a single word from the TextArea, (a way to clear the previous Clipboard contents)
Select All and copy all from the TextArea.
Then, with a dedicated AppleScript, I saved the Clipboard’s «Class RTF » to disk file and inspect it as rtf code.
The result is surprising.

I also take some minutes to display raw text file into a Canvas. Have a look below:

The line that have a number followed by a ‘large space’ (30 pixels) is in fact a line with tab between each number.
You can see that I can print in a canvas as many as 35 tabs (nearly 3 times what I can do with a TextArea) - the file holds 41 tabs).
You can also see that I have troubles to align lines where the text between tabs is larger than 30 pixels. If I can get exercicetime, I will try something to get a better look. But this is only a style exercise project.
Also: no H/V scroll bars, etc.
But, less than 20 lines / less the time spent to write this discussion to get that result.

Norman:

Hence why I’ve said I would not rely on RTF for what Emile is relying on it to do.
That is OK for me, I can use anything else (built-in Xojo), but what and how. Advice(s) needed.

Today image’s text comes from a “book” of 803 comic strips magazine run (Indrajal Comics) released in India. The text as you can read is a description of one issue contents. At first, I only used one tab (between the page number and the description); after a while, I added more tabs to get a better look / understanding.
Then I used two or three consecutive tabs to (try to) get a better look.

I even tried to create rtf files (read/write) instead of raw txt files, but I falled in some troubles, but I forgot what they were.

Mattew:
Of course, if I can hope some sales, paying to build a far better application is a good deal.

But this will not be the case, unfortunately.

That’s correct. As far as I can tell, the methods for saving/loading RTF data only work for the explicitly supported RTF attributes.

I was playing around and came up with:

[code] // To save all our RTF data, copy to Clipboard, then save Clipboard data as String
// Naturally, this is limited by how much data our Clipboard can hold - not the ideal solution

me.SelectAll
me.Copy

Dim st As String, c As New Clipboard

st = c.RawData(“public.rtf”) // get unstructured string
c.Close

Dim f as FolderItem=GetSaveFolderItem(TextTypes.TextRtf,“TestSaveRTF”)
If f <> nil then
Dim tos as TextOutputStream=TextOutputStream.Create(f)
tos.Write st
tos = nil
End if
[/code]
For Mac-only, this has information from Massimo Valle about how to use native methods for loading and saving. These seem to be the same as what’s provided with macoslib.

Thanks Tim, that very concisely and precisely defines the situation.

Write code to do whatever alignments etc you want in a Canvas (unless you need this to also be editable ?)
A listbox with lots of columns so you can insert the data to align to whatever point you want.

I need to have the data editable unless I have to do the edit in one software (say Word in OS X / Windows) and display them in another (mine) ?

The Canvas screen shot above only shows what I do not know:
how to deal with some lines with tabs ?
how to add (and make working) h & v scrollbars in a Canvas ?
etc.

I went to a development software to not have to deal with all of these, it was what I was believing.

That is what I was thinking of: Xojo is not capable of doing what I want and I am not capable to work-around these shortcomings.

It tooks me some months to discover that, back before the first release of REALbasic… so many years ago.

Conclusion: I will give up this absurd idea and will leave this bad display in the software.

No: no feature request because they have so many things to do that this functionality will come after I would be in position to eat dandelions by the root.