Opened 10 years ago

Last modified 10 years ago

#8347 closed

[2.9] wxST_MARKUP and wxST_ELLIPSIZE_* style support

Reported by: frm Owned by: vadz
Priority: high Milestone:
Component: Version:
Keywords: Cc: frm, vadz
Blocked By: Blocking:
Patch: yes

Description

This patch:

1) adds SetLabelWithMarkup() function to wxStaticText and implements it natively (in wxControl however) for GTK+ 2

2) adds a stattextcmn.cpp file for common wxStaticText functions and puts the wxTextWrapper helper class used by wxDialog functions and by wxLabel in a private/stattext.h header

3) modifies WIDGETS sample to show the new feature

4) documents the new feature

NOTE1: the patch does not add to build/bakefiles/files.bkl the new private header. this should be ok I think.

NOTE2: the wxStaticText default constructor is untouched (i.e. the wxStaticText constructor still takes undecorated labels) but to make it easier to use the markup maybe we should:

a) change the constructor to call SetLabelWithMarkup() instead of just SetLabel()

b) add another constructor overload which uses SetLabelWithMarkup()

being able to set the markup directly from the constructor is very useful as when building the GUI the programmers typically do:

mysizer->Add(new wxStaticText(...));

i.e. don't save a pointer to the just-created static text (as this is not usually needed).

Attachments (3)

setlabelwithmarkup.patch download (22.8 KB) - added by frm 10 years ago.
statictext.patch download (74.5 KB) - added by frm 10 years ago.
adds support for wxST_MARKUP and wxST_ELLIPSIZE_* styles
statictext_vz.patch download (75.4 KB) - added by vadz 10 years ago.
My modified/updated version (work in progress)

Download all attachments as: .zip

Change History (16)

comment:1 Changed 10 years ago by frm

tested also under wxMSW where the mnemonics chars however seems not to be interpreted as mnemonics; they're just removed (under wxGTK they make the next char underlined as any mnemonic). This should be ok however (I think).

File Added: setlabelwithmarkup.patch

Changed 10 years ago by frm

comment:2 Changed 10 years ago by frm

File Added: setlabelwithmarkup.patch

comment:3 Changed 10 years ago by frm

NOTE to myself: things I've just thought about this patch:

1) the comment in stattext.h referring to dlgcmn.cpp can be removed
2) this patch need more testing for some things like double ampersand && (specially when placed at the end of the string)
3) we could entirely change the logic: make private the SetLabelWithMarkup() function and create a wxST_WITH_MARKUP style which could be used to create wxStaticText objects whose SetLabel() takes a string with decorated markup.

This approach would be more extendable with e.g. ellipsize-able static texts which I plan to contribute in future (if we create a wxST_ELLIPSIZEABLE style).

comment:4 Changed 10 years ago by frm

Two other notes (to myself):

1) we need also a g_markup_escape-like public function to be used when the programmer needs to set into a wxStaticText a string with markup taken e.g. from user input. I'd say a static wxStaticText::EscapeLabelWithMarkup() should do.

2) the const arrays of strings can be taken out of SetLabelWithMarkup() since stepping with the debugger seems that they need to be initialized all the times.

comment:5 Changed 10 years ago by frm

Attached a new version of the patch which does a lot of things:

1) fixes all "notes to myself" of previous comments

2) adds support for wxST_ELLIPSIZE_START/MIDDLE/END, wxST_MARKUP to wxGTK, wxMSW, wxUniv, wxCarbon, wxMotif, wxOS2 ports.

3) patches the WIDGETS sample to be able to test all new features of the wxStaticText class.

Tested on wxGTK 2 only for now.

File Added: statictext.patch

comment:6 Changed 10 years ago by frm

Now tested also on wxMSW.

Please note that apart from wxGTK and wxMSW very probably it will require some additional work to get it to work under other platforms.

File Added: statictext.patch

comment:7 Changed 10 years ago by frm

NOTE: I've found that the MSWCreateControl modification introduces an unwanted effect: for wxTextCtrl a wxEVT_COMMAND_TEXT_UPDATED event is sent also on creation, and this may be undesiderate!

The solution is to just set the label when creating the control (i.e. discard the msw\control.cpp patch portion) and then immediately do:

m_strOriginalLabel = label;

Changed 10 years ago by frm

adds support for wxST_MARKUP and wxST_ELLIPSIZE_* styles

comment:8 Changed 10 years ago by frm

Attached the updated patch with the fix of the previous comment.

File Added: statictext.patch

comment:9 Changed 10 years ago by vadz

I'm looking at this but I'm confused by the 2 patches: is setlabelwithmarkup.patch still relevant?

comment:10 Changed 10 years ago by frm

I'm looking at this

Thanks!

is setlabelwithmarkup.patch still relevant?

sorry - it isn't; I left it just for historical purposes: it was the approach of adding SetLabelWithMarkup() function which I later abandoned in favour of the wxST_MARKUP style.

Changed 10 years ago by vadz

My modified/updated version (work in progress)

comment:11 Changed 10 years ago by vadz

I started looking at this patch a few days ago but unfortunately didn't have time to finish, there are still quite a few things I'm unsure about. But just so that the changes I already did don't get lost, I attach the current version of the patch (Francesco, please ask me if you have any questions about the differences between it and your original patch).
File Added: statictext_vz.patch

comment:12 Changed 10 years ago by frm

the changes looks right to me - even if most of them are "just" re-wording or my bad english ;)

Thanks!

comment:13 Changed 10 years ago by vadz

I've finally applied the patch with more (mostly cosmetic) changes, please review my changes in the cvs and let me know if I got anything wrong. Except for several compilation fixes and renaming, I've also removed many wxControl::SetLabel() calls from wxGTK controls and added it to GTKSetLabelForLabel() instead.

There are a couple of problems which I saw during tesing:

  1. Bad things happen if you pass a label with incorrect markup to wxGTK: the label changes internally but not on the screen. This is probably trivial to fix but I didn't have time to look at it today, I just wanted to apply this patch before the sources changed even more.
  1. Ellipsization in the middle and from end doesn't work correctly in wxUniv: just "..." is shown in the widgets sample

Thanks!

Note: See TracTickets for help on using tickets.