Static text containing links

107 views
Skip to first unread message

QuentinC

unread,
Feb 7, 2021, 4:46:25 AM2/7/21
to wx-u...@googlegroups.com
Hello,

For a credits/about box, I would like to have static text that can
contain several links.
Those links should be focusable with tab, and it should be possible to
take action when clicking them. Otherwise the rest of the text shouldn't
be editable, and probably not even selectable/copiable.

Example of text:
My wonderful program, version 1.2.3
Copyright (c) 2021, My Name
Contact our support at he...@example.com or go to our website www.example.com
This program is using library XXX copyright XXX, more info at www.test.com
This program is using library YYY copyright YYY, more info at www.test.com


The standard wxMessageBox and wxAboutBox don't seem to support it out of
the box.
The about box allow to set a link, but only a single one, as far as I know.

wxStaticText doesn't support links.

wxHyperlinkCtrl doesn't seem to support multiple links, nor having one
part of the text inside and another outside the link. The hole text of
the control makes the link.

It's probabgly going to be very hard to properly place a succession of
wxStaticText and wxHyperlinkCtrl so to have a correct looking. I don't
want to play with layout stuff for hours and don't see well how sizers
could help in such a situation?

wxTextCtrl with the style wxTE_RICH2 can show links and react to clicks
on them, but it works only if URLs are written in clear (it may not
always be the case). And it has the appearance of a textbox, not static
text, what could cause confusion as there is no interaction to expect
with the text outside of the links.

Using wxWebView for this is probably like trying to kill a fly with a
tank? Far too complicated for what is worth, isn't it?
The text is never going to be longer than a paragraph like above.

What could I use then? Any idea?

Thank you for your answers.

Vadim Zeitlin

unread,
Feb 7, 2021, 11:51:59 AM2/7/21
to wx-u...@googlegroups.com
On Sun, 7 Feb 2021 10:46:11 +0100 QuentinC wrote:

Q> For a credits/about box, I would like to have static text that can
Q> contain several links.
Q> Those links should be focusable with tab, and it should be possible to
Q> take action when clicking them. Otherwise the rest of the text shouldn't
Q> be editable, and probably not even selectable/copiable.
Q>
Q> Example of text:
Q> My wonderful program, version 1.2.3
Q> Copyright (c) 2021, My Name
Q> Contact our support at he...@example.com or go to our website www.example.com
Q> This program is using library XXX copyright XXX, more info at www.test.com
Q> This program is using library YYY copyright YYY, more info at www.test.com

The simplest solution would be to use wxHtmlWindow.

Q> The standard wxMessageBox and wxAboutBox don't seem to support it out of
Q> the box.
Q> The about box allow to set a link, but only a single one, as far as I know.

Yes.

Q> wxHyperlinkCtrl doesn't seem to support multiple links, nor having one
Q> part of the text inside and another outside the link. The hole text of
Q> the control makes the link.

You could achieve this by juxtaposing several wxStaticText and
wxHyperlinkCtrl controls, probably, but using wxTextCtrl seems like a
simpler solution.

Q> It's probabgly going to be very hard to properly place a succession of
Q> wxStaticText and wxHyperlinkCtrl so to have a correct looking. I don't
Q> want to play with layout stuff for hours and don't see well how sizers
Q> could help in such a situation?

wxWrapSizer could be useful for this.

Q> wxTextCtrl with the style wxTE_RICH2 can show links and react to clicks
Q> on them, but it works only if URLs are written in clear (it may not
Q> always be the case).

The above should work just fine with it though and my initial suggestion,
until I read the paragraph above, was to use a wxTextCtrl with
wxTE_READONLY and wxTE_AUTO_URL styles. If you need anything more, you'll
have to use wxHtmlWindow, but wxTextCtrl has some advantages, notably from
the accessibility point of view.

Q> Using wxWebView for this is probably like trying to kill a fly with a
Q> tank? Far too complicated for what is worth, isn't it?

Yes.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

QuentinC

unread,
Feb 8, 2021, 11:35:02 AM2/8/21
to wx-u...@googlegroups.com
Hello,

