Buttons don't follow Action.Caption if it includes a '&'
Original Reporter info from Mantis: zpeterson @boramis
-
Reporter name: Zoë Peterson
Original Reporter info from Mantis: zpeterson @boramis
- Reporter name: Zoë Peterson
Description:
When changing a TAction's Caption property, any linked controls should update their captions too. Buttons will do so until the Caption includes an '&' (ampersand) character. Once that's set, any further changes to the action's Caption are ignored.
The problem is because TCocoaWSButton.GetText returns the button's caption as it currently is, and ControlTitleToNSString strips out any ampersand characters. When TControlActionLink.IsCaptionLinked checks the button's current caption against the action's previous caption, it sees that difference, so TControlActionLink.SetCaption doesn't do anything (assuming it's an intentional difference that shouldn't be overridden).
This was caused by the changes in SVN rev 53001 to try to fix bug #30527 (closed). I believe the fix there was incorrect. Button captions can't be modified by the user at runtime, so there's no reason for TCocoaWSButton.GetText to return a value. Changing it and GetTextLen to unconditionally return False tells the upper level LCL code to use the TControl's Caption field as-is rather than relying on the widgetset and NSControl's value. The attached patch fixes both this issue and the issue originally reported in issue 30527.
TCocoaWSWinControl's GetText implementation is probably overly inclusive. It might be better to make it opt-in so it's only used for the widget types that actually need it.
Steps to reproduce:
Extract the attached project and compile for both Cocoa and Carbon. When you type in the edit, it updates the action's caption, which then updates the button's caption. The button caption will stay in sync with the edit text until you type a & character. Any further changes are ignored until you press the button to get the captions back in sync.