VZ> The simplest solution would be to use wxHtmlWindow.

VZ> You could achieve this by juxtaposing several wxStaticText and
wxHyperlinkCtrl controls, probably, but using wxTextCtrl seems like a
simpler solution.
VZ> wxWrapSizer could be useful for this.

Thank you VZ, I'll try out both ideas, and see how it goes.

Last time I tried HTML controls, it wasn't screen reader accessible. I
don't know if it changed since WX 3.1.1.
But as far as I understand, individual links won't be reachable with tab
anyway. Is it correct?


I'll try with juxtaposed wxStaticText and wxHyperlinkCtrl layed out with
wxWrapSizer. However I don't have the impression that wxWrapSizer will
help me a lot. I see two problems:
1 - Force a line break
I can add an empty wxStaticText, but which width?
Too short and it won't work, too long and the next line of text will be
indented that many on the right.

2 - Break at correct places to have text naturally following the flow.
I don't know if I'm clear enough but here's an example of what I'm
thinking about:
Let's say I want to display "One two three four five six", with "three"
being a link.
Let's say that after the "three" being a link, there is enough space to
write "four five" on the right after the link, but not "four five six".

IN my algorithm, I create a first wxStaticText with the text "one two",
and then a wxHyperlinkCtrl with the text "three". Well.
Then if I create another wxStaticText with the text "four five six", as
far as I understand, wxWrapSizer will find that "four five six" is too
long for the space left after "three" and will so put the whole
wxStaticText on next line. The result will be:
"one two three"
"four five six"
Where it could have been:
"one two three four five"
"six"
I can split "four five six" into two wxStaticText, but how am I supposed
to know if I need to, and where ?
It is probably unresonable to create a wxStaticText for each individual
word, isn't it?

Thank you.
wxTextCtrl and wxHTMLWindow have the great advantage to not need to deal
with something like this.

Vadim Zeitlin

unread,
Feb 8, 2021, 11:42:51 AM2/8/21
to wx-u...@googlegroups.com
On Mon, 8 Feb 2021 17:34:52 +0100 QuentinC wrote:

Q> Last time I tried HTML controls, it wasn't screen reader accessible.

Unfortunately this is still true. It would be great to implement a11y
support for wxHtmlWindow, but I can't promise doing this, sorry.

Q> But as far as I understand, individual links won't be reachable with tab
Q> anyway. Is it correct?

This is probably correct too, but shouldn't be difficult to fix and I just
might do this to make TAB work in my own code using wxHtmlWindow with
links.

Q> I'll try with juxtaposed wxStaticText and wxHyperlinkCtrl layed out with
Q> wxWrapSizer. However I don't have the impression that wxWrapSizer will
Q> help me a lot. I see two problems:
Q> 1 - Force a line break

I think this should be done by just using separate wxWrapSizers for
different lines.

Q> 2 - Break at correct places to have text naturally following the flow.
[...]
Q> It is probably unresonable to create a wxStaticText for each individual
Q> word, isn't it?

I think it should work for reasonably sized text.

QuentinC

unread,
Feb 8, 2021, 12:12:22 PM2/8/21
to wx-u...@googlegroups.com
Hello,

VZ> Unfortunately this is still true. It would be great to implement
a11y support for wxHtmlWindow, but I can't promise doing this, sorry.

Maybe I can try something. I'll try to see what I could do.
I can't help for mac, but perhaps I can help for windows.

IF I have news about a11y, I'll come back

> This is probably correct too, but shouldn't be difficult to fix and
I just might do this to make TAB work in my own code using wxHtmlWindow
with links.

That would already be good. Probably too late for the program I'm
talking about right now, but certainly very useful for others in the future.

VZ> I think this should be done by just using separate wxWrapSizers for
different lines.
> I think it should work for reasonably sized text.

OK. I didn't imagined it like that, but I'll try the
wxStaticText+wxHyperlinkCtrl+wxWrapSizer solution first, by following
your little advices.
And then if I have time, go back to wxHTMLWindow and try to add the
missing accessibility.

Thank you.
Regards.

Marian Beermann

unread,
Feb 8, 2021, 12:19:46 PM2/8/21
to wx-u...@googlegroups.com, QuentinC
wxHyperlinkCtrl will probably not look right, because the baselines are
offset relative to other labels and it requires manual layout of the
lines, rather annoying.

I'd suggest wxRichTextCtrl in read-only mode. With some fiddling with
the background color you almost don't notice that it's not a label, and
it supports most rich text things you'd generally want in a label
(bold/italics/underline, different fonts/font sizes, hyperlinks, lists).

I don't know whether wxRTC supports a11y. If it does not I would think
it'd be easier to add a11y to it compared to a HTML renderer.

-Marian

Vadim Zeitlin

unread,
Feb 8, 2021, 12:28:46 PM2/8/21
to wx-u...@googlegroups.com
On Mon, 8 Feb 2021 18:19:35 +0100 Marian Beermann wrote:

MB> wxHyperlinkCtrl will probably not look right, because the baselines are
MB> offset relative to other labels and it requires manual layout of the
MB> lines, rather annoying.

I think it should work. We still don't have true baseline alignments in
wx, unfortunately, but we partially compensate for it by ensuring that all
standard controls do align with each other (e.g. there is no reason
the text in wxTextCtrl and wxStaticText should use the same baseline, but
in they actually do).

MB> I don't know whether wxRTC supports a11y.

No, it doesn't support it neither.

MB> If it does not I would think it'd be easier to add a11y to it compared
MB> to a HTML renderer.

FWIW I think it's the other way round, but it should be roughly similar.

QuentinC

unread,
Feb 8, 2021, 12:42:33 PM2/8/21
to wx-u...@googlegroups.com
Hello,

MB> wxHyperlinkCtrl will probably not look right, because the baselines
are offset relative to other labels and it requires manual layout of the
lines, rather annoying.

I'll see and let you know. If it's only a few pixels off, it shouldn't
be so annoying.
In my case it's an about box, so it isn't something you look at it all
the time, afterall. It's probably enough for my particular case.


MB> I don't know whether wxRTC supports a11y. If it does not I would
think it'd be easier to add a11y to it compared to a HTML renderer.

Unfortunately not, at least not last time I tried, wxWidgets 3.1.1.

About difficulty to add accessibility, Imo HTML is probably simpler,
because HTML windows are always read only.
With rich text you need to consider selection and editing.
Additionally, HTML formatting is much better/thorroughly defined than
RTF. I'm pretty sure that it makes a difference.
Implementing a11y is going to be harder if you want to go as far as
normal browsers (chrome, firefox, etc.) do. Butt you don't need to. Even
something basic that allows to read text and click links would already
by very good.


Marian Beermann

unread,
Feb 8, 2021, 1:41:00 PM2/8/21
to wx-u...@googlegroups.com, QuentinC
>
> MB> I don't know whether wxRTC supports a11y. If it does not I would
> think it'd be easier to add a11y to it compared to a HTML renderer.
>
> Unfortunately not, at least not last time I tried, wxWidgets 3.1.1.
>
> About difficulty to add accessibility, Imo HTML is probably simpler,
> because HTML windows are always read only.
> With rich text you need to  consider selection and editing.
> Additionally, HTML formatting is much better/thorroughly  defined than
> RTF. I'm pretty sure that it makes a difference.
> Implementing a11y is going to be harder if you want to go as far as
> normal browsers (chrome, firefox, etc.) do. Butt you don't need to. Even
>  something basic that allows to read text and click links would already
> by very good.
>

The way I did this was by subclassing wxRTC and only using it through an
interface which parses a small subset of HTML, converting it to RTC
instructions on the fly (SAX-style parser). Hence, my custom "QLabel
substitute" is always read-only (as a label) and there is always a
well-formed representation of the contents in the used HTML subset.
That's why I assumed that for these purposes (read only label, but with
formatting), it would be relatively easy to provide this information to
an a11y interface.

I didn't mean (but wrote, my bad :) to add a11y support for all features
to RTC

-Marian
Reply all
Reply to author
Forward
0 new messages